From 2e80e7c6ef62503a9125a309c7d06816c194bc78 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 27 Sep 2011 15:37:15 +0100 Subject: [PATCH] BUG: solutionControl solver objects can return false positives in residualControl Reported by Mark Olesen --- .../pimpleControl/pimpleControl.C | 29 ++++++++++--------- .../pimpleControl/pimpleControl.H | 4 +-- .../simpleControl/simpleControl.C | 23 ++++++++------- .../simpleControl/simpleControl.H | 4 +-- .../solutionControl/solutionControl.H | 10 +++---- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C index 8707d021ad..87c3f13090 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C +++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C @@ -59,36 +59,37 @@ bool Foam::pimpleControl::criteriaSatisfied() bool firstIter = corr_ == 1; bool achieved = true; - const dictionary& solverDict = mesh_.solverPerformanceDict(); + bool checked = false; // safety that some checks were indeed performed + const dictionary& solverDict = mesh_.solverPerformanceDict(); forAllConstIter(dictionary, solverDict, iter) { const word& variableName = iter().keyword(); - label fieldI = applyToField(variableName); + const label fieldI = applyToField(variableName); if (fieldI != -1) { const List sp(iter().stream()); const scalar residual = sp.last().initialResidual(); + checked = true; + if (firstIter) { residualControl_[fieldI].initialResidual = sp.first().initialResidual(); } - bool absCheck = residual < residualControl_[fieldI].absTol; - + const bool absCheck = residual < residualControl_[fieldI].absTol; bool relCheck = false; scalar relative = 0.0; if (!firstIter) { - scalar iniRes = + const scalar iniRes = residualControl_[fieldI].initialResidual + ROOTVSMALL; relative = residual/iniRes; - relCheck = relative < residualControl_[fieldI].relTol; } @@ -110,7 +111,7 @@ bool Foam::pimpleControl::criteriaSatisfied() } } - return achieved; + return checked && achieved; } @@ -129,7 +130,13 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh) if (nOuterCorr_ > 1) { Info<< nl; - if (!residualControl_.empty()) + if (residualControl_.empty()) + { + Info<< algorithmName_ << ": no residual control data found. " + << "Calculations will employ " << nOuterCorr_ + << " corrector loops" << nl << endl; + } + else { Info<< algorithmName_ << ": max iterations = " << nOuterCorr_ << endl; @@ -142,12 +149,6 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh) } Info<< endl; } - else - { - Info<< algorithmName_ << ": no residual control data found. " << nl - << "Calculations will employ " << nOuterCorr_ - << " corrector loops" << nl << endl; - } } else { diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H index 54831aa97d..3b891a5aa9 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H +++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H @@ -69,10 +69,10 @@ protected: // Protected Member Functions - //- Read constrols from fvSolution dictionary + //- Read controls from fvSolution dictionary virtual void read(); - //- Return true if all convergence checks are satified + //- Return true if all convergence checks are satisfied virtual bool criteriaSatisfied(); //- Disallow default bitwise copy construct diff --git a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C index f40f19e04a..d2b603a5e0 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C +++ b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C @@ -50,17 +50,20 @@ bool Foam::simpleControl::criteriaSatisfied() } bool achieved = true; - const dictionary& solverDict = mesh_.solverPerformanceDict(); + bool checked = false; // safety that some checks were indeed performed + const dictionary& solverDict = mesh_.solverPerformanceDict(); forAllConstIter(dictionary, solverDict, iter) { const word& variableName = iter().keyword(); - label fieldI = applyToField(variableName); + const label fieldI = applyToField(variableName); if (fieldI != -1) { const List sp(iter().stream()); const scalar residual = sp.first().initialResidual(); + checked = true; + bool absCheck = residual < residualControl_[fieldI].absTol; achieved = achieved && absCheck; @@ -75,7 +78,7 @@ bool Foam::simpleControl::criteriaSatisfied() } } - return achieved; + return checked && achieved; } @@ -90,7 +93,13 @@ Foam::simpleControl::simpleControl(fvMesh& mesh) Info<< nl; - if (residualControl_.size() > 0) + if (residualControl_.empty()) + { + Info<< algorithmName_ << ": no convergence criteria found. " + << "Calculations will run for " << mesh_.time().endTime().value() + << " steps." << nl << endl; + } + else { Info<< algorithmName_ << ": convergence criteria" << nl; forAll(residualControl_, i) @@ -101,12 +110,6 @@ Foam::simpleControl::simpleControl(fvMesh& mesh) } Info<< endl; } - else - { - Info<< algorithmName_ << ": no convergence criteria found. " - << "Calculations will run for " << mesh_.time().endTime().value() - << " steps." << nl << endl; - } } diff --git a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H index e4a2e69cba..ee718ce424 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H +++ b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H @@ -59,10 +59,10 @@ protected: // Protected Member Functions - //- Read constrols from fvSolution dictionary + //- Read controls from fvSolution dictionary void read(); - //- Return true if all convergence checks are satified + //- Return true if all convergence checks are satisfied bool criteriaSatisfied(); //- Disallow default bitwise copy construct diff --git a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H index 75565551a2..82dd73dd9a 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H +++ b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H @@ -40,7 +40,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class solutionControl Declaration + Class solutionControl Declaration \*---------------------------------------------------------------------------*/ class solutionControl @@ -78,19 +78,19 @@ protected: //- Flag to indicate to solve for momentum bool momentumPredictor_; - //- Flag to indictae to solve using transonic algorithm + //- Flag to indicate to solve using transonic algorithm bool transonic_; // Protected Member Functions - //- Read constrols from fvSolution dictionary + //- Read controls from fvSolution dictionary virtual void read(const bool absTolOnly); //- Return index of field in residualControl_ if present virtual label applyToField(const word& fieldName) const; - //- Return true if all convergence checks are satified + //- Return true if all convergence checks are satisfied virtual bool criteriaSatisfied() = 0; //- Store previous iteration fields @@ -142,7 +142,7 @@ public: //- Flag to indicate to solve for momentum inline bool momentumPredictor() const; - //- Flag to indictae to solve using transonic algorithm + //- Flag to indicate to solve using transonic algorithm inline bool transonic() const; };