mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: storePrevIter now handled by solutionControl class
This commit is contained in:
@ -26,7 +26,7 @@ if (simple.transonic())
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Relax the pressure equation to ensure diagonal-dominance
|
// Relax the pressure equation to ensure diagonal-dominance
|
||||||
pEqn.relax(mesh.relaxationFactor("pEqn"));
|
pEqn.relax(mesh.equationRelaxationFactor("pEqn"));
|
||||||
|
|
||||||
pEqn.setReference(pRefCell, pRefValue);
|
pEqn.setReference(pRefCell, pRefValue);
|
||||||
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ int main(int argc, char *argv[])
|
|||||||
// mesh.relaxationFactor("alpha")
|
// mesh.relaxationFactor("alpha")
|
||||||
// *(lambda*max(Ua & U, zeroSensitivity) - alpha);
|
// *(lambda*max(Ua & U, zeroSensitivity) - alpha);
|
||||||
alpha +=
|
alpha +=
|
||||||
mesh.relaxationFactor("alpha")
|
mesh.fieldRelaxationFactor("alpha")
|
||||||
*(min(max(alpha + lambda*(Ua & U), zeroAlpha), alphaMax) - alpha);
|
*(min(max(alpha + lambda*(Ua & U), zeroAlpha), alphaMax) - alpha);
|
||||||
|
|
||||||
zeroCells(alpha, inletCells);
|
zeroCells(alpha, inletCells);
|
||||||
|
|||||||
@ -919,9 +919,9 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::relax()
|
|||||||
name += "Final";
|
name += "Final";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->mesh().relax(name))
|
if (this->mesh().relaxField(name))
|
||||||
{
|
{
|
||||||
relax(this->mesh().relaxationFactor(name));
|
relax(this->mesh().fieldRelaxationFactor(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,10 +56,52 @@ void Foam::solution::read(const dictionary& dict)
|
|||||||
|
|
||||||
if (dict.found("relaxationFactors"))
|
if (dict.found("relaxationFactors"))
|
||||||
{
|
{
|
||||||
relaxationFactors_ = dict.subDict("relaxationFactors");
|
const dictionary& relaxDict(dict.subDict("relaxationFactors"));
|
||||||
|
if (relaxDict.found("variables"))
|
||||||
|
{
|
||||||
|
fieldRelaxDict_ = relaxDict.subDict("variables");
|
||||||
|
eqnRelaxDict_ = relaxDict.subDict("equations");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// backwards compatibility
|
||||||
|
const wordList entryNames(relaxDict.toc());
|
||||||
|
forAll(entryNames, i)
|
||||||
|
{
|
||||||
|
const word& e = entryNames[i];
|
||||||
|
scalar value = readScalar(relaxDict.lookup(e));
|
||||||
|
|
||||||
|
if (e(0, 1) == "p")
|
||||||
|
{
|
||||||
|
fieldRelaxDict_.add(e, value);
|
||||||
|
}
|
||||||
|
else if (e.length() >= 3)
|
||||||
|
{
|
||||||
|
if (e(0, 3) == "rho")
|
||||||
|
{
|
||||||
|
fieldRelaxDict_.add(e, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
eqnRelaxDict_ = relaxDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldRelaxDefault_ =
|
||||||
|
fieldRelaxDict_.lookupOrDefault<scalar>("default", 0.0);
|
||||||
|
|
||||||
|
eqnRelaxDefault_ =
|
||||||
|
eqnRelaxDict_.lookupOrDefault<scalar>("default", 0.0);
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "relaxation factors:" << nl
|
||||||
|
<< "fields: " << fieldRelaxDict_ << nl
|
||||||
|
<< "equations: " << eqnRelaxDict_ << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
relaxationFactors_.readIfPresent("default", defaultRelaxationFactor_);
|
|
||||||
|
|
||||||
if (dict.found("solvers"))
|
if (dict.found("solvers"))
|
||||||
{
|
{
|
||||||
@ -92,11 +134,13 @@ Foam::solution::solution
|
|||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
cache_(ITstream("cache", tokenList())()),
|
cache_(dictionary::null),
|
||||||
caching_(false),
|
caching_(false),
|
||||||
relaxationFactors_(ITstream("relaxationFactors", tokenList())()),
|
fieldRelaxDict_(dictionary::null),
|
||||||
defaultRelaxationFactor_(0),
|
eqnRelaxDict_(dictionary::null),
|
||||||
solvers_(ITstream("solvers", tokenList())())
|
fieldRelaxDefault_(0),
|
||||||
|
eqnRelaxDefault_(0),
|
||||||
|
solvers_(dictionary::null)
|
||||||
{
|
{
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
@ -207,41 +251,80 @@ bool Foam::solution::cache(const word& name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::solution::relax(const word& name) const
|
bool Foam::solution::relaxField(const word& name) const
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "Find relax for " << name << endl;
|
Info<< "Find variable relaxation factor for " << name << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return fieldRelaxDict_.found(name) || fieldRelaxDict_.found("default");
|
||||||
relaxationFactors_.found(name)
|
|
||||||
|| relaxationFactors_.found("default");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::scalar Foam::solution::relaxationFactor(const word& name) const
|
bool Foam::solution::relaxEquation(const word& name) const
|
||||||
{
|
{
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Info<< "Lookup relaxationFactor for " << name << endl;
|
Info<< "Find equation relaxation factor for " << name << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relaxationFactors_.found(name))
|
return eqnRelaxDict_.found(name) || eqnRelaxDict_.found("default");
|
||||||
{
|
|
||||||
return readScalar(relaxationFactors_.lookup(name));
|
|
||||||
}
|
}
|
||||||
else if (defaultRelaxationFactor_ > SMALL)
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::solution::fieldRelaxationFactor(const word& name) const
|
||||||
{
|
{
|
||||||
return defaultRelaxationFactor_;
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "Lookup variable relaxation factor for " << name << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldRelaxDict_.found(name))
|
||||||
|
{
|
||||||
|
return readScalar(fieldRelaxDict_.lookup(name));
|
||||||
|
}
|
||||||
|
else if (fieldRelaxDefault_ > SMALL)
|
||||||
|
{
|
||||||
|
return fieldRelaxDefault_;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalIOErrorIn
|
FatalIOErrorIn
|
||||||
(
|
(
|
||||||
"Foam::solution::relaxationFactor(const word&)",
|
"Foam::solution::fieldRelaxationFactor(const word&)",
|
||||||
relaxationFactors_
|
fieldRelaxDict_
|
||||||
) << "Cannot find relaxationFactor for '" << name
|
) << "Cannot find variable relaxation factor for '" << name
|
||||||
|
<< "' or a suitable default value."
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::scalar Foam::solution::equationRelaxationFactor(const word& name) const
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< "Lookup equation relaxation factor for " << name << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eqnRelaxDict_.found(name))
|
||||||
|
{
|
||||||
|
return readScalar(eqnRelaxDict_.lookup(name));
|
||||||
|
}
|
||||||
|
else if (eqnRelaxDefault_ > SMALL)
|
||||||
|
{
|
||||||
|
return eqnRelaxDefault_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalIOErrorIn
|
||||||
|
(
|
||||||
|
"Foam::solution::eqnRelaxationFactor(const word&)",
|
||||||
|
eqnRelaxDict_
|
||||||
|
) << "Cannot find equation relaxation factor for '" << name
|
||||||
<< "' or a suitable default value."
|
<< "' or a suitable default value."
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
|
|||||||
@ -59,10 +59,16 @@ class solution
|
|||||||
bool caching_;
|
bool caching_;
|
||||||
|
|
||||||
//- Dictionary of relaxation factors for all the fields
|
//- Dictionary of relaxation factors for all the fields
|
||||||
dictionary relaxationFactors_;
|
dictionary fieldRelaxDict_;
|
||||||
|
|
||||||
|
//- Dictionary of relaxation factors for all the equations
|
||||||
|
dictionary eqnRelaxDict_;
|
||||||
|
|
||||||
//- Optional default relaxation factor for all the fields
|
//- Optional default relaxation factor for all the fields
|
||||||
scalar defaultRelaxationFactor_;
|
scalar fieldRelaxDefault_;
|
||||||
|
|
||||||
|
//- Optional default relaxation factor for all the equations
|
||||||
|
scalar eqnRelaxDefault_;
|
||||||
|
|
||||||
//- Dictionary of solver parameters for all the fields
|
//- Dictionary of solver parameters for all the fields
|
||||||
dictionary solvers_;
|
dictionary solvers_;
|
||||||
@ -107,10 +113,16 @@ public:
|
|||||||
bool cache(const word& name) const;
|
bool cache(const word& name) const;
|
||||||
|
|
||||||
//- Return true if the relaxation factor is given for the field
|
//- Return true if the relaxation factor is given for the field
|
||||||
bool relax(const word& name) const;
|
bool relaxField(const word& name) const;
|
||||||
|
|
||||||
|
//- Return true if the relaxation factor is given for the equation
|
||||||
|
bool relaxEquation(const word& name) const;
|
||||||
|
|
||||||
//- Return the relaxation factor for the given field
|
//- Return the relaxation factor for the given field
|
||||||
scalar relaxationFactor(const word& name) const;
|
scalar fieldRelaxationFactor(const word& name) const;
|
||||||
|
|
||||||
|
//- Return the relaxation factor for the given eqation
|
||||||
|
scalar equationRelaxationFactor(const word& name) const;
|
||||||
|
|
||||||
//- Return the selected sub-dictionary of solvers if the "select"
|
//- Return the selected sub-dictionary of solvers if the "select"
|
||||||
// keyword is given, otherwise return the complete dictionary
|
// keyword is given, otherwise return the complete dictionary
|
||||||
@ -122,6 +134,7 @@ public:
|
|||||||
//- Return the solver controls dictionary for the given field
|
//- Return the solver controls dictionary for the given field
|
||||||
const dictionary& solver(const word& name) const;
|
const dictionary& solver(const word& name) const;
|
||||||
|
|
||||||
|
|
||||||
// Read
|
// Read
|
||||||
|
|
||||||
//- Read the solution dictionary
|
//- Read the solution dictionary
|
||||||
|
|||||||
@ -75,6 +75,11 @@ inline bool Foam::pimpleControl::loop()
|
|||||||
Info<< algorithmName_ << ": iteration " << corr_ + 1 << endl;
|
Info<< algorithmName_ << ": iteration " << corr_ + 1 << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (corr_ != 0)
|
||||||
|
{
|
||||||
|
storePrevIterFields();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -43,12 +43,18 @@ inline bool Foam::simpleControl::loop()
|
|||||||
// Set to finalise calculation
|
// Set to finalise calculation
|
||||||
time.writeAndEnd();
|
time.writeAndEnd();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
storePrevIterFields();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
initialised_ = true;
|
initialised_ = true;
|
||||||
|
storePrevIterFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return time.loop();
|
return time.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -102,6 +102,17 @@ Foam::label Foam::solutionControl::applyToField(const word& fieldName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::solutionControl::storePrevIterFields() const
|
||||||
|
{
|
||||||
|
// storePrevIter<label>();
|
||||||
|
storePrevIter<scalar>();
|
||||||
|
storePrevIter<vector>();
|
||||||
|
storePrevIter<sphericalTensor>();
|
||||||
|
storePrevIter<symmTensor>();
|
||||||
|
storePrevIter<tensor>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
|
Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)
|
||||||
|
|||||||
@ -93,6 +93,13 @@ protected:
|
|||||||
//- Return true if all convergence checks are satified
|
//- Return true if all convergence checks are satified
|
||||||
virtual bool criteriaSatisfied() = 0;
|
virtual bool criteriaSatisfied() = 0;
|
||||||
|
|
||||||
|
//- Store previous iteration fields
|
||||||
|
virtual void storePrevIterFields() const;
|
||||||
|
|
||||||
|
//- Store previous iteration field for vol<Type>Fields
|
||||||
|
template<class Type>
|
||||||
|
void storePrevIter() const;
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
solutionControl(const solutionControl&);
|
solutionControl(const solutionControl&);
|
||||||
|
|
||||||
@ -146,6 +153,12 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
#include "solutionControlTemplates.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "solutionControlI.H"
|
#include "solutionControlI.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -0,0 +1,58 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
|
\\/ 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 "GeometricField.H"
|
||||||
|
#include "volMesh.H"
|
||||||
|
#include "fvPatchField.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Foam::solutionControl::storePrevIter() const
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> GeoField;
|
||||||
|
|
||||||
|
HashTable<const GeoField*>
|
||||||
|
flds(mesh_.objectRegistry::lookupClass<GeoField>());
|
||||||
|
|
||||||
|
forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
|
||||||
|
{
|
||||||
|
GeoField& fld = const_cast<GeoField&>(*iter());
|
||||||
|
|
||||||
|
if (mesh_.relaxField(fld.name()))
|
||||||
|
{
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
Info<< algorithmName_ << ": storing previous iter for "
|
||||||
|
<< fld.name() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
fld.storePrevIter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -627,9 +627,9 @@ void Foam::fvMatrix<Type>::relax()
|
|||||||
("finalIteration", false)
|
("finalIteration", false)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (psi_.mesh().relax(name))
|
if (psi_.mesh().relaxEquation(name))
|
||||||
{
|
{
|
||||||
relax(psi_.mesh().relaxationFactor(name));
|
relax(psi_.mesh().equationRelaxationFactor(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user