mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: expose solutionControl::maxResiduals as a static with simpler parameters
- use a Pair<scalar> with first() / last() residuals
This commit is contained in:
@ -63,10 +63,10 @@ class data
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
data(const data&);
|
data(const data&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const data&);
|
void operator=(const data&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -83,27 +83,24 @@ public:
|
|||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Access
|
//- Return the dictionary of solver performance data which
|
||||||
|
//- includes initial and final residuals for convergence checking
|
||||||
|
const dictionary& solverPerformanceDict() const;
|
||||||
|
|
||||||
//- Return the dictionary of solver performance data
|
//- Add/set the solverPerformance entry for the named field
|
||||||
// which includes initial and final residuals for convergence
|
template<class Type>
|
||||||
// checking
|
void setSolverPerformance
|
||||||
const dictionary& solverPerformanceDict() const;
|
(
|
||||||
|
const word& name,
|
||||||
|
const SolverPerformance<Type>& sp
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Add/set the solverPerformance entry for the named field
|
//- Add/set the solverPerformance entry, using its fieldName
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void setSolverPerformance
|
void setSolverPerformance
|
||||||
(
|
(
|
||||||
const word& name,
|
const SolverPerformance<Type>& sp
|
||||||
const SolverPerformance<Type>&
|
) const;
|
||||||
) const;
|
|
||||||
|
|
||||||
//- Add/set the solverPerformance entry, using its fieldName
|
|
||||||
template<class Type>
|
|
||||||
void setSolverPerformance
|
|
||||||
(
|
|
||||||
const SolverPerformance<Type>&
|
|
||||||
) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,7 +24,6 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "pimpleControl.H"
|
#include "pimpleControl.H"
|
||||||
#include "Switch.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -42,12 +41,12 @@ void Foam::pimpleControl::read()
|
|||||||
|
|
||||||
const dictionary& pimpleDict = dict();
|
const dictionary& pimpleDict = dict();
|
||||||
|
|
||||||
solveFlow_ = pimpleDict.lookupOrDefault<Switch>("solveFlow", true);
|
solveFlow_ = pimpleDict.lookupOrDefault("solveFlow", true);
|
||||||
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
||||||
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
|
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
|
||||||
SIMPLErho_ = pimpleDict.lookupOrDefault<Switch>("SIMPLErho", false);
|
SIMPLErho_ = pimpleDict.lookupOrDefault("SIMPLErho", false);
|
||||||
turbOnFinalIterOnly_ =
|
turbOnFinalIterOnly_ =
|
||||||
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
|
pimpleDict.lookupOrDefault("turbOnFinalIterOnly", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,41 +59,42 @@ bool Foam::pimpleControl::criteriaSatisfied()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool storeIni = this->storeInitialResiduals();
|
const 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
|
||||||
|
|
||||||
const dictionary& solverDict = mesh_.solverPerformanceDict();
|
const dictionary& solverDict = mesh_.solverPerformanceDict();
|
||||||
forAllConstIter(dictionary, solverDict, iter)
|
forAllConstIters(solverDict, iter)
|
||||||
{
|
{
|
||||||
const word& variableName = iter().keyword();
|
const entry& solverPerfDictEntry = *iter;
|
||||||
const label fieldi = applyToField(variableName);
|
|
||||||
|
const word& fieldName = solverPerfDictEntry.keyword();
|
||||||
|
const label fieldi = applyToField(fieldName);
|
||||||
|
|
||||||
if (fieldi != -1)
|
if (fieldi != -1)
|
||||||
{
|
{
|
||||||
scalar residual = 0;
|
Pair<scalar> residuals = maxResidual(solverPerfDictEntry);
|
||||||
const scalar firstResidual =
|
|
||||||
maxResidual(variableName, iter().stream(), residual);
|
|
||||||
|
|
||||||
checked = true;
|
checked = true;
|
||||||
|
|
||||||
if (storeIni)
|
scalar relative = 0.0;
|
||||||
{
|
|
||||||
residualControl_[fieldi].initialResidual = firstResidual;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool absCheck = residual < residualControl_[fieldi].absTol;
|
|
||||||
bool relCheck = false;
|
bool relCheck = false;
|
||||||
|
|
||||||
scalar relative = 0.0;
|
const bool absCheck =
|
||||||
if (!storeIni)
|
(residuals.last() < residualControl_[fieldi].absTol);
|
||||||
|
|
||||||
|
if (storeIni)
|
||||||
|
{
|
||||||
|
residualControl_[fieldi].initialResidual = residuals.first();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
const scalar iniRes =
|
const scalar iniRes =
|
||||||
residualControl_[fieldi].initialResidual
|
(residualControl_[fieldi].initialResidual + ROOTVSMALL);
|
||||||
+ ROOTVSMALL;
|
|
||||||
|
|
||||||
relative = residual/iniRes;
|
relative = residuals.last() / iniRes;
|
||||||
relCheck = relative < residualControl_[fieldi].relTol;
|
relCheck = (relative < residualControl_[fieldi].relTol);
|
||||||
}
|
}
|
||||||
|
|
||||||
achieved = achieved && (absCheck || relCheck);
|
achieved = achieved && (absCheck || relCheck);
|
||||||
@ -103,11 +103,11 @@ bool Foam::pimpleControl::criteriaSatisfied()
|
|||||||
{
|
{
|
||||||
Info<< algorithmName_ << " loop:" << endl;
|
Info<< algorithmName_ << " loop:" << endl;
|
||||||
|
|
||||||
Info<< " " << variableName
|
Info<< " " << fieldName
|
||||||
<< " PIMPLE iter " << corr_
|
<< " PIMPLE iter " << corr_
|
||||||
<< ": ini res = "
|
<< ": ini res = "
|
||||||
<< residualControl_[fieldi].initialResidual
|
<< residualControl_[fieldi].initialResidual
|
||||||
<< ", abs tol = " << residual
|
<< ", abs tol = " << residuals.last()
|
||||||
<< " (" << residualControl_[fieldi].absTol << ")"
|
<< " (" << residualControl_[fieldi].absTol << ")"
|
||||||
<< ", rel tol = " << relative
|
<< ", rel tol = " << relative
|
||||||
<< " (" << residualControl_[fieldi].relTol << ")"
|
<< " (" << residualControl_[fieldi].relTol << ")"
|
||||||
@ -135,50 +135,46 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh, const word& dictName)
|
|||||||
{
|
{
|
||||||
read();
|
read();
|
||||||
|
|
||||||
|
Info<< nl
|
||||||
|
<< algorithmName_;
|
||||||
|
|
||||||
if (nCorrPIMPLE_ > 1)
|
if (nCorrPIMPLE_ > 1)
|
||||||
{
|
{
|
||||||
Info<< nl;
|
|
||||||
if (residualControl_.empty())
|
if (residualControl_.empty())
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << ": no residual control data found. "
|
Info<< ": no residual control data found. "
|
||||||
<< "Calculations will employ " << nCorrPIMPLE_
|
<< "Calculations will employ " << nCorrPIMPLE_
|
||||||
<< " corrector loops" << nl << endl;
|
<< " corrector loops" << nl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << ": max iterations = " << nCorrPIMPLE_
|
Info<< ": max iterations = " << nCorrPIMPLE_ << nl;
|
||||||
<< endl;
|
|
||||||
forAll(residualControl_, i)
|
for (const fieldData& ctrl : residualControl_)
|
||||||
{
|
{
|
||||||
Info<< " field " << residualControl_[i].name << token::TAB
|
Info<< " field " << ctrl.name << token::TAB
|
||||||
<< ": relTol " << residualControl_[i].relTol
|
<< ": relTol " << ctrl.relTol
|
||||||
<< ", tolerance " << residualControl_[i].absTol
|
<< ", tolerance " << ctrl.absTol
|
||||||
<< nl;
|
<< nl;
|
||||||
}
|
}
|
||||||
Info<< endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Info<< nl << algorithmName_ << ": Operating solver in PISO mode" << nl
|
Info<< ": Operating solver in PISO mode" << nl;
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::pimpleControl::~pimpleControl()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::pimpleControl::loop()
|
bool Foam::pimpleControl::loop()
|
||||||
{
|
{
|
||||||
read();
|
read();
|
||||||
|
|
||||||
corr_++;
|
++corr_;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
@ -187,7 +183,7 @@ bool Foam::pimpleControl::loop()
|
|||||||
|
|
||||||
if (corr_ == nCorrPIMPLE_ + 1)
|
if (corr_ == nCorrPIMPLE_ + 1)
|
||||||
{
|
{
|
||||||
if ((!residualControl_.empty()) && (nCorrPIMPLE_ != 1))
|
if (!residualControl_.empty() && (nCorrPIMPLE_ != 1))
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << ": not converged within "
|
Info<< algorithmName_ << ": not converged within "
|
||||||
<< nCorrPIMPLE_ << " iterations" << endl;
|
<< nCorrPIMPLE_ << " iterations" << endl;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -57,10 +57,10 @@ class pimpleControl
|
|||||||
// Private member functions
|
// Private member functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
pimpleControl(const pimpleControl&);
|
pimpleControl(const pimpleControl&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const pimpleControl&);
|
void operator=(const pimpleControl&) = delete;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -116,7 +116,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~pimpleControl();
|
virtual ~pimpleControl() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -151,7 +151,7 @@ public:
|
|||||||
//- Return true for first PIMPLE (outer) iteration
|
//- Return true for first PIMPLE (outer) iteration
|
||||||
inline bool firstIter() const;
|
inline bool firstIter() const;
|
||||||
|
|
||||||
//- Return true fore final PIMPLE (outer) iteration
|
//- Return true for final PIMPLE (outer) iteration
|
||||||
inline bool finalIter() const;
|
inline bool finalIter() const;
|
||||||
|
|
||||||
//- Return true for final inner iteration
|
//- Return true for final inner iteration
|
||||||
|
|||||||
@ -51,7 +51,7 @@ inline bool Foam::pimpleControl::SIMPLErho() const
|
|||||||
|
|
||||||
inline bool Foam::pimpleControl::correct()
|
inline bool Foam::pimpleControl::correct()
|
||||||
{
|
{
|
||||||
corrPISO_++;
|
++corrPISO_;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
@ -62,11 +62,9 @@ inline bool Foam::pimpleControl::correct()
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
corrPISO_ = 0;
|
||||||
corrPISO_ = 0;
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -53,26 +53,29 @@ bool Foam::simpleControl::criteriaSatisfied()
|
|||||||
bool checked = false; // safety that some checks were indeed performed
|
bool checked = false; // safety that some checks were indeed performed
|
||||||
|
|
||||||
const dictionary& solverDict = mesh_.solverPerformanceDict();
|
const dictionary& solverDict = mesh_.solverPerformanceDict();
|
||||||
forAllConstIter(dictionary, solverDict, iter)
|
forAllConstIters(solverDict, iter)
|
||||||
{
|
{
|
||||||
const word& variableName = iter().keyword();
|
const entry& solverPerfDictEntry = *iter;
|
||||||
const label fieldi = applyToField(variableName);
|
|
||||||
|
const word& fieldName = solverPerfDictEntry.keyword();
|
||||||
|
const label fieldi = applyToField(fieldName);
|
||||||
|
|
||||||
if (fieldi != -1)
|
if (fieldi != -1)
|
||||||
{
|
{
|
||||||
scalar lastResidual = 0;
|
Pair<scalar> residuals = maxResidual(solverPerfDictEntry);
|
||||||
const scalar residual =
|
|
||||||
maxResidual(variableName, iter().stream(), lastResidual);
|
|
||||||
|
|
||||||
checked = true;
|
checked = true;
|
||||||
|
|
||||||
bool absCheck = residual < residualControl_[fieldi].absTol;
|
const bool absCheck =
|
||||||
|
(residuals.first() < residualControl_[fieldi].absTol);
|
||||||
|
|
||||||
achieved = achieved && absCheck;
|
achieved = achieved && absCheck;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << " solution statistics:" << endl;
|
Info<< algorithmName_ << " solution statistics:" << endl;
|
||||||
|
|
||||||
Info<< " " << variableName << ": tolerance = " << residual
|
Info<< " " << fieldName << ": tolerance = "
|
||||||
|
<< residuals.first()
|
||||||
<< " (" << residualControl_[fieldi].absTol << ")"
|
<< " (" << residualControl_[fieldi].absTol << ")"
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
@ -85,64 +88,53 @@ bool Foam::simpleControl::criteriaSatisfied()
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::simpleControl::simpleControl(fvMesh& mesh)
|
Foam::simpleControl::simpleControl(fvMesh& mesh, const word& dictName)
|
||||||
:
|
:
|
||||||
solutionControl(mesh, "SIMPLE"),
|
solutionControl(mesh, dictName),
|
||||||
initialised_(false)
|
initialised_(false)
|
||||||
{
|
{
|
||||||
read();
|
read();
|
||||||
|
|
||||||
Info<< nl;
|
Info<< nl
|
||||||
|
<< algorithmName_;
|
||||||
|
|
||||||
if (residualControl_.empty())
|
if (residualControl_.empty())
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << ": no convergence criteria found. "
|
Info<< ": no convergence criteria found. Calculations will run for "
|
||||||
<< "Calculations will run for "
|
|
||||||
<< mesh_.time().endTime().value() - mesh_.time().startTime().value()
|
<< mesh_.time().endTime().value() - mesh_.time().startTime().value()
|
||||||
<< " steps." << nl << endl;
|
<< " steps." << nl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Info<< algorithmName_ << ": convergence criteria" << nl;
|
Info<< ": convergence criteria" << nl;
|
||||||
forAll(residualControl_, i)
|
for (const fieldData& ctrl : residualControl_)
|
||||||
{
|
{
|
||||||
Info<< " field " << residualControl_[i].name << token::TAB
|
Info<< " field " << ctrl.name << token::TAB
|
||||||
<< " tolerance " << residualControl_[i].absTol
|
<< " tolerance " << ctrl.absTol
|
||||||
<< nl;
|
<< nl;
|
||||||
}
|
}
|
||||||
Info<< endl;
|
|
||||||
}
|
}
|
||||||
|
Info<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::simpleControl::~simpleControl()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::simpleControl::loop()
|
bool Foam::simpleControl::loop()
|
||||||
{
|
{
|
||||||
read();
|
read();
|
||||||
|
|
||||||
Time& time = const_cast<Time&>(mesh_.time());
|
Time& runTime = const_cast<Time&>(mesh_.time());
|
||||||
|
|
||||||
if (initialised_)
|
if (initialised_ && criteriaSatisfied())
|
||||||
{
|
{
|
||||||
if (criteriaSatisfied())
|
Info<< nl
|
||||||
{
|
<< algorithmName_
|
||||||
Info<< nl << algorithmName_ << " solution converged in "
|
<< " solution converged in "
|
||||||
<< time.timeName() << " iterations" << nl << endl;
|
<< runTime.timeName() << " iterations" << nl << endl;
|
||||||
|
|
||||||
// Set to finalise calculation
|
// Set to finalise calculation
|
||||||
time.writeAndEnd();
|
runTime.writeAndEnd();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
storePrevIterFields();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -150,8 +142,7 @@ bool Foam::simpleControl::loop()
|
|||||||
storePrevIterFields();
|
storePrevIterFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return runTime.loop();
|
||||||
return time.loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -74,10 +74,10 @@ private:
|
|||||||
// Private member functions
|
// Private member functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
simpleControl(const simpleControl&);
|
simpleControl(const simpleControl&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const simpleControl&);
|
void operator=(const simpleControl&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -90,19 +90,19 @@ public:
|
|||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from mesh
|
//- Construct from mesh and the name of control sub-dictionary
|
||||||
simpleControl(fvMesh& mesh);
|
simpleControl(fvMesh& mesh, const word& dictName="SIMPLE");
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~simpleControl();
|
virtual ~simpleControl() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
// Solution control
|
// Solution control
|
||||||
|
|
||||||
//- Loop loop
|
//- SIMPLE loop
|
||||||
virtual bool loop();
|
virtual bool loop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -148,11 +148,7 @@ Foam::label Foam::solutionControl::applyToField
|
|||||||
{
|
{
|
||||||
forAll(residualControl_, i)
|
forAll(residualControl_, i)
|
||||||
{
|
{
|
||||||
if (useRegEx && residualControl_[i].name.match(fieldName))
|
if (residualControl_[i].name.match(fieldName, !useRegEx))
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
else if (residualControl_[i].name == fieldName)
|
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -173,42 +169,68 @@ void Foam::solutionControl::storePrevIterFields() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
Foam::Pair<Foam::scalar> Foam::solutionControl::maxResidual
|
||||||
void Foam::solutionControl::maxTypeResidual
|
|
||||||
(
|
(
|
||||||
const word& fieldName,
|
const entry& solverPerfDictEntry
|
||||||
ITstream& data,
|
|
||||||
scalar& firstRes,
|
|
||||||
scalar& lastRes
|
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
return maxResidual(mesh_, solverPerfDictEntry);
|
||||||
|
|
||||||
if (mesh_.foundObject<fieldType>(fieldName))
|
|
||||||
{
|
|
||||||
const List<SolverPerformance<Type>> sp(data);
|
|
||||||
firstRes = cmptMax(sp.first().initialResidual());
|
|
||||||
lastRes = cmptMax(sp.last().initialResidual());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::solutionControl::maxResidual
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
bool Foam::solutionControl::maxTypeResidual
|
||||||
(
|
(
|
||||||
const word& fieldName,
|
const fvMesh& fvmesh,
|
||||||
ITstream& data,
|
const entry& solverPerfDictEntry,
|
||||||
scalar& lastRes
|
Pair<scalar>& residuals
|
||||||
) const
|
)
|
||||||
{
|
{
|
||||||
scalar firstRes = 0;
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
maxTypeResidual<scalar>(fieldName, data, firstRes, lastRes);
|
const word& fieldName = solverPerfDictEntry.keyword();
|
||||||
maxTypeResidual<vector>(fieldName, data, firstRes, lastRes);
|
|
||||||
maxTypeResidual<sphericalTensor>(fieldName, data, firstRes, lastRes);
|
|
||||||
maxTypeResidual<symmTensor>(fieldName, data, firstRes, lastRes);
|
|
||||||
maxTypeResidual<tensor>(fieldName, data, firstRes, lastRes);
|
|
||||||
|
|
||||||
return firstRes;
|
if (fvmesh.foundObject<fieldType>(fieldName))
|
||||||
|
{
|
||||||
|
const List<SolverPerformance<Type>> sp(solverPerfDictEntry.stream());
|
||||||
|
|
||||||
|
residuals.first() = cmptMax(sp.first().initialResidual());
|
||||||
|
residuals.last() = cmptMax(sp.last().initialResidual());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Pair<Foam::scalar> Foam::solutionControl::maxResidual
|
||||||
|
(
|
||||||
|
const fvMesh& fvmesh,
|
||||||
|
const entry& solverPerfDictEntry
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Pair<scalar> residuals(0,0);
|
||||||
|
|
||||||
|
// Check with builtin short-circuit
|
||||||
|
const bool ok =
|
||||||
|
(
|
||||||
|
maxTypeResidual<scalar>(fvmesh, solverPerfDictEntry, residuals)
|
||||||
|
|| maxTypeResidual<vector>(fvmesh, solverPerfDictEntry, residuals)
|
||||||
|
|| maxTypeResidual<sphericalTensor>(fvmesh, solverPerfDictEntry, residuals)
|
||||||
|
|| maxTypeResidual<symmTensor>(fvmesh, solverPerfDictEntry, residuals)
|
||||||
|
|| maxTypeResidual<tensor>(fvmesh, solverPerfDictEntry, residuals)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!ok && solutionControl::debug)
|
||||||
|
{
|
||||||
|
Info<<"no residual for " << solverPerfDictEntry.keyword()
|
||||||
|
<< " on mesh " << fvmesh.name() << nl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return residuals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -235,10 +257,4 @@ Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::solutionControl::~solutionControl()
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,6 +33,7 @@ Description
|
|||||||
#define solutionControl_H
|
#define solutionControl_H
|
||||||
|
|
||||||
#include "fvMesh.H"
|
#include "fvMesh.H"
|
||||||
|
#include "Pair.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -49,6 +50,7 @@ class solutionControl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
//- Simple convenient storage of field residuals
|
||||||
struct fieldData
|
struct fieldData
|
||||||
{
|
{
|
||||||
wordRe name;
|
wordRe name;
|
||||||
@ -58,6 +60,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Static Member Functions
|
||||||
|
|
||||||
|
//- Extract maximum residual for the solver performance entry,
|
||||||
|
//- provided the corresponding volume field is available on the mesh.
|
||||||
|
//
|
||||||
|
// \return initial residual as first member, the final residual
|
||||||
|
// as the second (or last) member
|
||||||
|
static Pair<scalar> maxResidual
|
||||||
|
(
|
||||||
|
const fvMesh& fvmesh,
|
||||||
|
const entry& dataDictEntry
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected data
|
// Protected data
|
||||||
@ -126,30 +142,34 @@ protected:
|
|||||||
template<class Type>
|
template<class Type>
|
||||||
void storePrevIter() const;
|
void storePrevIter() const;
|
||||||
|
|
||||||
|
//- Initial and final residual of the specified field-name,
|
||||||
|
//- provided that the corresponding volume field is available
|
||||||
|
//- on the fvMesh.
|
||||||
|
//
|
||||||
|
// Populate residuals with initial residual as first member and
|
||||||
|
// the final residual as second (last) member.
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void maxTypeResidual
|
static bool maxTypeResidual
|
||||||
(
|
(
|
||||||
const word& fieldName,
|
const fvMesh& fvmesh,
|
||||||
ITstream& data,
|
const entry& solverPerfDictEntry,
|
||||||
scalar& firstRes,
|
Pair<scalar>& residuals
|
||||||
scalar& lastRes
|
);
|
||||||
) const;
|
|
||||||
|
|
||||||
scalar maxResidual
|
//- Extract the maximum residual for the specified field
|
||||||
(
|
//
|
||||||
const word& fieldName,
|
// \return initial residual as first member, the final residual
|
||||||
ITstream& data,
|
// as second (last) member
|
||||||
scalar& lastRes
|
Pair<scalar> maxResidual(const entry& solverPerfDictEntry) const;
|
||||||
) const;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
solutionControl(const solutionControl&);
|
solutionControl(const solutionControl&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const solutionControl&);
|
void operator=(const solutionControl&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -168,7 +188,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
virtual ~solutionControl();
|
virtual ~solutionControl() = default;
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -81,7 +81,7 @@ inline bool Foam::solutionControl::frozenFlow() const
|
|||||||
|
|
||||||
inline bool Foam::solutionControl::correctNonOrthogonal()
|
inline bool Foam::solutionControl::correctNonOrthogonal()
|
||||||
{
|
{
|
||||||
corrNonOrtho_++;
|
++corrNonOrtho_;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
@ -93,11 +93,9 @@ inline bool Foam::solutionControl::correctNonOrthogonal()
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
corrNonOrtho_ = 0;
|
||||||
corrNonOrtho_ = 0;
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user