mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Extended and restructured solutionControl class
This commit is contained in:
@ -31,7 +31,7 @@
|
||||
}
|
||||
|
||||
// correct interface on first PIMPLE corrector
|
||||
if (pimple.corrPIMPLE() == 1)
|
||||
if (pimple.corr() == 1)
|
||||
{
|
||||
interface.correct();
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
}
|
||||
|
||||
// correct interface on first PIMPLE corrector
|
||||
if (pimple.corrPIMPLE() == 1)
|
||||
if (pimple.corr() == 1)
|
||||
{
|
||||
interface.correct();
|
||||
}
|
||||
|
||||
@ -44,8 +44,6 @@ void Foam::pimpleControl::read()
|
||||
const dictionary& pimpleDict = dict();
|
||||
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
||||
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
|
||||
nCorrNonOrtho_ =
|
||||
pimpleDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 1);
|
||||
turbOnFinalIterOnly_ =
|
||||
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
|
||||
}
|
||||
@ -54,7 +52,7 @@ void Foam::pimpleControl::read()
|
||||
bool Foam::pimpleControl::criteriaSatisfied()
|
||||
{
|
||||
// no checks on first iteration - nothing has been calculated yet
|
||||
if ((corrPIMPLE_ == 1) || residualControl_.empty() || finalIter())
|
||||
if ((corr_ == 1) || residualControl_.empty() || finalIter())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -104,7 +102,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
|
||||
Info<< algorithmName_ << " loop:" << endl;
|
||||
|
||||
Info<< " " << variableName
|
||||
<< " PIMPLE iter " << corrPIMPLE_
|
||||
<< " PIMPLE iter " << corr_
|
||||
<< ": ini res = "
|
||||
<< residualControl_[fieldI].initialResidual
|
||||
<< ", abs tol = " << residual
|
||||
@ -127,10 +125,7 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh)
|
||||
solutionControl(mesh, "PIMPLE"),
|
||||
nCorrPIMPLE_(0),
|
||||
nCorrPISO_(0),
|
||||
nCorrNonOrtho_(0),
|
||||
corrPIMPLE_(0),
|
||||
corrPISO_(0),
|
||||
corrNonOrtho_(0),
|
||||
turbOnFinalIterOnly_(true)
|
||||
{
|
||||
read();
|
||||
@ -172,4 +167,60 @@ Foam::pimpleControl::~pimpleControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::pimpleControl::loop()
|
||||
{
|
||||
read();
|
||||
|
||||
corr_++;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< algorithmName_ << " loop: corr = " << corr_ << endl;
|
||||
}
|
||||
|
||||
if (corr_ == nCorrPIMPLE_ + 1)
|
||||
{
|
||||
if ((!residualControl_.empty()) && (nCorrPIMPLE_ != 1))
|
||||
{
|
||||
Info<< algorithmName_ << ": not converged within "
|
||||
<< nCorrPIMPLE_ << " iterations" << endl;
|
||||
}
|
||||
|
||||
corr_ = 0;
|
||||
mesh_.data::remove("finalIteration");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool completed = false;
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< algorithmName_ << ": converged in " << corr_ << " iterations"
|
||||
<< endl;
|
||||
completed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (finalIter())
|
||||
{
|
||||
mesh_.data::add("finalIteration", true);
|
||||
}
|
||||
|
||||
if (corr_ <= nCorrPIMPLE_)
|
||||
{
|
||||
if (nCorrPIMPLE_ != 1)
|
||||
{
|
||||
Info<< algorithmName_ << ": iteration " << corr_ << endl;
|
||||
storePrevIterFields();
|
||||
}
|
||||
|
||||
completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
return !completed;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -60,18 +60,9 @@ protected:
|
||||
//- Maximum number of PISO correctors
|
||||
label nCorrPISO_;
|
||||
|
||||
//- Maximum number of non-orthogonal correctors
|
||||
label nCorrNonOrtho_;
|
||||
|
||||
//- Current PIMPLE corrector
|
||||
label corrPIMPLE_;
|
||||
|
||||
//- Current PISO corrector
|
||||
label corrPISO_;
|
||||
|
||||
//- Current non-orthogonal corrector
|
||||
label corrNonOrtho_;
|
||||
|
||||
//- Flag to indicate whether to only solve turbulence on final iter
|
||||
bool turbOnFinalIterOnly_;
|
||||
|
||||
@ -120,39 +111,24 @@ public:
|
||||
//- Maximum number of PISO correctors
|
||||
inline label nCorrPISO() const;
|
||||
|
||||
//- Maximum number of non-orthogonal correctors
|
||||
inline label nCorrNonOrtho() const;
|
||||
|
||||
//- Current PIMPLE corrector index
|
||||
inline label corrPIMPLE() const;
|
||||
|
||||
//- Current PISO corrector index
|
||||
inline label corrPISO() const;
|
||||
|
||||
//- Current non-orthogonal corrector index
|
||||
inline label corrNonOrtho() const;
|
||||
|
||||
|
||||
// Solution control
|
||||
|
||||
//- PIMPLE loop
|
||||
inline bool loop();
|
||||
virtual bool loop();
|
||||
|
||||
//- Corrector loop
|
||||
//- Pressure corrector loop
|
||||
inline bool correct();
|
||||
|
||||
//- Non-orthogonal corrector loop
|
||||
inline bool correctNonOrthogonal();
|
||||
|
||||
//- Helper function to identify when to store the intial residuals
|
||||
inline bool storeInitialResiduals() const;
|
||||
|
||||
//- Helper function to identify final PIMPLE (outer) iteration
|
||||
inline bool finalIter() const;
|
||||
|
||||
//- Helper function to identify final non-orthogonal iteration
|
||||
inline bool finalNonOrthogonalIter() const;
|
||||
|
||||
//- Helper function to identify final inner iteration
|
||||
inline bool finalInnerIter() const;
|
||||
|
||||
|
||||
@ -37,82 +37,12 @@ inline Foam::label Foam::pimpleControl::nCorrPISO() const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::nCorrNonOrtho() const
|
||||
{
|
||||
return nCorrPISO_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::corrPIMPLE() const
|
||||
{
|
||||
return corrPIMPLE_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::corrPISO() const
|
||||
{
|
||||
return corrPISO_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::corrNonOrtho() const
|
||||
{
|
||||
return corrNonOrtho_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::loop()
|
||||
{
|
||||
corrPIMPLE_++;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< algorithmName_ << " loop: corrPIMPLE = " << corrPIMPLE_ << endl;
|
||||
}
|
||||
|
||||
if (corrPIMPLE_ == nCorrPIMPLE_ + 1)
|
||||
{
|
||||
if ((!residualControl_.empty()) && (nCorrPIMPLE_ != 1))
|
||||
{
|
||||
Info<< algorithmName_ << ": not converged within "
|
||||
<< nCorrPIMPLE_ << " iterations" << endl;
|
||||
}
|
||||
|
||||
corrPIMPLE_ = 0;
|
||||
mesh_.data::remove("finalIteration");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool completed = false;
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< algorithmName_ << ": converged in " << corrPIMPLE_
|
||||
<< " iterations" << endl;
|
||||
completed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (finalIter())
|
||||
{
|
||||
mesh_.data::add("finalIteration", true);
|
||||
}
|
||||
|
||||
if (corrPIMPLE_ <= nCorrPIMPLE_)
|
||||
{
|
||||
if (nCorrPIMPLE_ != 1)
|
||||
{
|
||||
Info<< algorithmName_ << ": iteration " << corrPIMPLE_ << endl;
|
||||
storePrevIterFields();
|
||||
}
|
||||
|
||||
completed = false;
|
||||
}
|
||||
}
|
||||
|
||||
return !completed;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::correct()
|
||||
{
|
||||
corrPISO_++;
|
||||
@ -134,53 +64,25 @@ inline bool Foam::pimpleControl::correct()
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::correctNonOrthogonal()
|
||||
{
|
||||
corrNonOrtho_++;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
|
||||
<< corrNonOrtho_ << endl;
|
||||
}
|
||||
|
||||
if (corrNonOrtho_ <= nCorrNonOrtho_ + 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
corrNonOrtho_ = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::storeInitialResiduals() const
|
||||
{
|
||||
// start from second PIMPLE iteration
|
||||
return (corrPIMPLE_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
|
||||
return (corr_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalIter() const
|
||||
{
|
||||
return corrPIMPLE_ == nCorrPIMPLE_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalNonOrthogonalIter() const
|
||||
{
|
||||
return corrNonOrtho_ == nCorrNonOrtho_ + 1;
|
||||
return corr_ == nCorrPIMPLE_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalInnerIter() const
|
||||
{
|
||||
return
|
||||
corrPIMPLE_ == nCorrPIMPLE_
|
||||
&& corrPISO_ == nCorrPISO_
|
||||
&& corrNonOrtho_ == nCorrNonOrtho_ + 1;
|
||||
return
|
||||
corr_ == nCorrPIMPLE_
|
||||
&& corrPISO_ == nCorrPISO_
|
||||
&& corrNonOrtho_ == nNonOrthCorr_ + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -119,4 +119,38 @@ Foam::simpleControl::~simpleControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::simpleControl::loop()
|
||||
{
|
||||
read();
|
||||
|
||||
Time& time = const_cast<Time&>(mesh_.time());
|
||||
|
||||
if (initialised_)
|
||||
{
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< nl << algorithmName_ << " solution converged in "
|
||||
<< time.timeName() << " iterations" << nl << endl;
|
||||
|
||||
// Set to finalise calculation
|
||||
time.writeAndEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
storePrevIterFields();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
initialised_ = true;
|
||||
storePrevIterFields();
|
||||
}
|
||||
|
||||
|
||||
return time.loop();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -96,7 +96,7 @@ public:
|
||||
// Solution control
|
||||
|
||||
//- Loop loop
|
||||
inline bool loop();
|
||||
virtual bool loop();
|
||||
};
|
||||
|
||||
|
||||
@ -106,10 +106,6 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "simpleControlI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -27,36 +27,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::simpleControl::loop()
|
||||
{
|
||||
read();
|
||||
|
||||
Time& time = const_cast<Time&>(mesh_.time());
|
||||
|
||||
if (initialised_)
|
||||
{
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< nl << algorithmName_ << " solution converged in "
|
||||
<< time.timeName() << " iterations" << nl << endl;
|
||||
|
||||
// Set to finalise calculation
|
||||
time.writeAndEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
storePrevIterFields();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
initialised_ = true;
|
||||
storePrevIterFields();
|
||||
}
|
||||
|
||||
|
||||
return time.loop();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -170,7 +170,9 @@ Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
|
||||
algorithmName_(algorithmName),
|
||||
nNonOrthCorr_(0),
|
||||
momentumPredictor_(true),
|
||||
transonic_(false)
|
||||
transonic_(false),
|
||||
corr_(0),
|
||||
corrNonOrtho_(0)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -82,6 +82,15 @@ protected:
|
||||
bool transonic_;
|
||||
|
||||
|
||||
// Evolution
|
||||
|
||||
//- Current corrector loop index
|
||||
label corr_;
|
||||
|
||||
//- Current non-orthogonal corrector loop index
|
||||
label corrNonOrtho_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read controls from fvSolution dictionary
|
||||
@ -137,17 +146,35 @@ public:
|
||||
//- Return the solution dictionary
|
||||
inline const dictionary& dict() const;
|
||||
|
||||
//- Current corrector loop index
|
||||
inline label corr() const;
|
||||
|
||||
//- Current non-orthogonal corrector index
|
||||
inline label corrNonOrtho() const;
|
||||
|
||||
|
||||
// Solution control
|
||||
|
||||
//- Maximum number of non-orthogonal correctors
|
||||
inline label nNonOrthCorr() const;
|
||||
|
||||
//- Helper function to identify final non-orthogonal iteration
|
||||
inline bool finalNonOrthogonalIter() const;
|
||||
|
||||
//- Flag to indicate to solve for momentum
|
||||
inline bool momentumPredictor() const;
|
||||
|
||||
//- Flag to indicate to solve using transonic algorithm
|
||||
inline bool transonic() const;
|
||||
|
||||
|
||||
// Evolution
|
||||
|
||||
//- Main control loop
|
||||
virtual bool loop() = 0;
|
||||
|
||||
//- Non-orthogonal corrector loop
|
||||
inline bool correctNonOrthogonal();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -31,12 +31,30 @@ inline const Foam::dictionary& Foam::solutionControl::dict() const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::solutionControl::corr() const
|
||||
{
|
||||
return corr_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::solutionControl::corrNonOrtho() const
|
||||
{
|
||||
return corrNonOrtho_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::solutionControl::nNonOrthCorr() const
|
||||
{
|
||||
return nNonOrthCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::solutionControl::finalNonOrthogonalIter() const
|
||||
{
|
||||
return corrNonOrtho_ == nNonOrthCorr_ + 1;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::solutionControl::momentumPredictor() const
|
||||
{
|
||||
return momentumPredictor_;
|
||||
@ -49,4 +67,26 @@ inline bool Foam::solutionControl::transonic() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::solutionControl::correctNonOrthogonal()
|
||||
{
|
||||
corrNonOrtho_++;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
|
||||
<< corrNonOrtho_ << endl;
|
||||
}
|
||||
|
||||
if (corrNonOrtho_ <= nNonOrthCorr_ + 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
corrNonOrtho_ = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user