From 82c405882dc7b944b0635f570054c138e5f3643d Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 14 Dec 2021 16:07:18 +0000
Subject: [PATCH] ENH: fvPatch: allow explicit coupled provision for any patch.

---
 src/OpenFOAM/Make/files                       |  2 +
 .../polyPatches/polyPatch/polyPatch.C         | 12 ++++++
 .../polyPatches/polyPatch/polyPatch.H         | 13 +++++-
 src/finiteVolume/Make/files                   |  9 +++--
 .../fvsPatchField/fvsPatchFields.C            | 26 ++++++++++++
 .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.C    |  7 +++-
 src/finiteVolume/fvMesh/fvMesh.C              |  2 +
 .../fvPatches/basic/coupled/coupledFvPatch.H  |  2 +-
 .../fvMesh/fvPatches/fvPatch/fvPatch.H        | 40 +++++++++++++++++++
 .../simpleFoam/pitzDaily/system/blockMeshDict |  1 +
 10 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index 517293dbee8..60c4b1fd689 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -458,6 +458,8 @@ $(GAMGInterfaces)/GAMGInterface/GAMGInterfaceNew.C
 $(GAMGInterfaces)/processorGAMGInterface/processorGAMGInterface.C
 $(GAMGInterfaces)/processorCyclicGAMGInterface/processorCyclicGAMGInterface.C
 $(GAMGInterfaces)/cyclicGAMGInterface/cyclicGAMGInterface.C
+$(GAMGInterfaces)/primitiveGAMGInterface/primitiveGAMGInterface.C
+
 
 GAMGInterfaceFields = $(GAMG)/interfaceFields
 $(GAMGInterfaceFields)/GAMGInterfaceField/GAMGInterfaceField.C
diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
index 61be2728178..08bcdf49343 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
@@ -97,6 +97,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(start),
     boundaryMesh_(bm),
+    coupled_(false),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {
@@ -126,6 +127,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(start),
     boundaryMesh_(bm),
+    coupled_(false),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {}
@@ -153,6 +155,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(dict.get<label>("startFace")),
     boundaryMesh_(bm),
+    coupled_(dict.getOrDefault<bool>("coupled", false)),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {
@@ -160,6 +163,10 @@ Foam::polyPatch::polyPatch
     {
         inGroups().appendUniq(patchType);
     }
+
+DebugVar(name);
+DebugVar(coupled_);
+
 }
 
 
@@ -182,6 +189,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(pp.start()),
     boundaryMesh_(bm),
+    coupled_(pp.coupled()),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {}
@@ -209,6 +217,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(newStart),
     boundaryMesh_(bm),
+    coupled_(pp.coupled()),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {}
@@ -236,6 +245,7 @@ Foam::polyPatch::polyPatch
     ),
     start_(newStart),
     boundaryMesh_(bm),
+    coupled_(pp.coupled()),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {}
@@ -247,6 +257,7 @@ Foam::polyPatch::polyPatch(const polyPatch& p)
     primitivePatch(p),
     start_(p.start_),
     boundaryMesh_(p.boundaryMesh_),
+    coupled_(p.coupled()),
     faceCellsPtr_(nullptr),
     mePtr_(nullptr)
 {}
@@ -416,6 +427,7 @@ void Foam::polyPatch::write(Ostream& os) const
     patchIdentifier::write(os);
     os.writeEntry("nFaces", size());
     os.writeEntry("startFace", start());
+    os.writeEntryIfDifferent<bool>("coupled", false, coupled_);
 }
 
 
diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H
index 2dc4b2c00d3..22b158e189d 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H
@@ -79,6 +79,10 @@ class polyPatch
         //- Reference to boundary mesh
         const polyBoundaryMesh& boundaryMesh_;
 
+        //- Whether supports lduInterface (usually overriden by 'proper'
+        //  constraint coupled patches)
+        bool coupled_;
+
         //- Demand-driven: face-cell addressing
         mutable labelList::subList* faceCellsPtr_;
 
@@ -377,7 +381,14 @@ public:
         //  points correspondence)
         virtual bool coupled() const
         {
-            return false;
+            return coupled_;
+        }
+
+        //- Return true if this patch is geometrically coupled (i.e. faces and
+        //  points correspondence)
+        virtual void coupled(const bool coupled)
+        {
+            coupled_ = coupled;
         }
 
         //- Return true if the given type is a constraint type
diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files
index 8b184cfaf18..973fb90ff32 100644
--- a/src/finiteVolume/Make/files
+++ b/src/finiteVolume/Make/files
@@ -1,3 +1,8 @@
+fvPatches = fvMesh/fvPatches
+$(fvPatches)/fvPatch/fvPatch.C
+$(fvPatches)/fvPatch/fvPatchNew.C
+
+
 fvMesh/fvMeshGeometry.C
 fvMesh/fvMesh.C
 
@@ -21,10 +26,6 @@ fvMesh/simplifiedFvMesh/hexCellFvMesh/hexCellFvMesh.C
 fvBoundaryMesh = fvMesh/fvBoundaryMesh
 $(fvBoundaryMesh)/fvBoundaryMesh.C
 
-fvPatches = fvMesh/fvPatches
-$(fvPatches)/fvPatch/fvPatch.C
-$(fvPatches)/fvPatch/fvPatchNew.C
-
 basicFvPatches = $(fvPatches)/basic
 $(basicFvPatches)/coupled/coupledFvPatch.C
 $(basicFvPatches)/generic/genericFvPatch.C
