From c3e5510325bfe3f71442874c1273d1ad12247f36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Sat, 16 May 2015 20:24:40 +0200
Subject: [PATCH] particle::hitCyclicAMIPatch - corrected bug

---
 src/lagrangian/basic/particle/particleTemplates.C  |  3 -
 .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C        | 85 ++++++++++++++++++++--
 .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.H        | 14 ++++
 3 files changed, 93 insertions(+), 9 deletions(-)

diff --git a/src/lagrangian/basic/particle/particleTemplates.C b/src/lagrangian/basic/particle/particleTemplates.C
index 280165d..b6f9e72 100644
--- a/src/lagrangian/basic/particle/particleTemplates.C
+++ b/src/lagrangian/basic/particle/particleTemplates.C
@@ -1086,9 +1086,6 @@ void Foam::particle::hitCyclicAMIPatch
 
     // Now the particle is on the receiving side
 
-    // Have patch transform the position
-    receiveCpp.transformPosition(position_, patchFaceI);
-
     // Transform the properties
     if (!receiveCpp.parallel())
     {
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
index 9d33b27..82da2fb 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
@@ -922,6 +922,64 @@ void Foam::cyclicAMIPolyPatch::transformPosition
 }
 
 
+void Foam::cyclicAMIPolyPatch::reverseTransformPosition
+(
+    point& l,
+    const label faceI
+) const
+{
+    if (!parallel())
+    {
+        const tensor& T =
+        (
+            reverseT().size() == 1
+          ? reverseT()[0]
+          : reverseT()[faceI]
+        );
+
+        if (transform() == ROTATIONAL)
+        {
+            l = Foam::transform(T, l - rotationCentre_) + rotationCentre_;
+        }
+        else
+        {
+            l = Foam::transform(T, l);
+        }
+    }
+    else if (separated())
+    {
+        const vector& s =
+        (
+            separation().size() == 1
+          ? separation()[0]
+          : separation()[faceI]
+        );
+
+        l += s;
+    }
+}
+
+
+void Foam::cyclicAMIPolyPatch::reverseTransformDirection
+(
+    vector& d,
+    const label faceI
+) const
+{
+    if (!parallel())
+    {
+        const tensor& T =
+        (
+            reverseT().size() == 1
+          ? reverseT()[0]
+          : reverseT()[faceI]
+        );
+
+        d = Foam::transform(T, d);
+    }
+}
+
+
 void Foam::cyclicAMIPolyPatch::calcGeometry
 (
     const primitivePatch& referPatch,
@@ -978,28 +1036,43 @@ Foam::label Foam::cyclicAMIPolyPatch::pointFace
     point& p
 ) const
 {
+    point prt(p);
+    vector nrt(n);
+
+    label nbrFaceI = -1;
+
+    reverseTransformPosition(prt,faceI);
+    reverseTransformDirection(nrt,faceI);
+
     if (owner())
     {
-        return AMI().tgtPointFace
+        nbrFaceI = AMI().tgtPointFace
         (
             *this,
             neighbPatch(),
-            n,
+            nrt,
             faceI,
-            p
+            prt
         );
     }
     else
     {
-        return neighbPatch().AMI().srcPointFace
+        nbrFaceI = neighbPatch().AMI().srcPointFace
         (
             neighbPatch(),
             *this,
-            n,
+            nrt,
             faceI,
-            p
+            prt
         );
     }
+
+    if (nbrFaceI >= 0)
+    {
+        p = prt;
+    }
+
+    return nbrFaceI;
 }
 
 
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H
index 40cfc95..ff0d3d8 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H
+++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.H
@@ -329,6 +329,20 @@ public:
                     const label faceI
                 ) const;
 
+                //- Transform a patch-based position from this side to nbr side
+                virtual void reverseTransformPosition
+                (
+                    point& l,
+                    const label faceI
+                ) const;
+
+                //- Transform a patch-based direction from this side to nbr side
+                virtual void reverseTransformDirection
+                (
+                    vector& d,
+                    const label faceI
+                ) const;
+
 
             // Interpolations
 
