Merge branch 'feature-run-time-control-triggers' into 'develop'

Feature run time control triggers

See merge request Development/OpenFOAM-plus!228
This commit is contained in:
Andrew Heather
2019-01-23 14:59:18 +00:00
48 changed files with 1576 additions and 410 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -164,17 +164,22 @@ int main(int argc, char *argv[])
functionObjects::fileFieldSelection fields(mesh); functionObjects::fileFieldSelection fields(mesh);
if (args.found("fields")) if (args.found("fields"))
{ {
fields.insert(args.getList<wordRe>("fields")); fields.resetFieldFilters
(
HashSet<wordRe>(args.getList<wordRe>("fields"))
);
} }
if (args.found("field")) if (args.found("field"))
{ {
fields.insert(args.opt<wordRe>("field")); fields.resetFieldFilters(args.opt<wordRe>("field"));
} }
// Externally stored dictionary for functionObjectList // Externally stored dictionary for functionObjectList
// if not constructed from runTime // if not constructed from runTime
dictionary functionsDict; dictionary functionsDict;
HashSet<wordRe> fieldFilters(fields.filters());
// Construct functionObjectList // Construct functionObjectList
autoPtr<functionObjectList> functionsPtr autoPtr<functionObjectList> functionsPtr
( (
@ -183,7 +188,7 @@ int main(int argc, char *argv[])
args, args,
runTime, runTime,
functionsDict, functionsDict,
fields fieldFilters // include any additional command-line fields
) )
); );
@ -193,8 +198,6 @@ int main(int argc, char *argv[])
Info<< "Time = " << runTime.timeName() << endl; Info<< "Time = " << runTime.timeName() << endl;
fields.updateSelection();
if (mesh.readUpdate() != polyMesh::UNCHANGED) if (mesh.readUpdate() != polyMesh::UNCHANGED)
{ {
// Update functionObjectList if mesh changes // Update functionObjectList if mesh changes
@ -205,10 +208,14 @@ int main(int argc, char *argv[])
args, args,
runTime, runTime,
functionsDict, functionsDict,
fields fieldFilters
); );
} }
fields.resetFieldFilters(fieldFilters);
fields.updateSelection();
const bool throwingIOErr = FatalIOError.throwExceptions(); const bool throwingIOErr = FatalIOError.throwExceptions();
try try
@ -218,7 +225,7 @@ int main(int argc, char *argv[])
args, args,
runTime, runTime,
mesh, mesh,
fields.selection(), fields.selectionNames(),
functionsPtr(), functionsPtr(),
timei == timeDirs.size()-1 timei == timeDirs.size()-1
); );

View File

