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:
Mark Olesen
2010-04-09 13:42:00 +02:00
parent 3fef72510e
commit 16a16090db
3 changed files with 28 additions and 30 deletions

View File

@ -1,4 +1,4 @@
*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 | | \\ / O peration | Version: 1.6 |
@ -55,10 +55,13 @@ functions
outputInterval 1; outputInterval 1;
maxResiduals maxResiduals
( {
( p 5e-4 ) p 5e-4;
( U 1e-3 ) U 1e-3;
);
// possibly check turbulence fields
"(k|epsilon|omega)" 1e-3;
}
} }
} }

View File

@ -24,40 +24,35 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "residualControl.H" #include "residualControl.H"
#include "dictionary.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "Time.H" #include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam defineTypeNameAndDebug(Foam::residualControl, 0);
{
defineTypeNameAndDebug(residualControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::residualControl::checkCriteria(const bool output) const bool Foam::residualControl::checkCriteria(const bool verbose) const
{ {
bool achieved = true; bool achieved = true;
const fvMesh& mesh = static_cast<const fvMesh&>(obr_); const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
const dictionary& solverDict = mesh.solverPerformanceDict(); const dictionary& solverDict = mesh.solverPerformanceDict();
forAll(maxResiduals_, i)
{
const word& variableName = maxResiduals_[i].first();
if (solverDict.found(variableName))
{
const scalar maxResidual = maxResiduals_[i].second();
const lduMatrix::solverPerformance forAllConstIter(dictionary, solverDict, iter)
sp(solverDict.lookup(variableName)); {
const word& variableName = iter().keyword();
scalar maxResidual;
const scalar eqnResidual = sp.initialResidual(); if (maxResiduals_.readIfPresent(variableName, maxResidual))
{
const scalar eqnResidual =
lduMatrix::solverPerformance(iter().stream()).initialResidual();
achieved = achieved && (eqnResidual < maxResidual); achieved = achieved && (eqnResidual < maxResidual);
if (output) if (verbose)
{ {
Info<< " " << variableName Info<< " " << variableName
<< ": requested max residual = " << maxResidual << ": requested max residual = " << maxResidual
@ -121,7 +116,7 @@ void Foam::residualControl::read(const dictionary& dict)
{ {
if (active_) if (active_)
{ {
dict.lookup("maxResiduals") >> maxResiduals_; maxResiduals_ = dict.subDict("maxResiduals");
} }
} }

View File

@ -37,8 +37,8 @@ SourceFiles
#ifndef residualControl_H #ifndef residualControl_H
#define residualControl_H #define residualControl_H
#include "dictionary.H"
#include "pointFieldFwd.H" #include "pointFieldFwd.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -69,8 +69,8 @@ protected:
//- On/off switch - on if obr_ is an fvMesh object //- On/off switch - on if obr_ is an fvMesh object
bool active_; bool active_;
//- List of variable name vs max residual //- Dictionary of variable names vs max residual
List<Tuple2<word, scalar> > maxResiduals_; dictionary maxResiduals_;
//- Flag to indicate whether convergence criteria have been met //- Flag to indicate whether convergence criteria have been met
bool criteriaSatisfied_; bool criteriaSatisfied_;
@ -79,7 +79,7 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Perform residual control checks //- Perform residual control checks
bool checkCriteria(const bool output) const; bool checkCriteria(const bool verbose) const;
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
residualControl(const residualControl&); residualControl(const residualControl&);
@ -113,7 +113,7 @@ public:
// Member Functions // Member Functions
//- Return name of the system call set //- Return name of the residual criteria check name
virtual const word& name() const virtual const word& name() const
{ {
return name_; return name_;
@ -122,13 +122,13 @@ public:
//- Read the system calls //- Read the system calls
virtual void read(const dictionary&); virtual void read(const dictionary&);
//- Execute the "executeCalls" at each time-step //- Check the residual criteria at each time-step
virtual void execute(); virtual void execute();
//- Execute the "endCalls" at the final time-loop //- Report residual criteria check at the final time-loop
virtual void end(); virtual void end();
//- Write, execute the "writeCalls" //- Write, not used
virtual void write(); virtual void write();
//- Update for changes of mesh //- Update for changes of mesh