diff --git a/applications/utilities/postProcessing/postProcess/postProcess.C b/applications/utilities/postProcessing/postProcess/postProcess.C index 8a01c21eb4..884fe1d398 100644 --- a/applications/utilities/postProcessing/postProcess/postProcess.C +++ b/applications/utilities/postProcessing/postProcess/postProcess.C @@ -39,6 +39,7 @@ Description #include "surfaceFields.H" #include "pointFields.H" #include "uniformDimensionedFields.H" +#include "fileFieldSelection.H" using namespace Foam; @@ -153,14 +154,14 @@ int main(int argc, char *argv[]) #include "createNamedMesh.H" // Initialize the set of selected fields from the command-line options - HashSet selectedFields; + functionObjects::fileFieldSelection fields(mesh); if (args.optionFound("fields")) { - args.optionLookup("fields")() >> selectedFields; + args.optionLookup("fields")() >> fields; } if (args.optionFound("field")) { - selectedFields.insert(args.optionLookup("field")()); + fields.insert(args.optionLookup("field")()); } // Externally stored dictionary for functionObjectList @@ -170,7 +171,13 @@ int main(int argc, char *argv[]) // Construct functionObjectList autoPtr functionsPtr ( - functionObjectList::New(args, runTime, functionsDict, selectedFields) + functionObjectList::New + ( + args, + runTime, + functionsDict, + fields.selection() + ) ); forAll(timeDirs, timei) @@ -179,6 +186,8 @@ int main(int argc, char *argv[]) Info<< "Time = " << runTime.timeName() << endl; + fields.updateSelection(); + if (mesh.readUpdate() != polyMesh::UNCHANGED) { // Update functionObjectList if mesh changes @@ -187,7 +196,7 @@ int main(int argc, char *argv[]) args, runTime, functionsDict, - selectedFields + fields.selection() ); } @@ -200,7 +209,7 @@ int main(int argc, char *argv[]) args, runTime, mesh, - selectedFields, + fields.selection(), functionsPtr(), timei == timeDirs.size()-1 ); diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C index 3c71b2713d..60a2a8b764 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C @@ -150,7 +150,8 @@ Foam::functionObjects::writeFile::writeFile fileName_("undefined"), filePtr_(), writePrecision_(IOstream::defaultPrecision()), - writeToFile_(true) + writeToFile_(true), + writtenHeader_(false) {} @@ -167,7 +168,8 @@ Foam::functionObjects::writeFile::writeFile fileName_(fileName), filePtr_(), writePrecision_(IOstream::defaultPrecision()), - writeToFile_(true) + writeToFile_(true), + writtenHeader_(false) { read(dict); @@ -234,8 +236,13 @@ void Foam::functionObjects::writeFile::writeCommented const string& str ) const { - os << setw(1) << "#" << setw(1) << ' ' - << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str(); + os << setw(1) << "#"; + + if (str.size()) + { + os << setw(1) << ' ' + << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str(); + } } @@ -255,8 +262,8 @@ void Foam::functionObjects::writeFile::writeHeader const string& str ) const { - os << setw(1) << "#" << setw(1) << ' ' - << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl; + writeCommented(os, str); + os << nl; } @@ -267,4 +274,10 @@ void Foam::functionObjects::writeFile::writeTime(Ostream& os) const } +void Foam::functionObjects::writeFile::writeBreak(Ostream& os) const +{ + writeHeader(os, "==="); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H index 1f7f1edfce..918d86a133 100644 --- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H +++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.H @@ -79,6 +79,9 @@ protected: //- Flag to enable/disable writing to file bool writeToFile_; + //- Flag to identify whether the header has been written + bool writtenHeader_; + // Protected Member Functions @@ -171,6 +174,9 @@ public: //- Write the current time to stream virtual void writeTime(Ostream& os) const; + //- Write a break marker to the stream + virtual void writeBreak(Ostream& os) const; + //- Write a (commented) header property and value pair template void writeHeaderValue diff --git a/src/OpenFOAM/include/addFunctionObjectOptions.H b/src/OpenFOAM/include/addFunctionObjectOptions.H index 7747c16d4f..35f8503e7d 100644 --- a/src/OpenFOAM/include/addFunctionObjectOptions.H +++ b/src/OpenFOAM/include/addFunctionObjectOptions.H @@ -9,8 +9,7 @@ Foam::argList::addOption ( "fields", "list", - "Specify a list of fields to be processed, e.g. '(U T p)' - " - "regular expressions not currently supported" + "Specify a list of fields to be processed, e.g. '(U T p)'" ); Foam::argList::addOption ( diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index abdef09778..db88df52ae 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -93,6 +93,10 @@ $(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C functionObjects/volRegion/volRegion.C +functionObjects/fieldSelection/fieldSelection.C +functionObjects/fieldSelection/fileFieldSelection.C +functionObjects/fieldSelection/volFieldSelection.C +functionObjects/fieldSelection/solverFieldSelection.C fvPatchFields = fields/fvPatchFields $(fvPatchFields)/fvPatchField/fvPatchFields.C diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C new file mode 100644 index 0000000000..b8f9ad29ba --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.C @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "fieldSelection.H" +#include "objectRegistry.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::fieldSelection::fieldSelection +( + const objectRegistry& obr +) +: + HashSet(), + obr_(obr), + selection_() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::fieldSelection::~fieldSelection() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::fieldSelection::read(const dictionary& dict) +{ + dict.lookup("fields") >> *this; + + return true; +} + + +bool Foam::functionObjects::fieldSelection::containsPattern() const +{ + for (const wordRe& fieldName : *this) + { + if (fieldName.isPattern()) + { + return true; + } + } + + return false; +} + + +void Foam::functionObjects::fieldSelection::clearSelection() +{ + selection_.clear(); +} + + +bool Foam::functionObjects::fieldSelection::updateSelection() +{ + return false; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H new file mode 100644 index 0000000000..9d874f8322 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelection.H @@ -0,0 +1,139 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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::functionObjects::fieldSelection + +Description + Helper class to manage field selections + +SourceFiles + fieldSelection.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_fieldSelection_H +#define functionObjects_fieldSelection_H + +#include "HashSet.H" +#include "wordRe.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class dictionary; +class objectRegistry; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class fieldSelection Declaration +\*---------------------------------------------------------------------------*/ + +class fieldSelection +: + public HashSet +{ +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + fieldSelection(const fieldSelection&) = delete; + + +protected: + + // Protected member data + + //- Reference to the database + const objectRegistry& obr_; + + //- Current field selection + wordHashSet selection_; + + + // Protected Member Functions + + //- Add registered objects of a given type + template + void addRegistered(wordHashSet& set) const; + + +public: + + //- Construct from object registry + fieldSelection(const objectRegistry& obr); + + + //- Destructor + virtual ~fieldSelection(); + + + // Member Functions + + //- Return the current field selection + const wordHashSet& selection() const + { + return selection_; + } + + //- Return the current field selection + wordHashSet& selection() + { + return selection_; + } + + //- Read the fieldSelection data from dictionary + virtual bool read(const dictionary& dict); + + //- Return whether the field names contain a pattern + virtual bool containsPattern() const; + + //- Clear the current selection + virtual void clearSelection(); + + //- Update the selection using current contents of obr_ + virtual bool updateSelection(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fieldSelectionTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C new file mode 100644 index 0000000000..80c476a44e --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fieldSelectionTemplates.C @@ -0,0 +1,47 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "DynamicList.H" +#include "objectRegistry.H" + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +template +void Foam::functionObjects::fieldSelection::addRegistered +( + wordHashSet& set +) const +{ + DynamicList names; + for (const wordRe& name : *this) + { + names.append(obr_.names(name)); + } + + set.insert(names); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C new file mode 100644 index 0000000000..9d55a55393 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.C @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "fileFieldSelection.H" +#include "objectRegistry.H" +#include "volMesh.H" +#include "fvPatchField.H" +#include "surfaceMesh.H" +#include "fvsPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::fileFieldSelection::fileFieldSelection +( + const objectRegistry& obr +) +: + fieldSelection(obr) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::fileFieldSelection::~fileFieldSelection() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::fileFieldSelection::updateSelection() +{ + wordHashSet oldSet; + oldSet.swap(selection_); + + addFileGeoFields(selection_); + addFileGeoFields(selection_); + + return selection_ != oldSet; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H new file mode 100644 index 0000000000..d1d3a986c7 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelection.H @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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::functionObjects::fileFieldSelection + +Description + Helper class to manage file-based field selections + +SourceFiles + fieldSelection.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_fileFieldSelection_H +#define functionObjects_fileFieldSelection_H + +#include "fieldSelection.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class IOobjectList; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class fileFieldSelection Declaration +\*---------------------------------------------------------------------------*/ + +class fileFieldSelection +: + public fieldSelection +{ +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + fileFieldSelection(const fileFieldSelection&) = delete; + + +protected: + + // Protected Member Functions + + //- Add registered GeometricField types to selection + template class PatchType, class MeshType> + void addFileGeoFields(wordHashSet& set) const; + + //- Add objects of a given type + template + void addFromFile + ( + const IOobjectList& allFileObjects, + wordHashSet& set + ) const; + + +public: + + //- Construct from object registry + fileFieldSelection(const objectRegistry& obr); + + + //- Destructor + virtual ~fileFieldSelection(); + + + // Member Functions + + //- Update the selection + virtual bool updateSelection(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "fileFieldSelectionTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C new file mode 100644 index 0000000000..f915d04997 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/fileFieldSelectionTemplates.C @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "IOobjectList.H" +#include "GeometricField.H" +#include "fvMesh.H" +#include "DynamicList.H" + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +template +void Foam::functionObjects::fileFieldSelection::addFromFile +( + const IOobjectList& allFileObjects, + wordHashSet& set +) const +{ + DynamicList names; + + for (const wordRe& fieldName : *this) + { + names.append(allFileObjects.names(Type::typeName, fieldName)); + } + + set.insert(names); +} + + +template class PatchType, class MeshType> +void Foam::functionObjects::fileFieldSelection::addFileGeoFields +( + wordHashSet& set +) const +{ + const fvMesh& mesh = static_cast(obr_); + + const IOobjectList allObjects(mesh, mesh.time().timeName()); + + addFromFile>(allObjects, set); + addFromFile>(allObjects, set); + addFromFile> + ( + allObjects, + set + ); + addFromFile> + ( + allObjects, + set + ); + addFromFile>(allObjects, set); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C new file mode 100644 index 0000000000..d7508642d2 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.C @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "solverFieldSelection.H" +#include "fvMesh.H" +#include "volMesh.H" +#include "fvPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::solverFieldSelection::solverFieldSelection +( + const objectRegistry& obr +) +: + volFieldSelection(obr) +{ + if (!isA(obr)) + { + FatalErrorInFunction + << "Registry must be of type " << fvMesh::typeName + << abort(FatalError); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::solverFieldSelection::~solverFieldSelection() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::solverFieldSelection::updateSelection() +{ + wordHashSet oldSet; + oldSet.swap(selection_); + + wordHashSet volFields; + addRegisteredGeoFields(volFields); + + const fvMesh& mesh = static_cast(obr_); + + const Foam::dictionary& solverDict = mesh.solverPerformanceDict(); + + for (const word& fieldName : volFields) + { + if (solverDict.found(fieldName)) + { + selection_.insert(fieldName); + } + } + + return selection_ != oldSet; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H new file mode 100644 index 0000000000..55d860a199 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/solverFieldSelection.H @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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::functionObjects::volFieldSelection + +Description + Helper class to manage volume field selections + +SourceFiles + volFieldSelection.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_solverFieldSelection_H +#define functionObjects_solverFieldSelection_H + +#include "volFieldSelection.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class solverFieldSelection Declaration +\*---------------------------------------------------------------------------*/ + +class solverFieldSelection +: + public volFieldSelection +{ +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + solverFieldSelection(const solverFieldSelection&) = delete; + + +public: + + //- Construct from object registry + solverFieldSelection(const objectRegistry& obr); + + + //- Destructor + virtual ~solverFieldSelection(); + + + // Member Functions + + //- Update the selection using current contents of obr_ + virtual bool updateSelection(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C new file mode 100644 index 0000000000..b0b61eb524 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.C @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "volFieldSelection.H" +#include "volMesh.H" +#include "fvPatchField.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::volFieldSelection::volFieldSelection +( + const objectRegistry& obr +) +: + fieldSelection(obr) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::volFieldSelection::~volFieldSelection() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::functionObjects::volFieldSelection::updateSelection() +{ + wordHashSet oldSet; + + oldSet.swap(selection_); + + addRegisteredGeoFields(selection_); + + return selection_ != oldSet; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H new file mode 100644 index 0000000000..cad0440bd7 --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelection.H @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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::functionObjects::volFieldSelection + +Description + Helper class to manage volume field selections + +SourceFiles + volFieldSelection.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_volFieldSelection_H +#define functionObjects_volFieldSelection_H + +#include "fieldSelection.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class volFieldSelection Declaration +\*---------------------------------------------------------------------------*/ + +class volFieldSelection +: + public fieldSelection +{ +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + volFieldSelection(const volFieldSelection&) = delete; + + +protected: + + // Protected Member Functions + + //- Add registered GeometricField types to selection + template class PatchType, class MeshType> + void addRegisteredGeoFields(wordHashSet& set) const; + + +public: + + //- Construct from object registry + volFieldSelection(const objectRegistry& obr); + + + //- Destructor + virtual ~volFieldSelection(); + + + // Member Functions + + //- Update the selection using current contents of obr_ + virtual bool updateSelection(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "volFieldSelectionTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C new file mode 100644 index 0000000000..f1e0ea195f --- /dev/null +++ b/src/finiteVolume/functionObjects/fieldSelection/volFieldSelectionTemplates.C @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "volFields.H" + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +template class PatchType, class MeshType> +void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields +( + wordHashSet& set +) const +{ + addRegistered>(set); + addRegistered>(set); + addRegistered>(set); + addRegistered>(set); + addRegistered>(set); +} + + +// ************************************************************************* // diff --git a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C index 296fb0d081..2c4ea97f34 100644 --- a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C +++ b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,7 +55,7 @@ fieldCoordinateSystemTransform ) : fvMeshFunctionObject(name, runTime, dict), - fieldSet_(), + fieldSet_(mesh_), coordSys_(mesh_, dict.subDict("coordinateSystem")) { read(dict); @@ -90,23 +90,27 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::read const dictionary& dict ) { - fvMeshFunctionObject::read(dict); + if (fvMeshFunctionObject::read(dict)) + { + fieldSet_.read(dict); + return true; + } - dict.lookup("fields") >> fieldSet_; - - return true; + return false; } bool Foam::functionObjects::fieldCoordinateSystemTransform::execute() { - forAll(fieldSet_, fieldi) + fieldSet_.updateSelection(); + + for (const word& fieldName : fieldSet_.selection()) { - transform(fieldSet_[fieldi]); - transform(fieldSet_[fieldi]); - transform(fieldSet_[fieldi]); - transform(fieldSet_[fieldi]); - transform(fieldSet_[fieldi]); + transform(fieldName); + transform(fieldName); + transform(fieldName); + transform(fieldName); + transform(fieldName); } return true; @@ -115,9 +119,9 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute() bool Foam::functionObjects::fieldCoordinateSystemTransform::write() { - forAll(fieldSet_, fieldi) + forAllConstIters(fieldSet_, iter) { - writeObject(transformFieldName(fieldSet_[fieldi])); + writeObject(transformFieldName(iter())); } return true; diff --git a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H index f588d4f734..dbc0446cb7 100644 --- a/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H +++ b/src/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H @@ -83,6 +83,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "coordinateSystem.H" +#include "volFieldSelection.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -104,7 +105,7 @@ protected: // Protected data //- Fields to transform - wordList fieldSet_; + volFieldSelection fieldSet_; //- Co-ordinate system to transform to coordinateSystem coordSys_; diff --git a/src/functionObjects/field/fieldMinMax/fieldMinMax.C b/src/functionObjects/field/fieldMinMax/fieldMinMax.C index 35d68b92f0..5d3e3f0bfd 100644 --- a/src/functionObjects/field/fieldMinMax/fieldMinMax.C +++ b/src/functionObjects/field/fieldMinMax/fieldMinMax.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,9 +51,22 @@ Foam::functionObjects::fieldMinMax::modeTypeNames_ // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // -void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os) const +void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os) { - writeHeader(os, "Field minima and maxima"); + if (!fieldSet_.updateSelection()) + { + return; + } + + if (writtenHeader_) + { + writeBreak(file()); + } + else + { + writeHeader(os, "Field minima and maxima"); + } + writeCommented(os, "Time"); if (location_) @@ -77,14 +90,17 @@ void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os) const } else { - forAll(fieldSet_, fieldi) + forAllConstIters(fieldSet_.selection(), iter) { - writeTabbed(os, "min(" + fieldSet_[fieldi] + ')'); - writeTabbed(os, "max(" + fieldSet_[fieldi] + ')'); + const word& fieldName = iter(); + writeTabbed(os, "min(" + fieldName + ')'); + writeTabbed(os, "max(" + fieldName + ')'); } } os << endl; + + writtenHeader_ = true; } @@ -101,10 +117,9 @@ Foam::functionObjects::fieldMinMax::fieldMinMax writeFile(mesh_, name, typeName, dict), location_(true), mode_(mdMag), - fieldSet_() + fieldSet_(mesh_) { read(dict); - writeFileHeader(file()); } @@ -124,7 +139,8 @@ bool Foam::functionObjects::fieldMinMax::read(const dictionary& dict) location_ = dict.lookupOrDefault("location", true); mode_ = modeTypeNames_.lookupOrDefault("mode", dict, modeType::mdMag); - dict.lookup("fields") >> fieldSet_; + + fieldSet_.read(dict); return true; } @@ -138,16 +154,18 @@ bool Foam::functionObjects::fieldMinMax::execute() bool Foam::functionObjects::fieldMinMax::write() { + writeFileHeader(file()); + if (!location_) writeTime(file()); Log << type() << " " << name() << " write:" << nl; - forAll(fieldSet_, fieldi) + for (const word& fieldName : fieldSet_.selection()) { - calcMinMaxFields(fieldSet_[fieldi], mdCmpt); - calcMinMaxFields(fieldSet_[fieldi], mode_); - calcMinMaxFields(fieldSet_[fieldi], mode_); - calcMinMaxFields(fieldSet_[fieldi], mode_); - calcMinMaxFields(fieldSet_[fieldi], mode_); + calcMinMaxFields(fieldName, mdCmpt); + calcMinMaxFields(fieldName, mode_); + calcMinMaxFields(fieldName, mode_); + calcMinMaxFields(fieldName, mode_); + calcMinMaxFields(fieldName, mode_); } if (!location_) file()<< endl; diff --git a/src/functionObjects/field/fieldMinMax/fieldMinMax.H b/src/functionObjects/field/fieldMinMax/fieldMinMax.H index 588dc5c7fd..9f7cd954a8 100644 --- a/src/functionObjects/field/fieldMinMax/fieldMinMax.H +++ b/src/functionObjects/field/fieldMinMax/fieldMinMax.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,6 +82,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "writeFile.H" #include "vector.H" +#include "volFieldSelection.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -124,7 +125,7 @@ protected: modeType mode_; //- Fields to assess min/max - wordList fieldSet_; + volFieldSelection fieldSet_; // Protected Member Functions @@ -147,7 +148,7 @@ protected: //- Output file header information - virtual void writeFileHeader(Ostream& os) const; + virtual void writeFileHeader(Ostream& os); //- Disallow default bitwise copy construct fieldMinMax(const fieldMinMax&) = delete; diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.H b/src/functionObjects/field/nearWallFields/nearWallFields.H index 9a2850c20a..85c67d9b2d 100644 --- a/src/functionObjects/field/nearWallFields/nearWallFields.H +++ b/src/functionObjects/field/nearWallFields/nearWallFields.H @@ -107,7 +107,7 @@ protected: // Read from dictionary - //- Fields to process + //- Fields to process (input-name output-name) List> fieldSet_; //- Switch to send output to Info as well as to file diff --git a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C index 8ae33b507f..bf8a4a3856 100644 --- a/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C +++ b/src/functionObjects/field/regionSizeDistribution/regionSizeDistribution.C @@ -860,7 +860,7 @@ bool Foam::functionObjects::regionSizeDistribution::write() forAll(selected, i) { const word& fldName = scalarNames[selected[i]]; - Log << " Scalar field " << fldName << endl; + Log << " Scalar field " << fldName << endl; const scalarField& fld = obr_.lookupObject < diff --git a/src/functionObjects/utilities/residuals/residuals.C b/src/functionObjects/utilities/residuals/residuals.C index a9f41a02b1..0cdf2c6d97 100644 --- a/src/functionObjects/utilities/residuals/residuals.C +++ b/src/functionObjects/utilities/residuals/residuals.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,15 +46,26 @@ namespace functionObjects // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // -void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) const +void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) { - writeHeader(os, "Residuals"); + if (!fieldSet_.updateSelection()) + { + return; + } + + if (writtenHeader_) + { + writeBreak(file()); + } + else + { + writeHeader(os, "Residuals"); + } + writeCommented(os, "Time"); - forAll(fieldSet_, fieldi) + for (const word& fieldName : fieldSet_.selection()) { - const word& fieldName = fieldSet_[fieldi]; - writeFileHeader(os, fieldName); writeFileHeader(os, fieldName); writeFileHeader(os, fieldName); @@ -63,6 +74,8 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) const } os << endl; + + writtenHeader_ = true; } @@ -77,10 +90,9 @@ Foam::functionObjects::residuals::residuals : fvMeshFunctionObject(name, runTime, dict), writeFile(obr_, name, typeName, dict), - fieldSet_() + fieldSet_(mesh_) { read(dict); - writeFileHeader(file()); } @@ -94,13 +106,13 @@ Foam::functionObjects::residuals::~residuals() bool Foam::functionObjects::residuals::read(const dictionary& dict) { - fvMeshFunctionObject::read(dict); + if (fvMeshFunctionObject::read(dict)) + { + fieldSet_.read(dict); + return true; + } - wordList allFields(dict.lookup("fields")); - wordHashSet uniqueFields(allFields); - fieldSet_ = uniqueFields.toc(); - - return true; + return false; } @@ -114,12 +126,12 @@ bool Foam::functionObjects::residuals::write() { if (Pstream::master()) { + writeFileHeader(file()); + writeTime(file()); - forAll(fieldSet_, fieldi) + for (const word& fieldName : fieldSet_.selection()) { - const word& fieldName = fieldSet_[fieldi]; - writeResidual(fieldName); writeResidual(fieldName); writeResidual(fieldName); diff --git a/src/functionObjects/utilities/residuals/residuals.H b/src/functionObjects/utilities/residuals/residuals.H index 283e4738da..02e2db2843 100644 --- a/src/functionObjects/utilities/residuals/residuals.H +++ b/src/functionObjects/utilities/residuals/residuals.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,6 +62,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "writeFile.H" +#include "solverFieldSelection.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -84,13 +85,13 @@ protected: // Protected data //- Fields to write residuals - wordList fieldSet_; + solverFieldSelection fieldSet_; // Protected Member Functions //- Output file header information - void writeFileHeader(Ostream& os) const; + void writeFileHeader(Ostream& os); //- Output file header information per primitive type value template