STYLE: turbulenceFields: apply more recent OpenFOAM-coding practices

This commit is contained in:
Kutalmis Bercin
2021-06-23 17:24:15 +01:00
committed by Andrew Heather
parent 99291a7ac5
commit c6c575052f
2 changed files with 36 additions and 34 deletions

View File

@ -129,43 +129,46 @@ Foam::functionObjects::turbulenceFields::turbulenceFields
bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict) bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict)
{ {
fvMeshFunctionObject::read(dict); if (fvMeshFunctionObject::read(dict))
if (dict.found("field"))
{ {
fieldSet_.insert(dict.get<word>("field")); if (dict.found("field"))
}
else
{
fieldSet_.insert(dict.get<wordList>("fields"));
}
Info<< type() << " " << name() << ": ";
if (fieldSet_.size())
{
Info<< "storing fields:" << nl;
for (const word& f : fieldSet_)
{ {
Info<< " " << modelName_ << ':' << f << nl; fieldSet_.insert(dict.get<word>("field"));
} }
Info<< endl; else
} {
else fieldSet_.insert(dict.get<wordList>("fields"));
{ }
Info<< "no fields requested to be stored" << nl << endl;
Info<< type() << " " << name() << ": ";
if (fieldSet_.size())
{
Info<< "storing fields:" << nl;
for (const word& f : fieldSet_)
{
Info<< " " << modelName_ << ':' << f << nl;
}
Info<< endl;
}
else
{
Info<< "no fields requested to be stored" << nl << endl;
}
return true;
} }
return true; return false;
} }
bool Foam::functionObjects::turbulenceFields::execute() bool Foam::functionObjects::turbulenceFields::execute()
{ {
bool comp = compressible(); const bool comp = compressible();
if (comp) if (comp)
{ {
const compressible::turbulenceModel& model = const auto& model =
obr_.lookupObject<compressible::turbulenceModel>(modelName_); obr_.lookupObject<compressible::turbulenceModel>(modelName_);
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
@ -242,7 +245,7 @@ bool Foam::functionObjects::turbulenceFields::execute()
} }
else else
{ {
const incompressible::turbulenceModel& model = const auto& model =
obr_.lookupObject<incompressible::turbulenceModel>(modelName_); obr_.lookupObject<incompressible::turbulenceModel>(modelName_);
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
@ -316,9 +319,11 @@ bool Foam::functionObjects::turbulenceFields::write()
{ {
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
{ {
const word fieldName = modelName_ + ':' + f; const word scopedName(modelName_ + ':' + f);
writeObject(fieldName);
writeObject(scopedName);
} }
Info<< endl;
return true; return true;
} }

View File

@ -39,7 +39,7 @@ void Foam::functionObjects::turbulenceFields::processField
{ {
typedef GeometricField<Type, fvPatchField, volMesh> FieldType; typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
const word scopedName = modelName_ + ':' + fieldName; const word scopedName(modelName_ + ':' + fieldName);
FieldType* fldPtr = obr_.getObjectPtr<FieldType>(scopedName); FieldType* fldPtr = obr_.getObjectPtr<FieldType>(scopedName);
@ -99,17 +99,14 @@ Foam::functionObjects::turbulenceFields::L
const Model& model const Model& model
) const ) const
{ {
const scalar Cmu = 0.09;
// Assume k and epsilon are available // Assume k and epsilon are available
const volScalarField k(model.k()); const scalar Cmu = 0.09;
const volScalarField epsilon(model.epsilon()); const dimensionedScalar eps0(sqr(dimVelocity)/dimTime, SMALL);
const dimensionedScalar eps0("eps0", epsilon.dimensions(), SMALL);
return tmp<volScalarField>::New return tmp<volScalarField>::New
( (
"L.tmp", "L.tmp",
pow(Cmu, 0.75)*pow(k, 1.5)/(epsilon + eps0) pow(Cmu, 0.75)*pow(model.k(), 1.5)/(model.epsilon() + eps0)
); );
} }