From b992b862c0afd99b53c6cc0f2d43ca917abfe37d Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 16 May 2019 10:30:55 +0100
Subject: [PATCH] ENH: overset: allow use in non-dynamicMesh applications

This is to avoid overset interpolation in the calculation of the stencil
itself since this triggers a loop.
---
 .../cellVolumeWeightCellCellStencil.C         | 22 ++++++++++++++++---
 .../inverseDistanceCellCellStencil.C          | 20 ++++++++++++++---
 .../trackingInverseDistanceCellCellStencil.C  | 15 +++++++++++--
 .../dynamicOversetFvMesh.H                    | 18 +++++++--------
 .../dynamicOversetFvMeshTemplates.C           |  3 +--
 5 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C b/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
index 121c8c72443..4f02c9d466c 100644
--- a/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
+++ b/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
@@ -35,6 +35,7 @@ License
 #include "oversetFvPatch.H"
 #include "zeroGradientFvPatchFields.H"
 #include "syncTools.H"
+#include "dynamicOversetFvMesh.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -1116,7 +1117,12 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
         {
             patchTypes[cellI] = allPatchTypes[cellI];
         }
-        patchTypes.correctBoundaryConditions();
+        //patchTypes.correctBoundaryConditions();
+        dynamicOversetFvMesh::correctBoundaryConditions
+        <
+            volScalarField,
+            oversetFvPatchField<scalar>
+        >(patchTypes.boundaryFieldRef(), false);
         patchTypes.write();
     }
     if (debug)
@@ -1141,7 +1147,12 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
         {
             volTypes[cellI] = allCellTypes[cellI];
         }
-        volTypes.correctBoundaryConditions();
+        //volTypes.correctBoundaryConditions();
+        dynamicOversetFvMesh::correctBoundaryConditions
+        <
+            volScalarField,
+            oversetFvPatchField<scalar>
+        >(volTypes.boundaryFieldRef(), false);
         volTypes.write();
     }
 
@@ -1185,7 +1196,12 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
     cellStencil_.transfer(allStencil);
     cellInterpolationWeights_.transfer(allWeights);
     cellInterpolationWeight_.transfer(allWeight);
-    cellInterpolationWeight_.correctBoundaryConditions();
+    //cellInterpolationWeight_.correctBoundaryConditions();
+    dynamicOversetFvMesh::correctBoundaryConditions
+    <
+        volScalarField,
+        oversetFvPatchField<scalar>
+    >(cellInterpolationWeight_.boundaryFieldRef(), false);
 
     DynamicList<label> interpolationCells;
     forAll(cellStencil_, cellI)
diff --git a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
index 9bb6c6fef85..a595d80d15c 100644
--- a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
+++ b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
@@ -37,6 +37,7 @@ License
 #include "waveMethod.H"
 
 #include "regionSplit.H"
+#include "dynamicOversetFvMesh.H"
 //#include "minData.H"
 //#include "FaceCellWave.H"
 
@@ -2152,7 +2153,11 @@ bool Foam::cellCellStencils::inverseDistance::update()
         new mapDistribute(globalCells, cellStencil_, compactMap)
     );
     cellInterpolationWeight_.transfer(allWeight);
-    cellInterpolationWeight_.correctBoundaryConditions();
+    dynamicOversetFvMesh::correctBoundaryConditions
+    <
+        volScalarField,
+        oversetFvPatchField<scalar>
+    >(cellInterpolationWeight_.boundaryFieldRef(), false);
 
 
     if (debug&2)
@@ -2226,7 +2231,11 @@ bool Foam::cellCellStencils::inverseDistance::update()
             (
                 createField(mesh_, "maxMagWeight", maxMagWeight)
             );
-            tfld.ref().correctBoundaryConditions();
+            dynamicOversetFvMesh::correctBoundaryConditions
+            <
+                volScalarField,
+                oversetFvPatchField<scalar>
+            >(tfld.ref().boundaryFieldRef(), false);
             tfld().write();
         }
 
