From 9cae54b433ef2973f4bba4d6fe070bbb735fe014 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Thu, 22 Oct 2015 09:48:40 +0100
Subject: [PATCH] cyclicAMIPolyPatch, cyclicACMIPolyPatch: Ensure geometry is
 updated correctly following mesh-motion Resolves bug-report:
 http://www.openfoam.org/mantisbt/view.php?id=1664

---
 .../cyclicACMIPolyPatch/cyclicACMIPolyPatch.C | 24 +++++++++++++------
 .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C   | 18 +++++++-------
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
index 7a862ee9dac..6a033c394da 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
@@ -44,7 +44,11 @@ const Foam::scalar Foam::cyclicACMIPolyPatch::tolerance_ = 1e-6;
 
 void Foam::cyclicACMIPolyPatch::initPatchFaceAreas() const
 {
-    if (!empty() && faceAreas0_.empty())
+    if
+    (
+        !empty()
+     && (faceAreas0_.empty() || boundaryMesh().mesh().moving())
+    )
     {
         faceAreas0_ = faceAreas();
     }
@@ -52,9 +56,13 @@ void Foam::cyclicACMIPolyPatch::initPatchFaceAreas() const
     const cyclicACMIPolyPatch& nbrACMI =
         refCast<const cyclicACMIPolyPatch>(this->neighbPatch());
 
-    if (!nbrACMI.empty() && nbrACMI.faceAreas0().empty())
+    if
+    (
+        !nbrACMI.empty()
+     && (nbrACMI.faceAreas0().empty() || boundaryMesh().mesh().moving())
+    )
     {
-        nbrACMI.initPatchFaceAreas();
+        nbrACMI.faceAreas0_ = nbrACMI.faceAreas();
     }
 }
 
@@ -136,11 +144,10 @@ void Foam::cyclicACMIPolyPatch::setNeighbourFaceAreas() const
 
 void Foam::cyclicACMIPolyPatch::initGeometry(PstreamBuffers& pBufs)
 {
-    // Initialise the AMI so that base geometry (e.g. cell volumes) are
-    // correctly evaluated
-    resetAMI();
-
     cyclicAMIPolyPatch::initGeometry(pBufs);
+
+    // Initialise the AMI
+    resetAMI();
 }
 
 
@@ -157,6 +164,9 @@ void Foam::cyclicACMIPolyPatch::initMovePoints
 )
 {
     cyclicAMIPolyPatch::initMovePoints(pBufs, p);
+
+    // Initialise the AMI
+    resetAMI();
 }
 
 
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
index f58e99ce0e0..8f25ea76b89 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
@@ -71,7 +71,6 @@ Foam::vector Foam::cyclicAMIPolyPatch::findFaceNormalMaxRadius
 
 void Foam::cyclicAMIPolyPatch::calcTransforms()
 {
-    // Half0
     const cyclicAMIPolyPatch& half0 = *this;
     vectorField half0Areas(half0.size());
     forAll(half0, facei)
@@ -79,7 +78,6 @@ void Foam::cyclicAMIPolyPatch::calcTransforms()
         half0Areas[facei] = half0[facei].normal(half0.points());
     }
 
-    // Half1
     const cyclicAMIPolyPatch& half1 = neighbPatch();
     vectorField half1Areas(half1.size());
     forAll(half1, facei)
@@ -406,6 +404,9 @@ void Foam::cyclicAMIPolyPatch::resetAMI
 
 void Foam::cyclicAMIPolyPatch::initGeometry(PstreamBuffers& pBufs)
 {
+    // Clear the invalid AMI
+    AMIPtr_.clear();
+
     polyPatch::initGeometry(pBufs);
 }
 
@@ -431,6 +432,9 @@ void Foam::cyclicAMIPolyPatch::initMovePoints
     const pointField& p
 )
 {
+    // Clear the invalid AMI
+    AMIPtr_.clear();
+
     polyPatch::initMovePoints(pBufs, p);
 
     // See below. Clear out any local geometry
@@ -447,19 +451,15 @@ void Foam::cyclicAMIPolyPatch::movePoints
     polyPatch::movePoints(pBufs, p);
 
     calcTransforms();
-
-    // Note: resetAMI is called whilst in geometry update. So the slave
-    // side might not have reached 'movePoints'. Is explicitly handled by
-    // - clearing geometry of neighbour inside initMovePoints
-    // - not using localPoints() inside resetAMI
-    resetAMI();
 }
 
 
 void Foam::cyclicAMIPolyPatch::initUpdateMesh(PstreamBuffers& pBufs)
 {
-    polyPatch::initUpdateMesh(pBufs);
+    // Clear the invalid AMI
     AMIPtr_.clear();
+
+    polyPatch::initUpdateMesh(pBufs);
 }
 
 
-- 
GitLab