ENH: turbulenceFields: enable custom prefix for output fields

This commit is contained in:
Kutalmis Bercin
2021-06-25 18:49:00 +01:00
committed by Andrew Heather
parent 2e703543ff
commit 14b328d990
3 changed files with 21 additions and 11 deletions

View File

@ -94,12 +94,12 @@ void Foam::functionObjects::turbulenceFields::initialise()
{ {
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
{ {
const word scopedName(modelName_ + ':' + f); const word localName(IOobject::scopedName(prefix_, f));
if (obr_.found(scopedName)) if (obr_.found(localName))
{ {
WarningInFunction WarningInFunction
<< "Cannot store turbulence field " << scopedName << "Cannot store turbulence field " << localName
<< " since an object with that name already exists" << " since an object with that name already exists"
<< nl << endl; << nl << endl;
@ -141,6 +141,7 @@ Foam::functionObjects::turbulenceFields::turbulenceFields
: :
fvMeshFunctionObject(name, runTime, dict), fvMeshFunctionObject(name, runTime, dict),
initialised_(false), initialised_(false),
prefix_(dict.getOrDefault<word>("prefix", "turbulenceProperties")),
fieldSet_() fieldSet_()
{ {
read(dict); read(dict);
@ -153,6 +154,8 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict)
{ {
if (fvMeshFunctionObject::read(dict)) if (fvMeshFunctionObject::read(dict))
{ {
dict.readIfPresent("prefix", prefix_);
if (dict.found("field")) if (dict.found("field"))
{ {
fieldSet_.insert(dict.get<word>("field")); fieldSet_.insert(dict.get<word>("field"));
@ -168,7 +171,7 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict)
Info<< "storing fields:" << nl; Info<< "storing fields:" << nl;
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
{ {
Info<< " " << modelName_ << ':' << f << nl; Info<< " " << IOobject::scopedName(prefix_, f) << nl;
} }
Info<< endl; Info<< endl;
} }
@ -348,9 +351,9 @@ bool Foam::functionObjects::turbulenceFields::write()
{ {
for (const word& f : fieldSet_) for (const word& f : fieldSet_)
{ {
const word scopedName(modelName_ + ':' + f); const word localName(IOobject::scopedName(prefix_, f));
writeObject(scopedName); writeObject(localName);
} }
Info<< endl; Info<< endl;

View File

@ -35,8 +35,8 @@ Description
output during calculations, and stores/writes them on the mesh database output during calculations, and stores/writes them on the mesh database
for further manipulation. for further manipulation.
Fields are stored as copies of the original, with the prefix Fields are stored as copies of the original with a user-defined prefix
"turbulenceModel:", e.g.: e.g. a prefix of \c turbulenceModel yields the following for field \c R:
\verbatim \verbatim
turbulenceModel:R turbulenceModel:R
@ -79,6 +79,9 @@ Usage
// Option-2 // Option-2
field R; field R;
// Optional entries (runtime modifiable)
prefix <word>;
// Inherited entries // Inherited entries
... ...
} }
@ -91,6 +94,7 @@ Usage
libs | Library name: fieldFunctionObjects | word | yes | - libs | Library name: fieldFunctionObjects | word | yes | -
fields | Names of fields to store (see below) | wordList | yes | - fields | Names of fields to store (see below) | wordList | yes | -
field | Name of a field to store (see below) | word | yes | - field | Name of a field to store (see below) | word | yes | -
prefix | Name of output-field prefix | word | no | turbulenceProperties
\endtable \endtable
where \c fields can include: where \c fields can include:
@ -213,6 +217,9 @@ protected:
//- Flag to track initialisation //- Flag to track initialisation
bool initialised_; bool initialised_;
//- Name of output-field prefix
word prefix_;
//- Fields to load //- Fields to load
wordHashSet fieldSet_; wordHashSet fieldSet_;

View File

@ -39,9 +39,9 @@ void Foam::functionObjects::turbulenceFields::processField
{ {
typedef GeometricField<Type, fvPatchField, volMesh> FieldType; typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
const word scopedName(modelName_ + ':' + fieldName); const word localName(IOobject::scopedName(prefix_, fieldName));
FieldType* fldPtr = obr_.getObjectPtr<FieldType>(scopedName); FieldType* fldPtr = obr_.getObjectPtr<FieldType>(localName);
if (fldPtr) if (fldPtr)
{ {
@ -55,7 +55,7 @@ void Foam::functionObjects::turbulenceFields::processField
( (
IOobject IOobject
( (
scopedName, localName,
obr_.time().timeName(), obr_.time().timeName(),
obr_, obr_,
IOobject::READ_IF_PRESENT, IOobject::READ_IF_PRESENT,