mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Initial implementation for FO activation by trigger
This commit is contained in:
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
(
|
||||
|
||||
@ -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
|
||||
(triggeri >= triggerStart_)
|
||||
|| (
|
||||
time_.value() >= (timeStart_ - 0.5*time_.deltaTValue())
|
||||
&& time_.value() <= (timeEnd_ + 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;
|
||||
|
||||
@ -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_;
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -58,7 +58,9 @@ Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
writeStepI_(0),
|
||||
satisfiedAction_(satisfiedAction::end),
|
||||
triggerIndex_(labelMin)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
@ -99,7 +101,7 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
|
||||
if (groupMap_.insert(groupi, uniqueGroupi))
|
||||
{
|
||||
uniqueGroupi++;
|
||||
++uniqueGroupi;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,9 +118,9 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool active = false;
|
||||
forAll(conditions_, conditioni)
|
||||
for (const auto& condition : conditions_)
|
||||
{
|
||||
if (conditions_[conditioni].active())
|
||||
if (condition.active())
|
||||
{
|
||||
active = true;
|
||||
break;
|
||||
@ -133,6 +135,21 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
}
|
||||
}
|
||||
|
||||
// Set the action to perform when all conditions are satisfied
|
||||
// - set to end fro backwards compatibility with v1806
|
||||
satisfiedAction_ =
|
||||
satisfiedActionNames.lookupOrDefault
|
||||
(
|
||||
"satisfiedAction",
|
||||
dict,
|
||||
satisfiedAction::end
|
||||
);
|
||||
|
||||
if (satisfiedAction_ == satisfiedAction::setTrigger)
|
||||
{
|
||||
triggerIndex_ = readLabel(dict.lookup("trigger"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -200,20 +217,23 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
|
||||
if (done)
|
||||
{
|
||||
forAll(IDs, conditioni)
|
||||
for (label conditioni : IDs)
|
||||
{
|
||||
Info<< " " << conditions_[conditioni].type() << ": "
|
||||
<< conditions_[conditioni].name()
|
||||
<< " condition satisfied" << nl;
|
||||
}
|
||||
|
||||
|
||||
switch (satisfiedAction_)
|
||||
{
|
||||
case satisfiedAction::end:
|
||||
{
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
{
|
||||
writeStepI_++;
|
||||
++writeStepI_;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
@ -222,6 +242,14 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields - final step" << nl;
|
||||
time.writeAndEnd();
|
||||
break;
|
||||
}
|
||||
}
|
||||
case satisfiedAction::setTrigger:
|
||||
{
|
||||
setTrigger(triggerIndex_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -237,9 +265,9 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::write()
|
||||
{
|
||||
forAll(conditions_, conditioni)
|
||||
for (auto& condition : conditions_)
|
||||
{
|
||||
conditions_[conditioni].write();
|
||||
condition.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016- OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,6 +45,7 @@ SourceFiles
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "Map.H"
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -66,6 +67,21 @@ class runTimeControl
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum class satisfiedAction
|
||||
{
|
||||
end,
|
||||
setTrigger
|
||||
};
|
||||
|
||||
static Enum<satisfiedAction> satisfiedActionNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- List of conditions to satisfy
|
||||
@ -80,6 +96,13 @@ class runTimeControl
|
||||
//- Current number of steps written
|
||||
label writeStepI_;
|
||||
|
||||
//- Action to take when conditions are satified
|
||||
satisfiedAction satisfiedAction_;
|
||||
|
||||
//- Trigger index if satisfiedAction is setTrigger
|
||||
label triggerIndex_;
|
||||
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user