From 31dd5faf7d043f1d775934453cb77eb28197b837 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Tue, 10 Mar 2009 13:53:36 +0000
Subject: [PATCH] sliced fields as unallocated copies

---
 .../SlicedGeometricField.C                    | 120 ++++++++++++++++++
 .../SlicedGeometricField.H                    |  34 ++++-
 .../basic/sliced/slicedFvPatchField.C         |   8 +-
 .../basic/sliced/slicedFvPatchField.H         |   2 +-
 .../basic/sliced/slicedFvsPatchField.C        |   8 +-
 5 files changed, 155 insertions(+), 17 deletions(-)

diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
index 1bea3b3a535..3043b103aa3 100644
--- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
+++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C
@@ -97,6 +97,68 @@ slicedBoundaryField
 }
 
 
+template
+<
+    class Type,
+    template<class> class PatchField,
+    template<class> class SlicedPatchField,
+    class GeoMesh
+>
+Foam::tmp<Foam::FieldField<PatchField, Type> >
+Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
+slicedBoundaryField
+(
+    const Mesh& mesh,
+    const FieldField<PatchField, Type>& bField,
+    const bool preserveCouples
+)
+{
+    tmp<FieldField<PatchField, Type> > tbf
+    (
+        new FieldField<PatchField, Type>(mesh.boundary().size())
+    );
+
+    FieldField<PatchField, Type>& bf = tbf();
+
+    forAll (mesh.boundary(), patchi)
+    {
+        if (preserveCouples && mesh.boundary()[patchi].coupled())
+        {
+            // For coupled patched construct the correct patch field type
+            bf.set
+            (
+                patchi,
+                PatchField<Type>::New
+                (
+                    mesh.boundary()[patchi].type(),
+                    mesh.boundary()[patchi],
+                    *this
+                )
+            );
+
+            // Assign field
+            bf[patchi] == bField[patchi];
+        }
+        else
+        {
+            // Create unallocated copy of patch field
+            bf.set
+            (
+                patchi,
+                new SlicedPatchField<Type>
+                (
+                    mesh.boundary()[patchi],
+                    DimensionedField<Type, GeoMesh>::null()
+                )
+            );
+            bf[patchi].UList<Type>::operator=(bField[patchi]);
+        }
+    }
+
+    return tbf;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 template
@@ -204,6 +266,64 @@ SlicedGeometricField
 }
 
 
+template
+<
+    class Type,
+    template<class> class PatchField,
+    template<class> class SlicedPatchField,
+    class GeoMesh
+>
+Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
+SlicedGeometricField
+(
+    const IOobject& io,
+    const GeometricField<Type, PatchField, GeoMesh>& gf,
+    const bool preserveCouples
+)
+:
+    GeometricField<Type, PatchField, GeoMesh>
+    (
+        io,
+        gf.mesh(),
+        gf.dimensions(),
+        Field<Type>(),
+        slicedBoundaryField(gf.mesh(), gf.boundaryField(), preserveCouples)
+    )
+{
+    // Set the internalField to the supplied internal field
+    UList<Type>::operator=(gf.internalField());
+
+    correctBoundaryConditions();
+}
+
+
+template
+<
+    class Type,
+    template<class> class PatchField,
+    template<class> class SlicedPatchField,
+    class GeoMesh
+>
+Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
+SlicedGeometricField
+(
+    const SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>& gf
+)
+:
+    GeometricField<Type, PatchField, GeoMesh>
+    (
+        gf,
+        gf.mesh(),
+        gf.dimensions(),
+        Field<Type>(),
+        slicedBoundaryField(gf.mesh(), gf.boundaryField(), true)
+    )
+{
+    // Set the internalField to the supplied internal field
+    UList<Type>::operator=(gf.internalField());
+}
+
+
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
 template
diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
index 10f75917b5a..81c41fd5051 100644
--- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
+++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H
@@ -87,8 +87,17 @@ private:
             const bool preserveCouples
         );
 
-        //- Disallow default bitwise copy construct
-        SlicedGeometricField(const SlicedGeometricField&);
+        //- Slice the given field and a create a PtrList of SlicedPatchField
+        //  from which the boundary field is built
+        tmp<FieldField<PatchField, Type> >  slicedBoundaryField
+        (
+            const Mesh& mesh,
+            const FieldField<PatchField, Type>& bField,
+            const bool preserveCouples
+        );
+
+        ////- Disallow default bitwise copy construct
+        //SlicedGeometricField(const SlicedGeometricField&);
 
         //- Disallow default bitwise assignment
         void operator=(const SlicedGeometricField&);
@@ -128,6 +137,27 @@ public:
             const bool preserveCouples=true
         );
 
+        //- Construct from GeometricField. Reuses full internal and
+        //  patch fields except on couples (preserveCouples=true).
+        SlicedGeometricField
+        (
+            const IOobject&,
+            const GeometricField<Type, PatchField, GeoMesh>&,
+            const bool preserveCouples=true
+        );
+
+        //- Construct as copy
+        SlicedGeometricField
+        (
+            const SlicedGeometricField
+            <
+                Type,
+                PatchField,
+                SlicedPatchField,
+                GeoMesh
+            >&
+        );
+
 
     // Destructor
 
diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
index 47670dea8cd..8643dba429d 100644
--- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
@@ -56,13 +56,7 @@ slicedFvPatchField<Type>::slicedFvPatchField
 )
 :
     fvPatchField<Type>(p, iF)
-{
-    notImplemented
-    (
-        "slicedFvPatchField<Type>::"
-        "slicedFvPatchField(const fvPatch&, const Field<Type>&)"
-    );
-}
+{}
 
 
 template<class Type>
diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
index c712e5bb5ff..3d73cfc08db 100644
--- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
@@ -75,7 +75,7 @@ public:
             const Field<Type>&
         );
 
-        //- Construct from patch and internal field
+        //- Construct from patch and internal field. Assign value later.
         slicedFvPatchField
         (
             const fvPatch&,
diff --git a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C
index 9dffe160d9f..7e4174119b0 100644
--- a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C
@@ -56,13 +56,7 @@ slicedFvsPatchField<Type>::slicedFvsPatchField
 )
 :
     fvsPatchField<Type>(p, iF)
-{
-    notImplemented
-    (
-        "slicedFvsPatchField<Type>::"
-        "slicedFvsPatchField(const fvPatch&, const Field<Type>&)"
-    );
-}
+{}
 
 
 template<class Type>
-- 
GitLab