From 4c8122783aedaa7dadf0486163a98350e625db32 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 12 Jan 2018 12:10:01 +0000 Subject: [PATCH] solutionControl: Multi-region and PIMPLE time-loop control The solution controls have been rewritten for use in multi-region solvers, and PIMPLE fluid/solid solution controls have been implemented within this framework. PIMPLE also now has time-loop convergence control which can be used to end the simulation once a certain initial residual is reached. This allows a PIMPLE solver to run with equivalent convergence control to a SIMPLE solver. Corrector loop convergence control is still available, and can be used at the same time as the time-loop control. The "residualControl" sub-dictionary of PIMPLE contains the residual values required on the first solve of a time-step for the simulation to end. This behaviour is the same as SIMPLE. The "outerCorrectorResidualControl" sub-dictionary contains the tolerances required for the corrector loop to exit. An example specification with both types of control active is shown below. PIMPLE { // ... residualControl { p 1e-3; U 1e-4; "(k|epsilon|omega)" 1e-3; } outerCorrectorResidualControl { U { tolerance 1e-4; relTol 0.1; } "(k|epsilon|omega)" { tolerance 1e-3; relTol 0.1; } } } Note that existing PIMPLE "residualControl" entries will need to be renamed "outerCorrectorResidualControl". Application within a solver has also changed slightly. In order to have convergence control for the time loop as a whole, the solutionControl::loop(Time&) method (or the equivalent run method) must be used; i.e., while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; // solve ... } or, while (pimple.run(runTime)) { // pre-time-increment operations ... runTime ++; Info<< "Time = " << runTime.timeName() << nl << endl; // solve ... } --- .../basic/laplacianFoam/laplacianFoam.C | 4 +- .../scalarTransportFoam/scalarTransportFoam.C | 4 +- .../rhoPorousSimpleFoam/rhoPorousSimpleFoam.C | 4 +- .../rhoSimpleFoam/rhoSimpleFoam.C | 4 +- .../buoyantBoussinesqSimpleFoam.C | 4 +- .../buoyantSimpleFoam/buoyantSimpleFoam.C | 4 +- .../heatTransfer/thermoFoam/thermoFoam.C | 4 +- .../adjointShapeOptimizationFoam.C | 4 +- .../simpleFoam/SRFSimpleFoam/SRFSimpleFoam.C | 4 +- .../porousSimpleFoam/porousSimpleFoam.C | 4 +- .../incompressible/simpleFoam/simpleFoam.C | 4 +- .../simpleReactingParcelFoam.C | 4 +- src/finiteVolume/Make/files | 22 +- .../convergenceControl/convergenceControl.C | 99 +++++ .../convergenceControl/convergenceControl.H | 174 +++++++++ .../convergenceControlTemplates.C | 74 ++++ .../correctorConvergenceControl.C | 74 ++++ .../correctorConvergenceControl.H | 170 +++++++++ .../correctorConvergenceControlTemplates.C | 47 +++ .../singleRegionConvergenceControl.C | 193 ++++++++++ .../singleRegionConvergenceControl.H | 115 ++++++ .../singleRegionCorrectorConvergenceControl.C | 272 ++++++++++++++ .../singleRegionCorrectorConvergenceControl.H | 123 ++++++ .../pimpleControl/pimpleControl.C | 248 ------------- .../pimpleControl/pimpleControl.H | 180 --------- .../pimpleControl/pimpleControl.C | 136 +++++++ .../pimpleControl/pimpleControl.H | 135 +++++++ .../pimpleControl/pimpleControlI.H | 34 ++ .../pimpleControl/pimpleControlI.H | 112 ------ .../pimpleControl/pimpleLoop/pimpleLoop.C | 136 +++++++ .../pimpleControl/pimpleLoop/pimpleLoop.H | 134 +++++++ .../pimpleControl/pimpleLoop/pimpleLoopI.H | 58 +++ .../pimpleMultiRegionControl.C | 349 ++++++++++++++++++ .../pimpleMultiRegionControl.H | 169 +++++++++ .../pimpleMultiRegionControlI.H | 48 +++ .../pimpleNoLoopControl/pimpleNoLoopControl.C | 89 +++++ .../pimpleNoLoopControl/pimpleNoLoopControl.H | 124 +++++++ .../pimpleNoLoopControlI.H | 40 ++ .../solutionControl/pisoControl/pisoControl.C | 55 ++- .../solutionControl/pisoControl/pisoControl.H | 74 ++-- .../pisoControl/pisoControlI.H | 26 +- .../simpleControl/simpleControl.C | 173 ++------- .../simpleControl/simpleControl.H | 76 ++-- .../solidNoLoopControl/solidNoLoopControl.C | 76 ++++ .../solidNoLoopControl/solidNoLoopControl.H | 94 +++++ .../fluidSolutionControl.C | 79 ++++ .../fluidSolutionControl.H | 127 +++++++ .../fluidSolutionControlI.H} | 60 +-- .../multiRegionSolutionControl.C | 64 ++++ .../multiRegionSolutionControl.H | 97 +++++ .../nonOrthogonalSolutionControl.C | 92 +++++ .../nonOrthogonalSolutionControl.H | 121 ++++++ .../nonOrthogonalSolutionControlI.H | 46 +++ .../singleRegionSolutionControl.C | 74 ++++ .../singleRegionSolutionControl.H | 127 +++++++ .../singleRegionSolutionControlI.H | 40 ++ .../singleRegionSolutionControlTemplates.C} | 26 +- .../solutionControl/solutionControl.C | 244 ------------ .../solutionControl/solutionControl.H | 232 ------------ .../solutionControl/solutionControl.C | 85 +++++ .../solutionControl/solutionControl.H | 133 +++++++ .../solutionControl/solutionControlI.H | 46 +++ .../RAS/angledDuct/system/fvSolution | 2 +- 63 files changed, 4348 insertions(+), 1324 deletions(-) create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControlTemplates.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControlTemplates.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.H delete mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C delete mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl/pimpleControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl/pimpleControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl/pimpleControlI.H delete mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControlI.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleLoop/pimpleLoop.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleLoop/pimpleLoop.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleLoop/pimpleLoopI.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleMultiRegionControl/pimpleMultiRegionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleMultiRegionControl/pimpleMultiRegionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleMultiRegionControl/pimpleMultiRegionControlI.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleNoLoopControl/pimpleNoLoopControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleNoLoopControl/pimpleNoLoopControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleNoLoopControl/pimpleNoLoopControlI.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solidControl/solidNoLoopControl/solidNoLoopControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solidControl/solidNoLoopControl/solidNoLoopControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/fluidSolutionControl/fluidSolutionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/fluidSolutionControl/fluidSolutionControl.H rename src/finiteVolume/cfdTools/general/solutionControl/solutionControl/{solutionControlI.H => fluidSolutionControl/fluidSolutionControlI.H} (51%) create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/multiRegionSolutionControl/multiRegionSolutionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/multiRegionSolutionControl/multiRegionSolutionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/nonOrthogonalSolutionControl/nonOrthogonalSolutionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/nonOrthogonalSolutionControl/nonOrthogonalSolutionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/nonOrthogonalSolutionControl/nonOrthogonalSolutionControlI.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/singleRegionSolutionControl/singleRegionSolutionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/singleRegionSolutionControl/singleRegionSolutionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/singleRegionSolutionControl/singleRegionSolutionControlI.H rename src/finiteVolume/cfdTools/general/solutionControl/solutionControl/{solutionControlTemplates.C => singleRegionSolutionControl/singleRegionSolutionControlTemplates.C} (68%) delete mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.C delete mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl/solutionControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl/solutionControl.H create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/solutionControl/solutionControl/solutionControlI.H diff --git a/applications/solvers/basic/laplacianFoam/laplacianFoam.C b/applications/solvers/basic/laplacianFoam/laplacianFoam.C index 06798c829..da2bb4b02 100644 --- a/applications/solvers/basic/laplacianFoam/laplacianFoam.C +++ b/applications/solvers/basic/laplacianFoam/laplacianFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) Info<< "\nCalculating temperature distribution\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/basic/scalarTransportFoam/scalarTransportFoam.C b/applications/solvers/basic/scalarTransportFoam/scalarTransportFoam.C index 502cfd612..c94f8b400 100644 --- a/applications/solvers/basic/scalarTransportFoam/scalarTransportFoam.C +++ b/applications/solvers/basic/scalarTransportFoam/scalarTransportFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) #include "CourantNo.H" - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/rhoPorousSimpleFoam.C b/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/rhoPorousSimpleFoam.C index 3b147460d..2528b96bb 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/rhoPorousSimpleFoam.C +++ b/applications/solvers/compressible/rhoSimpleFoam/rhoPorousSimpleFoam/rhoPorousSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C b/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C index 8135d38f4..f7e857e47 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C +++ b/applications/solvers/compressible/rhoSimpleFoam/rhoSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/buoyantBoussinesqSimpleFoam.C b/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/buoyantBoussinesqSimpleFoam.C index 7847ffc91..fb70d3157 100644 --- a/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/buoyantBoussinesqSimpleFoam.C +++ b/applications/solvers/heatTransfer/buoyantBoussinesqSimpleFoam/buoyantBoussinesqSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/heatTransfer/buoyantSimpleFoam/buoyantSimpleFoam.C b/applications/solvers/heatTransfer/buoyantSimpleFoam/buoyantSimpleFoam.C index 7b12a547f..b97a01554 100644 --- a/applications/solvers/heatTransfer/buoyantSimpleFoam/buoyantSimpleFoam.C +++ b/applications/solvers/heatTransfer/buoyantSimpleFoam/buoyantSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/heatTransfer/thermoFoam/thermoFoam.C b/applications/solvers/heatTransfer/thermoFoam/thermoFoam.C index 08c983ff9..294ce4af0 100644 --- a/applications/solvers/heatTransfer/thermoFoam/thermoFoam.C +++ b/applications/solvers/heatTransfer/thermoFoam/thermoFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) { simpleControl simple(mesh); - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/incompressible/adjointShapeOptimizationFoam/adjointShapeOptimizationFoam.C b/applications/solvers/incompressible/adjointShapeOptimizationFoam/adjointShapeOptimizationFoam.C index d49c83767..e538f0483 100644 --- a/applications/solvers/incompressible/adjointShapeOptimizationFoam/adjointShapeOptimizationFoam.C +++ b/applications/solvers/incompressible/adjointShapeOptimizationFoam/adjointShapeOptimizationFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/SRFSimpleFoam.C b/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/SRFSimpleFoam.C index 4be32db84..f43c7eafe 100644 --- a/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/SRFSimpleFoam.C +++ b/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/SRFSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/porousSimpleFoam.C b/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/porousSimpleFoam.C index 164e86092..259de8644 100644 --- a/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/porousSimpleFoam.C +++ b/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/porousSimpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/incompressible/simpleFoam/simpleFoam.C b/applications/solvers/incompressible/simpleFoam/simpleFoam.C index fe0430fc4..d70af1578 100644 --- a/applications/solvers/incompressible/simpleFoam/simpleFoam.C +++ b/applications/solvers/incompressible/simpleFoam/simpleFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/simpleReactingParcelFoam.C b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/simpleReactingParcelFoam.C index d9b02c472..99b863c4a 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/simpleReactingParcelFoam.C +++ b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/simpleReactingParcelFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (simple.loop()) + while (simple.loop(runTime)) { Info<< "Time = " << runTime.timeName() << nl << endl; diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index c92022046..f2e55dab1 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -410,11 +410,29 @@ $(general)/pressureControl/pressureControl.C $(general)/levelSet/levelSet.C solutionControl = $(general)/solutionControl -$(solutionControl)/solutionControl/solutionControl.C +$(solutionControl)/solutionControl/solutionControl/solutionControl.C +$(solutionControl)/solutionControl/singleRegionSolutionControl/singleRegionSolutionControl.C +$(solutionControl)/solutionControl/multiRegionSolutionControl/multiRegionSolutionControl.C +$(solutionControl)/solutionControl/nonOrthogonalSolutionControl/nonOrthogonalSolutionControl.C +$(solutionControl)/solutionControl/fluidSolutionControl/fluidSolutionControl.C $(solutionControl)/simpleControl/simpleControl.C -$(solutionControl)/pimpleControl/pimpleControl.C $(solutionControl)/pisoControl/pisoControl.C +solidControl = $(solutionControl)/solidControl +$(solidControl)/solidNoLoopControl/solidNoLoopControl.C + +pimpleControl = $(solutionControl)/pimpleControl +$(pimpleControl)/pimpleControl/pimpleControl.C +$(pimpleControl)/pimpleNoLoopControl/pimpleNoLoopControl.C +$(pimpleControl)/pimpleLoop/pimpleLoop.C +$(pimpleControl)/pimpleMultiRegionControl/pimpleMultiRegionControl.C + +convergenceControl = $(solutionControl)/convergenceControl +$(convergenceControl)/convergenceControl/convergenceControl.C +$(convergenceControl)/singleRegionConvergenceControl/singleRegionConvergenceControl.C +$(convergenceControl)/correctorConvergenceControl/correctorConvergenceControl.C +$(convergenceControl)/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.C + porosity = $(general)/porosityModel $(porosity)/porosityModel/porosityModel.C $(porosity)/porosityModel/porosityModelNew.C diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.C new file mode 100644 index 000000000..0fbf50280 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.C @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "convergenceControl.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(convergenceControl, 0); +} + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +void Foam::convergenceControl::getInitialResiduals +( + const fvMesh& mesh, + const word& fieldName, + const label solvei, + ITstream& data, + scalar& r0, + scalar& r +) +{ + getInitialTypeResiduals(mesh, fieldName, solvei, data, r0, r); + getInitialTypeResiduals(mesh, fieldName, solvei, data, r0, r); + getInitialTypeResiduals + ( + mesh, + fieldName, + solvei, + data, + r0, + r + ); + getInitialTypeResiduals(mesh, fieldName, solvei, data, r0, r); + getInitialTypeResiduals(mesh, fieldName, solvei, data, r0, r); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::convergenceControl::convergenceControl(const solutionControl& control) +: + control_(control) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::convergenceControl::~convergenceControl() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::convergenceControl::converged() +{ + if + ( + control_.time().timeIndex() != control_.time().startTimeIndex() + && criteriaSatisfied() + ) + { + Info<< nl << control_.algorithmName() << " solution converged in " + << control_.time().timeName() << " iterations" << nl << endl; + + return true; + } + + return false; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.H b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.H new file mode 100644 index 000000000..3f821c893 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControl.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::convergenceControl + +Description + Convergence control class. Provides methods to check the convergence of the + time loop against an absolute residual tolerance. + +SourceFiles + convergenceControl.C + convergenceControlTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef convergenceControl_H +#define convergenceControl_H + +#include "fvMesh.H" +#include "solutionControl.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class convergenceControl Declaration +\*---------------------------------------------------------------------------*/ + +class convergenceControl +{ +public: + + //- Classes + + //- Residual data structure + struct residualData + { + wordRe name; + scalar absTol; + }; + + + // Static Functions + + //- Get the initial residuals for the first and the i-th solves in this + // time-step + static void getInitialResiduals + ( + const fvMesh& mesh, + const word& fieldName, + const label solvei, + ITstream& data, + scalar& r0, + scalar& r + ); + + + // Static Template Functions + + //- Return the index of the named field in residual control data, or -1 + // if not present + template + static label residualControlIndex + ( + const word& fieldName, + const List& residualControl, + const bool useRegEx=true + ); + + //- Get the initial residuals for the first and the i-th solves in this + // time-step + template + static void getInitialTypeResiduals + ( + const fvMesh& mesh, + const word& fieldName, + const label solvei, + ITstream& data, + scalar& r0, + scalar& r + ); + + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + convergenceControl(const convergenceControl&); + + //- Disallow default bitwise assignment + void operator=(const convergenceControl&); + + +protected: + + // Protected data + + //- Reference to the solution control + const solutionControl& control_; + + +public: + + // Static Data Members + + //- Run-time type information + TypeName("convergenceControl"); + + + // Constructors + + //- Construct from a solution control + convergenceControl(const solutionControl& control); + + + //- Destructor + virtual ~convergenceControl(); + + + // Member Functions + + // Evolution + + //- Return true if residual controls are present + virtual bool hasResidualControls() const = 0; + + //- Return true if all convergence checks are satisfied + virtual bool criteriaSatisfied() const = 0; + + //- Flag to indicate whether convergance has been reached + bool converged(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "convergenceControlTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControlTemplates.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControlTemplates.C new file mode 100644 index 000000000..ef84ee873 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/convergenceControl/convergenceControlTemplates.C @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::label Foam::convergenceControl::residualControlIndex +( + const word& fieldName, + const List& residualControl, + const bool useRegEx +) +{ + forAll(residualControl, i) + { + if (useRegEx && residualControl[i].name.match(fieldName)) + { + return i; + } + else if (residualControl[i].name == fieldName) + { + return i; + } + } + + return -1; +} + + +template +void Foam::convergenceControl::getInitialTypeResiduals +( + const fvMesh& mesh, + const word& fieldName, + const label solvei, + ITstream& data, + scalar& r0, + scalar& r +) +{ + typedef GeometricField fieldType; + + if (mesh.foundObject(fieldName)) + { + const List> sp(data); + r0 = cmptMax(sp[0].initialResidual()); + r = cmptMax(sp[solvei].initialResidual()); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.C new file mode 100644 index 000000000..e4011a94c --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.C @@ -0,0 +1,74 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "correctorConvergenceControl.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(correctorConvergenceControl, 0); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::correctorConvergenceControl::getNSolves +( + const fvMesh& mesh, + const word& fieldName, + ITstream& data, + label& n +) +{ + getNTypeSolves(mesh, fieldName, data, n); + getNTypeSolves(mesh, fieldName, data, n); + getNTypeSolves(mesh, fieldName, data, n); + getNTypeSolves(mesh, fieldName, data, n); + getNTypeSolves(mesh, fieldName, data, n); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::correctorConvergenceControl::correctorConvergenceControl +( + const solutionControl& control, + const word& loopName +) +: + control_(control), + loopName_(loopName) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::correctorConvergenceControl::~correctorConvergenceControl() +{} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.H b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.H new file mode 100644 index 000000000..ee72da664 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControl.H @@ -0,0 +1,170 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::correctorConvergenceControl + +Description + Corrector convergence control class. Provides methods to check the + convergence of an inner iteration loop (e.g., PIMPLE) against both absolute + and relative residual tolerances. + +SourceFiles + correctorConvergenceControl.C + correctorConvergenceControlTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef correctorConvergenceControl_H +#define correctorConvergenceControl_H + +#include "fvMesh.H" +#include "solutionControl.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class correctorConvergenceControl Declaration +\*---------------------------------------------------------------------------*/ + +class correctorConvergenceControl +{ +public: + + //- Residual correction data structure + struct corrResidualData + { + wordRe name; + scalar absTol; + scalar relTol; + label solveIndex; + }; + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + correctorConvergenceControl(const correctorConvergenceControl&); + + //- Disallow default bitwise assignment + void operator=(const correctorConvergenceControl&); + + +protected: + + // Protected data + + //- Reference to the solution control + const solutionControl& control_; + + //- Name of the corrector loop + const word loopName_; + + + // Protected Member Functions + + //- Get the number of solves that have happened for this variable in + // this time-step + static void getNSolves + ( + const fvMesh& mesh, + const word& fieldName, + ITstream& data, + label& n + ); + + + // Protected Static Template Functions + + //- Get the number of solves that have happened for this variable in + // this time-step + template + static void getNTypeSolves + ( + const fvMesh& mesh, + const word& fieldName, + ITstream& data, + label& n + ); + + +public: + + // Static Data Members + + //- Run-time type information + TypeName("correctorConvergenceControl"); + + + // Constructors + + //- Construct from a solution control and the loop name + correctorConvergenceControl + ( + const solutionControl& control, + const word& loopName + ); + + + //- Destructor + virtual ~correctorConvergenceControl(); + + + // Member Functions + + // Evolution + + //- Return true if corrector residual controls are present + virtual bool hasCorrResidualControls() const = 0; + + //- Return true if all correction convergence checks are satisfied + virtual bool corrCriteriaSatisfied() const = 0; + + //- Reset the solve index in the correction residual control data + virtual void resetCorrSolveIndex() = 0; + + //- Update the solve index in the correction residual control data + virtual void updateCorrSolveIndex() = 0; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "correctorConvergenceControlTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControlTemplates.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControlTemplates.C new file mode 100644 index 000000000..adf94384c --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/correctorConvergenceControl/correctorConvergenceControlTemplates.C @@ -0,0 +1,47 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void Foam::correctorConvergenceControl::getNTypeSolves +( + const fvMesh& mesh, + const word& fieldName, + ITstream& data, + label& n +) +{ + typedef GeometricField fieldType; + + if (mesh.foundObject(fieldName)) + { + const List> sp(data); + n = sp.size(); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.C new file mode 100644 index 000000000..086d42565 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.C @@ -0,0 +1,193 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "singleRegionConvergenceControl.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(singleRegionConvergenceControl, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::singleRegionConvergenceControl::singleRegionConvergenceControl +( + const singleRegionSolutionControl& control +) +: + convergenceControl(control), + mesh_(control.mesh()), + residualControl_() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::singleRegionConvergenceControl::~singleRegionConvergenceControl() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::singleRegionConvergenceControl::readResidualControls() +{ + const dictionary residualDict + ( + control_.dict().subOrEmptyDict("residualControl") + ); + + DynamicList data(residualControl_); + + forAllConstIter(dictionary, residualDict, iter) + { + const word& fName = iter().keyword(); + + if (iter().isDict()) + { + FatalErrorInFunction + << "Solution convergence criteria specified in " + << control_.algorithmName() << '.' << residualDict.dictName() + << " must be given as single values. Corrector loop " + << "convergence criteria, if appropriate, are specified as " + << "dictionaries in " << control_.algorithmName() + << ".ResidualControl." << exit(FatalError); + } + + const label fieldi = + residualControlIndex(fName, residualControl_, false); + if (fieldi == -1) + { + residualData rd; + rd.name = fName.c_str(); + rd.absTol = readScalar(residualDict.lookup(fName)); + data.append(rd); + } + else + { + residualData& rd = data[fieldi]; + rd.absTol = readScalar(residualDict.lookup(fName)); + } + } + + residualControl_.transfer(data); + + if (control_.debug > 1) + { + forAll(residualControl_, i) + { + const residualData& rd = residualControl_[i]; + Info<< residualDict.dictName() << '[' << i << "]:" << nl + << " name : " << rd.name << nl + << " absTol : " << rd.absTol << endl; + } + } + + return true; +} + + +void Foam::singleRegionConvergenceControl::printResidualControls() const +{ + Info<< nl; + + Info<< control_.algorithmName() << ": " + << (residualControl_.empty() ? "No c" : "C") + << "onvergence criteria found" << nl; + + forAll(residualControl_, i) + { + Info<< control_.algorithmSpace() << " " << residualControl_[i].name + << ": tolerance " << residualControl_[i].absTol << nl; + } + + Info << endl; +} + + +bool Foam::singleRegionConvergenceControl::hasResidualControls() const +{ + return !residualControl_.empty(); +} + + +bool Foam::singleRegionConvergenceControl::criteriaSatisfied() const +{ + if (!hasResidualControls()) + { + return false; + } + + bool achieved = true; + bool checked = false; // ensure that some checks were actually performed + + if (control_.debug) + { + Info<< control_.algorithmName() << ": Residuals" << endl; + } + + const dictionary& solverDict = mesh_.solverPerformanceDict(); + forAllConstIter(dictionary, solverDict, iter) + { + const word& variableName = iter().keyword(); + const label fieldi = + residualControlIndex(variableName, residualControl_); + if (fieldi != -1) + { + scalar residual; + getInitialResiduals + ( + mesh_, + variableName, + 0, + iter().stream(), + residual, + residual + ); + + checked = true; + + bool absCheck = residual < residualControl_[fieldi].absTol; + + achieved = achieved && absCheck; + + if (control_.debug) + { + Info<< control_.algorithmSpace() << " " << variableName + << ": tolerance " << residual << " (" + << residualControl_[fieldi].absTol << ")" + << (absCheck ? " CONVERGED" : "") << endl; + } + } + } + + return checked && achieved; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.H b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.H new file mode 100644 index 000000000..33a25a6a4 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionConvergenceControl/singleRegionConvergenceControl.H @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::singleRegionConvergenceControl + +Description + Single-region-specific derivation of the convergence control class + +SourceFiles + singleRegionConvergenceControl.C + +\*---------------------------------------------------------------------------*/ + +#ifndef singleRegionConvergenceControl_H +#define singleRegionConvergenceControl_H + +#include "convergenceControl.H" +#include "singleRegionSolutionControl.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class singleRegionConvergenceControl Declaration +\*---------------------------------------------------------------------------*/ + +class singleRegionConvergenceControl +: + public convergenceControl +{ +protected: + + // Protected data + + //- Reference to the mesh + const fvMesh& mesh_; + + //- List of residual data per field + List residualControl_; + + +public: + + // Static Data Members + + //- Run-time type information + TypeName("singleRegionConvergenceControl"); + + + // Constructors + + //- Construct from a solution control + singleRegionConvergenceControl + ( + const singleRegionSolutionControl& control + ); + + + //- Destructor + virtual ~singleRegionConvergenceControl(); + + + // Member Functions + + // IO + + //- Read residual controls + bool readResidualControls(); + + //- Print the residual controls + void printResidualControls() const; + + + // Evolution + + //- Return true if residual controls are present + virtual bool hasResidualControls() const; + + //- Return true if all convergence checks are satisfied + virtual bool criteriaSatisfied() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.C b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.C new file mode 100644 index 000000000..b045eaf17 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.C @@ -0,0 +1,272 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "singleRegionCorrectorConvergenceControl.H" +#include "convergenceControl.H" +#include "volFields.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(singleRegionCorrectorConvergenceControl, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::singleRegionCorrectorConvergenceControl:: +singleRegionCorrectorConvergenceControl +( + const singleRegionSolutionControl& control, + const word& loopName +) +: + correctorConvergenceControl(control, loopName), + mesh_(control.mesh()), + corrResidualControl_() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::singleRegionCorrectorConvergenceControl:: +~singleRegionCorrectorConvergenceControl() +{} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::singleRegionCorrectorConvergenceControl::readCorrResidualControls() +{ + const dictionary residualDict + ( + control_.dict().subOrEmptyDict(loopName_ + "ResidualControl") + ); + + DynamicList data(corrResidualControl_); + + forAllConstIter(dictionary, residualDict, iter) + { + const word& fName = iter().keyword(); + if (!iter().isDict()) + { + FatalErrorInFunction + << "Corrector loop convergence criteria specified in " + << control_.algorithmName() << '.' << residualDict.dictName() + << " must be given as dictionaries containing \"tolerance\" " + << "and \"relTol\" entries. Solution convergence criteria are " + << "specified as single numbers in " << control_.algorithmName() + << ".residualControl." << exit(FatalError); + } + + const label fieldi = + convergenceControl::residualControlIndex + ( + fName, + corrResidualControl_, + false + ); + if (fieldi == -1) + { + corrResidualData rd; + const dictionary& fieldDict(iter().dict()); + rd.name = fName.c_str(); + rd.absTol = readScalar(fieldDict.lookup("tolerance")); + rd.relTol = readScalar(fieldDict.lookup("relTol")); + rd.solveIndex = 0; + data.append(rd); + } + else + { + corrResidualData& rd = data[fieldi]; + const dictionary& fieldDict(iter().dict()); + rd.absTol = readScalar(fieldDict.lookup("tolerance")); + rd.relTol = readScalar(fieldDict.lookup("relTol")); + } + } + + corrResidualControl_.transfer(data); + + if (control_.debug > 1) + { + forAll(corrResidualControl_, i) + { + const corrResidualData& rd = corrResidualControl_[i]; + Info<< residualDict.dictName() << '[' << i << "]:" << nl + << " name : " << rd.name << nl + << " absTol : " << rd.absTol << nl + << " relTol : " << rd.relTol << endl; + } + } + + return true; +} + + +void Foam::singleRegionCorrectorConvergenceControl::printCorrResidualControls +( + const label n +) const +{ + Info<< nl; + + Info<< control_.algorithmName() << ": " + << (corrResidualControl_.empty() ? "No c" : "C") + << "orrector convergence criteria found" << nl; + + forAll(corrResidualControl_, i) + { + Info<< control_.algorithmSpace() << " " + << corrResidualControl_[i].name << ": tolerance " + << corrResidualControl_[i].absTol << ", relTol " + << corrResidualControl_[i].relTol << nl; + } + + Info<< control_.algorithmSpace() << " Calclations will do " << n + << " corrections" << (corrResidualControl_.empty() ? "" : + " if the convergence criteria are not met") << nl << endl; +} + + +bool Foam::singleRegionCorrectorConvergenceControl:: +hasCorrResidualControls() const +{ + return !corrResidualControl_.empty(); +} + + +bool Foam::singleRegionCorrectorConvergenceControl:: +corrCriteriaSatisfied() const +{ + if (!hasCorrResidualControls()) + { + return false; + } + + bool achieved = true; + bool checked = false; // ensure that some checks were actually performed + + if (control_.debug) + { + Info<< control_.algorithmName() << ": Correction residuals" << endl; + } + + const dictionary& solverDict = mesh_.solverPerformanceDict(); + forAllConstIter(dictionary, solverDict, iter) + { + const word& variableName = iter().keyword(); + const label fieldi = + convergenceControl::residualControlIndex + ( + variableName, + corrResidualControl_ + ); + if (fieldi != -1) + { + scalar firstResidual, residual; + convergenceControl::getInitialResiduals + ( + mesh_, + variableName, + corrResidualControl_[fieldi].solveIndex, + iter().stream(), + firstResidual, + residual + ); + const scalar relativeResidual = + residual/(firstResidual + ROOTVSMALL); + + const bool absCheck = + residual < corrResidualControl_[fieldi].absTol; + const bool relCheck = + relativeResidual < corrResidualControl_[fieldi].relTol; + + checked = true; + achieved = achieved && (absCheck || relCheck); + + if (control_.debug) + { + Info<< control_.algorithmSpace() << " " << variableName + << ": tolerance " << residual << " (" + << corrResidualControl_[fieldi].absTol << ")" + << ", relTol " << relativeResidual << " (" + << corrResidualControl_[fieldi].relTol << ")" + << (absCheck || relCheck ? " CONVERGED" : "") << endl; + } + } + } + + return checked && achieved; +} + + +void Foam::singleRegionCorrectorConvergenceControl::resetCorrSolveIndex() +{ + const dictionary& solverDict = mesh_.solverPerformanceDict(); + forAllConstIter(dictionary, solverDict, iter) + { + const word& variableName = iter().keyword(); + const label fieldi = + convergenceControl::residualControlIndex + ( + variableName, + corrResidualControl_ + ); + if (fieldi != -1) + { + corrResidualControl_[fieldi].solveIndex = 0; + } + } +} + + +void Foam::singleRegionCorrectorConvergenceControl::updateCorrSolveIndex() +{ + const dictionary& solverDict = mesh_.solverPerformanceDict(); + forAllConstIter(dictionary, solverDict, iter) + { + const word& variableName = iter().keyword(); + const label fieldi = + convergenceControl::residualControlIndex + ( + variableName, + corrResidualControl_ + ); + if (fieldi != -1) + { + getNSolves + ( + mesh_, + variableName, + iter().stream(), + corrResidualControl_[fieldi].solveIndex + ); + } + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.H b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.H new file mode 100644 index 000000000..5d33418e3 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/convergenceControl/singleRegionCorrectorConvergenceControl/singleRegionCorrectorConvergenceControl.H @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::singleRegionCorrectorConvergenceControl + +Description + Single-region-specific derivation of the corrector convergence control + class + +SourceFiles + singleRegionCorrectorConvergenceControl.C + +\*---------------------------------------------------------------------------*/ + +#ifndef singleRegionCorrectorConvergenceControl_H +#define singleRegionCorrectorConvergenceControl_H + +#include "correctorConvergenceControl.H" +#include "singleRegionSolutionControl.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class singleRegionCorrectorConvergenceControl Declaration +\*---------------------------------------------------------------------------*/ + +class singleRegionCorrectorConvergenceControl +: + public correctorConvergenceControl +{ +protected: + + // Protected data + + //- Reference to the mesh + const fvMesh& mesh_; + + //- List of residual data per field + List corrResidualControl_; + + +public: + + // Static Data Members + + //- Run-time type information + TypeName("singleRegionCorrectorConvergenceControl"); + + + // Constructors + + //- Construct from a solution control and the loop name + singleRegionCorrectorConvergenceControl + ( + const singleRegionSolutionControl& control, + const word& loopName + ); + + + //- Destructor + virtual ~singleRegionCorrectorConvergenceControl(); + + + // Member Functions + + // IO + + //- Read residual controls + bool readCorrResidualControls(); + + //- Print the residual controls + void printCorrResidualControls(const label n) const; + + + // Evolution + + //- Return true if corrector residual controls are present + virtual bool hasCorrResidualControls() const; + + //- Return true if all correction convergence checks are satisfied + virtual bool corrCriteriaSatisfied() const; + + //- Reset the solve index in the correction residual control data + virtual void resetCorrSolveIndex(); + + //- Update the solve index in the correction residual control data + virtual void updateCorrSolveIndex(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C deleted file mode 100644 index 2209761a5..000000000 --- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C +++ /dev/null @@ -1,248 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2018 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 . - -\*---------------------------------------------------------------------------*/ - -#include "pimpleControl.H" -#include "Switch.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - defineTypeNameAndDebug(pimpleControl, 0); -} - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -bool Foam::pimpleControl::read() -{ - bool ok = solutionControl::read(); - - if (ok) - { - const dictionary& pimpleDict = dict(); - - solveFlow_ = pimpleDict.lookupOrDefault("solveFlow", true); - nCorrPIMPLE_ = pimpleDict.lookupOrDefault