ENH: storePrevIter now handled by solutionControl class

This commit is contained in:
andy
2011-09-08 11:42:05 +01:00
parent 22fea113e4
commit bc952e63de
11 changed files with 219 additions and 30 deletions

View File

@ -26,7 +26,7 @@ if (simple.transonic())
);
// Relax the pressure equation to ensure diagonal-dominance
pEqn.relax(mesh.relaxationFactor("pEqn"));
pEqn.relax(mesh.equationRelaxationFactor("pEqn"));
pEqn.setReference(pRefCell, pRefValue);

View File

@ -93,7 +93,7 @@ int main(int argc, char *argv[])
// mesh.relaxationFactor("alpha")
// *(lambda*max(Ua & U, zeroSensitivity) - alpha);
alpha +=
mesh.relaxationFactor("alpha")
mesh.fieldRelaxationFactor("alpha")
*(min(max(alpha + lambda*(Ua & U), zeroAlpha), alphaMax) - alpha);
zeroCells(alpha, inletCells);

View File

@ -919,9 +919,9 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::relax()
name += "Final";
}
if (this->mesh().relax(name))
if (this->mesh().relaxField(name))
{
relax(this->mesh().relaxationFactor(name));
relax(this->mesh().fieldRelaxationFactor(name));
}
}

View File

@ -56,10 +56,52 @@ void Foam::solution::read(const dictionary& dict)
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"))
{
@ -92,11 +134,13 @@ Foam::solution::solution
IOobject::NO_WRITE
)
),
cache_(ITstream("cache", tokenList())()),
cache_(dictionary::null),
caching_(false),
relaxationFactors_(ITstream("relaxationFactors", tokenList())()),
defaultRelaxationFactor_(0),
solvers_(ITstream("solvers", tokenList())())
fieldRelaxDict_(dictionary::null),
eqnRelaxDict_(dictionary::null),
fieldRelaxDefault_(0),
eqnRelaxDefault_(0),
solvers_(dictionary::null)
{
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)
{
Info<< "Find relax for " << name << endl;
Info<< "Find variable relaxation factor for " << name << endl;
}
return
relaxationFactors_.found(name)
|| relaxationFactors_.found("default");
return fieldRelaxDict_.found(name) || fieldRelaxDict_.found("default");
}
Foam::scalar Foam::solution::relaxationFactor(const word& name) const
bool Foam::solution::relaxEquation(const word& name) const
{
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");
}
Foam::scalar Foam::solution::fieldRelaxationFactor(const word& name) const
{
if (debug)
{
return readScalar(relaxationFactors_.lookup(name));
Info<< "Lookup variable relaxation factor for " << name << endl;
}
else if (defaultRelaxationFactor_ > SMALL)
if (fieldRelaxDict_.found(name))
{
return defaultRelaxationFactor_;
return readScalar(fieldRelaxDict_.lookup(name));
}
else if (fieldRelaxDefault_ > SMALL)
{
return fieldRelaxDefault_;
}
else
{
FatalIOErrorIn
(
"Foam::solution::relaxationFactor(const word&)",
relaxationFactors_
) << "Cannot find relaxationFactor for '" << name
"Foam::solution::fieldRelaxationFactor(const word&)",
fieldRelaxDict_
) << "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."
<< exit(FatalIOError);

View File

@ -59,10 +59,16 @@ class solution
bool caching_;
//- 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
scalar defaultRelaxationFactor_;
scalar fieldRelaxDefault_;
//- Optional default relaxation factor for all the equations
scalar eqnRelaxDefault_;
//- Dictionary of solver parameters for all the fields
dictionary solvers_;
@ -107,10 +113,16 @@ public:
bool cache(const word& name) const;
//- 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
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"
// keyword is given, otherwise return the complete dictionary
@ -122,6 +134,7 @@ public:
//- Return the solver controls dictionary for the given field
const dictionary& solver(const word& name) const;
// Read
//- Read the solution dictionary

View File

@ -75,6 +75,11 @@ inline bool Foam::pimpleControl::loop()
Info<< algorithmName_ << ": iteration " << corr_ + 1 << endl;
}
if (corr_ != 0)
{
storePrevIterFields();
}
return true;
}
else

View File

@ -43,12 +43,18 @@ inline bool Foam::simpleControl::loop()
// Set to finalise calculation
time.writeAndEnd();
}
else
{
storePrevIterFields();
}
}
else
{
initialised_ = true;
storePrevIterFields();
}
return time.loop();
}

View File

@ -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 * * * * * * * * * * * * * * //
Foam::solutionControl::solutionControl(fvMesh& mesh, const word& algorithmName)

View File

@ -93,6 +93,13 @@ protected:
//- Return true if all convergence checks are satified
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
solutionControl(const solutionControl&);
@ -146,6 +153,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "solutionControlTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "solutionControlI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

@ -627,9 +627,9 @@ void Foam::fvMatrix<Type>::relax()
("finalIteration", false)
);
if (psi_.mesh().relax(name))
if (psi_.mesh().relaxEquation(name))
{
relax(psi_.mesh().relaxationFactor(name));
relax(psi_.mesh().equationRelaxationFactor(name));
}
}