diff --git a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C
index 804de5295fb..961ca0c990f 100644
--- a/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C
+++ b/src/finiteVolume/fields/fvsPatchFields/fvsPatchField/fvsPatchFields.C
@@ -26,6 +26,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "fvsPatchFields.H"
+#include "addToRunTimeSelectionTable.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -52,6 +53,31 @@ makeFvsPatchField(fvsPatchSphericalTensorField)
 makeFvsPatchField(fvsPatchSymmTensorField)
 makeFvsPatchField(fvsPatchTensorField)
 
+//- If running with coupled basic patch make sure PatchField<Type>::New
+//- works. TBD: avoid fvsPatchField but go through to SlicedPatchField?
+//- (see SlicedGeometricField::slicedBoundaryField)
+addNamedToRunTimeSelectionTable
+(
+    fvsPatchScalarField, fvsPatchScalarField, patch, patch
+);
+addNamedToRunTimeSelectionTable
+(
+    fvsPatchVectorField, fvsPatchVectorField, patch, patch
+);
+addNamedToRunTimeSelectionTable
+(
+    fvsPatchSphericalTensorField, fvsPatchSphericalTensorField, patch, patch
+);
+addNamedToRunTimeSelectionTable
+(
+    fvsPatchSymmTensorField, fvsPatchSymmTensorField, patch, patch
+);
+addNamedToRunTimeSelectionTable
+(
+    fvsPatchTensorField, fvsPatchTensorField, patch, patch
+);
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C
index f39a55d2c33..89f5d56247a 100644
--- a/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C
+++ b/src/finiteVolume/fvMesh/fvBoundaryMesh/fvBoundaryMesh.C
@@ -150,14 +150,19 @@ Foam::lduInterfacePtrsList Foam::fvBoundaryMesh::interfaces() const
 {
     const fvPatchList& patches = *this;
 
+DebugVar(patches.size());
     lduInterfacePtrsList list(patches.size());
 
     forAll(list, patchi)
     {
         const lduInterface* lduPtr = isA<lduInterface>(patches[patchi]);
 
-        if (lduPtr)
+        if (lduPtr && patches[patchi].coupled())
         {
+Pout<< "** fvBoundaryMesh : adding patch " << patches[patchi].name()
+    << " at index:" << patchi
+    << endl;
+
             list.set(patchi, lduPtr);
         }
     }
diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C
index 283fa43a38a..c86026b76aa 100644
--- a/src/finiteVolume/fvMesh/fvMesh.C
+++ b/src/finiteVolume/fvMesh/fvMesh.C
@@ -707,6 +707,8 @@ const Foam::lduAddressing& Foam::fvMesh::lduAddr() const
 
 Foam::lduInterfacePtrsList Foam::fvMesh::interfaces() const
 {
+DebugVar("here");
+
     return boundary().interfaces();
 }
 
diff --git a/src/finiteVolume/fvMesh/fvPatches/basic/coupled/coupledFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/basic/coupled/coupledFvPatch.H
index f334ab2f2ab..724d8cd172c 100644
--- a/src/finiteVolume/fvMesh/fvPatches/basic/coupled/coupledFvPatch.H
+++ b/src/finiteVolume/fvMesh/fvPatches/basic/coupled/coupledFvPatch.H
@@ -53,7 +53,7 @@ namespace Foam
 
 class coupledFvPatch
 :
-    public lduInterface,
+//    public lduInterface,
     public fvPatch
 {
     // Private data
diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
index 7ef94de2ab9..e5684d6f2b5 100644
--- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
+++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
@@ -49,6 +49,7 @@ SourceFiles
 #include "fvPatchFieldsFwd.H"
 #include "autoPtr.H"
 #include "runTimeSelectionTables.H"
+#include "lduInterface.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -64,6 +65,8 @@ class surfaceInterpolation;
 \*---------------------------------------------------------------------------*/
 
 class fvPatch
+:
+    public lduInterface
 {
     // Private Data
 
@@ -217,6 +220,43 @@ public:
             virtual const labelUList& faceCells() const;
 
 
+        // Interface transfer functions
+
+            //- Return the values of the given internal data adjacent to
+            //- the interface as a field using faceCell mapping
+            virtual tmp<labelField> interfaceInternalField
+            (
+                const labelUList& internalData,
+                const labelUList& faceCells
+            ) const
+            {
+                return tmp<labelField>
+                (
+                    new labelField(internalData, faceCells)
+                );
+            }
+
+            //- Return the values of the given internal data adjacent to
+            //  the interface as a field
+            virtual tmp<labelField> interfaceInternalField
+            (
+                const labelUList& internalData
+            ) const
+            {
+                return interfaceInternalField(internalData, faceCells());
+            }
+
+            //- Transfer and return internal field adjacent to the interface
+            virtual tmp<labelField> internalFieldTransfer
+            (
+                const Pstream::commsTypes commsType,
+                const labelUList& iF
+            ) const
+            {
+                return interfaceInternalField(iF);
+            }
+
+
         // Access functions for geometrical data
 
             //- Return face centres
diff --git a/tutorials/incompressible/simpleFoam/pitzDaily/system/blockMeshDict b/tutorials/incompressible/simpleFoam/pitzDaily/system/blockMeshDict
index ad7d6d03ede..985cf47ccd9 100644
--- a/tutorials/incompressible/simpleFoam/pitzDaily/system/blockMeshDict
+++ b/tutorials/incompressible/simpleFoam/pitzDaily/system/blockMeshDict
@@ -95,6 +95,7 @@ boundary
     inlet
     {
         type patch;
+        coupled true;
         faces
         (
             (0 1 12 11)
-- 
GitLab