mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Re-located solution/simple/pimple control
This commit is contained in:
@ -0,0 +1,162 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ 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);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::pimpleControl::read()
|
||||
{
|
||||
solutionControl::read(false);
|
||||
|
||||
// Read solution controls
|
||||
const dictionary& pimpleDict = dict();
|
||||
nOuterCorr_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
||||
nCorr_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
|
||||
}
|
||||
|
||||
|
||||
bool Foam::pimpleControl::criteriaSatisfied()
|
||||
{
|
||||
if ((corr_ == 0) || residualControl_.empty() || finalIter())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool firstIter = corr_ == 1;
|
||||
|
||||
bool achieved = true;
|
||||
const dictionary& solverDict = mesh_.solverPerformanceDict();
|
||||
|
||||
forAllConstIter(dictionary, solverDict, iter)
|
||||
{
|
||||
const word& variableName = iter().keyword();
|
||||
label fieldI = applyToField(variableName);
|
||||
if (fieldI != -1)
|
||||
{
|
||||
const List<lduMatrix::solverPerformance> sp(iter().stream());
|
||||
const scalar residual = sp.last().initialResidual();
|
||||
|
||||
if (firstIter)
|
||||
{
|
||||
residualControl_[fieldI].initialResidual =
|
||||
sp.first().initialResidual();
|
||||
}
|
||||
|
||||
bool absCheck = residual < residualControl_[fieldI].absTol;
|
||||
|
||||
bool relCheck = false;
|
||||
|
||||
scalar relative = 0.0;
|
||||
if (!firstIter)
|
||||
{
|
||||
scalar iniRes =
|
||||
residualControl_[fieldI].initialResidual
|
||||
+ ROOTVSMALL;
|
||||
|
||||
relative = residual/iniRes;
|
||||
|
||||
relCheck = relative < residualControl_[fieldI].relTol;
|
||||
}
|
||||
|
||||
achieved = achieved && (absCheck || relCheck);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< algorithmName_ << "loop statistics:" << endl;
|
||||
|
||||
Info<< " " << variableName << " iter " << corr_
|
||||
<< ": ini res = "
|
||||
<< residualControl_[fieldI].initialResidual
|
||||
<< ", abs tol = " << residual
|
||||
<< " (" << residualControl_[fieldI].absTol << ")"
|
||||
<< ", rel tol = " << relative
|
||||
<< " (" << residualControl_[fieldI].relTol << ")"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return achieved;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pimpleControl::pimpleControl(fvMesh& mesh)
|
||||
:
|
||||
solutionControl(mesh, "PIMPLE"),
|
||||
nOuterCorr_(0),
|
||||
nCorr_(0),
|
||||
corr_(0)
|
||||
{
|
||||
read();
|
||||
|
||||
if (nOuterCorr_ > 1)
|
||||
{
|
||||
Info<< nl;
|
||||
if (!residualControl_.empty())
|
||||
{
|
||||
Info<< algorithmName_ << ": max iterations = " << nOuterCorr_
|
||||
<< endl;
|
||||
forAll(residualControl_, i)
|
||||
{
|
||||
Info<< " field " << residualControl_[i].name << token::TAB
|
||||
<< ": relTol " << residualControl_[i].relTol
|
||||
<< ", absTol " << residualControl_[i].absTol
|
||||
<< nl;
|
||||
}
|
||||
Info<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< algorithmName_ << ": no residual control data found. " << nl
|
||||
<< "Calculations will employ " << nOuterCorr_
|
||||
<< " corrector loops" << nl << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< nl << algorithmName_ << ": Operating solver in PISO mode" << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::pimpleControl::~pimpleControl()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,152 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ 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.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef pimpleControl_H
|
||||
#define pimpleControl_H
|
||||
|
||||
#include "solutionControl.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pimpleControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pimpleControl
|
||||
:
|
||||
public solutionControl
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
// Solution controls
|
||||
|
||||
//- Maximum number of PIMPLE correctors
|
||||
label nOuterCorr_;
|
||||
|
||||
//- Maximum number of PISO correctors
|
||||
label nCorr_;
|
||||
|
||||
//- Current PIMPLE corrector
|
||||
label corr_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read constrols from fvSolution dictionary
|
||||
virtual void read();
|
||||
|
||||
//- Return true if all convergence checks are satified
|
||||
virtual bool criteriaSatisfied();
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
pimpleControl(const pimpleControl&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const pimpleControl&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// Static Data Members
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("pimpleControl");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from mesh
|
||||
pimpleControl(fvMesh& mesh);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~pimpleControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Current corrector index
|
||||
inline label corr() const;
|
||||
|
||||
//- Maximum number of PIMPLE correctors
|
||||
inline label nOuterCorr() const;
|
||||
|
||||
//- Maximum number of PISO correctors
|
||||
inline label nCorr() const;
|
||||
|
||||
|
||||
// Solution control
|
||||
|
||||
//- Loop start
|
||||
inline bool start();
|
||||
|
||||
//- Loop loop
|
||||
inline bool loop();
|
||||
|
||||
//- Helper function to identify final PIMPLE (outer) iteration
|
||||
inline bool finalIter() const;
|
||||
|
||||
//- Helper function to identify final inner iteration
|
||||
inline bool finalInnerIter
|
||||
(
|
||||
const label corr,
|
||||
const label nonOrth
|
||||
) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
void operator++(int);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "pimpleControlI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,124 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ 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::corr() const
|
||||
{
|
||||
return corr_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::nOuterCorr() const
|
||||
{
|
||||
return nOuterCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::nCorr() const
|
||||
{
|
||||
return nCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::start()
|
||||
{
|
||||
corr_ = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::loop()
|
||||
{
|
||||
read();
|
||||
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< algorithmName_ << ": converged in " << corr_ << " iterations"
|
||||
<< endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (finalIter())
|
||||
{
|
||||
mesh_.data::add("finalIteration", true);
|
||||
}
|
||||
|
||||
if (corr_ < nOuterCorr_)
|
||||
{
|
||||
if (nOuterCorr_ != 1)
|
||||
{
|
||||
Info<< algorithmName_ << ": iteration " << corr_ + 1 << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((!residualControl_.empty()) && (nOuterCorr_ != 1))
|
||||
{
|
||||
Info<< algorithmName_ << ": not converged within "
|
||||
<< nOuterCorr_ << " iterations" << endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalIter() const
|
||||
{
|
||||
return corr_ == nOuterCorr_-1;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalInnerIter
|
||||
(
|
||||
const label corr,
|
||||
const label nonOrth
|
||||
) const
|
||||
{
|
||||
return
|
||||
corr_ == nOuterCorr_-1
|
||||
&& corr == nCorr_-1
|
||||
&& nonOrth == nNonOrthCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::pimpleControl::operator++(int)
|
||||
{
|
||||
if (finalIter())
|
||||
{
|
||||
mesh_.data::remove("finalIteration");
|
||||
}
|
||||
|
||||
corr_++;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user