mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -164,17 +164,22 @@ int main(int argc, char *argv[])
|
||||
functionObjects::fileFieldSelection fields(mesh);
|
||||
if (args.found("fields"))
|
||||
{
|
||||
fields.insert(args.getList<wordRe>("fields"));
|
||||
fields.resetFieldFilters
|
||||
(
|
||||
HashSet<wordRe>(args.getList<wordRe>("fields"))
|
||||
);
|
||||
}
|
||||
if (args.found("field"))
|
||||
{
|
||||
fields.insert(args.opt<wordRe>("field"));
|
||||
fields.resetFieldFilters(args.opt<wordRe>("field"));
|
||||
}
|
||||
|
||||
// Externally stored dictionary for functionObjectList
|
||||
// if not constructed from runTime
|
||||
dictionary functionsDict;
|
||||
|
||||
HashSet<wordRe> fieldFilters(fields.filters());
|
||||
|
||||
// Construct functionObjectList
|
||||
autoPtr<functionObjectList> functionsPtr
|
||||
(
|
||||
@ -183,7 +188,7 @@ int main(int argc, char *argv[])
|
||||
args,
|
||||
runTime,
|
||||
functionsDict,
|
||||
fields
|
||||
fieldFilters // include any additional command-line fields
|
||||
)
|
||||
);
|
||||
|
||||
@ -193,8 +198,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< "Time = " << runTime.timeName() << endl;
|
||||
|
||||
fields.updateSelection();
|
||||
|
||||
if (mesh.readUpdate() != polyMesh::UNCHANGED)
|
||||
{
|
||||
// Update functionObjectList if mesh changes
|
||||
@ -205,10 +208,14 @@ int main(int argc, char *argv[])
|
||||
args,
|
||||
runTime,
|
||||
functionsDict,
|
||||
fields
|
||||
fieldFilters
|
||||
);
|
||||
}
|
||||
|
||||
fields.resetFieldFilters(fieldFilters);
|
||||
|
||||
fields.updateSelection();
|
||||
|
||||
const bool throwingIOErr = FatalIOError.throwExceptions();
|
||||
|
||||
try
|
||||
@ -218,7 +225,7 @@ int main(int argc, char *argv[])
|
||||
args,
|
||||
runTime,
|
||||
mesh,
|
||||
fields.selection(),
|
||||
fields.selectionNames(),
|
||||
functionsPtr(),
|
||||
timei == timeDirs.size()-1
|
||||
);
|
||||
|
||||
@ -458,6 +458,15 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::functionObjectList::triggerIndex() const
|
||||
{
|
||||
label triggeri = labelMin;
|
||||
stateDict().readIfPresent("triggerIndex", triggeri);
|
||||
|
||||
return triggeri;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectList::resetState()
|
||||
{
|
||||
// Reset (re-read) the state dictionary
|
||||
|
||||
@ -174,6 +174,9 @@ public:
|
||||
//- Access to the functionObjects
|
||||
using PtrList<functionObject>::operator[];
|
||||
|
||||
//- Return the current trigger index (read from the stateDict)
|
||||
label triggerIndex() const;
|
||||
|
||||
//- Reset/read state dictionary for current time
|
||||
void resetState();
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
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
|
||||
(
|
||||
const word& entryName
|
||||
@ -177,8 +205,8 @@ Foam::functionObjects::stateFunctionObject::objectResultEntries() const
|
||||
}
|
||||
|
||||
|
||||
Foam::List<Foam::word> Foam::functionObjects::stateFunctionObject::
|
||||
objectResultEntries
|
||||
Foam::List<Foam::word>
|
||||
Foam::functionObjects::stateFunctionObject::objectResultEntries
|
||||
(
|
||||
const word& objectName
|
||||
) const
|
||||
@ -210,5 +238,68 @@ objectResultEntries
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -125,6 +125,12 @@ public:
|
||||
//- Return true if the property exists
|
||||
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
|
||||
bool getDict
|
||||
(
|
||||
@ -244,6 +250,15 @@ public:
|
||||
|
||||
//- Return result entries for named object
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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 * * * * * * * * * * * * * * //
|
||||
|
||||
@ -51,6 +60,13 @@ void Foam::functionObjects::timeControl::readControls()
|
||||
{
|
||||
timeEnd_ = time_.userTimeToTime(timeEnd_);
|
||||
}
|
||||
|
||||
if (dict_.readIfPresent("triggerStart", triggerStart_))
|
||||
{
|
||||
dict_.readIfPresent("triggerEnd", triggerEnd_);
|
||||
controlMode_ = controlModeNames_.read(dict_.lookup("controlMode"));
|
||||
}
|
||||
|
||||
deltaTCoeff_ = GREAT;
|
||||
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
|
||||
{
|
||||
@ -70,9 +86,41 @@ void Foam::functionObjects::timeControl::readControls()
|
||||
|
||||
bool Foam::functionObjects::timeControl::active() const
|
||||
{
|
||||
return
|
||||
label triggeri = time_.functionObjects().triggerIndex();
|
||||
|
||||
bool inTime =
|
||||
time_.value() >= (timeStart_ - 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),
|
||||
time_(t),
|
||||
dict_(dict),
|
||||
controlMode_(controlMode::TIME),
|
||||
timeStart_(-VGREAT),
|
||||
timeEnd_(VGREAT),
|
||||
triggerStart_(labelMax),
|
||||
triggerEnd_(labelMax),
|
||||
nStepsToStartTimeChange_(labelMax),
|
||||
executeControl_(t, dict, "execute"),
|
||||
writeControl_(t, dict, "write"),
|
||||
@ -426,6 +477,8 @@ bool Foam::functionObjects::timeControl::entriesPresent(const dictionary& dict)
|
||||
|| Foam::timeControl::entriesPresent(dict, "execute")
|
||||
|| dict.found("timeStart")
|
||||
|| dict.found("timeEnd")
|
||||
|| dict.found("triggerStart")
|
||||
|| dict.found("triggerEnd")
|
||||
)
|
||||
{
|
||||
return true;
|
||||
@ -681,7 +734,7 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
|
||||
|
||||
// Set time, deltaT adjustments for writeInterval purposes
|
||||
// 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)
|
||||
{
|
||||
@ -746,12 +799,7 @@ bool Foam::functionObjects::timeControl::read(const dictionary& dict)
|
||||
|
||||
bool Foam::functionObjects::timeControl::filesModified() const
|
||||
{
|
||||
bool mod = false;
|
||||
if (active())
|
||||
{
|
||||
mod = foPtr_->filesModified();
|
||||
}
|
||||
return mod;
|
||||
return active() ? foPtr_->filesModified() : false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -75,6 +75,25 @@ class timeControl
|
||||
:
|
||||
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
|
||||
|
||||
//- Reference to the time database
|
||||
@ -86,12 +105,21 @@ class timeControl
|
||||
|
||||
// Optional user inputs
|
||||
|
||||
//- Control mode (combination of time/trigger behaviour)
|
||||
controlMode controlMode_;
|
||||
|
||||
//- Activation time - defaults to -VGREAT
|
||||
scalar timeStart_;
|
||||
|
||||
//- De-activation time - defaults to VGREAT
|
||||
scalar timeEnd_;
|
||||
|
||||
//- Activation trigger index - defaults to labelMin
|
||||
label triggerStart_;
|
||||
|
||||
//- De-activation trigger index - defaults to labelMax
|
||||
label triggerEnd_;
|
||||
|
||||
//- Max time step change
|
||||
scalar deltaTCoeff_;
|
||||
|
||||
|
||||
@ -97,10 +97,10 @@ $(faceToCell)/MeshObjects/centredCFCFaceToCellStencilObject.C
|
||||
|
||||
functionObjects/fvMeshFunctionObject/fvMeshFunctionObject.C
|
||||
functionObjects/volRegion/volRegion.C
|
||||
functionObjects/fieldSelection/fieldSelection.C
|
||||
functionObjects/fieldSelection/fileFieldSelection.C
|
||||
functionObjects/fieldSelection/volFieldSelection.C
|
||||
functionObjects/fieldSelection/solverFieldSelection.C
|
||||
functionObjects/fieldSelections/fieldSelection/fieldSelection.C
|
||||
functionObjects/fieldSelections/fileFieldSelection/fileFieldSelection.C
|
||||
functionObjects/fieldSelections/volFieldSelection/volFieldSelection.C
|
||||
functionObjects/fieldSelections/solverFieldSelection/solverFieldSelection.C
|
||||
|
||||
fvPatchFields = fields/fvPatchFields
|
||||
$(fvPatchFields)/fvPatchField/fvPatchFields.C
|
||||
|
||||
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -27,6 +27,11 @@ Class
|
||||
Description
|
||||
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
|
||||
fieldSelection.C
|
||||
|
||||
@ -35,8 +40,9 @@ SourceFiles
|
||||
#ifndef functionObjects_fieldSelection_H
|
||||
#define functionObjects_fieldSelection_H
|
||||
|
||||
#include "fieldInfo.H"
|
||||
#include "DynamicList.H"
|
||||
#include "HashSet.H"
|
||||
#include "wordRe.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -55,7 +61,7 @@ namespace functionObjects
|
||||
|
||||
class fieldSelection
|
||||
:
|
||||
public HashSet<wordRe>
|
||||
public List<fieldInfo>
|
||||
{
|
||||
private:
|
||||
|
||||
@ -72,34 +78,49 @@ protected:
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- Flag to indicate whether components are allowed
|
||||
const bool includeComponents_;
|
||||
|
||||
//- Current field selection
|
||||
wordHashSet selection_;
|
||||
List<fieldInfo> selection_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Add registered objects of a given type
|
||||
template<class Type>
|
||||
void addRegistered(wordHashSet& set) const;
|
||||
void addRegistered(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
fieldSelection(const objectRegistry& obr);
|
||||
fieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fieldSelection();
|
||||
virtual ~fieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the cuurent filters
|
||||
inline HashSet<wordRe> filters() const;
|
||||
|
||||
inline const List<fieldInfo>& selection() const;
|
||||
|
||||
//- Return the current field selection
|
||||
const wordHashSet& selection() const
|
||||
{
|
||||
return selection_;
|
||||
}
|
||||
inline wordHashSet selectionNames() const;
|
||||
|
||||
//- 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
|
||||
virtual bool read(const dictionary& dict);
|
||||
@ -110,8 +131,11 @@ public:
|
||||
//- Clear the current selection
|
||||
virtual void clearSelection();
|
||||
|
||||
//- Update the selection using current contents of obr_
|
||||
//- Update the selection
|
||||
virtual bool updateSelection();
|
||||
|
||||
//- Check that all requested fielda have been found
|
||||
virtual bool checkSelection();
|
||||
};
|
||||
|
||||
|
||||
@ -122,6 +146,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "fieldSelectionI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "fieldSelectionTemplates.C"
|
||||
#endif
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,62 +23,37 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fieldSelection.H"
|
||||
#include "objectRegistry.H"
|
||||
#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)
|
||||
inline Foam::HashSet<Foam::wordRe>
|
||||
Foam::functionObjects::fieldSelection::filters() const
|
||||
{
|
||||
dict.readEntry("fields", *this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldSelection::containsPattern() const
|
||||
{
|
||||
for (const wordRe& fieldName : *this)
|
||||
HashSet<wordRe> f;
|
||||
for (const auto fieldInfo : *this)
|
||||
{
|
||||
if (fieldName.isPattern())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
f.insert(fieldInfo.name());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::fieldSelection::updateSelection()
|
||||
{
|
||||
return false;
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -23,7 +23,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DynamicList.H"
|
||||
#include "objectRegistry.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
@ -31,12 +30,21 @@ License
|
||||
template<class Type>
|
||||
void Foam::functionObjects::fieldSelection::addRegistered
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -35,7 +35,7 @@ License
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
@ -52,7 +52,7 @@ void Foam::functionObjects::fileFieldSelection::addInternalFieldTypes
|
||||
|
||||
void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
@ -71,16 +71,11 @@ void Foam::functionObjects::fileFieldSelection::addUniformFieldTypes
|
||||
|
||||
Foam::functionObjects::fileFieldSelection::fileFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
fieldSelection(obr)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
|
||||
fieldSelection(obr, includeComponents)
|
||||
{}
|
||||
|
||||
|
||||
@ -88,19 +83,24 @@ Foam::functionObjects::fileFieldSelection::~fileFieldSelection()
|
||||
|
||||
bool Foam::functionObjects::fileFieldSelection::updateSelection()
|
||||
{
|
||||
wordHashSet oldSet;
|
||||
oldSet.swap(selection_);
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
DynamicList<fieldInfo> newSelection(oldSet.size());
|
||||
|
||||
// Geometric fields
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(selection_);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(selection_);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(selection_);
|
||||
addGeoFieldTypes<fvPatchField, volMesh>(newSelection);
|
||||
addGeoFieldTypes<fvsPatchField, surfaceMesh>(newSelection);
|
||||
addGeoFieldTypes<pointPatchField, pointMesh>(newSelection);
|
||||
|
||||
// Internal fields
|
||||
addInternalFieldTypes(selection_);
|
||||
addInternalFieldTypes(newSelection);
|
||||
|
||||
// Uniform fields
|
||||
addUniformFieldTypes(selection_);
|
||||
addUniformFieldTypes(newSelection);
|
||||
|
||||
selection_.transfer(newSelection);
|
||||
|
||||
(void)fieldSelection::checkSelection();
|
||||
|
||||
return selection_ != oldSet;
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -69,31 +69,35 @@ protected:
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addGeoFieldTypes(wordHashSet& set) const;
|
||||
void addGeoFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered Internal types to selection
|
||||
void addInternalFieldTypes(wordHashSet& set) const;
|
||||
void addInternalFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add registered uniform types to selection
|
||||
void addUniformFieldTypes(wordHashSet& set) const;
|
||||
void addUniformFieldTypes(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
//- Add objects of a given type
|
||||
template<class Type>
|
||||
void addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
fileFieldSelection(const objectRegistry& obr);
|
||||
fileFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~fileFieldSelection();
|
||||
virtual ~fileFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -33,12 +33,21 @@ template<class Type>
|
||||
void Foam::functionObjects::fileFieldSelection::addFromFile
|
||||
(
|
||||
const IOobjectList& allFileObjects,
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) 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>
|
||||
void Foam::functionObjects::fileFieldSelection::addGeoFieldTypes
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
@ -32,10 +32,11 @@ License
|
||||
|
||||
Foam::functionObjects::solverFieldSelection::solverFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
volFieldSelection(obr)
|
||||
fieldSelection(obr, includeComponents)
|
||||
{
|
||||
if (!isA<fvMesh>(obr))
|
||||
{
|
||||
@ -46,34 +47,43 @@ Foam::functionObjects::solverFieldSelection::solverFieldSelection
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::solverFieldSelection::~solverFieldSelection()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::solverFieldSelection::updateSelection()
|
||||
{
|
||||
wordHashSet oldSet;
|
||||
oldSet.swap(selection_);
|
||||
List<fieldInfo> oldSet(std::move(selection_));
|
||||
|
||||
wordHashSet volFields;
|
||||
addRegisteredGeoFields<fvPatchField, volMesh>(volFields);
|
||||
DynamicList<fieldInfo> newSelection(oldSet.size());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -25,17 +25,17 @@ Class
|
||||
Foam::functionObjects::volFieldSelection
|
||||
|
||||
Description
|
||||
Helper class to manage volume field selections
|
||||
Helper class to manage solver field selections
|
||||
|
||||
SourceFiles
|
||||
volFieldSelection.C
|
||||
solverFieldSelection.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_solverFieldSelection_H
|
||||
#define functionObjects_solverFieldSelection_H
|
||||
|
||||
#include "volFieldSelection.H"
|
||||
#include "fieldSelection.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -50,7 +50,7 @@ namespace functionObjects
|
||||
|
||||
class solverFieldSelection
|
||||
:
|
||||
public volFieldSelection
|
||||
public fieldSelection
|
||||
{
|
||||
private:
|
||||
|
||||
@ -63,11 +63,15 @@ private:
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
solverFieldSelection(const objectRegistry& obr);
|
||||
solverFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~solverFieldSelection();
|
||||
virtual ~solverFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2109 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -31,16 +31,11 @@ License
|
||||
|
||||
Foam::functionObjects::volFieldSelection::volFieldSelection
|
||||
(
|
||||
const objectRegistry& obr
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents
|
||||
)
|
||||
:
|
||||
fieldSelection(obr)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::volFieldSelection::~volFieldSelection()
|
||||
fieldSelection(obr, includeComponents)
|
||||
{}
|
||||
|
||||
|
||||
@ -48,11 +43,15 @@ Foam::functionObjects::volFieldSelection::~volFieldSelection()
|
||||
|
||||
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;
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -66,17 +66,21 @@ protected:
|
||||
|
||||
//- Add registered GeometricField types to selection
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void addRegisteredGeoFields(wordHashSet& set) const;
|
||||
void addRegisteredGeoFields(DynamicList<fieldInfo>& set) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Construct from object registry
|
||||
volFieldSelection(const objectRegistry& obr);
|
||||
volFieldSelection
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const bool includeComponents = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~volFieldSelection();
|
||||
virtual ~volFieldSelection() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -30,7 +30,7 @@ License
|
||||
template<template<class> class PatchType, class MeshType>
|
||||
void Foam::functionObjects::volFieldSelection::addRegisteredGeoFields
|
||||
(
|
||||
wordHashSet& set
|
||||
DynamicList<fieldInfo>& set
|
||||
) const
|
||||
{
|
||||
addRegistered<GeometricField<scalar, PatchType, MeshType>>(set);
|
||||
@ -151,7 +151,7 @@ bool Foam::functionObjects::columnAverage::execute()
|
||||
// Make fields up to date with current selection
|
||||
fieldSet_.updateSelection();
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
columnAverageField<scalar>(fieldName);
|
||||
columnAverageField<vector>(fieldName);
|
||||
@ -166,7 +166,7 @@ bool Foam::functionObjects::columnAverage::execute()
|
||||
|
||||
bool Foam::functionObjects::columnAverage::write()
|
||||
{
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word resultName("columnAverage(" + fieldName + ")");
|
||||
const regIOobject* obj =
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -191,7 +191,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
|
||||
{
|
||||
fieldSet_.updateSelection();
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
transform<scalar>(fieldName);
|
||||
transform<vector>(fieldName);
|
||||
@ -210,9 +210,9 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
|
||||
|
||||
bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
|
||||
{
|
||||
forAllConstIters(fieldSet_, iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeObject(transformFieldName(iter()));
|
||||
writeObject(transformFieldName(fieldName));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -60,9 +60,8 @@ void Foam::functionObjects::fieldExtents::writeFileHeader(Ostream& os)
|
||||
|
||||
writeCommented(os, "Time");
|
||||
|
||||
forAllConstIters(fieldSet_.selection(), iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word& fieldName = iter();
|
||||
if (internalField_)
|
||||
{
|
||||
writeTabbed(os, fieldName + "_internal");
|
||||
@ -183,7 +182,7 @@ bool Foam::functionObjects::fieldExtents::write()
|
||||
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
calcFieldExtents<scalar>(fieldName, true);
|
||||
calcFieldExtents<vector>(fieldName);
|
||||
|
||||
@ -90,9 +90,8 @@ void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os)
|
||||
}
|
||||
else
|
||||
{
|
||||
forAllConstIters(fieldSet_.selection(), iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word& fieldName = iter();
|
||||
writeTabbed(os, "min(" + fieldName + ')');
|
||||
writeTabbed(os, "max(" + fieldName + ')');
|
||||
}
|
||||
@ -153,7 +152,7 @@ bool Foam::functionObjects::fieldMinMax::write()
|
||||
if (!location_) writeTime(file());
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
calcMinMaxFields<scalar>(fieldName, mdCmpt);
|
||||
calcMinMaxFields<vector>(fieldName, mode_);
|
||||
|
||||
@ -17,6 +17,7 @@ runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C
|
||||
runTimeControl/runTimeCondition/runTimeCondition/runTimeConditionNew.C
|
||||
runTimeControl/runTimeCondition/equationMaxIterCondition/equationMaxIterCondition.C
|
||||
runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C
|
||||
runTimeControl/runTimeCondition/maxDurationCondition/maxDurationCondition.C
|
||||
runTimeControl/runTimeCondition/minMaxCondition/minMaxCondition.C
|
||||
runTimeControl/runTimeCondition/averageCondition/averageCondition.C
|
||||
runTimeControl/runTimeCondition/minTimeStepCondition/minTimeStepCondition.C
|
||||
|
||||
@ -64,7 +64,7 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os)
|
||||
|
||||
writeCommented(os, "Time");
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeFileHeader<scalar>(os, fieldName);
|
||||
writeFileHeader<vector>(os, fieldName);
|
||||
@ -193,7 +193,7 @@ bool Foam::functionObjects::residuals::execute()
|
||||
|
||||
if (writeFields_)
|
||||
{
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
initialiseField<scalar>(fieldName);
|
||||
initialiseField<vector>(fieldName);
|
||||
@ -214,7 +214,7 @@ bool Foam::functionObjects::residuals::write()
|
||||
{
|
||||
writeTime(file());
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeResidual<scalar>(fieldName);
|
||||
writeResidual<vector>(fieldName);
|
||||
|
||||
@ -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 * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,86 +68,79 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
tolerance_(dict.get<scalar>("tolerance")),
|
||||
window_(dict.lookupOrDefault<scalar>("window", -1)),
|
||||
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
|
||||
resetOnRestart_(false)
|
||||
windowType_
|
||||
(
|
||||
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];
|
||||
|
||||
if (dict.found(fieldName))
|
||||
conditionDict.set(fieldName, dictionary());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
const dictionary& valueDict = dict.subDict(fieldName);
|
||||
valueDict.readEntry("totalTime", totalTime_[fieldi]);
|
||||
const dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
valueDict.readIfPresent("totalTime", totalTime_[fieldi]);
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionDict.set(fieldName, dictionary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conditionDict.readIfPresent("iter", iter_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::~averageCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
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());
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName(fieldNames_[fieldi]);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
totalTime_[fieldi] += dt;
|
||||
|
||||
bool processed = false;
|
||||
calc<scalar>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<vector>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<sphericalTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<symmTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<tensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<scalar>(fieldi, satisfied, processed);
|
||||
calc<vector>(fieldi, satisfied, processed);
|
||||
calc<sphericalTensor>(fieldi, satisfied, processed);
|
||||
calc<symmTensor>(fieldi, satisfied, processed);
|
||||
calc<tensor>(fieldi, satisfied, processed);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
unprocessedFields.append(fieldi);
|
||||
}
|
||||
|
||||
totalTime_[fieldi] += dt;
|
||||
}
|
||||
|
||||
if (unprocessedFields.size())
|
||||
@ -145,14 +149,13 @@ bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
<< "From function object: " << functionObjectName_ << nl
|
||||
<< "Unprocessed fields:" << nl;
|
||||
|
||||
forAll(unprocessedFields, i)
|
||||
for (const label fieldi : unprocessedFields)
|
||||
{
|
||||
label fieldi = unprocessedFields[i];
|
||||
Info<< " " << fieldNames_[fieldi] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
@ -166,7 +169,6 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
// value dictionary should be present - mean values are written there
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
@ -179,6 +181,8 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
conditionDict.add(fieldName, valueDict);
|
||||
}
|
||||
}
|
||||
|
||||
conditionDict.set("iter", iter_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,7 +39,7 @@ SourceFiles
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Switch.H"
|
||||
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -58,6 +58,20 @@ class averageCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum class windowType
|
||||
{
|
||||
NONE,
|
||||
APPROXIMATE,
|
||||
EXACT
|
||||
};
|
||||
|
||||
static const Enum<windowType> windowTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
@ -74,12 +88,20 @@ protected:
|
||||
//- Averaging window
|
||||
const scalar window_;
|
||||
|
||||
//- Averaging window type
|
||||
windowType windowType_;
|
||||
|
||||
//- Average time per field
|
||||
List<scalar> totalTime_;
|
||||
|
||||
//- Reset the averaging process on restart flag
|
||||
Switch resetOnRestart_;
|
||||
|
||||
//- Number of start-up iterations before allowing satisfied checks
|
||||
label nIterStartUp_;
|
||||
|
||||
//- Current iteration count
|
||||
label iter_;
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
@ -87,9 +109,7 @@ protected:
|
||||
template<class Type>
|
||||
void calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
const label fieldi,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
);
|
||||
@ -110,7 +130,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~averageCondition();
|
||||
virtual ~averageCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -23,18 +23,21 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Time.H"
|
||||
#include "FIFOStack.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
const label fieldi,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
@ -43,22 +46,124 @@ void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
return;
|
||||
}
|
||||
|
||||
Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
const scalar dt = obr_.time().deltaTValue();
|
||||
|
||||
const Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
const word meanName(fieldName + "Mean");
|
||||
|
||||
// Current mean value
|
||||
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);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
}
|
||||
Log << " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
|
||||
// Note: Writing result to owner function object and not the local run-time
|
||||
// condition
|
||||
state_.setResult(meanName, meanValue);
|
||||
|
||||
if (delta > tolerance_)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,10 @@ License
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "volFields.H"
|
||||
|
||||
#define SetResidual(Type) \
|
||||
setResidual<Type>(mesh, solverDict, fieldName, component, canSet, residual);
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -66,8 +70,8 @@ operatingModeNames
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
equationInitialResidualCondition
|
||||
Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
@ -76,12 +80,14 @@ equationInitialResidualCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
fieldSelection_(obr, true),
|
||||
value_(dict.get<scalar>("value")),
|
||||
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
|
||||
mode_(operatingModeNames.get("mode", dict))
|
||||
{
|
||||
if (fieldNames_.size())
|
||||
fieldSelection_.read(dict);
|
||||
|
||||
if (fieldSelection_.size())
|
||||
{
|
||||
timeStart_ = obr.time().userTimeToTime(timeStart_);
|
||||
}
|
||||
@ -95,18 +101,13 @@ equationInitialResidualCondition
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
~equationInitialResidualCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
apply()
|
||||
bool Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::apply()
|
||||
{
|
||||
fieldSelection_.updateSelection();
|
||||
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
@ -123,16 +124,25 @@ apply()
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
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))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const scalar residual = sp.first().initialResidual();
|
||||
label component = fieldInfo.component();
|
||||
scalar residual = VGREAT;
|
||||
bool canSet = true;
|
||||
SetResidual(scalar);
|
||||
SetResidual(vector);
|
||||
SetResidual(symmTensor);
|
||||
SetResidual(sphericalTensor);
|
||||
SetResidual(tensor);
|
||||
|
||||
result[fieldi] = residual;
|
||||
|
||||
switch (mode_)
|
||||
@ -171,7 +181,9 @@ apply()
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
<< selection[i].name()
|
||||
<< ". Solver dictionary contains " << solverDict.sortedToc()
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -190,32 +202,26 @@ apply()
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << value_ << nl;
|
||||
}
|
||||
Log << type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << value_ << nl;
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] > 0)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", residual: " << result[resulti] << nl;
|
||||
}
|
||||
Log << " field: " << selection[resulti].name()
|
||||
<< ", residual: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
write()
|
||||
void Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,12 +37,15 @@ SourceFiles
|
||||
#define functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Enum.H"
|
||||
#include "solverFieldSelection.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class fvMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
@ -71,8 +74,8 @@ protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
//- Field names
|
||||
solverFieldSelection fieldSelection_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
@ -84,6 +87,21 @@ protected:
|
||||
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:
|
||||
|
||||
//- Runtime type information
|
||||
@ -99,7 +117,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationInitialResidualCondition();
|
||||
virtual ~equationInitialResidualCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
@ -120,6 +138,12 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "equationInitialResidualConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -76,13 +76,6 @@ equationMaxIterCondition
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
~equationMaxIterCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
@ -148,24 +141,18 @@ bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << threshold_ << nl;
|
||||
}
|
||||
Log << type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << threshold_ << nl;
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] != -1)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", iterations: " << result[resulti] << nl;
|
||||
}
|
||||
Log << " field: " << fieldNames_[resulti]
|
||||
<< ", iterations: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
|
||||
@ -84,7 +84,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationMaxIterCondition();
|
||||
virtual ~equationMaxIterCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -90,12 +90,6 @@ Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::~minMaxCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
@ -107,10 +101,8 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
for (const word& fieldName :fieldNames_)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
@ -153,13 +145,10 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
}
|
||||
}
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
}
|
||||
Log << " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
|
||||
satisfied = satisfied && ok;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minMaxCondition();
|
||||
virtual ~minMaxCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -63,13 +63,6 @@ minTimeStepCondition
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
~minTimeStepCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply()
|
||||
|
||||
@ -78,7 +78,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minTimeStepCondition();
|
||||
virtual ~minTimeStepCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -84,14 +84,8 @@ Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
|
||||
state_(state),
|
||||
active_(dict.lookupOrDefault("active", true)),
|
||||
conditionDict_(setConditionDict()),
|
||||
log_(dict.lookupOrDefault("log", true)),
|
||||
groupID_(dict.lookupOrDefault("groupID", -1))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::~runTimeCondition()
|
||||
groupID_(dict.lookupOrDefault("groupID", -1)),
|
||||
log(dict.lookupOrDefault("log", true))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -78,9 +78,6 @@ protected:
|
||||
//- Reference to the condition dictionary
|
||||
dictionary& conditionDict_;
|
||||
|
||||
//- Switch to send output to Info
|
||||
Switch log_;
|
||||
|
||||
//- Group index - if applied, all conditions in a group must be
|
||||
// satisfied before condition is met
|
||||
label groupID_;
|
||||
@ -129,7 +126,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeCondition();
|
||||
virtual ~runTimeCondition() = default;
|
||||
|
||||
//- Selector
|
||||
static autoPtr<runTimeCondition> New
|
||||
@ -140,6 +137,11 @@ public:
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
// Public Data
|
||||
|
||||
//- Switch to send output to Info
|
||||
Switch log;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
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 * * * * * * * * * * * * * * //
|
||||
|
||||
@ -58,18 +67,15 @@ Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
writeStepI_(0),
|
||||
satisfiedAction_(satisfiedAction::END),
|
||||
triggerIndex_(labelMin),
|
||||
active_(getObjectProperty(name, "active", true))
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::~runTimeControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
@ -77,68 +83,101 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
conditions_.setSize(conditionNames.size());
|
||||
|
||||
label uniqueGroupi = 0;
|
||||
forAll(conditionNames, conditioni)
|
||||
if (functionObject::postProcess)
|
||||
{
|
||||
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))
|
||||
{
|
||||
uniqueGroupi++;
|
||||
}
|
||||
}
|
||||
|
||||
dict.readIfPresent("nWriteStep", nWriteStep_);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " No conditions present" << nl
|
||||
Info<< "Deactivated " << name()
|
||||
<< " function object for post-processing"
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
if (fvMeshFunctionObject::read(dict))
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool active = false;
|
||||
forAll(conditions_, conditioni)
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
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;
|
||||
break;
|
||||
++uniqueGroupi;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active)
|
||||
dict.readIfPresent("nWriteStep", nWriteStep_);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " All conditions are inactive" << nl
|
||||
<< " No conditions present" << nl
|
||||
<< 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()
|
||||
{
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Info<< type() << " " << name() << " output:" << nl;
|
||||
|
||||
// IDs of satisfied conditions
|
||||
@ -200,33 +239,66 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
|
||||
if (done)
|
||||
{
|
||||
forAll(IDs, conditioni)
|
||||
for (label conditioni : IDs)
|
||||
{
|
||||
Info<< " " << conditions_[conditioni].type() << ": "
|
||||
<< conditions_[conditioni].name()
|
||||
<< conditions_[conditioni].name()
|
||||
<< " condition satisfied" << nl;
|
||||
}
|
||||
|
||||
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
switch (satisfiedAction_)
|
||||
{
|
||||
writeStepI_++;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields - final step" << nl;
|
||||
time.writeAndEnd();
|
||||
case satisfiedAction::END:
|
||||
{
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
{
|
||||
++writeStepI_;
|
||||
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
|
||||
{
|
||||
Info<< " Conditions not met - calculations proceeding" << nl;
|
||||
Info<< " Conditions not met" << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
@ -237,9 +309,9 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::write()
|
||||
{
|
||||
forAll(conditions_, conditioni)
|
||||
for (auto& condition : conditions_)
|
||||
{
|
||||
conditions_[conditioni].write();
|
||||
condition.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,7 +32,7 @@ Description
|
||||
user-specified conditions.
|
||||
|
||||
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.
|
||||
|
||||
SourceFiles
|
||||
@ -45,6 +45,7 @@ SourceFiles
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "Map.H"
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -66,6 +67,21 @@ class runTimeControl
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum class satisfiedAction
|
||||
{
|
||||
END,
|
||||
SET_TRIGGER
|
||||
};
|
||||
|
||||
static Enum<satisfiedAction> satisfiedActionNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- List of conditions to satisfy
|
||||
@ -80,6 +96,17 @@ class runTimeControl
|
||||
//- Current number of steps written
|
||||
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
|
||||
|
||||
@ -98,8 +125,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
//- Construct for given objectRegistry and dictionary
|
||||
runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
@ -109,7 +135,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeControl();
|
||||
virtual ~runTimeControl() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -48,6 +48,9 @@ runTimeModifiable true;
|
||||
functions
|
||||
{
|
||||
#include "forceCoeffs"
|
||||
#include "fieldAverage"
|
||||
#include "runTimeControls"
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user