From 8ddfe86d1d0e69afa5faf841c1a291ef4711ad20 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 9 Dec 2016 21:54:13 +0000 Subject: [PATCH 001/277] functionObjects::writeLocalObjects: Provides support for controlled writing of field defined by functionObjects, e.g. wallHeatFlux, wallShearStress and yPlus. Patch contributed by Bruno Santos Resolves bug-report http://bugs.openfoam.org/view.php?id=2353 --- src/OpenFOAM/Make/files | 2 + .../writeLocalObjects/writeLocalObjects.C | 106 +++++++++++ .../writeLocalObjects/writeLocalObjects.H | 160 +++++++++++++++++ .../writeObjectsBase/writeObjectsBase.C | 147 +++++++++++++++ .../writeObjectsBase/writeObjectsBase.H | 169 ++++++++++++++++++ .../field/wallHeatFlux/wallHeatFlux.C | 19 +- .../field/wallHeatFlux/wallHeatFlux.H | 9 +- .../field/wallShearStress/wallShearStress.C | 14 +- .../field/wallShearStress/wallShearStress.H | 9 +- src/functionObjects/field/yPlus/yPlus.C | 18 +- src/functionObjects/field/yPlus/yPlus.H | 29 ++- .../utilities/writeObjects/writeObjects.C | 154 +++++++--------- .../utilities/writeObjects/writeObjects.H | 18 +- 13 files changed, 731 insertions(+), 123 deletions(-) create mode 100644 src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.C create mode 100644 src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.H create mode 100644 src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C create mode 100644 src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 59d1692ca1..377b958ded 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -228,6 +228,8 @@ db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObjectList/functionObjectList.C db/functionObjects/writeFile/writeFile.C db/functionObjects/logFiles/logFiles.C +db/functionObjects/writeObjectsBase/writeObjectsBase.C +db/functionObjects/writeLocalObjects/writeLocalObjects.C db/functionObjects/timeControl/timeControl.C db/functionObjects/timeControl/timeControlFunctionObject.C db/functionObjects/regionFunctionObject/regionFunctionObject.C diff --git a/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.C b/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.C new file mode 100644 index 0000000000..1b99158468 --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.C @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 "writeLocalObjects.H" +#include "stringListOps.H" +#include "dictionary.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::writeLocalObjects::resetLocalObjectName +( + const word& name +) +{ + localObjectNames_.clear(); + localObjectNames_.append(name); +} + + +void Foam::functionObjects::writeLocalObjects::resetLocalObjectNames +( + const wordList& names +) +{ + localObjectNames_.clear(); + localObjectNames_.append(names); +} + + +Foam::wordList Foam::functionObjects::writeLocalObjects::objectNames() +{ + wordList names + ( + subsetStrings(wordReListMatcher(writeObjectNames_), localObjectNames_) + ); + + return names; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::writeLocalObjects::writeLocalObjects +( + const objectRegistry& obr, + const Switch& log +) +: + writeObjectsBase(obr, log), + localObjectNames_() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::writeLocalObjects::~writeLocalObjects() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const Foam::wordList& +Foam::functionObjects::writeLocalObjects::localObjectNames() const +{ + return localObjectNames_; +} + + +bool Foam::functionObjects::writeLocalObjects::read(const dictionary& dict) +{ + if (dict.found("objects")) + { + writeObjectsBase::read(dict); + } + else + { + resetWriteObjectName(wordRe(".*", wordRe::DETECT)); + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.H b/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.H new file mode 100644 index 0000000000..3cf18453c1 --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/writeLocalObjects/writeLocalObjects.H @@ -0,0 +1,160 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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::functionObjects::writeLocalObjects + +Description + FunctionObject base class for managing a list of objects on behalf of the + inheriting function object, on when those should be written to disk. + + FunctionObjects that inherit this class will receive the additional + dictionary option \c objects which allows selecting which fields of the + inherited function should be written to disk when \c write() is called. + When \c objects is omitted, it will write all objects and when that list is + empty, it will not write any of the inheriting function object's managed + objects. + + Example of function object specification: + \verbatim + + { + ... + objects (obj1 obj2); + ... + } + \endverbatim + +Usage + \table + Property | Description | Required | Default value + objects | List of objects to be written | no | ".*" + \endtable + + Note: Regular expressions can also be used in \c objects. + +See also + Foam::functionObject + Foam::functionObjects::writeObjectsBase + +SourceFiles + writeLocalObjects.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_writeLocalObjects_H +#define functionObjects_writeLocalObjects_H + +#include "wordList.H" +#include "writeObjectsBase.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class regIOobject; +class Switch; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class writeLocalObjects Declaration +\*---------------------------------------------------------------------------*/ + +class writeLocalObjects +: + public writeObjectsBase +{ + +protected: + + // Protected data + + //- Object names that are handled on behalf of the inheritor + wordList localObjectNames_; + + + // Protected Member Functions + + //- Reset the list of local object names from a single word + void resetLocalObjectName(const word& name); + + //- Reset the list of local object names from a wordList + void resetLocalObjectNames(const wordList& names); + + //- Get the list of field names to be written + virtual wordList objectNames(); + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + writeLocalObjects(const writeLocalObjects&); + + //- Disallow default bitwise assignment + void operator=(const writeLocalObjects&); + + +public: + + // Constructors + + //- Construct from objectRegistry and inheriting function object + writeLocalObjects + ( + const objectRegistry& obr, + const Switch& logRef + ); + + + //- Destructor + virtual ~writeLocalObjects(); + + + // Member Functions + + //- Return const access to the local object names + const wordList& localObjectNames() const; + + //- Read the list of objects to be written + virtual bool read(const dictionary&); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C new file mode 100644 index 0000000000..152a05764b --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.C @@ -0,0 +1,147 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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 "writeObjectsBase.H" +#include "Time.H" +#include "dictionary.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::writeObjectsBase::resetWriteObjectName +( + const wordRe& name +) +{ + writeObjectNames_.clear(); + writeObjectNames_.append(name); +} + + +void Foam::functionObjects::writeObjectsBase::resetWriteObjectNames +( + const wordReList& names +) +{ + writeObjectNames_.clear(); + writeObjectNames_.append(names); +} + + +Foam::wordList Foam::functionObjects::writeObjectsBase::objectNames() +{ + DynamicList allNames(writeObr_.toc().size()); + forAll(writeObjectNames_, i) + { + wordList names(writeObr_.names(writeObjectNames_[i])); + + if (names.size()) + { + allNames.append(names); + } + else + { + WarningInFunction + << "Object " << writeObjectNames_[i] << " not found in " + << "database. Available objects:" << nl << writeObr_.sortedToc() + << endl; + } + } + + return allNames; +} + + +void Foam::functionObjects::writeObjectsBase::writeObject +( + const regIOobject& obj +) +{ + if (log_) Info << " writing object " << obj.name() << endl; + + obj.write(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::functionObjects::writeObjectsBase::writeObjectsBase +( + const objectRegistry& obr, + const Switch& log +) +: + writeObr_(obr), + log_(log) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::functionObjects::writeObjectsBase::~writeObjectsBase() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const Foam::wordReList& +Foam::functionObjects::writeObjectsBase::writeObjectNames() const +{ + return writeObjectNames_; +} + + +bool Foam::functionObjects::writeObjectsBase::read(const dictionary& dict) +{ + dict.lookup("objects") >> writeObjectNames_; + + return true; +} + + +bool Foam::functionObjects::writeObjectsBase::write() +{ + wordList names(objectNames()); + + if(!names.empty()) + { + if (!writeObr_.time().writeTime()) + { + writeObr_.time().writeTimeDict(); + } + + forAll(names, i) + { + const regIOobject& obj = + writeObr_.lookupObject(names[i]); + + writeObject(obj); + } + } + + return true; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H new file mode 100644 index 0000000000..393bf1bd13 --- /dev/null +++ b/src/OpenFOAM/db/functionObjects/writeObjectsBase/writeObjectsBase.H @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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::functionObjects::writeObjectsBase + +Description + FunctionObject base class for writing a list of objects registered to the + database, on behalf of the inheriting function object, on when those should + be written to disk. + + FunctionObjects that inherit this class will receive the additional + dictionary option \c objects which allows selecting which fields of the + inherited function should be written to disk when \c write() is called. + + Example of function object specification: + \verbatim + + { + ... + objects (obj1 obj2); + ... + } + \endverbatim + +Usage + \table + Property | Description | Required | Default value + objects | List of objects to be written | yes | + \endtable + + Note: Regular expressions can also be used in \c objects. + +See also + Foam::functionObject + Foam::functionObjects::writeObjects + Foam::functionObjects::writeLocalObjects + +SourceFiles + writeObjectsBase.C + +\*---------------------------------------------------------------------------*/ + +#ifndef functionObjects_writeObjectsBase_H +#define functionObjects_writeObjectsBase_H + +#include "wordList.H" +#include "wordReList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class regIOobject; +class Switch; + +namespace functionObjects +{ + +/*---------------------------------------------------------------------------*\ + Class writeObjectsBase Declaration +\*---------------------------------------------------------------------------*/ + +class writeObjectsBase +{ + +protected: + + // Protected data + + //- Reference to the region objectRegistry + const objectRegistry& writeObr_; + + //- Reference to the inheriting function object's log variable + const Switch& log_; + + //- Object names requested by the user to be written + wordReList writeObjectNames_; + + + // Protected Member Functions + + //- Reset the list of object names to be written to a single regular + // expression + void resetWriteObjectName(const wordRe& name); + + //- Reset the list of object names to be written + void resetWriteObjectNames(const wordReList& names); + + //- Get the list of field names to be written + virtual wordList objectNames(); + + //- Write the requested registered IO object + virtual void writeObject(const regIOobject& obj); + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + writeObjectsBase(const writeObjectsBase&); + + //- Disallow default bitwise assignment + void operator=(const writeObjectsBase&); + + +public: + + // Constructors + + //- Construct from objectRegistry and inheriting function object + writeObjectsBase + ( + const objectRegistry& obr, + const Switch& logRef + ); + + + //- Destructor + virtual ~writeObjectsBase(); + + + // Member Functions + + //- Return const access to the object names requested to be written + const wordReList& writeObjectNames() const; + + //- Read the list of objects to be written + virtual bool read(const dictionary&); + + //- Write function + virtual bool write(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace functionObjects +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C index cc89adf8cb..67dfc57bff 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.C @@ -104,6 +104,7 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux : fvMeshFunctionObject(name, runTime, dict), logFiles(obr_, name), + writeLocalObjects(obr_, log), patchSet_() { volScalarField* wallHeatFluxPtr @@ -127,6 +128,7 @@ Foam::functionObjects::wallHeatFlux::wallHeatFlux read(dict); resetName(typeName); + resetLocalObjectName(typeName); } @@ -141,6 +143,7 @@ Foam::functionObjects::wallHeatFlux::~wallHeatFlux() bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict) { fvMeshFunctionObject::read(dict); + writeLocalObjects::read(dict); const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); @@ -229,16 +232,15 @@ bool Foam::functionObjects::wallHeatFlux::execute() bool Foam::functionObjects::wallHeatFlux::write() { + Log << type() << " " << name() << " write:" << nl; + + writeLocalObjects::write(); + logFiles::write(); const volScalarField& wallHeatFlux = obr_.lookupObject(type()); - Log << type() << " " << name() << " write:" << nl - << " writing field " << wallHeatFlux.name() << endl; - - wallHeatFlux.write(); - const fvPatchList& patches = mesh_.boundary(); const surfaceScalarField::Boundary& magSf = @@ -249,8 +251,7 @@ bool Foam::functionObjects::wallHeatFlux::write() label patchi = iter.key(); const fvPatch& pp = patches[patchi]; - const scalarField& hfp = - wallHeatFlux.boundaryField()[patchi]; + const scalarField& hfp = wallHeatFlux.boundaryField()[patchi]; const scalar minHfp = gMin(hfp); const scalar maxHfp = gMax(hfp); @@ -267,10 +268,12 @@ bool Foam::functionObjects::wallHeatFlux::write() << endl; } - Log << " min/max(" << pp.name() << ") = " + Log << " min/max/integ(" << pp.name() << ") = " << minHfp << ", " << maxHfp << ", " << integralHfp << endl; } + Log << endl; + return true; } diff --git a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H index 9cfc24da8a..3ccb8d7631 100644 --- a/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H +++ b/src/functionObjects/field/wallHeatFlux/wallHeatFlux.H @@ -52,10 +52,15 @@ Usage patches | list of patches to process | no | all wall patches \endtable +Note + Writing field 'wallHeatFlux' is done by default, but it can be overridden by + defining an empty \c objects list. For details see writeLocalObjects. + See also Foam::functionObject Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::logFiles + Foam::functionObjects::writeLocalObjects Foam::functionObjects::pressureTools Foam::functionObjects::timeControl @@ -69,6 +74,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "logFiles.H" +#include "writeLocalObjects.H" #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" #include "HashSet.H" @@ -88,7 +94,8 @@ namespace functionObjects class wallHeatFlux : public fvMeshFunctionObject, - public logFiles + public logFiles, + public writeLocalObjects { protected: diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.C b/src/functionObjects/field/wallShearStress/wallShearStress.C index 4272aa8374..06b7bb9d96 100644 --- a/src/functionObjects/field/wallShearStress/wallShearStress.C +++ b/src/functionObjects/field/wallShearStress/wallShearStress.C @@ -90,6 +90,7 @@ Foam::functionObjects::wallShearStress::wallShearStress : fvMeshFunctionObject(name, runTime, dict), logFiles(obr_, name), + writeLocalObjects(obr_, log), patchSet_() { volVectorField* wallShearStressPtr @@ -118,6 +119,7 @@ Foam::functionObjects::wallShearStress::wallShearStress read(dict); resetName(typeName); + resetLocalObjectName(typeName); } @@ -132,6 +134,7 @@ Foam::functionObjects::wallShearStress::~wallShearStress() bool Foam::functionObjects::wallShearStress::read(const dictionary& dict) { fvMeshFunctionObject::read(dict); + writeLocalObjects::read(dict); const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); @@ -225,16 +228,15 @@ bool Foam::functionObjects::wallShearStress::execute() bool Foam::functionObjects::wallShearStress::write() { + Log << type() << " " << name() << " write:" << nl; + + writeLocalObjects::write(); + logFiles::write(); const volVectorField& wallShearStress = obr_.lookupObject(type()); - Log << type() << " " << name() << " write:" << nl - << " writing field " << wallShearStress.name() << endl; - - wallShearStress.write(); - const fvPatchList& patches = mesh_.boundary(); forAllConstIter(labelHashSet, patchSet_, iter) @@ -260,6 +262,8 @@ bool Foam::functionObjects::wallShearStress::write() << minSsp << ", " << maxSsp << endl; } + Log << endl; + return true; } diff --git a/src/functionObjects/field/wallShearStress/wallShearStress.H b/src/functionObjects/field/wallShearStress/wallShearStress.H index f94a12a5ad..60c85e5821 100644 --- a/src/functionObjects/field/wallShearStress/wallShearStress.H +++ b/src/functionObjects/field/wallShearStress/wallShearStress.H @@ -63,10 +63,15 @@ Usage patches | list of patches to process | no | all wall patches \endtable +Note + Writing field 'wallShearStress' is done by default, but it can be overridden + by defining an empty \c objects list. For details see writeLocalObjects. + See also Foam::functionObject Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::logFiles + Foam::functionObjects::writeLocalObjects Foam::functionObjects::pressureTools Foam::functionObjects::timeControl @@ -80,6 +85,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "logFiles.H" +#include "writeLocalObjects.H" #include "volFieldsFwd.H" #include "HashSet.H" @@ -97,7 +103,8 @@ namespace functionObjects class wallShearStress : public fvMeshFunctionObject, - public logFiles + public logFiles, + public writeLocalObjects { protected: diff --git a/src/functionObjects/field/yPlus/yPlus.C b/src/functionObjects/field/yPlus/yPlus.C index 64c032c9f9..1116eac3f6 100644 --- a/src/functionObjects/field/yPlus/yPlus.C +++ b/src/functionObjects/field/yPlus/yPlus.C @@ -121,7 +121,8 @@ Foam::functionObjects::yPlus::yPlus ) : fvMeshFunctionObject(name, runTime, dict), - logFiles(obr_, name) + logFiles(obr_, name), + writeLocalObjects(obr_, log) { volScalarField* yPlusPtr ( @@ -144,6 +145,7 @@ Foam::functionObjects::yPlus::yPlus read(dict); resetName(typeName); + resetLocalObjectName(typeName); } @@ -158,6 +160,7 @@ Foam::functionObjects::yPlus::~yPlus() bool Foam::functionObjects::yPlus::read(const dictionary& dict) { fvMeshFunctionObject::read(dict); + writeLocalObjects::read(dict); return true; } @@ -193,16 +196,15 @@ bool Foam::functionObjects::yPlus::execute() bool Foam::functionObjects::yPlus::write() { - const volScalarField& yPlus = - obr_.lookupObject(type()); + Log << type() << " " << name() << " write:" << nl; - Log << type() << " " << name() << " write:" << nl - << " writing field " << yPlus.name() << endl; - - yPlus.write(); + writeLocalObjects::write(); logFiles::write(); + const volScalarField& yPlus = + mesh_.lookupObject(type()); + const volScalarField::Boundary& yPlusBf = yPlus.boundaryField(); const fvPatchList& patches = mesh_.boundary(); @@ -235,6 +237,8 @@ bool Foam::functionObjects::yPlus::write() } } + Log << endl; + return true; } diff --git a/src/functionObjects/field/yPlus/yPlus.H b/src/functionObjects/field/yPlus/yPlus.H index 1796a944e1..0ad148329b 100644 --- a/src/functionObjects/field/yPlus/yPlus.H +++ b/src/functionObjects/field/yPlus/yPlus.H @@ -28,13 +28,34 @@ Group grpFieldFunctionObjects Description - Evaluates and outputs turbulence y+ for models. Values written to - time directories as field 'yPlus' + Evaluates and outputs turbulence y+ for models. Values written to + time directories as field 'yPlus'. + + Example of function object specification: + \verbatim + yPlus1 + { + type yPlus; + libs ("libfieldFunctionObjects.so"); + ... + } + \endverbatim + +Usage + \table + Property | Description | Required | Default value + type | type name: yPlus | yes | + \endtable + +Note + Writing field 'yPlus' is done by default, but it can be overridden by + defining an empty \c objects list. For details see writeLocalObjects. See also Foam::functionObject Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::logFiles + Foam::functionObjects::writeLocalObjects Foam::functionObjects::timeControl SourceFiles @@ -47,6 +68,7 @@ SourceFiles #include "fvMeshFunctionObject.H" #include "logFiles.H" +#include "writeLocalObjects.H" #include "volFieldsFwd.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -67,7 +89,8 @@ namespace functionObjects class yPlus : public fvMeshFunctionObject, - public logFiles + public logFiles, + public writeLocalObjects { // Private Member Functions diff --git a/src/functionObjects/utilities/writeObjects/writeObjects.C b/src/functionObjects/utilities/writeObjects/writeObjects.C index ad3c73b080..71a650f5ba 100644 --- a/src/functionObjects/utilities/writeObjects/writeObjects.C +++ b/src/functionObjects/utilities/writeObjects/writeObjects.C @@ -64,6 +64,62 @@ const Foam::NamedEnum > Foam::functionObjects::writeObjects::writeOptionNames_; +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::writeObjects::writeObject +( + const regIOobject& obj +) +{ + switch (writeOption_) + { + case AUTO_WRITE: + { + if(obj.writeOpt() != IOobject::AUTO_WRITE) + { + return; + } + + break; + } + case NO_WRITE: + { + if(obj.writeOpt() != IOobject::NO_WRITE) + { + return; + } + + break; + } + case ANY_WRITE: + { + break; + } + default: + { + FatalErrorInFunction + << "Unknown writeOption " + << writeOptionNames_[writeOption_] + << ". Valid writeOption types are" << writeOptionNames_ + << exit(FatalError); + } + } + + if + ( + obj.writeOpt() == IOobject::AUTO_WRITE + && writeObr_.time().writeTime() + ) + { + Log << " automatically written object " << obj.name() << endl; + } + else + { + writeObjectsBase::writeObject(obj); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::writeObjects::writeObjects @@ -74,15 +130,15 @@ Foam::functionObjects::writeObjects::writeObjects ) : functionObject(name), - obr_ + writeObjectsBase ( runTime.lookupObject ( dict.lookupOrDefault("region", polyMesh::defaultRegion) - ) + ), + log ), - writeOption_(ANY_WRITE), - objectNames_() + writeOption_(ANY_WRITE) { read(dict); } @@ -100,16 +156,16 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict) { if (dict.found("field")) { - objectNames_.setSize(1); - dict.lookup("field") >> objectNames_[0]; + writeObjectNames_.setSize(1); + dict.lookup("field") >> writeObjectNames_[0]; } else if (dict.found("fields")) { - dict.lookup("fields") >> objectNames_; + dict.lookup("fields") >> writeObjectNames_; } else { - dict.lookup("objects") >> objectNames_; + writeObjectsBase::read(dict); } if (dict.found("writeOption")) @@ -121,7 +177,7 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict) writeOption_ = ANY_WRITE; } - return true; + return functionObject::read(dict); } @@ -135,85 +191,9 @@ bool Foam::functionObjects::writeObjects::write() { Info<< type() << " " << name() << " write:" << nl; - if (!obr_.time().writeTime()) - { - obr_.time().writeTimeDict(); - } + writeObjectsBase::write(); - DynamicList allNames(obr_.toc().size()); - forAll(objectNames_, i) - { - wordList names(obr_.names(objectNames_[i])); - - if (names.size()) - { - allNames.append(names); - } - else - { - WarningInFunction - << "Object " << objectNames_[i] << " not found in " - << "database. Available objects:" << nl << obr_.sortedToc() - << endl; - } - } - - forAll(allNames, i) - { - regIOobject& obj = const_cast - ( - obr_.lookupObject(allNames[i]) - ); - - switch (writeOption_) - { - case AUTO_WRITE: - { - if(obj.writeOpt() != IOobject::AUTO_WRITE) - { - continue; - } - - break; - } - case NO_WRITE: - { - if(obj.writeOpt() != IOobject::NO_WRITE) - { - continue; - } - - break; - } - case ANY_WRITE: - { - break; - } - default: - { - FatalErrorInFunction - << "Unknown writeOption " - << writeOptionNames_[writeOption_] - << ". Valid writeOption types are" << writeOptionNames_ - << exit(FatalError); - } - } - - if - ( - obj.writeOpt() == IOobject::AUTO_WRITE - && obr_.time().writeTime() - ) - { - Info<< " automatically written object " << obj.name() << endl; - } - else - { - Info<< " writing object " << obj.name() << endl; - - obj.write(); - } - } + Log << endl; return true; } diff --git a/src/functionObjects/utilities/writeObjects/writeObjects.H b/src/functionObjects/utilities/writeObjects/writeObjects.H index a39190077a..fd8a7507e1 100644 --- a/src/functionObjects/utilities/writeObjects/writeObjects.H +++ b/src/functionObjects/utilities/writeObjects/writeObjects.H @@ -72,6 +72,7 @@ Usage See also Foam::functionObject + Foam::functionObjects::writeObjectsBase Foam::functionObjects::timeControl SourceFiles @@ -83,7 +84,7 @@ SourceFiles #define functionObjects_writeObjects_H #include "functionObject.H" -#include "wordReList.H" +#include "writeObjectsBase.H" #include "NamedEnum.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -91,9 +92,6 @@ SourceFiles namespace Foam { -// Forward declaration of classes -class objectRegistry; - namespace functionObjects { @@ -103,7 +101,8 @@ namespace functionObjects class writeObjects : - public functionObject + public functionObject, + public writeObjectsBase { public: @@ -124,18 +123,15 @@ private: // Private data - //- Reference to Db - const objectRegistry& obr_; - //- To only write objects of defined writeOption writeOption writeOption_; - //- Names of objects to control - wordReList objectNames_; - // Private Member Functions + //- Write the requested registered IO object + virtual void writeObject(const regIOobject& obj); + //- Disallow default bitwise copy construct writeObjects(const writeObjects&); From f31623d337870d4e28326690dfd1483f6c5d7f05 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 12 Dec 2016 14:35:21 +0000 Subject: [PATCH 002/277] pimpleControl: Added optional 'solveFlow' control sprayFoam: Added support for the optional 'solveFlow' control to allow simulation of the spray evolution with all sub-models in a 'frozen' flow-field. --- .../solvers/lagrangian/sprayFoam/sprayFoam.C | 41 ++++++++++--------- .../pimpleControl/pimpleControl.C | 4 +- .../pimpleControl/pimpleControl.H | 18 +++++--- .../pimpleControl/pimpleControlI.H | 8 +++- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/applications/solvers/lagrangian/sprayFoam/sprayFoam.C b/applications/solvers/lagrangian/sprayFoam/sprayFoam.C index 4bffd93bbd..d70075000a 100644 --- a/applications/solvers/lagrangian/sprayFoam/sprayFoam.C +++ b/applications/solvers/lagrangian/sprayFoam/sprayFoam.C @@ -75,34 +75,37 @@ int main(int argc, char *argv[]) parcels.evolve(); - #include "rhoEqn.H" - - // --- Pressure-velocity PIMPLE corrector loop - while (pimple.loop()) + if (pimple.solveFlow()) { - #include "UEqn.H" - #include "YEqn.H" - #include "EEqn.H" + #include "rhoEqn.H" - // --- Pressure corrector loop - while (pimple.correct()) + // --- Pressure-velocity PIMPLE corrector loop + while (pimple.loop()) { - #include "pEqn.H" + #include "UEqn.H" + #include "YEqn.H" + #include "EEqn.H" + + // --- Pressure corrector loop + while (pimple.correct()) + { + #include "pEqn.H" + } + + if (pimple.turbCorr()) + { + turbulence->correct(); + } } - if (pimple.turbCorr()) + rho = thermo.rho(); + + if (runTime.write()) { - turbulence->correct(); + combustion->dQ()().write(); } } - rho = thermo.rho(); - - if (runTime.write()) - { - combustion->dQ()().write(); - } - Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << endl; diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C index 2622f94867..e500ab7587 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C +++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C @@ -40,8 +40,9 @@ void Foam::pimpleControl::read() { solutionControl::read(false); - // Read solution controls const dictionary& pimpleDict = dict(); + + solveFlow_ = pimpleDict.lookupOrDefault("solveFlow", true); nCorrPIMPLE_ = pimpleDict.lookupOrDefault