ENH: Extended and restructured solutionControl class

This commit is contained in:
andy
2011-10-26 14:29:49 +01:00
parent d05c5a41a1
commit 3f53a04f09
11 changed files with 173 additions and 175 deletions

View File

@ -31,7 +31,7 @@
} }
// correct interface on first PIMPLE corrector // correct interface on first PIMPLE corrector
if (pimple.corrPIMPLE() == 1) if (pimple.corr() == 1)
{ {
interface.correct(); interface.correct();
} }

View File

@ -33,7 +33,7 @@
} }
// correct interface on first PIMPLE corrector // correct interface on first PIMPLE corrector
if (pimple.corrPIMPLE() == 1) if (pimple.corr() == 1)
{ {
interface.correct(); interface.correct();
} }

View File

@ -44,8 +44,6 @@ void Foam::pimpleControl::read()
const dictionary& pimpleDict = dict(); const dictionary& pimpleDict = dict();
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1); nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorrPISO_ = 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);
} }
@ -54,7 +52,7 @@ void Foam::pimpleControl::read()
bool Foam::pimpleControl::criteriaSatisfied() bool Foam::pimpleControl::criteriaSatisfied()
{ {
// no checks on first iteration - nothing has been calculated yet // no checks on first iteration - nothing has been calculated yet
if ((corrPIMPLE_ == 1) || residualControl_.empty() || finalIter()) if ((corr_ == 1) || residualControl_.empty() || finalIter())
{ {
return false; return false;
} }
@ -104,7 +102,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
Info<< algorithmName_ << " loop:" << endl; Info<< algorithmName_ << " loop:" << endl;
Info<< " " << variableName Info<< " " << variableName
<< " PIMPLE iter " << corrPIMPLE_ << " PIMPLE iter " << corr_
<< ": ini res = " << ": ini res = "
<< residualControl_[fieldI].initialResidual << residualControl_[fieldI].initialResidual
<< ", abs tol = " << residual << ", abs tol = " << residual
@ -127,10 +125,7 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh)
solutionControl(mesh, "PIMPLE"), solutionControl(mesh, "PIMPLE"),
nCorrPIMPLE_(0), nCorrPIMPLE_(0),
nCorrPISO_(0), nCorrPISO_(0),
nCorrNonOrtho_(0),
corrPIMPLE_(0),
corrPISO_(0), corrPISO_(0),
corrNonOrtho_(0),
turbOnFinalIterOnly_(true) turbOnFinalIterOnly_(true)
{ {
read(); 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -60,18 +60,9 @@ protected:
//- Maximum number of PISO correctors //- Maximum number of PISO correctors
label nCorrPISO_; label nCorrPISO_;
//- Maximum number of non-orthogonal correctors
label nCorrNonOrtho_;
//- Current PIMPLE corrector
label corrPIMPLE_;
//- Current PISO corrector //- Current PISO corrector
label corrPISO_; 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_;
@ -120,39 +111,24 @@ public:
//- Maximum number of PISO correctors //- Maximum number of PISO correctors
inline label nCorrPISO() 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 //- Current PISO corrector index
inline label corrPISO() const; inline label corrPISO() const;
//- Current non-orthogonal corrector index
inline label corrNonOrtho() const;
// Solution control // Solution control
//- PIMPLE loop //- PIMPLE loop
inline bool loop(); virtual bool loop();
//- Corrector loop //- Pressure corrector loop
inline bool correct(); inline bool correct();
//- Non-orthogonal corrector loop
inline bool correctNonOrthogonal();
//- Helper function to identify when to store the intial residuals //- Helper function to identify when to store the intial residuals
inline bool storeInitialResiduals() const; 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() const; inline bool finalInnerIter() const;

View File

@ -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 inline Foam::label Foam::pimpleControl::corrPISO() const
{ {
return corrPISO_; 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() inline bool Foam::pimpleControl::correct()
{ {
corrPISO_++; 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 inline bool Foam::pimpleControl::storeInitialResiduals() const
{ {
// start from second PIMPLE iteration // 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 inline bool Foam::pimpleControl::finalIter() const
{ {
return corrPIMPLE_ == nCorrPIMPLE_; return corr_ == nCorrPIMPLE_;
}
inline bool Foam::pimpleControl::finalNonOrthogonalIter() const
{
return corrNonOrtho_ == nCorrNonOrtho_ + 1;
} }
inline bool Foam::pimpleControl::finalInnerIter() const inline bool Foam::pimpleControl::finalInnerIter() const
{ {
return return
corrPIMPLE_ == nCorrPIMPLE_ corr_ == nCorrPIMPLE_
&& corrPISO_ == nCorrPISO_ && corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nCorrNonOrtho_ + 1; && corrNonOrtho_ == nNonOrthCorr_ + 1;
} }

View File

@ -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();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -96,7 +96,7 @@ public:
// Solution control // Solution control
//- Loop loop //- Loop loop
inline bool loop(); virtual bool loop();
}; };
@ -106,10 +106,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "simpleControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -27,36 +27,6 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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();
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -170,7 +170,9 @@ Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
algorithmName_(algorithmName), algorithmName_(algorithmName),
nNonOrthCorr_(0), nNonOrthCorr_(0),
momentumPredictor_(true), momentumPredictor_(true),
transonic_(false) transonic_(false),
corr_(0),
corrNonOrtho_(0)
{} {}

View File

@ -82,6 +82,15 @@ protected:
bool transonic_; bool transonic_;
// Evolution
//- Current corrector loop index
label corr_;
//- Current non-orthogonal corrector loop index
label corrNonOrtho_;
// Protected Member Functions // Protected Member Functions
//- Read controls from fvSolution dictionary //- Read controls from fvSolution dictionary
@ -137,17 +146,35 @@ public:
//- Return the solution dictionary //- Return the solution dictionary
inline const dictionary& dict() const; inline const dictionary& dict() const;
//- Current corrector loop index
inline label corr() const;
//- Current non-orthogonal corrector index
inline label corrNonOrtho() const;
// Solution control // Solution control
//- Maximum number of non-orthogonal correctors //- Maximum number of non-orthogonal correctors
inline label nNonOrthCorr() const; inline label nNonOrthCorr() const;
//- Helper function to identify final non-orthogonal iteration
inline bool finalNonOrthogonalIter() const;
//- Flag to indicate to solve for momentum //- Flag to indicate to solve for momentum
inline bool momentumPredictor() const; inline bool momentumPredictor() const;
//- Flag to indicate to solve using transonic algorithm //- Flag to indicate to solve using transonic algorithm
inline bool transonic() const; inline bool transonic() const;
// Evolution
//- Main control loop
virtual bool loop() = 0;
//- Non-orthogonal corrector loop
inline bool correctNonOrthogonal();
}; };

View File

@ -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 inline Foam::label Foam::solutionControl::nNonOrthCorr() const
{ {
return nNonOrthCorr_; return nNonOrthCorr_;
} }
inline bool Foam::solutionControl::finalNonOrthogonalIter() const
{
return corrNonOrtho_ == nNonOrthCorr_ + 1;
}
inline bool Foam::solutionControl::momentumPredictor() const inline bool Foam::solutionControl::momentumPredictor() const
{ {
return momentumPredictor_; 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;
}
}
// ************************************************************************* // // ************************************************************************* //