diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C index 19fb67d4e3..ffad0cc4e6 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C @@ -168,7 +168,7 @@ Foam::functionObjectFile::functionObjectFile names_.insert(name); filePtrs_.clear(); - filePtrs_.setSize(names_.toc().size()); + filePtrs_.setSize(1); // cannot create files - need to access virtual function } @@ -193,7 +193,7 @@ Foam::functionObjectFile::functionObjectFile names_.insert(names); filePtrs_.clear(); - filePtrs_.setSize(names_.toc().size()); + filePtrs_.setSize(names_.size()); // cannot create files - need to access virtual function } diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H index 8710b92b7a..f4c0ab1178 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.H @@ -64,7 +64,7 @@ private: const objectRegistry& obr_; //- Prefix - const word& prefix_; + const word prefix_; //- File names wordHashSet names_; diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C index e1d2a1f11e..9d111be380 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C @@ -39,7 +39,7 @@ Foam::MRFZoneList::MRFZoneList { reset(dict); - active(); + active(true); } @@ -51,7 +51,7 @@ Foam::MRFZoneList::~MRFZoneList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::MRFZoneList::active() const +bool Foam::MRFZoneList::active(const bool warn) const { bool a = false; forAll(*this, i) @@ -59,7 +59,7 @@ bool Foam::MRFZoneList::active() const a = a || this->operator[](i).active(); } - if (!a) + if (warn && this->size() && !a) { Info<< " No MRF zones active" << endl; } diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H index e956f6e0e0..a2311c52c8 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.H @@ -88,7 +88,7 @@ public: // Member Functions //- Return active status - bool active() const; + bool active(const bool warn = false) const; //- Reset the source list void reset(const dictionary& dict); diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.C b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.C index 9cccc1f7f4..df3028547c 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.C @@ -38,6 +38,8 @@ Foam::porosityModelList::porosityModelList mesh_(mesh) { reset(dict); + + active(true); } @@ -49,7 +51,7 @@ Foam::porosityModelList::~porosityModelList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::porosityModelList::active() const +bool Foam::porosityModelList::active(const bool warn) const { bool a = false; forAll(*this, i) @@ -57,7 +59,7 @@ bool Foam::porosityModelList::active() const a = a || this->operator[](i).active(); } - if (!a) + if (warn && this->size() && !a) { Info<< "No porosity models active" << endl; } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.H b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.H index e580a2d0fa..3d0d015923 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelList.H @@ -88,7 +88,7 @@ public: // Member Functions //- Return active status - bool active() const; + bool active(const bool active = false) const; //- Reset the source list void reset(const dictionary& dict); diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index 0abf314f96..cba907676a 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -10,6 +10,9 @@ fieldMinMax/fieldMinMax.C fieldMinMax/fieldMinMaxFunctionObject.C fieldValues/fieldValue/fieldValue.C +fieldValues/fieldValue/fieldValueNew.C +fieldValues/fieldValueDelta/fieldValueDelta.C +fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.C fieldValues/faceSource/faceSource.C fieldValues/faceSource/faceSourceFunctionObject.C fieldValues/cellSource/cellSource.C diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C index 488f690ca4..799273b4ff 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C @@ -26,20 +26,14 @@ License #include "cellSource.H" #include "fvMesh.H" #include "volFields.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(Foam::fieldValues::cellSource, 0); - namespace Foam { - template<> - const char* Foam::NamedEnum - < - Foam::fieldValues::cellSource::sourceType, - 2 - >::names[] = + const char* NamedEnum::names[] = { "cellZone", "all" @@ -47,11 +41,7 @@ namespace Foam template<> - const char* Foam::NamedEnum - < - Foam::fieldValues::cellSource::operationType, - 9 - >::names[] = + const char* NamedEnum::names[] = { "none", "sum", @@ -63,6 +53,12 @@ namespace Foam "max", "CoV" }; + + namespace fieldValues + { + defineTypeNameAndDebug(cellSource, 0); + addToRunTimeSelectionTable(fieldValue, cellSource, dictionary); + } } diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C index ab59cf13b8..bdeccc6dd0 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSourceTemplates.C @@ -177,6 +177,9 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName) { Type result = processValues(values, V, weightField); + // add to result dictionary, over-writing any previous entry + resultDict_.add(fieldName, result, true); + if (valueOutput_) { IOField diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index d9f822dde5..14a6fa310e 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -32,19 +32,14 @@ License #include "mergePoints.H" #include "indirectPrimitivePatch.H" #include "PatchTools.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0); - namespace Foam { template<> - const char* Foam::NamedEnum - < - Foam::fieldValues::faceSource::sourceType, - 3 - >::names[] = + const char* NamedEnum::names[] = { "faceZone", "patch", @@ -53,11 +48,7 @@ namespace Foam template<> - const char* Foam::NamedEnum - < - Foam::fieldValues::faceSource::operationType, - 11 - >::names[] = + const char* NamedEnum::names[] = { "none", "sum", @@ -72,6 +63,11 @@ namespace Foam "areaNormalIntegrate" }; + namespace fieldValues + { + defineTypeNameAndDebug(faceSource, 0); + addToRunTimeSelectionTable(fieldValue, faceSource, dictionary); + } } diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index 4092bf4400..a82f489036 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -291,6 +291,9 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) { Type result = processValues(values, Sf, weightField); + // add to result dictionary, over-writing any previous entry + resultDict_.add(fieldName, result, true); + file()<< tab << result; if (log_) diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C index cc2aeb0423..dc37c6909d 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C @@ -26,12 +26,14 @@ License #include "fieldValue.H" #include "fvMesh.H" #include "Time.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(fieldValue, 0); + defineRunTimeSelectionTable(fieldValue, dictionary); } @@ -92,7 +94,8 @@ Foam::fieldValue::fieldValue log_(false), sourceName_(dict.lookupOrDefault("sourceName", "sampledSurface")), fields_(dict.lookup("fields")), - valueOutput_(dict.lookup("valueOutput")) + valueOutput_(dict.lookup("valueOutput")), + resultDict_(fileName("name"), dictionary::null) { // Only active if obr is an fvMesh if (isA(obr_)) diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H index 8e52e3ee45..1d6befa9ce 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H @@ -42,6 +42,8 @@ SourceFiles #include "Switch.H" #include "pointFieldFwd.H" #include "OFstream.H" +#include "dictionary.H" +#include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -49,7 +51,6 @@ namespace Foam { // Forward declaration of classes -class dictionary; class objectRegistry; class fvMesh; class mapPolyMesh; @@ -88,6 +89,9 @@ protected: //- Output field values flag Switch valueOutput_; + //- Results dictionary for external access of results + dictionary resultDict_; + // Functions to be over-ridden from IOoutputFilter class @@ -103,6 +107,21 @@ public: //- Run-time type information TypeName("fieldValue"); + // Declare runtime constructor selection table + + declareRunTimeSelectionTable + ( + autoPtr, + fieldValue, + dictionary, + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles + ), + (name, obr, dict, loadFromFiles) + ); //- Construct from components fieldValue @@ -114,6 +133,15 @@ public: const bool loadFromFiles = false ); + //- Return a reference to the selected fieldValue + static autoPtr New + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles = false, + const bool output = true + ); //- Destructor virtual ~fieldValue(); @@ -147,6 +175,9 @@ public: //- Helper function to return the reference to the mesh inline const fvMesh& mesh() const; + //- Return access to the latest set of results + inline const dictionary& resultDict() const; + // Function object functions diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H index c29a7b918a..aaee816af2 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,6 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "fieldValue.H" +#include "fvMesh.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -75,4 +76,10 @@ inline const Foam::fvMesh& Foam::fieldValue::mesh() const } +inline const Foam::dictionary& Foam::fieldValue::resultDict() const +{ + return resultDict_; +} + + // ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueNew.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueNew.C new file mode 100644 index 0000000000..f418ad0215 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueNew.C @@ -0,0 +1,80 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "fieldValue.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::autoPtr Foam::fieldValue::New +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles, + const bool output +) +{ + const word modelType(dict.lookup("type")); + + if (output) + { + Info<< "Selecting " << typeName << " " << modelType << endl; + } + + dictionaryConstructorTable::iterator cstrIter = + dictionaryConstructorTablePtr_->find(modelType); + + if (cstrIter == dictionaryConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "fieldValue::New" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "Unknown " << typeName << " type " + << modelType << nl << nl + << "Valid " << typeName << " types are:" << nl + << dictionaryConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr + ( + cstrIter() + ( + name, + obr, + dict, + loadFromFiles + ) + ); +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/IOfieldValueDelta.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/IOfieldValueDelta.H new file mode 100644 index 0000000000..7c316e926e --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/IOfieldValueDelta.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::IOfieldValueDelta + + +Description + Instance of the generic IOOutputFilter for fieldValueDelta. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOfieldValueDelta_H +#define IOfieldValueDelta_H + +#include "fieldValueDelta.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOfieldValueDelta; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C new file mode 100644 index 0000000000..ebcaaf2430 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.C @@ -0,0 +1,213 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "fieldValueDelta.H" +#include "ListOps.H" +#include "Time.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +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 * * * * * * * * * * * // + +void Foam::fieldValues::fieldValueDelta::updateMesh(const mapPolyMesh&) +{ + // Do nothing +} + + +void Foam::fieldValues::fieldValueDelta::movePoints(const Field&) +{ + // Do nothing +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fieldValues::fieldValueDelta::fieldValueDelta +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + functionObjectFile(obr, name, typeName), + name_(name), + obr_(obr), + loadFromFiles_(loadFromFiles), + log_(false), + operation_(opSubtract), + source1Ptr_(NULL), + source2Ptr_(NULL) +{ + read(dict); +} + + +void Foam::fieldValues::fieldValueDelta::writeFileHeader(const label i) +{ + const wordList& fields1 = source1Ptr_->fields(); + const wordList& fields2 = source2Ptr_->fields(); + + DynamicList commonFields(fields1.size()); + forAll(fields1, i) + { + label index = findIndex(fields2, fields1[i]); + if (index != -1) + { + commonFields.append(fields1[i]); + } + } + + Ostream& os = file(); + + os << "# Source1 : " << source1Ptr_->name() << nl + << "# Source2 : " << source2Ptr_->name() << nl + << "# Operation : " << operationTypeNames_[operation_] << nl; + + os << "# Time"; + + forAll(commonFields, i) + { + os << tab << commonFields[i]; + } + + os << endl; +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::fieldValues::fieldValueDelta::~fieldValueDelta() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fieldValues::fieldValueDelta::read(const dictionary& dict) +{ + log_ = dict.lookupOrDefault("log", false); + source1Ptr_.reset + ( + fieldValue::New + ( + name_ + ".source1", + obr_, + dict.subDict("source1"), + loadFromFiles_, + false + ).ptr() + ); + source2Ptr_.reset + ( + fieldValue::New + ( + name_ + ".source2", + obr_, + dict.subDict("source2"), + loadFromFiles_, + false + ).ptr() + ); + + operation_ = operationTypeNames_.read(dict.lookup("operation")); +} + + +void Foam::fieldValues::fieldValueDelta::write() +{ + functionObjectFile::write(); + + source1Ptr_->write(); + source2Ptr_->write(); + + if (Pstream::master()) + { + file()<< obr_.time().timeName(); + } + + if (log_) + { + Info<< type() << " output:" << endl; + } + + bool found = false; + processFields(found); + processFields(found); + processFields(found); + processFields(found); + processFields(found); + + if (Pstream::master()) + { + file()<< endl; + } + + if (log_) + { + if (!found) + { + Info<< " none" << endl; + } + else + { + Info<< endl; + } + } +} + + +void Foam::fieldValues::fieldValueDelta::execute() +{ + // Do nothing +} + + +void Foam::fieldValues::fieldValueDelta::end() +{ + // Do nothing +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H new file mode 100644 index 0000000000..916fa6d3b0 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDelta.H @@ -0,0 +1,206 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::fieldValues::fieldValueDelta + +Group + grpFieldFunctionObjects + +Description + This function object provides a differencing option between two 'field + value' function objects. + + Example of function object specification: + \verbatim + fieldValueDelta1 + { + type fieldValueDelta; + functionObjectLibs ("libfieldFunctionObjects.so"); + fieldValue1 + { + ... + } + fieldValue2 + { + ... + } + } + \endverbatim + + \heading Function object usage + \table + Property | Description | Required | Default value + type | type name: fieldValueDelta | yes | + \endtable + +SeeAlso + Foam::fieldValue + +SourceFiles + fieldValueDelta.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fieldValueDelta_H +#define fieldValueDelta_H + +#include "functionObjectFile.H" +#include "fieldValue.H" +#include "autoPtr.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +namespace fieldValues +{ + +/*---------------------------------------------------------------------------*\ + Class fieldValueDelta Declaration +\*---------------------------------------------------------------------------*/ + +class fieldValueDelta +: + public functionObjectFile +{ +public: + //- Operation type enumeration + enum operationType + { + opAdd, + opSubtract, + opMin, + opMax + }; + + //- Operation type names + static const NamedEnum operationTypeNames_; + + +private: + + // Private data + + //- Name of this fieldValue object + word name_; + + //- Database this class is registered to + const objectRegistry& obr_; + + //- Flag to indicate to load from files + bool loadFromFiles_; + + //- 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_; + + //- Field value source object 2 + autoPtr source2Ptr_; + + + // Private Member Functions + + //- Templated function to process common fields + template + void processFields(bool& found); + + //- Templated function to apply the operation + template + Type applyOperation(const Type& value1, const Type& value2) const; + + +protected: + + // Functions to be over-ridden from IOoutputFilter class + + //- Update mesh + virtual void updateMesh(const mapPolyMesh&); + + //- Move points + virtual void movePoints(const Field&); + + //- Output file header information + virtual void writeFileHeader(const label i); + + +public: + + //- Run-time type information + TypeName("fieldValueDelta"); + + + //- Construct from components + fieldValueDelta + ( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~fieldValueDelta(); + + + // Public Member Functions + + // Function object functions + + //- Read from dictionary + virtual void read(const dictionary&); + + //- Calculate and write + virtual void write(); + + //- Execute + virtual void execute(); + + //- Execute the at the final time-loop, currently does nothing + virtual void end(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fieldValues +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fieldValueDeltaTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.C new file mode 100644 index 0000000000..7d093c3781 --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.C @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "fieldValueDeltaFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug + ( + fieldValueDeltaFunctionObject, + 0 + ); + + addToRunTimeSelectionTable + ( + functionObject, + fieldValueDeltaFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.H new file mode 100644 index 0000000000..120d5991bc --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaFunctionObject.H @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::fieldValueDeltaFunctionObject + +Description + FunctionObject wrapper around fieldValueDelta to allow it to be + created via the functions entry within controlDict. + +SourceFiles + fieldValueDeltaFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef fieldValueDeltaFunctionObject_H +#define fieldValueDeltaFunctionObject_H + +#include "fieldValueDelta.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject + fieldValueDeltaFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C new file mode 100644 index 0000000000..6b757fc2df --- /dev/null +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValueDelta/fieldValueDeltaTemplates.C @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "GeometricField.H" +#include "volMesh.H" + +// * * * * * * * * * * * * * * * 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) +{ + typedef GeometricField vf; + + const wordList& fields1 = source1Ptr_->fields(); + + const dictionary& results1 = source1Ptr_->resultDict(); + const dictionary& results2 = source2Ptr_->resultDict(); + + Type r1(pTraits::zero); + Type r2(pTraits::zero); + + forAll(fields1, i) + { + const word& fieldName = fields1[i]; + if (obr_.foundObject(fieldName) && results2.found(fieldName)) + { + results1.lookup(fieldName) >> r1; + results2.lookup(fieldName) >> r2; + + Type result = applyOperation(r1, r2); + + if (log_) + { + Info<< " " << operationTypeNames_[operation_] + << "(" << fieldName << ") = " << result + << endl; + } + + if (Pstream::master()) + { + file()<< tab << result; + } + + found = true; + } + } +} + + +// ************************************************************************* //