From 137668ba81ff99e68e6250f15b2abd0ae7ddd14f Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 6 Oct 2015 15:32:01 +0100 Subject: [PATCH] ENH: fieldMinMax FO updated following update to use functionObjectState Properties stored in state dictionary: - minimum value: min - position of minimum value: min_position - processor ID of minimum value: min_processor - maximum value: max - position of maximum value: max_position - processor ID of maximum value: max_processor --- .../field/fieldMinMax/fieldMinMax.C | 20 +--- .../field/fieldMinMax/fieldMinMax.H | 45 ++++----- .../field/fieldMinMax/fieldMinMaxTemplates.C | 94 +++++++++++-------- 3 files changed, 73 insertions(+), 86 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C index 19e24273b9..56ce3cde08 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.C @@ -98,32 +98,16 @@ Foam::fieldMinMax::fieldMinMax const bool loadFromFiles ) : + functionObjectState(obr, name), functionObjectFile(obr, name, typeName, dict), obr_(obr), - active_(true), log_(true), writeLocation_(true), mode_(mdMag), fieldSet_() { // Check if the available mesh is an fvMesh otherise deactivate - if (!isA(obr_)) - { - active_ = false; - WarningIn - ( - "fieldMinMax::fieldMinMax" - "(" - "const word&, " - "const objectRegistry&, " - "const dictionary&, " - "const bool" - ")" - ) << "No fvMesh available, deactivating " << name_ - << endl; - } - - if (active_) + if (setActive()) { read(dict); writeFileHeader(file()); diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H index 6f73b89298..2c6f45e923 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMax.H @@ -43,13 +43,9 @@ Description ... writeToFile yes; log yes; - location yes; + writeLocation yes; mode magnitude; - fields - ( - U - p - ); + fields (U p); } \endverbatim @@ -59,7 +55,7 @@ Description type | type name: fieldMinMax | yes | writeToFile | write min/max data to file | no | yes log | write min/max data to standard output | no | yes - location | write location of the min/max value | no | yes + writeLocation | write location of the min/max value | no | yes mode | calculation mode: magnitude or component | no | magnitude fields | list of fields to process | yes | \endtable @@ -69,6 +65,7 @@ Description SeeAlso Foam::functionObject Foam::functionObjectFile + Foam::functionObjectState Foam::OutputFilterFunctionObject SourceFiles @@ -81,8 +78,10 @@ SourceFiles #ifndef fieldMinMax_H #define fieldMinMax_H +#include "functionObjectState.H" #include "functionObjectFile.H" #include "Switch.H" +#include "NamedEnum.H" #include "vector.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -97,20 +96,24 @@ class polyMesh; class mapPolyMesh; /*---------------------------------------------------------------------------*\ - Class fieldMinMax Declaration + Class fieldMinMax Declaration \*---------------------------------------------------------------------------*/ class fieldMinMax : + public functionObjectState, public functionObjectFile { public: - enum modeType - { - mdMag, // magnitude - mdCmpt // component - }; + // Public enumerations + + enum modeType + { + mdMag, // magnitude + mdCmpt // component + }; + protected: @@ -119,16 +122,10 @@ protected: //- Mode type names static const NamedEnum modeTypeNames_; - //- Name of this set of field min/max - // Also used as the name of the output directory - word name_; - + //- Reference to the database const objectRegistry& obr_; - //- On/off switch - bool active_; - - //- Switch to send output to Info as well as file + //- Switch to send output to Info as well Switch log_; //- Switch to write location of min/max values @@ -193,12 +190,6 @@ public: // Member Functions - //- Return name of the set of field min/max - virtual const word& name() const - { - return name_; - } - //- Read the field min/max data virtual void read(const dictionary&); diff --git a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C index f64fa135f9..3680134b89 100644 --- a/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldMinMax/fieldMinMaxTemplates.C @@ -95,6 +95,15 @@ void Foam::fieldMinMax::output } if (log_) Info<< endl; + + // Write state/results information + word nameStr('(' + outputName + ')'); + this->setResult("min" + nameStr, minValue); + this->setResult("min" + nameStr + "_position", minC); + this->setResult("min" + nameStr + "_processor", minProcI); + this->setResult("max" + nameStr, maxValue); + this->setResult("max" + nameStr + "_position", maxC); + this->setResult("max" + nameStr + "_processor", maxProcI); } @@ -163,33 +172,34 @@ void Foam::fieldMinMax::calcMinMaxFields } Pstream::gatherList(minVs); + Pstream::scatterList(minVs); Pstream::gatherList(minCs); + Pstream::scatterList(minCs); Pstream::gatherList(maxVs); + Pstream::scatterList(maxVs); Pstream::gatherList(maxCs); + Pstream::scatterList(maxCs); - if (Pstream::master()) - { - label minI = findMin(minVs); - scalar minValue = minVs[minI]; - const vector& minC = minCs[minI]; + label minI = findMin(minVs); + scalar minValue = minVs[minI]; + const vector& minC = minCs[minI]; - label maxI = findMax(maxVs); - scalar maxValue = maxVs[maxI]; - const vector& maxC = maxCs[maxI]; + label maxI = findMax(maxVs); + scalar maxValue = maxVs[maxI]; + const vector& maxC = maxCs[maxI]; - output - ( - fieldName, - word("mag(" + fieldName + ")"), - minC, - maxC, - minI, - maxI, - minValue, - maxValue - ); - } + output + ( + fieldName, + word("mag(" + fieldName + ")"), + minC, + maxC, + minI, + maxI, + minValue, + maxValue + ); break; } case mdCmpt: @@ -236,33 +246,34 @@ void Foam::fieldMinMax::calcMinMaxFields } Pstream::gatherList(minVs); + Pstream::scatterList(minVs); Pstream::gatherList(minCs); + Pstream::scatterList(minCs); Pstream::gatherList(maxVs); + Pstream::scatterList(maxVs); Pstream::gatherList(maxCs); + Pstream::scatterList(maxCs); - if (Pstream::master()) - { - label minI = findMin(minVs); - Type minValue = minVs[minI]; - const vector& minC = minCs[minI]; + label minI = findMin(minVs); + Type minValue = minVs[minI]; + const vector& minC = minCs[minI]; - label maxI = findMax(maxVs); - Type maxValue = maxVs[maxI]; - const vector& maxC = maxCs[maxI]; + label maxI = findMax(maxVs); + Type maxValue = maxVs[maxI]; + const vector& maxC = maxCs[maxI]; - output - ( - fieldName, - fieldName, - minC, - maxC, - minI, - maxI, - minValue, - maxValue - ); - } + output + ( + fieldName, + fieldName, + minC, + maxC, + minI, + maxI, + minValue, + maxValue + ); break; } default: @@ -274,7 +285,8 @@ void Foam::fieldMinMax::calcMinMaxFields "const word&, " "const modeType&" ")" - ) << "Unknown min/max mode: " << modeTypeNames_[mode_] + ) + << "Unknown min/max mode: " << modeTypeNames_[mode_] << exit(FatalError); } }