diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index e6dad2a01162150a45603f4f103bfa7f97ded198..c193f7e176679904d9f7468f9890cafc1f28abdc 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2023 OpenCFD Ltd. + Copyright (C) 2015-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -440,8 +440,19 @@ public: const dimensioned<Type>& dt ); - //- Return renamed tmp field (NO_READ, NO_WRITE). - //- [Takes current timeName from the mesh registry]. + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- retaining its instance/local. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<DimensionedField<Type, GeoMesh>> New + ( + const word& newName, + IOobjectOption::registerOption regOpt, + const tmp<DimensionedField<Type, GeoMesh>>& tfld + ); + + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- retaining its instance/local. // Registration/persistence determined by // objectRegistry::is_cacheTemporaryObject(). static tmp<DimensionedField<Type, GeoMesh>> New diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C index ba8f11430c7f73c7fe1adb025e6c92161e1e3333..c8f2e12f1d0c71494e984a44f09fb954382ac296 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,6 +40,7 @@ Foam::DimensionedField<Type, GeoMesh>::New_impl { auto ptr = tmp<DimensionedField<Type, GeoMesh>>::New ( + // == mesh.thisDb().newIOobject(name) IOobject ( name, @@ -53,19 +54,22 @@ Foam::DimensionedField<Type, GeoMesh>::New_impl std::forward<Args>(args)... ); - if (IOobjectOption::REGISTER == regOpt) + // Registration { - ptr->checkIn(); - } - else if - ( - // LEGACY_REGISTER: detect if caching is desired - (IOobjectOption::LEGACY_REGISTER == regOpt) - && ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -290,6 +294,7 @@ Foam::tmp<Foam::DimensionedField<Type, GeoMesh>> Foam::DimensionedField<Type, GeoMesh>::New ( const word& name, + IOobjectOption::registerOption regOpt, const tmp<DimensionedField<Type, GeoMesh>>& tfld ) { @@ -308,18 +313,44 @@ Foam::DimensionedField<Type, GeoMesh>::New tfld ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } +template<class Type, class GeoMesh> +Foam::tmp<Foam::DimensionedField<Type, GeoMesh>> +Foam::DimensionedField<Type, GeoMesh>::New +( + const word& name, + const tmp<DimensionedField<Type, GeoMesh>>& tfld +) +{ + return DimensionedField<Type, GeoMesh>::New + ( + name, + IOobjectOption::LEGACY_REGISTER, + tfld + ); +} + + template<class Type, class GeoMesh> template<class AnyType> Foam::tmp<Foam::DimensionedField<Type, GeoMesh>> @@ -345,13 +376,16 @@ Foam::DimensionedField<Type, GeoMesh>::New dims ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if + ( + ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -383,13 +417,16 @@ Foam::DimensionedField<Type, GeoMesh>::New dt.dimensions() ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if + ( + ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index d299f7c1a51a6726bb649456e9e55177f959fda8..8c66779bf2f1069aa3337f9801588a82c91b857c 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2023 OpenCFD Ltd. + Copyright (C) 2015-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -504,6 +504,68 @@ public: const word& patchFieldType = PatchField<Type>::calculatedType() ); + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field contents + //- and patch list to clone. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field<Type>& iField, + const PtrList<PatchField<Type>>& pflds + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, copy of internal field contents + //- and patch list to clone. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + const Field<Type>& iField, + const PtrList<PatchField<Type>>& pflds + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, moved internal field contents + //- and patch list to clone. + //- [Takes current timeName from the mesh registry]. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& pflds + ); + + //- Return tmp field (NO_READ, NO_WRITE) + //- from name, mesh, dimensions, moved internal field contents + //- and patch list to clone. + //- [Takes current timeName from the mesh registry]. + // Registration/persistence determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& pflds + ); + //- Return tmp field (NO_READ, NO_WRITE) //- from name, mesh, field value, dimensions and patch type. //- [Takes current timeName from the mesh registry]. @@ -621,36 +683,70 @@ public: ); //- Return renamed tmp field (NO_READ, NO_WRITE) - //- [Takes current timeName from the mesh registry]. + //- retaining its instance/local. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& newName, + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld + ); + + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- retaining its instance/local. // Registration/persistence determined by // objectRegistry::is_cacheTemporaryObject(). static tmp<GeometricField<Type, PatchField, GeoMesh>> New ( const word& newName, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld ); //- Return renamed tmp field (NO_READ, NO_WRITE) - //- with reset patch field type. - //- [Takes current timeName from the mesh registry]. + //- with reset patch field type, retaining its instance/local. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& newName, + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, + const word& patchFieldType + ); + + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- with reset patch field type, retaining its instance/local. // Registration/persistence determined by // objectRegistry::is_cacheTemporaryObject(). static tmp<GeometricField<Type, PatchField, GeoMesh>> New ( const word& newName, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, const word& patchFieldType ); //- Return renamed tmp field (NO_READ, NO_WRITE) - //- with reset patch field types. - //- [Takes instance from the field]. + //- with reset patch field types, retaining its instance/local. + // For LEGACY_REGISTER, registration is determined by + // objectRegistry::is_cacheTemporaryObject(). + static tmp<GeometricField<Type, PatchField, GeoMesh>> New + ( + const word& newName, + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes = wordList() + ); + + //- Return renamed tmp field (NO_READ, NO_WRITE) + //- with reset patch field types, retaining its instance/local. // Registration/persistence determined by // objectRegistry::is_cacheTemporaryObject(). static tmp<GeometricField<Type, PatchField, GeoMesh>> New ( const word& newName, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList() ); @@ -866,7 +962,6 @@ public: // Member Operators - //- Return a const-reference to the dimensioned internal field. //- Same as internalField(). // Useful in the formulation of source-terms for FV equations const Internal& operator()() const { return *this; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C index 29f69802c49964398c68e50e5f3cf45e0b167fff..138d14d3b078d6da69da2187f8fd30ed4c22892b 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2017 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,6 +41,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New_impl { auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New ( + // == mesh.thisDb().newIOobject(name) IOobject ( name, @@ -54,19 +55,22 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New_impl std::forward<Args>(args)... ); - if (IOobjectOption::REGISTER == regOpt) + // Registration { - ptr->checkIn(); - } - else if - ( - // LEGACY_REGISTER: detect if caching is desired - (IOobjectOption::LEGACY_REGISTER == regOpt) - && ptr->db().is_cacheTemporaryObject(ptr.get()) - ) - { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -211,6 +215,100 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New } +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + const Field<Type>& iField, + const PtrList<PatchField<Type>>& pflds +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New_impl + ( + regOpt, + name, + mesh, + dims, + iField, + pflds + ); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + const Field<Type>& iField, + const PtrList<PatchField<Type>>& pflds +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New_impl + ( + IOobjectOption::LEGACY_REGISTER, + name, + mesh, + dims, + iField, + pflds + ); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& pflds +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New_impl + ( + regOpt, + name, + mesh, + dims, + std::move(iField), + pflds + ); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& pflds +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New_impl + ( + IOobjectOption::LEGACY_REGISTER, + name, + mesh, + dims, + std::move(iField), + pflds + ); +} + + template<class Type, template<class> class PatchField, class GeoMesh> Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> Foam::GeometricField<Type, PatchField, GeoMesh>::New @@ -406,8 +504,8 @@ Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> Foam::GeometricField<Type, PatchField, GeoMesh>::New ( const word& name, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf, - const word& patchFieldType + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld ) { auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New @@ -415,24 +513,32 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New IOobject ( name, - tgf().instance(), - tgf().local(), - tgf().db(), + tfld().instance(), + tfld().local(), + tfld().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, IOobjectOption::NO_REGISTER ), - tgf, - patchFieldType + tfld ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -443,7 +549,26 @@ Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> Foam::GeometricField<Type, PatchField, GeoMesh>::New ( const word& name, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New + ( + name, + IOobjectOption::LEGACY_REGISTER, + tfld + ); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, + const word& patchFieldType ) { auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New @@ -451,23 +576,33 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New IOobject ( name, - tgf().instance(), - tgf().local(), - tgf().db(), + tfld().instance(), + tfld().local(), + tfld().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, IOobjectOption::NO_REGISTER ), - tgf + tfld, + patchFieldType ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -478,7 +613,27 @@ Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> Foam::GeometricField<Type, PatchField, GeoMesh>::New ( const word& name, - const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, + const word& patchFieldType +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New + ( + name, + IOobjectOption::LEGACY_REGISTER, + tfld, + patchFieldType + ); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + IOobjectOption::registerOption regOpt, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, const wordList& patchFieldTypes, const wordList& actualPatchTypes ) @@ -488,30 +643,60 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New IOobject ( name, - tgf().instance(), - tgf().local(), - tgf().db(), + tfld().instance(), + tfld().local(), + tfld().db(), IOobjectOption::NO_READ, IOobjectOption::NO_WRITE, IOobjectOption::NO_REGISTER ), - tgf, + tfld, patchFieldTypes, actualPatchTypes ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if (IOobjectOption::REGISTER == regOpt) + { + ptr->checkIn(); + } + else if + ( + // LEGACY_REGISTER: detect if caching is desired + (IOobjectOption::LEGACY_REGISTER == regOpt) + && ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> +Foam::GeometricField<Type, PatchField, GeoMesh>::New +( + const word& name, + const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld, + const wordList& patchFieldTypes, + const wordList& actualPatchTypes +) +{ + return GeometricField<Type, PatchField, GeoMesh>::New + ( + name, + IOobjectOption::LEGACY_REGISTER, + tfld, + patchFieldTypes, + actualPatchTypes + ); +} + + template<class Type, template<class> class PatchField, class GeoMesh> template<class AnyType> Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> @@ -539,13 +724,17 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New patchFieldType ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if + ( + // LEGACY_REGISTER: detect if caching is desired + ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; } @@ -579,13 +768,17 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New patchFieldType ); - if - ( - ptr->db().is_cacheTemporaryObject(ptr.get()) - ) + // Registration { - ptr.protect(true); - ptr->checkIn(); + if + ( + // LEGACY_REGISTER: detect if caching is desired + ptr->db().is_cacheTemporaryObject(ptr.get()) + ) + { + ptr.protect(true); + ptr->checkIn(); + } } return ptr; }