From 3f53a04f091bc8980eadea73b52caf4c9b106ec4 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Wed, 26 Oct 2011 14:29:49 +0100
Subject: [PATCH] ENH: Extended and restructured solutionControl class

---
 .../compressibleInterFoam/alphaEqnsSubCycle.H |   2 +-
 .../alphaEqnsSubCycle.H                       |   2 +-
 .../pimpleControl/pimpleControl.C             |  65 +++++++++--
 .../pimpleControl/pimpleControl.H             |  28 +----
 .../pimpleControl/pimpleControlI.H            | 110 +-----------------
 .../simpleControl/simpleControl.C             |  34 ++++++
 .../simpleControl/simpleControl.H             |   6 +-
 .../simpleControl/simpleControlI.H            |  30 -----
 .../solutionControl/solutionControl.C         |   4 +-
 .../solutionControl/solutionControl.H         |  27 +++++
 .../solutionControl/solutionControlI.H        |  40 +++++++
 11 files changed, 173 insertions(+), 175 deletions(-)

diff --git a/applications/solvers/multiphase/compressibleInterFoam/alphaEqnsSubCycle.H b/applications/solvers/multiphase/compressibleInterFoam/alphaEqnsSubCycle.H
index 6270f7e9e5d..2d70a5bab59 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/alphaEqnsSubCycle.H
+++ b/applications/solvers/multiphase/compressibleInterFoam/alphaEqnsSubCycle.H
@@ -31,7 +31,7 @@
     }
 
     // correct interface on first PIMPLE corrector
-    if (pimple.corrPIMPLE() == 1)
+    if (pimple.corr() == 1)
     {
         interface.correct();
     }
diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/alphaEqnsSubCycle.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/alphaEqnsSubCycle.H
index 862dc60409f..ade8af00817 100644
--- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/alphaEqnsSubCycle.H
+++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/alphaEqnsSubCycle.H
@@ -33,7 +33,7 @@
     }
 
     // correct interface on first PIMPLE corrector
-    if (pimple.corrPIMPLE() == 1)
+    if (pimple.corr() == 1)
     {
         interface.correct();
     }
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C
index d3b295cdf29..98a742e16bf 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C
+++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C
@@ -44,8 +44,6 @@ void Foam::pimpleControl::read()
     const dictionary& pimpleDict = dict();
     nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
     nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
-    nCorrNonOrtho_ =
-        pimpleDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 1);
     turbOnFinalIterOnly_ =
         pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
 }
@@ -54,7 +52,7 @@ void Foam::pimpleControl::read()
 bool Foam::pimpleControl::criteriaSatisfied()
 {
     // no checks on first iteration - nothing has been calculated yet
-    if ((corrPIMPLE_ == 1) || residualControl_.empty() || finalIter())
+    if ((corr_ == 1) || residualControl_.empty() || finalIter())
     {
         return false;
     }
@@ -104,7 +102,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
                 Info<< algorithmName_ << " loop:" << endl;
 
                 Info<< "    " << variableName
-                    << " PIMPLE iter " << corrPIMPLE_
+                    << " PIMPLE iter " << corr_
                     << ": ini res = "
                     << residualControl_[fieldI].initialResidual
                     << ", abs tol = " << residual
@@ -127,10 +125,7 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh)
     solutionControl(mesh, "PIMPLE"),
     nCorrPIMPLE_(0),
     nCorrPISO_(0),
-    nCorrNonOrtho_(0),
-    corrPIMPLE_(0),
     corrPISO_(0),
