fvOption: Rationalize corrections

This commit is contained in:
Henry
2015-06-01 11:18:45 +01:00
parent bbbad9cfc0
commit 257d71ebf1
10 changed files with 139 additions and 156 deletions

View File

@ -55,7 +55,11 @@ $(generalConstraints)/explicitSetValue/explicitSetValue.C
derivedConstraints=constraints/derived derivedConstraints=constraints/derived
$(derivedConstraints)/fixedTemperatureConstraint/fixedTemperatureConstraint.C $(derivedConstraints)/fixedTemperatureConstraint/fixedTemperatureConstraint.C
$(derivedConstraints)/temperatureLimitsConstraint/temperatureLimitsConstraint.C
/* Corrections */
corrections/limitTemperature/limitTemperature.C
LIB = $(FOAM_LIBBIN)/libfvOptions LIB = $(FOAM_LIBBIN)/libfvOptions

View File

@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "temperatureLimitsConstraint.H" #include "limitTemperature.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "basicThermo.H" #include "basicThermo.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -34,11 +34,11 @@ namespace Foam
{ {
namespace fv namespace fv
{ {
defineTypeNameAndDebug(temperatureLimitsConstraint, 0); defineTypeNameAndDebug(limitTemperature, 0);
addToRunTimeSelectionTable addToRunTimeSelectionTable
( (
option, option,
temperatureLimitsConstraint, limitTemperature,
dictionary dictionary
); );
} }
@ -46,7 +46,7 @@ namespace fv
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::temperatureLimitsConstraint::temperatureLimitsConstraint Foam::fv::limitTemperature::limitTemperature
( (
const word& name, const word& name,
const word& modelType, const word& modelType,
@ -65,13 +65,13 @@ Foam::fv::temperatureLimitsConstraint::temperatureLimitsConstraint
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::temperatureLimitsConstraint::alwaysApply() const bool Foam::fv::limitTemperature::alwaysApply() const
{ {
return true; return true;
} }
void Foam::fv::temperatureLimitsConstraint::correct(volScalarField& he) void Foam::fv::limitTemperature::correct(volScalarField& he)
{ {
const basicThermo& thermo = const basicThermo& thermo =
mesh_.lookupObject<basicThermo>("thermophysicalProperties"); mesh_.lookupObject<basicThermo>("thermophysicalProperties");
@ -125,7 +125,7 @@ void Foam::fv::temperatureLimitsConstraint::correct(volScalarField& he)
} }
bool Foam::fv::temperatureLimitsConstraint::read(const dictionary& dict) bool Foam::fv::limitTemperature::read(const dictionary& dict)
{ {
if (cellSetOption::read(dict)) if (cellSetOption::read(dict))
{ {

View File

@ -22,27 +22,27 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::fv::temperatureLimitsConstraint Foam::fv::limitTemperature
Description Description
Constraint for temperature to apply limits between minimum and maximum Correction for temperature to apply limits between minimum and maximum
values values
Constraint described by: Constraint described by:
temperatureLimitsConstraintCoeffs limitTemperatureCoeffs
{ {
minimum 200; minimum 200;
maximum 500; maximum 500;
} }
SourceFiles SourceFiles
temperatureLimitsConstraint.C limitTemperature.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef temperatureLimitsConstraint_H #ifndef limitTemperature_H
#define temperatureLimitsConstraint_H #define limitTemperature_H
#include "cellSetOption.H" #include "cellSetOption.H"
@ -54,10 +54,10 @@ namespace fv
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class temperatureLimitsConstraint Declaration Class limitTemperature Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class temperatureLimitsConstraint class limitTemperature
: :
public cellSetOption public cellSetOption
{ {
@ -78,22 +78,22 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
temperatureLimitsConstraint(const temperatureLimitsConstraint&); limitTemperature(const limitTemperature&);
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const temperatureLimitsConstraint&); void operator=(const limitTemperature&);
public: public:
//- Runtime type information //- Runtime type information
TypeName("temperatureLimitsConstraint"); TypeName("limitTemperature");
// Constructors // Constructors
//- Construct from components //- Construct from components
temperatureLimitsConstraint limitTemperature
( (
const word& name, const word& name,
const word& modelType, const word& modelType,
@ -103,7 +103,7 @@ public:
//- Destructor //- Destructor
virtual ~temperatureLimitsConstraint() virtual ~limitTemperature()
{} {}

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvOption.H" #include "fvOption.H"
#include "fvMatrices.H" #include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -65,8 +65,7 @@ Foam::fv::option::option
fieldNames_(), fieldNames_(),
applied_() applied_()
{ {
Info<< incrIndent << indent << "Source: " << name_ << endl; Info<< incrIndent << indent << "Source: " << name_ << endl << decrIndent;
Info<< decrIndent;
} }
@ -139,26 +138,6 @@ void Foam::fv::option::checkApplied() const
} }
void Foam::fv::option::correct(volScalarField& fld)
{}
void Foam::fv::option::correct(volVectorField& fld)
{}
void Foam::fv::option::correct(volSphericalTensorField& fld)
{}
void Foam::fv::option::correct(volSymmTensorField& fld)
{}
void Foam::fv::option::correct(volTensorField& fld)
{}
void Foam::fv::option::addSup void Foam::fv::option::addSup
( (
fvMatrix<scalar>& eqn, fvMatrix<scalar>& eqn,
@ -332,4 +311,24 @@ void Foam::fv::option::constrain(fvMatrix<tensor>& eqn, const label fieldI)
{} {}
void Foam::fv::option::correct(volScalarField& field)
{}
void Foam::fv::option::correct(volVectorField& field)
{}
void Foam::fv::option::correct(volSphericalTensorField& field)
{}
void Foam::fv::option::correct(volSymmTensorField& field)
{}
void Foam::fv::option::correct(volTensorField& field)
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -230,55 +230,32 @@ public:
// Evaluation // Evaluation
// Correct // Explicit and implicit sources
//- Scalar
virtual void correct(volScalarField& fld);
//- Vector
virtual void correct(volVectorField& fld);
//- Spherical tensor
virtual void correct(volSphericalTensorField& fld);
//- Symmetric tensor
virtual void correct(volSymmTensorField& fld);
//- Tensor
virtual void correct(volTensorField& fld);
// Add explicit and implicit contributions
//- Scalar
virtual void addSup virtual void addSup
( (
fvMatrix<scalar>& eqn, fvMatrix<scalar>& eqn,
const label fieldI const label fieldI
); );
//- Vector
virtual void addSup virtual void addSup
( (
fvMatrix<vector>& eqn, fvMatrix<vector>& eqn,
const label fieldI const label fieldI
); );
//- Spherical tensor
virtual void addSup virtual void addSup
( (
fvMatrix<symmTensor>& eqn, fvMatrix<symmTensor>& eqn,
const label fieldI const label fieldI
); );
//- Symmetric tensor
virtual void addSup virtual void addSup
( (
fvMatrix<sphericalTensor>& eqn, fvMatrix<sphericalTensor>& eqn,
const label fieldI const label fieldI
); );
//- Tensor
virtual void addSup virtual void addSup
( (
fvMatrix<tensor>& eqn, fvMatrix<tensor>& eqn,
@ -286,9 +263,8 @@ public:
); );
// Add explicit and implicit contributions to compressible equations // Explicit and implicit sources for compressible equations
//- Scalar
virtual void addSup virtual void addSup
( (
const volScalarField& rho, const volScalarField& rho,
@ -296,7 +272,6 @@ public:
const label fieldI const label fieldI
); );
//- Vector
virtual void addSup virtual void addSup
( (
const volScalarField& rho, const volScalarField& rho,
@ -304,7 +279,6 @@ public:
const label fieldI const label fieldI
); );
//- Spherical tensor
virtual void addSup virtual void addSup
( (
const volScalarField& rho, const volScalarField& rho,
@ -312,7 +286,6 @@ public:
const label fieldI const label fieldI
); );
//- Symmetric tensor
virtual void addSup virtual void addSup
( (
const volScalarField& rho, const volScalarField& rho,
@ -320,7 +293,6 @@ public:
const label fieldI const label fieldI
); );
//- Tensor
virtual void addSup virtual void addSup
( (
const volScalarField& rho, const volScalarField& rho,
@ -329,9 +301,8 @@ public:
); );
// Add explicit and implicit contributions to phase equations // Explicit and implicit sources for phase equations
//- Scalar
virtual void addSup virtual void addSup
( (
const volScalarField& alpha, const volScalarField& alpha,
@ -340,7 +311,6 @@ public:
const label fieldI const label fieldI
); );
//- Vector
virtual void addSup virtual void addSup
( (
const volScalarField& alpha, const volScalarField& alpha,
@ -349,7 +319,6 @@ public:
const label fieldI const label fieldI
); );
//- Spherical tensor
virtual void addSup virtual void addSup
( (
const volScalarField& alpha, const volScalarField& alpha,
@ -358,7 +327,6 @@ public:
const label fieldI const label fieldI
); );
//- Symmetric tensor
virtual void addSup virtual void addSup
( (
const volScalarField& alpha, const volScalarField& alpha,
@ -367,7 +335,6 @@ public:
const label fieldI const label fieldI
); );
//- Tensor
virtual void addSup virtual void addSup
( (
const volScalarField& alpha, const volScalarField& alpha,
@ -379,35 +346,30 @@ public:
// Constraints // Constraints
//- Scalar
virtual void constrain virtual void constrain
( (
fvMatrix<scalar>& eqn, fvMatrix<scalar>& eqn,
const label fieldI const label fieldI
); );
//- Vector
virtual void constrain virtual void constrain
( (
fvMatrix<vector>& eqn, fvMatrix<vector>& eqn,
const label fieldI const label fieldI
); );
//- Spherical tensor
virtual void constrain virtual void constrain
( (
fvMatrix<sphericalTensor>& eqn, fvMatrix<sphericalTensor>& eqn,
const label fieldI const label fieldI
); );
//- Symmetric tensor
virtual void constrain virtual void constrain
( (
fvMatrix<symmTensor>& eqn, fvMatrix<symmTensor>& eqn,
const label fieldI const label fieldI
); );
//- Tensor
virtual void constrain virtual void constrain
( (
fvMatrix<tensor>& eqn, fvMatrix<tensor>& eqn,
@ -415,6 +377,15 @@ public:
); );
// Correction
virtual void correct(volScalarField& field);
virtual void correct(volVectorField& field);
virtual void correct(volSphericalTensorField& field);
virtual void correct(volSymmTensorField& field);
virtual void correct(volTensorField& field);
// IO // IO
//- Write the source header information //- Write the source header information

View File

@ -32,13 +32,13 @@ SourceFile
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef optionList_H #ifndef fvOptionList_H
#define optionList_H #define fvOptionList_H
#include "fvOption.H"
#include "PtrList.H" #include "PtrList.H"
#include "GeometricField.H" #include "GeometricField.H"
#include "fvPatchField.H" #include "fvPatchField.H"
#include "fvOption.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -119,10 +119,6 @@ public:
//- Reset the source list //- Reset the source list
void reset(const dictionary& dict); void reset(const dictionary& dict);
//- Correct
template<class Type>
void correct(GeometricField<Type, fvPatchField, volMesh>& fld);
// Sources // Sources
@ -130,14 +126,14 @@ public:
template<class Type> template<class Type>
tmp<fvMatrix<Type> > operator() tmp<fvMatrix<Type> > operator()
( (
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
); );
//- Return source for equation with specified name //- Return source for equation with specified name
template<class Type> template<class Type>
tmp<fvMatrix<Type> > operator() tmp<fvMatrix<Type> > operator()
( (
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& field,
const word& fieldName const word& fieldName
); );
@ -146,7 +142,7 @@ public:
tmp<fvMatrix<Type> > operator() tmp<fvMatrix<Type> > operator()
( (
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
); );
//- Return source for equation with specified name //- Return source for equation with specified name
@ -154,7 +150,7 @@ public:
tmp<fvMatrix<Type> > operator() tmp<fvMatrix<Type> > operator()
( (
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& field,
const word& fieldName const word& fieldName
); );
@ -164,7 +160,7 @@ public:
( (
const volScalarField& alpha, const volScalarField& alpha,
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
); );
//- Return source for equation with specified name //- Return source for equation with specified name
@ -173,7 +169,7 @@ public:
( (
const volScalarField& alpha, const volScalarField& alpha,
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& field,
const word& fieldName const word& fieldName
); );
@ -185,6 +181,13 @@ public:
void constrain(fvMatrix<Type>& eqn); void constrain(fvMatrix<Type>& eqn);
// Correction
//- Apply correction to field
template<class Type>
void correct(GeometricField<Type, fvPatchField, volMesh>& field);
// IO // IO
//- Read dictionary //- Read dictionary

View File

@ -26,60 +26,27 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::fv::optionList::correct Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
) )
{ {
const word& fieldName = fld.name(); return this->operator()(field, field.name());
forAll(*this, i)
{
option& source = this->operator[](i);
label fieldI = source.applyToField(fieldName);
if (fieldI != -1)
{
source.setApplied(fieldI);
if (source.isActive())
{
if (debug)
{
Info<< "Correcting source " << source.name()
<< " for field " << fieldName << endl;
}
source.correct(fld);
}
}
}
} }
template<class Type> template<class Type>
Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator() Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field,
)
{
return this->operator()(fld, fld.name());
}
template<class Type>
Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
(
GeometricField<Type, fvPatchField, volMesh>& fld,
const word& fieldName const word& fieldName
) )
{ {
checkApplied(); checkApplied();
const dimensionSet ds = fld.dimensions()/dimTime*dimVolume; const dimensionSet ds = field.dimensions()/dimTime*dimVolume;
tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(fld, ds)); tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
fvMatrix<Type>& mtx = tmtx(); fvMatrix<Type>& mtx = tmtx();
forAll(*this, i) forAll(*this, i)
@ -113,10 +80,10 @@ template<class Type>
Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator() Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
) )
{ {
return this->operator()(rho, fld, fld.name()); return this->operator()(rho, field, field.name());
} }
@ -124,15 +91,18 @@ template<class Type>
Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator() Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& field,
const word& fieldName const word& fieldName
) )
{ {
checkApplied(); checkApplied();
const dimensionSet ds = rho.dimensions()*fld.dimensions()/dimTime*dimVolume; const dimensionSet ds
(
rho.dimensions()*field.dimensions()/dimTime*dimVolume
);
tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(fld, ds)); tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
fvMatrix<Type>& mtx = tmtx(); fvMatrix<Type>& mtx = tmtx();
forAll(*this, i) forAll(*this, i)
@ -167,10 +137,10 @@ Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
const volScalarField& alpha, const volScalarField& alpha,
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
) )
{ {
return this->operator()(alpha, rho, fld, fld.name()); return this->operator()(alpha, rho, field, field.name());
} }
@ -179,16 +149,19 @@ Foam::tmp<Foam::fvMatrix<Type> > Foam::fv::optionList::operator()
( (
const volScalarField& alpha, const volScalarField& alpha,
const volScalarField& rho, const volScalarField& rho,
GeometricField<Type, fvPatchField, volMesh>& fld, GeometricField<Type, fvPatchField, volMesh>& field,
const word& fieldName const word& fieldName
) )
{ {
checkApplied(); checkApplied();
const dimensionSet ds = const dimensionSet ds
alpha.dimensions()*rho.dimensions()*fld.dimensions()/dimTime*dimVolume; (
alpha.dimensions()*rho.dimensions()*field.dimensions()
/dimTime*dimVolume
);
tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(fld, ds)); tmp<fvMatrix<Type> > tmtx(new fvMatrix<Type>(field, ds));
fvMatrix<Type>& mtx = tmtx(); fvMatrix<Type>& mtx = tmtx();
forAll(*this, i) forAll(*this, i)
@ -248,4 +221,37 @@ void Foam::fv::optionList::constrain(fvMatrix<Type>& eqn)
} }
template<class Type>
void Foam::fv::optionList::correct
(
GeometricField<Type, fvPatchField, volMesh>& field
)
{
const word& fieldName = field.name();
forAll(*this, i)
{
option& source = this->operator[](i);
label fieldI = source.applyToField(fieldName);
if (fieldI != -1)
{
source.setApplied(fieldI);
if (source.isActive())
{
if (debug)
{
Info<< "Correcting source " << source.name()
<< " for field " << fieldName << endl;
}
source.correct(field);
}
}
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -169,7 +169,7 @@ void Foam::fv::rotorDiskSource::writeField
if (mesh_.time().outputTime() || writeNow) if (mesh_.time().outputTime() || writeNow)
{ {
tmp<fieldType> tfld tmp<fieldType> tfield
( (
new fieldType new fieldType
( (
@ -186,7 +186,7 @@ void Foam::fv::rotorDiskSource::writeField
) )
); );
Field<Type>& fld = tfld().internalField(); Field<Type>& field = tfield().internalField();
if (cells_.size() != values.size()) if (cells_.size() != values.size())
{ {
@ -197,10 +197,10 @@ void Foam::fv::rotorDiskSource::writeField
forAll(cells_, i) forAll(cells_, i)
{ {
const label cellI = cells_[i]; const label cellI = cells_[i];
fld[cellI] = values[i]; field[cellI] = values[i];
} }
tfld().write(); tfield().write();
} }
} }

View File

@ -149,7 +149,7 @@ Foam::fv::option& Foam::fv::CodedSource<Type>::redirectFvOption() const
template<class Type> template<class Type>
void Foam::fv::CodedSource<Type>::correct void Foam::fv::CodedSource<Type>::correct
( (
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
) )
{ {
if (debug) if (debug)
@ -159,7 +159,7 @@ void Foam::fv::CodedSource<Type>::correct
} }
updateLibrary(redirectType_); updateLibrary(redirectType_);
redirectFvOption().correct(fld); redirectFvOption().correct(field);
} }

View File

@ -31,7 +31,7 @@ Description
codeCorrect codeCorrect
( (
GeometricField<Type, fvPatchField, volMesh>& fld GeometricField<Type, fvPatchField, volMesh>& field
) )
codeAddSup codeAddSup
@ -47,7 +47,7 @@ Description
) )
where : where :
fld is the field in fieldNames field is the field in fieldNames
eqn is the fvMatrix eqn is the fvMatrix
\heading Source usage \heading Source usage