From 53be19989bf40a6963016de3dfe3ba208a357a69 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 25 Apr 2019 11:00:32 +0100
Subject: [PATCH] CONTRIBUTION: overset: handling patch interactions. See
 #1288.

- in case of cell overlapping a patch : set cell to hole always
- in case of cell changing from hole to calculated: set to hole
  and continue. Do so before 'flood filling' holes.
Patch supplied by Nicolas Edh.
---
 .../cellVolumeWeightCellCellStencil.C         | 99 ++++++++++---------
 .../inverseDistanceCellCellStencil.C          | 76 +++++++-------
 .../trackingInverseDistanceCellCellStencil.C  | 75 +++++++-------
 3 files changed, 122 insertions(+), 128 deletions(-)

diff --git a/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C b/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
index 8fa1c434b93..121c8c72443 100644
--- a/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
+++ b/src/overset/cellCellStencil/cellVolumeWeight/cellVolumeWeightCellCellStencil.C
@@ -585,18 +585,24 @@ void Foam::cellCellStencils::cellVolumeWeight::combineCellTypes
 
             case PATCH:
             {
-                if (allCellTypes[cellI] != HOLE)
-                {
-                    scalar overlapVol = sum(weights[subCellI]);
-                    scalar v = mesh_.V()[cellI];
-                    if (overlapVol < (1.0-overlapTolerance_)*v)
-                    {
-                        //Pout<< "** Patch overlap:" << cellI
-                        //    << " at:" << mesh_.cellCentres()[cellI] << endl;
-                        allCellTypes[cellI] = HOLE;
-                        validDonors = false;
-                    }
-                }
+                // Patch-patch interaction... For now disable always
+                allCellTypes[cellI] = HOLE;
+                validDonors = false;
+
+                // Alternative is to look at the amount of overlap but this
+                // is not very robust
+                //if (allCellTypes[cellI] != HOLE)
+                //{
+                //    scalar overlapVol = sum(weights[subCellI]);
+                //    scalar v = mesh_.V()[cellI];
+                //    if (overlapVol < (1.0-overlapTolerance_)*v)
+                //    {
+                //        //Pout<< "** Patch overlap:" << cellI
+                //        //    << " at:" << mesh_.cellCentres()[cellI] << endl;
+                //        allCellTypes[cellI] = HOLE;
+                //        validDonors = false;
+                //    }
+                //}
             }
             break;
 
@@ -994,6 +1000,41 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
     }
 
 
+    // Check previous iteration cellTypes_ for any hole->calculated changes
+    // If so set the cell either to interpolated (if there are donors) or
+    // holes (if there are no donors). Note that any interpolated cell might
+    // still be overwritten by the flood filling
+    {
+        label nCalculated = 0;
+
+        forAll(cellTypes_, celli)
+        {
+            if (allCellTypes[celli] == CALCULATED && cellTypes_[celli] == HOLE)
+            {
+                if (allStencil[celli].size() == 0)
+                {
+                    // Reset to hole
+                    allCellTypes[celli] = HOLE;
+                    allWeights[celli].clear();
+                    allStencil[celli].clear();
+                }
+                else
+                {
+                    allCellTypes[celli] = INTERPOLATED;
+                    nCalculated++;
+                }
+            }
+        }
+
+        if (debug)
+        {
+            Pout<< "Detected " << nCalculated << " cells changing from hole"
+                << " to calculated. Changed these to interpolated"
+                << endl;
+        }
+    }
+
+
     // Mark unreachable bits
     findHoles(globalCells, mesh_, zoneID, allStencil, allCellTypes);
 
@@ -1022,40 +1063,6 @@ bool Foam::cellCellStencils::cellVolumeWeight::update()
         tfld().write();
     }
 
-    // Check previous iteration cellTypes_ for any hole->calculated changes
-    {
-        label nCalculated = 0;
-
-        forAll(cellTypes_, celli)
-        {
-            if (allCellTypes[celli] == CALCULATED && cellTypes_[celli] == HOLE)
-            {
-                if (allStencil[celli].size() == 0)
-                {
-                    FatalErrorInFunction
-                        << "Cell:" << celli
-                        << " at:" << mesh_.cellCentres()[celli]
-                        << " zone:" << zoneID[celli]
-                        << " changed from hole to calculated"
-                        << " but there is no donor"
-                        << exit(FatalError);
-                }
-                else
-                {
-                    allCellTypes[celli] = INTERPOLATED;
-                    nCalculated++;
-                }
-            }
-        }
-
-        if (debug)
-        {
-            Pout<< "Detected " << nCalculated << " cells changing from hole"
-                << " to calculated. Changed these to interpolated"
-                << endl;
-        }
-    }
-
     // Normalise weights, Clear storage
     forAll(allCellTypes, cellI)
     {
diff --git a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
index 1e019dab394..9bb6c6fef85 100644
--- a/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
+++ b/src/overset/cellCellStencil/inverseDistance/inverseDistanceCellCellStencil.C
@@ -2048,6 +2048,41 @@ bool Foam::cellCellStencils::inverseDistance::update()
         tfld().write();
     }
 
