Commit 4c635909 authored by andy's avatar andy
Browse files

ENH: Updated pimpleControl - better encapsulation and included PISO/non-ortho loops

parent 72cc4cd7
......@@ -42,8 +42,10 @@ void Foam::pimpleControl::read()
// Read solution controls
const dictionary& pimpleDict = dict();
nOuterCorr_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorr_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
nCorrNonOrtho_ =
pimpleDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 1);
turbOnFinalIterOnly_ =
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
}
......@@ -51,12 +53,14 @@ void Foam::pimpleControl::read()
bool Foam::pimpleControl::criteriaSatisfied()
{
if ((corr_ == 0) || residualControl_.empty() || finalIter())
// no checks on first iteration - nothing has been calculated yet
if ((corrPIMPLE_ == 1) || residualControl_.empty() || finalIter())
{
return false;
}
bool firstIter = corr_ == 1;
bool storeIni = this->storeInitialResiduals();
bool achieved = true;
bool checked = false; // safety that some checks were indeed performed
......@@ -73,7 +77,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
checked = true;
if (firstIter)
if (storeIni)
{
residualControl_[fieldI].initialResidual =
sp.first().initialResidual();
......@@ -83,7 +87,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
bool relCheck = false;
scalar relative = 0.0;
if (!firstIter)
if (!storeIni)
{
const scalar iniRes =
residualControl_[fieldI].initialResidual
......@@ -97,9 +101,10 @@ bool Foam::pimpleControl::criteriaSatisfied()
if (debug)
{
Info<< algorithmName_ << "loop statistics:" << endl;
Info<< algorithmName_ << " loop:" << endl;
Info<< " " << variableName << " iter " << corr_
Info<< " " << variableName
<< " PIMPLE iter " << corrPIMPLE_
<< ": ini res = "
<< residualControl_[fieldI].initialResidual
<< ", abs tol = " << residual
......@@ -120,25 +125,28 @@ bool Foam::pimpleControl::criteriaSatisfied()
Foam::pimpleControl::pimpleControl(fvMesh& mesh)
:
solutionControl(mesh, "PIMPLE"),
nOuterCorr_(0),
nCorr_(0),
corr_(0),
nCorrPIMPLE_(0),
nCorrPISO_(0),
nCorrNonOrtho_(0),
corrPIMPLE_(0),
corrPISO_(0),
corrNonOrtho_(0),
turbOnFinalIterOnly_(true)
{
read();
if (nOuterCorr_ > 1)
if (nCorrPIMPLE_ > 1)
{
Info<< nl;
if (residualControl_.empty())
{
Info<< algorithmName_ << ": no residual control data found. "
<< "Calculations will employ " << nOuterCorr_
<< "Calculations will employ " << nCorrPIMPLE_
<< " corrector loops" << nl << endl;
}
else
{
Info<< algorithmName_ << ": max iterations = " << nOuterCorr_
Info<< algorithmName_ << ": max iterations = " << nCorrPIMPLE_
<< endl;
forAll(residualControl_, i)
{
......
......@@ -55,13 +55,22 @@ protected:
// Solution controls
//- Maximum number of PIMPLE correctors
label nOuterCorr_;
label nCorrPIMPLE_;
//- Maximum number of PISO correctors
label nCorr_;
label nCorrPISO_;
//- Maximum number of non-orthogonal correctors
label nCorrNonOrtho_;
//- Current PIMPLE corrector
label corr_;
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_;
......@@ -105,41 +114,50 @@ public:
// Access
//- Current corrector index
inline label corr() const;
//- Maximum number of PIMPLE correctors
inline label nOuterCorr() const;
inline label nCorrPIMPLE() const;
//- Maximum number of PISO correctors
inline label nCorr() const;
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
//- Loop start
inline bool start();
// Solution control
//- Loop loop
//- PIMPLE loop
inline bool loop();
//- 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 label corr,
const label nonOrth
) const;
inline bool finalInnerIter() const;
//- Helper function to identify whether to solve for turbulence
inline bool turbCorr() const;
// Member Operators
void operator++(int);
};
......
......@@ -25,42 +25,71 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::pimpleControl::corr() const
inline Foam::label Foam::pimpleControl::nCorrPIMPLE() const
{
return corr_;
return nCorrPIMPLE_;
}
inline Foam::label Foam::pimpleControl::nOuterCorr() const
inline Foam::label Foam::pimpleControl::nCorrPISO() const
{
return nOuterCorr_;
return nCorrPISO_;
}
inline Foam::label Foam::pimpleControl::nCorr() const
inline Foam::label Foam::pimpleControl::nCorrNonOrtho() const
{
return nCorr_;
return nCorrPISO_;
}
inline bool Foam::pimpleControl::start()
inline Foam::label Foam::pimpleControl::corrPIMPLE() const
{
corr_ = 0;
return corrPIMPLE_;
}
inline Foam::label Foam::pimpleControl::corrPISO() const
{
return corrPISO_;
}
return true;
inline Foam::label Foam::pimpleControl::corrNonOrtho() const
{
return corrNonOrtho_;
}
inline bool Foam::pimpleControl::loop()
{
read();
corrPIMPLE_++;
if (criteriaSatisfied())
if (debug)
{
Info<< algorithmName_ << ": converged in " << corr_ << " iterations"
<< endl;
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())
......@@ -68,63 +97,96 @@ inline bool Foam::pimpleControl::loop()
mesh_.data::add("finalIteration", true);
}
if (corr_ < nOuterCorr_)
if (corrPIMPLE_ <= nCorrPIMPLE_)
{
if (nOuterCorr_ != 1)
if (nCorrPIMPLE_ != 1)
{
Info<< algorithmName_ << ": iteration " << corr_ + 1 << endl;
Info<< algorithmName_ << ": iteration " << corrPIMPLE_ << endl;
storePrevIterFields();
}
return true;
completed = false;
}
else
{
if ((!residualControl_.empty()) && (nOuterCorr_ != 1))
{
Info<< algorithmName_ << ": not converged within "
<< nOuterCorr_ << " iterations" << endl;
}
}
return false;
}
return !completed;
}
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::finalIter() const
inline bool Foam::pimpleControl::correctNonOrthogonal()
{
return corr_ == nOuterCorr_-1;
corrNonOrtho_++;
if (debug)
{
Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
<< corrNonOrtho_ << endl;
}
if (corrNonOrtho_ <= nCorrNonOrtho_ + 1)
{
return true;
}
else
{
corrNonOrtho_ = 0;
return false;
}
}
inline bool Foam::pimpleControl::finalInnerIter
(
const label corr,
const label nonOrth
) const
inline bool Foam::pimpleControl::storeInitialResiduals() const
{
return
corr_ == nOuterCorr_-1
&& corr == nCorr_-1
&& nonOrth == nNonOrthCorr_;
// start from second PIMPLE iteration
return (corrPIMPLE_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
}
inline bool Foam::pimpleControl::turbCorr() const
inline bool Foam::pimpleControl::finalIter() const
{
return !turbOnFinalIterOnly_ || finalIter();
return corrPIMPLE_ == nCorrPIMPLE_;
}
inline void Foam::pimpleControl::operator++(int)
inline bool Foam::pimpleControl::finalNonOrthogonalIter() const
{
if (finalIter())
{
mesh_.data::remove("finalIteration");
}
return corrNonOrtho_ == nCorrNonOrtho_ + 1;
}
corr_++;
inline bool Foam::pimpleControl::finalInnerIter() const
{
return
corrPIMPLE_ == nCorrPIMPLE_
&& corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nCorrNonOrtho_ + 1;
}
inline bool Foam::pimpleControl::turbCorr() const
{
return !turbOnFinalIterOnly_ || finalIter();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment