From 80a416d2535d14dee78d03f175992c48096548f0 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 17 Mar 2023 18:19:41 +0100
Subject: [PATCH] ENH: support construct Geometric field from separate
 value/dimensions

- can be easier to specify than copying into a dimensioned type.

  Eg,
      volSymmTensorField(io, mesh, Zero, dimLength);

      fluxFieldType
      (
          io
          mesh,
          Zero,
          Uf.dimensions()*dimArea/dimTime
      );

  vs
      volSymmTensorField
      (
          io,
          mesh,
          dimensionedSymmTensor("0", dimLength, Zero)
      );

      fluxFieldType
      (
          io
          mesh,
          dimensioned<typename flux<Type>::type>
          (
              Uf.dimensions()*dimArea/dimTime, Zero
          )
      );
---
 src/OpenFOAM/dimensionSet/dimensionSet.H      |   2 +
 src/OpenFOAM/dimensionSet/dimensionSets.H     |   4 +-
 .../DimensionedField/DimensionedField.C       |  29 ++++-
 .../DimensionedField/DimensionedField.H       |  40 +++++--
 .../DimensionedField/DimensionedFieldIO.C     |   8 +-
 .../DimensionedField/DimensionedFieldNew.C    |  50 +++++---
 .../DimensionedField/SlicedDimensionedField.H |   4 +-
 .../GeometricField/GeometricField.C           |  93 +++++++++++----
 .../GeometricField/GeometricField.H           |  82 +++++++++++--
 .../GeometricField/GeometricFieldNew.C        | 108 +++++++++++++++---
 .../SlicedGeometricField.C                    |   8 +-
 .../SlicedGeometricField.H                    |   4 +-
 12 files changed, 343 insertions(+), 89 deletions(-)

diff --git a/src/OpenFOAM/dimensionSet/dimensionSet.H b/src/OpenFOAM/dimensionSet/dimensionSet.H
index b50571a767d..1c21e90f32f 100644
--- a/src/OpenFOAM/dimensionSet/dimensionSet.H
+++ b/src/OpenFOAM/dimensionSet/dimensionSet.H
@@ -433,6 +433,8 @@ dimensionSet operator&&(const dimensionSet& ds1, const dimensionSet& ds2);
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// Predefined dimensions (eg, dimless, dimMass, dimLength, dimTime, ...)
+// and unit systems
 #include "dimensionSets.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/dimensionSet/dimensionSets.H b/src/OpenFOAM/dimensionSet/dimensionSets.H
index b11797db0bd..a4f9c63f62b 100644
--- a/src/OpenFOAM/dimensionSet/dimensionSets.H
+++ b/src/OpenFOAM/dimensionSet/dimensionSets.H
@@ -34,8 +34,8 @@ SourceFiles
 
 \*---------------------------------------------------------------------------*/
 
-#ifndef dimensionSets_H
-#define dimensionSets_H
+#ifndef Foam_dimensionSets_H
+#define Foam_dimensionSets_H
 
 #include "scalarMatrices.H"
 #include "dimensionedScalarFwd.H"
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
index fad69810217..44168d5024a 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -168,14 +168,15 @@ Foam::DimensionedField<Type, GeoMesh>::DimensionedField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensioned<Type>& dt,
+    const Type& value,
+    const dimensionSet& dims,
     const bool checkIOFlags
 )
 :
     regIOobject(io),
-    Field<Type>(GeoMesh::size(mesh), dt.value()),
+    Field<Type>(GeoMesh::size(mesh), value),
     mesh_(mesh),
-    dimensions_(dt.dimensions()),
+    dimensions_(dims),
     oriented_()
 {
     if (checkIOFlags)
@@ -185,6 +186,26 @@ Foam::DimensionedField<Type, GeoMesh>::DimensionedField
 }
 
 
+template<class Type, class GeoMesh>
+Foam::DimensionedField<Type, GeoMesh>::DimensionedField
+(
+    const IOobject& io,
+    const Mesh& mesh,
+    const dimensioned<Type>& dt,
+    const bool checkIOFlags
+)
+:
+    DimensionedField<Type, GeoMesh>
+    (
+        io,
+        mesh,
+        dt.value(),
+        dt.dimensions(),
+        checkIOFlags
+    )
+{}
+
+
 template<class Type, class GeoMesh>
 Foam::DimensionedField<Type, GeoMesh>::DimensionedField
 (
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H
index 72ee48bb72a..60b3de87759 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-2022 OpenCFD Ltd.
+    Copyright (C) 2015-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -165,8 +165,8 @@ public:
             const tmp<Field<Type>>& tfield
         );
 
