39 bool Foam::objectRegistry::parentNotTime()
const 41 return (&parent_ != dynamic_cast<const objectRegistry*>(&time_));
45 void Foam::objectRegistry::readCacheTemporaryObjects()
const 49 !cacheTemporaryObjectsSet_
50 && time_.controlDict().found(
"cacheTemporaryObjects")
53 cacheTemporaryObjectsSet_ =
true;
55 const dictionary& controlDict = time_.controlDict();
59 if (controlDict.isDict(
"cacheTemporaryObjects"))
61 if(controlDict.subDict(
"cacheTemporaryObjects").found(
name()))
63 controlDict.subDict(
"cacheTemporaryObjects").lookup(
name())
64 >> cacheTemporaryObjects;
69 controlDict.lookup(
"cacheTemporaryObjects")
70 >> cacheTemporaryObjects;
73 forAll(cacheTemporaryObjects, i)
75 cacheTemporaryObjects_.insert
77 cacheTemporaryObjects[i],
85 void Foam::objectRegistry::deleteCachedObject(regIOobject& cachedOb)
const 89 cachedOb.rename(cachedOb.name() +
"Cached");
99 const label nIoObjects
106 string::validate<word>(t.
caseName()),
120 cacheTemporaryObjectsSet_(
false)
127 const label nIoObjects
134 dbDir_(parent_.dbDir()/local()/
name()),
136 cacheTemporaryObjectsSet_(
false)
146 cacheTemporaryObjects_.clear();
170 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
174 objectNames[count++] = iter.key();
186 wordList sortedLst = names(ClassName);
196 const bool forceCreate
199 if (forceCreate && !foundObject<objectRegistry>(name))
212 fieldsCachePtr->
store();
214 return lookupObject<objectRegistry>(
name);
220 label curEvent = event_++;
224 if (objectRegistry::debug)
227 <<
"Event counter has overflowed. " 228 <<
"Resetting counter on all dependent objects." <<
nl 229 <<
"This might cause extra evaluations." <<
endl;
236 for (const_iterator iter = begin(); iter != end(); ++iter)
240 if (objectRegistry::debug)
242 Pout<<
"objectRegistry::getEvent() : " 243 <<
"resetting count on " << iter.key() <<
endl;
259 if (objectRegistry::debug)
261 Pout<<
"objectRegistry::checkIn(regIOobject&) : " 262 <<
name() <<
" : checking in " << io.
name()
263 <<
" of type " << io.type()
269 if (cacheTemporaryObjects_.size())
273 cacheTemporaryObjects_.find(io.
name())
276 if (cacheIter != cacheTemporaryObjects_.
end())
282 if (objectRegistry::debug)
284 Pout<<
"objectRegistry::checkIn(regIOobject&) : " 285 <<
name() <<
" : deleting cached object " << iter.key()
289 cacheIter().first() =
false;
290 deleteCachedObject(*iter());
305 if (objectRegistry::debug)
307 Pout<<
"objectRegistry::checkOut(regIOobject&) : " 308 <<
name() <<
" : checking out " << iter.key()
314 if (objectRegistry::debug)
317 <<
name() <<
" : attempt to checkOut copy of " 340 if (objectRegistry::debug)
342 Pout<<
"objectRegistry::checkOut(regIOobject&) : " 343 <<
name() <<
" : could not find " << io.
name()
344 <<
" in registry " <<
name()
356 label nMyObjects = 0;
358 for (iterator iter = begin(); iter != end(); ++iter)
360 if (iter()->ownedByRegistry())
362 myObjects[nMyObjects++] = iter();
366 for (
label i=0; i < nMyObjects; i++)
368 checkOut(*myObjects[i]);
378 if (!cacheTemporaryObjects_.found(name))
380 cacheTemporaryObjects_.insert(name, {
false,
false});
390 return cacheTemporaryObjects_.found(name);
399 if (cacheTemporaryObjects_.size())
403 cacheTemporaryObjects_.find(ob.
name())
408 if (iter != cacheTemporaryObjects_.
end())
410 iter().first() =
false;
418 bool enabled = cacheTemporaryObjects_.size();
426 if (orPtr_ && orPtr_ !=
this)
437 cacheTemporaryObjects_,
441 if (!iter().second())
444 <<
"Could not find temporary object " << iter.key()
445 <<
" in registry " <<
name() <<
nl 446 <<
"Available temporary objects " 452 iter().second() =
false;
456 temporaryObjects_.clear();
470 if (i == string::npos)
476 dbDir_.
replace(i+1, string::npos, newName);
485 if (iter()->modified())
497 for (iterator iter = begin(); iter != end(); ++iter)
499 if (objectRegistry::debug)
501 Pout<<
"objectRegistry::readModifiedObjects() : " 502 <<
name() <<
" : Considering reading object " 503 << iter.key() <<
endl;
506 iter()->readIfModified();
513 readModifiedObjects();
530 if (objectRegistry::debug)
532 Pout<<
"objectRegistry::write() : " 533 <<
name() <<
" : Considering writing object " 535 <<
" of type " << iter()->type()
536 <<
" with writeOpt " << iter()->writeOpt()
537 <<
" to file " << iter()->objectPath()
541 if (iter()->writeOpt() != NO_WRITE)
543 ok = iter()->writeObject(fmt, ver, cmp, write) && ok;
bool cacheTemporaryObject(const word &name) const
Return true if given name is in the cacheTemporaryObjects set.
#define forAll(list, i)
Loop across all elements in list.
void addTemporaryObject(const word &name) const
Add the given name to the set of temporary objects to cache.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
void readModifiedObjects()
Read the objects that have been modified.
void resetCacheTemporaryObject(const regIOobject &ob) const
Reset the cache state of the given object.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
wordList names() const
Return the list of names of the IOobjects.
virtual bool modified() const
Return true if any of the object's files have been modified.
Ostream & endl(Ostream &os)
Add newline and flush stream.
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
bool ownedByRegistry() const
Is this object owned by the registry?
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
objectRegistry(const Time &db, const label nIoObjects=128)
Construct the time objectRegistry given an initial estimate.
An ordered pair of two objects of type <T> with first() and second() elements.
A class for handling words, derived from string.
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
const fileName & caseName() const
Return case name.
virtual ~objectRegistry()
Destructor.
label getEvent() const
Return new event number.
streamFormat
Enumeration for the format of data in the stream.
label eventNo() const
Event number at last update.
static const label labelMax
virtual bool readIfModified()
Read object if modified.
An STL-conforming hash table.
graph_traits< Graph >::vertices_size_type size_type
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
bool checkCacheTemporaryObjects() const
Check that all objects in the cacheTemporaryObjects set.
compressionType
Enumeration for the format of data in the stream.
void store()
Transfer ownership of this object to its registry.
bool checkOut()
Remove object from registry.
defineTypeNameAndDebug(combustionModel, 0)
virtual void rename(const word &newName)
Rename.
word name(const complex &)
Return a string representation of a complex.
List< word > wordList
A List of words.
void setSize(const label)
Reset size of List.
string & replace(const string &oldStr, const string &newStr, size_type start=0)
Replace first occurrence of sub-string oldStr with newStr.
#define WarningInFunction
Report a warning using Foam::Warning.
const Time & time() const
Return time.
prefixOSstream Pout(cout, "Pout")
List< Key > sortedToc() const
Return the table of contents as a sorted list.
void clear()
Remove all regIOobject owned by the registry.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
const objectRegistry & subRegistry(const word &name, const bool forceCreate=false) const
Lookup and return a const sub-objectRegistry. Optionally create.
List< Key > toc() const
Return the table of contents.
Registry of regIOobjects.
const objectRegistry & db() const
Return the local objectRegistry.
fileName path() const
Return path.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write) const
Write the objects.
bool checkIn()
Add object to registry.
virtual void rename(const word &newName)
Rename.