Time and functionObject updated for end()

- added end() method to functionObject, functionObjectList & associated classes
- moved outputFilters from src/sampling -> src/OpenFOAM/db/functionObjects
This commit is contained in:
Mark Olesen 2009-02-17 12:48:10 +01:00
parent c2256e51f3
commit fee6e312b9
35 changed files with 255 additions and 114 deletions

View File

@ -144,11 +144,14 @@ $(regIOobject)/regIOobjectWrite.C
db/IOobjectList/IOobjectList.C
db/objectRegistry/objectRegistry.C
db/functionObject/functionObject.C
db/functionObjectList/functionObjectList.C
db/CallbackRegistry/CallbackRegistryName.C
db/dlLibraryTable/dlLibraryTable.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
db/functionObjects/outputFilterOutputControl/outputFilterOutputControl.C
Time = db/Time
$(Time)/TimePaths.C
$(Time)/TimeState.C

View File

@ -498,8 +498,8 @@ bool Foam::Time::run() const
// ie, when exiting the control loop
if (!running && timeIndex_ != startTimeIndex_)
{
// Note, the execute() also calls an indirect start() if required
functionObjects_.execute();
// Note, end() also calls an indirect start() as required
functionObjects_.end();
}
}
@ -509,8 +509,7 @@ bool Foam::Time::run() const
bool Foam::Time::end() const
{
bool done = value() > (endTime_ + 0.5*deltaT_);
return done;
return value() > (endTime_ + 0.5*deltaT_);
}

View File

@ -348,16 +348,28 @@ public:
// Check
//- Return true if run should continue
// @sa end()
//- Return true if run should continue,
// also invokes the functionObjectList::end() method
// when the time goes out of range
// @note
// the rounding heuristics near endTime mean that
// @code run() @endcode and @code !end() @endcode may
// not yield the same result
// For correct baheviour, the following style of time-loop
// is recommended:
// @code
// while (runTime.run())
// {
// runTime++;
// solve;
// runTime.write();
// }
// @endcode
virtual bool run() const;
//- Return true if end of run
// @sa run()
//- Return true if end of run,
// does not invoke any functionObject methods
// @note
// The rounding heuristics near endTime mean that
// @code run() @endcode and @code !end() @endcode may
// not yield the same result
virtual bool end() const;
@ -406,13 +418,15 @@ public:
// Member operators
//- Set deltaT to that specified and increment time
//- Set deltaT to that specified and increment time via operator++()
virtual Time& operator+=(const dimensionedScalar&);
//- Set deltaT to that specified and increment time
//- Set deltaT to that specified and increment time via operator++()
virtual Time& operator+=(const scalar);
//- Prefix increment
//- Prefix increment,
// also invokes the functionObjectList::start() or
// functionObjectList::execute() method, depending on the time-index
virtual Time& operator++();
//- Postfix increment, this is identical to the prefix increment

View File

@ -65,6 +65,20 @@ Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::on()
{
enabled_ = true;
}
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::off()
{
enabled_ = false;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
{
@ -120,16 +134,19 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::execute()
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::on()
bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
{
enabled_ = true;
}
if (enabled_)
{
ptr_->end();
if (enabled_ && outputControl_.output())
{
ptr_->write();
}
}
template<class OutputFilter>
void Foam::OutputFilterFunctionObject<OutputFilter>::off()
{
enabled_ = false;
return true;
}

View File

@ -53,7 +53,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class OutputFilterFunctionObject Declaration
Class OutputFilterFunctionObject Declaration
\*---------------------------------------------------------------------------*/
template<class OutputFilter>
@ -69,7 +69,7 @@ class OutputFilterFunctionObject
word regionName_;
word dictName_;
//- Switch for the execution of the functionObjects
//- Switch for the execution of the functionObject
bool enabled_;
outputFilterOutputControl outputControl_;
@ -114,18 +114,23 @@ public:
return name_;
}
//- start is called at the start of the time-loop
virtual bool start();
//- execute is called at each ++ or += of the time-loop
virtual bool execute();
//- Switch the function object on
virtual void on();
//- Switch the function object off
virtual void off();
//- Called at the start of the time-loop
virtual bool start();
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&);
};