-        //- Construct from components, setting the initial size and assigning
-        //- the dimensions, but not initialising any field values.
+        //- Construct from components, setting initial size and dimensions,
+        //- but not initialising any field values.
         //  Used for temporary fields which are initialised after construction
         DimensionedField
         (
@@ -176,9 +176,20 @@ public:
             const bool checkIOFlags = true
         );
 
-        //- Construct from components, setting the initial size and assigning
-        //- both dimensions and values.
-        //  The internal name for the dimensioned\<Type\> has no influence.
+        //- Construct from components, setting dimensions and initial
+        //- uniform field value.
+        DimensionedField
+        (
+            const IOobject& io,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims,
+            const bool checkIOFlags = true
+        );
+
+        //- Construct from components, setting dimensions and initial
+        //- uniform field value.
+        //  The name of the dimensioned\<Type\> has no influence.
         DimensionedField
         (
             const IOobject& io,
@@ -292,7 +303,7 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const Field<Type>& iField
         );
 
@@ -304,7 +315,7 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             Field<Type>&& iField
         );
 
@@ -315,7 +326,18 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds
+            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
+        static tmp<DimensionedField<Type, GeoMesh>> New
+        (
+            const word& name,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims
         );
 
         //- Return tmp field from name, mesh, dimensioned\<Type\>.
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C
index 0f27a6fb1d6..c17948b4ae1 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldIO.C
@@ -49,8 +49,12 @@ void Foam::DimensionedField<Type, GeoMesh>::readField
         oriented_.read(fieldDict);
     }
 
-    Field<Type> f(fieldDictEntry, fieldDict, GeoMesh::size(mesh_));
-    this->transfer(f);
+
+    // The primitive field
+    auto& fld = static_cast<Field<Type>&>(*this);
+
+    fld.resize_nocopy(GeoMesh::size(mesh_));
+    fld.assign(fieldDictEntry, fieldDict, fld.size());
 }
 
 
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldNew.C
index 8caf9d2b68a..2c57d75fd98 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 OpenCFD Ltd.
+    Copyright (C) 2022-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -33,7 +33,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& iField
 )
 {
@@ -49,7 +49,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
+        dims,
         iField
     );
 }
@@ -61,7 +61,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     Field<Type>&& iField
 )
 {
@@ -77,7 +77,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
+        dims,
         std::move(iField)
     );
 }
@@ -89,7 +89,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds
+    const dimensionSet& dims
 )
 {
     return tmp<DimensionedField<Type, GeoMesh>>::New
@@ -104,8 +104,8 @@ Foam::DimensionedField<Type, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
-        false  // checkIOFlags = true
+        dims,
+        false  // checkIOFlags off
     );
 }
 
@@ -116,7 +116,8 @@ Foam::DimensionedField<Type, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensioned<Type>& dt
+    const Type& value,
+    const dimensionSet& dims
 )
 {
     return tmp<DimensionedField<Type, GeoMesh>>::New
@@ -131,8 +132,28 @@ Foam::DimensionedField<Type, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        dt,
-        false  // checkIOFlags = true
+        value,
+        dims,
+        false  // checkIOFlags off
+    );
+}
+
+
+template<class Type, class GeoMesh>
+Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
+Foam::DimensionedField<Type, GeoMesh>::New
+(
+    const word& name,
+    const Mesh& mesh,
+    const dimensioned<Type>& dt
+)
+{
+    return DimensionedField<Type, GeoMesh>::New
+    (
+        name,
+        mesh,
+        dt.value(),
+        dt.dimensions()
     );
 }
 
