BUG: functionObjectState required update when accessed via execFlowFunctionObjects- fixes #54

This commit is contained in:
Andrew Heather
2016-04-22 13:01:21 +01:00
parent a661bf281e
commit a592347b91
5 changed files with 97 additions and 66 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -66,7 +66,7 @@ Foam::functionObject* Foam::functionObjectList::remove
{ {
oldIndex = fnd(); 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(); ptr = this->set(oldIndex, 0).ptr();
indices_.erase(fnd); indices_.erase(fnd);
} }
@ -124,6 +124,14 @@ Foam::functionObjectList::~functionObjectList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::functionObjectList::resetState()
{
// Reset (re-read) the state dictionary
stateDictPtr_.clear();
createStateDict();
}
Foam::IOdictionary& Foam::functionObjectList::stateDict() Foam::IOdictionary& Foam::functionObjectList::stateDict()
{ {
if (!stateDictPtr_.valid()) if (!stateDictPtr_.valid())
@ -177,7 +185,7 @@ void Foam::functionObjectList::on()
void Foam::functionObjectList::off() 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; updated_ = execution_ = false;
} }
@ -200,6 +208,11 @@ bool Foam::functionObjectList::execute(const bool forceWrite)
if (execution_) if (execution_)
{ {
if (forceWrite)
{
resetState();
}
if (!updated_) if (!updated_)
{ {
read(); read();
@ -304,7 +317,7 @@ bool Foam::functionObjectList::read()
bool ok = true; bool ok = true;
updated_ = execution_; updated_ = execution_;
// avoid reading/initializing if execution is off // Avoid reading/initializing if execution is off
if (!execution_) if (!execution_)
{ {
return ok; return ok;
@ -328,7 +341,7 @@ bool Foam::functionObjectList::read()
if (entryPtr->isDict()) if (entryPtr->isDict())
{ {
// a dictionary of functionObjects // A dictionary of functionObjects
const dictionary& functionDicts = entryPtr->dict(); const dictionary& functionDicts = entryPtr->dict();
newPtrs.setSize(functionDicts.size()); newPtrs.setSize(functionDicts.size());
@ -336,7 +349,7 @@ bool Foam::functionObjectList::read()
forAllConstIter(dictionary, functionDicts, iter) forAllConstIter(dictionary, functionDicts, iter)
{ {
// safety: // Safety:
if (!iter().isDict()) if (!iter().isDict())
{ {
continue; continue;
@ -350,7 +363,7 @@ bool Foam::functionObjectList::read()
functionObject* objPtr = remove(key, oldIndex); functionObject* objPtr = remove(key, oldIndex);
if (objPtr) if (objPtr)
{ {
// an existing functionObject, and dictionary changed // An existing functionObject, and dictionary changed
if (newDigs[nFunc] != digests_[oldIndex]) if (newDigs[nFunc] != digests_[oldIndex])
{ {
ok = objPtr->read(dict) && ok; ok = objPtr->read(dict) && ok;
@ -358,7 +371,7 @@ bool Foam::functionObjectList::read()
} }
else else
{ {
// new functionObject // New functionObject
objPtr = functionObject::New(key, time_, dict).ptr(); objPtr = functionObject::New(key, time_, dict).ptr();
ok = objPtr->start() && ok; ok = objPtr->start() && ok;
} }
@ -370,7 +383,7 @@ bool Foam::functionObjectList::read()
} }
else else
{ {
// a list of functionObjects // A list of functionObjects
PtrList<entry> functionDicts(entryPtr->stream()); PtrList<entry> functionDicts(entryPtr->stream());
newPtrs.setSize(functionDicts.size()); newPtrs.setSize(functionDicts.size());
@ -378,7 +391,7 @@ bool Foam::functionObjectList::read()
forAllIter(PtrList<entry>, functionDicts, iter) forAllIter(PtrList<entry>, functionDicts, iter)
{ {
// safety: // Safety:
if (!iter().isDict()) if (!iter().isDict())
{ {
continue; continue;
@ -392,7 +405,7 @@ bool Foam::functionObjectList::read()
functionObject* objPtr = remove(key, oldIndex); functionObject* objPtr = remove(key, oldIndex);
if (objPtr) if (objPtr)
{ {
// an existing functionObject, and dictionary changed // An existing functionObject, and dictionary changed
if (newDigs[nFunc] != digests_[oldIndex]) if (newDigs[nFunc] != digests_[oldIndex])
{ {
ok = objPtr->read(dict) && ok; ok = objPtr->read(dict) && ok;
@ -400,7 +413,7 @@ bool Foam::functionObjectList::read()
} }
else else
{ {
// new functionObject // New functionObject
objPtr = functionObject::New(key, time_, dict).ptr(); objPtr = functionObject::New(key, time_, dict).ptr();
ok = objPtr->start() && ok; ok = objPtr->start() && ok;
} }
@ -411,11 +424,11 @@ bool Foam::functionObjectList::read()
} }
} }
// safety: // Safety:
newPtrs.setSize(nFunc); newPtrs.setSize(nFunc);
newDigs.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 // but unused functionObjects
PtrList<functionObject>::transfer(newPtrs); PtrList<functionObject>::transfer(newPtrs);
digests_.transfer(newDigs); digests_.transfer(newDigs);

View File

@ -143,11 +143,14 @@ public:
//- Access to the functionObjects //- Access to the functionObjects
using PtrList<functionObject>::operator[]; using PtrList<functionObject>::operator[];
//- Reset/read state dictionary for current time
virtual void resetState();
//- Return the state dictionary //- Return the state dictionary
IOdictionary& stateDict(); virtual IOdictionary& stateDict();
//- Return const access to the state dictionary //- Return const access to the state dictionary
const IOdictionary& stateDict() const; virtual const IOdictionary& stateDict() const;
//- Clear the list of function objects //- Clear the list of function objects
virtual void clear(); virtual void clear();
@ -164,7 +167,6 @@ public:
//- Return the execution status (on/off) of the function objects //- Return the execution status (on/off) of the function objects
virtual bool status() const; virtual bool status() const;
//- Called at the start of the time-loop //- Called at the start of the time-loop
virtual bool start(); virtual bool start();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,6 +28,19 @@ License
const Foam::word Foam::functionObjectState::resultsName_ = "results"; 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -39,11 +52,7 @@ Foam::functionObjectState::functionObjectState
: :
obr_(obr), obr_(obr),
name_(name), name_(name),
active_(true), active_(true)
stateDict_
(
const_cast<IOdictionary&>(obr.time().functionObjects().stateDict())
)
{} {}
@ -67,28 +76,26 @@ bool Foam::functionObjectState::active() const
} }
const Foam::IOdictionary& Foam::functionObjectState::stateDict() const
{
return stateDict_;
}
Foam::dictionary& Foam::functionObjectState::propertyDict() 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 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); return baseDict.found(entryName);
} }
@ -109,10 +116,11 @@ Foam::word Foam::functionObjectState::objectResultType
) const ) const
{ {
word result = word::null; 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)) if (resultsDict.found(objectName))
{ {
@ -147,9 +155,11 @@ Foam::List<Foam::word> Foam::functionObjectState::objectResultEntries
{ {
DynamicList<word> result(2); 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)) if (resultsDict.found(objectName))
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -65,6 +65,15 @@ private:
const objectRegistry& obr_; const objectRegistry& obr_;
// Private Member Functions
//- Disallow default bitwise copy construct
functionObjectState(const functionObjectState&);
//- Disallow default bitwise assignment
void operator=(const functionObjectState&);
protected: protected:
// Protected data // Protected data
@ -75,19 +84,15 @@ protected:
//- Flag to indicate whether the object is active //- Flag to indicate whether the object is active
bool active_; bool active_;
//- Reference to the state dictionary
IOdictionary& stateDict_;
// Protacted Member Functions
protected: //- Return a const reference to the state dictionary
const IOdictionary& stateDict() const;
// Protected Member Functions //- Return non-const access to the state dictionary
IOdictionary& stateDict();
//- Disallow default bitwise copy construct
functionObjectState(const functionObjectState&);
//- Disallow default bitwise assignment
void operator=(const functionObjectState&);
public: public:
@ -95,11 +100,7 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
functionObjectState functionObjectState(const objectRegistry& obr, const word& name);
(
const objectRegistry& obr,
const word& name
);
//- Destructor //- Destructor
@ -114,9 +115,6 @@ public:
//- Return the active flag //- Return the active flag
bool active() const; bool active() const;
//- Return access to the state dictionary
const IOdictionary& stateDict() const;
//- Return access to the property dictionary //- Return access to the property dictionary
dictionary& propertyDict(); dictionary& propertyDict();

View File

@ -100,9 +100,11 @@ void Foam::functionObjectState::getObjectProperty
Type& value Type& value
) const ) 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.found(entryName))
{ {
if (baseDict.isDict(entryName)) if (baseDict.isDict(entryName))
@ -126,12 +128,14 @@ void Foam::functionObjectState::setObjectProperty
const Type& value 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); baseDict.add(entryName, value, true);
} }
@ -155,12 +159,14 @@ void Foam::functionObjectState::setObjectResult
const Type& value 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)) if (!resultsDict.found(objectName))
{ {
@ -215,9 +221,11 @@ void Foam::functionObjectState::getObjectResult
Type& value Type& value
) const ) 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)) if (resultsDict.found(objectName))
{ {