From c7c7553ed060b5f5243eb5a9e38b423d53e05bf3 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 26 Mar 2013 12:49:54 +0000
Subject: [PATCH] BUG: attachDetach: accessing outside neighbour size

---
 src/dynamicMesh/attachDetach/attachInterface.C   | 16 ++++++++++++++--
 .../layerAdditionRemoval/addCellLayer.C          |  6 +++---
 .../layerAdditionRemoval/removeCellLayer.C       |  6 +++---
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/dynamicMesh/attachDetach/attachInterface.C b/src/dynamicMesh/attachDetach/attachInterface.C
index 11332a62576..40c68cb8453 100644
--- a/src/dynamicMesh/attachDetach/attachInterface.C
+++ b/src/dynamicMesh/attachDetach/attachInterface.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -83,6 +83,10 @@ void Foam::attachDetach::attachInterface
 
     forAll(removedPoints, pointI)
     {
+        //Pout<< "Removing point:" << removedPoints[pointI]
+        //    << " currently at:" << ref.points()[removedPoints[pointI]]
+        //    << endl;
+
         ref.setAction(polyRemovePoint(removedPoints[pointI]));
     }
 
@@ -90,8 +94,16 @@ void Foam::attachDetach::attachInterface
     // Remove all faces from the slave patch
     forAll(slavePatch, i)
     {
+        //Pout<< "Removing face " << i + slavePatchStart
+        //    << " with verts:" << ref.faces()[i + slavePatchStart]
+        //    << " at:"
+        //    <<  UIndirectList<point>
+        //        (
+        //            ref.points(),
+        //            ref.faces()[i + slavePatchStart]
+        //        )
+        //    << endl;
         ref.setAction(polyRemoveFace(i + slavePatchStart));
-// Pout<< "Removing face " << i + slavePatchStart << endl;
     }
 
     // Modify the faces from the master patch
diff --git a/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C b/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
index fdcc41b6cb4..2fe428d45c0 100644
--- a/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
+++ b/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -203,8 +203,8 @@ void Foam::layerAdditionRemoval::addCellLayer
         // Flip the face as necessary
         if
         (
-            mc[faceI] == nei[mf[faceI]]
-         || !mesh.isInternalFace(mf[faceI])
+           !mesh.isInternalFace(mf[faceI])
+         || mc[faceI] == nei[mf[faceI]]
         )
         {
             flipFaceFlux = true;
diff --git a/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C b/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
index c6348af3634..1edaf10735c 100644
--- a/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
+++ b/src/dynamicMesh/layerAdditionRemoval/removeCellLayer.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -275,7 +275,7 @@ void Foam::layerAdditionRemoval::removeCellLayer
         // of the cell to be removed
         label masterSideCell = own[mf[faceI]];
 
-        if (masterSideCell == mc[faceI])
+        if (mesh.isInternalFace(mf[faceI]) && masterSideCell == mc[faceI])
         {
             // Owner cell of the face is being removed.
             // Grab the neighbour instead
@@ -284,7 +284,7 @@ void Foam::layerAdditionRemoval::removeCellLayer
 
         label slaveSideCell = own[ftc[faceI]];
 
-        if (slaveSideCell == mc[faceI])
+        if (mesh.isInternalFace(ftc[faceI]) && slaveSideCell == mc[faceI])
         {
             // Owner cell of the face is being removed.
             // Grab the neighbour instead
-- 
GitLab