functionObject: Added executeAtStart
By default most functionObjects now execute and write at the start-time except those that perform averaging (fieldAverage, dsmcFields) which cannot be executed until the end of the first time-step. There is also a new optional functionObject dictionary entry "executeAtStart" which defaults to true but can be set false if the execution and results of the functionObject are not required or appropriate at the start-time. A result of this change is that time logs of forces, sampling etc. now include a values for time 0.
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -44,7 +44,8 @@ bool Foam::functionObject::postProcess(false);
|
|||||||
Foam::functionObject::functionObject(const word& name)
|
Foam::functionObject::functionObject(const word& name)
|
||||||
:
|
:
|
||||||
name_(name),
|
name_(name),
|
||||||
log(postProcess)
|
log(false),
|
||||||
|
executeAtStart_(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -128,12 +129,19 @@ bool Foam::functionObject::read(const dictionary& dict)
|
|||||||
if (!postProcess)
|
if (!postProcess)
|
||||||
{
|
{
|
||||||
log = dict.lookupOrDefault<Switch>("log", true);
|
log = dict.lookupOrDefault<Switch>("log", true);
|
||||||
|
executeAtStart_ = dict.lookupOrDefault<Switch>("executeAtStart", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::functionObject::executeAtStart() const
|
||||||
|
{
|
||||||
|
return executeAtStart_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObject::end()
|
bool Foam::functionObject::end()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ Description
|
|||||||
field and derived quantities. Alternatively, the same actions can be
|
field and derived quantities. Alternatively, the same actions can be
|
||||||
executed after the simulation using the \c -postProcess command-line option.
|
executed after the simulation using the \c -postProcess command-line option.
|
||||||
|
|
||||||
\subsection secFunctionObjects Using function objects
|
\subsection secFunctionObjects Using functionObjects
|
||||||
|
|
||||||
FunctionObjects are selected by additional entries in the
|
FunctionObjects are selected by additional entries in the
|
||||||
$FOAM_CASE/system/controlDict dictionary. Each object is listed in the \c
|
$FOAM_CASE/system/controlDict dictionary. Each object is listed in the \c
|
||||||
@ -60,7 +60,7 @@ Description
|
|||||||
Where:
|
Where:
|
||||||
\table
|
\table
|
||||||
Property | Description | Required | Default value
|
Property | Description | Required | Default value
|
||||||
type | Type of function object | yes |
|
type | Type of functionObject | yes |
|
||||||
libs | Libraries containing implementation | yes |
|
libs | Libraries containing implementation | yes |
|
||||||
region | Name of region for multi-region cases | no |
|
region | Name of region for multi-region cases | no |
|
||||||
enabled | On/off switch | no | yes
|
enabled | On/off switch | no | yes
|
||||||
@ -92,7 +92,7 @@ Description
|
|||||||
libraries and the \c libs entry is used to specify which library should be
|
libraries and the \c libs entry is used to specify which library should be
|
||||||
loaded.
|
loaded.
|
||||||
|
|
||||||
Each function object has two separate run phases:
|
Each functionObject has two separate run phases:
|
||||||
|
|
||||||
- The \c execute phase is meant to be used for updating calculations
|
- The \c execute phase is meant to be used for updating calculations
|
||||||
or for management tasks.
|
or for management tasks.
|
||||||
@ -104,7 +104,7 @@ Class
|
|||||||
Foam::functionObject
|
Foam::functionObject
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Abstract base-class for Time/database function objects.
|
Abstract base-class for Time/database functionObjects.
|
||||||
|
|
||||||
See also
|
See also
|
||||||
Foam::functionObjectList
|
Foam::functionObjectList
|
||||||
@ -158,6 +158,9 @@ public:
|
|||||||
//- Switch write log to Info
|
//- Switch write log to Info
|
||||||
Switch log;
|
Switch log;
|
||||||
|
|
||||||
|
//- Switch write log to Info
|
||||||
|
Switch executeAtStart_;
|
||||||
|
|
||||||
|
|
||||||
// Declare run-time constructor selection tables
|
// Declare run-time constructor selection tables
|
||||||
|
|
||||||
@ -207,9 +210,12 @@ public:
|
|||||||
//- Return the name of this functionObject
|
//- Return the name of this functionObject
|
||||||
const word& name() const;
|
const word& name() const;
|
||||||
|
|
||||||
//- Read and set the function object if its data have changed
|
//- Read and set the functionObject if its data have changed
|
||||||
virtual bool read(const dictionary&);
|
virtual bool read(const dictionary&);
|
||||||
|
|
||||||
|
//- Return true if the functionObject should be executed at the start
|
||||||
|
virtual bool executeAtStart() const;
|
||||||
|
|
||||||
//- Called at each ++ or += of the time-loop.
|
//- Called at each ++ or += of the time-loop.
|
||||||
// postProcess overrides the usual executeControl behaviour and
|
// postProcess overrides the usual executeControl behaviour and
|
||||||
// forces execution (used in post-processing mode)
|
// forces execution (used in post-processing mode)
|
||||||
@ -224,12 +230,12 @@ public:
|
|||||||
// By default it simply calls execute().
|
// By default it simply calls execute().
|
||||||
virtual bool end();
|
virtual bool end();
|
||||||
|
|
||||||
//- Called by Time::setDeltaT(). Allows the function object to override
|
//- Called by Time::setDeltaT(). Allows the functionObject to override
|
||||||
// the time-step value.
|
// the time-step value.
|
||||||
// Returns whether or not the value was overridden.
|
// Returns whether or not the value was overridden.
|
||||||
virtual bool setTimeStep();
|
virtual bool setTimeStep();
|
||||||
|
|
||||||
//- Called by Time::adjustTimeStep(). Allows the function object to
|
//- Called by Time::adjustTimeStep(). Allows the functionObject to
|
||||||
// insert a write time earlier than that already in use by the run
|
// insert a write time earlier than that already in use by the run
|
||||||
// time. Returns the write time, or vGreat.
|
// time. Returns the write time, or vGreat.
|
||||||
virtual scalar timeToNextWrite();
|
virtual scalar timeToNextWrite();
|
||||||
|
|||||||
@ -565,11 +565,11 @@ void Foam::functionObjectList::clear()
|
|||||||
|
|
||||||
Foam::label Foam::functionObjectList::findObjectID(const word& name) const
|
Foam::label Foam::functionObjectList::findObjectID(const word& name) const
|
||||||
{
|
{
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
if (operator[](objectI).name() == name)
|
if (operator[](oi).name() == name)
|
||||||
{
|
{
|
||||||
return objectI;
|
return oi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,7 +598,21 @@ bool Foam::functionObjectList::status() const
|
|||||||
|
|
||||||
bool Foam::functionObjectList::start()
|
bool Foam::functionObjectList::start()
|
||||||
{
|
{
|
||||||
return read();
|
bool ok = read();
|
||||||
|
|
||||||
|
if (execution_)
|
||||||
|
{
|
||||||
|
forAll(*this, oi)
|
||||||
|
{
|
||||||
|
if (operator[](oi).executeAtStart())
|
||||||
|
{
|
||||||
|
ok = operator[](oi).execute() && ok;
|
||||||
|
ok = operator[](oi).write() && ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -613,10 +627,10 @@ bool Foam::functionObjectList::execute()
|
|||||||
read();
|
read();
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
ok = operator[](objectI).execute() && ok;
|
ok = operator[](oi).execute() && ok;
|
||||||
ok = operator[](objectI).write() && ok;
|
ok = operator[](oi).write() && ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,9 +649,9 @@ bool Foam::functionObjectList::end()
|
|||||||
read();
|
read();
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
ok = operator[](objectI).end() && ok;
|
ok = operator[](oi).end() && ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,11 +672,11 @@ bool Foam::functionObjectList::setTimeStep()
|
|||||||
|
|
||||||
wordList names;
|
wordList names;
|
||||||
|
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
if (operator[](objectI).setTimeStep())
|
if (operator[](oi).setTimeStep())
|
||||||
{
|
{
|
||||||
names.append(operator[](objectI).name());
|
names.append(operator[](oi).name());
|
||||||
set = true;
|
set = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -693,9 +707,9 @@ Foam::scalar Foam::functionObjectList::timeToNextWrite()
|
|||||||
read();
|
read();
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
result = min(result, operator[](objectI).timeToNextWrite());
|
result = min(result, operator[](oi).timeToNextWrite());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,9 +884,9 @@ void Foam::functionObjectList::updateMesh(const mapPolyMesh& mpm)
|
|||||||
{
|
{
|
||||||
if (execution_)
|
if (execution_)
|
||||||
{
|
{
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
operator[](objectI).updateMesh(mpm);
|
operator[](oi).updateMesh(mpm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -882,9 +896,9 @@ void Foam::functionObjectList::movePoints(const polyMesh& mesh)
|
|||||||
{
|
{
|
||||||
if (execution_)
|
if (execution_)
|
||||||
{
|
{
|
||||||
forAll(*this, objectI)
|
forAll(*this, oi)
|
||||||
{
|
{
|
||||||
operator[](objectI).movePoints(mesh);
|
operator[](oi).movePoints(mesh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,9 +93,23 @@ Foam::functionObjects::timeControl::timeControl
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
bool Foam::functionObjects::timeControl::executeAtStart() const
|
||||||
|
{
|
||||||
|
return foPtr_->executeAtStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::timeControl::execute()
|
bool Foam::functionObjects::timeControl::execute()
|
||||||
{
|
{
|
||||||
if (active() && (postProcess || executeControl_.execute()))
|
if
|
||||||
|
(
|
||||||
|
active()
|
||||||
|
&& (
|
||||||
|
postProcess
|
||||||
|
|| executeControl_.execute()
|
||||||
|
|| (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
foPtr_->execute();
|
foPtr_->execute();
|
||||||
}
|
}
|
||||||
@ -106,7 +120,15 @@ bool Foam::functionObjects::timeControl::execute()
|
|||||||
|
|
||||||
bool Foam::functionObjects::timeControl::write()
|
bool Foam::functionObjects::timeControl::write()
|
||||||
{
|
{
|
||||||
if (active() && (postProcess || writeControl_.execute()))
|
if
|
||||||
|
(
|
||||||
|
active()
|
||||||
|
&& (
|
||||||
|
postProcess
|
||||||
|
|| writeControl_.execute()
|
||||||
|
|| (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
|
||||||
|
)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
foPtr_->write();
|
foPtr_->write();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,6 +142,10 @@ public:
|
|||||||
|
|
||||||
// Function object control
|
// Function object control
|
||||||
|
|
||||||
|
//- Return true if the functionObject should be executed
|
||||||
|
// at the start
|
||||||
|
virtual bool executeAtStart() const;
|
||||||
|
|
||||||
//- Called at each ++ or += of the time-loop.
|
//- Called at each ++ or += of the time-loop.
|
||||||
// postProcess overrides the usual executeControl behaviour and
|
// postProcess overrides the usual executeControl behaviour and
|
||||||
// forces execution (used in post-processing mode)
|
// forces execution (used in post-processing mode)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -151,7 +151,7 @@ void Foam::functionObjects::fieldAverage::calcAverages()
|
|||||||
periodIndex_++;
|
periodIndex_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log << type() << " " << name() << " write:" << nl
|
Log << type() << " " << name() << nl
|
||||||
<< " Calculating averages" << nl;
|
<< " Calculating averages" << nl;
|
||||||
|
|
||||||
addMeanSqrToPrime2Mean<scalar, scalar>();
|
addMeanSqrToPrime2Mean<scalar, scalar>();
|
||||||
|
|||||||
@ -286,6 +286,12 @@ public:
|
|||||||
//- Read the field average data
|
//- Read the field average data
|
||||||
virtual bool read(const dictionary&);
|
virtual bool read(const dictionary&);
|
||||||
|
|
||||||
|
//- Do not average at the start of the run
|
||||||
|
virtual bool executeAtStart() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//- Calculate the field averages
|
//- Calculate the field averages
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
|
|||||||
@ -89,6 +89,12 @@ public:
|
|||||||
//- Read the dsmcFields data
|
//- Read the dsmcFields data
|
||||||
virtual bool read(const dictionary&);
|
virtual bool read(const dictionary&);
|
||||||
|
|
||||||
|
//- Do not evaluate the state at the start of the run
|
||||||
|
virtual bool executeAtStart() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//- Do nothing
|
//- Do nothing
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user