ENH: update DimensionedField and GeometricField New factory methods

- allow separate specification of the registerObject (no/yes/auto)
  to improve the flexibility of the factory methods.
This commit is contained in:
Mark Olesen
2023-10-13 16:37:43 +02:00
parent 28b6a5b85a
commit 4cf1691cdd
8 changed files with 711 additions and 239 deletions

View File

@ -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;
}
}

View File

@ -376,6 +376,16 @@ Foam::DimensionedField<Type, GeoMesh>::clone() const
}
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
Foam::DimensionedField<Type, GeoMesh>::~DimensionedField()
{
// FUTURE: register cache field info
// // this->db().cacheTemporaryObject(*this);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class GeoMesh>

View File

@ -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<class... Args>
static tmp<DimensionedField<Type, GeoMesh>> 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
@ -310,10 +336,25 @@ public:
const Field<Type>& 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
Field<Type>&& 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
@ -322,9 +363,24 @@ public:
Field<Type>&& 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<DimensionedField<Type, GeoMesh>> 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<DimensionedField<Type, GeoMesh>> 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<DimensionedField<Type, GeoMesh>> 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
@ -343,9 +415,24 @@ public:
const dimensionSet& dims
);
//- Return tmp field from name, mesh, dimensioned\<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.
//- [Takes current timeName from the mesh registry].
// For LEGACY_REGISTER, registration is determined by
// objectRegistry::is_cacheTemporaryObject().
static tmp<DimensionedField<Type, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensioned<Type>& 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<DimensionedField<Type, GeoMesh>> New
(
const word& name,
@ -353,19 +440,21 @@ public:
const dimensioned<Type>& 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<DimensionedField<Type, GeoMesh>> New
(
const word& newName,
const tmp<DimensionedField<Type, GeoMesh>>& 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<class AnyType>
static tmp<DimensionedField<Type, GeoMesh>> 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<class AnyType>
static tmp<DimensionedField<Type, GeoMesh>> 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

View File

@ -25,16 +25,17 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, class GeoMesh>
template<class... Args>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
Foam::DimensionedField<Type, GeoMesh>::New_impl
(
IOobjectOption::registerOption regOpt,
const word& name,
const Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& iField
Args&&... args
)
{
auto ptr = tmp<DimensionedField<Type, GeoMesh>>::New
@ -49,13 +50,18 @@ Foam::DimensionedField<Type, GeoMesh>::New
IOobjectOption::NO_REGISTER
),
mesh,
dims,
iField
std::forward<Args>(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<Type, GeoMesh>::New
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& iField
)
{
return DimensionedField<Type, GeoMesh>::New_impl
(
regOpt,
name,
mesh,
dims,
iField
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
const Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& iField
)
{
return DimensionedField<Type, GeoMesh>::New_impl
(
IOobjectOption::LEGACY_REGISTER,
name,
mesh,
dims,
iField
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
Field<Type>&& iField
)
{
return DimensionedField<Type, GeoMesh>::New_impl
(
regOpt,
name,
mesh,
dims,
std::move(iField)
);
}
template<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
@ -75,31 +148,35 @@ Foam::DimensionedField<Type, GeoMesh>::New
Field<Type>&& iField
)
{
auto ptr = tmp<DimensionedField<Type, GeoMesh>>::New
return DimensionedField<Type, GeoMesh>::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<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims
)
{
return DimensionedField<Type, GeoMesh>::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<Type, GeoMesh>::New
const dimensionSet& dims
)
{
auto ptr = tmp<DimensionedField<Type, GeoMesh>>::New
return DimensionedField<Type, GeoMesh>::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<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const Type& value,
const dimensionSet& dims
)
{
return DimensionedField<Type, GeoMesh>::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<Type, GeoMesh>::New
const dimensionSet& dims
)
{
auto ptr = tmp<DimensionedField<Type, GeoMesh>>::New
return DimensionedField<Type, GeoMesh>::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<class Type, class GeoMesh>
Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
Foam::DimensionedField<Type, GeoMesh>::New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensioned<Type>& dt
)
{
return DimensionedField<Type, GeoMesh>::New
(
ptr->db().is_cacheTemporaryObject(ptr.get())
)
{
ptr.protect(true);
ptr->checkIn();
}
return ptr;
name,
regOpt,
mesh,
dt.value(),
dt.dimensions()
);
}

View File

@ -899,6 +899,11 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::~GeometricField()
deleteDemandDrivenData(field0Ptr_);
deleteDemandDrivenData(fieldPrevIterPtr_);
// FUTURE: register cache field info
// // this->db().cacheTemporaryObject(*this);
clearOldTimes();
}
@ -955,6 +960,14 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryFieldRef
}
template<class Type, template<class> class PatchField, class GeoMesh>
Foam::label
Foam::GeometricField<Type, PatchField, GeoMesh>::nOldTimes() const noexcept
{
return (field0Ptr_ ? (field0Ptr_->nOldTimes() + 1) : 0);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTimes() const
{
@ -995,18 +1008,6 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTime() const
}
template<class Type, template<class> class PatchField, class GeoMesh>
Foam::label Foam::GeometricField<Type, PatchField, GeoMesh>::nOldTimes() const
{
if (field0Ptr_)
{
return field0Ptr_->nOldTimes() + 1;
}
return 0;
}
template<class Type, template<class> class PatchField, class GeoMesh>
const Foam::GeometricField<Type, PatchField, GeoMesh>&
Foam::GeometricField<Type, PatchField, GeoMesh>::oldTime() const
@ -1097,6 +1098,14 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::prevIter() const
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::clearOldTimes()
{
deleteDemandDrivenData(field0Ptr_);
deleteDemandDrivenData(fieldPrevIterPtr_);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::
correctBoundaryConditions()

View File

@ -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<class... Args>
static tmp<GeometricField<Type, PatchField, GeoMesh>> 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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -416,10 +444,26 @@ public:
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& iField,
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -429,10 +473,28 @@ public:
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensionSet& dims,
Field<Type>&& iField,
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -442,10 +504,26 @@ public:
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const Type& value,
const dimensionSet& dims,
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -455,10 +533,27 @@ public:
const word& patchFieldType = PatchField<Type>::calculatedType()
);
//- Return tmp field from name, mesh, dimensioned\<Type\>
//- 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<GeometricField<Type, PatchField, GeoMesh>> 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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -469,10 +564,25 @@ public:
const wordList& actualPatchTypes = wordList()
);
//- Return tmp field from name, mesh, dimensioned\<Type\>
//- 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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensioned<Type>& dt,
const word& patchFieldType = PatchField<Type>::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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
@ -481,10 +591,26 @@ public:
const word& patchFieldType = PatchField<Type>::calculatedType()
);
//- Return tmp field from name, mesh, dimensioned\<Type\>
//- 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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& name,
IOobjectOption::registerOption regOpt,
const Mesh& mesh,
const dimensioned<Type>& 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<GeometricField<Type, PatchField, GeoMesh>> 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<GeometricField<Type, PatchField, GeoMesh>> New
(
const word& newName,
const tmp<GeometricField<Type, PatchField, GeoMesh>>& 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<GeometricField<Type, PatchField, GeoMesh>> 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<GeometricField<Type, PatchField, GeoMesh>> 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<class AnyType>
static tmp<GeometricField<Type, PatchField, GeoMesh>> New
(
@ -537,10 +669,12 @@ public:
const word& patchFieldType = PatchField<Type>::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<class AnyType>
static tmp<GeometricField<Type, PatchField, GeoMesh>> 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<Type, PatchField, GeoMesh>& oldTime() const;
@ -632,6 +766,9 @@ public:
//- Return previous iteration field
const GeometricField<Type, PatchField, GeoMesh>& 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<GeometricField<Type, PatchField, GeoMesh>> T() const;
@ -774,6 +908,13 @@ public:
bool operator!=(const dimensioned<Type>&) = delete;
// Write
//- The writeData function (required by regIOobject),
//- calls operator<<
bool writeData(Ostream& os) const;
// Ostream Operators
friend Ostream& operator<< <Type, PatchField, GeoMesh>

View File

@ -26,16 +26,17 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
template<class... Args>
Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>>
Foam::GeometricField<Type, PatchField, GeoMesh>::New
Foam::GeometricField<Type, PatchField, GeoMesh>::New_impl
(
IOobjectOption::registerOption regOpt,
const word& name,
const Mesh& mesh,
const dimensionSet& dims,
const word& patchFieldType
Args&&... args
)
{
auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New
@ -50,13 +51,18 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
IOobjectOption::NO_REGISTER
),
mesh,
dims,
patchFieldType
std::forward<Args>(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<Type, PatchField, GeoMesh>::New
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
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 word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::New_impl
(
regOpt,
name,
mesh,
dims,
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,
const Mesh& mesh,
const dimensionSet& dims,
const word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::New_impl
(
IOobjectOption::LEGACY_REGISTER,
name,
mesh,
dims,
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 Mesh& mesh,
const dimensionSet& dims,
const Field<Type>& iField,
const word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::New_impl
(
regOpt,
name,
mesh,
dims,
iField,
patchFieldType
);
}
template<class Type, template<class> class PatchField, class GeoMesh>
Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>>
Foam::GeometricField<Type, PatchField, GeoMesh>::New
@ -77,32 +152,39 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
const word& patchFieldType
)
{
auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New
return GeometricField<Type, PatchField, GeoMesh>::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 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 word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::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<Type, PatchField, GeoMesh>::New
const word& patchFieldType
)
{
auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New
return GeometricField<Type, PatchField, GeoMesh>::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 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 Type& value,
const dimensionSet& dims,
const word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::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<Type, PatchField, GeoMesh>::New
const word& patchFieldType
)
{
auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New
return GeometricField<Type, PatchField, GeoMesh>::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 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 Type& value,
const dimensionSet& dims,
const wordList& patchFieldTypes,
const wordList& actualPatchTypes
)
{
return GeometricField<Type, PatchField, GeoMesh>::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<Type, PatchField, GeoMesh>::New
const wordList& actualPatchTypes
)
{
auto ptr = tmp<GeometricField<Type, PatchField, GeoMesh>>::New
return GeometricField<Type, PatchField, GeoMesh>::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 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 dimensioned<Type>& dt,
const word& patchFieldType
)
{
return GeometricField<Type, PatchField, GeoMesh>::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<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 dimensioned<Type>& dt,
const wordList& patchFieldTypes,
const wordList& actualPatchTypes
)
{
return GeometricField<Type, PatchField, GeoMesh>::New
(
name,
regOpt,
mesh,
dt.value(),
dt.dimensions(),
patchFieldTypes,
actualPatchTypes
);
}
template<class Type, template<class> class PatchField, class GeoMesh>
Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>>
Foam::GeometricField<Type, PatchField, GeoMesh>::New

View File

@ -89,7 +89,7 @@ void Foam::heThermo<BasicThermo, MixtureType>::init
this->heBoundaryCorrection(he);
// Note: T does not have oldTime
if (p.nOldTimes() > 0)
if (p.nOldTimes())
{
init(p.oldTime(), T.oldTime(), he.oldTime());
}