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:
Henry Weller
2019-09-30 11:03:20 +01:00
parent 6f1c3362a6
commit 2ebed5ec71
8 changed files with 97 additions and 31 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,7 +44,8 @@ bool Foam::functionObject::postProcess(false);
Foam::functionObject::functionObject(const word& name)
:
name_(name),
log(postProcess)
log(false),
executeAtStart_(true)
{}
@ -128,12 +129,19 @@ bool Foam::functionObject::read(const dictionary& dict)
if (!postProcess)
{
log = dict.lookupOrDefault<Switch>("log", true);
executeAtStart_ = dict.lookupOrDefault<Switch>("executeAtStart", true);
}
return true;
}
bool Foam::functionObject::executeAtStart() const
{
return executeAtStart_;
}
bool Foam::functionObject::end()
{
return true;

View File

@ -32,7 +32,7 @@ Description
field and derived quantities. Alternatively, the same actions can be
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
$FOAM_CASE/system/controlDict dictionary. Each object is listed in the \c
@ -60,7 +60,7 @@ Description
Where:
\table
Property | Description | Required | Default value
type | Type of function object | yes |
type | Type of functionObject | yes |
libs | Libraries containing implementation | yes |
region | Name of region for multi-region cases | no |
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
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
or for management tasks.
@ -104,7 +104,7 @@ Class
Foam::functionObject
Description
Abstract base-class for Time/database function objects.
Abstract base-class for Time/database functionObjects.
See also
Foam::functionObjectList
@ -158,6 +158,9 @@ public:
//- Switch write log to Info
Switch log;
//- Switch write log to Info
Switch executeAtStart_;
// Declare run-time constructor selection tables
@ -207,9 +210,12 @@ public:
//- Return the name of this functionObject
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&);
//- Return true if the functionObject should be executed at the start
virtual bool executeAtStart() const;
//- Called at each ++ or += of the time-loop.
// postProcess overrides the usual executeControl behaviour and
// forces execution (used in post-processing mode)
@ -224,12 +230,12 @@ public:
// By default it simply calls execute().
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.
// Returns whether or not the value was overridden.
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
// time. Returns the write time, or vGreat.
virtual scalar timeToNextWrite();

View File

@ -565,11 +565,11 @@ void Foam::functionObjectList::clear()
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()
{
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();
}
forAll(*this, objectI)
forAll(*this, oi)
{
ok = operator[](objectI).execute() && ok;
ok = operator[](objectI).write() && ok;
ok = operator[](oi).execute() && ok;
ok = operator[](oi).write() && ok;
}
}
@ -635,9 +649,9 @@ bool Foam::functionObjectList::end()
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;
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;
}
}
@ -693,9 +707,9 @@ Foam::scalar Foam::functionObjectList::timeToNextWrite()
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_)
{
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_)
{
forAll(*this, objectI)
forAll(*this, oi)
{
operator[](objectI).movePoints(mesh);
operator[](oi).movePoints(mesh);
}
}
}

View File

@ -93,9 +93,23 @@ Foam::functionObjects::timeControl::timeControl
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::timeControl::executeAtStart() const
{
return foPtr_->executeAtStart();
}
bool Foam::functionObjects::timeControl::execute()
{
if (active() && (postProcess || executeControl_.execute()))
if
(
active()
&& (
postProcess
|| executeControl_.execute()
|| (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
)
)
{
foPtr_->execute();
}
@ -106,7 +120,15 @@ bool Foam::functionObjects::timeControl::execute()
bool Foam::functionObjects::timeControl::write()
{
if (active() && (postProcess || writeControl_.execute()))
if
(
active()
&& (
postProcess
|| writeControl_.execute()
|| (executeAtStart() && time_.timeIndex() == time_.startTimeIndex())
)
)
{
foPtr_->write();
}

View File

@ -142,6 +142,10 @@ public:
// 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.
// postProcess overrides the usual executeControl behaviour and
// forces execution (used in post-processing mode)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -151,7 +151,7 @@ void Foam::functionObjects::fieldAverage::calcAverages()
periodIndex_++;
}
Log << type() << " " << name() << " write:" << nl
Log << type() << " " << name() << nl
<< " Calculating averages" << nl;
addMeanSqrToPrime2Mean<scalar, scalar>();

View File

@ -286,6 +286,12 @@ public:
//- Read the field average data
virtual bool read(const dictionary&);
//- Do not average at the start of the run
virtual bool executeAtStart() const
{
return false;
}
//- Calculate the field averages
virtual bool execute();

View File

@ -89,6 +89,12 @@ public:
//- Read the dsmcFields data
virtual bool read(const dictionary&);
//- Do not evaluate the state at the start of the run
virtual bool executeAtStart() const
{
return false;
}
//- Do nothing
virtual bool execute();