-    corrNonOrtho_(0),
     turbOnFinalIterOnly_(true)
 {
     read();
@@ -172,4 +167,60 @@ Foam::pimpleControl::~pimpleControl()
 {}
 
 
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+bool Foam::pimpleControl::loop()
+{
+    read();
+
+    corr_++;
+
+    if (debug)
+    {
+        Info<< algorithmName_ << " loop: corr = " << corr_ << endl;
+    }
+
+    if (corr_ == nCorrPIMPLE_ + 1)
+    {
+        if ((!residualControl_.empty()) && (nCorrPIMPLE_ != 1))
+        {
+            Info<< algorithmName_ << ": not converged within "
+                << nCorrPIMPLE_ << " iterations" << endl;
+        }
+
+        corr_ = 0;
+        mesh_.data::remove("finalIteration");
+        return false;
+    }
+
+    bool completed = false;
+    if (criteriaSatisfied())
+    {
+        Info<< algorithmName_ << ": converged in " << corr_ << " iterations"
+            << endl;
+        completed = true;
+    }
+    else
+    {
+        if (finalIter())
+        {
+            mesh_.data::add("finalIteration", true);
+        }
+
+        if (corr_ <= nCorrPIMPLE_)
+        {
+            if (nCorrPIMPLE_ != 1)
+            {
+                Info<< algorithmName_ << ": iteration " << corr_ << endl;
+                storePrevIterFields();
+            }
+
+            completed = false;
+        }
+    }
+
+    return !completed;
+}
+
+
 // ************************************************************************* //
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H
index 0e6b2195056..9a5912e4fb7 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H
@@ -60,18 +60,9 @@ protected:
             //- Maximum number of PISO correctors
             label nCorrPISO_;
 
-            //- Maximum number of non-orthogonal correctors
-            label nCorrNonOrtho_;
-
-            //- Current PIMPLE corrector
-            label corrPIMPLE_;
-
             //- Current PISO corrector
             label corrPISO_;
 
-            //- Current non-orthogonal corrector
-            label corrNonOrtho_;
-
             //- Flag to indicate whether to only solve turbulence on final iter
             bool turbOnFinalIterOnly_;
 
@@ -120,39 +111,24 @@ public:
             //- Maximum number of PISO correctors
             inline label nCorrPISO() const;
 
-            //- Maximum number of non-orthogonal correctors
-            inline label nCorrNonOrtho() const;
-
-            //- Current PIMPLE corrector index
-            inline label corrPIMPLE() const;
-
             //- Current PISO corrector index
             inline label corrPISO() const;
 
-            //- Current non-orthogonal corrector index
-            inline label corrNonOrtho() const;
-
 
         // Solution control
 
             //- PIMPLE loop
-            inline bool loop();
+            virtual bool loop();
 
-            //- Corrector loop
+            //- Pressure corrector loop
             inline bool correct();
 
-            //- Non-orthogonal corrector loop
-            inline bool correctNonOrthogonal();
-
             //- Helper function to identify when to store the intial residuals
             inline bool storeInitialResiduals() const;
 
             //- Helper function to identify final PIMPLE (outer) iteration
             inline bool finalIter() const;
 
-            //- Helper function to identify final non-orthogonal iteration
-            inline bool finalNonOrthogonalIter() const;
-
             //- Helper function to identify final inner iteration
             inline bool finalInnerIter() const;
 
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControlI.H b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControlI.H
index 791c71b730f..1fe60987317 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControlI.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControlI.H
@@ -37,82 +37,12 @@ inline Foam::label Foam::pimpleControl::nCorrPISO() const
 }
 
 
-inline Foam::label Foam::pimpleControl::nCorrNonOrtho() const
-{
-    return nCorrPISO_;
-}
-
-
-inline Foam::label Foam::pimpleControl::corrPIMPLE() const
-{
-    return corrPIMPLE_;
-}
-
-
 inline Foam::label Foam::pimpleControl::corrPISO() const
 {
     return corrPISO_;
 }
 
 
-inline Foam::label Foam::pimpleControl::corrNonOrtho() const
-{
-    return corrNonOrtho_;
-}
-
-
-inline bool Foam::pimpleControl::loop()
-{
-    corrPIMPLE_++;
-
-    if (debug)
-    {
-        Info<< algorithmName_ << " loop: corrPIMPLE = " << corrPIMPLE_ << endl;
-    }
-
-    if (corrPIMPLE_ == nCorrPIMPLE_ + 1)
-    {
-        if ((!residualControl_.empty()) && (nCorrPIMPLE_ != 1))
-        {
-            Info<< algorithmName_ << ": not converged within "
-                << nCorrPIMPLE_ << " iterations" << endl;
-        }
-
-        corrPIMPLE_ = 0;
-        mesh_.data::remove("finalIteration");
-        return false;
-    }
-
-    bool completed = false;
-    if (criteriaSatisfied())
-    {
-        Info<< algorithmName_ << ": converged in " << corrPIMPLE_
-            << " iterations" << endl;
-        completed = true;
-    }
-    else
-    {
-        if (finalIter())
-        {
-            mesh_.data::add("finalIteration", true);
-        }
-
-        if (corrPIMPLE_ <= nCorrPIMPLE_)
-        {
-            if (nCorrPIMPLE_ != 1)
-            {
-                Info<< algorithmName_ << ": iteration " << corrPIMPLE_ << endl;
-                storePrevIterFields();
-            }
-
-            completed = false;
-        }
-    }
-
-    return !completed;
-}
-
-
 inline bool Foam::pimpleControl::correct()
 {
     corrPISO_++;
@@ -134,53 +64,25 @@ inline bool Foam::pimpleControl::correct()
 }
 
 
-inline bool Foam::pimpleControl::correctNonOrthogonal()
-{
-    corrNonOrtho_++;
-
-    if (debug)
-    {
-        Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
-            << corrNonOrtho_ << endl;
-    }
-
-    if (corrNonOrtho_ <= nCorrNonOrtho_ + 1)
-    {
-        return true;
-    }
-    else
-    {
-        corrNonOrtho_ = 0;
-        return false;
-    }
-}
-
-
 inline bool Foam::pimpleControl::storeInitialResiduals() const
 {
     // start from second PIMPLE iteration
-    return (corrPIMPLE_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
+    return (corr_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
 }
 
 
 inline bool Foam::pimpleControl::finalIter() const
 {
-    return corrPIMPLE_ == nCorrPIMPLE_;
-}
-
-
-inline bool Foam::pimpleControl::finalNonOrthogonalIter() const
-{
-    return corrNonOrtho_ == nCorrNonOrtho_ + 1;
+    return corr_ == nCorrPIMPLE_;
 }
 
 
 inline bool Foam::pimpleControl::finalInnerIter() const
 {
-     return
-        corrPIMPLE_ == nCorrPIMPLE_
-     && corrPISO_ == nCorrPISO_
-     && corrNonOrtho_ == nCorrNonOrtho_ + 1;
+    return
+       corr_ == nCorrPIMPLE_
+    && corrPISO_ == nCorrPISO_
+    && corrNonOrtho_ == nNonOrthCorr_ + 1;
 }
 
 
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C
index d2b603a5e01..b944f38b8f4 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C
+++ b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.C
@@ -119,4 +119,38 @@ Foam::simpleControl::~simpleControl()
 {}
 
 
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+bool Foam::simpleControl::loop()
+{
+    read();
+
+    Time& time = const_cast<Time&>(mesh_.time());
+
+    if (initialised_)
+    {
+        if (criteriaSatisfied())
+        {
+            Info<< nl << algorithmName_ << " solution converged in "
+                << time.timeName() << " iterations" << nl << endl;
+
+            // Set to finalise calculation
+            time.writeAndEnd();
+        }
+        else
+        {
+            storePrevIterFields();
+        }
+    }
+    else
+    {
+        initialised_ = true;
+        storePrevIterFields();
+    }
+
+
+    return time.loop();
+}
+
+
 // ************************************************************************* //
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H
index ee718ce424b..71f8d0e04c7 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControl.H
@@ -96,7 +96,7 @@ public:
         // Solution control
 
             //- Loop loop
-            inline bool loop();
+            virtual bool loop();
 };
 
 
@@ -106,10 +106,6 @@ public:
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-#include "simpleControlI.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 #endif
 
 // ************************************************************************* //
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControlI.H b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControlI.H
index 9080c9b2452..eaca9b079d0 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControlI.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/simpleControl/simpleControlI.H
@@ -27,36 +27,6 @@ License
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-inline bool Foam::simpleControl::loop()
-{
-    read();
-
-    Time& time = const_cast<Time&>(mesh_.time());
-
-    if (initialised_)
-    {
-        if (criteriaSatisfied())
-        {
-            Info<< nl << algorithmName_ << " solution converged in "
-                << time.timeName() << " iterations" << nl << endl;
-
-            // Set to finalise calculation
-            time.writeAndEnd();
-        }
-        else
-        {
-            storePrevIterFields();
-        }
-    }
-    else
-    {
-        initialised_ = true;
-        storePrevIterFields();
-    }
-
-
-    return time.loop();
-}
 
 
 // ************************************************************************* //
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.C b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.C
index a238d94e0af..3de1587e7e9 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.C
+++ b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.C
@@ -170,7 +170,9 @@ Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
     algorithmName_(algorithmName),
     nNonOrthCorr_(0),
     momentumPredictor_(true),
-    transonic_(false)
+    transonic_(false),
+    corr_(0),
+    corrNonOrtho_(0)
 {}
 
 
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H
index 94a8b413052..45970fc325b 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H
@@ -82,6 +82,15 @@ protected:
             bool transonic_;
 
 
+        // Evolution
+
+            //- Current corrector loop index
+            label corr_;
+
+            //- Current non-orthogonal corrector loop index
+            label corrNonOrtho_;
+
+
     // Protected Member Functions
 
         //- Read controls from fvSolution dictionary
@@ -137,17 +146,35 @@ public:
             //- Return the solution dictionary
             inline const dictionary& dict() const;
 
+            //- Current corrector loop index
+            inline label corr() const;
+
+            //- Current non-orthogonal corrector index
+            inline label corrNonOrtho() const;
+
 
         // Solution control
 
             //- Maximum number of non-orthogonal correctors
             inline label nNonOrthCorr() const;
 
+            //- Helper function to identify final non-orthogonal iteration
+            inline bool finalNonOrthogonalIter() const;
+
             //- Flag to indicate to solve for momentum
             inline bool momentumPredictor() const;
 
             //- Flag to indicate to solve using transonic algorithm
             inline bool transonic() const;
+
+
+        // Evolution
+
+            //- Main control loop
+            virtual bool loop() = 0;
+
+            //- Non-orthogonal corrector loop
+            inline bool correctNonOrthogonal();
 };
 
 
