From fa2971c17a83a40266453b6b14726be62fdca6ac Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 21 Nov 2018 15:34:13 +0000
Subject: [PATCH] BUG: cyclicACMI: ensure transformation tensors are valid.
 Fixes #1088.

---
 .../cyclicACMIPolyPatch/cyclicACMIPolyPatch.C | 34 ++++--------------
 .../cyclicACMIPolyPatch/cyclicACMIPolyPatch.H | 14 +-------
 .../cyclicAMIPolyPatch/cyclicAMIPolyPatch.C   | 35 +++++++------------
 3 files changed, 21 insertions(+), 62 deletions(-)

diff --git a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
index 95fb2acfa97..31745412259 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2017 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2017-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -238,9 +238,11 @@ void Foam::cyclicACMIPolyPatch::initGeometry(PstreamBuffers& pBufs)
         Pout<< "cyclicACMIPolyPatch::initGeometry : " << name() << endl;
     }
 
+    // Note: calculates transformation and triggers face centre calculation
     cyclicAMIPolyPatch::initGeometry(pBufs);
 
-    // Initialise the AMI
+    // Initialise the AMI early to make sure we adapt the face areas before the
+    // cell centre calculation gets triggered.
     resetAMI();
 }
 
@@ -265,9 +267,11 @@ void Foam::cyclicACMIPolyPatch::initMovePoints
     {
         Pout<< "cyclicACMIPolyPatch::initMovePoints : " << name() << endl;
     }
+
+    // Note: calculates transformation and triggers face centre calculation
     cyclicAMIPolyPatch::initMovePoints(pBufs, p);
 
-    // Initialise the AMI
+    // Initialise the AMI early. See initGeometry.
     resetAMI();
 }
 
@@ -540,30 +544,6 @@ Foam::label Foam::cyclicACMIPolyPatch::nonOverlapPatchID() const
 }
 
 
-void Foam::cyclicACMIPolyPatch::calcGeometry
-(
-    const primitivePatch& referPatch,
-    const pointField& thisCtrs,
-    const vectorField& thisAreas,
-    const pointField& thisCc,
-    const pointField& nbrCtrs,
-    const vectorField& nbrAreas,
-    const pointField& nbrCc
-)
-{
-    cyclicAMIPolyPatch::calcGeometry
-    (
-        referPatch,
-        thisCtrs,
-        thisAreas,
-        thisCc,
-        nbrCtrs,
-        nbrAreas,
-        nbrCc
-    );
-}
-
-
 void Foam::cyclicACMIPolyPatch::initOrder
 (
     PstreamBuffers& pBufs,
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.H b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.H
index b2493360c67..0f0934f1f31 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.H
+++ b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPolyPatch/cyclicACMIPolyPatch.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -267,18 +267,6 @@ public:
             inline static scalar tolerance();
 
 
-        //- Calculate the patch geometry
-        virtual void calcGeometry
-        (
-            const primitivePatch& referPatch,
-            const pointField& thisCtrs,
-            const vectorField& thisAreas,
-            const pointField& thisCc,
-            const pointField& nbrCtrs,
-            const vectorField& nbrAreas,
-            const pointField& nbrCc
-        );
-
         //- Initialize ordering for primitivePatch. Does not
         //  refer to *this (except for name() and type() etc.)
         virtual void initOrder
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
index 6807318c3a7..f4dbac15d23 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
+     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -403,21 +403,18 @@ void Foam::cyclicAMIPolyPatch::initGeometry(PstreamBuffers& pBufs)
     AMIPtr_.clear();
 
     polyPatch::initGeometry(pBufs);
+
+    // Early calculation of transforms so e.g. cyclicACMI can use them.
+    // Note: also triggers primitiveMesh face centre. Note that cell
+    // centres should -not- be calculated
+    // since e.g. cyclicACMI override face areas
+    calcTransforms();
 }
 
 
 void Foam::cyclicAMIPolyPatch::calcGeometry(PstreamBuffers& pBufs)
 {
-    calcGeometry
-    (
-        *this,
-        faceCentres(),
-        faceAreas(),
-        faceCellCentres(),
-        neighbPatch().faceCentres(),
-        neighbPatch().faceAreas(),
-        neighbPatch().faceCellCentres()
-    );
+    // All geometry done inside initGeometry
 }
 
 
@@ -434,6 +431,9 @@ void Foam::cyclicAMIPolyPatch::initMovePoints
 
     // See below. Clear out any local geometry
     primitivePatch::movePoints(p);
+
+    // Early calculation of transforms. See above.
+    calcTransforms();
 }
 
 
@@ -445,7 +445,7 @@ void Foam::cyclicAMIPolyPatch::movePoints
 {
     polyPatch::movePoints(pBufs, p);
 
-    calcTransforms();
+    // All transformation tensors already done in initMovePoints
 }
 
 
@@ -962,16 +962,7 @@ void Foam::cyclicAMIPolyPatch::calcGeometry
     const vectorField& nbrAreas,
     const pointField& nbrCc
 )
-{
-    calcTransforms
-    (
-        referPatch,
-        thisCtrs,
-        thisAreas,
-        nbrCtrs,
-        nbrAreas
-    );
-}
+{}
 
 
 void Foam::cyclicAMIPolyPatch::initOrder
-- 
GitLab