ENH: Initial implementation for FO activation by trigger

This commit is contained in:
Andrew Heather
2018-08-16 12:44:33 +01:00
parent a8fa75246b
commit 21d2d7e6c3
8 changed files with 142 additions and 26 deletions

View File

@ -458,6 +458,15 @@ Foam::autoPtr<Foam::functionObjectList> Foam::functionObjectList::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::functionObjectList::triggerIndex() const
{
label triggeri = labelMin;
stateDict().readIfPresent("triggerIndex", triggeri);
return triggeri;
}
void Foam::functionObjectList::resetState()
{
// Reset (re-read) the state dictionary

View File

@ -174,6 +174,9 @@ public:
//- Access to the functionObjects
using PtrList<functionObject>::operator[];
//- Return the current trigger index (read from the stateDict)
label triggerIndex() const;
//- Reset/read state dictionary for current time
void resetState();

View File

@ -78,6 +78,34 @@ Foam::dictionary& Foam::functionObjects::stateFunctionObject::propertyDict()
}
bool Foam::functionObjects::stateFunctionObject::setTrigger
(
const label triggeri
)
{
IOdictionary& stateDict = this->stateDict();
label oldTriggeri =
stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
if (triggeri > oldTriggeri)
{
stateDict.set("triggerIndex", triggeri);
return true;
}
return false;
}
Foam::label Foam::functionObjects::stateFunctionObject::getTrigger() const
{
const IOdictionary& stateDict = this->stateDict();
return stateDict.lookupOrDefault<label>("triggerIndex", labelMin);
}
bool Foam::functionObjects::stateFunctionObject::foundProperty
(
const word& entryName

View File

@ -125,6 +125,12 @@ public:
//- Return true if the property exists
bool foundProperty(const word& entryName) const;
//- Get the current trigger index
label getTrigger() const;
//- Set the current trigger index
bool setTrigger(const label triggeri);
//- Set dictionary, return true if set
bool getDict
(

View File

@ -51,6 +51,10 @@ void Foam::functionObjects::timeControl::readControls()
{
timeEnd_ = time_.userTimeToTime(timeEnd_);
}
dict_.readIfPresent("triggerStart", triggerStart_);
dict_.readIfPresent("triggerEnd", triggerEnd_);
deltaTCoeff_ = GREAT;
if (dict_.readIfPresent("deltaTCoeff", deltaTCoeff_))
{
@ -70,9 +74,14 @@ void Foam::functionObjects::timeControl::readControls()
bool Foam::functionObjects::timeControl::active() const
{
label triggeri = time_.functionObjects().triggerIndex();
return
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
&& time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue());
(triggeri >= triggerStart_)
|| (
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
&& time_.value() <= (timeEnd_ + 0.5*time_.deltaTValue())
);
}
@ -403,6 +412,8 @@ Foam::functionObjects::timeControl::timeControl
dict_(dict),
timeStart_(-VGREAT),
timeEnd_(VGREAT),
triggerStart_(labelMin),
triggerEnd_(labelMax),
nStepsToStartTimeChange_(labelMax),
executeControl_(t, dict, "execute"),
writeControl_(t, dict, "write"),
@ -426,6 +437,8 @@ bool Foam::functionObjects::timeControl::entriesPresent(const dictionary& dict)
|| Foam::timeControl::entriesPresent(dict, "execute")
|| dict.found("timeStart")
|| dict.found("timeEnd")
|| dict.found("triggerStart")
|| dict.found("triggerEnd")
)
{
return true;

View File

@ -92,6 +92,12 @@ class timeControl
//- De-activation time - defaults to VGREAT
scalar timeEnd_;
//- Activation trigger index - defaults to labelMin
label triggerStart_;
//- De-activation trigger index - defaults to labelMax
label triggerEnd_;
//- Max time step change
scalar deltaTCoeff_;