From 913f844eb6b5217c7a3b15ccc19b0e6c3400bc4b Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 15 Jun 2022 17:46:29 +0100
Subject: [PATCH] BUG: reconstructPar: do not locate positions. See #2205.

Specific to the VOF-to-lagrangian FO is to generate particles
which potentially do not relate to the mesh. So here they
are preserved instead of trying to locate them on the
reconstructed mesh. Note: this has the same effect
of actually copying the file...
---
 .../reconstruct/lagrangianReconstructor.C     | 22 ++++++++--
 .../reconstruct/passivePositionParticle.H     | 44 ++++++++++++++++---
 2 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/src/parallel/reconstruct/reconstruct/lagrangianReconstructor.C b/src/parallel/reconstruct/reconstruct/lagrangianReconstructor.C
index 1db87b6e32a..c2656072b71 100644
--- a/src/parallel/reconstruct/reconstruct/lagrangianReconstructor.C
+++ b/src/parallel/reconstruct/reconstruct/lagrangianReconstructor.C
@@ -116,14 +116,30 @@ Foam::label Foam::lagrangianReconstructor::reconstructPositions
             }
             else
             {
-                // No valid coordinates. Use built-in locating from cell -1
+                // No valid coordinates. Two choices:
+                // - assume reconstructed mesh contains the position so do
+                //   a locate with the (reconstructed) mesh
+                // - preserve -1 as cell id, maintain the read location
                 lagrangianPositions.append
                 (
+
+                    //- Option 1: locate on reconstructed mesh
+                    //new passivePositionParticle
+                    //(
+                    //    mesh_,
+                    //    ppi.location(),
+                    //    mappedCell
+                    //)
+
+                    //- Option 2: maintain read location
                     new passivePositionParticle
                     (
                         mesh_,
-                        ppi.location(),
-                        mappedCell
+                        Zero,   // position
+                        -1,     // celli
+                        -1,     // tetFacei
+                        -1,     // tetPti
+                        ppi.location()
                     )
                 );
             }
diff --git a/src/parallel/reconstruct/reconstruct/passivePositionParticle.H b/src/parallel/reconstruct/reconstruct/passivePositionParticle.H
index 8612c632a22..ebf685f1f61 100644
--- a/src/parallel/reconstruct/reconstruct/passivePositionParticle.H
+++ b/src/parallel/reconstruct/reconstruct/passivePositionParticle.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2021 OpenCFD Ltd.
+    Copyright (C) 2021-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -68,7 +68,7 @@ public:
 
     // Constructors
 
-        //- Construct from components
+        //- Construct from components (known location)
         passivePositionParticle
         (
             const polyMesh& mesh,
@@ -83,16 +83,18 @@ public:
         {}
 
 
-        //- Construct from a position and a cell.
-        //  Searches for the rest of the required topology.
+        //- Construct from components (supplied location)
         passivePositionParticle
         (
             const polyMesh& mesh,
-            const vector& position,
-            const label celli = -1
+            const barycentric& coordinates,
+            const label celli,
+            const label tetFacei,
+            const label tetPti,
+            const vector& position
         )
         :
-            particle(mesh, position, celli),
+            particle(mesh, coordinates, celli, tetFacei, tetPti),
             location_(position)
         {}
 
@@ -168,6 +170,34 @@ public:
             {
                 return location_;
             }
+
+            //- Write the particle position and cell id
+            virtual void writePosition(Ostream& os) const
+            {
+                // Use cached location() instead of calculated position()
+                if (os.format() == IOstream::ASCII)
+                {
+                    os  << location() << token::SPACE << cell();
+                }
+                else
+                {
+                    positionsCompat1706 p;
+
+                    const size_t s =
+                    (
+                        offsetof(positionsCompat1706, facei)
+                      - offsetof(positionsCompat1706, position)
+                    );
+
+                    p.position = location();
+                    p.celli = cell();
+
+                    os.write(reinterpret_cast<const char*>(&p.position), s);
+                }
+
+                // Check state of Ostream
+                os.check(FUNCTION_NAME);
+            }
 };
 
 
-- 
GitLab