mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: Multiple changes - first clean build after latest merge - UNTESTED
This commit is contained in:
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "averageCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(averageCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObjectName")),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
tolerance_(readScalar(dict.lookup("tolerance"))),
|
||||
window_(dict.lookupOrDefault<scalar>("window", -1)),
|
||||
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
|
||||
resetOnRestart_(false)
|
||||
{
|
||||
if (resetOnRestart_)
|
||||
{
|
||||
const dictionary& dict = conditionDict();
|
||||
|
||||
forAll(fieldNames_, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldI];
|
||||
|
||||
if (dict.found(fieldName))
|
||||
{
|
||||
const dictionary& valueDict = dict.subDict(fieldName);
|
||||
totalTime_[fieldI] = readScalar(valueDict.lookup("totalTime"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::~averageCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
scalar dt = obr_.time().deltaTValue();
|
||||
|
||||
if (log_) Info<< " " << 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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
unprocessedFields.append(fieldI);
|
||||
}
|
||||
|
||||
totalTime_[fieldI] += dt;
|
||||
}
|
||||
|
||||
if (unprocessedFields.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "From function object: " << functionObjectName_ << nl
|
||||
<< "Unprocessed fields:" << nl;
|
||||
|
||||
forAll(unprocessedFields, i)
|
||||
{
|
||||
label fieldI = unprocessedFields[i];
|
||||
Info<< " " << fieldNames_[fieldI] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_) Info<< endl;
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
{
|
||||
dictionary& conditionDict = this->conditionDict();
|
||||
|
||||
forAll(fieldNames_, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldI];
|
||||
|
||||
// value dictionary should be present - mean values are written there
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
valueDict.add("totalTime", totalTime_[fieldI], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary valueDict;
|
||||
valueDict.add("totalTime", totalTime_[fieldI], true);
|
||||
conditionDict.add(fieldName, valueDict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::averageCondition
|
||||
|
||||
Description
|
||||
Average run time condition - satisfied when average does not change by
|
||||
more than a given value.
|
||||
|
||||
SourceFiles
|
||||
averageCondition.H
|
||||
averageCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef averageCondition_H
|
||||
#define averageCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Switch.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class averageCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class averageCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object to retrueve data from
|
||||
word functionObjectName_;
|
||||
|
||||
//- List of fields on which to operate
|
||||
wordList fieldNames_;
|
||||
|
||||
//- Satisfied when difference in mean values is less than this value
|
||||
const scalar tolerance_;
|
||||
|
||||
//- Averaging window
|
||||
const scalar window_;
|
||||
|
||||
//- Average time per field
|
||||
List<scalar> totalTime_;
|
||||
|
||||
//- Reset the averaging process on restart flag
|
||||
Switch resetOnRestart_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Templated function to calculate the average
|
||||
template<class Type>
|
||||
void calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("average");
|
||||
|
||||
//- Constructor
|
||||
averageCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~averageCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "averageConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
if (pTraits<Type>::typeName != valueType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
|
||||
const word meanName(fieldName + "Mean");
|
||||
|
||||
Type meanValue = state_.getResult<Type>(meanName);
|
||||
meanValue = alpha*meanValue + beta*currentValue;
|
||||
|
||||
scalar delta = mag(meanValue - currentValue);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
}
|
||||
|
||||
state_.setResult(meanName, meanValue);
|
||||
|
||||
if (delta > tolerance_)
|
||||
{
|
||||
satisfied = false;
|
||||
}
|
||||
|
||||
processed = true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,231 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "equationInitialResidualCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(equationInitialResidualCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationInitialResidualCondition,
|
||||
dictionary
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::equationInitialResidualCondition
|
||||
::operatingMode,
|
||||
2
|
||||
>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::equationInitialResidualCondition
|
||||
::operatingMode,
|
||||
2
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
operatingModeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value"))),
|
||||
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
|
||||
mode_(operatingModeNames.read(dict.lookup("mode")))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
~equationInitialResidualCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((obr_.time().timeIndex() < 3) || (obr_.time().value() < timeStart_))
|
||||
{
|
||||
// Do not start checking until reached start time
|
||||
return false;
|
||||
}
|
||||
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
List<scalar> result(fieldNames_.size(), -VGREAT);
|
||||
|
||||
forAll(fieldNames_, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldI];
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const scalar residual = sp.first().initialResidual();
|
||||
result[fieldI] = residual;
|
||||
|
||||
switch (mode_)
|
||||
{
|
||||
case omMin:
|
||||
{
|
||||
if (residual < value_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case omMax:
|
||||
{
|
||||
if (residual > value_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unhandled enumeration "
|
||||
<< operatingModeNames[mode_]
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
forAll(result, i)
|
||||
{
|
||||
if (result[i] < 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for any fields: "
|
||||
<< "deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::equationInitialResidualCondition
|
||||
|
||||
Description
|
||||
Minimum or maximum initial residual run time condition
|
||||
|
||||
SourceFiles
|
||||
equationInitialResidualCondition.H
|
||||
equationInitialResidualCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
#define functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class equationInitialResidualCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class equationInitialResidualCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
enum operatingMode
|
||||
{
|
||||
omMin, //< Minimum
|
||||
omMax //< Maximum
|
||||
};
|
||||
|
||||
static const NamedEnum<operatingMode, 2> operatingModeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
|
||||
//- Start checking from time - always skips first iteration
|
||||
scalar timeStart_;
|
||||
|
||||
//- Operating mode
|
||||
operatingMode mode_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("equationInitialResidual");
|
||||
|
||||
//- Constructor
|
||||
equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationInitialResidualCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,181 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "equationMaxIterCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(equationMaxIterCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationMaxIterCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
equationMaxIterCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
threshold_(readLabel(dict.lookup("threshold"))),
|
||||
startIter_(dict.lookupOrDefault("startIter", 2))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
startIter_ = max(startIter_, 2);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
~equationMaxIterCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obr_.time().timeIndex() < startIter_)
|
||||
{
|
||||
// Do not start checking until start iter
|
||||
return false;
|
||||
}
|
||||
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
List<label> result(fieldNames_.size(), -1);
|
||||
|
||||
forAll(fieldNames_, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldI];
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const label nIterations = sp.first().nIterations();
|
||||
result[fieldI] = nIterations;
|
||||
|
||||
if (nIterations > threshold_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
forAll(result, i)
|
||||
{
|
||||
if (result[i] < 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Number of iterations data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Number of iterations data not found for any fields: "
|
||||
<< "deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationMaxIterCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::equationMaxIterCondition
|
||||
|
||||
Description
|
||||
Maximum number of equation iterations run time condition
|
||||
|
||||
SourceFiles
|
||||
equationMaxIterCondition.H
|
||||
equationMaxIterCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeConditions_equationMaxIterCondition_H
|
||||
#define functionObjects_runTimeConditions_equationMaxIterCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class equationMaxIterCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class equationMaxIterCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Threshold for maximum number of iterations
|
||||
const label threshold_;
|
||||
|
||||
//- Start checking from iteration - always skips first iteration
|
||||
label startIter_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("equationMaxIter");
|
||||
|
||||
//- Constructor
|
||||
equationMaxIterCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationMaxIterCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,180 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "minMaxCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fieldTypes.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<>
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::
|
||||
setValue<Foam::scalar>
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const
|
||||
{
|
||||
state_.getObjectResult(functionObjectName_, fieldName, value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(minMaxCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, minMaxCondition, dictionary);
|
||||
|
||||
template<>
|
||||
const char* NamedEnum<minMaxCondition::modeType, 2>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::minMaxCondition
|
||||
::modeType,
|
||||
2
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::modeTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObjectName")),
|
||||
mode_(modeTypeNames_.read(dict.lookup("mode"))),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::~minMaxCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
forAll(fieldNames_, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldI];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
if (valueType == word::null)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unable to find entry " << fieldName
|
||||
<< " for function object " << functionObjectName_
|
||||
<< ". Condition will not be applied."
|
||||
<< endl;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
scalar v = 0;
|
||||
setValue<scalar>(valueType, fieldName, v);
|
||||
setValue<vector>(valueType, fieldName, v);
|
||||
setValue<sphericalTensor>(valueType, fieldName, v);
|
||||
setValue<symmTensor>(valueType, fieldName, v);
|
||||
setValue<tensor>(valueType, fieldName, v);
|
||||
|
||||
Switch ok = false;
|
||||
switch (mode_)
|
||||
{
|
||||
case mdMin:
|
||||
{
|
||||
if (v < value_)
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case mdMax:
|
||||
{
|
||||
if (v > value_)
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
}
|
||||
|
||||
satisfied = satisfied && ok;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,151 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Class
|
||||
Foam::minMaxCondition
|
||||
|
||||
Description
|
||||
Minimum/maximum run time conditions. If the value type is not scalar,
|
||||
the magnitude of the value is used in the evaluation.
|
||||
|
||||
SourceFiles
|
||||
minMaxCondition.H
|
||||
minMaxCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_minMaxCondition_H
|
||||
#define functionObjects_runTimeControls_minMaxCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class minMaxCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class minMaxCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
// Mode type
|
||||
enum modeType
|
||||
{
|
||||
mdMin, //< Minimum
|
||||
mdMax //< Maximum
|
||||
};
|
||||
|
||||
static const NamedEnum<modeType, 2> modeTypeNames_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object to retrueve data from
|
||||
word functionObjectName_;
|
||||
|
||||
//- Mode
|
||||
modeType mode_;
|
||||
|
||||
//- Field names
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
|
||||
//- Helper function to retrieve the value from the state dictionary
|
||||
template<class Type>
|
||||
void setValue
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("minMax");
|
||||
|
||||
//- Constructor
|
||||
minMaxCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minMaxCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
template<>
|
||||
void minMaxCondition::setValue<Foam::scalar>
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const;
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "minMaxConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::setValue
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const
|
||||
{
|
||||
if (pTraits<Type>::typeName != valueType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type v = state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
value = mag(v);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "minTimeStepCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(minTimeStepCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
minTimeStepCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
minTimeStepCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
minValue_(readScalar(dict.lookup("minValue")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
~minTimeStepCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obr_.time().deltaTValue() < minValue_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::minTimeStepCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,105 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::minTimeStepCondition
|
||||
|
||||
Description
|
||||
Minimum time step condition
|
||||
|
||||
SourceFiles
|
||||
minTimeStepCondition.H
|
||||
minTimeStepCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeConditions_minTimeStepCondition_H
|
||||
#define functionObjects_runTimeConditions_minTimeStepCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class minTimeStepCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class minTimeStepCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Minumim time step value to compare
|
||||
const scalar minValue_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("minTimeStep");
|
||||
|
||||
//- Constructor
|
||||
minTimeStepCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minTimeStepCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeCondition, 0);
|
||||
defineRunTimeSelectionTable(runTimeCondition, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::setConditionDict()
|
||||
{
|
||||
dictionary& propertyDict = state_.propertyDict();
|
||||
|
||||
if (!propertyDict.found(name_))
|
||||
{
|
||||
propertyDict.add(name_, dictionary());
|
||||
}
|
||||
|
||||
return propertyDict.subDict(name_);
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::conditionDict() const
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::conditionDict()
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
state_(state),
|
||||
active_(dict.lookupOrDefault<bool>("active", true)),
|
||||
conditionDict_(setConditionDict()),
|
||||
log_(dict.lookupOrDefault("log", true)),
|
||||
groupID_(dict.lookupOrDefault("groupID", -1))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::~runTimeCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::word&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeCondition::active() const
|
||||
{
|
||||
return active_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::groupID() const
|
||||
{
|
||||
return groupID_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::runTimeCondition
|
||||
|
||||
Description
|
||||
Base class for run time conditions
|
||||
|
||||
SourceFiles
|
||||
runTimeCondition.C
|
||||
runTimeConditionNew.C
|
||||
runTimeCondition.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_runTimeCondition_H
|
||||
#define functionObjects_runTimeControls_runTimeCondition_H
|
||||
|
||||
#include "stateFunctionObject.H"
|
||||
#include "dictionary.H"
|
||||
#include "autoPtr.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeCondition
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Condition name
|
||||
word name_;
|
||||
|
||||
//- Reference to the object registry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- State
|
||||
stateFunctionObject& state_;
|
||||
|
||||
//- On/off switch
|
||||
bool active_;
|
||||
|
||||
//- 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
|
||||
// satisfield before condition is met
|
||||
label groupID_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set the condition dictionary (create if necessary)
|
||||
dictionary& setConditionDict();
|
||||
|
||||
//- Return const access to the conditions dictionary
|
||||
const dictionary& conditionDict() const;
|
||||
|
||||
//- Return non-const access to the conditions dictionary
|
||||
dictionary& conditionDict();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimeCondition");
|
||||
|
||||
//- Declare runtime constructor selection table
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
runTimeCondition,
|
||||
dictionary,
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
),
|
||||
(name, obr, dict, state)
|
||||
);
|
||||
|
||||
|
||||
//- Constructor
|
||||
runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeCondition();
|
||||
|
||||
//- Selector
|
||||
static autoPtr<runTimeCondition> New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the condition name
|
||||
virtual const word& name() const;
|
||||
|
||||
//- Return the active flag
|
||||
virtual bool active() const;
|
||||
|
||||
//- Return the group index
|
||||
virtual label groupID() const;
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply() = 0;
|
||||
|
||||
//- Write
|
||||
virtual void write() = 0;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::functionObjects::runTimeControls::runTimeCondition>
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
{
|
||||
word conditionType(dict.lookup("type"));
|
||||
|
||||
Info<< "Selecting runTimeCondition " << conditionType << endl;
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(conditionType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown runTimeCondition type "
|
||||
<< conditionType << nl << nl
|
||||
<< "Valid runTimeCondition types are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<runTimeCondition>
|
||||
(
|
||||
cstrIter()(conditionName, obr, dict, state)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
247
src/functionObjects/utilities/runTimeControl/runTimeControl.C
Normal file
247
src/functionObjects/utilities/runTimeControl/runTimeControl.C
Normal file
@ -0,0 +1,247 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeControl.H"
|
||||
#include "dictionary.H"
|
||||
#include "runTimeCondition.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeControl, 0);
|
||||
addToRunTimeSelectionTable(functionObject, runTimeControl, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::~runTimeControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
conditions_.setSize(conditionNames.size());
|
||||
|
||||
label uniqueGroupI = 0;
|
||||
forAll(conditionNames, conditionI)
|
||||
{
|
||||
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
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool active = false;
|
||||
forAll(conditions_, conditionI)
|
||||
{
|
||||
if (conditions_[conditionI].active())
|
||||
{
|
||||
active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active)
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " All conditions are inactive" << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl;
|
||||
|
||||
// IDs of satisfied conditions
|
||||
DynamicList<label> IDs(conditions_.size());
|
||||
|
||||
// Run stops only if all conditions within a group are satisfied
|
||||
List<bool> groupSatisfied(groupMap_.size(), true);
|
||||
List<bool> groupActive(groupMap_.size(), false);
|
||||
|
||||
forAll(conditions_, conditionI)
|
||||
{
|
||||
runTimeCondition& condition = conditions_[conditionI];
|
||||
|
||||
if (condition.active())
|
||||
{
|
||||
bool conditionSatisfied = condition.apply();
|
||||
|
||||
label groupI = condition.groupID();
|
||||
|
||||
Map<label>::const_iterator conditionIter = groupMap_.find(groupI);
|
||||
|
||||
if (conditionIter == groupMap_.end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "group " << groupI << " not found in map"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (conditionSatisfied)
|
||||
{
|
||||
IDs.append(conditionI);
|
||||
|
||||
groupActive[conditionIter()] = true;
|
||||
|
||||
if (groupI == -1)
|
||||
{
|
||||
// Condition not part of a group - only requires this to be
|
||||
// satisfied for completion flag to be set
|
||||
groupSatisfied[conditionIter()] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
groupSatisfied[conditionIter()] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
forAll(groupSatisfied, groupI)
|
||||
{
|
||||
if (groupSatisfied[groupI] && groupActive[groupI])
|
||||
{
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
forAll(IDs, conditionI)
|
||||
{
|
||||
Info<< " " << conditions_[conditionI].type() << ": "
|
||||
<< 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)
|
||||
{
|
||||
writeStepI_++;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields - final step" << nl;
|
||||
time.writeAndEnd();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Conditions not met - calculations proceeding" << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::write()
|
||||
{
|
||||
forAll(conditions_, conditionI)
|
||||
{
|
||||
conditions_[conditionI].write();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
141
src/functionObjects/utilities/runTimeControl/runTimeControl.H
Normal file
141
src/functionObjects/utilities/runTimeControl/runTimeControl.H
Normal file
@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 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/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjects::runTimeControl
|
||||
|
||||
Group
|
||||
grpJobControlFunctionObjects
|
||||
|
||||
Description
|
||||
Controls when the calculation is terminated based on satisfying
|
||||
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
|
||||
satisfied.
|
||||
|
||||
SourceFiles
|
||||
runTimeControl.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControl_H
|
||||
#define functionObjects_runTimeControl_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "Map.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class runTimeCondition;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeControl
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- List of conditions to satisfy
|
||||
PtrList<runTimeCondition> conditions_;
|
||||
|
||||
//- Map to define group IDs
|
||||
Map<label> groupMap_;
|
||||
|
||||
//- Number of write steps before exiting
|
||||
label nWriteStep_;
|
||||
|
||||
//- Current number of steps written
|
||||
label writeStepI_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
runTimeControl(const runTimeControl&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const runTimeControl&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimeControl");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the runTimeControl data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual void timeSet();
|
||||
|
||||
//- Calculate the runTimeControl and write
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user