functionObjectList: Rationalized and simplified the handling of disabled functionObjects

Simplified and generalized the handling of functionObjects which fail to
construct by removing them from the list rather than maintaining an
"enabled" switch in each functionObject.
This commit is contained in:
Henry Weller
2016-05-11 09:03:52 +01:00
parent 080908732d
commit 32dbb01e96
9 changed files with 222 additions and 271 deletions

View File

@ -54,24 +54,24 @@ Foam::functionObjects::setTimeStepFunctionObject::setTimeStepFunctionObject
)
:
functionObject(name),
time_(runTime),
enabled_(true)
time_(runTime)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::setTimeStepFunctionObject::~setTimeStepFunctionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjects::setTimeStepFunctionObject::on()
const Foam::Time&
Foam::functionObjects::setTimeStepFunctionObject::time() const
{
enabled_ = true;
}
void Foam::functionObjects::setTimeStepFunctionObject::off()
{
enabled_ = false;
return time_;
}
@ -104,19 +104,13 @@ bool Foam::functionObjects::setTimeStepFunctionObject::timeSet()
bool Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep()
{
if (enabled())
{
// Wanted timestep
scalar newDeltaT = timeStepPtr_().value(time_.timeOutputValue());
const_cast<Time&>(time()).setDeltaT
(
timeStepPtr_().value(time_.timeOutputValue()),
false
);
const_cast<Time&>(time()).setDeltaT(newDeltaT, false);
return true;
}
else
{
return false;
}
return true;
}
@ -125,27 +119,23 @@ bool Foam::functionObjects::setTimeStepFunctionObject::read
const dictionary& dict
)
{
enabled_ = dict.lookupOrDefault("enabled", true);
timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
if (enabled_)
// Check that adjustTimeStep is active
const dictionary& controlDict = time_.controlDict();
Switch adjust;
if
(
!controlDict.readIfPresent<Switch>("adjustTimeStep", adjust)
|| !adjust
)
{
timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
// Check that time has adjustTimeStep
const dictionary& controlDict = time_.controlDict();
Switch adjust;
if
(
!controlDict.readIfPresent<Switch>("adjustTimeStep", adjust)
|| !adjust
)
{
FatalIOErrorInFunction(dict)
<< "Need to have 'adjustTimeStep' true to enable external"
<< " timestep control" << exit(FatalIOError);
}
FatalIOErrorInFunction(dict)
<< "Need to set 'adjustTimeStep' true to allow timestep control"
<< exit(FatalIOError);
}
return true;
}

View File

@ -43,7 +43,6 @@ SourceFiles
#define functionObjects_setTimeStepFunctionObject_H
#include "functionObject.H"
#include "dictionary.H"
#include "Function1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,15 +65,11 @@ class setTimeStepFunctionObject
//- Reference to the time database
const Time& time_;
//- Time step function/table
autoPtr<Function1<scalar>> timeStepPtr_;
// Optional user inputs
//- Switch for the execution - defaults to 'yes/on'
bool enabled_;
//- Time step
autoPtr<Function1<scalar>> timeStepPtr_;
// Private member functions
//- Disallow default bitwise copy construct
setTimeStepFunctionObject(const setTimeStepFunctionObject&);
@ -84,9 +79,11 @@ class setTimeStepFunctionObject
public:
//- Runtime type information
TypeName("setTimeStep");
// Constructors
//- Construct from components
@ -98,32 +95,20 @@ public:
);
// Destructor
virtual ~setTimeStepFunctionObject();
// Member Functions
// Access
//- Return time database
virtual const Time& time() const
{
return time_;
}
//- Return the enabled flag
virtual bool enabled() const
{
return enabled_;
}
const Time& time() const;
// Function object control
//- 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();
@ -147,9 +132,9 @@ public:
//- Update for changes of mesh
virtual void movePoints(const polyMesh& mesh);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects