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

This commit is contained in:
andy
2011-10-26 12:02:26 +01:00
parent 72cc4cd7d8
commit 4c63590979
3 changed files with 172 additions and 84 deletions

View File

@ -42,8 +42,10 @@ void Foam::pimpleControl::read()
// Read solution controls // Read solution controls
const dictionary& pimpleDict = dict(); const dictionary& pimpleDict = dict();
nOuterCorr_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1); nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorr_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1); nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
nCorrNonOrtho_ =
pimpleDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 1);
turbOnFinalIterOnly_ = turbOnFinalIterOnly_ =
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true); pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
} }
@ -51,12 +53,14 @@ void Foam::pimpleControl::read()
bool Foam::pimpleControl::criteriaSatisfied() 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; return false;
} }
bool firstIter = corr_ == 1;
bool storeIni = this->storeInitialResiduals();
bool achieved = true; bool achieved = true;
bool checked = false; // safety that some checks were indeed performed bool checked = false; // safety that some checks were indeed performed
@ -73,7 +77,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
checked = true; checked = true;
if (firstIter) if (storeIni)
{ {
residualControl_[fieldI].initialResidual = residualControl_[fieldI].initialResidual =
sp.first().initialResidual(); sp.first().initialResidual();
@ -83,7 +87,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
bool relCheck = false; bool relCheck = false;
scalar relative = 0.0; scalar relative = 0.0;
if (!firstIter) if (!storeIni)
{ {
const scalar iniRes = const scalar iniRes =
residualControl_[fieldI].initialResidual residualControl_[fieldI].initialResidual
@ -97,9 +101,10 @@ bool Foam::pimpleControl::criteriaSatisfied()
if (debug) if (debug)
{ {
Info<< algorithmName_ << "loop statistics:" << endl; Info<< algorithmName_ << " loop:" << endl;
Info<< " " << variableName << " iter " << corr_ Info<< " " << variableName
<< " PIMPLE iter " << corrPIMPLE_
<< ": ini res = " << ": ini res = "
<< residualControl_[fieldI].initialResidual << residualControl_[fieldI].initialResidual
<< ", abs tol = " << residual << ", abs tol = " << residual
@ -120,25 +125,28 @@ bool Foam::pimpleControl::criteriaSatisfied()
Foam::pimpleControl::pimpleControl(fvMesh& mesh) Foam::pimpleControl::pimpleControl(fvMesh& mesh)
: :
solutionControl(mesh, "PIMPLE"), solutionControl(mesh, "PIMPLE"),
nOuterCorr_(0), nCorrPIMPLE_(0),
nCorr_(0), nCorrPISO_(0),
corr_(0), nCorrNonOrtho_(0),
corrPIMPLE_(0),
corrPISO_(0),
corrNonOrtho_(0),
turbOnFinalIterOnly_(true) turbOnFinalIterOnly_(true)
{ {
read(); read();
if (nOuterCorr_ > 1) if (nCorrPIMPLE_ > 1)
{ {
Info<< nl; Info<< nl;
if (residualControl_.empty()) if (residualControl_.empty())
{ {
Info<< algorithmName_ << ": no residual control data found. " Info<< algorithmName_ << ": no residual control data found. "
<< "Calculations will employ " << nOuterCorr_ << "Calculations will employ " << nCorrPIMPLE_
<< " corrector loops" << nl << endl; << " corrector loops" << nl << endl;
} }
else else
{ {
Info<< algorithmName_ << ": max iterations = " << nOuterCorr_ Info<< algorithmName_ << ": max iterations = " << nCorrPIMPLE_
<< endl; << endl;
forAll(residualControl_, i) forAll(residualControl_, i)
{ {

View File

@ -55,13 +55,22 @@ protected:
// Solution controls // Solution controls
//- Maximum number of PIMPLE correctors //- Maximum number of PIMPLE correctors
label nOuterCorr_; label nCorrPIMPLE_;
//- Maximum number of PISO correctors //- Maximum number of PISO correctors
label nCorr_; label nCorrPISO_;
//- Maximum number of non-orthogonal correctors
label nCorrNonOrtho_;
//- Current PIMPLE corrector //- 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 //- Flag to indicate whether to only solve turbulence on final iter
bool turbOnFinalIterOnly_; bool turbOnFinalIterOnly_;
@ -105,41 +114,50 @@ public:
// Access // Access
//- Current corrector index
inline label corr() const;
//- Maximum number of PIMPLE correctors //- Maximum number of PIMPLE correctors
inline label nOuterCorr() const; inline label nCorrPIMPLE() const;
//- Maximum number of PISO correctors //- 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 // Solution control
//- Loop start //- PIMPLE loop
inline bool start();
//- Loop loop
inline bool 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 //- Helper function to identify final PIMPLE (outer) iteration
inline bool finalIter() const; inline bool finalIter() const;
//- Helper function to identify final non-orthogonal iteration
inline bool finalNonOrthogonalIter() const;
//- Helper function to identify final inner iteration //- Helper function to identify final inner iteration
inline bool finalInnerIter inline bool finalInnerIter() const;
(
const label corr,
const label nonOrth
) const;
//- Helper function to identify whether to solve for turbulence //- Helper function to identify whether to solve for turbulence
inline bool turbCorr() const; inline bool turbCorr() const;
// Member Operators
void operator++(int);
}; };

View File

@ -25,41 +25,70 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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_;
}
return true;
inline Foam::label Foam::pimpleControl::corrPISO() const
{
return corrPISO_;
}
inline Foam::label Foam::pimpleControl::corrNonOrtho() const
{
return corrNonOrtho_;
} }
inline bool Foam::pimpleControl::loop() inline bool Foam::pimpleControl::loop()
{ {
read(); 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()) if (criteriaSatisfied())
{ {
Info<< algorithmName_ << ": converged in " << corr_ << " iterations" Info<< algorithmName_ << ": converged in " << corrPIMPLE_
<< endl; << " iterations" << endl;
return false; completed = true;
} }
else else
{ {
@ -68,46 +97,90 @@ inline bool Foam::pimpleControl::loop()
mesh_.data::add("finalIteration", true); 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(); 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::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);
} }
inline bool Foam::pimpleControl::finalIter() const inline bool Foam::pimpleControl::finalIter() const
{ {
return corr_ == nOuterCorr_-1; return corrPIMPLE_ == nCorrPIMPLE_;
} }
inline bool Foam::pimpleControl::finalInnerIter inline bool Foam::pimpleControl::finalNonOrthogonalIter() const
(
const label corr,
const label nonOrth
) const
{ {
return return corrNonOrtho_ == nCorrNonOrtho_ + 1;
corr_ == nOuterCorr_-1 }
&& corr == nCorr_-1
&& nonOrth == nNonOrthCorr_;
inline bool Foam::pimpleControl::finalInnerIter() const
{
return
corrPIMPLE_ == nCorrPIMPLE_
&& corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nCorrNonOrtho_ + 1;
} }
@ -117,15 +190,4 @@ inline bool Foam::pimpleControl::turbCorr() const
} }
inline void Foam::pimpleControl::operator++(int)
{
if (finalIter())
{
mesh_.data::remove("finalIteration");
}
corr_++;
}
// ************************************************************************* // // ************************************************************************* //