Commit fee6e312 authored by Mark Olesen's avatar Mark Olesen
Browse files

Time and functionObject updated for end()

- added end() method to functionObject, functionObjectList & associated classes
- moved outputFilters from src/sampling -> src/OpenFOAM/db/functionObjects
parent c2256e51
......@@ -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
......
......@@ -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_);
}
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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&);
};
......
......@@ -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,
......
......@@ -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;
};
......
......@@ -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;
}
// ************************************************************************* //
......@@ -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();
};
......
......@@ -255,6 +255,15 @@ void Foam::fieldAverage::execute()
}
void Foam::fieldAverage::end()
{
if (active_)
{
calcAverages();
}
}
void Foam::fieldAverage::write()
{
if (active_)
......
......@@ -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();
};
......
......@@ -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
(
......
......@@ -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_)
......
......@@ -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);
......
......@@ -104,6 +104,12 @@ void Foam::forceCoeffs::execute()
}
void Foam::forceCoeffs::end()
{
// Do nothing - only valid on write
}
void Foam::forceCoeffs::write()
{
if (active_)
......
......@@ -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();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment