mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: invert logic of residualControl check to allow dictionary entry.
- lets the user specify controls like this:
maxResiduals
{
p 5e-4;
U 1e-3;
"(k|epsilon|omega)" 1e-3;
}
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
*--------------------------------*- C++ -*----------------------------------*\
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
@ -55,10 +55,13 @@ functions
|
||||
outputInterval 1;
|
||||
|
||||
maxResiduals
|
||||
(
|
||||
( p 5e-4 )
|
||||
( U 1e-3 )
|
||||
);
|
||||
{
|
||||
p 5e-4;
|
||||
U 1e-3;
|
||||
|
||||
// possibly check turbulence fields
|
||||
"(k|epsilon|omega)" 1e-3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,40 +24,35 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "residualControl.H"
|
||||
#include "dictionary.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(residualControl, 0);
|
||||
}
|
||||
defineTypeNameAndDebug(Foam::residualControl, 0);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::residualControl::checkCriteria(const bool output) const
|
||||
bool Foam::residualControl::checkCriteria(const bool verbose) const
|
||||
{
|
||||
bool achieved = true;
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
forAll(maxResiduals_, i)
|
||||
|
||||
forAllConstIter(dictionary, solverDict, iter)
|
||||
{
|
||||
const word& variableName = maxResiduals_[i].first();
|
||||
if (solverDict.found(variableName))
|
||||
const word& variableName = iter().keyword();
|
||||
scalar maxResidual;
|
||||
|
||||
if (maxResiduals_.readIfPresent(variableName, maxResidual))
|
||||
{
|
||||
const scalar maxResidual = maxResiduals_[i].second();
|
||||
|
||||
const lduMatrix::solverPerformance
|
||||
sp(solverDict.lookup(variableName));
|
||||
|
||||
const scalar eqnResidual = sp.initialResidual();
|
||||
const scalar eqnResidual =
|
||||
lduMatrix::solverPerformance(iter().stream()).initialResidual();
|
||||
|
||||
achieved = achieved && (eqnResidual < maxResidual);
|
||||
|
||||
if (output)
|
||||
if (verbose)
|
||||
{
|
||||
Info<< " " << variableName
|
||||
<< ": requested max residual = " << maxResidual
|
||||
@ -121,7 +116,7 @@ void Foam::residualControl::read(const dictionary& dict)
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
dict.lookup("maxResiduals") >> maxResiduals_;
|
||||
maxResiduals_ = dict.subDict("maxResiduals");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,8 +37,8 @@ SourceFiles
|
||||
#ifndef residualControl_H
|
||||
#define residualControl_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "pointFieldFwd.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -69,8 +69,8 @@ protected:
|
||||
//- On/off switch - on if obr_ is an fvMesh object
|
||||
bool active_;
|
||||
|
||||
//- List of variable name vs max residual
|
||||
List<Tuple2<word, scalar> > maxResiduals_;
|
||||
//- Dictionary of variable names vs max residual
|
||||
dictionary maxResiduals_;
|
||||
|
||||
//- Flag to indicate whether convergence criteria have been met
|
||||
bool criteriaSatisfied_;
|
||||
@ -79,7 +79,7 @@ protected:
|
||||
// Protected Member Functions
|
||||
|
||||
//- Perform residual control checks
|
||||
bool checkCriteria(const bool output) const;
|
||||
bool checkCriteria(const bool verbose) const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
residualControl(const residualControl&);
|
||||
@ -113,7 +113,7 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return name of the system call set
|
||||
//- Return name of the residual criteria check name
|
||||
virtual const word& name() const
|
||||
{
|
||||
return name_;
|
||||
@ -122,13 +122,13 @@ public:
|
||||
//- Read the system calls
|
||||
virtual void read(const dictionary&);
|
||||
|
||||
//- Execute the "executeCalls" at each time-step
|
||||
//- Check the residual criteria at each time-step
|
||||
virtual void execute();
|
||||
|
||||
//- Execute the "endCalls" at the final time-loop
|
||||
//- Report residual criteria check at the final time-loop
|
||||
virtual void end();
|
||||
|
||||
//- Write, execute the "writeCalls"
|
||||
//- Write, not used
|
||||
virtual void write();
|
||||
|
||||
//- Update for changes of mesh
|
||||
|
||||
Reference in New Issue
Block a user