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();
155 const word& instance,
160 return rootPath()/caseName()/instance/dbDir()/local;
180 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
184 objectNames[count++] = iter.key();
196 wordList sortedLst = names(ClassName);
206 const bool forceCreate
209 if (forceCreate && !foundObject<objectRegistry>(name))
222 fieldsCachePtr->
store();
224 return lookupObject<objectRegistry>(
name);
230 label curEvent = event_++;
234 if (objectRegistry::debug)
237 <<
"Event counter has overflowed. " 238 <<
"Resetting counter on all dependent objects." <<
nl 239 <<
"This might cause extra evaluations." <<
endl;
246 for (const_iterator iter = begin(); iter != end(); ++iter)
250 if (objectRegistry::debug)
252 Pout<<
"objectRegistry::getEvent() : " 253 <<
"resetting count on " << iter.key() <<
endl;
269 if (objectRegistry::debug)
271 Pout<<
"objectRegistry::checkIn(regIOobject&) : " 272 <<
name() <<
" : checking in " << io.
name()
273 <<
" of type " << io.type()
279 if (cacheTemporaryObjects_.size())
283 cacheTemporaryObjects_.find(io.
name())
286 if (cacheIter != cacheTemporaryObjects_.
end())
292 if (objectRegistry::debug)
294 Pout<<
"objectRegistry::checkIn(regIOobject&) : " 295 <<
name() <<
" : deleting cached object " << iter.key()
299 cacheIter().first() =
false;
300 deleteCachedObject(*iter());
315 if (objectRegistry::debug)
317 Pout<<
"objectRegistry::checkOut(regIOobject&) : " 318 <<
name() <<
" : checking out " << iter.key()
324 if (objectRegistry::debug)
327 <<
name() <<
" : attempt to checkOut copy of " 350 if (objectRegistry::debug)
352 Pout<<
"objectRegistry::checkOut(regIOobject&) : " 353 <<
name() <<
" : could not find " << io.
name()
354 <<
" in registry " <<
name()
366 label nMyObjects = 0;
368 for (iterator iter = begin(); iter != end(); ++iter)
370 if (iter()->ownedByRegistry())
372 myObjects[nMyObjects++] = iter();
376 for (
label i=0; i < nMyObjects; i++)
378 checkOut(*myObjects[i]);
388 if (!cacheTemporaryObjects_.found(name))
390 cacheTemporaryObjects_.insert(name, {
false,
false});
400 return cacheTemporaryObjects_.found(name);
409 if (cacheTemporaryObjects_.size())
413 cacheTemporaryObjects_.find(ob.
name())
418 if (iter != cacheTemporaryObjects_.
end())
420 iter().first() =
false;
428 bool enabled = cacheTemporaryObjects_.size();
436 if (orPtr_ && orPtr_ !=
this)
447 cacheTemporaryObjects_,
454 <<
"Could not find temporary object " << iter.key()
455 <<
" in registry " <<
name() <<
nl 456 <<
"Available temporary objects " 462 iter().second() =
false;
466 temporaryObjects_.clear();
480 if (i == string::npos)
486 dbDir_.
replace(i+1, string::npos, newName);
495 if (iter()->modified())
507 for (iterator iter = begin(); iter != end(); ++iter)
509 if (objectRegistry::debug)
511 Pout<<
"objectRegistry::readModifiedObjects() : " 512 <<
name() <<
" : Considering reading object " 513 << iter.key() <<
endl;
516 iter()->readIfModified();
523 readModifiedObjects();
540 if (objectRegistry::debug)
542 Pout<<
"objectRegistry::write() : " 543 <<
name() <<
" : Considering writing object " 545 <<
" of type " << iter()->type()
546 <<
" with writeOpt " << iter()->writeOpt()
547 <<
" to file " << iter()->objectPath()
551 if (iter()->writeOpt() != NO_WRITE)
553 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.
const word & name() const
Return name.
A class for handling file names.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
void readModifiedObjects()
Read the objects that have been modified.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
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
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.
labelList second(const UList< labelPair > &p)
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)
In this string replace first occurrence of sub-string oldStr.
#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 complete path.
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.