ENH: timeControl - extended use of time and triggers

This commit is contained in:
Andrew Heather
2018-08-21 13:09:21 +01:00
parent 74dc8b3ce1
commit 848f0266eb
2 changed files with 73 additions and 16 deletions

View File

@ -38,6 +38,15 @@ namespace functionObjects
} }
} }
const Foam::Enum<Foam::functionObjects::timeControl::controlMode>
Foam::functionObjects::timeControl::controlModeNames_
{
{ controlMode::TIME, "time" },
{ controlMode::TRIGGER, "trigger" },
{ controlMode::TIME_OR_TRIGGER, "timeOrTrigger" },
{ controlMode::TIME_AND_TRIGGER, "timeAndTrigger" }
};
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
@ -52,8 +61,11 @@ void Foam::functionObjects::timeControl::readControls()
timeEnd_ = time_.userTimeToTime(timeEnd_); timeEnd_ = time_.userTimeToTime(timeEnd_);
} }
dict_.readIfPresent("triggerStart", triggerStart_); if (dict_.readIfPresent("triggerStart", triggerStart_))
dict_.readIfPresent("triggerEnd", triggerEnd_); {
dict_.readIfPresent("triggerEnd", triggerEnd_);
controlMode_ = controlModeNames_.read(dict_.lookup("controlMode"));
}
deltaTCoeff_ = GREAT; deltaTCoeff_ = GREAT;
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_)) if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
@ -76,12 +88,39 @@ bool Foam::functionObjects::timeControl::active() const
{ {
label triggeri = time_.functionObjects().triggerIndex(); label triggeri = time_.functionObjects().triggerIndex();
return bool inTime =
(triggeri >= triggerStart_) time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
|| ( && time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue());
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
&& time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue()) bool inTrigger = triggeri >= triggerStart_ && triggeri <= triggerEnd_;
);
switch (controlMode_)
{
case controlMode::TIME:
{
return inTime;
}
case controlMode::TRIGGER:
{
return inTrigger;
}
case controlMode::TIME_OR_TRIGGER:
{
return inTime || inTrigger;
}
case controlMode::TIME_AND_TRIGGER:
{
return inTime && inTrigger;
}
default:
{
FatalErrorInFunction
<< "Unhandled enumeration: " << controlModeNames_[controlMode_]
<< abort(FatalError);
}
}
return false;
} }
@ -410,9 +449,10 @@ Foam::functionObjects::timeControl::timeControl
functionObject(name), functionObject(name),
time_(t), time_(t),
dict_(dict), dict_(dict),
controlMode_(controlMode::TIME),
timeStart_(-VGREAT), timeStart_(-VGREAT),
timeEnd_(VGREAT), timeEnd_(VGREAT),
triggerStart_(labelMin), triggerStart_(labelMax),
triggerEnd_(labelMax), triggerEnd_(labelMax),
nStepsToStartTimeChange_(labelMax), nStepsToStartTimeChange_(labelMax),
executeControl_(t, dict, "execute"), executeControl_(t, dict, "execute"),
@ -694,7 +734,7 @@ bool Foam::functionObjects::timeControl::adjustTimeStep()
// Set time, deltaT adjustments for writeInterval purposes // Set time, deltaT adjustments for writeInterval purposes
// are already taken care. Hence disable auto-update // are already taken care. Hence disable auto-update
const_cast<Time&>( time_).setDeltaT(newDeltaT, false); const_cast<Time&>(time_).setDeltaT(newDeltaT, false);
if (seriesDTCoeff_ < 1.0) if (seriesDTCoeff_ < 1.0)
{ {
@ -759,12 +799,7 @@ bool Foam::functionObjects::timeControl::read(const dictionary& dict)
bool Foam::functionObjects::timeControl::filesModified() const bool Foam::functionObjects::timeControl::filesModified() const
{ {
bool mod = false; return active() ? foPtr_->filesModified() : false;
if (active())
{
mod = foPtr_->filesModified();
}
return mod;
} }

View File

@ -75,6 +75,25 @@ class timeControl
: :
public functionObject public functionObject
{ {
public:
// Public enumerations
//- Control mode
enum class controlMode
{
TIME,
TRIGGER,
TIME_OR_TRIGGER,
TIME_AND_TRIGGER
};
static const Enum<controlMode> controlModeNames_;
private:
// Private data // Private data
//- Reference to the time database //- Reference to the time database
@ -86,6 +105,9 @@ class timeControl
// Optional user inputs // Optional user inputs
//- Control mode (combination of time/trigger behaviour)
controlMode controlMode_;
//- Activation time - defaults to -VGREAT //- Activation time - defaults to -VGREAT
scalar timeStart_; scalar timeStart_;