ENH: refactored pimpleControl class
This commit is contained in:
parent
d92ea3f5e5
commit
aa2a54f36d
@ -33,19 +33,16 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::pimpleControl::applyToField(const word& fieldName) const
|
||||
void Foam::pimpleControl::read()
|
||||
{
|
||||
forAll(residualControl_, i)
|
||||
{
|
||||
if (residualControl_[i].name.match(fieldName))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
solutionControl::read(false);
|
||||
|
||||
return -1;
|
||||
// Read solution controls
|
||||
const dictionary& pimpleDict = dict();
|
||||
nOuterCorr_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
||||
nCorr_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
|
||||
}
|
||||
|
||||
|
||||
@ -96,7 +93,7 @@ bool Foam::pimpleControl::criteriaSatisfied()
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Info<< "PIMPLE loop statistics:" << endl;
|
||||
Info<< dictName_ << "loop statistics:" << endl;
|
||||
|
||||
Info<< " " << variableName << " iter " << corr_
|
||||
<< ": ini res = "
|
||||
@ -118,16 +115,16 @@ bool Foam::pimpleControl::criteriaSatisfied()
|
||||
|
||||
Foam::pimpleControl::pimpleControl(fvMesh& mesh)
|
||||
:
|
||||
mesh_(mesh),
|
||||
solutionControl(mesh, "PIMPLE"),
|
||||
nOuterCorr_(0),
|
||||
nCorr_(0),
|
||||
corr_(0),
|
||||
residualControl_()
|
||||
corr_(0)
|
||||
{
|
||||
read();
|
||||
|
||||
if (residualControl_.size() > 0)
|
||||
{
|
||||
Info<< "PIMPLE: max iterations = " << nCorr_ << endl;
|
||||
Info<< dictName_ << ": max iterations = " << nOuterCorr_ << endl;
|
||||
forAll(residualControl_, i)
|
||||
{
|
||||
Info<< " field " << residualControl_[i].name << token::TAB
|
||||
@ -139,7 +136,7 @@ Foam::pimpleControl::pimpleControl(fvMesh& mesh)
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "No PIMPLE residual control data found. "
|
||||
Info<< "No " << dictName_ << " residual control data found. "
|
||||
<< "Calculations will employ a fixed number of corrector loops"
|
||||
<< nl << endl;
|
||||
}
|
||||
@ -152,40 +149,4 @@ Foam::pimpleControl::~pimpleControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::pimpleControl::read()
|
||||
{
|
||||
const dictionary& dict = mesh_.solutionDict().subDict("PIMPLE");
|
||||
nCorr_ = dict.lookupOrDefault<label>("nOuterCorrectors", 1);
|
||||
const dictionary residualDict(dict.subOrEmptyDict("residualControl"));
|
||||
DynamicList<fieldData> data(residualDict.toc().size());
|
||||
wordHashSet fieldNames;
|
||||
forAllConstIter(dictionary, residualDict, iter)
|
||||
{
|
||||
if (fieldNames.insert(iter().keyword()))
|
||||
{
|
||||
fieldData fd;
|
||||
fd.name = iter().keyword().c_str();
|
||||
if (iter().isDict())
|
||||
{
|
||||
const dictionary& fieldDict(iter().dict());
|
||||
fd.relTol = readScalar(fieldDict.lookup("relTol"));
|
||||
fd.absTol = readScalar(fieldDict.lookup("absTol"));
|
||||
fd.initialResidual = 0.0;
|
||||
data.append(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("bool Foam::pimpleControl::read()")
|
||||
<< "Residual data for " << iter().keyword()
|
||||
<< " must be specified as a dictionary";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
residualControl_.transfer(data);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
@ -33,8 +33,7 @@ Description
|
||||
#ifndef pimpleControl_H
|
||||
#define pimpleControl_H
|
||||
|
||||
#include "fvMesh.H"
|
||||
//#include "className.H"
|
||||
#include "solutionControl.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -42,42 +41,36 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class pimpleControl Declaration
|
||||
Class pimpleControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class pimpleControl
|
||||
:
|
||||
public solutionControl
|
||||
{
|
||||
struct fieldData
|
||||
{
|
||||
wordRe name;
|
||||
scalar relTol;
|
||||
scalar absTol;
|
||||
scalar initialResidual;
|
||||
};
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
// Solution controls
|
||||
|
||||
//- Maximum number of PIMPLE correctors
|
||||
label nOuterCorr_;
|
||||
|
||||
//- Maximum number of PISO correctors
|
||||
label nCorr_;
|
||||
|
||||
//- Current PIMPLE corrector
|
||||
label corr_;
|
||||
|
||||
|
||||
// Private data
|
||||
// Protected Member Functions
|
||||
|
||||
//- Reference to the mesh database
|
||||
fvMesh& mesh_;
|
||||
|
||||
//- Maximum number of PIMPLE correctors
|
||||
int nCorr_;
|
||||
|
||||
//- Current PIMPLE corrector
|
||||
int corr_;
|
||||
|
||||
//- List of residual data per field
|
||||
List<fieldData> residualControl_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return index of field in residualControl_ if present
|
||||
label applyToField(const word& fieldName) const;
|
||||
//- Read constrols from fvSolution dictionary
|
||||
virtual void read();
|
||||
|
||||
//- Return true if all convergence checks are satified
|
||||
bool criteriaSatisfied();
|
||||
virtual bool criteriaSatisfied();
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
pimpleControl(const pimpleControl&);
|
||||
@ -107,17 +100,32 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read constrols from fvSolution dictionary
|
||||
void read();
|
||||
// Access
|
||||
|
||||
//- Loop start
|
||||
bool start();
|
||||
//- Maximum number of PIMPLE correctors
|
||||
inline label nOuterCorr() const;
|
||||
|
||||
//- Loop loop
|
||||
bool loop();
|
||||
//- Maximum number of PISO correctors
|
||||
inline label nCorr() const;
|
||||
|
||||
//- Helper function to identify final iteration
|
||||
bool finalIter() const;
|
||||
|
||||
// Solution control
|
||||
|
||||
//- Loop start
|
||||
inline bool start();
|
||||
|
||||
//- Loop loop
|
||||
inline bool loop();
|
||||
|
||||
//- Helper function to identify final PIMPLE (outer) iteration
|
||||
inline bool finalIter() const;
|
||||
|
||||
//- Helper function to identify final inner iteration
|
||||
inline bool finalInnerIter
|
||||
(
|
||||
const label corr,
|
||||
const label nonOrth
|
||||
) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
@ -25,6 +25,18 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::label Foam::pimpleControl::nOuterCorr() const
|
||||
{
|
||||
return nOuterCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::pimpleControl::nCorr() const
|
||||
{
|
||||
return nCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::start()
|
||||
{
|
||||
corr_ = 0;
|
||||
@ -35,9 +47,12 @@ inline bool Foam::pimpleControl::start()
|
||||
|
||||
inline bool Foam::pimpleControl::loop()
|
||||
{
|
||||
read();
|
||||
|
||||
if (criteriaSatisfied())
|
||||
{
|
||||
Info<< "PIMPLE loop converged in " << corr_ << " iterations" << endl;
|
||||
Info<< dictName_ << "loop converged in " << corr_ << " iterations"
|
||||
<< endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -47,14 +62,14 @@ inline bool Foam::pimpleControl::loop()
|
||||
mesh_.data::add("finalIteration", true);
|
||||
}
|
||||
|
||||
if (corr_ < nCorr_)
|
||||
if (corr_ < nOuterCorr_)
|
||||
{
|
||||
Info<< "PIMPLE iteration " << corr_ + 1 << endl;
|
||||
Info<< dictName_ << " iteration " << corr_ + 1 << endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "PIMPLE loop not converged within " << nCorr_
|
||||
Info<< dictName_ << " loop not converged within " << nOuterCorr_
|
||||
<< " iterations" << endl;
|
||||
return false;
|
||||
}
|
||||
@ -64,7 +79,20 @@ inline bool Foam::pimpleControl::loop()
|
||||
|
||||
inline bool Foam::pimpleControl::finalIter() const
|
||||
{
|
||||
return corr_ == nCorr_-1;
|
||||
return corr_ == nOuterCorr_-1;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::pimpleControl::finalInnerIter
|
||||
(
|
||||
const label corr,
|
||||
const label nonOrth
|
||||
) const
|
||||
{
|
||||
return
|
||||
corr_ == nOuterCorr_-1
|
||||
&& corr == nCorr_-1
|
||||
&& nonOrth == nNonOrthCorr_;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,124 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "solutionControl.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(solutionControl, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::solutionControl::read(const bool absTolOnly)
|
||||
{
|
||||
const dictionary& solnDict = this->dict();
|
||||
|
||||
// Read solution controls
|
||||
nNonOrthCorr_ =
|
||||
solnDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
|
||||
momentumPredictor_ = solnDict.lookupOrDefault("momentumPredictor", true);
|
||||
transonic_ = solnDict.lookupOrDefault("transonic", false);
|
||||
|
||||
// Read residual information
|
||||
const dictionary residualDict(solnDict.subOrEmptyDict("residualControl"));
|
||||
DynamicList<fieldData> data(residualDict.toc().size());
|
||||
wordHashSet fieldNames;
|
||||
|
||||
forAllConstIter(dictionary, residualDict, iter)
|
||||
{
|
||||
if (fieldNames.insert(iter().keyword()))
|
||||
{
|
||||
fieldData fd;
|
||||
fd.name = iter().keyword().c_str();
|
||||
|
||||
if (absTolOnly)
|
||||
{
|
||||
fd.absTol = readScalar(residualDict.lookup(iter().keyword()));
|
||||
fd.relTol = -1;
|
||||
fd.initialResidual = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iter().isDict())
|
||||
{
|
||||
const dictionary& fieldDict(iter().dict());
|
||||
fd.absTol = readScalar(fieldDict.lookup("absTol"));
|
||||
fd.relTol = readScalar(fieldDict.lookup("relTol"));
|
||||
fd.initialResidual = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn("bool Foam::solutionControl::read()")
|
||||
<< "Residual data for " << iter().keyword()
|
||||
<< " must be specified as a dictionary";
|
||||
}
|
||||
}
|
||||
|
||||
data.append(fd);
|
||||
}
|
||||
}
|
||||
|
||||
residualControl_.transfer(data);
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::solutionControl::applyToField(const word& fieldName) const
|
||||
{
|
||||
forAll(residualControl_, i)
|
||||
{
|
||||
if (residualControl_[i].name.match(fieldName))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::solutionControl::solutionControl(fvMesh& mesh, const word& dictName)
|
||||
:
|
||||
mesh_(mesh),
|
||||
residualControl_(),
|
||||
dictName_(dictName),
|
||||
nNonOrthCorr_(0),
|
||||
momentumPredictor_(true),
|
||||
transonic_(false)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::solutionControl::~solutionControl()
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -0,0 +1,155 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::solutionControl
|
||||
|
||||
Description
|
||||
Base class for solution control classes
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef solutionControl_H
|
||||
#define solutionControl_H
|
||||
|
||||
#include "fvMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class solutionControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class solutionControl
|
||||
{
|
||||
public:
|
||||
|
||||
struct fieldData
|
||||
{
|
||||
wordRe name;
|
||||
scalar absTol;
|
||||
scalar relTol;
|
||||
scalar initialResidual;
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the mesh database
|
||||
fvMesh& mesh_;
|
||||
|
||||
//- List of residual data per field
|
||||
List<fieldData> residualControl_;
|
||||
|
||||
//- The dictionary name, e.g. SIMPLE, PIMPLE
|
||||
const word dictName_;
|
||||
|
||||
|
||||
// Solution controls
|
||||
|
||||
//- Maximum number of non-orthogonal correctors
|
||||
label nNonOrthCorr_;
|
||||
|
||||
//- Flag to indicate to solve for momentum
|
||||
bool momentumPredictor_;
|
||||
|
||||
//- Flag to indictae to solve using transonic algorithm
|
||||
bool transonic_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Read constrols from fvSolution dictionary
|
||||
virtual void read(const bool absTolOnly);
|
||||
|
||||
//- Return index of field in residualControl_ if present
|
||||
virtual label applyToField(const word& fieldName) const;
|
||||
|
||||
//- Return true if all convergence checks are satified
|
||||
virtual bool criteriaSatisfied() = 0;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
solutionControl(const solutionControl&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const solutionControl&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// Static Data Members
|
||||
|
||||
//- Run-time type information
|
||||
TypeName("solutionControl");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from mesh
|
||||
solutionControl(fvMesh& mesh, const word& dictName);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~solutionControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the solution dictionary
|
||||
inline const dictionary& dict() const;
|
||||
|
||||
|
||||
// Solution control
|
||||
|
||||
//- Maximum number of non-orthogonal correctors
|
||||
inline label nNonOrthCorr() const;
|
||||
|
||||
//- Flag to indicate to solve for momentum
|
||||
inline bool momentumPredictor() const;
|
||||
|
||||
//- Flag to indictae to solve using transonic algorithm
|
||||
inline bool transonic() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "solutionControlI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline const Foam::dictionary& Foam::solutionControl::dict() const
|
||||
{
|
||||
return mesh_.solutionDict().subDict(dictName_);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::solutionControl::nNonOrthCorr() const
|
||||
{
|
||||
return nNonOrthCorr_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::solutionControl::momentumPredictor() const
|
||||
{
|
||||
return momentumPredictor_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::solutionControl::transonic() const
|
||||
{
|
||||
return transonic_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
Loading…
Reference in New Issue
Block a user