@@ -141,7 +162,7 @@ template<class Type, class GeoMesh>
 Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
 Foam::DimensionedField<Type, GeoMesh>::New
 (
-    const word& newName,
+    const word& name,
     const tmp<DimensionedField<Type, GeoMesh>>& tfld
 )
 {
@@ -149,7 +170,7 @@ Foam::DimensionedField<Type, GeoMesh>::New
     (
         IOobject
         (
-            newName,
+            name,
             tfld().instance(),
             tfld().local(),
             tfld().db(),
@@ -211,7 +232,8 @@ Foam::DimensionedField<Type, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         fld.mesh(),
-        dt
+        dt.value(),
+        dt.dimensions()
     );
 }
 
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H
index d9ad2fb5fc0..9f6df361ac9 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H
@@ -67,11 +67,11 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const Field<Type>& iField
         )
         :
-            DimensionedField<Type, GeoMesh>(io, mesh, ds, Field<Type>())
+            DimensionedField<Type, GeoMesh>(io, mesh, dims, Field<Type>())
         {
             // Set internalField to the slice of the complete field
             UList<Type>::shallowCopy
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
index af2ef82dd95..3756d2208e9 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
@@ -193,18 +193,18 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const word& patchFieldType
 )
 :
-    Internal(io, mesh, ds, false),
+    Internal(io, mesh, dims, false),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
     boundaryField_(mesh.boundary(), *this, patchFieldType)
 {
     DebugInFunction
-        << "Creating temporary" << nl << this->info() << endl;
+        << "Creating" << nl << this->info() << endl;
 
     readIfPresent();
 }
@@ -215,43 +215,45 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const wordList& patchFieldTypes,
     const wordList& actualPatchTypes
 )
 :
-    Internal(io, mesh, ds, false),
+    Internal(io, mesh, dims, false),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
     boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes)
 {
     DebugInFunction
-        << "Creating temporary" << nl << this->info() << endl;
+        << "Creating" << nl << this->info() << endl;
 
     readIfPresent();
 }
 
 
+
 template<class Type, template<class> class PatchField, class GeoMesh>
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensioned<Type>& dt,
+    const Type& value,
+    const dimensionSet& dims,
     const word& patchFieldType
 )
 :
-    Internal(io, mesh, dt, false),
+    Internal(io, mesh, value, dims, false),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
     boundaryField_(mesh.boundary(), *this, patchFieldType)
 {
     DebugInFunction
-        << "Creating temporary" << nl << this->info() << endl;
+        << "Creating" << nl << this->info() << endl;
 
-    boundaryField_ == dt.value();
+    boundaryField_ == value;
 
     readIfPresent();
 }
@@ -262,26 +264,69 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensioned<Type>& dt,
+    const Type& value,
+    const dimensionSet& dims,
     const wordList& patchFieldTypes,
     const wordList& actualPatchTypes
 )
 :
-    Internal(io, mesh, dt, false),
+    Internal(io, mesh, value, dims, false),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
     boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes)
 {
     DebugInFunction
-        << "Creating temporary" << nl << this->info() << endl;
+        << "Creating" << nl << this->info() << endl;
 
-    boundaryField_ == dt.value();
+    boundaryField_ == value;
 
     readIfPresent();
 }
 
 
+template<class Type, template<class> class PatchField, class GeoMesh>
+Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
+(
+    const IOobject& io,
+    const Mesh& mesh,
+    const dimensioned<Type>& dt,
+    const word& patchFieldType
+)
+:
+    GeometricField<Type, PatchField, GeoMesh>
+    (
+        io,
+        mesh,
+        dt.value(),
+        dt.dimensions(),
+        patchFieldType
+    )
+{}
+
+
+template<class Type, template<class> class PatchField, class GeoMesh>
+Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
+(
+    const IOobject& io,
+    const Mesh& mesh,
+    const dimensioned<Type>& dt,
+    const wordList& patchFieldTypes,
+    const wordList& actualPatchTypes
+)
+:
+    GeometricField<Type, PatchField, GeoMesh>
+    (
+        io,
+        mesh,
+        dt.value(),
+        dt.dimensions(),
+        patchFieldTypes,
+        actualPatchTypes
+    )
+{}
+
+
 template<class Type, template<class> class PatchField, class GeoMesh>
 Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
@@ -390,12 +435,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& iField,
     const word& patchFieldType
 )
 :
-    Internal(io, mesh, ds, iField),
+    Internal(io, mesh, dims, iField),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
@@ -413,12 +458,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     Field<Type>&& iField,
     const word& patchFieldType
 )
 :
