Skip to content
Snippets Groups Projects
Commit e5986e90 authored by Andrew Heather's avatar Andrew Heather
Browse files

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

parent c62d36ed
Branches
Tags
1 merge request!33Merge foundation
......@@ -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);
......
......@@ -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();
......
......@@ -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))
{
......
......@@ -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();
......
......@@ -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))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment