diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C index 06a01c759c..ebcaaf2430 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C @@ -29,7 +29,24 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(Foam::fieldValues::fieldValueDelta, 0); +namespace Foam +{ + defineTypeNameAndDebug(Foam::fieldValues::fieldValueDelta, 0); + + template<> + const char* + NamedEnum::names[] = + { + "add", + "subtract", + "min", + "max" + }; + + const Foam::NamedEnum + Foam::fieldValues::fieldValueDelta::operationTypeNames_; +} + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -60,6 +77,7 @@ Foam::fieldValues::fieldValueDelta::fieldValueDelta obr_(obr), loadFromFiles_(loadFromFiles), log_(false), + operation_(opSubtract), source1Ptr_(NULL), source2Ptr_(NULL) { @@ -82,14 +100,20 @@ void Foam::fieldValues::fieldValueDelta::writeFileHeader(const label i) } } - file() << "# Time"; + Ostream& os = file(); + + os << "# Source1 : " << source1Ptr_->name() << nl + << "# Source2 : " << source2Ptr_->name() << nl + << "# Operation : " << operationTypeNames_[operation_] << nl; + + os << "# Time"; forAll(commonFields, i) { - file()<< tab << commonFields[i]; + os << tab << commonFields[i]; } - file() << endl; + os << endl; } @@ -126,6 +150,8 @@ void Foam::fieldValues::fieldValueDelta::read(const dictionary& dict) false ).ptr() ); + + operation_ = operationTypeNames_.read(dict.lookup("operation")); } diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H index cd11545d93..916fa6d3b0 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H @@ -85,6 +85,19 @@ class fieldValueDelta : public functionObjectFile { +public: + //- Operation type enumeration + enum operationType + { + opAdd, + opSubtract, + opMin, + opMax + }; + + //- Operation type names + static const NamedEnum operationTypeNames_; + private: @@ -102,6 +115,9 @@ private: //- Switch to send output to Info as well as to file Switch log_; + //- Operation to apply to values + operationType operation_; + //- Field value source object 1 autoPtr source1Ptr_; @@ -115,6 +131,10 @@ private: template void processFields(bool& found); + //- Templated function to apply the operation + template + Type applyOperation(const Type& value1, const Type& value2) const; + protected: diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C index 7f5eda5b74..6b757fc2df 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C @@ -28,6 +28,57 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +Type Foam::fieldValues::fieldValueDelta::applyOperation +( + const Type& value1, + const Type& value2 +) const +{ + Type result = pTraits::zero; + + switch (operation_) + { + case opAdd: + { + result = value1 + value2; + break; + } + case opSubtract: + { + result = value1 - value2; + break; + } + case opMin: + { + result = min(value1, value2); + break; + } + case opMax: + { + result = max(value1, value2); + break; + } + default: + { + FatalErrorIn + ( + "Type Foam::fieldValues::fieldValueDelta::applyOperation" + "(" + "const Type&, " + "const Type&" + ") const" + ) + << "Unable to process operation " + << operationTypeNames_[operation_] + << abort(FatalError); + } + } + + return result; +} + + template void Foam::fieldValues::fieldValueDelta::processFields(bool& found) { @@ -49,15 +100,18 @@ void Foam::fieldValues::fieldValueDelta::processFields(bool& found) results1.lookup(fieldName) >> r1; results2.lookup(fieldName) >> r2; + Type result = applyOperation(r1, r2); + if (log_) { - Info<< " field: " << fieldName << ", delta: " << r2 - r1 + Info<< " " << operationTypeNames_[operation_] + << "(" << fieldName << ") = " << result << endl; } if (Pstream::master()) { - file()<< tab << r2 - r1; + file()<< tab << result; } found = true;