diff --git a/src/functionObjects/field/fieldStatistics/fieldStatistics.C b/src/functionObjects/field/fieldStatistics/fieldStatistics.C index 350bcfc8a6..ad39bdc856 100644 --- a/src/functionObjects/field/fieldStatistics/fieldStatistics.C +++ b/src/functionObjects/field/fieldStatistics/fieldStatistics.C @@ -143,6 +143,87 @@ void Foam::functionObjects::fieldStatistics::writeFileHeader } +void Foam::functionObjects::fieldStatistics::writeStatData() +{ + for (const word& fieldName : fieldSet_.selectionNames()) + { + const auto& results = results_(fieldName); + + if (!results.size()) break; + + OFstream& file = *filePtrs_(fieldName); + + writeCurrentTime(file); + + for (const auto& iter : results.csorted()) + { + const variantOutput& value = iter.val(); + + std::visit + ( + [&file](const auto& v) + { + if constexpr + ( + is_vectorspace_v> + ) + { + for (const auto& val : v) file<< token::TAB << val; + } + else + { + file<< token::TAB << v; + } + }, + value + ); + } + file<< nl; + } +} + + +void Foam::functionObjects::fieldStatistics::logStatData() +{ + for (const word& fieldName : fieldSet_.selectionNames()) + { + const auto& results = results_(fieldName); + + if (!results.size()) break; + + Info<< nl << " Field " << fieldName << nl; + + for (const auto& iter : results.csorted()) + { + const word& name = iter.key(); + const variantOutput& value = iter.val(); + + std::visit + ( + [name](const auto& v) + { + if constexpr + ( + is_vectorspace_v> + ) + { + Info<< " " << name << " "; + for (const auto& val : v) Info<< val << " "; + Info<< nl; + } + else + { + Info<< " " << name << " " << v << nl; + } + }, + value + ); + } + } + Info<< endl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::fieldStatistics::fieldStatistics @@ -261,78 +342,13 @@ bool Foam::functionObjects::fieldStatistics::write() // Write the statistical results to the output file if requested if (writeToFile()) { - for (const word& fieldName : fieldSet_.selectionNames()) - { - const auto& results = results_(fieldName); - - OFstream& file = *filePtrs_(fieldName); - - writeCurrentTime(file); - - for (const auto& iter : results.csorted()) - { - const variantOutput& value = iter.val(); - - std::visit - ( - [&file](const auto& v) - { - if constexpr - ( - is_vectorspace_v> - ) - { - for (const auto& val : v) file<< token::TAB << val; - } - else - { - file<< token::TAB << v; - } - }, - value - ); - } - file<< nl; - } + writeStatData(); } // Print the statistical results to the standard stream if requested if (log) { - for (const word& fieldName : fieldSet_.selectionNames()) - { - const auto& results = results_(fieldName); - - Info<< nl << " Field " << fieldName << nl; - - for (const auto& iter : results.csorted()) - { - const word& name = iter.key(); - const variantOutput& value = iter.val(); - - std::visit - ( - [name](const auto& v) - { - if constexpr - ( - is_vectorspace_v> - ) - { - Info<< " " << name << " "; - for (const auto& val : v) Info<< val << " "; - Info<< nl; - } - else - { - Info<< " " << name << " " << v << nl; - } - }, - value - ); - } - } - Info<< endl; + logStatData(); } return true; diff --git a/src/functionObjects/field/fieldStatistics/fieldStatistics.H b/src/functionObjects/field/fieldStatistics/fieldStatistics.H index 98e7bf35bd..5c20cb348e 100644 --- a/src/functionObjects/field/fieldStatistics/fieldStatistics.H +++ b/src/functionObjects/field/fieldStatistics/fieldStatistics.H @@ -249,6 +249,12 @@ class fieldStatistics //- Output the file header information void writeFileHeader(Ostream& os, const word& fieldName); + //- + void writeStatData(); + + //- + void logStatData(); + public: //- Runtime type information