+
+    // Check previous iteration cellTypes_ for any hole->calculated changes
+    // If so set the cell either to interpolated (if there are donors) or
+    // holes (if there are no donors). Note that any interpolated cell might
+    // still be overwritten by the flood filling
+    {
+        label nCalculated = 0;
+
+        forAll(cellTypes_, celli)
+        {
+            if (allCellTypes[celli] == CALCULATED && cellTypes_[celli] == HOLE)
+            {
+                if (allStencil[celli].size() == 0)
+                {
+                    // Reset to hole
+                    allCellTypes[celli] = HOLE;
+                    allStencil[celli].clear();
+                }
+                else
+                {
+                    allCellTypes[celli] = INTERPOLATED;
+                    nCalculated++;
+                }
+            }
+        }
+
+        if (debug)
+        {
+            Pout<< "Detected " << nCalculated << " cells changing from hole"
+                << " to calculated. Changed to interpolated"
+                << endl;
+        }
+    }
+
+
     // Mark unreachable bits
     findHoles(globalCells, mesh_, zoneID, allStencil, allCellTypes);
 
@@ -2088,47 +2123,6 @@ bool Foam::cellCellStencils::inverseDistance::update()
     }
 
 
-    // Check previous iteration cellTypes_ for any hole->calculated changes
-    {
-        label nCalculated = 0;
-
-        forAll(cellTypes_, celli)
-        {
-            if (allCellTypes[celli] == CALCULATED && cellTypes_[celli] == HOLE)
-            {
-                if (allStencil[celli].size() == 0)
-                {
-                    FatalErrorInFunction
-                    //WarningInFunction
-                        << "Cell:" << celli
-                        << " at:" << mesh_.cellCentres()[celli]
-                        << " zone:" << zoneID[celli]
-                        << " changed from hole to calculated"
-                        << " but there is no donor"
-                        //<< endl;
-                        << exit(FatalError);
-                }
-                else
-                {
-                    //Pout<< "cell:" << mesh_.cellCentres()[celli]
-                    //    << " changed from hole to calculated"
-                    //    << " using donors:" << allStencil[celli]
-                    //    << endl;
-                    allCellTypes[celli] = INTERPOLATED;
-                    nCalculated++;
-                }
-            }
-        }
-
-        if (debug)
-        {
-            Pout<< "Detected " << nCalculated << " cells changing from hole"
-                << " to calculated. Changed to interpolated"
-                << endl;
-        }
-    }
-
-
     // Convert cell-cell addressing to stencil in compact notation
 
     cellTypes_.transfer(allCellTypes);
diff --git a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
index 96fb1a445c7..db10a358c45 100644
--- a/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
+++ b/src/overset/cellCellStencil/trackingInverseDistance/trackingInverseDistanceCellCellStencil.C
@@ -865,35 +865,10 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
     }
 
 
-    // Mark unreachable bits
-    findHoles(globalCells_, mesh_, zoneID, allStencil, allCellTypes);
-    DebugInfo<< FUNCTION_NAME << " : Flood-filled holes" << endl;
-
-    if (debug)
-    {
-        tmp<volScalarField> tfld
-        (
-            createField(mesh_, "allCellTypes_hole", allCellTypes)
-        );
-        tfld().write();
-    }
-
-    // Add buffer interpolation layer(s) around holes
-    scalarField allWeight(mesh_.nCells(), Zero);
-    walkFront(layerRelax, allStencil, allCellTypes, allWeight);
-    DebugInfo<< FUNCTION_NAME << " : Implemented layer relaxation" << endl;
-
-    if (debug)
-    {
-        tmp<volScalarField> tfld
-        (
-            createField(mesh_, "allCellTypes_front", allCellTypes)
-        );
-        tfld().write();
-    }
-
-
     // Check previous iteration cellTypes_ for any hole->calculated changes
+    // If so set the cell either to interpolated (if there are donors) or
+    // holes (if there are no donors). Note that any interpolated cell might
+    // still be overwritten by the flood filling
     {
         label nCalculated = 0;
 
@@ -903,22 +878,12 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
             {
                 if (allStencil[celli].size() == 0)
                 {
-                    FatalErrorInFunction
-                    //WarningInFunction
-                        << "Cell:" << celli
-                        << " at:" << mesh_.cellCentres()[celli]
-                        << " zone:" << zoneID[celli]
-                        << " changed from hole to calculated"
-                        << " but there is no donor"
-                        //<< endl;
-                        << exit(FatalError);
+                    // Reset to hole
+                    allCellTypes[celli] = HOLE;
+                    allStencil[celli].clear();
                 }
                 else
                 {
-                    Pout<< "cell:" << mesh_.cellCentres()[celli]
-                        << " changed from hole to calculated"
-                        << " using donors:" << allStencil[celli]
-                        << endl;
                     allCellTypes[celli] = INTERPOLATED;
                     nCalculated++;
                 }
@@ -934,6 +899,34 @@ bool Foam::cellCellStencils::trackingInverseDistance::update()
     }
 
 
+    // Mark unreachable bits
+    findHoles(globalCells_, mesh_, zoneID, allStencil, allCellTypes);
+    DebugInfo<< FUNCTION_NAME << " : Flood-filled holes" << endl;
+
+    if (debug)
+    {
+        tmp<volScalarField> tfld
+        (
+            createField(mesh_, "allCellTypes_hole", allCellTypes)
+        );
+        tfld().write();
+    }
+
+    // Add buffer interpolation layer(s) around holes
+    scalarField allWeight(mesh_.nCells(), Zero);
+    walkFront(layerRelax, allStencil, allCellTypes, allWeight);
+    DebugInfo<< FUNCTION_NAME << " : Implemented layer relaxation" << endl;
+
+    if (debug)
+    {
+        tmp<volScalarField> tfld
+        (
+            createField(mesh_, "allCellTypes_front", allCellTypes)
+        );
+        tfld().write();
+    }
+
+
     // Convert cell-cell addressing to stencil in compact notation
 
     cellTypes_.transfer(allCellTypes);
-- 
GitLab