@@ -2236,7 +2245,12 @@ bool Foam::cellCellStencils::inverseDistance::update()
             (
                 createField(mesh_, "cellTypes", cellTypes_)
             );
-            tfld.ref().correctBoundaryConditions();
+            //tfld.ref().correctBoundaryConditions();
+            dynamicOversetFvMesh::correctBoundaryConditions
+            <
+                volScalarField,
+                oversetFvPatchField<scalar>
+            >(tfld.ref().boundaryFieldRef(), false);
             tfld().write();
         }
 
diff --git a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
index db10a358c45..a4c315dd815 100644
--- a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
+++ b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
@@ -34,6 +34,7 @@ License
 #include "syncTools.H"
 #include "treeBoundBoxList.H"
 #include "voxelMeshSearch.H"
+#include "dynamicOversetFvMesh.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -961,7 +962,12 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
         )
     );
     cellInterpolationWeight_.transfer(allWeight);
-    cellInterpolationWeight_.correctBoundaryConditions();
+    //cellInterpolationWeight_.correctBoundaryConditions();
+    dynamicOversetFvMesh::correctBoundaryConditions
+    <
+        volScalarField,
+        oversetFvPatchField<scalar>
+    >(cellInterpolationWeight_.boundaryFieldRef(), false);
 
 
     if (debug & 2)
@@ -1024,7 +1030,12 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
         {
             volTypes[celli] = cellTypes_[celli];
         }
-        volTypes.correctBoundaryConditions();
+        //volTypes.correctBoundaryConditions();
+        dynamicOversetFvMesh::correctBoundaryConditions
+        <
+            volScalarField,
+            oversetFvPatchField<scalar>
+        >(volTypes.boundaryFieldRef(), false);
         volTypes.write();
 
         // Dump stencil
diff --git a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
index ff499f7142b..0f7bfc18ad0 100644
--- a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
+++ b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMesh.H
@@ -128,15 +128,6 @@ protected:
         //template<class GeoField, class PatchType>
         //lduInterfaceFieldPtrsList scalarInterfaces(const GeoField& psi) const;
 
-        //- Correct boundary conditions of certain type (typeOnly = true)
-        //  or explicitly not of the type (typeOnly = false)
-        template<class GeoField, class PatchType>
-        static void correctBoundaryConditions
-        (
-            typename GeoField::Boundary& bfld,
-            const bool typeOnly
-        );
-
         //- Determine normalisation for interpolation. This equals the
         //  original diagonal except stabilised for zero diagonals (possible
         //  in hole cells)
@@ -358,6 +349,15 @@ public:
         //- Debug: check halo swap is ok
         template<class GeoField>
         static void checkCoupledBC(const GeoField& fld);
+
+        //- Correct boundary conditions of certain type (typeOnly = true)
+        //  or explicitly not of the type (typeOnly = false)
+        template<class GeoField, class PatchType>
+        static void correctBoundaryConditions
+        (
+            typename GeoField::Boundary& bfld,
+            const bool typeOnly
+        );
 };
 
 
diff --git a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMeshTemplates.C b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMeshTemplates.C
index a875867238e..f0331304959 100644
--- a/src/overset/dynamicOversetFvMesh/dynamicOversetFvMeshTemplates.C
+++ b/src/overset/dynamicOversetFvMesh/dynamicOversetFvMeshTemplates.C
@@ -155,11 +155,10 @@ Foam::tmp<Foam::scalarField> Foam::dynamicOversetFvMesh::normalisation
     tmp<scalarField> tnorm(tmp<scalarField>::New(m.diag()));
     scalarField& norm = tnorm.ref();
 
-    // Add boundary coeffs to duplicate behaviour of fvMatrix
+    // Add boundary coeffs to duplicate behaviour of fvMatrix::addBoundaryDiag
     const FieldField<Field, Type>& internalCoeffs = m.internalCoeffs();
     for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
     {
-        //m.addBoundaryDiag(norm, cmpt);
         forAll(internalCoeffs, patchi)
         {
             const labelUList& fc = lduAddr().patchAddr(patchi);
-- 
GitLab