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 ...
    }
This commit is contained in:
Will Bainbridge
2018-01-12 12:10:01 +00:00
parent 08d5fce8ca
commit 4c8122783a
63 changed files with 4348 additions and 1324 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -50,7 +50,7 @@ int main(int argc, char *argv[])
Info<< "\nCalculating temperature distribution\n" << endl; Info<< "\nCalculating temperature distribution\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -51,7 +51,7 @@ int main(int argc, char *argv[])
#include "CourantNo.H" #include "CourantNo.H"
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -71,7 +71,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -57,7 +57,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -60,7 +60,7 @@ int main(int argc, char *argv[])
{ {
simpleControl simple(mesh); simpleControl simple(mesh);
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
Info<< "\nStarting time loop\n" << endl; Info<< "\nStarting time loop\n" << endl;
while (simple.loop()) while (simple.loop(runTime))
{ {
Info<< "Time = " << runTime.timeName() << nl << endl; Info<< "Time = " << runTime.timeName() << nl << endl;

View File

@ -410,11 +410,29 @@ $(general)/pressureControl/pressureControl.C
$(general)/levelSet/levelSet.C $(general)/levelSet/levelSet.C
solutionControl = $(general)/solutionControl 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)/simpleControl/simpleControl.C
$(solutionControl)/pimpleControl/pimpleControl.C
$(solutionControl)/pisoControl/pisoControl.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 = $(general)/porosityModel
$(porosity)/porosityModel/porosityModel.C $(porosity)/porosityModel/porosityModel.C
$(porosity)/porosityModel/porosityModelNew.C $(porosity)/porosityModel/porosityModelNew.C

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<scalar>(mesh, fieldName, solvei, data, r0, r);
getInitialTypeResiduals<vector>(mesh, fieldName, solvei, data, r0, r);
getInitialTypeResiduals<sphericalTensor>
(
mesh,
fieldName,
solvei,
data,
r0,
r
);
getInitialTypeResiduals<symmTensor>(mesh, fieldName, solvei, data, r0, r);
getInitialTypeResiduals<tensor>(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;
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<class ResidualData>
static label residualControlIndex
(
const word& fieldName,
const List<ResidualData>& residualControl,
const bool useRegEx=true
);
//- Get the initial residuals for the first and the i-th solves in this
// time-step
template<class Type>
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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class ResidualData>
Foam::label Foam::convergenceControl::residualControlIndex
(
const word& fieldName,
const List<ResidualData>& 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<class Type>
void Foam::convergenceControl::getInitialTypeResiduals
(
const fvMesh& mesh,
const word& fieldName,
const label solvei,
ITstream& data,
scalar& r0,
scalar& r
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (mesh.foundObject<fieldType>(fieldName))
{
const List<SolverPerformance<Type>> sp(data);
r0 = cmptMax(sp[0].initialResidual());
r = cmptMax(sp[solvei].initialResidual());
}
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<scalar>(mesh, fieldName, data, n);
getNTypeSolves<vector>(mesh, fieldName, data, n);
getNTypeSolves<sphericalTensor>(mesh, fieldName, data, n);
getNTypeSolves<symmTensor>(mesh, fieldName, data, n);
getNTypeSolves<tensor>(mesh, fieldName, data, n);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::correctorConvergenceControl::correctorConvergenceControl
(
const solutionControl& control,
const word& loopName
)
:
control_(control),
loopName_(loopName)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::correctorConvergenceControl::~correctorConvergenceControl()
{}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<class Type>
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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::correctorConvergenceControl::getNTypeSolves
(
const fvMesh& mesh,
const word& fieldName,
ITstream& data,
label& n
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (mesh.foundObject<fieldType>(fieldName))
{
const List<SolverPerformance<Type>> sp(data);
n = sp.size();
}
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<residualData> 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()
<< ".<loopName>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;
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<residualData> 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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<corrResidualData> 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
);
}
}
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
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<corrResidualData> 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
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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<Switch>("solveFlow", true);
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
SIMPLErho_ = pimpleDict.lookupOrDefault<Switch>("SIMPLErho", false);
turbOnFinalIterOnly_ =
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
}
return ok;
}
bool Foam::pimpleControl::criteriaSatisfied()
{
// no checks on first iteration - nothing has been calculated yet
if ((corr_ == 1) || residualControl_.empty() || finalIter())
{
return false;
}
bool storeIni = this->storeInitialResiduals();
bool achieved = true;
bool checked = false; // safety that some checks were indeed performed
const dictionary& solverDict = mesh_.solverPerformanceDict();
forAllConstIter(dictionary, solverDict, iter)
{
const word& variableName = iter().keyword();
const label fieldi = applyToField(variableName);
if (fieldi != -1)
{
scalar residual = 0;
const scalar firstResidual =
maxResidual(variableName, iter().stream(), residual);
checked = true;
if (storeIni)
{
residualControl_[fieldi].initialResidual = firstResidual;
}
const bool absCheck = residual < residualControl_[fieldi].absTol;
bool relCheck = false;
scalar relative = 0.0;
if (!storeIni)
{
const scalar iniRes =
residualControl_[fieldi].initialResidual
+ rootVSmall;
relative = residual/iniRes;
relCheck = relative < residualControl_[fieldi].relTol;
}
achieved = achieved && (absCheck || relCheck);
if (debug)
{
Info<< algorithmName_ << " loop:" << endl;
Info<< " " << variableName
<< " PIMPLE iter " << corr_
<< ": ini res = "
<< residualControl_[fieldi].initialResidual
<< ", abs tol = " << residual
<< " (" << residualControl_[fieldi].absTol << ")"
<< ", rel tol = " << relative
<< " (" << residualControl_[fieldi].relTol << ")"
<< endl;
}
}
}
return checked && achieved;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleControl::pimpleControl(fvMesh& mesh, const word& dictName)
:
solutionControl(mesh, dictName),
solveFlow_(true),
nCorrPIMPLE_(0),
nCorrPISO_(0),
corrPISO_(0),
SIMPLErho_(false),
turbOnFinalIterOnly_(true),
converged_(false)
{
read();
if (nCorrPIMPLE_ > 1)
{
Info<< nl;
if (residualControl_.empty())
{
Info<< algorithmName_ << ": no residual control data found. "
<< "Calculations will employ " << nCorrPIMPLE_
<< " corrector loops" << nl << endl;
}
else
{
Info<< algorithmName_ << ": max iterations = " << nCorrPIMPLE_
<< endl;
forAll(residualControl_, i)
{
Info<< " field " << residualControl_[i].name << token::TAB
<< ": relTol " << residualControl_[i].relTol
<< ", tolerance " << residualControl_[i].absTol
<< nl;
}
Info<< endl;
}
}
else
{
Info<< nl << algorithmName_ << ": Operating solver in PISO mode" << nl
<< endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
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 (converged_ || criteriaSatisfied())
{
if (converged_)
{
Info<< algorithmName_ << ": converged in " << corr_ - 1
<< " iterations" << endl;
mesh_.data::remove("finalIteration");
corr_ = 0;
converged_ = false;
completed = true;
}
else
{
Info<< algorithmName_ << ": iteration " << corr_ << endl;
storePrevIterFields();
mesh_.data::add("finalIteration", true);
converged_ = true;
}
}
else
{
if (finalIter())
{
mesh_.data::add("finalIteration", true);
}
if (corr_ <= nCorrPIMPLE_)
{
Info<< algorithmName_ << ": iteration " << corr_ << endl;
storePrevIterFields();
completed = false;
}
}
return !completed;
}
// ************************************************************************* //

View File

@ -1,180 +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 <http://www.gnu.org/licenses/>.
Class
Foam::pimpleControl
Description
PIMPLE control class to supply convergence information/checks for
the PIMPLE loop.
May also be used to for PISO-based algorithms as PISO controls are a
sub-set of PIMPLE controls.
\*---------------------------------------------------------------------------*/
#ifndef pimpleControl_H
#define pimpleControl_H
#include "solutionControl.H"
//- Declare that pimpleControl will be used
#define PIMPLE_CONTROL
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleControl Declaration
\*---------------------------------------------------------------------------*/
class pimpleControl
:
public solutionControl
{
// Private member functions
//- Disallow default bitwise copy construct
pimpleControl(const pimpleControl&);
//- Disallow default bitwise assignment
void operator=(const pimpleControl&);
protected:
// Protected data
// Solution controls
//- Flag to indicate whether to solve for the flow
bool solveFlow_;
//- Maximum number of PIMPLE correctors
label nCorrPIMPLE_;
//- Maximum number of PISO correctors
label nCorrPISO_;
//- Current PISO corrector
label corrPISO_;
//- Flag to indicate whether to update density in SIMPLE
// rather than PISO mode
bool SIMPLErho_;
//- Flag to indicate whether to only solve turbulence on final iter
bool turbOnFinalIterOnly_;
//- Converged flag
bool converged_;
// Protected Member Functions
//- Read controls from fvSolution dictionary
virtual bool read();
//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied();
public:
// Static Data Members
//- Run-time type information
TypeName("pimpleControl");
// Constructors
//- Construct from mesh and the name of control sub-dictionary
pimpleControl(fvMesh& mesh, const word& dictName="PIMPLE");
//- Destructor
virtual ~pimpleControl();
// Member Functions
// Access
//- Maximum number of PIMPLE correctors
inline label nCorrPIMPLE() const;
//- Maximum number of PISO correctors
inline label nCorrPISO() const;
//- Current PISO corrector index
inline label corrPISO() const;
//- Flag to indicate whether to update density in SIMPLE
// rather than PISO mode
inline bool SIMPLErho() const;
// Solution control
//- PIMPLE loop
virtual bool loop();
//- Pressure corrector loop control
inline bool correct();
//- Return true to store the intial residuals
inline bool storeInitialResiduals() const;
//- Return true for first PIMPLE (outer) iteration
inline bool firstIter() const;
//- Return true fore final PIMPLE (outer) iteration
inline bool finalIter() const;
//- Return true for final inner iteration
inline bool finalInnerIter() const;
//- Return true to solve for flow
inline bool solveFlow() const;
//- Return true to solve for turbulence
inline bool turbCorr() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,136 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pimpleControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pimpleControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleControl::pimpleControl(fvMesh& mesh, const word& algorithmName)
:
pimpleNoLoopControl(mesh, algorithmName),
pimpleLoop(static_cast<solutionControl&>(*this))
{
read();
printResidualControls();
if (nCorrPIMPLE_ > 1)
{
printCorrResidualControls(nCorrPIMPLE_);
}
else
{
Info<< nl << algorithmName << ": Operating solver in PISO mode" << nl
<< endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pimpleControl::~pimpleControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::pimpleControl::read()
{
if (!pimpleNoLoopControl::read() || !pimpleLoop::read())
{
return false;
}
nCorrPIMPLE_ = dict().lookupOrDefault<label>("nOuterCorrectors", 1);
return true;
}
bool Foam::pimpleControl::loop()
{
read();
if (!pimpleLoop::loop(*this))
{
mesh().data::remove("finalIteration");
return false;
}
storePrevIterFields();
if (finalIter())
{
mesh().data::add("finalIteration", true);
}
return true;
}
bool Foam::pimpleControl::run(Time& time)
{
read();
if (converged())
{
time.writeAndEnd();
}
else
{
storePrevIterFields();
}
return time.run();
}
bool Foam::pimpleControl::loop(Time& time)
{
read();
if (converged())
{
time.writeAndEnd();
}
else
{
storePrevIterFields();
}
return time.loop();
}
// ************************************************************************* //

View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::pimpleControl
Description
PIMPLE control class. Provides time-loop control methods which exit the
simulation once convergence criteria have been reached. Also provides
PIMPLE-loop control methods which exit the iteration once corrector
convergence criteria have been met. Example usage:
\verbatim
pimpleControl pimple(mesh);
while (pimple.run(runTime))
{
// pre-time-increment operations ...
runTime ++;
Info<< "Time = " << runTime.timeName() << nl << endl;
while (pimple.loop())
{
// solve ...
}
// post-solve operations ...
}
\endverbatim
SourceFiles
pimpleControlI.H
pimpleControl.C
\*---------------------------------------------------------------------------*/
#ifndef pimpleControl_H
#define pimpleControl_H
#include "pimpleNoLoopControl.H"
#include "pimpleLoop.H"
#include "singleRegionConvergenceControl.H"
#include "singleRegionCorrectorConvergenceControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleControl Declaration
\*---------------------------------------------------------------------------*/
class pimpleControl
:
public pimpleNoLoopControl,
public pimpleLoop
{
public:
// Static data members
//- Run-time type information
TypeName("pimpleControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
pimpleControl(fvMesh& mesh, const word& algorithmName="PIMPLE");
//- Destructor
virtual ~pimpleControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
// Access
//- Flag to indicate whether to solve the turbulence
inline bool turbCorr() const;
// Evolution
//- PIMPLE loop
bool loop();
//- Time run loop
bool run(Time& time);
//- Time loop loop
bool loop(Time& time);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline bool Foam::pimpleControl::turbCorr() const
{
return !turbOnFinalIterOnly() || finalIter();
}
// ************************************************************************* //

View File

@ -1,112 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::pimpleControl::nCorrPIMPLE() const
{
return nCorrPIMPLE_;
}
inline Foam::label Foam::pimpleControl::nCorrPISO() const
{
return nCorrPISO_;
}
inline Foam::label Foam::pimpleControl::corrPISO() const
{
return corrPISO_;
}
inline bool Foam::pimpleControl::SIMPLErho() const
{
return SIMPLErho_;
}
inline bool Foam::pimpleControl::correct()
{
corrPISO_++;
if (debug)
{
Info<< algorithmName_ << " correct: corrPISO = " << corrPISO_ << endl;
}
if (corrPISO_ <= nCorrPISO_)
{
return true;
}
else
{
corrPISO_ = 0;
return false;
}
}
inline bool Foam::pimpleControl::storeInitialResiduals() const
{
// Start from second PIMPLE iteration
return (corr_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
}
inline bool Foam::pimpleControl::firstIter() const
{
return corr_ == 1;
}
inline bool Foam::pimpleControl::finalIter() const
{
return converged_ || (corr_ == nCorrPIMPLE_);
}
inline bool Foam::pimpleControl::finalInnerIter() const
{
return
corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nNonOrthCorr_ + 1;
}
inline bool Foam::pimpleControl::solveFlow() const
{
return solveFlow_;
}
inline bool Foam::pimpleControl::turbCorr() const
{
return !turbOnFinalIterOnly_ || finalIter();
}
// ************************************************************************* //

View File

@ -0,0 +1,136 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pimpleLoop.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pimpleLoop, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::pimpleLoop::read()
{
nCorrPIMPLE_ =
control_.dict().lookupOrDefault<label>("nOuterCorrectors", 1);
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleLoop::pimpleLoop(const solutionControl& control)
:
control_(control),
nCorrPIMPLE_(-1),
corrPIMPLE_(0),
converged_(false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pimpleLoop::~pimpleLoop()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::pimpleLoop::loop(correctorConvergenceControl& convergence)
{
read();
++ corrPIMPLE_;
// Handle quit conditions first
{
// If all corrections have been completed then end the correction loop
if (corrPIMPLE_ > nCorrPIMPLE_)
{
if (convergence.hasCorrResidualControls() && nCorrPIMPLE_ > 1)
{
Info<< control_.algorithmName() << ": Not converged within "
<< nCorrPIMPLE_ << " iterations" << endl;
}
corrPIMPLE_ = 0;
return false;
}
// If converged on the last iteration then end the correction loop
if (converged_)
{
Info<< control_.algorithmName() << ": Converged in "
<< corrPIMPLE_ - 1 << " iterations" << endl;
corrPIMPLE_ = 0;
converged_ = false;
return false;
}
}
// If we reached here, we are doing another loop
{
// If convergence has been reached then set the flag so that the loop
// exits next time around
if (!firstPIMPLEIter() && convergence.corrCriteriaSatisfied())
{
Info<< control_.algorithmName() << ": Converged " << nl
<< control_.algorithmSpace() << " Doing final iteration"
<< endl;
converged_ = true;
}
// Set up the next iteration by storing the index of the solution to
// check the convergence of
if (firstPIMPLEIter())
{
convergence.resetCorrSolveIndex();
}
else
{
convergence.updateCorrSolveIndex();
}
// Print the number of the iteration about to take place
if (nCorrPIMPLE_ > 1)
{
Info<< control_.algorithmName() << ": Iteration " << corrPIMPLE_
<< endl;
}
return true;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,134 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::pimpleLoop
Description
PIMPLE loop class. Implements the logic which controls the PIMPLE loop
generically for a given corrector convergence control. Can therefore be
used be either single- or multi-region control classes.
SourceFiles
pimpleLoopI.H
pimpleLoop.C
\*---------------------------------------------------------------------------*/
#ifndef pimpleLoop_H
#define pimpleLoop_H
#include "correctorConvergenceControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleLoop Declaration
\*---------------------------------------------------------------------------*/
class pimpleLoop
{
protected:
// Protected data
//- Reference to the solution control
const solutionControl& control_;
//- Maximum number of PIMPLE correctors
label nCorrPIMPLE_;
//- Current PIMPLE corrector
label corrPIMPLE_;
//- Flag to indicate convergence of the PIMPLE loop
bool converged_;
// Protected Member Functions
//- Read controls
virtual bool read();
public:
// Static data members
//- Run-time type information
TypeName("pimpleLoop");
// Constructors
//- Construct from a solution control
pimpleLoop(const solutionControl& control);
//- Destructor
virtual ~pimpleLoop();
// Member Functions
// Access
//- Maximum number of PIMPLE correctors
inline label nCorrPIMPLE() const;
//- Flag to indicate the first PIMPLE iteration
inline bool firstPIMPLEIter() const;
//- Flag to indicate the last PIMPLE iteration
inline bool finalPIMPLEIter() const;
//- Flag to indicate the first iteration
inline bool firstIter() const;
//- Flag to indicate the last iteration
inline bool finalIter() const;
// Evolution
//- PIMPLE loop
bool loop(correctorConvergenceControl& convergence);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleLoopI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::label Foam::pimpleLoop::nCorrPIMPLE() const
{
return nCorrPIMPLE_;
}
inline bool Foam::pimpleLoop::firstPIMPLEIter() const
{
return corrPIMPLE_ == 1;
}
inline bool Foam::pimpleLoop::finalPIMPLEIter() const
{
return corrPIMPLE_ >= nCorrPIMPLE_;
}
inline bool Foam::pimpleLoop::firstIter() const
{
return firstPIMPLEIter();
}
inline bool Foam::pimpleLoop::finalIter() const
{
return converged_ || finalPIMPLEIter();
}
// ************************************************************************* //

View File

@ -0,0 +1,349 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pimpleMultiRegionControl.H"
#include "pimpleControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pimpleMultiRegionControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
const Foam::Time& Foam::pimpleMultiRegionControl::time
(
const PtrList<fvMesh>& pimpleMeshes,
const PtrList<fvMesh>& solidMeshes
)
{
if (pimpleMeshes.empty() && solidMeshes.empty())
{
FatalErrorInFunction
<< "There needs to be at least one region"
<< exit(FatalError);
}
if (!pimpleMeshes.empty())
{
return pimpleMeshes[0].time();
}
return solidMeshes[0].time();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleMultiRegionControl::pimpleMultiRegionControl
(
PtrList<fvMesh>& pimpleMeshes,
PtrList<fvMesh>& solidMeshes,
const word& algorithmName
)
:
multiRegionSolutionControl(time(pimpleMeshes, solidMeshes), algorithmName),
pimpleLoop(static_cast<solutionControl&>(*this)),
convergenceControl(static_cast<solutionControl&>(*this)),
correctorConvergenceControl
(
static_cast<solutionControl&>(*this),
"outerCorrector"
),
pimpleControls_(),
solidControls_()
{
forAll(pimpleMeshes, i)
{
pimpleControls_.append
(
new pimpleNoLoopControl(pimpleMeshes[i], algorithmName)
);
}
forAll(solidMeshes, i)
{
solidControls_.append
(
new solidNoLoopControl(solidMeshes[i], algorithmName)
);
}
read();
forAll(pimpleMeshes, i)
{
Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
pimpleControls_[i].printResidualControls();
if (nCorrPIMPLE_ > 1)
{
Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
pimpleControls_[i].printCorrResidualControls(nCorrPIMPLE_);
}
}
forAll(solidMeshes, i)
{
Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
solidControls_[i].printResidualControls();
if (nCorrPIMPLE_ > 1)
{
Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
solidControls_[i].printCorrResidualControls(nCorrPIMPLE_);
}
}
if (nCorrPIMPLE_ < 1)
{
Info<< nl << algorithmName << ": Operating solver in PISO mode" << nl
<< endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pimpleMultiRegionControl::~pimpleMultiRegionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::pimpleMultiRegionControl::read()
{
forAll(pimpleControls_, i)
{
if (!pimpleControls_[i].read())
{
return false;
}
}
forAll(solidControls_, i)
{
if (!solidControls_[i].read())
{
return false;
}
}
const dictionary& solutionDict = dict();
nCorrPIMPLE_ = solutionDict.lookupOrDefault<label>("nOuterCorrectors", 1);
return true;
}
bool Foam::pimpleMultiRegionControl::hasResidualControls() const
{
bool result = true;
forAll(pimpleControls_, i)
{
result = result && pimpleControls_[i].hasResidualControls();
}
forAll(solidControls_, i)
{
result = result && solidControls_[i].hasResidualControls();
}
return result;
}
bool Foam::pimpleMultiRegionControl::hasCorrResidualControls() const
{
bool result = true;
forAll(pimpleControls_, i)
{
result = result && pimpleControls_[i].hasCorrResidualControls();
}
forAll(solidControls_, i)
{
result = result && solidControls_[i].hasCorrResidualControls();
}
return result;
}
bool Foam::pimpleMultiRegionControl::criteriaSatisfied() const
{
bool result = true;
forAll(pimpleControls_, i)
{
result = pimpleControls_[i].criteriaSatisfied() && result;
}
forAll(solidControls_, i)
{
result = solidControls_[i].criteriaSatisfied() && result;
}
return result;
}
bool Foam::pimpleMultiRegionControl::corrCriteriaSatisfied() const
{
bool result = true;
forAll(pimpleControls_, i)
{
result = pimpleControls_[i].corrCriteriaSatisfied() && result;
}
forAll(solidControls_, i)
{
result = solidControls_[i].corrCriteriaSatisfied() && result;
}
return result;
}
void Foam::pimpleMultiRegionControl::resetCorrSolveIndex()
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].resetCorrSolveIndex();
}
forAll(solidControls_, i)
{
solidControls_[i].resetCorrSolveIndex();
}
}
void Foam::pimpleMultiRegionControl::updateCorrSolveIndex()
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].updateCorrSolveIndex();
}
forAll(solidControls_, i)
{
solidControls_[i].updateCorrSolveIndex();
}
}
bool Foam::pimpleMultiRegionControl::loop()
{
read();
if (!pimpleLoop::loop(*this))
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].mesh().data::remove("finalIteration");
}
forAll(solidControls_, i)
{
solidControls_[i].mesh().data::remove("finalIteration");
}
return false;
}
forAll(pimpleControls_, i)
{
pimpleControls_[i].storePrevIterFields();
}
forAll(solidControls_, i)
{
solidControls_[i].storePrevIterFields();
}
if (finalIter())
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].mesh().data::add("finalIteration", true);
}
forAll(solidControls_, i)
{
solidControls_[i].mesh().data::add("finalIteration", true);
}
}
return true;
}
bool Foam::pimpleMultiRegionControl::run(Time& time)
{
read();
if (converged())
{
time.writeAndEnd();
}
else
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].storePrevIterFields();
}
forAll(solidControls_, i)
{
solidControls_[i].storePrevIterFields();
}
}
return time.run();
}
bool Foam::pimpleMultiRegionControl::loop(Time& time)
{
read();
if (converged())
{
time.writeAndEnd();
}
else
{
forAll(pimpleControls_, i)
{
pimpleControls_[i].storePrevIterFields();
}
forAll(solidControls_, i)
{
solidControls_[i].storePrevIterFields();
}
}
return time.loop();
}
// ************************************************************************* //

View File

@ -0,0 +1,169 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::pimpleMultiRegionControl
Description
PIMPLE multi-region control class. As Foam::pimpleControl, but for a multi-
region simulation comprising PIMPLE and solid regions. More region types
could be added.
SourceFiles
pimpleMultiRegionControlI.H
pimpleMultiRegionControl.C
\*---------------------------------------------------------------------------*/
#ifndef pimpleMultiRegionControl_H
#define pimpleMultiRegionControl_H
#include "multiRegionSolutionControl.H"
#include "pimpleLoop.H"
#include "convergenceControl.H"
#include "correctorConvergenceControl.H"
#include "pimpleNoLoopControl.H"
#include "solidNoLoopControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleMultiRegionControl Declaration
\*---------------------------------------------------------------------------*/
class pimpleMultiRegionControl
:
public multiRegionSolutionControl,
public pimpleLoop,
public convergenceControl,
public correctorConvergenceControl
{
protected:
// Protected data
//- The per-region PIMPLE controls
PtrList<pimpleNoLoopControl> pimpleControls_;
//- The per-region solid controls
PtrList<solidNoLoopControl> solidControls_;
// Protected Static Functions
//- Get the time from the region meshes
static const Time& time
(
const PtrList<fvMesh>& pimpleMeshes,
const PtrList<fvMesh>& solidMeshes
);
public:
// Static data members
//- Run-time type information
TypeName("pimpleMultiRegionControl");
// Constructors
//- Construct from meshes and the algorithm name
pimpleMultiRegionControl
(
PtrList<fvMesh>& pimpleMeshes,
PtrList<fvMesh>& solidMeshes,
const word& algorithmName="PIMPLE"
);
//- Destructor
virtual ~pimpleMultiRegionControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
// Access
//- Access the i-th pimple control
inline pimpleNoLoopControl& pimple(const label i);
//- Access the i-th solid control
inline solidNoLoopControl& solid(const label i);
//- Flag to indicate whether to solve the turbulence
inline bool pimpleTurbCorr(const label i) const;
// Evolution
//- Return true if residual controls are present
virtual bool hasResidualControls() const;
//- Return true if corrector residual controls are present
virtual bool hasCorrResidualControls() const;
//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() 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();
//- PIMPLE loop
bool loop();
//- Time run loop
bool run(Time& time);
//- Time loop loop
bool loop(Time& time);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleMultiRegionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::pimpleNoLoopControl&
Foam::pimpleMultiRegionControl::pimple(const label i)
{
return pimpleControls_[i];
}
inline Foam::solidNoLoopControl&
Foam::pimpleMultiRegionControl::solid(const label i)
{
return solidControls_[i];
}
inline bool Foam::pimpleMultiRegionControl::pimpleTurbCorr(const label i) const
{
return !pimpleControls_[i].turbOnFinalIterOnly() || finalIter();
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pimpleNoLoopControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pimpleNoLoopControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleNoLoopControl::pimpleNoLoopControl
(
fvMesh& mesh,
const word& algorithmName
)
:
pisoControl(mesh, algorithmName),
singleRegionConvergenceControl
(
static_cast<singleRegionSolutionControl&>(*this)
),
singleRegionCorrectorConvergenceControl
(
static_cast<singleRegionSolutionControl&>(*this),
"outerCorrector"
),
SIMPLErho_(false),
turbOnFinalIterOnly_(true)
{
read();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pimpleNoLoopControl::~pimpleNoLoopControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::pimpleNoLoopControl::read()
{
if
(
!pisoControl::read()
|| !readResidualControls()
|| !readCorrResidualControls()
)
{
return false;
}
SIMPLErho_ = dict().lookupOrDefault<bool>("SIMPLErho", false);
turbOnFinalIterOnly_ =
dict().lookupOrDefault<bool>("turbOnFinalIterOnly", true);
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::pimpleNoLoopControl
Description
PIMPLE no-loop control class. Implements various option flags, but leaves
loop controls to the derivation or owner. Can be derived into a "full"
PIMPLE control or can be owned by a multi-region PIMPLE class.
SourceFiles
pimpleNoLoopControlI.H
pimpleNoLoopControl.C
\*---------------------------------------------------------------------------*/
#ifndef pimpleNoLoopControl_H
#define pimpleNoLoopControl_H
#include "pisoControl.H"
#include "singleRegionConvergenceControl.H"
#include "singleRegionCorrectorConvergenceControl.H"
#undef PISO_CONTROL
#define PIMPLE_CONTROL
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleNoLoopControl Declaration
\*---------------------------------------------------------------------------*/
class pimpleNoLoopControl
:
public pisoControl,
public singleRegionConvergenceControl,
public singleRegionCorrectorConvergenceControl
{
protected:
// Protected data
//- Flag to indicate whether to update the density in SIMPLE mode rather
// than PISO mode
bool SIMPLErho_;
//- Flag to control whether turblence is solved just on the final PIMPLE
// iteration, or on every PIMPLE iteration
bool turbOnFinalIterOnly_;
public:
// Static data members
//- Run-time type information
TypeName("pimpleNoLoopControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
pimpleNoLoopControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~pimpleNoLoopControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
// Access
//- Flag to indicate whether to update the density in SIMPLE mode
inline bool SIMPLErho() const;
//- Flag to indicate whether to solve the turbulence on the final
// PIMPLE iteration only
inline bool turbOnFinalIterOnly() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleNoLoopControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline bool Foam::pimpleNoLoopControl::SIMPLErho() const
{
return SIMPLErho_;
}
inline bool Foam::pimpleNoLoopControl::turbOnFinalIterOnly() const
{
return turbOnFinalIterOnly_;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,11 +35,13 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pisoControl::pisoControl(fvMesh& mesh, const word& dictName) Foam::pisoControl::pisoControl(fvMesh& mesh, const word& algorithmName)
: :
pimpleControl(mesh, dictName) fluidSolutionControl(mesh, algorithmName),
nCorrPISO_(-1),
corrPISO_(0)
{ {
// mesh_.data::add("finalIteration", true); read();
} }
@ -49,4 +51,49 @@ Foam::pisoControl::~pisoControl()
{} {}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::pisoControl::read()
{
if (!fluidSolutionControl::read())
{
return false;
}
const dictionary& solutionDict = dict();
nCorrPISO_ = solutionDict.lookupOrDefault<label>("nCorrectors", 1);
return true;
}
bool Foam::pisoControl::correct()
{
read();
if (finalPISOIter())
{
corrPISO_ = 0;
return false;
}
++ corrPISO_;
return true;
}
bool Foam::pisoControl::run(Time& time)
{
return time.run();
}
bool Foam::pisoControl::loop(Time& time)
{
return time.loop();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,18 +25,21 @@ Class
Foam::pisoControl Foam::pisoControl
Description Description
Specialization of the pimpleControl class for PISO control. PISO control class. Provides time-loop and PISO-loop control methods. No
convergence checking is done.
SourceFiles
pisoControlI.H
pisoControl.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef pisoControl_H #ifndef pisoControl_H
#define pisoControl_H #define pisoControl_H
#include "pimpleControl.H" #include "fluidSolutionControl.H"
//- Declare that pisoControl will be used
#define PISO_CONTROL #define PISO_CONTROL
#undef PIMPLE_CONTROL
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,20 +52,22 @@ namespace Foam
class pisoControl class pisoControl
: :
public pimpleControl public fluidSolutionControl
{ {
// Private member functions protected:
//- Disallow default bitwise copy construct // Protected data
pisoControl(const pisoControl&);
//- Disallow default bitwise assignment //- Maximum number of PISO correctors
void operator=(const pisoControl&); label nCorrPISO_;
//- Current PISO corrector
label corrPISO_;
public: public:
// Static Data Members // Static data members
//- Run-time type information //- Run-time type information
TypeName("pisoControl"); TypeName("pisoControl");
@ -70,8 +75,8 @@ public:
// Constructors // Constructors
//- Construct from mesh and the name of control sub-dictionary //- Construct from a mesh and the name of the algorithm
pisoControl(fvMesh& mesh, const word& dictName="PISO"); pisoControl(fvMesh& mesh, const word& algorithmName="PISO");
//- Destructor //- Destructor
@ -80,23 +85,50 @@ public:
// Member Functions // Member Functions
// Solution control // IO
//- Return true if in the final inner (PISO) iteration //- Read controls
virtual bool read();
// Access
//- Maximum number of PISO correctors
inline label nCorrPISO() const;
//- Flag to indicate the first PISO iteration
inline bool firstPISOIter() const;
//- Flag to indicate the last PISO iteration
inline bool finalPISOIter() const;
//- Flag to indicate the last inner iteration (last PISO and last
// non-orthogonal)
inline bool finalInnerIter() const; inline bool finalInnerIter() const;
// Evolution
//- PISO loop
bool correct();
//- Time run loop
bool run(Time& time);
//- Time loop loop
bool loop(Time& time);
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pisoControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pisoControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,13 +23,29 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::label Foam::pisoControl::nCorrPISO() const
{
return nCorrPISO_;
}
inline bool Foam::pisoControl::firstPISOIter() const
{
return corrPISO_ == 1;
}
inline bool Foam::pisoControl::finalPISOIter() const
{
return corrPISO_ >= nCorrPISO_;
}
inline bool Foam::pisoControl::finalInnerIter() const inline bool Foam::pisoControl::finalInnerIter() const
{ {
return return finalNonOrthogonalIter() && finalPISOIter();
corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nNonOrthCorr_ + 1;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "simpleControl.H" #include "simpleControl.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -34,130 +33,18 @@ namespace Foam
} }
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::simpleControl::readResidualControl()
{
const dictionary& solutionDict = this->dict();
// Read residual information
const dictionary residualDict
(
solutionDict.subOrEmptyDict("residualControl")
);
DynamicList<fieldData> data(residualControl_);
forAllConstIter(dictionary, residualDict, iter)
{
const word& fName = iter().keyword();
const label fieldi = applyToField(fName, false);
if (fieldi == -1)
{
fieldData fd;
fd.name = fName.c_str();
fd.absTol = readScalar(residualDict.lookup(fName));
fd.relTol = -1;
fd.initialResidual = -1;
data.append(fd);
}
else
{
fieldData& fd = data[fieldi];
fd.absTol = readScalar(residualDict.lookup(fName));
}
}
residualControl_.transfer(data);
if (debug)
{
forAll(residualControl_, i)
{
const fieldData& fd = residualControl_[i];
Info<< "residualControl[" << i << "]:" << nl
<< " name : " << fd.name << nl
<< " absTol : " << fd.absTol << endl;
}
}
return true;
}
bool Foam::simpleControl::criteriaSatisfied()
{
if (residualControl_.empty())
{
return false;
}
bool achieved = true;
bool checked = false; // safety that some checks were indeed performed
const dictionary& solverDict = mesh_.solverPerformanceDict();
forAllConstIter(dictionary, solverDict, iter)
{
const word& variableName = iter().keyword();
const label fieldi = applyToField(variableName);
if (fieldi != -1)
{
scalar lastResidual = 0;
const scalar residual =
maxResidual(variableName, iter().stream(), lastResidual);
checked = true;
bool absCheck = residual < residualControl_[fieldi].absTol;
achieved = achieved && absCheck;
if (debug)
{
Info<< algorithmName_ << " solution statistics:" << endl;
Info<< " " << variableName << ": tolerance = " << residual
<< " (" << residualControl_[fieldi].absTol << ")"
<< endl;
}
}
}
return checked && achieved;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::simpleControl::simpleControl(fvMesh& mesh) Foam::simpleControl::simpleControl(fvMesh& mesh, const word& algorithmName)
: :
solutionControl(mesh, "SIMPLE"), fluidSolutionControl(mesh, algorithmName),
initialised_(false) singleRegionConvergenceControl
(
static_cast<singleRegionSolutionControl&>(*this)
)
{ {
read(); read();
printResidualControls();
Info<< nl;
if (residualControl_.empty())
{
Info<< algorithmName_ << ": no convergence criteria found. "
<< "Calculations will run for "
<< mesh_.time().endTime().value() - mesh_.time().startTime().value()
<< " steps." << nl << endl;
}
else
{
Info<< algorithmName_ << ": convergence criteria" << nl;
forAll(residualControl_, i)
{
Info<< " field " << residualControl_[i].name << token::TAB
<< " tolerance " << residualControl_[i].absTol
<< nl;
}
Info<< endl;
}
} }
@ -167,36 +54,44 @@ Foam::simpleControl::~simpleControl()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::simpleControl::loop() bool Foam::simpleControl::read()
{
return fluidSolutionControl::read() && readResidualControls();
}
bool Foam::simpleControl::run(Time& time)
{ {
read(); read();
Time& time = const_cast<Time&>(mesh_.time()); if (converged())
if (initialised_)
{ {
if (criteriaSatisfied())
{
Info<< nl << algorithmName_ << " solution converged in "
<< time.timeName() << " iterations" << nl << endl;
// Set to finalise calculation
time.writeAndEnd(); time.writeAndEnd();
} }
else else
{ {
storePrevIterFields(); storePrevIterFields();
} }
return time.run();
}
bool Foam::simpleControl::loop(Time& time)
{
read();
if (converged())
{
time.writeAndEnd();
} }
else else
{ {
initialised_ = true;
storePrevIterFields(); storePrevIterFields();
} }
return time.loop(); return time.loop();
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,17 +25,31 @@ Class
Foam::simpleControl Foam::simpleControl
Description Description
SIMPLE control class to supply convergence information/checks for SIMPLE control class. Provides time-loop control methods which exit the
the SIMPLE loop. simulation once convergence criteria have been reached. Example usage:
\verbatim
simpleControl simple(mesh);
while (simple.loop(runTime))
{
Info<< "Time = " << runTime.timeName() << nl << endl;
// solve ...
}
\endverbatim
SourceFiles
simpleControl.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef simpleControl_H #ifndef simpleControl_H
#define simpleControl_H #define simpleControl_H
#include "solutionControl.H" #include "fluidSolutionControl.H"
#include "singleRegionConvergenceControl.H"
//- Declare that pimpleControl will be used
#define SIMPLE_CONTROL #define SIMPLE_CONTROL
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,40 +63,12 @@ namespace Foam
class simpleControl class simpleControl
: :
public solutionControl public fluidSolutionControl,
public singleRegionConvergenceControl
{ {
protected:
// Protected Data
//- Initialised flag
bool initialised_;
// Protected Member Functions
//- Read absolute residual controls from fvSolution dictionary
virtual bool readResidualControl();
//- Return true if all convergence checks are satisfied
bool criteriaSatisfied();
private:
// Private member functions
//- Disallow default bitwise copy construct
simpleControl(const simpleControl&);
//- Disallow default bitwise assignment
void operator=(const simpleControl&);
public: public:
// Static Data Members // Static data members
//- Run-time type information //- Run-time type information
TypeName("simpleControl"); TypeName("simpleControl");
@ -90,8 +76,8 @@ public:
// Constructors // Constructors
//- Construct from mesh //- Construct from a mesh and the name of the algorithm
simpleControl(fvMesh& mesh); simpleControl(fvMesh& mesh, const word& algorithmName="SIMPLE");
//- Destructor //- Destructor
@ -100,10 +86,18 @@ public:
// Member Functions // Member Functions
// Solution control // IO
//- Loop loop //- Read controls
virtual bool loop(); virtual bool read();
// Evolution
//- Time run loop
bool run(Time& time);
//- Time loop loop
bool loop(Time& time);
}; };

View File

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "solidNoLoopControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(solidNoLoopControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solidNoLoopControl::solidNoLoopControl
(
fvMesh& mesh,
const word& algorithmName
)
:
nonOrthogonalSolutionControl(mesh, algorithmName),
singleRegionConvergenceControl
(
static_cast<singleRegionSolutionControl&>(*this)
),
singleRegionCorrectorConvergenceControl
(
static_cast<singleRegionSolutionControl&>(*this),
"outerCorrector"
)
{
read();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::solidNoLoopControl::~solidNoLoopControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::solidNoLoopControl::read()
{
return
nonOrthogonalSolutionControl::read()
&& readResidualControls()
&& readCorrResidualControls();
}
// ************************************************************************* //

View File

@ -0,0 +1,94 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::solidNoLoopControl
Description
PIMPLE no-loop control class. Implements non-orthogonal and convergence
controls, but leaves loop controls to the derivation or owner. Can be
derived into a "full" solid control or can be owned by a multi-region class.
SourceFiles
solidNoLoopControl.C
\*---------------------------------------------------------------------------*/
#ifndef solidNoLoopControl_H
#define solidNoLoopControl_H
#include "nonOrthogonalSolutionControl.H"
#include "singleRegionConvergenceControl.H"
#include "singleRegionCorrectorConvergenceControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class solidNoLoopControl Declaration
\*---------------------------------------------------------------------------*/
class solidNoLoopControl
:
public nonOrthogonalSolutionControl,
public singleRegionConvergenceControl,
public singleRegionCorrectorConvergenceControl
{
public:
// Static data members
//- Run-time type information
TypeName("solidNoLoopControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
solidNoLoopControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~solidNoLoopControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fluidSolutionControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(fluidSolutionControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fluidSolutionControl::fluidSolutionControl
(
fvMesh& mesh,
const word& algorithmName
)
:
nonOrthogonalSolutionControl(mesh, algorithmName),
solveFlow_(false),
momentumPredictor_(false),
transonic_(false),
consistent_(false)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fluidSolutionControl::~fluidSolutionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::fluidSolutionControl::read()
{
if (!nonOrthogonalSolutionControl::read())
{
return false;
}
const dictionary& solutionDict = dict();
solveFlow_ = solutionDict.lookupOrDefault<bool>("solveFlow", true);
momentumPredictor_ =
solutionDict.lookupOrDefault<bool>("momentumPredictor", true);
transonic_ = solutionDict.lookupOrDefault<bool>("transonic", false);
consistent_ = solutionDict.lookupOrDefault<bool>("consistent", false);
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::fluidSolutionControl
Description
Fluid solution control class. Holds flags specific to the solution of
fluids.
SourceFiles
fluidSolutionControlI.H
fluidSolutionControl.C
\*---------------------------------------------------------------------------*/
#ifndef fluidSolutionControl_H
#define fluidSolutionControl_H
#include "nonOrthogonalSolutionControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class fluidSolutionControl Declaration
\*---------------------------------------------------------------------------*/
class fluidSolutionControl
:
public nonOrthogonalSolutionControl
{
protected:
// Protected data
//- Flag to indicate to solve for the flow
bool solveFlow_;
//- Flag to indicate to solve for momentum
bool momentumPredictor_;
//- Flag to indicate to solve using transonic algorithm
bool transonic_;
//- Flag to indicate to relax pressure using the "consistent" approach
// of SIMPLEC
bool consistent_;
public:
// Static Data Members
//- Run-time type information
TypeName("fluidSolutionControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
fluidSolutionControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~fluidSolutionControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
// Access
//- Flag to indicate to solve for the flow
inline bool solveFlow() const;
//- Flag to indicate to solve for momentum
inline bool momentumPredictor() const;
//- Flag to indicate to solve using transonic algorithm
inline bool transonic() const;
//- Flag to indicate to relax pressure using the "consistent"
// approach of SIMPLEC
inline bool consistent() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fluidSolutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,76 +23,30 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const Foam::dictionary& Foam::solutionControl::dict() const inline bool Foam::fluidSolutionControl::solveFlow() const
{ {
return mesh_.solutionDict().subDict(algorithmName_); return solveFlow_;
} }
inline Foam::label Foam::solutionControl::corr() const inline bool Foam::fluidSolutionControl::momentumPredictor() 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_; return momentumPredictor_;
} }
inline bool Foam::solutionControl::transonic() const inline bool Foam::fluidSolutionControl::transonic() const
{ {
return transonic_; return transonic_;
} }
inline bool Foam::solutionControl::consistent() const inline bool Foam::fluidSolutionControl::consistent() const
{ {
return consistent_; return consistent_;
} }
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;
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "multiRegionSolutionControl.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(multiRegionSolutionControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::multiRegionSolutionControl::multiRegionSolutionControl
(
const Time& time,
const word& algorithmName
)
:
solutionControl(time, time, algorithmName),
solution_(time)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::multiRegionSolutionControl::~multiRegionSolutionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::dictionary& Foam::multiRegionSolutionControl::dict() const
{
return solution_.subDict(algorithmName_);
}
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::multiRegionSolutionControl
Description
Multi-region-specific derivation of the solution control class
SourceFiles
multiRegionSolutionControl.C
\*---------------------------------------------------------------------------*/
#ifndef multiRegionSolutionControl_H
#define multiRegionSolutionControl_H
#include "solutionControl.H"
#include "fvSolution.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class multiRegionSolutionControl Declaration
\*---------------------------------------------------------------------------*/
class multiRegionSolutionControl
:
public solutionControl
{
private:
// Private data
//- Solution instance
const fvSolution solution_;
public:
// Static Data Members
//- Run-time type information
TypeName("multiRegionSolutionControl");
// Constructors
//- Construct from a time and the name of the algorithm
multiRegionSolutionControl(const Time& time, const word& algorithmName);
//- Destructor
virtual ~multiRegionSolutionControl();
// Member Functions
// Access
//- Return the solution dictionary
virtual const dictionary& dict() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,92 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "nonOrthogonalSolutionControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(nonOrthogonalSolutionControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::nonOrthogonalSolutionControl::nonOrthogonalSolutionControl
(
fvMesh& mesh,
const word& algorithmName
)
:
singleRegionSolutionControl(mesh, algorithmName),
nNonOrthCorr_(-1),
nonOrthCorr_(0)
{
read();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::nonOrthogonalSolutionControl::~nonOrthogonalSolutionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::nonOrthogonalSolutionControl::read()
{
if (!singleRegionSolutionControl::read())
{
return false;
}
const dictionary& solutionDict = dict();
nNonOrthCorr_ =
solutionDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
return true;
}
bool Foam::nonOrthogonalSolutionControl::correctNonOrthogonal()
{
read();
if (finalNonOrthogonalIter())
{
nonOrthCorr_ = 0;
return false;
}
++ nonOrthCorr_;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,121 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::nonOrthogonalSolutionControl
Description
Non-orthogonal solution control class. Provides non-orthogonal-loop control
methods.
SourceFiles
nonOrthogonalControlI.H
nonOrthogonalSolutionControl.C
\*---------------------------------------------------------------------------*/
#ifndef nonOrthogonalSolutionControl_H
#define nonOrthogonalSolutionControl_H
#include "singleRegionSolutionControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class nonOrthogonalSolutionControl Declaration
\*---------------------------------------------------------------------------*/
class nonOrthogonalSolutionControl
:
public singleRegionSolutionControl
{
protected:
// Protected data
//- Maximum number of non-orthogonal correctors
label nNonOrthCorr_;
//- Current non-orthogonal corrector index
label nonOrthCorr_;
public:
// Static Data Members
//- Run-time type information
TypeName("nonOrthogonalSolutionControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
nonOrthogonalSolutionControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~nonOrthogonalSolutionControl();
// Member Functions
// IO
//- Read controls
virtual bool read();
// Access
//- Maximum number of non-orthogonal correctors
inline label nNonOrthCorr() const;
//- Flag to indicate the first non-orthogonal iteration
inline bool firstNonOrthogonalIter() const;
//- Flag to indicate the last non-orthogonal iteration
inline bool finalNonOrthogonalIter() const;
// Evolution
//- Non-orthogonal corrector loop
bool correctNonOrthogonal();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "nonOrthogonalSolutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::label Foam::nonOrthogonalSolutionControl::nNonOrthCorr() const
{
return nNonOrthCorr_;
}
inline bool Foam::nonOrthogonalSolutionControl::firstNonOrthogonalIter() const
{
return nonOrthCorr_ == 1;
}
inline bool Foam::nonOrthogonalSolutionControl::finalNonOrthogonalIter() const
{
return nonOrthCorr_ > nNonOrthCorr_;
}
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "singleRegionSolutionControl.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(singleRegionSolutionControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::singleRegionSolutionControl::singleRegionSolutionControl
(
fvMesh& mesh,
const word& algorithmName
)
:
solutionControl(mesh, mesh.time(), algorithmName),
mesh_(mesh)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::singleRegionSolutionControl::~singleRegionSolutionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::dictionary& Foam::singleRegionSolutionControl::dict() const
{
return mesh_.solutionDict().subDict(algorithmName());
}
void Foam::singleRegionSolutionControl::storePrevIterFields()
{
storePrevIterTypeFields<scalar>();
storePrevIterTypeFields<vector>();
storePrevIterTypeFields<sphericalTensor>();
storePrevIterTypeFields<symmTensor>();
storePrevIterTypeFields<tensor>();
}
// ************************************************************************* //

View File

@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::singleRegionSolutionControl
Description
Single-region-specific derivation of the solution control class
SourceFiles
singleRegionSolutionControlI.H
singleRegionSolutionControl.C
singleRegionSolutionControlTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef singleRegionSolutionControl_H
#define singleRegionSolutionControl_H
#include "fvMesh.H"
#include "solutionControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class singleRegionSolutionControl Declaration
\*---------------------------------------------------------------------------*/
class singleRegionSolutionControl
:
public solutionControl
{
protected:
// Protected data
//- Reference to the mesh
fvMesh& mesh_;
// Protected Member Functions
//- Store previous iteration for fields
template<class Type>
void storePrevIterTypeFields() const;
public:
// Static Data Members
//- Run-time type information
TypeName("singleRegionSolutionControl");
// Constructors
//- Construct from a mesh and the name of the algorithm
singleRegionSolutionControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~singleRegionSolutionControl();
// Member Functions
// Access
//- Return the mesh
inline const fvMesh& mesh() const;
//- Return the mesh
inline fvMesh& mesh();
//- Return the solution dictionary
virtual const dictionary& dict() const;
// Evolution
//- Store previous iteration for fields
void storePrevIterFields();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "singleRegionSolutionControlTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "singleRegionSolutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const Foam::fvMesh& Foam::singleRegionSolutionControl::mesh() const
{
return mesh_;
}
inline Foam::fvMesh& Foam::singleRegionSolutionControl::mesh()
{
return mesh_;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,36 +23,26 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "GeometricField.H"
#include "volMesh.H"
#include "fvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::solutionControl::storePrevIter() const void Foam::singleRegionSolutionControl::storePrevIterTypeFields() const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> GeoField; typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
HashTable<GeoField*> HashTable<fieldType*>
flds(mesh_.objectRegistry::lookupClass<GeoField>()); flds(mesh_.objectRegistry::lookupClass<fieldType>());
forAllIter(typename HashTable<GeoField*>, flds, iter) forAllIter(typename HashTable<fieldType*>, flds, iter)
{ {
GeoField& fld = *iter(); fieldType& fld = *iter();
const word& fName = fld.name(); const word& fName = fld.name();
size_t prevIterField = fName.find("PrevIter"); size_t prevIterField = fName.find("PrevIter");
if ((prevIterField == word::npos) && mesh_.relaxField(fName)) if (prevIterField == word::npos && mesh_.relaxField(fName))
{ {
if (debug)
{
Info<< algorithmName_ << ": storing previous iter for "
<< fName << endl;
}
fld.storePrevIter(); fld.storePrevIter();
} }
} }

View File

@ -1,244 +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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "solutionControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(solutionControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::solutionControl::readResidualControl()
{
const dictionary& solutionDict = this->dict();
// Read residual information
const dictionary residualDict
(
solutionDict.subOrEmptyDict("residualControl")
);
DynamicList<fieldData> data(residualControl_);
forAllConstIter(dictionary, residualDict, iter)
{
const word& fName = iter().keyword();
const label fieldi = applyToField(fName, false);
if (fieldi == -1)
{
fieldData fd;
fd.name = fName.c_str();
if (iter().isDict())
{
const dictionary& fieldDict(iter().dict());
fd.absTol = readScalar(fieldDict.lookup("tolerance"));
fd.relTol = readScalar(fieldDict.lookup("relTol"));
fd.initialResidual = 0;
}
else
{
FatalErrorInFunction
<< "Residual data for " << iter().keyword()
<< " must be specified as a dictionary"
<< exit(FatalError);
}
data.append(fd);
}
else
{
fieldData& fd = data[fieldi];
if (iter().isDict())
{
const dictionary& fieldDict(iter().dict());
fd.absTol = readScalar(fieldDict.lookup("tolerance"));
fd.relTol = readScalar(fieldDict.lookup("relTol"));
}
else
{
FatalErrorInFunction
<< "Residual data for " << iter().keyword()
<< " must be specified as a dictionary"
<< exit(FatalError);
}
}
}
residualControl_.transfer(data);
if (debug)
{
forAll(residualControl_, i)
{
const fieldData& fd = residualControl_[i];
Info<< "residualControl[" << i << "]:" << nl
<< " name : " << fd.name << nl
<< " absTol : " << fd.absTol << nl
<< " relTol : " << fd.relTol << endl;
}
}
return true;
}
bool Foam::solutionControl::read()
{
const dictionary& solutionDict = this->dict();
// Read solution controls
nNonOrthCorr_ =
solutionDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
momentumPredictor_ =
solutionDict.lookupOrDefault("momentumPredictor", true);
transonic_ = solutionDict.lookupOrDefault("transonic", false);
consistent_ = solutionDict.lookupOrDefault("consistent", false);
readResidualControl();
return true;
}
bool Foam::solutionControl::writeData(Ostream&) const
{
NotImplemented;
return false;
}
Foam::label Foam::solutionControl::applyToField
(
const word& fieldName,
const bool useRegEx
) const
{
forAll(residualControl_, i)
{
if (useRegEx && residualControl_[i].name.match(fieldName))
{
return i;
}
else if (residualControl_[i].name == fieldName)
{
return i;
}
}
return -1;
}
void Foam::solutionControl::storePrevIterFields() const
{
// storePrevIter<label>();
storePrevIter<scalar>();
storePrevIter<vector>();
storePrevIter<sphericalTensor>();
storePrevIter<symmTensor>();
storePrevIter<tensor>();
}
template<class Type>
void Foam::solutionControl::maxTypeResidual
(
const word& fieldName,
ITstream& data,
scalar& firstRes,
scalar& lastRes
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (mesh_.foundObject<fieldType>(fieldName))
{
const List<SolverPerformance<Type>> sp(data);
firstRes = cmptMax(sp.first().initialResidual());
lastRes = cmptMax(sp.last().initialResidual());
}
}
Foam::scalar Foam::solutionControl::maxResidual
(
const word& fieldName,
ITstream& data,
scalar& lastRes
) const
{
scalar firstRes = 0;
maxTypeResidual<scalar>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor>(fieldName, data, firstRes, lastRes);
maxTypeResidual<symmTensor>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor>(fieldName, data, firstRes, lastRes);
return firstRes;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
:
regIOobject
(
IOobject
(
typeName,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
)
),
mesh_(mesh),
residualControl_(),
algorithmName_(algorithmName),
nNonOrthCorr_(0),
momentumPredictor_(true),
transonic_(false),
consistent_(false),
corr_(0),
corrNonOrtho_(0)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::solutionControl::~solutionControl()
{}
// ************************************************************************* //

View File

@ -1,232 +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 <http://www.gnu.org/licenses/>.
Class
Foam::solutionControl
Description
Base class for solution control classes
\*---------------------------------------------------------------------------*/
#ifndef solutionControl_H
#define solutionControl_H
#include "fvMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class solutionControl Declaration
\*---------------------------------------------------------------------------*/
class solutionControl
:
public regIOobject
{
public:
struct fieldData
{
wordRe name;
scalar absTol;
scalar relTol;
scalar initialResidual;
};
protected:
// Protected data
//- Reference to the mesh database
fvMesh& mesh_;
//- List of residual data per field
List<fieldData> residualControl_;
//- The dictionary name, e.g. SIMPLE, PIMPLE
const word algorithmName_;
// Solution controls
//- Maximum number of non-orthogonal correctors
label nNonOrthCorr_;
//- Flag to indicate to solve for momentum
bool momentumPredictor_;
//- Flag to indicate to solve using transonic algorithm
bool transonic_;
//- Flag to indicate to relax pressure using the
// "consistent" approach of SIMPLEC
bool consistent_;
// Evolution
//- Current corrector loop index
label corr_;
//- Current non-orthogonal corrector loop index
label corrNonOrtho_;
// Protected Member Functions
//- Read residual controls from fvSolution dictionary
virtual bool readResidualControl();
//- Read controls from fvSolution dictionary
virtual bool read();
virtual bool writeData(Ostream&) const;
//- Return index of field in residualControl_ if present
virtual label applyToField
(
const word& fieldName,
const bool useRegEx = true
) const;
//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() = 0;
//- Store previous iteration fields
virtual void storePrevIterFields() const;
//- Store previous iteration field for vol<Type>Fields
template<class Type>
void storePrevIter() const;
template<class Type>
void maxTypeResidual
(
const word& fieldName,
ITstream& data,
scalar& firstRes,
scalar& lastRes
) const;
scalar maxResidual
(
const word& fieldName,
ITstream& data,
scalar& lastRes
) const;
private:
//- Disallow default bitwise copy construct
solutionControl(const solutionControl&);
//- Disallow default bitwise assignment
void operator=(const solutionControl&);
public:
// Static Data Members
//- Run-time type information
TypeName("solutionControl");
// Constructors
//- Construct from mesh
solutionControl(fvMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~solutionControl();
// Member Functions
// Access
//- 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;
//- Flag to indicate to relax pressure using the
// "consistent" approach of SIMPLEC
inline bool consistent() const;
// Evolution
//- Main control loop
virtual bool loop() = 0;
//- Non-orthogonal corrector loop
inline bool correctNonOrthogonal();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "solutionControlTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "solutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,85 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "solutionControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(solutionControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
bool Foam::solutionControl::writeData(Ostream&) const
{
NotImplemented;
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solutionControl::solutionControl
(
const objectRegistry& registry,
const Time& time,
const word& algorithmName
)
:
regIOobject
(
IOobject
(
typeName,
time.timeName(),
registry,
IOobject::NO_READ,
IOobject::NO_WRITE
)
),
time_(time),
algorithmName_(algorithmName),
algorithmSpaceStr_(algorithmName.size(), ' ')
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::solutionControl::~solutionControl()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::solutionControl::read()
{
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,133 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Class
Foam::solutionControl
Description
Solution control class
SourceFiles
solutionControlI.H
solutionControl.C
\*---------------------------------------------------------------------------*/
#ifndef solutionControl_H
#define solutionControl_H
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class solutionControl Declaration
\*---------------------------------------------------------------------------*/
class solutionControl
:
public regIOobject
{
protected:
// Protected data
//- Reference to the time
const Time& time_;
//- Name of the algorithm
const word algorithmName_;
//- Whitespace the same length as the algorithm name
const string algorithmSpaceStr_;
// Protected Member Functions
//- Dummy write for regIOobject
virtual bool writeData(Ostream&) const;
public:
// Static Data Members
//- Run-time type information
TypeName("solutionControl");
// Constructors
//- Construct from the time, a the name of the algorithm and a registry
solutionControl
(
const objectRegistry& registry,
const Time& time,
const word& algorithmName
);
//- Destructor
virtual ~solutionControl();
// Member Functions
// IO
//- Dummy read
virtual bool read();
// Access
//- Return the time
inline const Time& time() const;
//- Return the name of the algorithm
inline const word& algorithmName() const;
//- Return some whitespace the same length as the algorithm name
inline const char* algorithmSpace() const;
//- Return the dictionary
virtual const dictionary& dict() const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "solutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const Foam::Time& Foam::solutionControl::time() const
{
return time_;
}
inline const Foam::word& Foam::solutionControl::algorithmName() const
{
return algorithmName_;
}
inline const char* Foam::solutionControl::algorithmSpace() const
{
return algorithmSpaceStr_.c_str();
}
// ************************************************************************* //

View File

@ -59,7 +59,7 @@ PIMPLE
pMaxFactor 1.5; pMaxFactor 1.5;
pMinFactor 0.9; pMinFactor 0.9;
residualControl outerCorrectorResidualControl
{ {
"(U|k|epsilon)" "(U|k|epsilon)"
{ {