diff --git a/src/functionObjects/field/turbulenceFields/turbulenceFields.C b/src/functionObjects/field/turbulenceFields/turbulenceFields.C index 9eb8d494ec13777f66f43d29dc9794c94a618a9e..c445161ddbf835d57192403c47b46da9293fbc48 100644 --- a/src/functionObjects/field/turbulenceFields/turbulenceFields.C +++ b/src/functionObjects/field/turbulenceFields/turbulenceFields.C @@ -90,6 +90,27 @@ const Foam::word Foam::functionObjects::turbulenceFields::modelName_ // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // +void Foam::functionObjects::turbulenceFields::initialise() +{ + for (const word& f : fieldSet_) + { + const word scopedName(modelName_ + ':' + f); + + if (obr_.found(scopedName)) + { + WarningInFunction + << "Cannot store turbulence field " << scopedName + << " since an object with that name already exists" + << nl << endl; + + fieldSet_.unset(f); + } + } + + initialised_ = true; +} + + bool Foam::functionObjects::turbulenceFields::compressible() { if (obr_.foundObject<compressible::turbulenceModel>(modelName_)) @@ -119,6 +140,7 @@ Foam::functionObjects::turbulenceFields::turbulenceFields ) : fvMeshFunctionObject(name, runTime, dict), + initialised_(false), fieldSet_() { read(dict); @@ -155,6 +177,8 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict) Info<< "no fields requested to be stored" << nl << endl; } + initialised_ = false; + return true; } @@ -164,6 +188,11 @@ bool Foam::functionObjects::turbulenceFields::read(const dictionary& dict) bool Foam::functionObjects::turbulenceFields::execute() { + if (!initialised_) + { + initialise(); + } + const bool comp = compressible(); if (comp) diff --git a/src/functionObjects/field/turbulenceFields/turbulenceFields.H b/src/functionObjects/field/turbulenceFields/turbulenceFields.H index 55b714d952b0ab53eadc967598bd425ba9b6d490..fea10c00e22a0feb4463057119ebabfa981f632d 100644 --- a/src/functionObjects/field/turbulenceFields/turbulenceFields.H +++ b/src/functionObjects/field/turbulenceFields/turbulenceFields.H @@ -214,12 +214,18 @@ protected: // Protected Data + //- Flag to track initialisation + bool initialised_; + //- Fields to load wordHashSet fieldSet_; // Protected Member Functions + //- Unset duplicate fields already registered by other function objects + void initialise(); + //- Return true if compressible turbulence model is identified bool compressible(); diff --git a/src/functionObjects/field/turbulenceFields/turbulenceFieldsTemplates.C b/src/functionObjects/field/turbulenceFields/turbulenceFieldsTemplates.C index 643bd8dae740f2fa5d15f49b11eca030ce103fd1..eff64c673ce3485a74895fc86d26e08e686dbad5 100644 --- a/src/functionObjects/field/turbulenceFields/turbulenceFieldsTemplates.C +++ b/src/functionObjects/field/turbulenceFields/turbulenceFieldsTemplates.C @@ -48,13 +48,6 @@ void Foam::functionObjects::turbulenceFields::processField { (*fldPtr) == tvalue(); } - else if (obr_.found(scopedName)) - { - WarningInFunction - << "Cannot store turbulence field " << scopedName - << " since an object with that name already exists" - << nl << endl; - } else { obr_.store