ENH: fieldMinMax FO updated following update to use functionObjectState

Properties stored in state dictionary:
- minimum value: min<identifier>
- position of minimum value: min<identifier>_position
- processor ID of minimum value: min<identifier>_processor
- maximum value: max<identifier>
- position of maximum value: max<identifier>_position
- processor ID of maximum value: max<identifier>_processor
This commit is contained in:
Andrew Heather
2015-10-06 15:32:01 +01:00
parent 9b10608715
commit 137668ba81
3 changed files with 73 additions and 86 deletions

View File

@ -98,32 +98,16 @@ Foam::fieldMinMax::fieldMinMax
const bool loadFromFiles const bool loadFromFiles
) )
: :
functionObjectState(obr, name),
functionObjectFile(obr, name, typeName, dict), functionObjectFile(obr, name, typeName, dict),
obr_(obr), obr_(obr),
active_(true),
log_(true), log_(true),
writeLocation_(true), writeLocation_(true),
mode_(mdMag), mode_(mdMag),
fieldSet_() fieldSet_()
{ {
// Check if the available mesh is an fvMesh otherise deactivate // Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_)) if (setActive<fvMesh>())
{
active_ = false;
WarningIn
(
"fieldMinMax::fieldMinMax"
"("
"const word&, "
"const objectRegistry&, "
"const dictionary&, "
"const bool"
")"
) << "No fvMesh available, deactivating " << name_
<< endl;
}
if (active_)
{ {
read(dict); read(dict);
writeFileHeader(file()); writeFileHeader(file());

View File

@ -43,13 +43,9 @@ Description
... ...
writeToFile yes; writeToFile yes;
log yes; log yes;
location yes; writeLocation yes;
mode magnitude; mode magnitude;
fields fields (U p);
(
U
p
);
} }
\endverbatim \endverbatim
@ -59,7 +55,7 @@ Description
type | type name: fieldMinMax | yes | type | type name: fieldMinMax | yes |
writeToFile | write min/max data to file | no | yes writeToFile | write min/max data to file | no | yes
log | write min/max data to standard output | 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 mode | calculation mode: magnitude or component | no | magnitude
fields | list of fields to process | yes | fields | list of fields to process | yes |
\endtable \endtable
@ -69,6 +65,7 @@ Description
SeeAlso SeeAlso
Foam::functionObject Foam::functionObject
Foam::functionObjectFile Foam::functionObjectFile
Foam::functionObjectState
Foam::OutputFilterFunctionObject Foam::OutputFilterFunctionObject
SourceFiles SourceFiles
@ -81,8 +78,10 @@ SourceFiles
#ifndef fieldMinMax_H #ifndef fieldMinMax_H
#define fieldMinMax_H #define fieldMinMax_H
#include "functionObjectState.H"
#include "functionObjectFile.H" #include "functionObjectFile.H"
#include "Switch.H" #include "Switch.H"
#include "NamedEnum.H"
#include "vector.H" #include "vector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -97,20 +96,24 @@ class polyMesh;
class mapPolyMesh; class mapPolyMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class fieldMinMax Declaration Class fieldMinMax Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class fieldMinMax class fieldMinMax
: :
public functionObjectState,
public functionObjectFile public functionObjectFile
{ {
public: public:
enum modeType // Public enumerations
{
mdMag, // magnitude enum modeType
mdCmpt // component {
}; mdMag, // magnitude
mdCmpt // component
};
protected: protected:
@ -119,16 +122,10 @@ protected:
//- Mode type names //- Mode type names
static const NamedEnum<modeType, 2> modeTypeNames_; static const NamedEnum<modeType, 2> modeTypeNames_;
//- Name of this set of field min/max //- Reference to the database
// Also used as the name of the output directory
word name_;
const objectRegistry& obr_; const objectRegistry& obr_;
//- On/off switch //- Switch to send output to Info as well
bool active_;
//- Switch to send output to Info as well as file
Switch log_; Switch log_;
//- Switch to write location of min/max values //- Switch to write location of min/max values
@ -193,12 +190,6 @@ public:
// Member Functions // Member Functions
//- Return name of the set of field min/max
virtual const word& name() const
{
return name_;
}
//- Read the field min/max data //- Read the field min/max data
virtual void read(const dictionary&); virtual void read(const dictionary&);

View File

@ -95,6 +95,15 @@ void Foam::fieldMinMax::output
} }
if (log_) Info<< endl; 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::gatherList(minVs);
Pstream::scatterList(minVs);
Pstream::gatherList(minCs); Pstream::gatherList(minCs);
Pstream::scatterList(minCs);
Pstream::gatherList(maxVs); Pstream::gatherList(maxVs);
Pstream::scatterList(maxVs);
Pstream::gatherList(maxCs); Pstream::gatherList(maxCs);
Pstream::scatterList(maxCs);
if (Pstream::master()) label minI = findMin(minVs);
{ scalar minValue = minVs[minI];
label minI = findMin(minVs); const vector& minC = minCs[minI];
scalar minValue = minVs[minI];
const vector& minC = minCs[minI];
label maxI = findMax(maxVs); label maxI = findMax(maxVs);
scalar maxValue = maxVs[maxI]; scalar maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI]; const vector& maxC = maxCs[maxI];
output output
( (
fieldName, fieldName,
word("mag(" + fieldName + ")"), word("mag(" + fieldName + ")"),
minC, minC,
maxC, maxC,
minI, minI,
maxI, maxI,
minValue, minValue,
maxValue maxValue
); );
}
break; break;
} }
case mdCmpt: case mdCmpt:
@ -236,33 +246,34 @@ void Foam::fieldMinMax::calcMinMaxFields
} }
Pstream::gatherList(minVs); Pstream::gatherList(minVs);
Pstream::scatterList(minVs);
Pstream::gatherList(minCs); Pstream::gatherList(minCs);
Pstream::scatterList(minCs);
Pstream::gatherList(maxVs); Pstream::gatherList(maxVs);
Pstream::scatterList(maxVs);
Pstream::gatherList(maxCs); Pstream::gatherList(maxCs);
Pstream::scatterList(maxCs);
if (Pstream::master()) label minI = findMin(minVs);
{ Type minValue = minVs[minI];
label minI = findMin(minVs); const vector& minC = minCs[minI];
Type minValue = minVs[minI];
const vector& minC = minCs[minI];
label maxI = findMax(maxVs); label maxI = findMax(maxVs);
Type maxValue = maxVs[maxI]; Type maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI]; const vector& maxC = maxCs[maxI];
output output
( (
fieldName, fieldName,
fieldName, fieldName,
minC, minC,
maxC, maxC,
minI, minI,
maxI, maxI,
minValue, minValue,
maxValue maxValue
); );
}
break; break;
} }
default: default:
@ -274,7 +285,8 @@ void Foam::fieldMinMax::calcMinMaxFields
"const word&, " "const word&, "
"const modeType&" "const modeType&"
")" ")"
) << "Unknown min/max mode: " << modeTypeNames_[mode_] )
<< "Unknown min/max mode: " << modeTypeNames_[mode_]
<< exit(FatalError); << exit(FatalError);
} }
} }