Added solutionFaControl files (forgot to add it in the previous commit)

This commit is contained in:
Vanja Skuric 2018-02-11 21:20:36 +01:00
parent f569d9ffaa
commit c180b7088c
11 changed files with 1587 additions and 0 deletions

View file

@ -0,0 +1,239 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pimpleFaControl.H"
#include "Switch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pimpleFaControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::pimpleFaControl::read()
{
solutionFaControl::read(false);
// Read solution controls
const dictionary& pimpleDict = dict();
nCorrPIMPLE_ = pimpleDict.lookupOrDefault<label>("nOuterCorrectors", 1);
nCorrPISO_ = pimpleDict.lookupOrDefault<label>("nCorrectors", 1);
turbOnFinalIterOnly_ =
pimpleDict.lookupOrDefault<Switch>("turbOnFinalIterOnly", true);
}
bool Foam::pimpleFaControl::criteriaSatisfied()
{
// no checks on first iteration - nothing has been calculated yet
if ((corr_ == 1) || residualControl_.empty() || finalIter())
{
return false;
}
bool storeIni = this->storeInitialResiduals();
bool achieved = true;
bool checked = false; // safety that some checks were indeed performed
const dictionary& solverDict = mesh_.solutionDict().solverPerformanceDict();
forAllConstIter(dictionary, solverDict, iter)
{
const word& variableName = iter().keyword();
const label fieldI = applyToField(variableName);
if (fieldI != -1)
{
scalar residual = 0;
const scalar firstResidual =
maxResidual(variableName, iter().stream(), residual);
checked = true;
if (storeIni)
{
residualControl_[fieldI].initialResidual = firstResidual;
}
const bool absCheck = residual < residualControl_[fieldI].absTol;
bool relCheck = false;
scalar relative = 0.0;
if (!storeIni)
{
const scalar iniRes =
residualControl_[fieldI].initialResidual
+ ROOTVSMALL;
relative = residual/iniRes;
relCheck = relative < residualControl_[fieldI].relTol;
}
achieved = achieved && (absCheck || relCheck);
if (debug)
{
Info<< algorithmName_ << " loop:" << endl;
Info<< " " << variableName
<< " PIMPLE iter " << corr_
<< ": ini res = "
<< residualControl_[fieldI].initialResidual
<< ", abs tol = " << residual
<< " (" << residualControl_[fieldI].absTol << ")"
<< ", rel tol = " << relative
<< " (" << residualControl_[fieldI].relTol << ")"
<< endl;
}
}
}
return checked && achieved;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pimpleFaControl::pimpleFaControl(faMesh& mesh, const word& dictName)
:
solutionFaControl(mesh, dictName),
nCorrPIMPLE_(0),
nCorrPISO_(0),
corrPISO_(0),
turbOnFinalIterOnly_(true),
converged_(false)
{
read();
if (nCorrPIMPLE_ > 1)
{
Info<< nl;
if (residualControl_.empty())
{
Info<< algorithmName_ << ": no residual control data found. "
<< "Calculations will employ " << nCorrPIMPLE_
<< " corrector loops" << nl << endl;
}
else
{
Info<< algorithmName_ << ": max iterations = " << nCorrPIMPLE_
<< endl;
forAll(residualControl_, i)
{
Info<< " field " << residualControl_[i].name << token::TAB
<< ": relTol " << residualControl_[i].relTol
<< ", tolerance " << residualControl_[i].absTol
<< nl;
}
Info<< endl;
}
}
else
{
Info<< nl << algorithmName_ << ": Operating solver in PISO mode" << nl
<< endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pimpleFaControl::~pimpleFaControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::pimpleFaControl::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_.solutionDict().remove("finalIteration");
return false;
}
bool completed = false;
if (converged_ || criteriaSatisfied())
{
if (converged_)
{
Info<< algorithmName_ << ": converged in " << corr_ - 1
<< " iterations" << endl;
mesh_.solutionDict().remove("finalIteration");
corr_ = 0;
converged_ = false;
completed = true;
}
else
{
Info<< algorithmName_ << ": iteration " << corr_ << endl;
storePrevIterFields();
mesh_.solutionDict().add("finalIteration", true);
converged_ = true;
}
}
else
{
if (finalIter())
{
mesh_.solutionDict().add("finalIteration", true);
}
if (corr_ <= nCorrPIMPLE_)
{
Info<< algorithmName_ << ": iteration " << corr_ << endl;
storePrevIterFields();
completed = false;
}
}
return !completed;
}
// ************************************************************************* //

View file

@ -0,0 +1,163 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::pimpleFaControl
Description
PIMPLE control class to supply convergence information/checks for
the PIMPLE loop.
May also be used to for PISO-based algorithms as PISO controls are a
sub-set of PIMPLE controls.
\*---------------------------------------------------------------------------*/
#ifndef pimpleFaControl_H
#define pimpleFaControl_H
#include "solutionFaControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pimpleFaControl Declaration
\*---------------------------------------------------------------------------*/
class pimpleFaControl
:
public solutionFaControl
{
// Private member functions
//- Disallow default bitwise copy construct
pimpleFaControl(const pimpleFaControl&);
//- Disallow default bitwise assignment
void operator=(const pimpleFaControl&);
protected:
// Protected data
// Solution controls
//- Maximum number of PIMPLE correctors
label nCorrPIMPLE_;
//- Maximum number of PISO correctors
label nCorrPISO_;
//- Current PISO corrector
label corrPISO_;
//- Flag to indicate whether to only solve turbulence on final iter
bool turbOnFinalIterOnly_;
//- Converged flag
bool converged_;
// Protected Member Functions
//- Read controls from faSolution dictionary
virtual void read();
//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied();
public:
// Static Data Members
//- Run-time type information
TypeName("pimpleFaControl");
// Constructors
//- Construct from mesh and the name of control sub-dictionary
pimpleFaControl(faMesh& mesh, const word& dictName="PIMPLE");
//- Destructor
virtual ~pimpleFaControl();
// Member Functions
// Access
//- Maximum number of PIMPLE correctors
inline label nCorrPIMPLE() const;
//- Maximum number of PISO correctors
inline label nCorrPISO() const;
//- Current PISO corrector index
inline label corrPISO() const;
// Solution control
//- PIMPLE loop
virtual bool loop();
//- Pressure corrector loop
inline bool correct();
//- Helper function to identify when to store the intial residuals
inline bool storeInitialResiduals() const;
//- Helper function to identify first PIMPLE (outer) iteration
inline bool firstIter() const;
//- Helper function to identify final PIMPLE (outer) iteration
inline bool finalIter() const;
//- Helper function to identify final inner iteration
inline bool finalInnerIter() const;
//- Helper function to identify whether to solve for turbulence
inline bool turbCorr() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pimpleFaControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::pimpleFaControl::nCorrPIMPLE() const
{
return nCorrPIMPLE_;
}
inline Foam::label Foam::pimpleFaControl::nCorrPISO() const
{
return nCorrPISO_;
}
inline Foam::label Foam::pimpleFaControl::corrPISO() const
{
return corrPISO_;
}
inline bool Foam::pimpleFaControl::correct()
{
corrPISO_++;
if (debug)
{
Info<< algorithmName_ << " correct: corrPISO = " << corrPISO_ << endl;
}
if (corrPISO_ <= nCorrPISO_)
{
return true;
}
else
{
corrPISO_ = 0;
return false;
}
}
inline bool Foam::pimpleFaControl::storeInitialResiduals() const
{
// Start from second PIMPLE iteration
return (corr_ == 2) && (corrPISO_ == 0) && (corrNonOrtho_ == 0);
}
inline bool Foam::pimpleFaControl::firstIter() const
{
return corr_ == 1;
}
inline bool Foam::pimpleFaControl::finalIter() const
{
return converged_ || (corr_ == nCorrPIMPLE_);
}
inline bool Foam::pimpleFaControl::finalInnerIter() const
{
return
finalIter()
&& corrPISO_ == nCorrPISO_
&& corrNonOrtho_ == nNonOrthCorr_ + 1;
}
inline bool Foam::pimpleFaControl::turbCorr() const
{
return !turbOnFinalIterOnly_ || finalIter();
}
// ************************************************************************* //

View file

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pisoFaControl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pisoFaControl, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pisoFaControl::pisoFaControl(faMesh& mesh, const word& dictName)
:
pimpleFaControl(mesh, dictName)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pisoFaControl::~pisoFaControl()
{}
// ************************************************************************* //

View file

@ -0,0 +1,86 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::pisoFaControl
Description
Specialization of the pimpleFaControl class for PISO control.
\*---------------------------------------------------------------------------*/
#ifndef pisoFaControl_H
#define pisoFaControl_H
#include "pimpleFaControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pisoFaControl Declaration
\*---------------------------------------------------------------------------*/
class pisoFaControl
:
public pimpleFaControl
{
// Private member functions
//- Disallow default bitwise copy construct
pisoFaControl(const pisoFaControl&);
//- Disallow default bitwise assignment
void operator=(const pisoFaControl&);
public:
// Static Data Members
//- Run-time type information
TypeName("pisoFaControl");
// Constructors
//- Construct from mesh and the name of control sub-dictionary
pisoFaControl(faMesh& mesh, const word& dictName="PISO");
//- Destructor
virtual ~pisoFaControl();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "simpleFaControl.H"
#include "foamTime.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(simpleFaControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::simpleFaControl::read()
{
solutionFaControl::read(true);
}
bool Foam::simpleFaControl::criteriaSatisfied()
{
if (residualControl_.empty())
{
return false;
}
bool achieved = true;
bool checked = false; // safety that some checks were indeed performed
const dictionary& solverDict = mesh_.solutionDict().solverPerformanceDict();
forAllConstIter(dictionary, solverDict, iter)
{
const word& variableName = iter().keyword();
const label fieldI = applyToField(variableName);
if (fieldI != -1)
{
scalar lastResidual = 0;
const scalar residual =
maxResidual(variableName, iter().stream(), lastResidual);
checked = true;
bool absCheck = residual < residualControl_[fieldI].absTol;
achieved = achieved && absCheck;
if (debug)
{
Info<< algorithmName_ << " solution statistics:" << endl;
Info<< " " << variableName << ": tolerance = " << residual
<< " (" << residualControl_[fieldI].absTol << ")"
<< endl;
}
}
}
return checked && achieved;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::simpleFaControl::simpleFaControl(faMesh& mesh)
:
solutionFaControl(mesh, "SIMPLE"),
initialised_(false)
{
read();
Info<< nl;
if (residualControl_.empty())
{
Info<< algorithmName_ << ": no convergence criteria found. "
<< "Calculations will run for " << mesh_.time().endTime().value()
<< " steps." << nl << endl;
}
else
{
Info<< algorithmName_ << ": convergence criteria" << nl;
forAll(residualControl_, i)
{
Info<< " field " << residualControl_[i].name << token::TAB
<< " tolerance " << residualControl_[i].absTol
<< nl;
}
Info<< endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::simpleFaControl::~simpleFaControl()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::simpleFaControl::loop()
{
read();
Time& time = const_cast<Time&>(mesh_.time());
if (initialised_)
{
if (criteriaSatisfied())
{
Info<< nl << algorithmName_ << " solution converged in "
<< time.value() << " iterations" << nl << endl;
// Set to finalise calculation
time.writeAndEnd();
}
else
{
storePrevIterFields();
}
}
else
{
initialised_ = true;
storePrevIterFields();
}
return time.loop();
}
// ************************************************************************* //

View file

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::simpleFaControl
Description
SIMPLE control class to supply convergence information/checks for
the SIMPLE loop.
\*---------------------------------------------------------------------------*/
#ifndef simpleFaControl_H
#define simpleFaControl_H
#include "solutionFaControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class simpleFaControl Declaration
\*---------------------------------------------------------------------------*/
class simpleFaControl
:
public solutionFaControl
{
protected:
// Protected Data
//- Initialised flag
bool initialised_;
// Protected Member Functions
//- Read controls from faSolution dictionary
void read();
//- Return true if all convergence checks are satisfied
bool criteriaSatisfied();
//- Disallow default bitwise copy construct
simpleFaControl(const simpleFaControl&);
//- Disallow default bitwise assignment
void operator=(const simpleFaControl&);
public:
// Static Data Members
//- Run-time type information
TypeName("simpleFaControl");
// Constructors
//- Construct from mesh
simpleFaControl(faMesh& mesh);
//- Destructor
virtual ~simpleFaControl();
// Member Functions
// Solution control
//- Loop loop
virtual bool loop();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,280 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "solutionFaControl.H"
#include "fieldTypes.H"
#include "VectorNFieldTypes.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(solutionFaControl, 0);
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::solutionFaControl::read(const bool absTolOnly)
{
const dictionary& solutionDict = this->dict();
// Read solution controls
nNonOrthCorr_ =
solutionDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
momentumPredictor_ =
solutionDict.lookupOrDefault("momentumPredictor", true);
transonic_ = solutionDict.lookupOrDefault("transonic", false);
consistent_ = solutionDict.lookupOrDefault("consistent", false);
// Read residual information
const dictionary residualDict
(
solutionDict.subOrEmptyDict("residualControl")
);
DynamicList<fieldData> data(residualControl_);
forAllConstIter(dictionary, residualDict, iter)
{
const word& fName = iter().keyword();
const label fieldI = applyToField(fName, false);
if (fieldI == -1)
{
fieldData fd;
fd.name = fName.c_str();
if (absTolOnly)
{
fd.absTol = readScalar(residualDict.lookup(fName));
fd.relTol = -1;
fd.initialResidual = -1;
}
else
{
if (iter().isDict())
{
const dictionary& fieldDict(iter().dict());
fd.absTol = readScalar(fieldDict.lookup("tolerance"));
fd.relTol = readScalar(fieldDict.lookup("relTol"));
fd.initialResidual = 0.0;
}
else
{
FatalErrorIn
(
"void Foam::solutionFaControl::read"
"(const bool absTolOnly)"
) << "Residual data for " << iter().keyword()
<< " must be specified as a dictionary"
<< exit(FatalError);
}
}
data.append(fd);
}
else
{
fieldData& fd = data[fieldI];
if (absTolOnly)
{
fd.absTol = readScalar(residualDict.lookup(fName));
}
else
{
if (iter().isDict())
{
const dictionary& fieldDict(iter().dict());
fd.absTol = readScalar(fieldDict.lookup("tolerance"));
fd.relTol = readScalar(fieldDict.lookup("relTol"));
}
else
{
FatalErrorIn
(
"void Foam::solutionFaControl::read"
"(const bool absTolOnly)"
) << "Residual data for " << iter().keyword()
<< " must be specified as a dictionary"
<< exit(FatalError);
}
}
}
}
residualControl_.transfer(data);
if (debug)
{
forAll(residualControl_, i)
{
const fieldData& fd = residualControl_[i];
Info<< "residualControl[" << i << "]:" << nl
<< " name : " << fd.name << nl
<< " absTol : " << fd.absTol << nl
<< " relTol : " << fd.relTol << nl
<< " iniResid : " << fd.initialResidual << endl;
}
}
}
void Foam::solutionFaControl::read()
{
read(false);
}
Foam::label Foam::solutionFaControl::applyToField
(
const word& fieldName,
const bool useRegEx
) const
{
forAll(residualControl_, i)
{
if (useRegEx && residualControl_[i].name.match(fieldName))
{
return i;
}
else if (residualControl_[i].name == fieldName)
{
return i;
}
}
return -1;
}
void Foam::solutionFaControl::storePrevIterFields() const
{
// storePrevIter<label>();
storePrevIter<scalar>();
storePrevIter<vector>();
storePrevIter<sphericalTensor>();
storePrevIter<symmTensor>();
storePrevIter<tensor>();
storePrevIter<vector2>();
storePrevIter<vector4>();
storePrevIter<vector6>();
storePrevIter<vector8>();
storePrevIter<sphericalTensor2>();
storePrevIter<sphericalTensor4>();
storePrevIter<sphericalTensor6>();
storePrevIter<sphericalTensor8>();
storePrevIter<tensor2>();
storePrevIter<tensor4>();
storePrevIter<tensor6>();
storePrevIter<tensor8>();
}
template<class Type>
void Foam::solutionFaControl::maxTypeResidual
(
const word& fieldName,
ITstream& data,
scalar& firstRes,
scalar& lastRes
) const
{
typedef GeometricField<Type, faPatchField, areaMesh> fieldType;
if (mesh_.db().foundObject<fieldType>(fieldName))
{
const List<BlockSolverPerformance<Type> > sp(data);
firstRes = cmptMax(sp.first().initialResidual());
lastRes = cmptMax(sp.last().initialResidual());
}
}
Foam::scalar Foam::solutionFaControl::maxResidual
(
const word& fieldName,
ITstream& data,
scalar& lastRes
) const
{
scalar firstRes = 0;
maxTypeResidual<scalar>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor>(fieldName, data, firstRes, lastRes);
maxTypeResidual<symmTensor>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector2>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector4>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector6>(fieldName, data, firstRes, lastRes);
maxTypeResidual<vector8>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor2>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor4>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor6>(fieldName, data, firstRes, lastRes);
maxTypeResidual<sphericalTensor8>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor2>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor4>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor6>(fieldName, data, firstRes, lastRes);
maxTypeResidual<tensor8>(fieldName, data, firstRes, lastRes);
return firstRes;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::solutionFaControl::solutionFaControl(faMesh& mesh, const word& algorithmName)
:
IOobject
(
"solutionFaControl",
mesh.time().timeName(),
mesh.mesh()
),
mesh_(mesh),
residualControl_(),
algorithmName_(algorithmName),
nNonOrthCorr_(0),
momentumPredictor_(true),
transonic_(false),
consistent_(false),
corr_(0),
corrNonOrtho_(0)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::solutionFaControl::~solutionFaControl()
{}
// ************************************************************************* //

View file

@ -0,0 +1,235 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::solutionFaControl
Description
Base class for solution control classes
\*---------------------------------------------------------------------------*/
#ifndef solutionFaControl_H
#define solutionFaControl_H
#include "faMesh.H"
#include "edgeMesh.H"
#include "faePatchField.H"
#include "faMatrices.H"
#include "wordRe.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class solutionFaControl Declaration
\*---------------------------------------------------------------------------*/
class solutionFaControl
:
public IOobject
{
public:
struct fieldData
{
wordRe name;
scalar absTol;
scalar relTol;
scalar initialResidual;
};
protected:
// Protected data
//- Reference to the mesh database
faMesh& mesh_;
//- List of residual data per field
List<fieldData> residualControl_;
//- The dictionary name, e.g. SIMPLE, PIMPLE
const word algorithmName_;
// Solution controls
//- Maximum number of non-orthogonal correctors
label nNonOrthCorr_;
//- Flag to indicate to solve for momentum
bool momentumPredictor_;
//- Flag to indicate to solve using transonic algorithm
bool transonic_;
//- Flag to indicate to relax pressure using the
// "consistent" approach of SIMPLEC
bool consistent_;
// Eareaution
//- Current corrector loop index
label corr_;
//- Current non-orthogonal corrector loop index
label corrNonOrtho_;
// Protected Member Functions
//- Read controls from faSolution dictionary
virtual void read(const bool absTolOnly);
//- Read controls from faSolution dictionary
virtual void read();
//- Return index of field in residualControl_ if present
virtual label applyToField
(
const word& fieldName,
const bool useRegEx = true
) const;
//- Return true if all convergence checks are satisfied
virtual bool criteriaSatisfied() = 0;
//- Store previous iteration fields
virtual void storePrevIterFields() const;
//- Store previous iteration field for area<Type>Fields
template<class Type>
void storePrevIter() const;
template<class Type>
void maxTypeResidual
(
const word& fieldName,
ITstream& data,
scalar& firstRes,
scalar& lastRes
) const;
scalar maxResidual
(
const word& fieldName,
ITstream& data,
scalar& lastRes
) const;
private:
//- Disallow default bitwise copy construct
solutionFaControl(const solutionFaControl&);
//- Disallow default bitwise assignment
void operator=(const solutionFaControl&);
public:
// Static Data Members
//- Run-time type information
TypeName("solutionFaControl");
// Constructors
//- Construct from mesh
solutionFaControl(faMesh& mesh, const word& algorithmName);
//- Destructor
virtual ~solutionFaControl();
// Member Functions
// Access
//- Return the solution dictionary
inline const dictionary& dict() const;
//- Current corrector loop index
inline label corr() const;
//- Current non-orthogonal corrector index
inline label corrNonOrtho() const;
// Solution control
//- Maximum number of non-orthogonal correctors
inline label nNonOrthCorr() const;
//- Helper function to identify final non-orthogonal iteration
inline bool finalNonOrthogonalIter() const;
//- Flag to indicate to solve for momentum
inline bool momentumPredictor() const;
//- Flag to indicate to solve using transonic algorithm
inline bool transonic() const;
//- Flag to indicate to relax pressure using the
// "consistent" approach of SIMPLEC
inline bool consistent() const;
// Eareaution
//- Main control loop
virtual bool loop() = 0;
//- Non-orthogonal corrector loop
inline bool correctNonOrthogonal();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "solutionFaControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "solutionFaControlTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::dictionary& Foam::solutionFaControl::dict() const
{
return mesh_.solutionDict().subDict(algorithmName_);
}
inline Foam::label Foam::solutionFaControl::corr() const
{
return corr_;
}
inline Foam::label Foam::solutionFaControl::corrNonOrtho() const
{
return corrNonOrtho_;
}
inline Foam::label Foam::solutionFaControl::nNonOrthCorr() const
{
return nNonOrthCorr_;
}
inline bool Foam::solutionFaControl::finalNonOrthogonalIter() const
{
return corrNonOrtho_ == nNonOrthCorr_ + 1;
}
inline bool Foam::solutionFaControl::momentumPredictor() const
{
return momentumPredictor_;
}
inline bool Foam::solutionFaControl::transonic() const
{
return transonic_;
}
inline bool Foam::solutionFaControl::consistent() const
{
return consistent_;
}
inline bool Foam::solutionFaControl::correctNonOrthogonal()
{
corrNonOrtho_++;
if (debug)
{
Info<< algorithmName_ << " correctNonOrthogonal: corrNonOrtho = "
<< corrNonOrtho_ << endl;
}
if (corrNonOrtho_ <= nNonOrthCorr_ + 1)
{
return true;
}
else
{
corrNonOrtho_ = 0;
return false;
}
}
// ************************************************************************* //

View file

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "GeometricField.H"
#include "areaMesh.H"
#include "faPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::solutionFaControl::storePrevIter() const
{
typedef GeometricField<Type, faPatchField, areaMesh> GeoField;
HashTable<const GeoField*>
flds(mesh_.db().objectRegistry::lookupClass<GeoField>());
forAllIter(typename HashTable<const GeoField*>, flds, iter)
{
const GeoField& fld = *iter();
const word& fName = fld.name();
size_t prevIterField = fName.find("PrevIter");
if
(
(prevIterField == word::npos)
&& mesh_.solutionDict().relaxField(fName)
)
{
if (debug)
{
Info<< algorithmName_ << ": storing previous iter for "
<< fName << endl;
}
fld.storePrevIter();
}
}
}
// ************************************************************************* //