1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "functionObjectList.H"
30 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
33 Foam::functionObjectList::remove(const word& key, label& oldIndex)
35 functionObject* ptr = 0;
37 // Find index of existing functionObject
38 HashTable<label>::iterator fnd = indices_.find(key);
40 if (fnd != indices_.end())
44 // retrieve the pointer and remove it from the old list
45 ptr = this->set(oldIndex, 0).ptr();
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 Foam::functionObjectList::functionObjectList
65 PtrList<functionObject>(),
69 parentDict_(t.controlDict()),
70 execution_(execution),
75 Foam::functionObjectList::functionObjectList
78 const dictionary& parentDict,
82 PtrList<functionObject>(),
86 parentDict_(parentDict),
87 execution_(execution),
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 Foam::functionObjectList::~functionObjectList()
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 void Foam::functionObjectList::clear()
102 PtrList<functionObject>::clear();
109 void Foam::functionObjectList::on()
115 void Foam::functionObjectList::off()
117 // for safety, also force a read() when execution is turned back on
118 updated_ = execution_ = false;
122 bool Foam::functionObjectList::status() const
128 bool Foam::functionObjectList::start()
134 bool Foam::functionObjectList::execute()
147 PtrList<functionObject>,
148 static_cast<PtrList<functionObject>&>(*this),
152 ok = iter().execute() && ok;
160 bool Foam::functionObjectList::end()
173 PtrList<functionObject>,
174 static_cast<PtrList<functionObject>&>(*this),
178 ok = iter().end() && ok;
186 bool Foam::functionObjectList::read()
189 updated_ = execution_;
191 // avoid reading/initializing if execution is off
197 // Update existing and add new functionObjects
198 const entry* entryPtr = parentDict_.lookupEntryPtr("functions",false,false);
201 PtrList<functionObject> newPtrs;
202 List<SHA1Digest> newDigs;
203 HashTable<label> newIndices;
207 if (entryPtr->isDict())
209 // a dictionary of functionObjects
210 const dictionary& functionDicts = entryPtr->dict();
212 newPtrs.setSize(functionDicts.size());
213 newDigs.setSize(functionDicts.size());
215 forAllConstIter(dictionary, functionDicts, iter)
218 if (!iter().isDict())
222 const word& key = iter().keyword();
223 const dictionary& dict = iter().dict();
225 newDigs[nFunc] = dict.digest();
228 functionObject* objPtr = remove(key, oldIndex);
231 // an existing functionObject, and dictionary changed
232 if (newDigs[nFunc] != digests_[oldIndex])
234 ok = objPtr->read(dict) && ok;
239 // new functionObject
240 objPtr = functionObject::New(key, time_, dict).ptr();
241 ok = objPtr->start() && ok;
244 newPtrs.set(nFunc, objPtr);
245 newIndices.insert(key, nFunc);
251 // a list of functionObjects
252 PtrList<entry> functionDicts(entryPtr->stream());
254 newPtrs.setSize(functionDicts.size());
255 newDigs.setSize(functionDicts.size());
257 forAllIter(PtrList<entry>, functionDicts, iter)
260 if (!iter().isDict())
264 const word& key = iter().keyword();
265 const dictionary& dict = iter().dict();
267 newDigs[nFunc] = dict.digest();
270 functionObject* objPtr = remove(key, oldIndex);
273 // an existing functionObject, and dictionary changed
274 if (newDigs[nFunc] != digests_[oldIndex])
276 ok = objPtr->read(dict) && ok;
281 // new functionObject
282 objPtr = functionObject::New(key, time_, dict).ptr();
283 ok = objPtr->start() && ok;
286 newPtrs.set(nFunc, objPtr);
287 newIndices.insert(key, nFunc);
293 newPtrs.setSize(nFunc);
294 newDigs.setSize(nFunc);
296 // updating the PtrList of functionObjects also deletes any existing,
297 // but unused functionObjects
298 PtrList<functionObject>::transfer(newPtrs);
299 digests_.transfer(newDigs);
300 indices_.transfer(newIndices);
304 PtrList<functionObject>::clear();
313 // ************************************************************************* //