@ -458,6 +458,15 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::functionObjectList::triggerIndex() const
{
label triggeri = labelMin;
stateDict().readIfPresent("triggerIndex", triggeri);
return triggeri;
}
void Foam::functionObjectList::resetState() void Foam::functionObjectList::resetState()
{ {
// Reset (re-read) the state dictionary // Reset (re-read) the state dictionary

View File

@ -174,6 +174,9 @@ public:
//- Access to the functionObjects //- Access to the functionObjects
using PtrList<functionObject>::operator[]; using PtrList<functionObject>::operator[];
//- Return the current trigger index (read from the stateDict)
label triggerIndex() const;
//- Reset/read state dictionary for current time //- Reset/read state dictionary for current time
void resetState(); void resetState();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -78,6 +78,34 @@ Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
} }
bool Foam::functionObjects::stateFunctionObject::setTrigger
(
const label triggeri
)
{
IOdictionary& stateDict = this->stateDict();
label oldTriggeri =
stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
if (triggeri > oldTriggeri)
{
stateDict.set("triggerIndex", triggeri);
return true;
}
return false;
}
Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
{
const IOdictionary& stateDict = this->stateDict();
return stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
}
bool Foam::functionObjects::stateFunctionObject::foundProperty bool Foam::functionObjects::stateFunctionObject::foundProperty
( (
const word& entryName const word& entryName
@ -177,8 +205,8 @@ Foam::functionObjects::stateFunctionObject::objectResultEntries() const
} }
Foam::List<Foam::word> Foam::functionObjects::stateFunctionObject:: Foam::List<Foam::word>
objectResultEntries Foam::functionObjects::stateFunctionObject::objectResultEntries
( (
const word& objectName const word& objectName
) const ) const
@ -210,5 +238,68 @@ objectResultEntries
return entries; return entries;
} }
void Foam::functionObjects::stateFunctionObject::writeResultEntries
(
Ostream& os
) const
{
writeResultEntries(name(), os);
}
void Foam::functionObjects::stateFunctionObject::writeResultEntries
(
const word& objectName,
Ostream& os
) const
{
const IOdictionary& stateDict = this->stateDict();
if (stateDict.found(resultsName_))
{
const dictionary& resultsDict = stateDict.subDict(resultsName_);
if (resultsDict.found(objectName))
{
const dictionary& objectDict = resultsDict.subDict(objectName);
for (const word& dataFormat : objectDict.sortedToc())
{
os << " Type: " << dataFormat << nl;
const dictionary& resultDict = objectDict.subDict(dataFormat);
for (const word& result : resultDict.sortedToc())
{
os << " " << result << nl;
}
}
}
}
}
void Foam::functionObjects::stateFunctionObject::writeAllResultEntries
(
Ostream& os
) const
{
const IOdictionary& stateDict = this->stateDict();
if (stateDict.found(resultsName_))
{
const dictionary& resultsDict = stateDict.subDict(resultsName_);
const wordList allObjectNames = resultsDict.sortedToc();
for (const word& objectName : allObjectNames)
{
os << "Object: " << objectName << endl;
writeResultEntries(objectName, os);
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -125,6 +125,12 @@ public:
//- Return true if the property exists //- Return true if the property exists
bool foundProperty(const word& entryName) const; bool foundProperty(const word& entryName) const;
//- Get the current trigger index
label getTrigger() const;
//- Set the current trigger index
bool setTrigger(const label triggeri);
//- Set dictionary, return true if set //- Set dictionary, return true if set
bool getDict bool getDict
( (
@ -244,6 +250,15 @@ public:
//- Return result entries for named object //- Return result entries for named object
List<word> objectResultEntries(const word& objectName) const; List<word> objectResultEntries(const word& objectName) const;
//- Write the results entries for all objects to stream
void writeResultEntries(Ostream& os) const;
//- Write the results entries for named object to stream
void writeResultEntries(const word& objectName, Ostream& os) const;
//- Write the results entries for all objects to stream
void writeAllResultEntries(Ostream& os) const;
}; };

View File

@ -38,6 +38,15 @@ namespace functionObjects
} }
} }
const Foam::Enum<Foam::functionObjects::timeControl::controlMode>
Foam::functionObjects::timeControl::controlModeNames_
{
{ controlMode::TIME, "time" },
{ controlMode::TRIGGER, "trigger" },
{ controlMode::TIME_OR_TRIGGER, "timeOrTrigger" },
{ controlMode::TIME_AND_TRIGGER, "timeAndTrigger" }
};
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
@ -51,6 +60,13 @@ void Foam::functionObjects::timeControl::readControls()
{ {
timeEnd_ = time_.userTimeToTime(timeEnd_); timeEnd_ = time_.userTimeToTime(timeEnd_);
} }
if (dict_.readIfPresent("triggerStart", triggerStart_))
{
dict_.readIfPresent("triggerEnd", triggerEnd_);
controlMode_ = controlModeNames_.read(dict_.lookup("controlMode"));
}
deltaTCoeff_ = GREAT; deltaTCoeff_ = GREAT;
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_)) if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
{ {
@ -70,9 +86,41 @@ void Foam::functionObjects::timeControl::readControls()
bool Foam::functionObjects::timeControl::active() const bool Foam::functionObjects::timeControl::active() const
{ {
return label triggeri = time_.functionObjects().triggerIndex();
bool inTime =
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue()) time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
&& time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue()); && time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue());
bool inTrigger = triggeri >= triggerStart_ && triggeri <= triggerEnd_;
switch (controlMode_)
{
case controlMode::TIME:
{
return inTime;
}
case controlMode::TRIGGER:
{
return inTrigger;
}
case controlMode::TIME_OR_TRIGGER:
{
return inTime || inTrigger;
}
case controlMode::TIME_AND_TRIGGER:
{
return inTime && inTrigger;
}
default:
{
FatalErrorInFunction
<< "Unhandled enumeration: " << controlModeNames_[controlMode_]
<< abort(FatalError);
}
}
return false;
} }
@ -401,8 +449,11 @@ Foam::functionObjects::timeControl::timeControl
functionObject(name), functionObject(name),
time_(t), time_(t),
dict_(dict), dict_(dict),
controlMode_(controlMode::TIME),
timeStart_(-VGREAT), timeStart_(-VGREAT),
timeEnd_(VGREAT), timeEnd_(VGREAT),
triggerStart_(labelMax),
triggerEnd_(labelMax),
nStepsToStartTimeChange_(labelMax), nStepsToStartTimeChange_(labelMax),
executeControl_(t, dict, "execute"), executeControl_(t, dict, "execute"),
writeControl_(t, dict, "write"), writeControl_(t, dict, "write"),
@ -426,6 +477,8 @@ bool Foam::functionObjects::timeControl::entriesPresent(const dictionary& dict)
|| Foam::timeControl::entriesPresent(dict, "execute") || Foam::timeControl::entriesPresent(dict, "execute")
|| dict.found("timeStart") || dict.found("timeStart")
|| dict.found("timeEnd") || dict.found("timeEnd")
|| dict.found("triggerStart")
|| dict.found("triggerEnd")
) )
{ {
return true; return true;
@ -681,7 +734,7 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
// Set time, deltaT adjustments for writeInterval purposes // Set time, deltaT adjustments for writeInterval purposes
// are already taken care. Hence disable auto-update // are already taken care. Hence disable auto-update
const_cast<Time&>( time_).setDeltaT(newDeltaT, false); const_cast<Time&>(time_).setDeltaT(newDeltaT, false);
if (seriesDTCoeff_ < 1.0) if (seriesDTCoeff_ < 1.0)
{ {
@ -746,12 +799,7 @@ bool Foam::functionObjects::timeControl::read(const dictionary& dict)
bool Foam::functionObjects::timeControl::filesModified() const bool Foam::functionObjects::timeControl::filesModified() const
{ {
bool mod = false; return active() ? foPtr_->filesModified() : false;
if (active())
{
mod = foPtr_->filesModified();
}
return mod;
} }

View File

@ -75,6 +75,25 @@ class timeControl
: :
public functionObject public functionObject
{ {
public:
// Public enumerations
//- Control mode
enum class controlMode
{
TIME,
TRIGGER,
TIME_OR_TRIGGER,
TIME_AND_TRIGGER
};
static const Enum<controlMode> controlModeNames_;
private:
// Private data // Private data
//- Reference to the time database //- Reference to the time database
@ -86,12 +105,21 @@ class timeControl
// Optional user inputs // Optional user inputs
//- Control mode (combination of time/trigger behaviour)
controlMode controlMode_;
//- Activation time - defaults to -VGREAT //- Activation time - defaults to -VGREAT
scalar timeStart_; scalar timeStart_;
//- De-activation time - defaults to VGREAT //- De-activation time - defaults to VGREAT
scalar timeEnd_; scalar timeEnd_;
//- Activation trigger index - defaults to labelMin
label triggerStart_;
//- De-activation trigger index - defaults to labelMax
label triggerEnd_;
//- Max time step change //- Max time step change
scalar deltaTCoeff_; scalar deltaTCoeff_;

View File

@ -97,10 +97,10 @@ $(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C
functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C
functionObjects/volRegion/volRegion.C functionObjects/volRegion/volRegion.C
functionObjects/fieldSelection/fieldSelection.C functionObjects/fieldSelections/fieldSelection/fieldSelection.C
functionObjects/fieldSelection/fileFieldSelection.C functionObjects/fieldSelections/fileFieldSelection/fileFieldSelection.C
functionObjects/fieldSelection/volFieldSelection.C functionObjects/fieldSelections/volFieldSelection/volFieldSelection.C
functionObjects/fieldSelection/solverFieldSelection.C functionObjects/fieldSelections/solverFieldSelection/solverFieldSelection.C
fvPatchFields = fields/fvPatchFields fvPatchFields = fields/fvPatchFields
$(fvPatchFields)/fvPatchField/fvPatchFields.C $(fvPatchFields)/fvPatchField/fvPatchFields.C

View File

@ -0,0 +1,157 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::fieldInfo
Description
Helper class to store a wordRe and label used by
Foam::functionObjects::fieldSelection
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldInfo_H
#define functionObjects_fieldInfo_H
#include "wordRe.H"
#include "label.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldInfo Declaration
\*---------------------------------------------------------------------------*/
class fieldInfo;
Istream& operator>>(Istream&, fieldInfo&);
Ostream& operator<<(Ostream&, const fieldInfo&);
class fieldInfo
{
// Pivate data
//- Pattern for the field name
wordRe name_;
//- Field component
label component_;
//- Found
mutable Switch found_;
public:
// Constructors
//- Null constructor
fieldInfo()
:
name_(word::null),
component_(-1),
found_(false)
{}
//- Construct from components
fieldInfo(const wordRe& name, const label component = -1)
:
name_(name),
component_(component),
found_(false)
{}
//- Construct from stream
fieldInfo(Istream& is)
:
name_(is),
component_(readLabel(is)),
found_(false)
{}
//- Destructor
~fieldInfo() = default;
// Member Functions
const wordRe& name() const
{
return name_;
}
label component() const
{
return component_;
}
Switch& found() const
{
return found_;
}
friend bool operator==(const fieldInfo& a, const fieldInfo& b)
{
return
a.name_ == b.name_
&& a.component_ == b.component_
&& a.found_ == b.found_;
}
friend bool operator!=(const fieldInfo& a, const fieldInfo& b)
{
return !(a == b);
}
// IOstream Operators
friend Istream& operator>>(Istream& is, fieldInfo& fi)
{
is >> fi.name_ >> fi.component_ >> fi.found_;
return is;
}
friend Ostream& operator<<(Ostream& os, const fieldInfo& fi)
{
os << fi.name_ << ' ' << fi.component_ << ' ' << fi.found_;
return os;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
#endif
// ************************************************************************* //

View File

@ -0,0 +1,176 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017-2019 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fieldSelection.H"
#include "objectRegistry.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldSelection::fieldSelection
(
const objectRegistry& obr,
const bool includeComponents
)
:
List<fieldInfo>(),
obr_(obr),
includeComponents_(includeComponents),
selection_()
{}
bool Foam::functionObjects::fieldSelection::resetFieldFilters
(
const HashSet<wordRe>& names
)
{
static word cmptStr(".component(");
static string::size_type len(cmptStr.size());
DynamicList<fieldInfo> nameAndComponent(names.size());
for (const wordRe& name : names)
{
string::size_type n = name.find(cmptStr);
if (n != string::npos)
{
// Field should be written <field>.component(i)
if (!includeComponents_)
{
FatalErrorInFunction
<< "Component specification not allowed for " << name
<< exit(FatalError);
}
if (name.isPattern())
{
FatalErrorInFunction
<< "Cannot use \".component option\" in combination with "
<< "wildcards for " << name
<< exit(FatalError);
}
word baseName = name.substr(0, n);
// Extract the component - number between ()'s
string::size_type closei = name.find(')', n);
if (closei == string::npos)
{
FatalErrorInFunction
<< "Invalid field component specification for "
<< name << nl
<< ". Field should be expressed as <field>.component(i)"
<< exit(FatalError);
}
string::size_type cmptWidth = closei - n - len;
label component
(
readLabel(IStringStream(name.substr(n+len, cmptWidth))())
);
nameAndComponent.append(fieldInfo(wordRe(baseName), component));
}
else
{
nameAndComponent.append(fieldInfo(name));
}
}
this->transfer(nameAndComponent);
return true;
}
bool Foam::functionObjects::fieldSelection::resetFieldFilters
(
const wordRe& name
)
{
return resetFieldFilters(HashSet<wordRe>({name}));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldSelection::read(const dictionary& dict)
{
HashSet<wordRe> fields(dict.lookup("fields"));
return resetFieldFilters(fields);
}
bool Foam::functionObjects::fieldSelection::containsPattern() const
{
for (const fieldInfo& fi : *this)
{
if (fi.name().isPattern())
{
return true;
}
}
return false;
}
void Foam::functionObjects::fieldSelection::clearSelection()
{
selection_.clear();
}
bool Foam::functionObjects::fieldSelection::updateSelection()
{
return false;
}
bool Foam::functionObjects::fieldSelection::checkSelection()
{
bool ok = true;
for (const fieldInfo& fi : *this)
{
if (!fi.found())
{
WarningInFunction
<< "Field " << fi.name() << " not found"
<< endl;
ok = false;
}
}
return ok;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -27,6 +27,11 @@ Class
Description Description
Helper class to manage field selections Helper class to manage field selections
The class holds a list of field name filters which are then applied to a
set of field objects (in derived classes) from which the resulting set is
available via the selection() function. This returns a list of
(fieldName, component) objects, e.g. for U.component(0) this is (U, 0).
SourceFiles SourceFiles
fieldSelection.C fieldSelection.C
@ -35,8 +40,9 @@ SourceFiles
#ifndef functionObjects_fieldSelection_H #ifndef functionObjects_fieldSelection_H
#define functionObjects_fieldSelection_H #define functionObjects_fieldSelection_H
#include "fieldInfo.H"
#include "DynamicList.H"
#include "HashSet.H" #include "HashSet.H"
#include "wordRe.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -55,7 +61,7 @@ namespace functionObjects
class fieldSelection class fieldSelection
: :
public HashSet<wordRe> public List<fieldInfo>
{ {
private: private:
@ -72,34 +78,49 @@ protected:
//- Reference to the database //- Reference to the database
const objectRegistry& obr_; const objectRegistry& obr_;
//- Flag to indicate whether components are allowed
const bool includeComponents_;
//- Current field selection //- Current field selection
wordHashSet selection_; List<fieldInfo> selection_;
// Protected Member Functions // Protected Member Functions
//- Add registered objects of a given type //- Add registered objects of a given type
template<class Type> template<class Type>
void addRegistered(wordHashSet& set) const; void addRegistered(DynamicList<fieldInfo>& set) const;
public: public:
//- Construct from object registry //- Construct from object registry
fieldSelection(const objectRegistry& obr); fieldSelection
(
const objectRegistry& obr,
const bool includeComponents = false
);
//- Destructor //- Destructor
virtual ~fieldSelection(); virtual ~fieldSelection() = default;
// Member Functions // Member Functions
//- Return the cuurent filters
inline HashSet<wordRe> filters() const;
inline const List<fieldInfo>& selection() const;
//- Return the current field selection //- Return the current field selection
const wordHashSet& selection() const inline wordHashSet selectionNames() const;
{
return selection_; //- Reset the field filters to the given field names
} virtual bool resetFieldFilters(const HashSet<wordRe>& names);
//- Reset the field filters to the given field name
virtual bool resetFieldFilters(const wordRe& name);
//- Read the fieldSelection data from dictionary //- Read the fieldSelection data from dictionary
virtual bool read(const dictionary& dict); virtual bool read(const dictionary& dict);
@ -110,8 +131,11 @@ public:
//- Clear the current selection //- Clear the current selection
virtual void clearSelection(); virtual void clearSelection();
//- Update the selection using current contents of obr_ //- Update the selection
virtual bool updateSelection(); virtual bool updateSelection();
//- Check that all requested fielda have been found
virtual bool checkSelection();
}; };
@ -122,6 +146,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fieldSelectionI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "fieldSelectionTemplates.C" #include "fieldSelectionTemplates.C"
#endif #endif

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,62 +23,37 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fieldSelection.H" inline Foam::HashSet<Foam::wordRe>
#include "objectRegistry.H" Foam::functionObjects::fieldSelection::filters() const
#include "dictionary.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldSelection::fieldSelection
(
const objectRegistry& obr
)
:
HashSet<wordRe>(),
obr_(obr),
selection_()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldSelection::~fieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldSelection::read(const dictionary& dict)
{ {
dict.readEntry("fields", *this); HashSet<wordRe> f;
for (const auto fieldInfo : *this)
return true;
}
bool Foam::functionObjects::fieldSelection::containsPattern() const
{
for (const wordRe& fieldName : *this)
{ {
if (fieldName.isPattern()) f.insert(fieldInfo.name());
{
return true;
}
} }
return false; return f;
}
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
inline const Foam::List<Foam::functionObjects::fieldInfo>&
Foam::functionObjects::fieldSelection::selection() const
{
return selection_;
} }
void Foam::functionObjects::fieldSelection::clearSelection() inline Foam::wordHashSet
Foam::functionObjects::fieldSelection::selectionNames() const
{ {
selection_.clear(); wordHashSet names;
} for (const fieldInfo& fi : *this)
{
names.insert(fi.name());
}
return names;
bool Foam::functionObjects::fieldSelection::updateSelection()
{
return false;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "DynamicList.H"
#include "objectRegistry.H" #include "objectRegistry.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
@ -31,12 +30,21 @@ License
template<class Type> template<class Type>
void Foam::functionObjects::fieldSelection::addRegistered void Foam::functionObjects::fieldSelection::addRegistered
( (
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
for (const wordRe& name : *this) for (const fieldInfo& fi : *this)
{ {
set.insert(obr_.names<Type>(name)); wordList names(obr_.names<Type>(fi.name()));
if (names.size())
{
for (const word& name : names)
{
set.append(fieldInfo(wordRe(name), fi.component()));
}
fi.found() = true;
}
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,7 +35,7 @@ License
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
( (
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
@ -52,7 +52,7 @@ void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
( (
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
@ -71,16 +71,11 @@ void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
Foam::functionObjects::fileFieldSelection::fileFieldSelection Foam::functionObjects::fileFieldSelection::fileFieldSelection
( (
const objectRegistry& obr const objectRegistry& obr,
const bool includeComponents
) )
: :
fieldSelection(obr) fieldSelection(obr, includeComponents)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
{} {}
@ -88,19 +83,24 @@ Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
bool Foam::functionObjects::fileFieldSelection::updateSelection() bool Foam::functionObjects::fileFieldSelection::updateSelection()
{ {
wordHashSet oldSet; List<fieldInfo> oldSet(std::move(selection_));
oldSet.swap(selection_);
DynamicList<fieldInfo> newSelection(oldSet.size());
// Geometric fields // Geometric fields
addGeoFieldTypes<fvPatchField, volMesh>(selection_); addGeoFieldTypes<fvPatchField, volMesh>(newSelection);
addGeoFieldTypes<fvsPatchField, surfaceMesh>(selection_); addGeoFieldTypes<fvsPatchField, surfaceMesh>(newSelection);
addGeoFieldTypes<pointPatchField, pointMesh>(selection_); addGeoFieldTypes<pointPatchField, pointMesh>(newSelection);
// Internal fields // Internal fields
addInternalFieldTypes(selection_); addInternalFieldTypes(newSelection);
// Uniform fields // Uniform fields
addUniformFieldTypes(selection_); addUniformFieldTypes(newSelection);
selection_.transfer(newSelection);
(void)fieldSelection::checkSelection();
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -69,31 +69,35 @@ protected:
//- Add registered GeometricField types to selection //- Add registered GeometricField types to selection
template<template<class> class PatchType, class MeshType> template<template<class> class PatchType, class MeshType>
void addGeoFieldTypes(wordHashSet& set) const; void addGeoFieldTypes(DynamicList<fieldInfo>& set) const;
//- Add registered Internal types to selection //- Add registered Internal types to selection
void addInternalFieldTypes(wordHashSet& set) const; void addInternalFieldTypes(DynamicList<fieldInfo>& set) const;
//- Add registered uniform types to selection //- Add registered uniform types to selection
void addUniformFieldTypes(wordHashSet& set) const; void addUniformFieldTypes(DynamicList<fieldInfo>& set) const;
//- Add objects of a given type //- Add objects of a given type
template<class Type> template<class Type>
void addFromFile void addFromFile
( (
const IOobjectList& allFileObjects, const IOobjectList& allFileObjects,
wordHashSet& set DynamicList<fieldInfo>& set
) const; ) const;
public: public:
//- Construct from object registry //- Construct from object registry
fileFieldSelection(const objectRegistry& obr); fileFieldSelection
(
const objectRegistry& obr,
const bool includeComponents = false
);
//- Destructor //- Destructor
virtual ~fileFieldSelection(); virtual ~fileFieldSelection() = default;
// Member Functions // Member Functions

View File

@ -33,12 +33,21 @@ template<class Type>
void Foam::functionObjects::fileFieldSelection::addFromFile void Foam::functionObjects::fileFieldSelection::addFromFile
( (
const IOobjectList& allFileObjects, const IOobjectList& allFileObjects,
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
for (const wordRe& fieldName : *this) for (const fieldInfo& fi : *this)
{ {
set.insert(allFileObjects.names(Type::typeName, fieldName)); const wordList names(allFileObjects.names(Type::typeName, fi.name()));
if (names.size())
{
for (const word& name : names)
{
set.append(fieldInfo(wordRe(name)));
}
fi.found() = true;
}
} }
} }
@ -46,7 +55,7 @@ void Foam::functionObjects::fileFieldSelection::addFromFile
template<template<class> class PatchType, class MeshType> template<template<class> class PatchType, class MeshType>
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
( (
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);

View File

@ -32,10 +32,11 @@ License
Foam::functionObjects::solverFieldSelection::solverFieldSelection Foam::functionObjects::solverFieldSelection::solverFieldSelection
( (
const objectRegistry& obr const objectRegistry& obr,
const bool includeComponents
) )
: :
volFieldSelection(obr) fieldSelection(obr, includeComponents)
{ {
if (!isA<fvMesh>(obr)) if (!isA<fvMesh>(obr))
{ {
@ -46,34 +47,43 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::solverFieldSelection::~solverFieldSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::solverFieldSelection::updateSelection() bool Foam::functionObjects::solverFieldSelection::updateSelection()
{ {
wordHashSet oldSet; List<fieldInfo> oldSet(std::move(selection_));
oldSet.swap(selection_);
wordHashSet volFields; DynamicList<fieldInfo> newSelection(oldSet.size());
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const Foam::dictionary& solverDict = mesh.solverPerformanceDict(); const dictionary& solverDict = mesh.solverPerformanceDict();
for (const word& fieldName : volFields) const wordList solvedFieldNames(solverDict.sortedToc());
for (const fieldInfo& fi : *this)
{ {
if (solverDict.found(fieldName)) for (const word& solvedField : solvedFieldNames)
{ {
selection_.insert(fieldName); if (fi.name().match(solvedField))
{
newSelection.append
(
fieldInfo(wordRe(solvedField), fi.component())
);
fi.found() = true;
}
} }
} }
selection_.transfer(newSelection);
if (!fieldSelection::checkSelection())
{
WarningInFunction
<< "Valid solver fields are: " << solvedFieldNames;
}
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,17 +25,17 @@ Class
Foam::functionObjects::volFieldSelection Foam::functionObjects::volFieldSelection
Description Description
Helper class to manage volume field selections Helper class to manage solver field selections
SourceFiles SourceFiles
volFieldSelection.C solverFieldSelection.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef functionObjects_solverFieldSelection_H #ifndef functionObjects_solverFieldSelection_H
#define functionObjects_solverFieldSelection_H #define functionObjects_solverFieldSelection_H
#include "volFieldSelection.H" #include "fieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,7 +50,7 @@ namespace functionObjects
class solverFieldSelection class solverFieldSelection
: :
public volFieldSelection public fieldSelection
{ {
private: private:
@ -63,11 +63,15 @@ private:
public: public:
//- Construct from object registry //- Construct from object registry
solverFieldSelection(const objectRegistry& obr); solverFieldSelection
(
const objectRegistry& obr,
const bool includeComponents = false
);
//- Destructor //- Destructor
virtual ~solverFieldSelection(); virtual ~solverFieldSelection() = default;
// Member Functions // Member Functions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2109 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -31,16 +31,11 @@ License
Foam::functionObjects::volFieldSelection::volFieldSelection Foam::functionObjects::volFieldSelection::volFieldSelection
( (
const objectRegistry& obr const objectRegistry& obr,
const bool includeComponents
) )
: :
fieldSelection(obr) fieldSelection(obr, includeComponents)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::volFieldSelection::~volFieldSelection()
{} {}
@ -48,11 +43,15 @@ Foam::functionObjects::volFieldSelection::~volFieldSelection()
bool Foam::functionObjects::volFieldSelection::updateSelection() bool Foam::functionObjects::volFieldSelection::updateSelection()
{ {
wordHashSet oldSet; List<fieldInfo> oldSet(std::move(selection_));
oldSet.swap(selection_); DynamicList<fieldInfo> newSet(oldSet.size());
addRegisteredGeoFields<fvPatchField, volMesh>(selection_); addRegisteredGeoFields<fvPatchField, volMesh>(newSet);
selection_.transfer(newSet);
(void)fieldSelection::checkSelection();
return selection_ != oldSet; return selection_ != oldSet;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -66,17 +66,21 @@ protected:
//- Add registered GeometricField types to selection //- Add registered GeometricField types to selection
template<template<class> class PatchType, class MeshType> template<template<class> class PatchType, class MeshType>
void addRegisteredGeoFields(wordHashSet& set) const; void addRegisteredGeoFields(DynamicList<fieldInfo>& set) const;
public: public:
//- Construct from object registry //- Construct from object registry
volFieldSelection(const objectRegistry& obr); volFieldSelection
(
const objectRegistry& obr,
const bool includeComponents = false
);
//- Destructor //- Destructor
virtual ~volFieldSelection(); virtual ~volFieldSelection() = default;
// Member Functions // Member Functions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -30,7 +30,7 @@ License
template<template<class> class PatchType, class MeshType> template<template<class> class PatchType, class MeshType>
void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields
( (
wordHashSet& set DynamicList<fieldInfo>& set
) const ) const
{ {
addRegistered<GeometricField<scalar, PatchType, MeshType>>(set); addRegistered<GeometricField<scalar, PatchType, MeshType>>(set);

View File

@ -151,7 +151,7 @@ bool Foam::functionObjects::columnAverage::execute()
// Make fields up to date with current selection // Make fields up to date with current selection
fieldSet_.updateSelection(); fieldSet_.updateSelection();
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
columnAverageField<scalar>(fieldName); columnAverageField<scalar>(fieldName);
columnAverageField<vector>(fieldName); columnAverageField<vector>(fieldName);
@ -166,7 +166,7 @@ bool Foam::functionObjects::columnAverage::execute()
bool Foam::functionObjects::columnAverage::write() bool Foam::functionObjects::columnAverage::write()
{ {
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
const word resultName("columnAverage(" + fieldName + ")"); const word resultName("columnAverage(" + fieldName + ")");
const regIOobject* obj = const regIOobject* obj =

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -191,7 +191,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
{ {
fieldSet_.updateSelection(); fieldSet_.updateSelection();
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
transform<scalar>(fieldName); transform<scalar>(fieldName);
transform<vector>(fieldName); transform<vector>(fieldName);
@ -210,9 +210,9 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
bool Foam::functionObjects::fieldCoordinateSystemTransform::write() bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
{ {
forAllConstIters(fieldSet_, iter) for (const word& fieldName : fieldSet_.selectionNames())
{ {
writeObject(transformFieldName(iter())); writeObject(transformFieldName(fieldName));
} }
return true; return true;

View File

@ -60,9 +60,8 @@ void Foam::functionObjects::fieldExtents::writeFileHeader(Ostream& os)
writeCommented(os, "Time"); writeCommented(os, "Time");
forAllConstIters(fieldSet_.selection(), iter) for (const word& fieldName : fieldSet_.selectionNames())
{ {
const word& fieldName = iter();
if (internalField_) if (internalField_)
{ {
writeTabbed(os, fieldName + "_internal"); writeTabbed(os, fieldName + "_internal");
@ -183,7 +182,7 @@ bool Foam::functionObjects::fieldExtents::write()
Log << type() << " " << name() << " write:" << nl; Log << type() << " " << name() << " write:" << nl;
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
calcFieldExtents<scalar>(fieldName, true); calcFieldExtents<scalar>(fieldName, true);
calcFieldExtents<vector>(fieldName); calcFieldExtents<vector>(fieldName);

View File

@ -90,9 +90,8 @@ void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os)
} }
else else
{ {
forAllConstIters(fieldSet_.selection(), iter) for (const word& fieldName : fieldSet_.selectionNames())
{ {
const word& fieldName = iter();
writeTabbed(os, "min(" + fieldName + ')'); writeTabbed(os, "min(" + fieldName + ')');
writeTabbed(os, "max(" + fieldName + ')'); writeTabbed(os, "max(" + fieldName + ')');
} }
@ -153,7 +152,7 @@ bool Foam::functionObjects::fieldMinMax::write()
if (!location_) writeTime(file()); if (!location_) writeTime(file());
Log << type() << " " << name() << " write:" << nl; Log << type() << " " << name() << " write:" << nl;
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
calcMinMaxFields<scalar>(fieldName, mdCmpt); calcMinMaxFields<scalar>(fieldName, mdCmpt);
calcMinMaxFields<vector>(fieldName, mode_); calcMinMaxFields<vector>(fieldName, mode_);

View File

@ -17,6 +17,7 @@ runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C
runTimeControl/runTimeCondition/runTimeCondition/runTimeConditionNew.C runTimeControl/runTimeCondition/runTimeCondition/runTimeConditionNew.C
runTimeControl/runTimeCondition/equationMaxIterCondition/equationMaxIterCondition.C runTimeControl/runTimeCondition/equationMaxIterCondition/equationMaxIterCondition.C
runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C
runTimeControl/runTimeCondition/maxDurationCondition/maxDurationCondition.C
runTimeControl/runTimeCondition/minMaxCondition/minMaxCondition.C runTimeControl/runTimeCondition/minMaxCondition/minMaxCondition.C
runTimeControl/runTimeCondition/averageCondition/averageCondition.C runTimeControl/runTimeCondition/averageCondition/averageCondition.C
runTimeControl/runTimeCondition/minTimeStepCondition/minTimeStepCondition.C runTimeControl/runTimeCondition/minTimeStepCondition/minTimeStepCondition.C

View File

@ -64,7 +64,7 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os)
writeCommented(os, "Time"); writeCommented(os, "Time");
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
writeFileHeader<scalar>(os, fieldName); writeFileHeader<scalar>(os, fieldName);
writeFileHeader<vector>(os, fieldName); writeFileHeader<vector>(os, fieldName);
@ -193,7 +193,7 @@ bool Foam::functionObjects::residuals::execute()
if (writeFields_) if (writeFields_)
{ {
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
initialiseField<scalar>(fieldName); initialiseField<scalar>(fieldName);
initialiseField<vector>(fieldName); initialiseField<vector>(fieldName);
@ -214,7 +214,7 @@ bool Foam::functionObjects::residuals::write()
{ {
writeTime(file()); writeTime(file());
for (const word& fieldName : fieldSet_.selection()) for (const word& fieldName : fieldSet_.selectionNames())
{ {
writeResidual<scalar>(fieldName); writeResidual<scalar>(fieldName);
writeResidual<vector>(fieldName); writeResidual<vector>(fieldName);

View File

@ -41,6 +41,17 @@ namespace runTimeControls
} }
} }
const Foam::Enum
<
Foam::functionObjects::runTimeControls::averageCondition::windowType
>
Foam::functionObjects::runTimeControls::averageCondition::windowTypeNames
{
{ windowType::NONE, "none" },
{ windowType::APPROXIMATE, "approximate" },
{ windowType::EXACT, "exact" }
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -57,86 +68,79 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
fieldNames_(dict.get<wordList>("fields")), fieldNames_(dict.get<wordList>("fields")),
tolerance_(dict.get<scalar>("tolerance")), tolerance_(dict.get<scalar>("tolerance")),
window_(dict.lookupOrDefault<scalar>("window", -1)), window_(dict.lookupOrDefault<scalar>("window", -1)),
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()), windowType_
resetOnRestart_(false) (
window_ > 0 ?
windowTypeNames.read(dict.lookup("windowType"))
: windowType::NONE
),
totalTime_(fieldNames_.size(), scalar(0)),
resetOnRestart_(dict.lookupOrDefault<bool>("resetOnRestart", false)),
nIterStartUp_(dict.lookupOrDefault<label>("nIterStartUp", 10)),
iter_(-1)
{ {
if (resetOnRestart_) dictionary& conditionDict = this->conditionDict();
forAll(fieldNames_, fieldi)
{ {
const dictionary& dict = conditionDict(); const word& fieldName = fieldNames_[fieldi];
forAll(fieldNames_, fieldi) if (resetOnRestart_)
{ {
const word& fieldName = fieldNames_[fieldi]; conditionDict.set(fieldName, dictionary());
}
if (dict.found(fieldName)) else
{
if (conditionDict.found(fieldName))
{ {
const dictionary& valueDict = dict.subDict(fieldName); const dictionary& valueDict = conditionDict.subDict(fieldName);
valueDict.readEntry("totalTime", totalTime_[fieldi]); valueDict.readIfPresent("totalTime", totalTime_[fieldi]);
}
else
{
conditionDict.set(fieldName, dictionary());
} }
} }
} }
conditionDict.readIfPresent("iter", iter_);
} }
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::averageCondition::~averageCondition()
{}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::averageCondition::apply() bool Foam::functionObjects::runTimeControls::averageCondition::apply()
{ {
bool satisfied = true;
if (!active_) if (!active_)
{ {
return satisfied; return true;
} }
scalar dt = obr_.time().deltaTValue(); bool satisfied = iter_ > nIterStartUp_ ? true : false;
if (log_) Info<< " " << type() << ": " << name_ << " averages:" << nl; ++iter_;
const scalar dt = obr_.time().deltaTValue();
Log << " " << type() << ": " << name_ << " averages:" << nl;
DynamicList<label> unprocessedFields(fieldNames_.size()); DynamicList<label> unprocessedFields(fieldNames_.size());
forAll(fieldNames_, fieldi) forAll(fieldNames_, fieldi)
{ {
const word& fieldName(fieldNames_[fieldi]); totalTime_[fieldi] += dt;
scalar Dt = totalTime_[fieldi];
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (window_ > 0)
{
if (Dt - dt >= window_)
{
alpha = (window_ - dt)/window_;
beta = dt/window_;
}
else
{
// Ensure that averaging is performed over window time
// before condition can be satisfied
satisfied = false;
}
}
bool processed = false; bool processed = false;
calc<scalar>(fieldName, alpha, beta, satisfied, processed); calc<scalar>(fieldi, satisfied, processed);
calc<vector>(fieldName, alpha, beta, satisfied, processed); calc<vector>(fieldi, satisfied, processed);
calc<sphericalTensor>(fieldName, alpha, beta, satisfied, processed); calc<sphericalTensor>(fieldi, satisfied, processed);
calc<symmTensor>(fieldName, alpha, beta, satisfied, processed); calc<symmTensor>(fieldi, satisfied, processed);
calc<tensor>(fieldName, alpha, beta, satisfied, processed); calc<tensor>(fieldi, satisfied, processed);
if (!processed) if (!processed)
{ {
unprocessedFields.append(fieldi); unprocessedFields.append(fieldi);
} }
totalTime_[fieldi] += dt;
} }
if (unprocessedFields.size()) if (unprocessedFields.size())
@ -145,14 +149,13 @@ bool Foam::functionObjects::runTimeControls::averageCondition::apply()
<< "From function object: " << functionObjectName_ << nl << "From function object: " << functionObjectName_ << nl
<< "Unprocessed fields:" << nl; << "Unprocessed fields:" << nl;
forAll(unprocessedFields, i) for (const label fieldi : unprocessedFields)
{ {
label fieldi = unprocessedFields[i];
Info<< " " << fieldNames_[fieldi] << nl; Info<< " " << fieldNames_[fieldi] << nl;
} }
} }
if (log_) Info<< endl; Log << endl;
return satisfied; return satisfied;
} }
@ -166,7 +169,6 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
{ {
const word& fieldName = fieldNames_[fieldi]; const word& fieldName = fieldNames_[fieldi];
// value dictionary should be present - mean values are written there
if (conditionDict.found(fieldName)) if (conditionDict.found(fieldName))
{ {
dictionary& valueDict = conditionDict.subDict(fieldName); dictionary& valueDict = conditionDict.subDict(fieldName);
@ -179,6 +181,8 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
conditionDict.add(fieldName, valueDict); conditionDict.add(fieldName, valueDict);
} }
} }
conditionDict.set("iter", iter_);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,7 +39,7 @@ SourceFiles
#include "runTimeCondition.H" #include "runTimeCondition.H"
#include "Switch.H" #include "Switch.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,6 +58,20 @@ class averageCondition
: :
public runTimeCondition public runTimeCondition
{ {
public:
// Public enumerations
enum class windowType
{
NONE,
APPROXIMATE,
EXACT
};
static const Enum<windowType> windowTypeNames;
protected: protected:
// Protected data // Protected data
@ -74,12 +88,20 @@ protected:
//- Averaging window //- Averaging window
const scalar window_; const scalar window_;
//- Averaging window type
windowType windowType_;
//- Average time per field //- Average time per field
List<scalar> totalTime_; List<scalar> totalTime_;
//- Reset the averaging process on restart flag //- Reset the averaging process on restart flag
Switch resetOnRestart_; Switch resetOnRestart_;
//- Number of start-up iterations before allowing satisfied checks
label nIterStartUp_;
//- Current iteration count
label iter_;
// Protected Member Functions // Protected Member Functions
@ -87,9 +109,7 @@ protected:
template<class Type> template<class Type>
void calc void calc
( (
const word& fieldName, const label fieldi,
const scalar alpha,
const scalar beta,
bool& satisfied, bool& satisfied,
bool& processed bool& processed
); );
@ -110,7 +130,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~averageCondition(); virtual ~averageCondition() = default;
// Public Member Functions // Public Member Functions

View File

@ -23,18 +23,21 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Time.H"
#include "FIFOStack.H"
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::functionObjects::runTimeControls::averageCondition::calc void Foam::functionObjects::runTimeControls::averageCondition::calc
( (
const word& fieldName, const label fieldi,
const scalar alpha,
const scalar beta,
bool& satisfied, bool& satisfied,
bool& processed bool& processed
) )
{ {
const word& fieldName = fieldNames_[fieldi];
const word valueType = const word valueType =
state_.objectResultType(functionObjectName_, fieldName); state_.objectResultType(functionObjectName_, fieldName);
@ -43,22 +46,124 @@ void Foam::functionObjects::runTimeControls::averageCondition::calc
return; return;
} }
Type currentValue = const scalar dt = obr_.time().deltaTValue();
state_.getObjectResult<Type>(functionObjectName_, fieldName);
const Type currentValue =
state_.getObjectResult<Type>(functionObjectName_, fieldName);
const word meanName(fieldName + "Mean"); const word meanName(fieldName + "Mean");
// Current mean value
Type meanValue = state_.getResult<Type>(meanName); Type meanValue = state_.getResult<Type>(meanName);
meanValue = alpha*meanValue + beta*currentValue;
switch (windowType_)
{
case windowType::NONE:
{
const scalar Dt = totalTime_[fieldi];
const scalar alpha = (Dt - dt)/Dt;
const scalar beta = dt/Dt;
meanValue = alpha*meanValue + beta*currentValue;
break;
}
case windowType::APPROXIMATE:
{
const scalar Dt = totalTime_[fieldi];
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (Dt - dt >= window_)
{
alpha = (window_ - dt)/window_;
beta = dt/window_;
}
else
{
// Ensure that averaging is performed over window time
// before condition can be satisfied
satisfied = false;
}
meanValue = alpha*meanValue + beta*currentValue;
totalTime_[fieldi] += dt;
break;
}
case windowType::EXACT:
{
FIFOStack<scalar> windowTimes;
FIFOStack<Type> windowValues;
dictionary& dict = this->conditionDict().subDict(fieldName);
dict.readIfPresent("windowTimes", windowTimes);
dict.readIfPresent("windowValues", windowValues);
// Increment time for all existing values
for (scalar& dti : windowTimes)
{
dti += dt;
}
// Remove any values outside the window
bool removeValue = true;
while (removeValue && windowTimes.size())
{
removeValue = windowTimes.first() > window_;
if (removeValue)
{
windowTimes.pop();
windowValues.pop();
}
}
// Add the current value
windowTimes.push(dt);
windowValues.push(currentValue);
// Calculate the window average
typename FIFOStack<scalar>::const_iterator timeIter =
windowTimes.begin();
typename FIFOStack<Type>::const_iterator valueIter =
windowValues.begin();
meanValue = pTraits<Type>::zero;
Type valueOld(pTraits<Type>::zero);
for
(
label i = 0;
timeIter != windowTimes.end();
++i, ++timeIter, ++valueIter
)
{
const Type& value = valueIter();
const scalar dt = timeIter();
meanValue += dt*value;
if (i)
{
meanValue -= dt*valueOld;
}
valueOld = value;
}
meanValue /= windowTimes.first();
// Store the state information for the next step
dict.set("windowTimes", windowTimes);
dict.set("windowValues", windowValues);
break;
}
}
scalar delta = mag(meanValue - currentValue); scalar delta = mag(meanValue - currentValue);
if (log_) Log << " " << meanName << ": " << meanValue
{ << ", delta: " << delta << nl;
Info<< " " << meanName << ": " << meanValue
<< ", delta: " << delta << nl;
}
// Note: Writing result to owner function object and not the local run-time
// condition
state_.setResult(meanName, meanValue); state_.setResult(meanName, meanValue);
if (delta > tolerance_) if (delta > tolerance_)

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,10 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H" #include "Time.H"
#include "volFields.H"
#define SetResidual(Type) \
setResidual<Type>(mesh, solverDict, fieldName, component, canSet, residual);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -66,8 +70,8 @@ operatingModeNames
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: Foam::functionObjects::runTimeControls::
equationInitialResidualCondition equationInitialResidualCondition::equationInitialResidualCondition
( (
const word& name, const word& name,
const objectRegistry& obr, const objectRegistry& obr,
@ -76,12 +80,14 @@ equationInitialResidualCondition
) )
: :
runTimeCondition(name, obr, dict, state), runTimeCondition(name, obr, dict, state),
fieldNames_(dict.get<wordList>("fields")), fieldSelection_(obr, true),
value_(dict.get<scalar>("value")), value_(dict.get<scalar>("value")),
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)), timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
mode_(operatingModeNames.get("mode", dict)) mode_(operatingModeNames.get("mode", dict))
{ {
if (fieldNames_.size()) fieldSelection_.read(dict);
if (fieldSelection_.size())
{ {
timeStart_ = obr.time().userTimeToTime(timeStart_); timeStart_ = obr.time().userTimeToTime(timeStart_);
} }
@ -95,18 +101,13 @@ equationInitialResidualCondition
} }
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
~equationInitialResidualCondition()
{}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: bool Foam::functionObjects::runTimeControls::
apply() equationInitialResidualCondition::apply()
{ {
fieldSelection_.updateSelection();
bool satisfied = false; bool satisfied = false;
if (!active_) if (!active_)
@ -123,16 +124,25 @@ apply()
const fvMesh& mesh = refCast<const fvMesh>(obr_); const fvMesh& mesh = refCast<const fvMesh>(obr_);
const dictionary& solverDict = mesh.solverPerformanceDict(); const dictionary& solverDict = mesh.solverPerformanceDict();
List<scalar> result(fieldNames_.size(), -VGREAT); const auto& selection = fieldSelection_.selection();
List<scalar> result(selection.size(), -VGREAT);
forAll(fieldNames_, fieldi) forAll(selection, fieldi)
{ {
const word& fieldName = fieldNames_[fieldi]; const auto& fieldInfo = selection[fieldi];
const word& fieldName = fieldInfo.name();
if (solverDict.found(fieldName)) if (solverDict.found(fieldName))
{ {
const List<solverPerformance> sp(solverDict.lookup(fieldName)); label component = fieldInfo.component();
const scalar residual = sp.first().initialResidual(); scalar residual = VGREAT;
bool canSet = true;
SetResidual(scalar);
SetResidual(vector);
SetResidual(symmTensor);
SetResidual(sphericalTensor);
SetResidual(tensor);
result[fieldi] = residual; result[fieldi] = residual;
switch (mode_) switch (mode_)
@ -171,7 +181,9 @@ apply()
{ {
WarningInFunction WarningInFunction
<< "Initial residual data not found for field " << "Initial residual data not found for field "
<< fieldNames_[i] << endl; << selection[i].name()
<< ". Solver dictionary contains " << solverDict.sortedToc()
<< endl;
} }
else else
{ {
@ -190,32 +202,26 @@ apply()
if (satisfied && valid) if (satisfied && valid)
{ {
if (log_) Log << type() << ": " << name_
{ << ": satisfied using threshold value: " << value_ << nl;
Info<< type() << ": " << name_
<< ": satisfied using threshold value: " << value_ << nl;
}
forAll(result, resulti) forAll(result, resulti)
{ {
if (result[resulti] > 0) if (result[resulti] > 0)
{ {
if (log_) Log << " field: " << selection[resulti].name()
{ << ", residual: " << result[resulti] << nl;
Info<< " field: " << fieldNames_[resulti]
<< ", residual: " << result[resulti] << nl;
}
} }
} }
if (log_) Info<< endl; Log << endl;
} }
return satisfied; return satisfied;
} }
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition:: void Foam::functionObjects::runTimeControls::
write() equationInitialResidualCondition::write()
{ {
// do nothing // do nothing
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,12 +37,15 @@ SourceFiles
#define functionObjects_runTimeControls_equationInitialResidualCondition_H #define functionObjects_runTimeControls_equationInitialResidualCondition_H
#include "runTimeCondition.H" #include "runTimeCondition.H"
#include "Enum.H" #include "solverFieldSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
class fvMesh;
namespace functionObjects namespace functionObjects
{ {
namespace runTimeControls namespace runTimeControls
@ -71,8 +74,8 @@ protected:
// Protected data // Protected data
//- Field name //- Field names
const wordList fieldNames_; solverFieldSelection fieldSelection_;
//- Value to compare //- Value to compare
const scalar value_; const scalar value_;
@ -84,6 +87,21 @@ protected:
operatingMode mode_; operatingMode mode_;
// Protected Member Functions
//- Set the residual (scalar) value
template<class Type>
void setResidual
(
const fvMesh& mesh,
const dictionary& dict,
const word& fieldName,
const label componenti,
bool& canSet,
scalar& residual
) const;
public: public:
//- Runtime type information //- Runtime type information
@ -99,7 +117,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~equationInitialResidualCondition(); virtual ~equationInitialResidualCondition() = default;
// Public Member Functions // Public Member Functions
@ -120,6 +138,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "equationInitialResidualConditionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fvMesh.H"
template<class Type>
void Foam::functionObjects::runTimeControls::
equationInitialResidualCondition::setResidual
(
const fvMesh& mesh,
const dictionary& dict,
const word& fieldName,
const label componenti,
bool& canSet,
scalar& residual
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
if (canSet && mesh.foundObject<volFieldType>(fieldName))
{
const List<SolverPerformance<Type>> sp(dict.lookup(fieldName));
const Type& allComponents = sp.first().initialResidual();
if (componenti != -1)
{
if (componenti > pTraits<Type>::nComponents - 1)
{
FatalErrorInFunction
<< "Requested component [" << componenti
<< "] for field " << fieldName
<< " is out of range 0.."
<< pTraits<Type>::nComponents - 1
<< exit(FatalError);
}
residual = component(allComponents, componenti);
}
else
{
residual = cmptMax(allComponents);
}
canSet = false;
}
}

View File

@ -76,13 +76,6 @@ equationMaxIterCondition
} }
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
~equationMaxIterCondition()
{}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply() bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
@ -148,24 +141,18 @@ bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
if (satisfied && valid) if (satisfied && valid)
{ {
if (log_) Log << type() << ": " << name_
{ << ": satisfied using threshold value: " << threshold_ << nl;
Info<< type() << ": " << name_
<< ": satisfied using threshold value: " << threshold_ << nl;
}
forAll(result, resulti) forAll(result, resulti)
{ {
if (result[resulti] != -1) if (result[resulti] != -1)
{ {
if (log_) Log << " field: " << fieldNames_[resulti]
{ << ", iterations: " << result[resulti] << nl;
Info<< " field: " << fieldNames_[resulti]
<< ", iterations: " << result[resulti] << nl;
}
} }
} }
if (log_) Info<< endl; Log << endl;
} }
return satisfied; return satisfied;

View File

@ -84,7 +84,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~equationMaxIterCondition(); virtual ~equationMaxIterCondition() = default;
// Public Member Functions // Public Member Functions

View File

@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "maxDurationCondition.H"
#include "addToRunTimeSelectionTable.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace runTimeControls
{
defineTypeNameAndDebug(maxDurationCondition, 0);
addToRunTimeSelectionTable
(
runTimeCondition,
maxDurationCondition,
dictionary
);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::maxDurationCondition::
maxDurationCondition
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
stateFunctionObject& state
)
:
runTimeCondition(name, obr, dict, state),
duration_(dict.get<scalar>("duration")),
startTime_(-1),
initialised_(false),
resetOnRestart_(dict.lookupOrDefault("resetOnRestart", false))
{
if
(
!resetOnRestart_
&& conditionDict().readIfPresent("startTime", startTime_))
{
initialised_ = true;
}
duration_ = obr_.time().userTimeToTime(duration_);
}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::maxDurationCondition::apply()
{
if (!active_)
{
return true;
}
if (!initialised_)
{
startTime_ = obr_.time().value();
initialised_ = true;
}
scalar delta = obr_.time().value() - startTime_;
delta = obr_.time().timeToUserTime(delta);
Log << " " << type() << ": " << name_ << nl
<< " Completed " << delta << " out of " << duration_ << nl;
return delta >= duration_;
}
void Foam::functionObjects::runTimeControls::maxDurationCondition::write()
{
if (initialised_)
{
conditionDict().set("startTime", startTime_);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::runTimeControls::maxDurationCondition
Description
Activated after a user-specified duration
SourceFiles
maxDurationCondition.H
maxDurationCondition.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_runTimeConditions_maxDurationCondition_H
#define functionObjects_runTimeConditions_maxDurationCondition_H
#include "runTimeCondition.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace runTimeControls
{
/*---------------------------------------------------------------------------*\
Class maxDurationCondition Declaration
\*---------------------------------------------------------------------------*/
class maxDurationCondition
:
public runTimeCondition
{
protected:
// Protected data
//- Duration
scalar duration_;
//- Time when the condition is activated
scalar startTime_;
//- Initialisation flag
bool initialised_;
//- Reset on restart (ignores any state information)
Switch resetOnRestart_;
public:
//- Runtime type information
TypeName("maxDuration");
//- Constructor
maxDurationCondition
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
stateFunctionObject& state
);
//- Destructor
virtual ~maxDurationCondition() = default;
// Public Member Functions
//- Apply the condition
virtual bool apply();
//- Write
virtual void write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace runTimeControls
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -90,12 +90,6 @@ Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
{} {}
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::minMaxCondition::~minMaxCondition()
{}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::minMaxCondition::apply() bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
@ -107,10 +101,8 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
return satisfied; return satisfied;
} }
forAll(fieldNames_, fieldi) for (const word& fieldName :fieldNames_)
{ {
const word& fieldName = fieldNames_[fieldi];
const word valueType = const word valueType =
state_.objectResultType(functionObjectName_, fieldName); state_.objectResultType(functionObjectName_, fieldName);
@ -153,13 +145,10 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
} }
} }
if (log_) Log << " " << type() << ": " << modeTypeNames_[mode_] << " "
{ << fieldName << ": value = " << v
Info<< " " << type() << ": " << modeTypeNames_[mode_] << " " << ", threshold value = " << value_
<< fieldName << ": value = " << v << ", satisfied = " << ok << endl;
<< ", threshold value = " << value_
<< ", satisfied = " << ok << endl;
}
satisfied = satisfied && ok; satisfied = satisfied && ok;
} }

View File

@ -112,7 +112,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~minMaxCondition(); virtual ~minMaxCondition() = default;
// Public Member Functions // Public Member Functions

View File

@ -63,13 +63,6 @@ minTimeStepCondition
{} {}
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::minTimeStepCondition::
~minTimeStepCondition()
{}
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply() bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply()

View File

@ -78,7 +78,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~minTimeStepCondition(); virtual ~minTimeStepCondition() = default;
// Public Member Functions // Public Member Functions

View File

@ -84,14 +84,8 @@ Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
state_(state), state_(state),
active_(dict.lookupOrDefault("active", true)), active_(dict.lookupOrDefault("active", true)),
conditionDict_(setConditionDict()), conditionDict_(setConditionDict()),
log_(dict.lookupOrDefault("log", true)), groupID_(dict.lookupOrDefault("groupID", -1)),
groupID_(dict.lookupOrDefault("groupID", -1)) log(dict.lookupOrDefault("log", true))
{}
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::runTimeCondition::~runTimeCondition()
{} {}

View File

@ -78,9 +78,6 @@ protected:
//- Reference to the condition dictionary //- Reference to the condition dictionary
dictionary& conditionDict_; dictionary& conditionDict_;
//- Switch to send output to Info
Switch log_;
//- Group index - if applied, all conditions in a group must be //- Group index - if applied, all conditions in a group must be
// satisfied before condition is met // satisfied before condition is met
label groupID_; label groupID_;
@ -129,7 +126,7 @@ public:
); );
//- Destructor //- Destructor
virtual ~runTimeCondition(); virtual ~runTimeCondition() = default;
//- Selector //- Selector
static autoPtr<runTimeCondition> New static autoPtr<runTimeCondition> New
@ -140,6 +137,11 @@ public:
stateFunctionObject& state stateFunctionObject& state
); );
// Public Data
//- Switch to send output to Info
Switch log;
// Public Member Functions // Public Member Functions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -44,6 +44,15 @@ namespace runTimeControls
} }
} }
Foam::Enum
<
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedAction
>
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedActionNames
{
{ satisfiedAction::END, "end"},
{ satisfiedAction::SET_TRIGGER, "setTrigger"},
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -58,18 +67,15 @@ Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
conditions_(), conditions_(),
groupMap_(), groupMap_(),
nWriteStep_(0), nWriteStep_(0),
writeStepI_(0) writeStepI_(0),
satisfiedAction_(satisfiedAction::END),
triggerIndex_(labelMin),
active_(getObjectProperty(name, "active", true))
{ {
read(dict); read(dict);
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::runTimeControls::runTimeControl::~runTimeControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::runTimeControls::runTimeControl::read bool Foam::functionObjects::runTimeControls::runTimeControl::read
@ -77,68 +83,101 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
const dictionary& dict const dictionary& dict
) )
{ {
fvMeshFunctionObject::read(dict); if (functionObject::postProcess)
const dictionary& conditionsDict = dict.subDict("conditions");
const wordList conditionNames(conditionsDict.toc());
conditions_.setSize(conditionNames.size());
label uniqueGroupi = 0;
forAll(conditionNames, conditioni)
{ {
const word& conditionName = conditionNames[conditioni]; Info<< "Deactivated " << name()
const dictionary& dict = conditionsDict.subDict(conditionName); << " function object for post-processing"
conditions_.set
(
conditioni,
runTimeCondition::New(conditionName, obr_, dict, *this)
);
label groupi = conditions_[conditioni].groupID();
if (groupMap_.insert(groupi, uniqueGroupi))
{
uniqueGroupi++;
}
}
dict.readIfPresent("nWriteStep", nWriteStep_);
// Check that some conditions are set
if (conditions_.empty())
{
Info<< type() << " " << name() << " output:" << nl
<< " No conditions present" << nl
<< endl; << endl;
return false;
} }
else
if (fvMeshFunctionObject::read(dict))
{ {
// Check that at least one condition is active const dictionary& conditionsDict = dict.subDict("conditions");
bool active = false; const wordList conditionNames(conditionsDict.toc());
forAll(conditions_, conditioni) conditions_.setSize(conditionNames.size());
label uniqueGroupi = 0;
forAll(conditionNames, conditioni)
{ {
if (conditions_[conditioni].active()) const word& conditionName = conditionNames[conditioni];
const dictionary& dict = conditionsDict.subDict(conditionName);
conditions_.set
(
conditioni,
runTimeCondition::New(conditionName, obr_, dict, *this)
);
label groupi = conditions_[conditioni].groupID();
if (groupMap_.insert(groupi, uniqueGroupi))
{ {
active = true; ++uniqueGroupi;
break;
} }
} }
if (!active) dict.readIfPresent("nWriteStep", nWriteStep_);
// Check that some conditions are set
if (conditions_.empty())
{ {
Info<< type() << " " << name() << " output:" << nl Info<< type() << " " << name() << " output:" << nl
<< " All conditions are inactive" << nl << " No conditions present" << nl
<< endl; << endl;
} }
else
{
// Check that at least one condition is active
bool check = false;
for (const auto& condition : conditions_)
{
if (condition.active())
{
check = true;
break;
}
}
if (!check)
{
Info<< type() << " " << name() << " output:" << nl
<< " All conditions are inactive" << nl
<< endl;
}
}
// Set the action to perform when all conditions are satisfied
// - set to end fro backwards compatibility with v1806
satisfiedAction_ =
satisfiedActionNames.lookupOrDefault
(
"satisfiedAction",
dict,
satisfiedAction::END
);
if (satisfiedAction_ == satisfiedAction::SET_TRIGGER)
{
triggerIndex_ = readLabel(dict.lookup("trigger"));
}
return true;
} }
return true; return false;
} }
bool Foam::functionObjects::runTimeControls::runTimeControl::execute() bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
{ {
if (!active_)
{
return true;
}
Info<< type() << " " << name() << " output:" << nl; Info<< type() << " " << name() << " output:" << nl;
// IDs of satisfied conditions // IDs of satisfied conditions
@ -200,33 +239,66 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
if (done) if (done)
{ {
forAll(IDs, conditioni) for (label conditioni : IDs)
{ {
Info<< " " << conditions_[conditioni].type() << ": " Info<< " " << conditions_[conditioni].type() << ": "
<< conditions_[conditioni].name() << conditions_[conditioni].name()
<< " condition satisfied" << nl; << " condition satisfied" << nl;
} }
switch (satisfiedAction_)
// Set to write a data dump or finalise the calculation
Time& time = const_cast<Time&>(time_);
if (writeStepI_ < nWriteStep_ - 1)
{ {
writeStepI_++; case satisfiedAction::END:
Info<< " Writing fields - step " << writeStepI_ << nl; {
time.writeNow(); // Set to write a data dump or finalise the calculation
} Time& time = const_cast<Time&>(time_);
else
{ if (writeStepI_ < nWriteStep_ - 1)
Info<< " Stopping calculation" << nl {
<< " Writing fields - final step" << nl; ++writeStepI_;
time.writeAndEnd(); Info<< " Writing fields - step " << writeStepI_ << nl;
time.writeNow();
}
else
{
Info<< " Stopping calculation" << nl
<< " Writing fields";
if (nWriteStep_ != 0)
{
Info<< " - final step" << nl;
}
else
{
Info<< nl;
}
Info<< endl;
active_ = false;
// Write any registered objects and set the end-time
time.writeAndEnd();
// Trigger any function objects
time.run();
}
break;
}
case satisfiedAction::SET_TRIGGER:
{
Info<< " Setting trigger " << triggerIndex_ << nl;
setTrigger(triggerIndex_);
// Deactivate the model
active_ = false;
setProperty("active", active_);
break;
}
} }
} }
else else
{ {
Info<< " Conditions not met - calculations proceeding" << nl; Info<< " Conditions not met" << nl;
} }
Info<< endl; Info<< endl;
@ -237,9 +309,9 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
bool Foam::functionObjects::runTimeControls::runTimeControl::write() bool Foam::functionObjects::runTimeControls::runTimeControl::write()
{ {
forAll(conditions_, conditioni) for (auto& condition : conditions_)
{ {
conditions_[conditioni].write(); condition.write();
} }
return true; return true;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,7 +32,7 @@ Description
user-specified conditions. user-specified conditions.
Optionally specify a number of write steps before the calculation is Optionally specify a number of write steps before the calculation is
terminated. Here, a write is performed each time that all conditons are terminated. Here, a write is performed each time that all conditions are
satisfied. satisfied.
SourceFiles SourceFiles
@ -45,6 +45,7 @@ SourceFiles
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "Map.H" #include "Map.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,6 +67,21 @@ class runTimeControl
: :
public fvMeshFunctionObject public fvMeshFunctionObject
{ {
public:
// Public enumerations
enum class satisfiedAction
{
END,
SET_TRIGGER
};
static Enum<satisfiedAction> satisfiedActionNames;
private:
// Private data // Private data
//- List of conditions to satisfy //- List of conditions to satisfy
@ -80,6 +96,17 @@ class runTimeControl
//- Current number of steps written //- Current number of steps written
label writeStepI_; label writeStepI_;
//- Action to take when conditions are satisfied
satisfiedAction satisfiedAction_;
//- Trigger index if satisfiedAction is setTrigger
label triggerIndex_;
//- Active flag
// Used in the trigger case to bypass any evaluations after the
// trigger has been set
bool active_;
// Private Member Functions // Private Member Functions
@ -98,8 +125,7 @@ public:
// Constructors // Constructors
//- Construct for given objectRegistry and dictionary. //- Construct for given objectRegistry and dictionary
// Allow the possibility to load fields from files
runTimeControl runTimeControl
( (
const word& name, const word& name,
@ -109,7 +135,7 @@ public:
//- Destructor //- Destructor
virtual ~runTimeControl(); virtual ~runTimeControl() = default;
// Member Functions // Member Functions

View File

@ -48,6 +48,9 @@ runTimeModifiable true;
functions functions
{ {
#include "forceCoeffs" #include "forceCoeffs"
#include "fieldAverage"
#include "runTimeControls"
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,18 @@
fieldAverage1
{
type fieldAverage;
libs ("libfieldFunctionObjects.so");
triggerStart 1;
timeStart 500;
controlMode timeOrTrigger;
writeControl writeTime;
fields
(
U
{
base iteration;
mean on;
prime2Mean off;
}
);
}

View File

@ -0,0 +1,55 @@
runTimeControl1
{
type runTimeControl;
libs ("libutilityFunctionObjects.so");
conditions
{
condition1
{
type average;
functionObject forceCoeffs1;
fields (Cd);
tolerance 1e-3;
window 20;
windowType exact;
}
}
satisfiedAction setTrigger;
trigger 1;
}
runTimeControl2
{
type runTimeControl;
libs ("libutilityFunctionObjects.so");
controlMode trigger;
triggerStart 1;
conditions
{
condition1
{
type maxDuration;
duration 100;
}
}
satisfiedAction end;
}
/*
runTimeControl3
{
type runTimeControl;
libs ("libutilityFunctionObjects.so");
conditions
{
condition1
{
type equationInitialResidual;
fields (U.component(0));
value 1e-02;
mode minimum;
}
}
satisfiedAction end;
}
*/