View File

@ -103,6 +103,12 @@ Foam::functionObject::~functionObject()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObject::end()
{
return execute();
}
Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
(
const word& name,

View File

@ -137,12 +137,16 @@ public:
// Member Functions
//- start is called at the start of the time-loop
//- Called at the start of the time-loop
virtual bool start() = 0;
//- execute is called at each ++ or += of the time-loop
//- Called at each ++ or += of the time-loop
virtual bool execute() = 0;
//- Called when Time::run() determines that the time-loop exits.
// By default it simply calls execute().
virtual bool end();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&) = 0;
};

View File

@ -142,7 +142,12 @@ bool Foam::functionObjectList::execute()
read();
}
forAllIter(PtrList<functionObject>, *this, iter)
forAllIter
(
PtrList<functionObject>,
static_cast<PtrList<functionObject>&>(*this),
iter
)
{
ok = iter().execute() && ok;
}
@ -152,6 +157,32 @@ bool Foam::functionObjectList::execute()
}
bool Foam::functionObjectList::end()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAllIter
(
PtrList<functionObject>,
static_cast<PtrList<functionObject>&>(*this),
iter
)
{
ok = iter().end() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::read()
{
bool ok = true;
@ -279,28 +310,4 @@ bool Foam::functionObjectList::read()
}
bool Foam::functionObjectList::manualStart()
{
bool state = execution_;
execution_ = true;
bool ret = start();
execution_ = state;
return ret;
}
bool Foam::functionObjectList::manualExecute()
{
bool state = execution_;
execution_ = true;
bool ret = execute();
execution_ = state;
return ret;
}
// ************************************************************************* //

View File

@ -26,8 +26,8 @@ Class
Foam::functionObjectList
Description
List of function objects with execute() function that is called for each
object.
List of function objects with start(), execute() and end() functions
that is called for each object.
See Also
Foam::functionObject and Foam::OutputFilterFunctionObject
@ -147,22 +147,18 @@ public:
virtual bool status() const;
//- Start is called at the start of the time-loop
//- Called at the start of the time-loop
virtual bool start();
//- Execute is called at each ++ or += of the time-loop
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Read and set the function objects if their data have changed
virtual bool read();
//- Call start() manually regardless of the execution status
virtual bool manualStart();
//- Call execute() manually regardless of the execution status
virtual bool manualExecute();
};

View File

@ -255,6 +255,15 @@ void Foam::fieldAverage::execute()
}
void Foam::fieldAverage::end()
{
if (active_)
{
calcAverages();
}
}
void Foam::fieldAverage::write()
{
if (active_)

View File

@ -41,7 +41,7 @@ Description
// averaging info if available
cleanRestart true;
// Fields to be probed. runTime modifiable!
// Fields to be averaged. runTime modifiable!
fields
(
U
@ -281,6 +281,9 @@ public:
//- Execute the averaging
virtual void execute();
//- Execute the averaging at the final time-loop
virtual void end();
//- Calculate the field average data and write
virtual void write();
};

View File

@ -76,14 +76,12 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const fieldAverageItem& faItem)
"(Foam::Ostream&, const Foam::fieldAverageItem&)"
);
os<< faItem.fieldName_ << nl;
os<< token::BEGIN_BLOCK << nl;
os << faItem.fieldName_ << nl << token::BEGIN_BLOCK << nl;
os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
os.writeKeyword("prime2Mean") << faItem.mean_
<< token::END_STATEMENT << nl;
os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
<< token::END_STATEMENT << nl;
os<< token::END_BLOCK << nl;
<< token::END_STATEMENT << nl << token::END_BLOCK << nl;
os.check
(

View File

@ -163,6 +163,13 @@ void Foam::fieldMinMax::execute()
// Do nothing - only valid on write
}
void Foam::fieldMinMax::end()
{
// Do nothing - only valid on write
}
void Foam::fieldMinMax::write()
{
if (active_)

View File

@ -80,8 +80,8 @@ protected:
// Protected data
//- Name of this set of forces,
// Also used as the name of the probes directory.
//- Name of this set of field min/max.
// Also used as the name of the output directory.
word name_;
const objectRegistry& obr_;
@ -108,7 +108,7 @@ protected:
// Private Member Functions
//- If the forces file has not been created create it
//- If the output file has not been created create it
void makeFile();
//- Disallow default bitwise copy construct
@ -147,18 +147,21 @@ public:
// Member Functions
//- Return name of the set of forces
//- Return name of the set of field min/max
virtual const word& name() const
{
return name_;
}
//- Read the forces data
//- Read the field min/max data
virtual void read(const dictionary&);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Calculate the field min/max
template<class Type>
void calcMinMaxFields(const word& fieldName);

View File

@ -104,6 +104,12 @@ void Foam::forceCoeffs::execute()
}
void Foam::forceCoeffs::end()
{
// Do nothing - only valid on write
}
void Foam::forceCoeffs::write()
{
if (active_)

View File

@ -126,9 +126,12 @@ public:
//- Read the forces data
virtual void read(const dictionary&);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Write the forces
virtual void write();
};

View File

@ -273,6 +273,13 @@ void Foam::forces::execute()
// Do nothing - only valid on write
}
void Foam::forces::end()
{
// Do nothing - only valid on write
}
void Foam::forces::write()
{
if (active_)

View File

@ -200,9 +200,12 @@ public:
//- Read the forces data
virtual void read(const dictionary&);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Write the forces
virtual void write();

View File

@ -41,15 +41,14 @@ namespace Foam
Foam::systemCall::systemCall
(
const word& name,
const objectRegistry& obr,
const objectRegistry&,
const dictionary& dict,
const bool loadFromFiles
const bool
)
:
name_(name),
obr_(obr),
active_(true),
executeCalls_(),
endCalls_(),
writeCalls_()
{
read(dict);
@ -66,8 +65,16 @@ Foam::systemCall::~systemCall()
void Foam::systemCall::read(const dictionary& dict)
{
dict.lookup("executeCalls") >> executeCalls_;
dict.lookup("writeCalls") >> writeCalls_;
dict.readIfPresent("executeCalls", executeCalls_);
dict.readIfPresent("endCalls", endCalls_);
dict.readIfPresent("writeCalls", writeCalls_);
if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
{
WarningIn("Foam::system::read(const dictionary&)")
<< "no executeCalls, endCalls or writeCalls defined."
<< endl;
}
}
@ -79,6 +86,16 @@ void Foam::systemCall::execute()
}
}
void Foam::systemCall::end()
{
forAll(endCalls_, callI)
{
::system(endCalls_[callI].c_str());
}
}
void Foam::systemCall::write()
{
forAll(writeCalls_, callI)

View File

@ -63,14 +63,12 @@ protected:
//- Name of this set of system calls
word name_;
const objectRegistry& obr_;
//- on/off switch
bool active_;
//- List of calls to execute - every step
stringList executeCalls_;
//- List of calls to execute when exiting the time-loop
stringList endCalls_;
//- List of calls to execute - write steps
stringList writeCalls_;
@ -97,9 +95,9 @@ public:
systemCall
(
const word& name,
const objectRegistry&,
const objectRegistry& unused,
const dictionary&,
const bool loadFromFiles = false
const bool loadFromFilesUnused = false
);
@ -119,10 +117,13 @@ public:
//- Read the system calls
virtual void read(const dictionary&);
//- Execute
//- Execute the "executeCalls" at each time-step
virtual void execute();
//- Write
//- Execute the "endCalls" at the final time-loop
virtual void end();
//- Write, execute the "writeCalls"
virtual void write();
//- Update for changes of mesh

View File

@ -58,7 +58,7 @@ Foam::dynamicPressure::dynamicPressure
name_(name),
obr_(obr),
active_(true),
pName_(dict.lookup("p")),
pName_(dict.lookupOrDefault<word>("p", "p")),
rho_(readScalar(dict.lookup("rho")))
{
// Check if the available mesh is an fvMesh, otherwise deactivate
@ -68,7 +68,7 @@ Foam::dynamicPressure::dynamicPressure
WarningIn
(
"dynamicPressure::dynamicPressure"
"(const objectRegistry& obr, const dictionary& dict)"
"(const objectRegistry&, const dictionary&)"
) << "No fvMesh available, deactivating." << nl
<< endl;
}
@ -81,7 +81,7 @@ Foam::dynamicPressure::dynamicPressure
WarningIn
(
"dynamicPressure::dynamicPressure"
"(const objectRegistry& obr, const dictionary& dict)"
"(const objectRegistry&, const dictionary&)"
) << "Pressure is not kinematic pressure, deactivating." << nl
<< endl;
}
@ -103,7 +103,7 @@ void Foam::dynamicPressure::read(const dictionary& dict)
{
if (active_)
{
dict.lookup("p") >> pName_;
dict.readIfPresent("p", pName_);
dict.lookup("rho") >> rho_;
}
}
@ -115,6 +115,12 @@ void Foam::dynamicPressure::execute()
}
void Foam::dynamicPressure::end()
{
// Do nothing - only valid on write
}
void Foam::dynamicPressure::write()
{
if (active_)

View File

@ -66,10 +66,10 @@ class dynamicPressure
//- on/off switch
bool active_;
//- Name of pressure field
//- Name of pressure field, default is "p"
word pName_;
//- Density
//- Density value
scalar rho_;
@ -120,9 +120,12 @@ public:
//- Read the dynamicPressure data
virtual void read(const dictionary&);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Calculate the dynamicPressure and write
virtual void write();

View File

@ -48,8 +48,6 @@ graphField/writePatchGraph.C
graphField/writeCellGraph.C
graphField/makeGraph.C
outputFilters/outputFilterOutputControl/outputFilterOutputControl.C
meshToMesh = meshToMeshInterpolation/meshToMesh
$(meshToMesh)/meshToMesh.C
$(meshToMesh)/calculateMeshToMeshAddressing.C

View File

@ -304,6 +304,12 @@ void Foam::probes::execute()
}
void Foam::probes::end()
{
// Do nothing - only valid on write
}
void Foam::probes::write()
{
if (probeLocations_.size() && checkFieldTypes())

View File

@ -194,15 +194,18 @@ public:
return cellList_;
}
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Sample and write
virtual void write();
//- Read the probes
virtual void read(const dictionary&);
//- Execute
virtual void execute();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}