-    Internal(io, mesh, ds, std::move(iField)),
+    Internal(io, mesh, dims, std::move(iField)),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
@@ -436,12 +481,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& iField,
     const PtrList<PatchField<Type>>& ptfl
 )
 :
-    Internal(io, mesh, ds, iField),
+    Internal(io, mesh, dims, iField),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
@@ -459,12 +504,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     Field<Type>&& iField,
     const PtrList<PatchField<Type>>& ptfl
 )
 :
-    Internal(io, mesh, ds, std::move(iField)),
+    Internal(io, mesh, dims, std::move(iField)),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
@@ -482,12 +527,12 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const tmp<Field<Type>>& tfield,
     const PtrList<PatchField<Type>>& ptfl
 )
 :
-    Internal(io, mesh, ds, tfield),
+    Internal(io, mesh, dims, tfield),
     timeIndex_(this->time().timeIndex()),
     field0Ptr_(nullptr),
     fieldPrevIterPtr_(nullptr),
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H
index d7fffa0d238..eaa54bab721 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H
@@ -155,7 +155,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const word& patchFieldType = PatchField<Type>::calculatedType()
         );
 
@@ -166,7 +166,32 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
+            const wordList& wantedPatchTypes,
+            const wordList& actualPatchTypes = wordList()
+        );
+
+        //- Construct given IOobject, mesh, dimensions, initial field value
+        //- and given patch type.
+        //  This assigns both dimensions and values.
+        GeometricField
+        (
+            const IOobject& io,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims,
+            const word& patchFieldType = PatchField<Type>::calculatedType()
+        );
+
+        //- Construct given IOobject, mesh, dimensions, initial field value
+        //- and given patch types.
+        //  This assigns both dimensions and values.
+        GeometricField
+        (
+            const IOobject& io,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims,
             const wordList& wantedPatchTypes,
             const wordList& actualPatchTypes = wordList()
         );
@@ -237,7 +262,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const Field<Type>& iField,
             const word& patchFieldType = PatchField<Type>::calculatedType()
         );
@@ -247,7 +272,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             Field<Type>&& iField,
             const word& patchFieldType = PatchField<Type>::calculatedType()
         );
@@ -257,7 +282,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const Field<Type>& iField,
             const PtrList<PatchField<Type>>& ptfl
         );
@@ -267,7 +292,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             Field<Type>&& iField,
             const PtrList<PatchField<Type>>& ptfl
         );
@@ -277,7 +302,7 @@ public:
         (
             const IOobject& io,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const tmp<Field<Type>>& tiField,
             const PtrList<PatchField<Type>>& ptfl
         );
@@ -387,7 +412,7 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const word& patchFieldType = PatchField<Type>::calculatedType()
         );
 
@@ -399,7 +424,7 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             const Field<Type>& iField,
             const word& patchFieldType = PatchField<Type>::calculatedType()
         );
@@ -412,11 +437,38 @@ public:
         (
             const word& name,
             const Mesh& mesh,
-            const dimensionSet& ds,
+            const dimensionSet& dims,
             Field<Type>&& iField,
             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
+        static tmp<GeometricField<Type, PatchField, GeoMesh>> New
+        (
+            const word& name,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims,
+            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
+        static tmp<GeometricField<Type, PatchField, GeoMesh>> New
+        (
+            const word& name,
+            const Mesh& mesh,
+            const Type& value,
+            const dimensionSet& dims,
+            const wordList& patchFieldTypes,
+            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
@@ -451,6 +503,16 @@ public:
             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
+        static tmp<GeometricField<Type, PatchField, GeoMesh>> New
+        (
+            const word& newName,
+            const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf,
+            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
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldNew.C
index 5c0b0cb8220..8aa3f79d7fc 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-2022 OpenCFD Ltd.
+    Copyright (C) 2019-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -34,7 +34,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const word& patchFieldType
 )
 {
@@ -50,7 +50,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
+        dims,
         patchFieldType
     );
 }
@@ -62,7 +62,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& iField,
     const word& patchFieldType
 )
@@ -79,7 +79,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
+        dims,
         iField,
         patchFieldType
     );
@@ -92,7 +92,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     Field<Type>&& iField,
     const word& patchFieldType
 )
@@ -109,7 +109,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        ds,
+        dims,
         std::move(iField),
         patchFieldType
     );
