functionObjects::blendingFactor: simplified, standardized, rationalized

This commit is contained in:
Henry Weller
2016-05-22 16:30:48 +01:00
parent 15773bf1b7
commit 3c44f08d52
5 changed files with 33 additions and 100 deletions

View File

@ -41,5 +41,6 @@ Q/Q.C
Lambda2/Lambda2.C Lambda2/Lambda2.C
CourantNo/CourantNo.C CourantNo/CourantNo.C
PecletNo/PecletNo.C PecletNo/PecletNo.C
blendingFactor/blendingFactor.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "blendingFactor.H" #include "blendingFactor.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -48,7 +47,7 @@ Foam::functionObjects::blendingFactor::blendingFactor
const dictionary& dict const dictionary& dict
) )
: :
fvMeshFunctionObject(name, runTime, dict) fieldExpression(name, runTime, dict)
{ {
read(dict); read(dict);
} }
@ -64,8 +63,11 @@ Foam::functionObjects::blendingFactor::~blendingFactor()
bool Foam::functionObjects::blendingFactor::read(const dictionary& dict) bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
{ {
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi"); phiName_ = dict.lookupOrDefault<word>("phi", "phi");
dict.lookup("field") >> fieldName_;
resultName_ = "blendingFactor:" + fieldName_;
return true; return true;
} }
@ -73,27 +75,18 @@ bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
bool Foam::functionObjects::blendingFactor::execute(const bool postProcess) bool Foam::functionObjects::blendingFactor::execute(const bool postProcess)
{ {
calc<scalar>(); bool processed = false;
calc<vector>();
return true; processed = processed || calc<scalar>();
} processed = processed || calc<vector>();
if (!processed)
{
WarningInFunction
<< "Unprocessed field " << fieldName_ << endl;
}
bool Foam::functionObjects::blendingFactor::write(const bool postProcess) return processed;
{
const word fieldName = "blendingFactor:" + fieldName_;
const volScalarField& blendingFactor =
obr_.lookupObject<volScalarField>(fieldName);
Info<< type() << " " << name() << " output:" << nl
<< " writing field " << blendingFactor.name() << nl
<< endl;
blendingFactor.write();
return true;
} }

View File

@ -33,6 +33,7 @@ Description
value is calculated via the maximum blending factor for any cell face. value is calculated via the maximum blending factor for any cell face.
SeeAlso SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject Foam::functionObjects::fvMeshFunctionObject
SourceFiles SourceFiles
@ -43,17 +44,12 @@ SourceFiles
#ifndef functionObjects_blendingFactor_H #ifndef functionObjects_blendingFactor_H
#define functionObjects_blendingFactor_H #define functionObjects_blendingFactor_H
#include "fvMeshFunctionObject.H" #include "fieldExpression.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class objectRegistry;
namespace functionObjects namespace functionObjects
{ {
@ -63,35 +59,19 @@ namespace functionObjects
class blendingFactor class blendingFactor
: :
public fvMeshFunctionObject public fieldExpression
{ {
// Private data // Private data
//- Name of flux field, default is "phi" //- Name of flux field, default is "phi"
word phiName_; word phiName_;
//- Field name
word fieldName_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct
blendingFactor(const blendingFactor&);
//- Disallow default bitwise assignment
void operator=(const blendingFactor&);
//- Return the blending factor field from the database
template<class Type>
volScalarField& factor
(
const GeometricField<Type, fvPatchField, volMesh>& field
);
//- Calculate the blending factor //- Calculate the blending factor
template<class Type> template<class Type>
void calc(); bool calc();
public: public:
@ -122,9 +102,6 @@ public:
//- Calculate the blending-factor //- Calculate the blending-factor
virtual bool execute(const bool postProcess = false); virtual bool execute(const bool postProcess = false);
//- Write the blending-factor
virtual bool write(const bool postProcess = false);
}; };

View File

@ -26,64 +26,25 @@ License
#include "gaussConvectionScheme.H" #include "gaussConvectionScheme.H"
#include "blendedSchemeBase.H" #include "blendedSchemeBase.H"
#include "fvcCellReduce.H" #include "fvcCellReduce.H"
#include "zeroGradientFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::volScalarField& Foam::functionObjects::blendingFactor::factor bool Foam::functionObjects::blendingFactor::calc()
(
const GeometricField<Type, fvPatchField, volMesh>& field
)
{ {
const word fieldName = "blendingFactor:" + field.name(); typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
if (!mesh_.foundObject<volScalarField>(fieldName)) if (!foundField<FieldType>(fieldName_))
{ {
volScalarField* factorPtr = return false;
new volScalarField
(
IOobject
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
);
obr_.store(factorPtr);
} }
return const FieldType& field = lookupField<FieldType>(fieldName_);
const_cast<volScalarField&>
(
mesh_.lookupObject<volScalarField>(fieldName)
);
}
template<class Type>
void Foam::functionObjects::blendingFactor::calc()
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (!mesh_.foundObject<fieldType>(fieldName_))
{
return;
}
const fieldType& field = mesh_.lookupObject<fieldType>(fieldName_);
const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')'); const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')');
ITstream& its = mesh_.divScheme(divScheme); ITstream& its = mesh_.divScheme(divScheme);
const surfaceScalarField& phi = const surfaceScalarField& phi = lookupField<surfaceScalarField>(phiName_);
mesh_.lookupObject<surfaceScalarField>(phiName_);
tmp<fv::convectionScheme<Type>> cs = tmp<fv::convectionScheme<Type>> cs =
fv::convectionScheme<Type>::New(mesh_, phi, its); fv::convectionScheme<Type>::New(mesh_, phi, its);
@ -101,15 +62,17 @@ void Foam::functionObjects::blendingFactor::calc()
<< exit(FatalError); << exit(FatalError);
} }
// retrieve the face-based blending factor // Retrieve the face-based blending factor
const blendedSchemeBase<Type>& blendedScheme = const blendedSchemeBase<Type>& blendedScheme =
refCast<const blendedSchemeBase<Type>>(interpScheme); refCast<const blendedSchemeBase<Type>>(interpScheme);
const surfaceScalarField factorf(blendedScheme.blendingFactor(field)); tmp<surfaceScalarField> factorf(blendedScheme.blendingFactor(field));
// convert into vol field whose values represent the local face maxima // Convert into vol field whose values represent the local face maxima
volScalarField& factor = this->factor(field); return store
factor = fvc::cellReduce(factorf, maxEqOp<scalar>()); (
factor.correctBoundaryConditions(); resultName_,
fvc::cellReduce(factorf, maxEqOp<scalar>())
);
} }

View File

@ -9,7 +9,6 @@ writeDictionary/writeDictionary.C
writeRegisteredObject/writeRegisteredObject.C writeRegisteredObject/writeRegisteredObject.C
scalarTransport/scalarTransport.C scalarTransport/scalarTransport.C
blendingFactor/blendingFactor.C
dsmcFields/dsmcFields.C dsmcFields/dsmcFields.C
turbulenceFields/turbulenceFields.C turbulenceFields/turbulenceFields.C