diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 7845c5fbc6b76e28f281cd0c992e348a45dbce85..a66ef2893bcf7cd007f714c799d4518218970ac5 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,7 +66,7 @@ Foam::functionObject* Foam::functionObjectList::remove { oldIndex = fnd(); - // retrieve the pointer and remove it from the old list + // Retrieve the pointer and remove it from the old list ptr = this->set(oldIndex, 0).ptr(); indices_.erase(fnd); } @@ -124,6 +124,14 @@ Foam::functionObjectList::~functionObjectList() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::functionObjectList::resetState() +{ + // Reset (re-read) the state dictionary + stateDictPtr_.clear(); + createStateDict(); +} + + Foam::IOdictionary& Foam::functionObjectList::stateDict() { if (!stateDictPtr_.valid()) @@ -177,7 +185,7 @@ void Foam::functionObjectList::on() void Foam::functionObjectList::off() { - // for safety, also force a read() when execution is turned back on + // For safety, also force a read() when execution is turned back on updated_ = execution_ = false; } @@ -200,6 +208,11 @@ bool Foam::functionObjectList::execute(const bool forceWrite) if (execution_) { + if (forceWrite) + { + resetState(); + } + if (!updated_) { read(); @@ -304,7 +317,7 @@ bool Foam::functionObjectList::read() bool ok = true; updated_ = execution_; - // avoid reading/initializing if execution is off + // Avoid reading/initializing if execution is off if (!execution_) { return ok; @@ -328,7 +341,7 @@ bool Foam::functionObjectList::read() if (entryPtr->isDict()) { - // a dictionary of functionObjects + // A dictionary of functionObjects const dictionary& functionDicts = entryPtr->dict(); newPtrs.setSize(functionDicts.size()); @@ -336,7 +349,7 @@ bool Foam::functionObjectList::read() forAllConstIter(dictionary, functionDicts, iter) { - // safety: + // Safety: if (!iter().isDict()) { continue; @@ -350,7 +363,7 @@ bool Foam::functionObjectList::read() functionObject* objPtr = remove(key, oldIndex); if (objPtr) { - // an existing functionObject, and dictionary changed + // An existing functionObject, and dictionary changed if (newDigs[nFunc] != digests_[oldIndex]) { ok = objPtr->read(dict) && ok; @@ -358,7 +371,7 @@ bool Foam::functionObjectList::read() } else { - // new functionObject + // New functionObject objPtr = functionObject::New(key, time_, dict).ptr(); ok = objPtr->start() && ok; } @@ -370,7 +383,7 @@ bool Foam::functionObjectList::read() } else { - // a list of functionObjects + // A list of functionObjects PtrList<entry> functionDicts(entryPtr->stream()); newPtrs.setSize(functionDicts.size()); @@ -378,7 +391,7 @@ bool Foam::functionObjectList::read() forAllIter(PtrList<entry>, functionDicts, iter) { - // safety: + // Safety: if (!iter().isDict()) { continue; @@ -392,7 +405,7 @@ bool Foam::functionObjectList::read() functionObject* objPtr = remove(key, oldIndex); if (objPtr) { - // an existing functionObject, and dictionary changed + // An existing functionObject, and dictionary changed if (newDigs[nFunc] != digests_[oldIndex]) { ok = objPtr->read(dict) && ok; @@ -400,7 +413,7 @@ bool Foam::functionObjectList::read() } else { - // new functionObject + // New functionObject objPtr = functionObject::New(key, time_, dict).ptr(); ok = objPtr->start() && ok; } @@ -411,11 +424,11 @@ bool Foam::functionObjectList::read() } } - // safety: + // Safety: newPtrs.setSize(nFunc); newDigs.setSize(nFunc); - // updating the PtrList of functionObjects also deletes any existing, + // Updating the PtrList of functionObjects also deletes any existing, // but unused functionObjects PtrList<functionObject>::transfer(newPtrs); digests_.transfer(newDigs); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index 6a46de60631636634af2179d070e15d8e90064b6..3a14a90e8d54d07d91aceca7ca9752313c6f93ac 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -143,11 +143,14 @@ public: //- Access to the functionObjects using PtrList<functionObject>::operator[]; + //- Reset/read state dictionary for current time + virtual void resetState(); + //- Return the state dictionary - IOdictionary& stateDict(); + virtual IOdictionary& stateDict(); //- Return const access to the state dictionary - const IOdictionary& stateDict() const; + virtual const IOdictionary& stateDict() const; //- Clear the list of function objects virtual void clear(); @@ -164,7 +167,6 @@ public: //- Return the execution status (on/off) of the function objects virtual bool status() const; - //- Called at the start of the time-loop virtual bool start(); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C index ce0b1c850f76ca76cdba7e066c8f756e60fbcb76..3dc191cefe7edbc550f3c1961a78c6b3c54cddf0 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,19 @@ License const Foam::word Foam::functionObjectState::resultsName_ = "results"; +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +const Foam::IOdictionary& Foam::functionObjectState::stateDict() const +{ + return obr_.time().functionObjects().stateDict(); +} + + +Foam::IOdictionary& Foam::functionObjectState::stateDict() +{ + return const_cast<IOdictionary&>(obr_.time().functionObjects().stateDict()); +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -39,11 +52,7 @@ Foam::functionObjectState::functionObjectState : obr_(obr), name_(name), - active_(true), - stateDict_ - ( - const_cast<IOdictionary&>(obr.time().functionObjects().stateDict()) - ) + active_(true) {} @@ -67,28 +76,26 @@ bool Foam::functionObjectState::active() const } -const Foam::IOdictionary& Foam::functionObjectState::stateDict() const -{ - return stateDict_; -} - - Foam::dictionary& Foam::functionObjectState::propertyDict() { - if (!stateDict_.found(name_)) + IOdictionary& stateDict = this->stateDict(); + + if (!stateDict.found(name_)) { - stateDict_.add(name_, dictionary()); + stateDict.add(name_, dictionary()); } - return stateDict_.subDict(name_); + return stateDict.subDict(name_); } bool Foam::functionObjectState::foundProperty(const word& entryName) const { - if (stateDict_.found(name_)) + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(name_)) { - const dictionary& baseDict = stateDict_.subDict(name_); + const dictionary& baseDict = stateDict.subDict(name_); return baseDict.found(entryName); } @@ -109,10 +116,11 @@ Foam::word Foam::functionObjectState::objectResultType ) const { word result = word::null; + const IOdictionary& stateDict = this->stateDict(); - if (stateDict_.found(resultsName_)) + if (stateDict.found(resultsName_)) { - const dictionary& resultsDict = stateDict_.subDict(resultsName_); + const dictionary& resultsDict = stateDict.subDict(resultsName_); if (resultsDict.found(objectName)) { @@ -147,9 +155,11 @@ Foam::List<Foam::word> Foam::functionObjectState::objectResultEntries { DynamicList<word> result(2); - if (stateDict_.found(resultsName_)) + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(resultsName_)) { - const dictionary& resultsDict = stateDict_.subDict(resultsName_); + const dictionary& resultsDict = stateDict.subDict(resultsName_); if (resultsDict.found(objectName)) { diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H index c945451dac0a82f10beedb3d2d45dc18164ad4f2..6bf3ec4331ccae923a1be6cb8cca649e98f7e528 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectState.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -65,6 +65,15 @@ private: const objectRegistry& obr_; + // Private Member Functions + + //- Disallow default bitwise copy construct + functionObjectState(const functionObjectState&); + + //- Disallow default bitwise assignment + void operator=(const functionObjectState&); + + protected: // Protected data @@ -75,19 +84,15 @@ protected: //- Flag to indicate whether the object is active bool active_; - //- Reference to the state dictionary - IOdictionary& stateDict_; + // Protacted Member Functions -protected: - - // Protected Member Functions + //- Return a const reference to the state dictionary + const IOdictionary& stateDict() const; - //- Disallow default bitwise copy construct - functionObjectState(const functionObjectState&); + //- Return non-const access to the state dictionary + IOdictionary& stateDict(); - //- Disallow default bitwise assignment - void operator=(const functionObjectState&); public: @@ -95,11 +100,7 @@ public: // Constructors //- Construct from components - functionObjectState - ( - const objectRegistry& obr, - const word& name - ); + functionObjectState(const objectRegistry& obr, const word& name); //- Destructor @@ -114,9 +115,6 @@ public: //- Return the active flag bool active() const; - //- Return access to the state dictionary - const IOdictionary& stateDict() const; - //- Return access to the property dictionary dictionary& propertyDict(); diff --git a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C index f102eb0a4c2d93822fe36313ecf1b9de80c15da1..ef791f3547b404100fce60a9158e3616dcd36ed2 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectState/functionObjectStateTemplates.C @@ -100,9 +100,11 @@ void Foam::functionObjectState::getObjectProperty Type& value ) const { - if (stateDict_.found(objectName)) + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(objectName)) { - const dictionary& baseDict = stateDict_.subDict(objectName); + const dictionary& baseDict = stateDict.subDict(objectName); if (baseDict.found(entryName)) { if (baseDict.isDict(entryName)) @@ -126,12 +128,14 @@ void Foam::functionObjectState::setObjectProperty const Type& value ) { - if (!stateDict_.found(objectName)) + IOdictionary& stateDict = this->stateDict(); + + if (!stateDict.found(objectName)) { - stateDict_.add(objectName, dictionary()); + stateDict.add(objectName, dictionary()); } - dictionary& baseDict = stateDict_.subDict(objectName); + dictionary& baseDict = stateDict.subDict(objectName); baseDict.add(entryName, value, true); } @@ -155,12 +159,14 @@ void Foam::functionObjectState::setObjectResult const Type& value ) { - if (!stateDict_.found(resultsName_)) + IOdictionary& stateDict = this->stateDict(); + + if (!stateDict.found(resultsName_)) { - stateDict_.add(resultsName_, dictionary()); + stateDict.add(resultsName_, dictionary()); } - dictionary& resultsDict = stateDict_.subDict(resultsName_); + dictionary& resultsDict = stateDict.subDict(resultsName_); if (!resultsDict.found(objectName)) { @@ -215,9 +221,11 @@ void Foam::functionObjectState::getObjectResult Type& value ) const { - if (stateDict_.found(resultsName_)) + const IOdictionary& stateDict = this->stateDict(); + + if (stateDict.found(resultsName_)) { - const dictionary& resultsDict = stateDict_.subDict(resultsName_); + const dictionary& resultsDict = stateDict.subDict(resultsName_); if (resultsDict.found(objectName)) {