diff --git a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControlI.H b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControlI.H
index 438c8569d3e..b9d975cfba2 100644
--- a/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControlI.H
+++ b/src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControlI.H
@@ -31,12 +31,30 @@ inline const Foam::dictionary& Foam::solutionControl::dict() const
 }
 
 
+inline Foam::label Foam::solutionControl::corr() const
+{
+    return corr_;
+}
+
+
+inline Foam::label Foam::solutionControl::corrNonOrtho() const
+{
+    return corrNonOrtho_;
+}
+
+
 inline Foam::label Foam::solutionControl::nNonOrthCorr() const
 {
     return nNonOrthCorr_;
 }
 
 
+inline bool Foam::solutionControl::finalNonOrthogonalIter() const
+{
+    return corrNonOrtho_ == nNonOrthCorr_ + 1;
+}
+
+
 inline bool Foam::solutionControl::momentumPredictor() const
 {
     return momentumPredictor_;
@@ -49,4 +67,26 @@ inline bool Foam::solutionControl::transonic() const
 }
 
 
+inline bool Foam::solutionControl::correctNonOrthogonal()
+{
+    corrNonOrtho_++;
+
+    if (debug)
+    {
+        Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
+            << corrNonOrtho_ << endl;
+    }
+
+    if (corrNonOrtho_ <= nNonOrthCorr_ + 1)
+    {
+        return true;
+    }
+    else
+    {
+        corrNonOrtho_ = 0;
+        return false;
+    }
+}
+
+
 // ************************************************************************* //
-- 
GitLab