View File

@ -275,6 +275,12 @@ void Foam::sampledSets::execute()
}
void Foam::sampledSets::end()
{
// Do nothing - only valid on write
}
void Foam::sampledSets::write()
{
if (size() && checkFieldTypes())

View File

@ -270,9 +270,12 @@ public:
//- set verbosity level
void verbose(const bool verbosity = true);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Sample and write
virtual void write();

View File

@ -335,7 +335,7 @@ bool Foam::sampledIsoSurface::updateGeometry() const
subMeshPtr_.reset
(
new fvMeshSubset(static_cast<const fvMesh&>(mesh()))
new fvMeshSubset(fvm)
);
subMeshPtr_().setLargeCellSubset
(

View File

@ -87,7 +87,7 @@ class sampledIsoSurface
// Recreated for every isoSurface
//- Time at last call, also track it surface needs an update
//- Time at last call, also track if surface needs an update
mutable label prevTimeIndex_;
//- Cached volfield

View File

@ -203,7 +203,6 @@ Foam::sampledSurfaces::~sampledSurfaces()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sampledSurfaces::verbose(const bool verbosity)
{
verbose_ = verbosity;
@ -216,6 +215,12 @@ void Foam::sampledSurfaces::execute()
}
void Foam::sampledSurfaces::end()
{
// Do nothing - only valid on write
}
void Foam::sampledSurfaces::write()
{
if (size() && checkFieldTypes())

View File

@ -257,9 +257,12 @@ public:
//- set verbosity level
void verbose(const bool verbosity = true);
//- Execute
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Sample and write
virtual void write();