mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-run-time-control-triggers' into 'develop'
Feature run time control triggers See merge request Development/OpenFOAM-plus!228
This commit is contained in:
@ -151,7 +151,7 @@ bool Foam::functionObjects::columnAverage::execute()
|
||||
// Make fields up to date with current selection
|
||||
fieldSet_.updateSelection();
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
columnAverageField<scalar>(fieldName);
|
||||
columnAverageField<vector>(fieldName);
|
||||
@ -166,7 +166,7 @@ bool Foam::functionObjects::columnAverage::execute()
|
||||
|
||||
bool Foam::functionObjects::columnAverage::write()
|
||||
{
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word resultName("columnAverage(" + fieldName + ")");
|
||||
const regIOobject* obj =
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -191,7 +191,7 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
|
||||
{
|
||||
fieldSet_.updateSelection();
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
transform<scalar>(fieldName);
|
||||
transform<vector>(fieldName);
|
||||
@ -210,9 +210,9 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
|
||||
|
||||
bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
|
||||
{
|
||||
forAllConstIters(fieldSet_, iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeObject(transformFieldName(iter()));
|
||||
writeObject(transformFieldName(fieldName));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -60,9 +60,8 @@ void Foam::functionObjects::fieldExtents::writeFileHeader(Ostream& os)
|
||||
|
||||
writeCommented(os, "Time");
|
||||
|
||||
forAllConstIters(fieldSet_.selection(), iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word& fieldName = iter();
|
||||
if (internalField_)
|
||||
{
|
||||
writeTabbed(os, fieldName + "_internal");
|
||||
@ -183,7 +182,7 @@ bool Foam::functionObjects::fieldExtents::write()
|
||||
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
calcFieldExtents<scalar>(fieldName, true);
|
||||
calcFieldExtents<vector>(fieldName);
|
||||
|
||||
@ -90,9 +90,8 @@ void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os)
|
||||
}
|
||||
else
|
||||
{
|
||||
forAllConstIters(fieldSet_.selection(), iter)
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
const word& fieldName = iter();
|
||||
writeTabbed(os, "min(" + fieldName + ')');
|
||||
writeTabbed(os, "max(" + fieldName + ')');
|
||||
}
|
||||
@ -153,7 +152,7 @@ bool Foam::functionObjects::fieldMinMax::write()
|
||||
if (!location_) writeTime(file());
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
calcMinMaxFields<scalar>(fieldName, mdCmpt);
|
||||
calcMinMaxFields<vector>(fieldName, mode_);
|
||||
|
||||
@ -17,6 +17,7 @@ runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C
|
||||
runTimeControl/runTimeCondition/runTimeCondition/runTimeConditionNew.C
|
||||
runTimeControl/runTimeCondition/equationMaxIterCondition/equationMaxIterCondition.C
|
||||
runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C
|
||||
runTimeControl/runTimeCondition/maxDurationCondition/maxDurationCondition.C
|
||||
runTimeControl/runTimeCondition/minMaxCondition/minMaxCondition.C
|
||||
runTimeControl/runTimeCondition/averageCondition/averageCondition.C
|
||||
runTimeControl/runTimeCondition/minTimeStepCondition/minTimeStepCondition.C
|
||||
|
||||
@ -64,7 +64,7 @@ void Foam::functionObjects::residuals::writeFileHeader(Ostream& os)
|
||||
|
||||
writeCommented(os, "Time");
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeFileHeader<scalar>(os, fieldName);
|
||||
writeFileHeader<vector>(os, fieldName);
|
||||
@ -193,7 +193,7 @@ bool Foam::functionObjects::residuals::execute()
|
||||
|
||||
if (writeFields_)
|
||||
{
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
initialiseField<scalar>(fieldName);
|
||||
initialiseField<vector>(fieldName);
|
||||
@ -214,7 +214,7 @@ bool Foam::functionObjects::residuals::write()
|
||||
{
|
||||
writeTime(file());
|
||||
|
||||
for (const word& fieldName : fieldSet_.selection())
|
||||
for (const word& fieldName : fieldSet_.selectionNames())
|
||||
{
|
||||
writeResidual<scalar>(fieldName);
|
||||
writeResidual<vector>(fieldName);
|
||||
|
||||
@ -41,6 +41,17 @@ namespace runTimeControls
|
||||
}
|
||||
}
|
||||
|
||||
const Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimeControls::averageCondition::windowType
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::averageCondition::windowTypeNames
|
||||
{
|
||||
{ windowType::NONE, "none" },
|
||||
{ windowType::APPROXIMATE, "approximate" },
|
||||
{ windowType::EXACT, "exact" }
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,86 +68,79 @@ Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
tolerance_(dict.get<scalar>("tolerance")),
|
||||
window_(dict.lookupOrDefault<scalar>("window", -1)),
|
||||
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
|
||||
resetOnRestart_(false)
|
||||
windowType_
|
||||
(
|
||||
window_ > 0 ?
|
||||
windowTypeNames.read(dict.lookup("windowType"))
|
||||
: windowType::NONE
|
||||
),
|
||||
totalTime_(fieldNames_.size(), scalar(0)),
|
||||
resetOnRestart_(dict.lookupOrDefault<bool>("resetOnRestart", false)),
|
||||
nIterStartUp_(dict.lookupOrDefault<label>("nIterStartUp", 10)),
|
||||
iter_(-1)
|
||||
{
|
||||
if (resetOnRestart_)
|
||||
dictionary& conditionDict = this->conditionDict();
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const dictionary& dict = conditionDict();
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
if (resetOnRestart_)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
if (dict.found(fieldName))
|
||||
conditionDict.set(fieldName, dictionary());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
const dictionary& valueDict = dict.subDict(fieldName);
|
||||
valueDict.readEntry("totalTime", totalTime_[fieldi]);
|
||||
const dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
valueDict.readIfPresent("totalTime", totalTime_[fieldi]);
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionDict.set(fieldName, dictionary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conditionDict.readIfPresent("iter", iter_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::~averageCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return satisfied;
|
||||
return true;
|
||||
}
|
||||
|
||||
scalar dt = obr_.time().deltaTValue();
|
||||
bool satisfied = iter_ > nIterStartUp_ ? true : false;
|
||||
|
||||
if (log_) Info<< " " << type() << ": " << name_ << " averages:" << nl;
|
||||
++iter_;
|
||||
|
||||
const scalar dt = obr_.time().deltaTValue();
|
||||
|
||||
Log << " " << type() << ": " << name_ << " averages:" << nl;
|
||||
|
||||
DynamicList<label> unprocessedFields(fieldNames_.size());
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName(fieldNames_[fieldi]);
|
||||
|
||||
scalar Dt = totalTime_[fieldi];
|
||||
scalar alpha = (Dt - dt)/Dt;
|
||||
scalar beta = dt/Dt;
|
||||
|
||||
if (window_ > 0)
|
||||
{
|
||||
if (Dt - dt >= window_)
|
||||
{
|
||||
alpha = (window_ - dt)/window_;
|
||||
beta = dt/window_;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure that averaging is performed over window time
|
||||
// before condition can be satisfied
|
||||
satisfied = false;
|
||||
}
|
||||
}
|
||||
totalTime_[fieldi] += dt;
|
||||
|
||||
bool processed = false;
|
||||
calc<scalar>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<vector>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<sphericalTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<symmTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<tensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<scalar>(fieldi, satisfied, processed);
|
||||
calc<vector>(fieldi, satisfied, processed);
|
||||
calc<sphericalTensor>(fieldi, satisfied, processed);
|
||||
calc<symmTensor>(fieldi, satisfied, processed);
|
||||
calc<tensor>(fieldi, satisfied, processed);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
unprocessedFields.append(fieldi);
|
||||
}
|
||||
|
||||
totalTime_[fieldi] += dt;
|
||||
}
|
||||
|
||||
if (unprocessedFields.size())
|
||||
@ -145,14 +149,13 @@ bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
<< "From function object: " << functionObjectName_ << nl
|
||||
<< "Unprocessed fields:" << nl;
|
||||
|
||||
forAll(unprocessedFields, i)
|
||||
for (const label fieldi : unprocessedFields)
|
||||
{
|
||||
label fieldi = unprocessedFields[i];
|
||||
Info<< " " << fieldNames_[fieldi] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
@ -166,7 +169,6 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
// value dictionary should be present - mean values are written there
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
@ -179,6 +181,8 @@ void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
conditionDict.add(fieldName, valueDict);
|
||||
}
|
||||
}
|
||||
|
||||
conditionDict.set("iter", iter_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,7 +39,7 @@ SourceFiles
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Switch.H"
|
||||
|
||||
#include "Enum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -58,6 +58,20 @@ class averageCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
enum class windowType
|
||||
{
|
||||
NONE,
|
||||
APPROXIMATE,
|
||||
EXACT
|
||||
};
|
||||
|
||||
static const Enum<windowType> windowTypeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
@ -74,12 +88,20 @@ protected:
|
||||
//- Averaging window
|
||||
const scalar window_;
|
||||
|
||||
//- Averaging window type
|
||||
windowType windowType_;
|
||||
|
||||
//- Average time per field
|
||||
List<scalar> totalTime_;
|
||||
|
||||
//- Reset the averaging process on restart flag
|
||||
Switch resetOnRestart_;
|
||||
|
||||
//- Number of start-up iterations before allowing satisfied checks
|
||||
label nIterStartUp_;
|
||||
|
||||
//- Current iteration count
|
||||
label iter_;
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
@ -87,9 +109,7 @@ protected:
|
||||
template<class Type>
|
||||
void calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
const label fieldi,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
);
|
||||
@ -110,7 +130,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~averageCondition();
|
||||
virtual ~averageCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -23,18 +23,21 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "Time.H"
|
||||
#include "FIFOStack.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
const label fieldi,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
@ -43,22 +46,124 @@ void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
return;
|
||||
}
|
||||
|
||||
Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
const scalar dt = obr_.time().deltaTValue();
|
||||
|
||||
const Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
const word meanName(fieldName + "Mean");
|
||||
|
||||
// Current mean value
|
||||
Type meanValue = state_.getResult<Type>(meanName);
|
||||
meanValue = alpha*meanValue + beta*currentValue;
|
||||
|
||||
switch (windowType_)
|
||||
{
|
||||
case windowType::NONE:
|
||||
{
|
||||
const scalar Dt = totalTime_[fieldi];
|
||||
const scalar alpha = (Dt - dt)/Dt;
|
||||
const scalar beta = dt/Dt;
|
||||
meanValue = alpha*meanValue + beta*currentValue;
|
||||
|
||||
break;
|
||||
}
|
||||
case windowType::APPROXIMATE:
|
||||
{
|
||||
const scalar Dt = totalTime_[fieldi];
|
||||
scalar alpha = (Dt - dt)/Dt;
|
||||
scalar beta = dt/Dt;
|
||||
if (Dt - dt >= window_)
|
||||
{
|
||||
alpha = (window_ - dt)/window_;
|
||||
beta = dt/window_;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure that averaging is performed over window time
|
||||
// before condition can be satisfied
|
||||
satisfied = false;
|
||||
}
|
||||
|
||||
meanValue = alpha*meanValue + beta*currentValue;
|
||||
totalTime_[fieldi] += dt;
|
||||
break;
|
||||
}
|
||||
case windowType::EXACT:
|
||||
{
|
||||
FIFOStack<scalar> windowTimes;
|
||||
FIFOStack<Type> windowValues;
|
||||
dictionary& dict = this->conditionDict().subDict(fieldName);
|
||||
dict.readIfPresent("windowTimes", windowTimes);
|
||||
dict.readIfPresent("windowValues", windowValues);
|
||||
|
||||
// Increment time for all existing values
|
||||
for (scalar& dti : windowTimes)
|
||||
{
|
||||
dti += dt;
|
||||
}
|
||||
|
||||
// Remove any values outside the window
|
||||
bool removeValue = true;
|
||||
while (removeValue && windowTimes.size())
|
||||
{
|
||||
removeValue = windowTimes.first() > window_;
|
||||
|
||||
if (removeValue)
|
||||
{
|
||||
windowTimes.pop();
|
||||
windowValues.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the current value
|
||||
windowTimes.push(dt);
|
||||
windowValues.push(currentValue);
|
||||
|
||||
// Calculate the window average
|
||||
typename FIFOStack<scalar>::const_iterator timeIter =
|
||||
windowTimes.begin();
|
||||
typename FIFOStack<Type>::const_iterator valueIter =
|
||||
windowValues.begin();
|
||||
|
||||
meanValue = pTraits<Type>::zero;
|
||||
Type valueOld(pTraits<Type>::zero);
|
||||
|
||||
for
|
||||
(
|
||||
label i = 0;
|
||||
timeIter != windowTimes.end();
|
||||
++i, ++timeIter, ++valueIter
|
||||
)
|
||||
{
|
||||
const Type& value = valueIter();
|
||||
const scalar dt = timeIter();
|
||||
|
||||
meanValue += dt*value;
|
||||
|
||||
if (i)
|
||||
{
|
||||
meanValue -= dt*valueOld;
|
||||
}
|
||||
|
||||
valueOld = value;
|
||||
}
|
||||
|
||||
meanValue /= windowTimes.first();
|
||||
|
||||
// Store the state information for the next step
|
||||
dict.set("windowTimes", windowTimes);
|
||||
dict.set("windowValues", windowValues);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
scalar delta = mag(meanValue - currentValue);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
}
|
||||
Log << " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
|
||||
// Note: Writing result to owner function object and not the local run-time
|
||||
// condition
|
||||
state_.setResult(meanName, meanValue);
|
||||
|
||||
if (delta > tolerance_)
|
||||
|
||||
@ -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-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,10 @@ License
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "volFields.H"
|
||||
|
||||
#define SetResidual(Type) \
|
||||
setResidual<Type>(mesh, solverDict, fieldName, component, canSet, residual);
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -66,8 +70,8 @@ operatingModeNames
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
equationInitialResidualCondition
|
||||
Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
@ -76,12 +80,14 @@ equationInitialResidualCondition
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.get<wordList>("fields")),
|
||||
fieldSelection_(obr, true),
|
||||
value_(dict.get<scalar>("value")),
|
||||
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
|
||||
mode_(operatingModeNames.get("mode", dict))
|
||||
{
|
||||
if (fieldNames_.size())
|
||||
fieldSelection_.read(dict);
|
||||
|
||||
if (fieldSelection_.size())
|
||||
{
|
||||
timeStart_ = obr.time().userTimeToTime(timeStart_);
|
||||
}
|
||||
@ -95,18 +101,13 @@ equationInitialResidualCondition
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
~equationInitialResidualCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
apply()
|
||||
bool Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::apply()
|
||||
{
|
||||
fieldSelection_.updateSelection();
|
||||
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
@ -123,16 +124,25 @@ apply()
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
List<scalar> result(fieldNames_.size(), -VGREAT);
|
||||
const auto& selection = fieldSelection_.selection();
|
||||
List<scalar> result(selection.size(), -VGREAT);
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
forAll(selection, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
const auto& fieldInfo = selection[fieldi];
|
||||
const word& fieldName = fieldInfo.name();
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const scalar residual = sp.first().initialResidual();
|
||||
label component = fieldInfo.component();
|
||||
scalar residual = VGREAT;
|
||||
bool canSet = true;
|
||||
SetResidual(scalar);
|
||||
SetResidual(vector);
|
||||
SetResidual(symmTensor);
|
||||
SetResidual(sphericalTensor);
|
||||
SetResidual(tensor);
|
||||
|
||||
result[fieldi] = residual;
|
||||
|
||||
switch (mode_)
|
||||
@ -171,7 +181,9 @@ apply()
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
<< selection[i].name()
|
||||
<< ". Solver dictionary contains " << solverDict.sortedToc()
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -190,32 +202,26 @@ apply()
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << value_ << nl;
|
||||
}
|
||||
Log << type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << value_ << nl;
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] > 0)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", residual: " << result[resulti] << nl;
|
||||
}
|
||||
Log << " field: " << selection[resulti].name()
|
||||
<< ", residual: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
write()
|
||||
void Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@ -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) 2016 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -37,12 +37,15 @@ SourceFiles
|
||||
#define functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Enum.H"
|
||||
#include "solverFieldSelection.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class fvMesh;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
@ -71,8 +74,8 @@ protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
//- Field names
|
||||
solverFieldSelection fieldSelection_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
@ -84,6 +87,21 @@ protected:
|
||||
operatingMode mode_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set the residual (scalar) value
|
||||
template<class Type>
|
||||
void setResidual
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const dictionary& dict,
|
||||
const word& fieldName,
|
||||
const label componenti,
|
||||
bool& canSet,
|
||||
scalar& residual
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
@ -99,7 +117,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationInitialResidualCondition();
|
||||
virtual ~equationInitialResidualCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
@ -120,6 +138,12 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "equationInitialResidualConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "fvMesh.H"
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::
|
||||
equationInitialResidualCondition::setResidual
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const dictionary& dict,
|
||||
const word& fieldName,
|
||||
const label componenti,
|
||||
bool& canSet,
|
||||
scalar& residual
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
|
||||
|
||||
if (canSet && mesh.foundObject<volFieldType>(fieldName))
|
||||
{
|
||||
const List<SolverPerformance<Type>> sp(dict.lookup(fieldName));
|
||||
const Type& allComponents = sp.first().initialResidual();
|
||||
|
||||
if (componenti != -1)
|
||||
{
|
||||
if (componenti > pTraits<Type>::nComponents - 1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Requested component [" << componenti
|
||||
<< "] for field " << fieldName
|
||||
<< " is out of range 0.."
|
||||
<< pTraits<Type>::nComponents - 1
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
residual = component(allComponents, componenti);
|
||||
}
|
||||
else
|
||||
{
|
||||
residual = cmptMax(allComponents);
|
||||
}
|
||||
|
||||
canSet = false;
|
||||
}
|
||||
}
|
||||
@ -76,13 +76,6 @@ equationMaxIterCondition
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
~equationMaxIterCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
@ -148,24 +141,18 @@ bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << threshold_ << nl;
|
||||
}
|
||||
Log << type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << threshold_ << nl;
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] != -1)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", iterations: " << result[resulti] << nl;
|
||||
}
|
||||
Log << " field: " << fieldNames_[resulti]
|
||||
<< ", iterations: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
Log << endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
|
||||
@ -84,7 +84,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationMaxIterCondition();
|
||||
virtual ~equationMaxIterCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "maxDurationCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(maxDurationCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
maxDurationCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::maxDurationCondition::
|
||||
maxDurationCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
duration_(dict.get<scalar>("duration")),
|
||||
startTime_(-1),
|
||||
initialised_(false),
|
||||
resetOnRestart_(dict.lookupOrDefault("resetOnRestart", false))
|
||||
{
|
||||
if
|
||||
(
|
||||
!resetOnRestart_
|
||||
&& conditionDict().readIfPresent("startTime", startTime_))
|
||||
{
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
duration_ = obr_.time().userTimeToTime(duration_);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::maxDurationCondition::apply()
|
||||
{
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!initialised_)
|
||||
{
|
||||
startTime_ = obr_.time().value();
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
scalar delta = obr_.time().value() - startTime_;
|
||||
delta = obr_.time().timeToUserTime(delta);
|
||||
|
||||
Log << " " << type() << ": " << name_ << nl
|
||||
<< " Completed " << delta << " out of " << duration_ << nl;
|
||||
|
||||
return delta >= duration_;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::maxDurationCondition::write()
|
||||
{
|
||||
if (initialised_)
|
||||
{
|
||||
conditionDict().set("startTime", startTime_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,113 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimeControls::maxDurationCondition
|
||||
|
||||
Description
|
||||
Activated after a user-specified duration
|
||||
|
||||
SourceFiles
|
||||
maxDurationCondition.H
|
||||
maxDurationCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeConditions_maxDurationCondition_H
|
||||
#define functionObjects_runTimeConditions_maxDurationCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class maxDurationCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class maxDurationCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Duration
|
||||
scalar duration_;
|
||||
|
||||
//- Time when the condition is activated
|
||||
scalar startTime_;
|
||||
|
||||
//- Initialisation flag
|
||||
bool initialised_;
|
||||
|
||||
//- Reset on restart (ignores any state information)
|
||||
Switch resetOnRestart_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("maxDuration");
|
||||
|
||||
//- Constructor
|
||||
maxDurationCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~maxDurationCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -90,12 +90,6 @@ Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::~minMaxCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
@ -107,10 +101,8 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
for (const word& fieldName :fieldNames_)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
@ -153,13 +145,10 @@ bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
}
|
||||
}
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
}
|
||||
Log << " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
|
||||
satisfied = satisfied && ok;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minMaxCondition();
|
||||
virtual ~minMaxCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -63,13 +63,6 @@ minTimeStepCondition
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
~minTimeStepCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply()
|
||||
|
||||
@ -78,7 +78,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minTimeStepCondition();
|
||||
virtual ~minTimeStepCondition() = default;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
@ -84,14 +84,8 @@ Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
|
||||
state_(state),
|
||||
active_(dict.lookupOrDefault("active", true)),
|
||||
conditionDict_(setConditionDict()),
|
||||
log_(dict.lookupOrDefault("log", true)),
|
||||
groupID_(dict.lookupOrDefault("groupID", -1))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::~runTimeCondition()
|
||||
groupID_(dict.lookupOrDefault("groupID", -1)),
|
||||
log(dict.lookupOrDefault("log", true))
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -78,9 +78,6 @@ protected:
|
||||
//- Reference to the condition dictionary
|
||||
dictionary& conditionDict_;
|
||||
|
||||
//- Switch to send output to Info
|
||||
Switch log_;
|
||||
|
||||
//- Group index - if applied, all conditions in a group must be
|
||||
// satisfied before condition is met
|
||||
label groupID_;
|
||||
@ -129,7 +126,7 @@ public:
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeCondition();
|
||||
virtual ~runTimeCondition() = default;
|
||||
|
||||
//- Selector
|
||||
static autoPtr<runTimeCondition> New
|
||||
@ -140,6 +137,11 @@ public:
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
// Public Data
|
||||
|
||||
//- Switch to send output to Info
|
||||
Switch log;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
|
||||
@ -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.
|
||||
@ -44,6 +44,15 @@ namespace runTimeControls
|
||||
}
|
||||
}
|
||||
|
||||
Foam::Enum
|
||||
<
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedAction
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::satisfiedActionNames
|
||||
{
|
||||
{ satisfiedAction::END, "end"},
|
||||
{ satisfiedAction::SET_TRIGGER, "setTrigger"},
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -58,18 +67,15 @@ Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
writeStepI_(0),
|
||||
satisfiedAction_(satisfiedAction::END),
|
||||
triggerIndex_(labelMin),
|
||||
active_(getObjectProperty(name, "active", true))
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::~runTimeControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
@ -77,68 +83,101 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
conditions_.setSize(conditionNames.size());
|
||||
|
||||
label uniqueGroupi = 0;
|
||||
forAll(conditionNames, conditioni)
|
||||
if (functionObject::postProcess)
|
||||
{
|
||||
const word& conditionName = conditionNames[conditioni];
|
||||
const dictionary& dict = conditionsDict.subDict(conditionName);
|
||||
|
||||
conditions_.set
|
||||
(
|
||||
conditioni,
|
||||
runTimeCondition::New(conditionName, obr_, dict, *this)
|
||||
);
|
||||
|
||||
label groupi = conditions_[conditioni].groupID();
|
||||
|
||||
if (groupMap_.insert(groupi, uniqueGroupi))
|
||||
{
|
||||
uniqueGroupi++;
|
||||
}
|
||||
}
|
||||
|
||||
dict.readIfPresent("nWriteStep", nWriteStep_);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " No conditions present" << nl
|
||||
Info<< "Deactivated " << name()
|
||||
<< " function object for post-processing"
|
||||
<< endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
if (fvMeshFunctionObject::read(dict))
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool active = false;
|
||||
forAll(conditions_, conditioni)
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
conditions_.setSize(conditionNames.size());
|
||||
|
||||
label uniqueGroupi = 0;
|
||||
forAll(conditionNames, conditioni)
|
||||
{
|
||||
if (conditions_[conditioni].active())
|
||||
const word& conditionName = conditionNames[conditioni];
|
||||
const dictionary& dict = conditionsDict.subDict(conditionName);
|
||||
|
||||
conditions_.set
|
||||
(
|
||||
conditioni,
|
||||
runTimeCondition::New(conditionName, obr_, dict, *this)
|
||||
);
|
||||
|
||||
label groupi = conditions_[conditioni].groupID();
|
||||
|
||||
if (groupMap_.insert(groupi, uniqueGroupi))
|
||||
{
|
||||
active = true;
|
||||
break;
|
||||
++uniqueGroupi;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active)
|
||||
dict.readIfPresent("nWriteStep", nWriteStep_);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " All conditions are inactive" << nl
|
||||
<< " No conditions present" << nl
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool check = false;
|
||||
for (const auto& condition : conditions_)
|
||||
{
|
||||
if (condition.active())
|
||||
{
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!check)
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " All conditions are inactive" << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
// 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::SET_TRIGGER)
|
||||
{
|
||||
triggerIndex_ = readLabel(dict.lookup("trigger"));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
{
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Info<< type() << " " << name() << " output:" << nl;
|
||||
|
||||
// IDs of satisfied conditions
|
||||
@ -200,33 +239,66 @@ bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
|
||||
if (done)
|
||||
{
|
||||
forAll(IDs, conditioni)
|
||||
for (label conditioni : IDs)
|
||||
{
|
||||
Info<< " " << conditions_[conditioni].type() << ": "
|
||||
<< conditions_[conditioni].name()
|
||||
<< conditions_[conditioni].name()
|
||||
<< " condition satisfied" << nl;
|
||||
}
|
||||
|
||||
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
switch (satisfiedAction_)
|
||||
{
|
||||
writeStepI_++;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields - final step" << nl;
|
||||
time.writeAndEnd();
|
||||
case satisfiedAction::END:
|
||||
{
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
{
|
||||
++writeStepI_;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields";
|
||||
|
||||
if (nWriteStep_ != 0)
|
||||
{
|
||||
Info<< " - final step" << nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
active_ = false;
|
||||
|
||||
// Write any registered objects and set the end-time
|
||||
time.writeAndEnd();
|
||||
|
||||
// Trigger any function objects
|
||||
time.run();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case satisfiedAction::SET_TRIGGER:
|
||||
{
|
||||
Info<< " Setting trigger " << triggerIndex_ << nl;
|
||||
setTrigger(triggerIndex_);
|
||||
|
||||
// Deactivate the model
|
||||
active_ = false;
|
||||
setProperty("active", active_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Conditions not met - calculations proceeding" << nl;
|
||||
Info<< " Conditions not met" << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
@ -237,9 +309,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-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,7 +32,7 @@ Description
|
||||
user-specified conditions.
|
||||
|
||||
Optionally specify a number of write steps before the calculation is
|
||||
terminated. Here, a write is performed each time that all conditons are
|
||||
terminated. Here, a write is performed each time that all conditions are
|
||||
satisfied.
|
||||
|
||||
SourceFiles
|
||||
@ -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,
|
||||
SET_TRIGGER
|
||||
};
|
||||
|
||||
static Enum<satisfiedAction> satisfiedActionNames;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- List of conditions to satisfy
|
||||
@ -80,6 +96,17 @@ class runTimeControl
|
||||
//- Current number of steps written
|
||||
label writeStepI_;
|
||||
|
||||
//- Action to take when conditions are satisfied
|
||||
satisfiedAction satisfiedAction_;
|
||||
|
||||
//- Trigger index if satisfiedAction is setTrigger
|
||||
label triggerIndex_;
|
||||
|
||||
//- Active flag
|
||||
// Used in the trigger case to bypass any evaluations after the
|
||||
// trigger has been set
|
||||
bool active_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -98,8 +125,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
//- Construct for given objectRegistry and dictionary
|
||||
runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
@ -109,7 +135,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeControl();
|
||||
virtual ~runTimeControl() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
Reference in New Issue
Block a user