diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C b/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C index 8800c04782..3143384fb3 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryCache.C @@ -81,6 +81,8 @@ void Foam::objectRegistry::deleteCachedObject(regIOobject* io) const { io->release(); // Relinquish any ownership by registry io->checkOut(); + // Additional safety - not certain this is actually needed... + io->rename(io->name() + "-Cache"); delete io; } } diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C index 5fd20ff64e..016dfa2093 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C @@ -376,6 +376,16 @@ Foam::DimensionedField::clone() const } +// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * // + +template +Foam::DimensionedField::~DimensionedField() +{ + // FUTURE: register cache field info + // // this->db().cacheTemporaryObject(*this); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index e18bd87160..e6dad2a011 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -117,6 +117,17 @@ private: void readIfPresent(const word& fieldDictEntry = "value"); + //- Implementation for 'New' with specified registerObject preference. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + template + static tmp> New_impl + ( + IOobjectOption::registerOption regOpt, + const word& name, + const Mesh& mesh, + Args&&... args + ); public: @@ -298,10 +309,25 @@ public: // Factory Methods - //- Return tmp field from name, mesh, dimensions, - //- copy of internal field. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field& iField + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -310,10 +336,25 @@ public: const Field& iField ); - //- Return tmp field from name, mesh, dimensions, - //- moved internal field contents. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, move internal field contents. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field&& iField + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, move internal field contents. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -322,9 +363,24 @@ public: Field&& iField ); - //- Return tmp field from name, mesh, dimensions. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -332,9 +388,25 @@ public: const dimensionSet& dims ); - //- Return uniform value tmp field from name, mesh, dimensions, value. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, value, dimensions. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, value, dimensions. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -343,9 +415,24 @@ public: const dimensionSet& dims ); - //- Return tmp field from name, mesh, dimensioned\. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -353,19 +440,21 @@ public: const dimensioned& dt ); - //- Return renamed tmp field - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return renamed tmp field (NO_READ, NO_WRITE). + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& newName, const tmp>& tfld ); - //- Construct tmp field based on mesh/registry information from - //- an existing field. - // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance - // from the field + //- Construct tmp field (NO_READ, NO_WRITE) + //- based on mesh/registry information from an existing field. + //- [Takes instance from the field]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). template static tmp> New ( @@ -374,10 +463,11 @@ public: const dimensionSet& dims ); - //- Construct tmp field based on mesh/registry information from - //- an existing field and initialise with value. - // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance - // from the field + //- Construct tmp field (NO_READ, NO_WRITE) + //- based on mesh/registry information from an existing field + //- and initialise with value. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). template static tmp> New ( @@ -388,7 +478,7 @@ public: //- Destructor - virtual ~DimensionedField() = default; + virtual ~DimensionedField(); // Member Functions @@ -469,11 +559,15 @@ public: ) const; - // Write + // Write - bool writeData(Ostream& os, const word& fieldDictEntry) const; + //- Write dimensions, oriented flag (if valid) and the + //- field data as a dictionary entry with the specified name. + bool writeData(Ostream& os, const word& fieldDictEntry) const; - bool writeData(Ostream& os) const; + //- The writeData function (required by regIOobject), + //- call writeData with dictionary entry name = "value" + bool writeData(Ostream& os) const; // Member Operators diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C index 5bb6daef0d..ba8f11430c 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C @@ -25,16 +25,17 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template +template Foam::tmp> -Foam::DimensionedField::New +Foam::DimensionedField::New_impl ( + IOobjectOption::registerOption regOpt, const word& name, const Mesh& mesh, - const dimensionSet& dims, - const Field& iField + Args&&... args ) { auto ptr = tmp>::New @@ -49,13 +50,18 @@ Foam::DimensionedField::New IOobjectOption::NO_REGISTER ), mesh, - dims, - iField + std::forward(args)... ); - if + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if ( - ptr->db().is_cacheTemporaryObject(ptr.get()) + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) ) { ptr.protect(true); @@ -65,6 +71,73 @@ Foam::DimensionedField::New } +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field& iField +) +{ + return DimensionedField::New_impl + ( + regOpt, + name, + mesh, + dims, + iField + ); +} + + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + const Field& iField +) +{ + return DimensionedField::New_impl + ( + IOobjectOption::LEGACY_REGISTER, + name, + mesh, + dims, + iField + ); +} + + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field&& iField +) +{ + return DimensionedField::New_impl + ( + regOpt, + name, + mesh, + dims, + std::move(iField) + ); +} + + template Foam::tmp> Foam::DimensionedField::New @@ -75,31 +148,35 @@ Foam::DimensionedField::New Field&& iField ) { - auto ptr = tmp>::New + return DimensionedField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, dims, std::move(iField) ); +} - if + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims +) +{ + return DimensionedField::New_impl ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + regOpt, + name, + mesh, + dims, + false // No checkIOFlags (is NO_READ anyhow) + ); } @@ -112,31 +189,37 @@ Foam::DimensionedField::New const dimensionSet& dims ) { - auto ptr = tmp>::New + return DimensionedField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, dims, - false // checkIOFlags off + false // No checkIOFlags (is NO_READ anyhow) ); +} - if + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims +) +{ + return DimensionedField::New_impl ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + regOpt, + name, + mesh, + value, + dims, + false // No checkIOFlags (is NO_READ anyhow) + ); } @@ -150,32 +233,36 @@ Foam::DimensionedField::New const dimensionSet& dims ) { - auto ptr = tmp>::New + return DimensionedField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, value, dims, - false // checkIOFlags off + false // No checkIOFlags (is NO_READ anyhow) ); +} - if + +template +Foam::tmp> +Foam::DimensionedField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt +) +{ + return DimensionedField::New ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + name, + regOpt, + mesh, + dt.value(), + dt.dimensions() + ); } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index 048999ae4d..12603e72ef 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -899,6 +899,11 @@ Foam::GeometricField::~GeometricField() deleteDemandDrivenData(field0Ptr_); deleteDemandDrivenData(fieldPrevIterPtr_); + + // FUTURE: register cache field info + // // this->db().cacheTemporaryObject(*this); + + clearOldTimes(); } @@ -955,6 +960,14 @@ Foam::GeometricField::boundaryFieldRef } +template class PatchField, class GeoMesh> +Foam::label +Foam::GeometricField::nOldTimes() const noexcept +{ + return (field0Ptr_ ? (field0Ptr_->nOldTimes() + 1) : 0); +} + + template class PatchField, class GeoMesh> void Foam::GeometricField::storeOldTimes() const { @@ -995,18 +1008,6 @@ void Foam::GeometricField::storeOldTime() const } -template class PatchField, class GeoMesh> -Foam::label Foam::GeometricField::nOldTimes() const -{ - if (field0Ptr_) - { - return field0Ptr_->nOldTimes() + 1; - } - - return 0; -} - - template class PatchField, class GeoMesh> const Foam::GeometricField& Foam::GeometricField::oldTime() const @@ -1097,6 +1098,14 @@ Foam::GeometricField::prevIter() const } +template class PatchField, class GeoMesh> +void Foam::GeometricField::clearOldTimes() +{ + deleteDemandDrivenData(field0Ptr_); + deleteDemandDrivenData(fieldPrevIterPtr_); +} + + template class PatchField, class GeoMesh> void Foam::GeometricField:: correctBoundaryConditions() diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 8cacf3b4fc..d299f7c1a5 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -134,6 +134,18 @@ private: //- Read the field - create the field dictionary on-the-fly void readFields(); + //- Implementation for 'New' with specified registerObject preference. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + template + static tmp> New_impl + ( + IOobjectOption::registerOption regOpt, + const word& name, + const Mesh& mesh, + Args&&... args + ); + public: //- Runtime type information @@ -405,9 +417,25 @@ public: // Factory Methods - //- Return tmp field from name, mesh, dimensions and patch type. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions and patch type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const word& patchFieldType = PatchField::calculatedType() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions and patch type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -416,10 +444,26 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Return tmp field from name, mesh, dimensions, - //- copy of internal field, with specified patch type. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field and patch type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field& iField, + const word& patchFieldType = PatchField::calculatedType() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field and patch type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -429,10 +473,28 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Return tmp field from name, mesh, dimensions, - //- moved internal field contents, with specified patch type. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, moved internal field contents + //- and patch type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field&& iField, + const word& patchFieldType = PatchField::calculatedType() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, moved internal field contents + //- and patch type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -442,10 +504,26 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Return tmp field from name, mesh, dimensions, initial field value - //- and patch type. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, field value, dimensions and patch type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims, + const word& patchFieldType = PatchField::calculatedType() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, field value, dimensions and patch type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -455,10 +533,27 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Return tmp field from name, mesh, dimensioned\ - //- and patch types. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, field value, dimensions and patch field types. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes = wordList() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, field value, dimensions and patch field types. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -469,10 +564,25 @@ public: const wordList& actualPatchTypes = wordList() ); - //- Return tmp field from name, mesh, dimensioned\ - //- and patch type. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type and patch type. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt, + const word& patchFieldType = PatchField::calculatedType() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type and patch type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -481,10 +591,26 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Return tmp field from name, mesh, dimensioned\ - //- and patch types. - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type and patch field types. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes = wordList() + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensioned-type and patch field types. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& name, @@ -494,18 +620,21 @@ public: const wordList& actualPatchTypes = wordList() ); - //- Return renamed tmp field - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& newName, const tmp>& tgf ); - //- Rename tmp field and reset patch field type - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- with reset patch field type. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& newName, @@ -513,9 +642,11 @@ public: const word& patchFieldType ); - //- Rename tmp field and reset patch field types and return - // The field is NO_READ, NO_WRITE, unregistered and uses the - // current timeName from the mesh registry + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- with reset patch field types. + //- [Takes instance from the field]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). static tmp> New ( const word& newName, @@ -524,10 +655,11 @@ public: const wordList& actualPatchTypes = wordList() ); - //- Construct tmp field based on mesh/registry information from - //- an existing field. - // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance - // from the field + //- Construct tmp field (NO_READ, NO_WRITE) + //- based on mesh/registry information from an existing field. + //- [Takes instance from the field]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). template static tmp> New ( @@ -537,10 +669,12 @@ public: const word& patchFieldType = PatchField::calculatedType() ); - //- Construct tmp field based on mesh/registry information from - //- an existing field and initialise with value. - // Created NO_READ, NO_WRITE, NO_REGISTER, using the instance - // from the field + //- Construct tmp field (NO_READ, NO_WRITE) + //- based on mesh/registry information from an existing field. + //- and initialise with value. + //- [Takes instance from the field]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). template static tmp> New ( @@ -610,15 +744,15 @@ public: //- Write-access to the time index of the field inline label& timeIndex() noexcept; + //- The number of old time fields stored + label nOldTimes() const noexcept; + //- Store the old-time fields void storeOldTimes() const; //- Store the old-time field void storeOldTime() const; - //- Return the number of old time fields stored - label nOldTimes() const; - //- Return old time field const GeometricField& oldTime() const; @@ -632,6 +766,9 @@ public: //- Return previous iteration field const GeometricField& prevIter() const; + //- Remove old-time and prev-iter fields + void clearOldTimes(); + //- Correct boundary field void correctBoundaryConditions(); @@ -648,9 +785,6 @@ public: const direction ) const; - //- WriteData member function required by regIOobject - bool writeData(Ostream&) const; - //- Return transpose (only if it is a tensor field) tmp> T() const; @@ -774,6 +908,13 @@ public: bool operator!=(const dimensioned&) = delete; + // Write + + //- The writeData function (required by regIOobject), + //- calls operator<< + bool writeData(Ostream& os) const; + + // Ostream Operators friend Ostream& operator<< diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C index a8a5723e93..29f69802c4 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C @@ -26,16 +26,17 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template class PatchField, class GeoMesh> +template Foam::tmp> -Foam::GeometricField::New +Foam::GeometricField::New_impl ( + IOobjectOption::registerOption regOpt, const word& name, const Mesh& mesh, - const dimensionSet& dims, - const word& patchFieldType + Args&&... args ) { auto ptr = tmp>::New @@ -50,13 +51,18 @@ Foam::GeometricField::New IOobjectOption::NO_REGISTER ), mesh, - dims, - patchFieldType + std::forward(args)... ); - if + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if ( - ptr->db().is_cacheTemporaryObject(ptr.get()) + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) ) { ptr.protect(true); @@ -66,6 +72,75 @@ Foam::GeometricField::New } +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const word& patchFieldType +) +{ + return GeometricField::New_impl + ( + regOpt, + name, + mesh, + dims, + patchFieldType + ); +} + + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + const word& patchFieldType +) +{ + return GeometricField::New_impl + ( + IOobjectOption::LEGACY_REGISTER, + name, + mesh, + dims, + patchFieldType + ); +} + + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field& iField, + const word& patchFieldType +) +{ + return GeometricField::New_impl + ( + regOpt, + name, + mesh, + dims, + iField, + patchFieldType + ); +} + + template class PatchField, class GeoMesh> Foam::tmp> Foam::GeometricField::New @@ -77,32 +152,39 @@ Foam::GeometricField::New const word& patchFieldType ) { - auto ptr = tmp>::New + return GeometricField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, dims, iField, patchFieldType ); +} - if + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field&& iField, + const word& patchFieldType +) +{ + return GeometricField::New_impl ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + regOpt, + name, + mesh, + dims, + std::move(iField), + patchFieldType + ); } @@ -117,32 +199,39 @@ Foam::GeometricField::New const word& patchFieldType ) { - auto ptr = tmp>::New + return GeometricField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, dims, std::move(iField), patchFieldType ); +} - if + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims, + const word& patchFieldType +) +{ + return GeometricField::New_impl ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + regOpt, + name, + mesh, + value, + dims, + patchFieldType + ); } @@ -157,32 +246,41 @@ Foam::GeometricField::New const word& patchFieldType ) { - auto ptr = tmp>::New + return GeometricField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, value, dims, patchFieldType ); +} - if + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const Type& value, + const dimensionSet& dims, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes +) +{ + return GeometricField::New_impl ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + regOpt, + name, + mesh, + value, + dims, + patchFieldTypes, + actualPatchTypes + ); } @@ -198,33 +296,39 @@ Foam::GeometricField::New const wordList& actualPatchTypes ) { - auto ptr = tmp>::New + return GeometricField::New_impl ( - IOobject - ( - name, - mesh.thisDb().time().timeName(), - mesh.thisDb(), - IOobjectOption::NO_READ, - IOobjectOption::NO_WRITE, - IOobjectOption::NO_REGISTER - ), + IOobjectOption::LEGACY_REGISTER, + name, mesh, value, dims, patchFieldTypes, actualPatchTypes ); +} - if + +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt, + const word& patchFieldType +) +{ + return GeometricField::New ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); - } - return ptr; + name, + regOpt, + mesh, + dt.value(), + dt.dimensions(), + patchFieldType + ); } @@ -249,6 +353,31 @@ Foam::GeometricField::New } +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensioned& dt, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes +) +{ + return GeometricField::New + ( + name, + regOpt, + mesh, + dt.value(), + dt.dimensions(), + patchFieldTypes, + actualPatchTypes + ); +} + + template class PatchField, class GeoMesh> Foam::tmp> Foam::GeometricField::New diff --git a/src/thermophysicalModels/basic/heThermo/heThermo.C b/src/thermophysicalModels/basic/heThermo/heThermo.C index 3690a1f30d..78600ba69c 100644 --- a/src/thermophysicalModels/basic/heThermo/heThermo.C +++ b/src/thermophysicalModels/basic/heThermo/heThermo.C @@ -89,7 +89,7 @@ void Foam::heThermo::init this->heBoundaryCorrection(he); // Note: T does not have oldTime - if (p.nOldTimes() > 0) + if (p.nOldTimes()) { init(p.oldTime(), T.oldTime(), he.oldTime()); }