@@ -122,7 +122,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensioned<Type>& dt,
+    const Type& value,
+    const dimensionSet& dims,
     const word& patchFieldType
 )
 {
@@ -138,7 +139,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        dt,
+        value,
+        dims,
         patchFieldType
     );
 }
@@ -150,7 +152,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
     const word& name,
     const Mesh& mesh,
-    const dimensioned<Type>& dt,
+    const Type& value,
+    const dimensionSet& dims,
     const wordList& patchFieldTypes,
     const wordList& actualPatchTypes
 )
@@ -167,7 +170,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         mesh,
-        dt,
+        value,
+        dims,
         patchFieldTypes,
         actualPatchTypes
     );
@@ -178,7 +182,78 @@ template<class Type, template<class> class PatchField, class GeoMesh>
 Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>>
 Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
-    const word& newName,
+    const word& name,
+    const Mesh& mesh,
+    const dimensioned<Type>& dt,
+    const word& patchFieldType
+)
+{
+    return GeometricField<Type, PatchField, GeoMesh>::New
+    (
+        name,
+        mesh,
+        dt.value(),
+        dt.dimensions(),
+        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 dimensioned<Type>& dt,
+    const wordList& patchFieldTypes,
+    const wordList& actualPatchTypes
+)
+{
+    return GeometricField<Type, PatchField, GeoMesh>::New
+    (
+        name,
+        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
+(
+    const word& name,
+    const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf,
+    const word& patchFieldType
+)
+{
+    return tmp<GeometricField<Type, PatchField, GeoMesh>>::New
+    (
+        IOobject
+        (
+            name,
+            tgf().instance(),
+            tgf().local(),
+            tgf().db(),
+            IOobjectOption::NO_READ,
+            IOobjectOption::NO_WRITE,
+            IOobjectOption::NO_REGISTER
+        ),
+        tgf,
+        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 tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf
 )
 {
@@ -186,7 +261,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
     (
         IOobject
         (
-            newName,
+            name,
             tgf().instance(),
             tgf().local(),
             tgf().db(),
@@ -203,7 +278,7 @@ template<class Type, template<class> class PatchField, class GeoMesh>
 Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>>
 Foam::GeometricField<Type, PatchField, GeoMesh>::New
 (
-    const word& newName,
+    const word& name,
     const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf,
     const wordList& patchFieldTypes,
     const wordList& actualPatchTypes
@@ -213,7 +288,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
     (
         IOobject
         (
-            newName,
+            name,
             tgf().instance(),
             tgf().local(),
             tgf().db(),
@@ -280,7 +355,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::New
             IOobjectOption::NO_REGISTER
         ),
         fld.mesh(),
-        dt,
+        dt.value(),
+        dt.dimensions(),
         patchFieldType
     );
 }
diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
index efa92277d22..2b378137fd4 100644
--- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
+++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
@@ -201,7 +201,7 @@ SlicedGeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& completeField,
     const bool preserveCouples
 )
@@ -210,7 +210,7 @@ SlicedGeometricField
     (
         io,
         mesh,
-        ds,
+        dims,
         Field<Type>(),
         // preserveProcessorOnly = false
         // isBoundaryOnly = false
@@ -239,7 +239,7 @@ SlicedGeometricField
 (
     const IOobject& io,
     const Mesh& mesh,
-    const dimensionSet& ds,
+    const dimensionSet& dims,
     const Field<Type>& completeIField,
     const Field<Type>& completeBField,
     const bool preserveCouples,
@@ -250,7 +250,7 @@ SlicedGeometricField
     (
         io,
         mesh,
-        ds,
+        dims,
         Field<Type>(),
         makeBoundary
         (
diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
index 1ae1df29a86..d26923f8b5f 100644
--- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
+++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
@@ -140,7 +140,7 @@ public:
         (
             const IOobject&,
             const Mesh&,
-            const dimensionSet&,
+            const dimensionSet& dims,
             const Field<Type>& completeField,
             const bool preserveCouples = true
         );
@@ -151,7 +151,7 @@ public:
         (
             const IOobject&,
             const Mesh&,
-            const dimensionSet&,
+            const dimensionSet& dims,
             const Field<Type>& completeIField,
             const Field<Type>& completeBField,
             const bool preserveCouples = true,
-- 
GitLab