From 7c21f42b6d21bb15bb85aad2a3910e69b9deff66 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 8 Feb 2019 17:47:45 +0100 Subject: [PATCH] ENH: add remove objects handling in timeFunctionObject and regionFunctionObject - makes it easier to implement functionObject or field object removal --- .../regionFunctionObject.C | 33 ++++++++++++++----- .../regionFunctionObject.H | 7 ++-- .../stateFunctionObject/stateFunctionObject.C | 3 ++ .../stateFunctionObject/stateFunctionObject.H | 7 ++-- .../timeFunctionObject/timeFunctionObject.C | 16 +++++++++ .../timeFunctionObject/timeFunctionObject.H | 8 +++-- .../field/externalCoupled/externalCoupled.C | 4 +-- .../field/externalCoupled/externalCoupled.H | 6 ++-- src/functionObjects/utilities/abort/abort.C | 4 +-- src/functionObjects/utilities/abort/abort.H | 7 +--- .../codedFunctionObject/codedFunctionObject.C | 4 +-- .../setTimeStep/setTimeStepFunctionObject.C | 4 +-- .../setTimeStep/setTimeStepFunctionObject.H | 4 +-- .../utilities/systemCall/systemCall.C | 2 +- .../utilities/systemCall/systemCall.H | 6 ++-- .../timeActivatedFileUpdate.C | 4 +-- .../timeActivatedFileUpdate.H | 6 ++-- .../utilities/vtkWrite/vtkWrite.C | 4 +-- .../utilities/vtkWrite/vtkWrite.H | 2 +- 19 files changed, 83 insertions(+), 48 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C index 7526304ee2..42aeeb20ad 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C @@ -71,14 +71,14 @@ bool Foam::functionObjects::regionFunctionObject::writeObject const word& fieldName ) { - const regIOobject* obj = this->findObject(fieldName); + const regIOobject* ptr = this->cfindObject(fieldName); - if (obj) + if (ptr) { Log << " functionObjects::" << type() << " " << name() - << " writing field: " << obj->name() << endl; + << " writing field: " << ptr->name() << endl; - obj->write(); + ptr->write(); return true; } @@ -93,13 +93,13 @@ bool Foam::functionObjects::regionFunctionObject::clearObject ) { // Same as getObjectPtr, since the object is already non-const - regIOobject* obj = this->findObject(fieldName); + regIOobject* ptr = this->findObject(fieldName); - if (obj) + if (ptr) { - if (obj->ownedByRegistry()) + if (ptr->ownedByRegistry()) { - return obj->checkOut(); + return ptr->checkOut(); } else { @@ -113,6 +113,23 @@ bool Foam::functionObjects::regionFunctionObject::clearObject } +void Foam::functionObjects::regionFunctionObject::clearObjects +( + const wordList& objNames +) +{ + for (const word& objName : objNames) + { + regIOobject* ptr = this->findObject(objName); + + if (ptr && ptr->ownedByRegistry()) + { + ptr->checkOut(); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::regionFunctionObject::regionFunctionObject diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H index 72cd0ec8db..d34bfb8b4d 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2016 OpenFOAM Foundation @@ -57,7 +57,7 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::regionFunctionObject Declaration + Class regionFunctionObject Declaration \*---------------------------------------------------------------------------*/ class regionFunctionObject @@ -149,6 +149,9 @@ protected: //- Clear field from the (sub) objectRegistry if present bool clearObject(const word& fieldName); + //- Clear fields from the (sub) objectRegistry if present + void clearObjects(const wordList& objNames); + //- No copy construct regionFunctionObject(const regionFunctionObject&) = delete; diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C index b445c34434..243711abae 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.C @@ -28,9 +28,12 @@ License #include "stateFunctionObject.H" #include "Time.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + const Foam::word Foam::functionObjects::stateFunctionObject::resultsName_ = "results"; + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // const Foam::IOdictionary& diff --git a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H index e3b6907bc0..d6c4705a27 100644 --- a/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/stateFunctionObject/stateFunctionObject.H @@ -61,17 +61,14 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::stateFunctionObject Declaration + Class stateFunctionObject Declaration \*---------------------------------------------------------------------------*/ class stateFunctionObject : public functionObjects::timeFunctionObject { - -private: - - // Private member data + // Private Member Data //- Name of the results dictionary static const word resultsName_; diff --git a/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.C b/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.C index 08daa28fc4..9a9e700615 100644 --- a/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.C @@ -39,6 +39,22 @@ Foam::functionObjects::timeFunctionObject::timeFunctionObject {} +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::functionObjects::timeFunctionObject::clearOutputObjects +( + const wordList& objNames +) +{ + objectRegistry& obr = storedObjects(); + + for (const word& objName : objNames) + { + obr.checkOut(objName); + } +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::objectRegistry& diff --git a/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.H b/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.H index 90e3bcfc4e..bfd9724ee0 100644 --- a/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/timeFunctionObject/timeFunctionObject.H @@ -49,7 +49,7 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::timeFunctionObject Declaration + Class timeFunctionObject Declaration \*---------------------------------------------------------------------------*/ class timeFunctionObject @@ -66,6 +66,10 @@ protected: // Protected Member Functions + //- Remove specified items from "functionObjectObjects" + void clearOutputObjects(const wordList& objNames); + + //- No copy construct timeFunctionObject(const timeFunctionObject&) = delete; @@ -77,7 +81,7 @@ public: // Constructors - //- Construct from components + //- Construct from Time timeFunctionObject(const word& name, const Time& runTime); diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.C b/src/functionObjects/field/externalCoupled/externalCoupled.C index f9e68db678..19f6956efb 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.C +++ b/src/functionObjects/field/externalCoupled/externalCoupled.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -564,7 +564,7 @@ bool Foam::functionObjects::externalCoupled::end() bool Foam::functionObjects::externalCoupled::read(const dictionary& dict) { - functionObject::read(dict); + timeFunctionObject::read(dict); externalFileCoupler::readDict(dict); calcFrequency_ = dict.lookupOrDefault("calcFrequency", 1); diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.H b/src/functionObjects/field/externalCoupled/externalCoupled.H index 596ea5d74c..331a9f0795 100644 --- a/src/functionObjects/field/externalCoupled/externalCoupled.H +++ b/src/functionObjects/field/externalCoupled/externalCoupled.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -160,7 +160,7 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward Declarations class fvMesh; class IFstream; @@ -168,7 +168,7 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::externalCoupled Declaration + Class externalCoupled Declaration \*---------------------------------------------------------------------------*/ class externalCoupled diff --git a/src/functionObjects/utilities/abort/abort.C b/src/functionObjects/utilities/abort/abort.C index 3e7dd2ee49..2c2f2dc983 100644 --- a/src/functionObjects/utilities/abort/abort.C +++ b/src/functionObjects/utilities/abort/abort.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -159,7 +159,7 @@ Foam::functionObjects::abort::abort bool Foam::functionObjects::abort::read(const dictionary& dict) { - functionObject::read(dict); + timeFunctionObject::read(dict); file_.clear(); diff --git a/src/functionObjects/utilities/abort/abort.H b/src/functionObjects/utilities/abort/abort.H index 3df11b24b3..ce245ff327 100644 --- a/src/functionObjects/utilities/abort/abort.H +++ b/src/functionObjects/utilities/abort/abort.H @@ -136,12 +136,7 @@ public: // Constructors //- Construct from Time and dictionary - abort - ( - const word& name, - const Time& runTime, - const dictionary& dict - ); + abort(const word& name, const Time& runTime, const dictionary& dict); //- Destructor diff --git a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C index cc1a7a92e3..ce45990ae1 100644 --- a/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C +++ b/src/functionObjects/utilities/codedFunctionObject/codedFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2011, 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -185,7 +185,7 @@ bool Foam::functionObjects::codedFunctionObject::end() bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict) { - functionObject::read(dict); + timeFunctionObject::read(dict); dict.readCompat("name", {{"redirectType", 1706}}, name_); diff --git a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C index e39a2574ad..e1ae0a4aaf 100644 --- a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C +++ b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2013-2016 OpenFOAM Foundation @@ -89,7 +89,7 @@ bool Foam::functionObjects::setTimeStepFunctionObject::read const dictionary& dict ) { - functionObject::read(dict); + timeFunctionObject::read(dict); timeStepPtr_ = Function1::New("deltaT", dict); diff --git a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H index f0492e66c3..c91d23286c 100644 --- a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H +++ b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2013-2017 OpenFOAM Foundation @@ -82,7 +82,7 @@ namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::setTimeStepFunctionObject Declaration + Class setTimeStepFunctionObject Declaration \*---------------------------------------------------------------------------*/ class setTimeStepFunctionObject diff --git a/src/functionObjects/utilities/systemCall/systemCall.C b/src/functionObjects/utilities/systemCall/systemCall.C index f80fcb9fad..16246218a1 100644 --- a/src/functionObjects/utilities/systemCall/systemCall.C +++ b/src/functionObjects/utilities/systemCall/systemCall.C @@ -90,8 +90,8 @@ Foam::functionObjects::systemCall::systemCall : functionObject(name), executeCalls_(), - endCalls_(), writeCalls_(), + endCalls_(), masterOnly_(false) { read(dict); diff --git a/src/functionObjects/utilities/systemCall/systemCall.H b/src/functionObjects/utilities/systemCall/systemCall.H index 6d86c23af7..9054af6a5e 100644 --- a/src/functionObjects/utilities/systemCall/systemCall.H +++ b/src/functionObjects/utilities/systemCall/systemCall.H @@ -118,12 +118,12 @@ protected: //- List of calls to execute - every step stringList executeCalls_; - //- List of calls to execute when exiting the time-loop - stringList endCalls_; - //- List of calls to execute - write steps stringList writeCalls_; + //- List of calls to execute when exiting the time-loop + stringList endCalls_; + //- Perform system calls on the master only bool masterOnly_; diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C index 86ac4dac2f..a082202cd4 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010, 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2010, 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -108,7 +108,7 @@ bool Foam::functionObjects::timeActivatedFileUpdate::read const dictionary& dict ) { - functionObject::read(dict); + timeFunctionObject::read(dict); dict.readEntry("fileToUpdate", fileToUpdate_); dict.readEntry("timeVsFile", timeVsFile_); diff --git a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H index 343a5bed1e..4f24cbeeda 100644 --- a/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H +++ b/src/functionObjects/utilities/timeActivatedFileUpdate/timeActivatedFileUpdate.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010, 2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2010, 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -80,14 +80,14 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward Declarations class Time; namespace functionObjects { /*---------------------------------------------------------------------------*\ - Class functionObjects::timeActivatedFileUpdate Declaration + Class timeActivatedFileUpdate Declaration \*---------------------------------------------------------------------------*/ class timeActivatedFileUpdate diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C index 073873b98d..af3de3aad4 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWrite.C +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -161,7 +161,7 @@ Foam::functionObjects::vtkWrite::vtkWrite bool Foam::functionObjects::vtkWrite::read(const dictionary& dict) { - functionObject::read(dict); + timeFunctionObject::read(dict); readSelection(dict); diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.H b/src/functionObjects/utilities/vtkWrite/vtkWrite.H index 2b5da87199..197a252868 100644 --- a/src/functionObjects/utilities/vtkWrite/vtkWrite.H +++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License