1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "functionObjectList.H"
29 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
32 Foam::functionObjectList::remove(const word& key, label& oldIndex)
34 functionObject* ptr = 0;
36 // Find index of existing functionObject
37 HashTable<label>::iterator fnd = indices_.find(key);
39 if (fnd != indices_.end())
43 // retrieve the pointer and remove it from the old list
44 ptr = this->set(oldIndex, 0).ptr();
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 Foam::functionObjectList::functionObjectList
64 PtrList<functionObject>(),
68 parentDict_(t.controlDict()),
69 execution_(execution),
74 Foam::functionObjectList::functionObjectList
77 const dictionary& parentDict,
81 PtrList<functionObject>(),
85 parentDict_(parentDict),
86 execution_(execution),
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 Foam::functionObjectList::~functionObjectList()
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 void Foam::functionObjectList::clear()
101 PtrList<functionObject>::clear();
108 Foam::label Foam::functionObjectList::findObjectID(const word& name) const
110 forAll(*this, objectI)
112 if (operator[](objectI).name() == name)
122 void Foam::functionObjectList::on()
128 void Foam::functionObjectList::off()
130 // for safety, also force a read() when execution is turned back on
131 updated_ = execution_ = false;
135 bool Foam::functionObjectList::status() const
141 bool Foam::functionObjectList::start()
147 bool Foam::functionObjectList::execute(const bool forceWrite)
158 forAll(*this, objectI)
160 ok = operator[](objectI).execute(forceWrite) && ok;
168 bool Foam::functionObjectList::end()
179 forAll(*this, objectI)
181 ok = operator[](objectI).end() && ok;
189 bool Foam::functionObjectList::read()
192 updated_ = execution_;
194 // avoid reading/initializing if execution is off
200 // Update existing and add new functionObjects
201 const entry* entryPtr = parentDict_.lookupEntryPtr
210 PtrList<functionObject> newPtrs;
211 List<SHA1Digest> newDigs;
212 HashTable<label> newIndices;
216 if (entryPtr->isDict())
218 // a dictionary of functionObjects
219 const dictionary& functionDicts = entryPtr->dict();
221 newPtrs.setSize(functionDicts.size());
222 newDigs.setSize(functionDicts.size());
224 forAllConstIter(dictionary, functionDicts, iter)
227 if (!iter().isDict())
231 const word& key = iter().keyword();
232 const dictionary& dict = iter().dict();
234 newDigs[nFunc] = dict.digest();
237 functionObject* objPtr = remove(key, oldIndex);
240 // an existing functionObject, and dictionary changed
241 if (newDigs[nFunc] != digests_[oldIndex])
243 ok = objPtr->read(dict) && ok;
248 // new functionObject
249 objPtr = functionObject::New(key, time_, dict).ptr();
250 ok = objPtr->start() && ok;
253 newPtrs.set(nFunc, objPtr);
254 newIndices.insert(key, nFunc);
260 // a list of functionObjects
261 PtrList<entry> functionDicts(entryPtr->stream());
263 newPtrs.setSize(functionDicts.size());
264 newDigs.setSize(functionDicts.size());
266 forAllIter(PtrList<entry>, functionDicts, iter)
269 if (!iter().isDict())
273 const word& key = iter().keyword();
274 const dictionary& dict = iter().dict();
276 newDigs[nFunc] = dict.digest();
279 functionObject* objPtr = remove(key, oldIndex);
282 // an existing functionObject, and dictionary changed
283 if (newDigs[nFunc] != digests_[oldIndex])
285 ok = objPtr->read(dict) && ok;
290 // new functionObject
291 objPtr = functionObject::New(key, time_, dict).ptr();
292 ok = objPtr->start() && ok;
295 newPtrs.set(nFunc, objPtr);
296 newIndices.insert(key, nFunc);
302 newPtrs.setSize(nFunc);
303 newDigs.setSize(nFunc);
305 // updating the PtrList of functionObjects also deletes any existing,
306 // but unused functionObjects
307 PtrList<functionObject>::transfer(newPtrs);
308 digests_.transfer(newDigs);
309 indices_.transfer(newIndices);
313 PtrList<functionObject>::clear();
322 // ************************************************************************* //