Commit ded5f35d authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects: Separated 'execute' and 'write' functions to simplify support for post-processing

parent 6164c2f2
......@@ -218,8 +218,8 @@ db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
db/functionObjects/functionObjectFile/functionObjectFile.C
db/functionObjects/functionObjectFiles/functionObjectFiles.C
db/functionObjects/outputFilterControl/outputFilterControl.C
db/functionObjects/timeControl/timeControl.C
db/functionObjects/timeControl/timeControlFunctionObject.C
Time = db/Time
$(Time)/TimePaths.C
......
......@@ -88,17 +88,30 @@ Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::execute
(
const bool forceWrite
const bool postProcess
)
{
if (active())
{
if (evaluateControl_.execute())
if (postProcess || evaluateControl_.execute())
{
filter_.execute();
}
}
return true;
}
if (forceWrite || writeControl_.execute())
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::write
(
const bool postProcess
)
{
if (active())
{
if (postProcess || writeControl_.execute())
{
filter_.write();
}
......@@ -141,7 +154,7 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::adjustTimeStep()
(
active()
&& writeControl_.control()
== outputFilterControl::ocAdjustableRunTime
== timeControl::ocAdjustableRunTime
)
{
const label writeTimeIndex = writeControl_.executionIndex();
......
......@@ -44,7 +44,7 @@ SourceFiles
#include "functionObject.H"
#include "dictionary.H"
#include "outputFilterControl.H"
#include "timeControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -83,10 +83,10 @@ class OutputFilterFunctionObject
//- Output controls
outputFilterControl writeControl_;
timeControl writeControl_;
//- Evaluate controls
outputFilterControl evaluateControl_;
timeControl evaluateControl_;
//- The output filter
OutputFilter filter_;
......@@ -138,7 +138,7 @@ public:
inline const word& regionName() const;
//- Return the output control object
inline const outputFilterControl& writeControl() const;
inline const timeControl& writeControl() const;
//- Return the output filter
inline const OutputFilter& outputFilter() const;
......@@ -147,9 +147,14 @@ public:
// Function object control
//- Called at each ++ or += of the time-loop.
// forceWrite overrides the usual writeControl behaviour and
// postProcess overrides the usual executeControl behaviour and
// forces execution (used in post-processing mode)
virtual bool execute(const bool postProcess = false);
//- Called at each ++ or += of the time-loop.
// postProcess overrides the usual writeControl behaviour and
// forces writing (used in post-processing mode)
virtual bool execute(const bool forceWrite = false);
virtual bool write(const bool postProcess = false);
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
......
......@@ -42,7 +42,7 @@ Foam::OutputFilterFunctionObject<OutputFilter>::dict() const
template<class OutputFilter>
inline const Foam::outputFilterControl&
inline const Foam::timeControl&
Foam::OutputFilterFunctionObject<OutputFilter>::writeControl() const
{
return writeControl_;
......
......@@ -110,7 +110,7 @@ const Foam::word& Foam::functionObject::name() const
bool Foam::functionObject::end()
{
return execute(false);
return execute();
}
......
......@@ -197,10 +197,15 @@ public:
//- Name
virtual const word& name() const;
//- Called at each ++ or += of the time-loop. forceWrite overrides
// the usual writeControl behaviour and forces writing always
// (used in post-processing mode)
virtual bool execute(const bool forceWrite) = 0;
//- Called at each ++ or += of the time-loop.
// postProcess overrides the usual executeControl behaviour and
// forces execution (used in post-processing mode)
virtual bool execute(const bool postProcess = false) = 0;
//- Called at each ++ or += of the time-loop.
// postProcess overrides the usual writeControl behaviour and
// forces writing always (used in post-processing mode)
virtual bool write(const bool postProcess = false) = 0;
//- Called when Time::run() determines that the time-loop exits.
// By default it simply calls execute().
......
......@@ -47,7 +47,6 @@ SourceFiles
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class functionObjectFile Declaration
\*---------------------------------------------------------------------------*/
......
......@@ -185,7 +185,7 @@ bool Foam::functionObjectList::start()
}
bool Foam::functionObjectList::execute(const bool forceWrite)
bool Foam::functionObjectList::execute(const bool postProcess)
{
bool ok = true;
......@@ -198,7 +198,8 @@ bool Foam::functionObjectList::execute(const bool forceWrite)
forAll(*this, objectI)
{
ok = operator[](objectI).execute(forceWrite) && ok;
ok = operator[](objectI).execute(postProcess) && ok;
ok = operator[](objectI).write(postProcess) && ok;
}
}
......
......@@ -170,10 +170,10 @@ public:
//- Called at the start of the time-loop
bool start();
//- Called at each ++ or += of the time-loop. forceWrite overrides
// the usual writeControl behaviour and forces writing always
// (used in post-processing mode)
bool execute(const bool forceWrite = false);
//- Called at each ++ or += of the time-loop.
// postProcess overrides the usual executeControl behaviour and
// forces execution (used in post-processing mode)
bool execute(const bool postProcess = false);
//- Called when Time::run() determines that the time-loop exits
bool end();
......
......@@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "outputFilterControl.H"
#include "timeControl.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
......@@ -31,7 +31,7 @@ License
namespace Foam
{
template<>
const char* NamedEnum<outputFilterControl::timeControls, 8>::
const char* NamedEnum<timeControl::timeControls, 8>::
names[] =
{
"timeStep",
......@@ -45,13 +45,13 @@ namespace Foam
};
}
const Foam::NamedEnum<Foam::outputFilterControl::timeControls, 8>
Foam::outputFilterControl::timeControlNames_;
const Foam::NamedEnum<Foam::timeControl::timeControls, 8>
Foam::timeControl::timeControlNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::outputFilterControl::outputFilterControl
Foam::timeControl::timeControl
(
const Time& t,
const dictionary& dict,
......@@ -71,13 +71,13 @@ Foam::outputFilterControl::outputFilterControl
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::outputFilterControl::~outputFilterControl()
Foam::timeControl::~timeControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::outputFilterControl::read(const dictionary& dict)
void Foam::timeControl::read(const dictionary& dict)
{
word controlName(prefix_ + "Control");
word intervalName(prefix_ + "Interval");
......@@ -137,7 +137,7 @@ void Foam::outputFilterControl::read(const dictionary& dict)
}
bool Foam::outputFilterControl::execute()
bool Foam::timeControl::execute()
{
switch (timeControl_)
{
......
......@@ -22,23 +22,21 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::outputFilterControl
Foam::timeControl
Description
An output control for function objects.
The default is time-step execution at every interval.
General time dependent execution controller.
The default to execute every time-step.
SourceFiles
outputFilterControl.C
timeControl.C
\*---------------------------------------------------------------------------*/
#ifndef outputFilterControl_H
#define outputFilterControl_H
#ifndef timeControl_H
#define timeControl_H
#include "dictionary.H"
#include "Time.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -46,14 +44,14 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class outputFilterControl Declaration
Class timeControl Declaration
\*---------------------------------------------------------------------------*/
class outputFilterControl
class timeControl
{
public:
//- The output control options
//- The time control options
enum timeControls
{
ocTimeStep, //!< execution is coupled to the time-step
......@@ -63,7 +61,7 @@ public:
ocRunTime, //!< run time for execution
ocClockTime, //!< clock time for execution
ocCpuTime, //!< cpu time for execution
ocNone //!< no output
ocNone //!< no execution
};
......@@ -80,7 +78,7 @@ private:
//- String representation of timeControls enums
static const NamedEnum<timeControls, 8> timeControlNames_;
//- Type of output
//- Type of time control
timeControls timeControl_;
//- Execution interval steps for timeStep mode
......@@ -97,10 +95,10 @@ private:
// Private Member Functions
//- Disallow default bitwise copy construct and assignment
outputFilterControl(const outputFilterControl&);
timeControl(const timeControl&);
//- Disallow default bitwise assignment
void operator=(const outputFilterControl&);
void operator=(const timeControl&);
public:
......@@ -108,7 +106,7 @@ public:
// Constructors
//- Construct from Time object and dictionary
outputFilterControl
timeControl
(
const Time&,
const dictionary&,
......@@ -117,7 +115,7 @@ public:
//- Destructor
~outputFilterControl();
~timeControl();
// Member Functions
......@@ -148,7 +146,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "outputFilterControlI.H"
#include "timeControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "timeControlFunctionObject.H"
#include "polyMesh.H"
#include "mapPolyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(timeControl, 0);
}
}
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
void Foam::functionObjects::timeControl::readControls()
{
dict_.readIfPresent("timeStart", timeStart_);
dict_.readIfPresent("timeEnd", timeEnd_);
dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
}
bool Foam::functionObjects::timeControl::active() const
{
return
time_.value() >= timeStart_
&& time_.value() <= timeEnd_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::timeControl::timeControl
(
const word& name,
const Time& t,
const dictionary& dict
)
:
functionObject(name),
time_(t),
dict_(dict),
timeStart_(-VGREAT),
timeEnd_(VGREAT),
nStepsToStartTimeChange_
(
dict.lookupOrDefault("nStepsToStartTimeChange", 3)
),
executeControl_(t, dict, "execute"),
writeControl_(t, dict, "write"),
foPtr_(functionObject::New(name, t, dict_))
{
readControls();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::timeControl::execute(const bool postProcess)
{
if (active())
{
if (postProcess || executeControl_.execute())
{
foPtr_->execute();
}
}
return true;
}
bool Foam::functionObjects::timeControl::write(const bool postProcess)
{
if (active())
{
if (postProcess || writeControl_.execute())
{
foPtr_->write();
}
}
return true;
}
bool Foam::functionObjects::timeControl::end()
{
foPtr_->end();
if (writeControl_.execute())
{
foPtr_->write();
}
return true;
}
bool Foam::functionObjects::timeControl::timeSet()
{
if (active())
{
foPtr_->timeSet();
}
return true;
}
bool Foam::functionObjects::timeControl::adjustTimeStep()
{
if
(
active()
&& writeControl_.control()
== Foam::timeControl::ocAdjustableRunTime
)
{
const label writeTimeIndex = writeControl_.executionIndex();
const scalar writeInterval = writeControl_.interval();
scalar timeToNextWrite = max
(
0.0,
(writeTimeIndex + 1)*writeInterval
- (time_.value() - time_.startTime().value())
);
scalar deltaT = time_.deltaTValue();
scalar nSteps = timeToNextWrite/deltaT - SMALL;
// functionObjects modify deltaT within nStepsToStartTimeChange
// NOTE: Potential problems arise if two function objects dump within
// the same interval
if (nSteps < nStepsToStartTimeChange_)
{
label nStepsToNextWrite = label(nSteps) + 1;
scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
// Adjust time step
if (newDeltaT < deltaT)
{
deltaT = max(newDeltaT, 0.2*deltaT);
const_cast<Time&>(time_).setDeltaT(deltaT, false);
}
}
}
return true;
}
bool Foam::functionObjects::timeControl::read
(
const dictionary& dict
)
{
if (dict != dict_)
{
dict_ = dict;
writeControl_.read(dict);
executeControl_.read(dict);
readControls();
return true;
}
else
{
return false;
}
}
void Foam::functionObjects::timeControl::updateMesh
(
const mapPolyMesh& mpm
)
{
if (active())
{
foPtr_->updateMesh(mpm);
}
}
void Foam::functionObjects::timeControl::movePoints
(
const polyMesh& mesh
)
{
if (active())
{
foPtr_->movePoints(mesh);
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License