From f5310ca48cefe1b4a4a1d18efa9042624e8b60b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Crist=C3=B3bal=20Ib=C3=A1=C3=B1ez?= <email@address.com>
Date: Mon, 18 Nov 2024 11:51:18 +0000
Subject: [PATCH] ENH: cyclicAMI-topoChange: allow restart. Fixes #3265

---
 CONTRIBUTORS.md                               |  1 +
 .../dynamicMotionSolverFvMeshAMI.C            | 30 +++++++++++++++++++
 .../system/controlDict                        |  2 +-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 8d6cc649474..8c3342d9f98 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -27,6 +27,7 @@ It is likely incomplete...
 - Bernhard Gschaider
 - Andrew Heather
 - David Hill
+- Crist�bal Ib��ez
 - Yoshiaki Inoue
 - Mattijs Janssens
 - Andrew Jackson
diff --git a/src/dynamicFvMesh/dynamicMotionSolverFvMeshAMI/dynamicMotionSolverFvMeshAMI.C b/src/dynamicFvMesh/dynamicMotionSolverFvMeshAMI/dynamicMotionSolverFvMeshAMI.C
index bb94134e1fd..bbad4c5bd30 100644
--- a/src/dynamicFvMesh/dynamicMotionSolverFvMeshAMI/dynamicMotionSolverFvMeshAMI.C
+++ b/src/dynamicFvMesh/dynamicMotionSolverFvMeshAMI/dynamicMotionSolverFvMeshAMI.C
@@ -31,6 +31,7 @@ License
 #include "volFields.H"
 #include "surfaceFields.H"
 #include "cyclicAMIPolyPatch.H"
+#include "cyclicACMIPolyPatch.H"
 #include "polyTopoChange.H"
 #include "MeshObject.H"
 #include "lduMesh.H"
@@ -83,6 +84,35 @@ bool Foam::dynamicMotionSolverFvMeshAMI::init(const bool doInit)
     }
 
     motionPtr_ = motionSolver::New(*this);
+
+    // allow restarts during initialization to match patch field values if
+    // required 
+    const auto& pbm = boundaryMesh();
+    bool changeRequired = false;
+    for (label patchi = 0; patchi < pbm.nNonProcessor(); ++patchi)
+    {
+        const auto* cycAmiPtr = isA<cyclicAMIPolyPatch>(pbm[patchi]);
+
+        if (cycAmiPtr)
+        {
+            changeRequired = cycAmiPtr->createAMIFaces() || changeRequired;
+        }
+        else
+        {
+            const auto* cycAcmiPtr = isA<cyclicACMIPolyPatch>(pbm[patchi]);
+            if (cycAcmiPtr)
+            {
+                changeRequired =
+                    cycAcmiPtr->cyclicAMIPolyPatch::createAMIFaces()
+                 || changeRequired;
+            }
+        }
+    }
+    if (returnReduceOr(changeRequired))
+    {
+        update();
+    }
+
     return true;
 }
 
diff --git a/tutorials/incompressible/pimpleFoam/laminar/mixerVesselAMI2D/mixerVesselAMI2D-topologyChange/system/controlDict b/tutorials/incompressible/pimpleFoam/laminar/mixerVesselAMI2D/mixerVesselAMI2D-topologyChange/system/controlDict
index fee05d98df2..67b81572349 100644
--- a/tutorials/incompressible/pimpleFoam/laminar/mixerVesselAMI2D/mixerVesselAMI2D-topologyChange/system/controlDict
+++ b/tutorials/incompressible/pimpleFoam/laminar/mixerVesselAMI2D/mixerVesselAMI2D-topologyChange/system/controlDict
@@ -32,7 +32,7 @@ writeInterval   0.1;
 
 purgeWrite      0;
 
-writeFormat     ascii;
+writeFormat     binary; //ascii;
 
 writePrecision  6;
 
-- 
GitLab