diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 9eb84d9243..f9bb85e565 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -361,6 +361,7 @@ $(regIOobject)/regIOobjectWrite.C db/IOobjectList/IOobjectList.C db/objectRegistry/objectRegistry.C +db/objectRegistry/objectRegistryCache.C db/CallbackRegistry/CallbackRegistryName.C dll = db/dynamicLibrary diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 878413360b..a35e9d7b0c 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -459,6 +459,7 @@ Foam::Time::Time writeStreamOption_(IOstreamOption::ASCII), graphFormat_("raw"), runTimeModifiable_(false), + cacheTemporaryObjects_(true), functionObjects_(*this, false) { if (enableFunctionObjects) @@ -525,6 +526,7 @@ Foam::Time::Time writeStreamOption_(IOstreamOption::ASCII), graphFormat_("raw"), runTimeModifiable_(false), + cacheTemporaryObjects_(true), functionObjects_(*this, false) { // Functions @@ -609,6 +611,7 @@ Foam::Time::Time writeStreamOption_(IOstreamOption::ASCII), graphFormat_("raw"), runTimeModifiable_(false), + cacheTemporaryObjects_(true), functionObjects_(*this, false) { if (enableFunctionObjects) @@ -683,6 +686,7 @@ Foam::Time::Time writeStreamOption_(IOstreamOption::ASCII), graphFormat_("raw"), runTimeModifiable_(false), + cacheTemporaryObjects_(true), functionObjects_(*this, false) { if (enableFunctionObjects) @@ -885,6 +889,11 @@ bool Foam::Time::run() const addProfiling(fo, "functionObjects.end()"); functionObjects_.end(); } + + if (cacheTemporaryObjects_) + { + cacheTemporaryObjects_ = checkCacheTemporaryObjects(); + } } } @@ -915,6 +924,11 @@ bool Foam::Time::run() const { const_cast(*this).readModifiedObjects(); } + + if (cacheTemporaryObjects_) + { + cacheTemporaryObjects_ = checkCacheTemporaryObjects(); + } } // Update the "is-running" status following the diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index f9a410114f..ad28409a43 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2011-2019 OpenFOAM Foundation + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -215,6 +215,9 @@ private: //- Is runtime modification of dictionaries allowed? Switch runTimeModifiable_; + //- Is temporary object cache enabled? + mutable bool cacheTemporaryObjects_; + //- Function objects executed at start and on ++, += mutable functionObjectList functionObjects_; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 13f1b5f16e..9e33ec1fe1 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2011-2019 OpenFOAM Foundation Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -98,7 +98,10 @@ Foam::objectRegistry::objectRegistry(const Time& t, const label nObjects) time_(t), parent_(t), dbDir_(name()), - event_(1) + event_(1), + cacheTemporaryObjectsActive_(false), + cacheTemporaryObjects_(0), + temporaryObjects_(0) {} @@ -109,7 +112,10 @@ Foam::objectRegistry::objectRegistry(const IOobject& io, const label nObjects) time_(io.time()), parent_(io.db()), dbDir_(parent_.dbDir()/local()/name()), - event_(1) + event_(1), + cacheTemporaryObjectsActive_(false), + cacheTemporaryObjects_(0), + temporaryObjects_(0) { writeOpt(IOobject::AUTO_WRITE); } @@ -249,6 +255,8 @@ bool Foam::objectRegistry::checkIn(regIOobject* io) const { if (!io) return false; + objectRegistry& obr = const_cast(*this); + if (objectRegistry::debug) { Pout<< "objectRegistry::checkIn : " @@ -257,7 +265,36 @@ bool Foam::objectRegistry::checkIn(regIOobject* io) const << endl; } - objectRegistry& obr = const_cast(*this); + // Delete cached object if it has the same name as io, and in the + // cacheTemporaryObjects list + if (!cacheTemporaryObjects_.empty()) + { + auto cacheIter = cacheTemporaryObjects_.find(io->name()); + + if (cacheIter.good()) + { + iterator iter = obr.find(io->name()); + + if + ( + iter.good() + && iter.val() != io + && iter.val()->ownedByRegistry() + ) + { + if (objectRegistry::debug) + { + Pout<< "objectRegistry::checkIn : " + << name() << " : deleting cached object " + << io->name() << endl; + } + + cacheIter.val().first() = false; + deleteCachedObject(iter.val()); + } + } + } + bool ok = obr.insert(io->name(), io); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index f0cff91d5c..5216ce223d 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2011-2019 OpenFOAM Foundation + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,6 +44,7 @@ SourceFiles #include "UPtrList.H" #include "regIOobject.H" #include "wordRes.H" +#include "Pair.H" // Historically included by objectRegistryTemplates (until NOV-2018), // but not used by objectRegistry directly. @@ -78,6 +79,17 @@ class objectRegistry //- Current event mutable label event_; + //- State of cacheTemporaryObjects_, set true after reading + mutable bool cacheTemporaryObjectsActive_; + + //- Names of temporary object with current state + mutable HashTable> cacheTemporaryObjects_; + + //- Accumulated list of temporary objects available to cache + // Used to provide diagnostics in case the requested object is not + // available + mutable wordHashSet temporaryObjects_; + // Private Member Functions @@ -85,6 +97,13 @@ class objectRegistry // Used to terminate searching within the ancestors bool parentNotTime() const noexcept; + //- Read the cacheTemporaryObjects list from Time controlDict + void readCacheTemporaryObjects() const; + + //- Delete the cached object. Eg, before caching a new object + //- A nullptr is ignored. + void deleteCachedObject(regIOobject* io) const; + //- Templated implementation for count() // The number of items with a matching class template @@ -559,6 +578,30 @@ public: virtual void rename(const word& newName); + // Temporaries + + //FUTURE //- Add given name to the set of temporary objects to cache + //FUTURE void addTemporaryObject(const word& name) const; + + //- True if given name is in the cacheTemporaryObjects set + bool cacheTemporaryObject(const word& name) const; + + //- Cache the given object. Moves content and stores + template + bool cacheTemporaryObject(Type& obj) const; + + //- Reset the cache state of the given object (nullptr is ignored) + void resetCacheTemporaryObject(const regIOobject* io) const; + + //- Reset the cache state of the given object + // in the cacheTemporaryObjects set + void resetCacheTemporaryObject(const regIOobject& io) const; + + //- Check that all objects specified in the cacheTemporaryObjects + //- were also cached + bool checkCacheTemporaryObjects() const; + + // Reading //- Return true if any of the object's files have been modified @@ -573,7 +616,7 @@ public: // Writing - //- writeData function required by regIOobject but not used. + //- The writeData function is required by regIOobject but not used. // For this class, write is used instead virtual bool writeData(Ostream&) const { diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C b/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C new file mode 100644 index 0000000000..891431c937 --- /dev/null +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C @@ -0,0 +1,183 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2019 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "objectRegistry.H" +#include "Time.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::objectRegistry::readCacheTemporaryObjects() const +{ + if (cacheTemporaryObjectsActive_) return; + + const auto* eptr = time_.controlDict().findEntry + ( + "cacheTemporaryObjects", + keyType::LITERAL + ); + + if (eptr) + { + cacheTemporaryObjectsActive_ = true; + + // Clear old cache? + // cacheTemporaryObjects_.clear(); + + wordList objectNames; + + if (eptr->isDict()) + { + // Per region (sub-dictionary syntax) + eptr->dict().readIfPresent(name(), objectNames); + } + else + { + // All regions + eptr->readEntry(objectNames); + } + + for (const word& objName : objectNames) + { + cacheTemporaryObjects_.emplace(objName, false, false); + } + } +} + + +void Foam::objectRegistry::deleteCachedObject(regIOobject* io) const +{ + if (io) + { + io->release(); // Relinquish any ownership by registry + io->checkOut(); + delete io; + } +} + + +// FUTURE: (currently not needed) +// void Foam::objectRegistry::addTemporaryObject +// ( +// const word& name +// ) const +// { +// cacheTemporaryObjects_.emplace(name, false, false); +// } + + +bool Foam::objectRegistry::cacheTemporaryObject +( + const word& name +) const +{ + return cacheTemporaryObjects_.found(name); +} + + +void Foam::objectRegistry::resetCacheTemporaryObject +( + const regIOobject* io +) const +{ + if (io && !cacheTemporaryObjects_.empty()) + { + auto iter = cacheTemporaryObjects_.find(io->name()); + + // Reset the cached flag + if (iter.good()) + { + iter.val().first() = false; + } + } +} + + +void Foam::objectRegistry::resetCacheTemporaryObject +( + const regIOobject& io +) const +{ + resetCacheTemporaryObject(&io); +} + + +bool Foam::objectRegistry::checkCacheTemporaryObjects() const +{ + bool enabled = cacheTemporaryObjects_.size(); + + forAllConstIters(*this, iter) + { + const auto* subObr = dynamic_cast(iter.val()); + + // Protect against re-searching the top-level registry + if (subObr && subObr != this) + { + enabled = subObr->checkCacheTemporaryObjects() || enabled; + } + } + + if (enabled) + { + OSstream* emitWarning = nullptr; + + forAllIters(cacheTemporaryObjects_, iter) + { + if (!iter.val().second()) + { + if (!emitWarning) + { + emitWarning = &(Foam::Warning.stream()); + + *emitWarning + << "objectRegistry '" + << name() << "' has missing temporary objects:" << nl; + } + + *emitWarning<< " " << iter.key() << nl; + } + else + { + iter.val().second() = false; + } + } + + if (emitWarning) + { + *emitWarning + << "Available temporary objects: " + << temporaryObjects_.sortedToc() << endl; + } + + temporaryObjects_.clear(); + } + + return enabled; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index a4cb56253d..9204516b5d 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -5,8 +5,8 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2011-2019 OpenFOAM Foundation + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -595,4 +595,50 @@ Type& Foam::objectRegistry::lookupObjectRef } +template +bool Foam::objectRegistry::cacheTemporaryObject(Type& obj) const +{ + bool ok = false; + + readCacheTemporaryObjects(); + + if (cacheTemporaryObjects_.size()) + { + temporaryObjects_.insert(obj.name()); + + auto iter = cacheTemporaryObjects_.find(obj.name()); + + // Cache object if is in the cacheTemporaryObjects list + // and hasn't been cached yet + if (iter.good() && iter.val().first() == false) + { + iter.val().first() = true; + iter.val().second() = true; + + Type* cachedPtr = obj.db().template getObjectPtr(obj.name()); + + // Remove any name collisions from the cache + if (cachedPtr && cachedPtr != &obj && cachedPtr->ownedByRegistry()) + { + deleteCachedObject(cachedPtr); + } + + if (debug) + { + Info<< "Caching " << obj.name() + << " of type " << obj.type() << endl; + } + + obj.release(); + obj.checkOut(); + regIOobject::store(new Type(std::move(obj))); + + ok = true; + } + } + + return ok; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/db/regIOobject/regIOobject.C b/src/OpenFOAM/db/regIOobject/regIOobject.C index 2d3294016a..25711b8729 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobject.C +++ b/src/OpenFOAM/db/regIOobject/regIOobject.C @@ -178,6 +178,9 @@ Foam::regIOobject::~regIOobject() // checkOut(). By being 'unowned', the registry will not attempt a // second deletion when the object name is removed from the registry. + // Reset the cache state (if any) + db().resetCacheTemporaryObject(this); + // Revoke any registry ownership: we are already deleting ownedByRegistry_ = false; diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C index 2c57d75fd9..9b724d5a68 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C @@ -37,8 +37,11 @@ Foam::DimensionedField::New const Field& iField ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -46,7 +49,7 @@ Foam::DimensionedField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -65,8 +68,11 @@ Foam::DimensionedField::New Field&& iField ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -74,7 +80,7 @@ Foam::DimensionedField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -92,8 +98,11 @@ Foam::DimensionedField::New const dimensionSet& dims ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -101,7 +110,7 @@ Foam::DimensionedField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -120,8 +129,11 @@ Foam::DimensionedField::New const dimensionSet& dims ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -129,7 +141,7 @@ Foam::DimensionedField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, value, @@ -166,8 +178,11 @@ Foam::DimensionedField::New const tmp>& tfld ) { - return tmp>::New + const bool caching = tfld().db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -176,7 +191,7 @@ Foam::DimensionedField::New tfld().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), tfld ); @@ -193,8 +208,11 @@ Foam::DimensionedField::New const dimensionSet& dims ) { - return tmp>::New + const bool caching = fld.db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -202,7 +220,7 @@ Foam::DimensionedField::New fld.db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), fld.mesh(), dims @@ -220,8 +238,11 @@ Foam::DimensionedField::New const dimensioned& dt ) { - return tmp>::New + const bool caching = fld.db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -229,7 +250,7 @@ Foam::DimensionedField::New fld.db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), fld.mesh(), dt.value(), diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C index 8aa3f79d7f..b222d2960f 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C @@ -38,8 +38,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -47,7 +50,7 @@ Foam::GeometricField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -67,8 +70,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -76,7 +82,7 @@ Foam::GeometricField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -97,8 +103,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -106,7 +115,7 @@ Foam::GeometricField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, dims, @@ -127,8 +136,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -136,7 +148,7 @@ Foam::GeometricField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, value, @@ -158,8 +170,11 @@ Foam::GeometricField::New const wordList& actualPatchTypes ) { - return tmp>::New + const bool caching = mesh.thisDb().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -167,7 +182,7 @@ Foam::GeometricField::New mesh.thisDb(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), mesh, value, @@ -231,8 +246,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = tgf().db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -241,7 +259,7 @@ Foam::GeometricField::New tgf().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), tgf, patchFieldType @@ -257,8 +275,11 @@ Foam::GeometricField::New const tmp>& tgf ) { - return tmp>::New + const bool caching = tgf().db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -267,7 +288,7 @@ Foam::GeometricField::New tgf().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), tgf ); @@ -284,8 +305,11 @@ Foam::GeometricField::New const wordList& actualPatchTypes ) { - return tmp>::New + const bool caching = tgf().db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -294,7 +318,7 @@ Foam::GeometricField::New tgf().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), tgf, patchFieldTypes, @@ -314,8 +338,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = fld.db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -323,7 +350,7 @@ Foam::GeometricField::New fld.db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), fld.mesh(), dims, @@ -343,8 +370,11 @@ Foam::GeometricField::New const word& patchFieldType ) { - return tmp>::New + const bool caching = fld.db().cacheTemporaryObject(name); + + return tmp>::NewImmovable ( + caching, // (true: immovable, false: movable) IOobject ( name, @@ -352,7 +382,7 @@ Foam::GeometricField::New fld.db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER + caching // (true: REGISTER, false: NO_REGISTER) ), fld.mesh(), dt.value(), diff --git a/src/functionObjects/utilities/writeObjects/writeObjects.C b/src/functionObjects/utilities/writeObjects/writeObjects.C index 4d796125d8..6dd5944ca9 100644 --- a/src/functionObjects/utilities/writeObjects/writeObjects.C +++ b/src/functionObjects/utilities/writeObjects/writeObjects.C @@ -219,9 +219,22 @@ bool Foam::functionObjects::writeObjects::write() } else { - Log << " writing object " << obj.name() << endl; + // TBD: + // If the object is a temporary field expression wrap with tmp<...> - obj.write(); + // if (obj.db().cacheTemporaryObject(objName)) + // { + // obj.IOobject::rename("tmp<" + objName + ">"); + // + // Log << " writing object " << obj.name() << endl; + // obj.write(); + // obj.IOobject::rename(objName); + // } + // else + { + Log << " writing object " << obj.name() << endl; + obj.write(); + } } }