From c4498bb903faed1f400f99b41bf11e7160f6ceb2 Mon Sep 17 00:00:00 2001
From: Gregor Weiss <gregor.weiss@hlrs.de>
Date: Tue, 4 Jul 2023 16:45:40 +0200
Subject: [PATCH] ENH: fix to HOTFIX -- consistent path layout for coherent
 format mesh and fields are stored in data.bp and ascii metadata files ->
 consistent layout in time folders and constant/polyMesh - propagate pathname
 through all ADIOS2 functionality - removing redundant usages, includes, and
 dependencies to wrapping functions to ADIOS2 - adding initialization strategy
 for FieldComponents - minor formatting

---
 .../finiteVolume/domainDecomposition.C        | 11 +++-
 .../src/foam/containers/Lists/List/ListIO.C   | 16 -----
 .../src/foam/containers/Lists/UList/UListIO.C |  1 -
 .../foam/db/IOstreams/A2streams/adiosPaths.H  |  2 +-
 .../IOstreams/A2streams/adiosReadPrimitives.C | 12 ++--
 .../IOstreams/A2streams/adiosReadPrimitives.H | 12 +++-
 .../foam/db/IOstreams/A2streams/adiosStream.H |  4 +-
 .../A2streams/adiosWritePrimitives.C          | 11 +++-
 .../A2streams/adiosWritePrimitives.H          |  9 +++
 .../src/foam/db/IOstreams/Fstreams/OFstream.C |  6 +-
 .../src/foam/meshes/polyMesh/polyMesh.C       | 13 ++--
 .../CoherenceComposite/DataComponentFree.H    | 11 ----
 .../CoherenceComposite/DataComponentFreeI.H   | 46 --------------
 .../CoherenceComposite/FieldComponent.H       |  2 +
 .../CoherenceComposite/FieldComponentI.H      | 19 +++---
 .../CoherenceComposite/IndexComponent.C       | 31 ++--------
 .../CoherenceComposite/IndexComponent.H       | 13 +---
 .../strategies/InitStrategies.H               | 61 +++++++++++++++++++
 .../meshes/polyMesh/sliceMesh/sliceMesh.C     | 31 ++++++----
 19 files changed, 161 insertions(+), 150 deletions(-)
 delete mode 100644 io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFreeI.H

diff --git a/io/reduced-foam-extend/src/decompositionMethods/decomposeReconstruct/decomposeTools/finiteVolume/domainDecomposition.C b/io/reduced-foam-extend/src/decompositionMethods/decomposeReconstruct/decomposeTools/finiteVolume/domainDecomposition.C
index 1e6a937c061..f4024786d5a 100644
--- a/io/reduced-foam-extend/src/decompositionMethods/decomposeReconstruct/decomposeTools/finiteVolume/domainDecomposition.C
+++ b/io/reduced-foam-extend/src/decompositionMethods/decomposeReconstruct/decomposeTools/finiteVolume/domainDecomposition.C
@@ -38,6 +38,7 @@ License
 
 #include "sliceMeshHelper.H"
 #include "slicePermutation.H"
+#include "adiosWritePrimitives.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -115,7 +116,15 @@ Foam::autoPtr<Foam::fvMesh> Foam::domainDecomposition::parallelMesh
             ++gCellI;
         }
     }
-    adiosWritePrimitives( "mesh", "partitionStarts", partitionStarts.size(), partitionStarts.cdata() );
+    auto path = mesh_.pointsInstance()/mesh_.meshDir();
+    adiosWritePrimitives
+    (
+        "mesh",
+        path,
+        "partitionStarts",
+        partitionStarts.size(),
+        partitionStarts.cdata()
+    );
 
     // Get complete owner-neighour addressing in the mesh
     const labelList& own = mesh_.faceOwner();
diff --git a/io/reduced-foam-extend/src/foam/containers/Lists/List/ListIO.C b/io/reduced-foam-extend/src/foam/containers/Lists/List/ListIO.C
index be5ac0c4382..c8622ea454f 100644
--- a/io/reduced-foam-extend/src/foam/containers/Lists/List/ListIO.C
+++ b/io/reduced-foam-extend/src/foam/containers/Lists/List/ListIO.C
@@ -30,8 +30,6 @@ License
 #include "contiguous.H"
 #include <iostream>
 
-#include "adiosReadPrimitives.H"
-
 #include "Ostream.H"
 #include "prefixOSstream.H"
 
@@ -201,20 +199,6 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& list)
                 Pout<< "Reading via COHERENT id = " << id << endl;
             }
 
-            //ToDoIO Check the string read from the stream
-            /*
-            is.parread
-            (
-                reinterpret_cast<parIOType*>(list.data()),
-                id.replace("\"","")
-            );
-            */
-            // Foam::string type = "fields";
-            // if ( is.name().find("polyMesh") != std::string::npos ) {
-            //     type = "mesh";
-            // }
-            // adiosReadPrimitives( type, id, list.data() );
-
             if (UList<T>::debug > 1)
             {
                 Pout<< "List read via COHERENT = " << nl << list << endl;
diff --git a/io/reduced-foam-extend/src/foam/containers/Lists/UList/UListIO.C b/io/reduced-foam-extend/src/foam/containers/Lists/UList/UListIO.C
index 9bcb564def1..a3c2f97b1db 100644
--- a/io/reduced-foam-extend/src/foam/containers/Lists/UList/UListIO.C
+++ b/io/reduced-foam-extend/src/foam/containers/Lists/UList/UListIO.C
@@ -32,7 +32,6 @@ License
 
 #include "prefixOSstream.H"
 
-#include "adiosWritePrimitives.H"
 #include "UListProxy.H"
 
 // * * * * * * * * * * * * * * * Ostream Operator *  * * * * * * * * * * * * //
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosPaths.H b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosPaths.H
index 4b07e554a87..ba4ef27db89 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosPaths.H
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosPaths.H
@@ -41,7 +41,7 @@ class adiosPaths
 {
 
     // Mesh data file name
-    const Foam::fileName meshPathname_{"constant/polyMesh/data.bp"};
+    const Foam::fileName meshPathname_{"data.bp"};
 
     // Field data file name
     const Foam::fileName dataPathname_{"data.bp"};
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.C b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.C
index e10c18f4341..2e2cc3370a4 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.C
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.C
@@ -34,6 +34,7 @@ template<typename T>
 void _implReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     T* buf,
     const Foam::List<Foam::label>& start,
@@ -41,7 +42,7 @@ void _implReadPrimitives
 )
 {
     auto adiosStreamPtr = Foam::adiosReading{}.createStream();
-    adiosStreamPtr->open(type);
+    adiosStreamPtr->open(type, pathname);
     if (start.size()>0 && count.size()>0)
     {
         adiosStreamPtr->transfer(blockId, buf, start, count);
@@ -57,39 +58,42 @@ void _implReadPrimitives
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     Foam::scalar* buf,
     const Foam::List<Foam::label>& start,
     const Foam::List<Foam::label>& count
 )
 {
-    _implReadPrimitives(type, blockId, buf, start, count);
+    _implReadPrimitives(type, pathname, blockId, buf, start, count);
 }
 
 
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     Foam::label* buf,
     const Foam::List<Foam::label>& start,
     const Foam::List<Foam::label>& count
 )
 {
-    _implReadPrimitives(type, blockId, buf, start, count);
+    _implReadPrimitives(type, pathname, blockId, buf, start, count);
 }
 
 
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     char* buf,
     const Foam::List<Foam::label>& start,
     const Foam::List<Foam::label>& count
 )
 {
-    _implReadPrimitives(type, blockId, buf, start, count);
+    _implReadPrimitives(type, pathname, blockId, buf, start, count);
 }
 
 // ************************************************************************* //
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.H b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.H
index fb00369c0c6..4fc391be4ad 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.H
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosReadPrimitives.H
@@ -45,6 +45,7 @@ class string;
 void adiosReadPrimitives
 (
     const string type,
+    const string pathname,
     const string name,
     scalar* buf,
     const List<label>& start = {},
@@ -54,6 +55,7 @@ void adiosReadPrimitives
 void adiosReadPrimitives
 (
     const string type,
+    const string pathname,
     const string name,
     label* buf,
     const List<label>& start = {},
@@ -63,6 +65,7 @@ void adiosReadPrimitives
 void adiosReadPrimitives
 (
     const string type,
+    const string pathname,
     const string name,
     char* buf,
     const List<label>& start = {},
@@ -80,6 +83,7 @@ template
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     T* buf,
     const Foam::List<Foam::label>& start = {},
@@ -100,6 +104,7 @@ template
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     T* buf,
     const Foam::List<Foam::label>& start = {},
@@ -116,6 +121,7 @@ void Foam::adiosReadPrimitives
     Foam::adiosReadPrimitives
     (
         type,
+        pathname,
         name,
         reinterpret_cast<scalar*>( buf ),
         startList,
@@ -135,6 +141,7 @@ template
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     T* buf,
     Integral start = -1,
@@ -148,7 +155,7 @@ void Foam::adiosReadPrimitives
         startList = Foam::List<Foam::label>({start});
         countList = Foam::List<Foam::label>({count});
     }
-    Foam::adiosReadPrimitives(type, name, buf, startList, countList);
+    Foam::adiosReadPrimitives(type, pathname, name, buf, startList, countList);
 }
 
 
@@ -163,6 +170,7 @@ template
 void Foam::adiosReadPrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     T* buf,
     Integral start = -1,
@@ -171,7 +179,7 @@ void Foam::adiosReadPrimitives
 {
     Foam::List<Integral> startList({start});
     Foam::List<Integral> countList({count});
-    Foam::adiosReadPrimitives(type, name, buf, startList, countList);
+    Foam::adiosReadPrimitives(type, pathname, name, buf, startList, countList);
 }
 
 
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosStream.H b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosStream.H
index 0d0d0c00d22..472de88c2f6 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosStream.H
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosStream.H
@@ -26,6 +26,7 @@ template<typename Container>
 void adiosReadToContainer
 (
     const Foam::string& type,
+    const Foam::string& pathname,
     const Foam::string& blockId,
     Container& container,
     const labelList& start = {},
@@ -185,6 +186,7 @@ template<typename Container>
 void Foam::adiosReadToContainer
 (
     const Foam::string& type,
+    const Foam::string& pathname,
     const Foam::string& blockId,
     Container& container,
     const Foam::labelList& start,
@@ -192,7 +194,7 @@ void Foam::adiosReadToContainer
 )
 {
     auto adiosStreamPtr = adiosReading{}.createStream();
-    adiosStreamPtr->open(type);
+    adiosStreamPtr->open(type, pathname);
     adiosStreamPtr->transfer(blockId, container, start, count);
     adiosStreamPtr->close();
 }
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.C b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.C
index 2d8d3d0aca2..6411e0429e3 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.C
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.C
@@ -35,6 +35,7 @@ template< typename T >
 void _implWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     const Foam::labelList& shape,
     const Foam::labelList& start,
@@ -43,7 +44,7 @@ void _implWritePrimitives
 )
 {
     auto adiosStreamPtr = Foam::adiosWriting{}.createStream();
-    adiosStreamPtr->open( type );
+    adiosStreamPtr->open( type, pathname );
     adiosStreamPtr->transfer( blockId, shape, start, count, buf );
     adiosStreamPtr->close();
 }
@@ -52,6 +53,7 @@ void _implWritePrimitives
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     const Foam::label count,
     const Foam::scalar* buf
@@ -60,6 +62,7 @@ void Foam::adiosWritePrimitives
     _implWritePrimitives
     (
         type,
+        pathname,
         blockId,
         { count },
         { 0 },
@@ -72,6 +75,7 @@ void Foam::adiosWritePrimitives
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     const Foam::label count,
     const Foam::label* buf
@@ -80,6 +84,7 @@ void Foam::adiosWritePrimitives
     _implWritePrimitives
     (
         type,
+        pathname,
         blockId,
         { count },
         { 0 },
@@ -92,6 +97,7 @@ void Foam::adiosWritePrimitives
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     const Foam::List<label> shape,
     const Foam::List<label> start,
@@ -102,6 +108,7 @@ void Foam::adiosWritePrimitives
     _implWritePrimitives
     (
         type,
+        pathname,
         blockId,
         shape,
         start,
@@ -114,6 +121,7 @@ void Foam::adiosWritePrimitives
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string blockId,
     const Foam::label shape,
     const Foam::label start,
@@ -124,6 +132,7 @@ void Foam::adiosWritePrimitives
     _implWritePrimitives
     (
         type,
+        pathname,
         blockId,
         { shape },
         { start },
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.H b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.H
index 89462352f34..8c44d6037a1 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.H
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/A2streams/adiosWritePrimitives.H
@@ -44,6 +44,7 @@ template<typename T> class List;
 void adiosWritePrimitives
 (
     const string type,
+    const string pathname,
     const string blockId,
     const label count,
     const scalar* buf
@@ -53,6 +54,7 @@ void adiosWritePrimitives
 void adiosWritePrimitives
 (
     const string type,
+    const string pathname,
     const string blockId,
     const label count,
     const label* buf
@@ -62,6 +64,7 @@ void adiosWritePrimitives
 void adiosWritePrimitives
 (
     const string type,
+    const string pathname,
     const string blockId,
     const List<label> shape,
     const List<label> start,
@@ -73,6 +76,7 @@ void adiosWritePrimitives
 void adiosWritePrimitives
 (
     const string type,
+    const string pathname,
     const string blockId,
     const label shape,
     const label start,
@@ -92,6 +96,7 @@ template
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     const Foam::label count,
     const T* buf
@@ -112,6 +117,7 @@ template
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     const Foam::label count,
     const T* buf
@@ -123,6 +129,7 @@ void Foam::adiosWritePrimitives
     adiosWritePrimitives
     (
         type,
+        pathname,
         name,
         shapeList,
         startList,
@@ -141,6 +148,7 @@ template
 void Foam::adiosWritePrimitives
 (
     const Foam::string type,
+    const Foam::string pathname,
     const Foam::string name,
     const Foam::label shape,
     const Foam::label start,
@@ -154,6 +162,7 @@ void Foam::adiosWritePrimitives
     adiosWritePrimitives
     (
         type,
+        pathname,
         name,
         shapeList,
         startList,
diff --git a/io/reduced-foam-extend/src/foam/db/IOstreams/Fstreams/OFstream.C b/io/reduced-foam-extend/src/foam/db/IOstreams/Fstreams/OFstream.C
index 790b9b91b00..aa1c6405069 100644
--- a/io/reduced-foam-extend/src/foam/db/IOstreams/Fstreams/OFstream.C
+++ b/io/reduced-foam-extend/src/foam/db/IOstreams/Fstreams/OFstream.C
@@ -33,9 +33,10 @@ License
 #include <iostream>
 #include <memory>
 
-#include "adiosWriting.H"
-#include "adiosFileStream.H"
+//#include "adiosWriting.H"
+//#include "adiosFileStream.H"
 #include "adiosStream.H"
+#include "adiosWritePrimitives.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -331,6 +332,7 @@ Foam::Ostream& Foam::OFstream::write
     adiosWritePrimitives
     (
         "fields",
+        "",
         this->getBlockId(),
         byteSize/sizeof(scalar),
         reinterpret_cast<const scalar*>(data)
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/polyMesh.C b/io/reduced-foam-extend/src/foam/meshes/polyMesh/polyMesh.C
index c86620c6937..4064e2bc30d 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/polyMesh.C
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/polyMesh.C
@@ -37,8 +37,6 @@ License
 #include "adiosWriting.H"
 #include "adiosFileStream.H"
 #include "adiosWritePrimitives.H"
-#include "adiosReadPrimitives.H"
-//#include "SortableList.H"
 
 #include "DynamicList.H"
 #include <numeric>
@@ -1589,7 +1587,7 @@ bool Foam::polyMesh::write() const
         // Write mesh to a separate file
         auto path = pointsInstance()/meshDir();
         auto adiosStreamPtr = adiosWriting{}.createStream();
-        adiosStreamPtr->open( "mesh" );
+        adiosStreamPtr->open("mesh", path);
 
         slicePermutation sliceablePermutation{ *this };
 
@@ -1652,7 +1650,14 @@ bool Foam::polyMesh::write() const
 
         adiosStreamPtr->close();
 
-        adiosWritePrimitives( "mesh", "points", adiosPoints.size(), adiosPoints.cdata() );
+        adiosWritePrimitives
+        (
+            "mesh",
+            path,
+            "points",
+            adiosPoints.size(),
+            adiosPoints.cdata()
+        );
     }
 
     return regIOobject::write();
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFree.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFree.H
index 7618f586a1c..c1faceb01f0 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFree.H
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFree.H
@@ -48,17 +48,6 @@ class InitStrategy;
 
 bool head_of_composition(const DataComponent& component);
 
-template<typename FieldType = DataComponent::index_container>
-std::unique_ptr<InitStrategy>
-create_component_initializer
-(
-    const string& type,
-    const string& name,
-    const bool accumulate
-);
-
 } // End namespace Foam
 
-#include "DataComponentFreeI.H"
-
 #endif
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFreeI.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFreeI.H
deleted file mode 100644
index 143014fcacd..00000000000
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/DataComponentFreeI.H
+++ /dev/null
@@ -1,46 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | foam-extend: Open Source CFD
-   \\    /   O peration     | Version:     4.1
-    \\  /    A nd           | Web:         http://www.foam-extend.org
-     \\/     M anipulation  | For copyright notice see file Copyright
--------------------------------------------------------------------------------
-License
-    This file is part of foam-extend.
-
-    foam-extend is free software: you can redistribute it and/or modify it
-    under the terms of the GNU General Public License as published by the
-    Free Software Foundation, either version 3 of the License, or (at your
-    option) any later version.
-
-    foam-extend is distributed in the hope that it will be useful, but
-    WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#include "InitStrategies.H"
-#include <memory>
-
-
-template<typename FieldType>
-std::unique_ptr<Foam::InitStrategy>
-Foam::create_component_initializer
-(
-    const Foam::string& type,
-    const Foam::string& name,
-    const bool accumulate
-)
-{
-    if (type == "offsets")
-    {
-        return std::make_unique<Foam::InitOffsets>(accumulate);
-    }
-    return std::make_unique<Foam::InitFromADIOS<FieldType> >(type, name);
-}
-
-// ************************************************************************* //
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponent.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponent.H
index fa8ba7786fc..b5688feff6e 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponent.H
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponent.H
@@ -50,6 +50,8 @@ class FieldComponent
 {
     FieldType data_;
 
+    std::unique_ptr<InitStrategy> init_strategy_{nullptr};
+
     OffsetStrategy calc_start_{nullptr};
 
     OffsetStrategy calc_count_{nullptr};
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponentI.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponentI.H
index e5d9fd27009..5e1959caade 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponentI.H
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/FieldComponentI.H
@@ -40,6 +40,7 @@ Foam::FieldComponent<FieldType>::FieldComponent
 :
     Foam::DataComponent(type, name, parent_component),
     data_{},
+    init_strategy_{std::move(init_strategy)},
     calc_start_{calc_start},
     calc_count_{calc_count},
     initialized_{false}
@@ -52,18 +53,12 @@ void Foam::FieldComponent<FieldType>::init()
 {
     // FieldComponent (as leaf) must be attached to a IndexComponent (as node)
     auto parent = parent_component_;
-    if (calc_start_ && calc_count_)
-    {
-        auto start = parent->accept(calc_start_);
-        auto count = parent->accept(calc_count_);
-        data_.resize(count);
-        Foam::adiosReadPrimitives(type(), name(), data_.data(), start, count);
-    }
-    else
-    {
-        // TODO: resizing
-        Foam::adiosReadPrimitives(type(), name(), data_.data());
-    }
+    Foam::InitStrategy::labelPair start_count
+    (
+        parent->accept(calc_start_),
+        parent->accept(calc_count_)
+    );
+    init_strategy_->operator()(data_, start_count);
     initialized_ = true;
 }
 
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.C b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.C
index 02bc6ed598e..9da7d5ab803 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.C
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.C
@@ -33,27 +33,6 @@ License
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-Foam::IndexComponent::IndexComponent
-(
-    const Foam::string type,
-    const Foam::string name,
-    Foam::OffsetStrategy calc_start,
-    Foam::OffsetStrategy calc_count,
-    Foam::DataComponent* const parent_component
-)
-:
-    DataComponent(type, name, parent_component),
-    components_map_{},
-    data_{},
-    calc_start_{calc_start},
-    calc_count_{calc_count},
-    init_strategy_
-    {
-        Foam::create_component_initializer(type, name, !calc_start_)
-    },
-    initialized_{false}
-{}
-
 
 Foam::IndexComponent::IndexComponent
 (
@@ -68,9 +47,9 @@ Foam::IndexComponent::IndexComponent
     DataComponent(type, name, parent_component),
     components_map_{},
     data_{},
+    init_strategy_{std::move(init_strategy)},
     calc_start_{calc_start},
     calc_count_{calc_count},
-    init_strategy_{std::move(init_strategy)},
     initialized_{false}
 {}
 
@@ -124,10 +103,10 @@ void Foam::IndexComponent::init()
 {
     auto parent = !parent_component_ ? this : parent_component_;
     Foam::InitStrategy::labelPair start_count
-                                  (
-                                      parent->accept(calc_start_),
-                                      parent->accept(calc_count_)
-                                  );
+    (
+        parent->accept(calc_start_),
+        parent->accept(calc_count_)
+    );
     init_strategy_->operator()(data_, start_count);
     initialized_ = true;
 }
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.H
index ab98227a926..51ab507673e 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.H
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/IndexComponent.H
@@ -51,12 +51,12 @@ class IndexComponent
 
     index_container data_{};
 
+    std::unique_ptr<InitStrategy> init_strategy_{nullptr};
+
     OffsetStrategy calc_start_{nullptr};
 
     OffsetStrategy calc_count_{nullptr};
 
-    std::unique_ptr<InitStrategy> init_strategy_;
-
     bool initialized_{false};
 
     // Core initialization for this index component
@@ -91,15 +91,6 @@ public:
 
     IndexComponent() = default;
 
-    IndexComponent
-    (
-        const Foam::string type,
-        const Foam::string name,
-        OffsetStrategy calc_start = nullptr,
-        OffsetStrategy calc_count = nullptr,
-        base_raw_ptr const parent_component = nullptr
-    );
-
     IndexComponent
     (
         const Foam::string type,
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/strategies/InitStrategies.H b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/strategies/InitStrategies.H
index 52416c2e5ef..1829fa46322 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/strategies/InitStrategies.H
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/CoherenceComposite/strategies/InitStrategies.H
@@ -37,6 +37,7 @@ SourceFiles
 
 #include "Offsets.H"
 #include "adiosStream.H"
+#include "adiosReadPrimitives.H"
 
 #include "labelList.H"
 #include "scalarField.H"
@@ -83,10 +84,12 @@ struct InitFromADIOS
     explicit InitFromADIOS
     (
         const Foam::string& type,
+        const Foam::string& pathname,
         const Foam::string& name
     )
     :
         type_{type},
+        pathname_{pathname},
         name_{name}
     {}
 
@@ -107,6 +110,7 @@ private:
         Foam::adiosReadToContainer
         (
             type_,
+            pathname_,
             name_,
             data,
             start,
@@ -116,6 +120,8 @@ private:
 
     Foam::string type_{};
 
+    Foam::string pathname_{};
+
     Foam::string name_{};
 
 };
@@ -141,6 +147,61 @@ private:
 
 };
 
+
+template<typename FieldType = InitStrategy::index_container>
+struct InitPrimitivesFromADIOS
+:
+    public InitStrategy
+{
+    InitPrimitivesFromADIOS() = default;
+
+    explicit InitPrimitivesFromADIOS
+    (
+        const Foam::string& type,
+        const Foam::string& pathname,
+        const Foam::string& name
+    )
+    :
+        type_{type},
+        pathname_{pathname},
+        name_{name}
+    {}
+
+private:
+
+    void execute
+    (
+        FieldType& data,
+        Foam::InitStrategy::labelPair& start_count
+    ) final
+    {
+        auto start = (start_count.first != -1) ?
+                     labelList({start_count.first}) :
+                     labelList({});
+        auto count = (start_count.second != -1) ?
+                     labelList({start_count.second}) :
+                     labelList({});
+        data.resize(count[0]);
+        Foam::adiosReadPrimitives
+        (
+            type_,
+            pathname_,
+            name_,
+            data.data(),
+            start,
+            count
+        );
+    }
+
+    Foam::string type_{};
+
+    Foam::string pathname_{};
+
+    Foam::string name_{};
+
+};
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/sliceMesh.C b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/sliceMesh.C
index 0dea016cfa4..de161ffaea2 100644
--- a/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/sliceMesh.C
+++ b/io/reduced-foam-extend/src/foam/meshes/polyMesh/sliceMesh/sliceMesh.C
@@ -27,10 +27,6 @@ License
 #include "sliceMeshHelper.H"
 #include "nonblockConsensus.H"
 
-#include "adiosFileStream.H"
-#include "adiosWritePrimitives.H"
-#include "adiosReadPrimitives.H"
-
 #include "processorPolyPatch.H"
 
 #include "DataComponent.H"
@@ -60,7 +56,7 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
     {
         InitStrategyPtr init_partitionStarts
         (
-            new InitIndexComp("mesh", "partitionStarts")
+            new InitIndexComp("mesh", pathname, "partitionStarts")
         );
         meshSlice.add
         (
@@ -73,7 +69,7 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
 
         InitStrategyPtr init_ownerStarts
         (
-            new InitIndexComp("mesh", "ownerStarts")
+            new InitIndexComp("mesh", pathname, "ownerStarts")
         );
         meshSlice.node("partitionStarts")->add
         (
@@ -88,7 +84,7 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
     {
         InitStrategyPtr init_ownerStarts
         (
-            new InitIndexComp("mesh", "ownerStarts")
+            new InitIndexComp("mesh", pathname, "ownerStarts")
         );
         meshSlice.add("mesh", "ownerStarts", std::move(init_ownerStarts));
     }
@@ -104,7 +100,10 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
     );
     meshSlice.decorate<Foam::SliceDecorator>("cellOffsets");
 
-    InitStrategyPtr init_neighbours(new InitIndexComp("mesh", "neighbours"));
+    InitStrategyPtr init_neighbours
+    (
+        new InitIndexComp("mesh", pathname, "neighbours")
+    );
     meshSlice.node("ownerStarts")->add
     (
         "mesh",
@@ -134,7 +133,10 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
         Foam::count_geq(0)
     );
 
-    InitStrategyPtr init_faceStarts(new InitIndexComp("mesh", "faceStarts"));
+    InitStrategyPtr init_faceStarts
+    (
+        new InitIndexComp("mesh", pathname, "faceStarts")
+    );
     meshSlice.node("ownerStarts")->add
     (
         "mesh",
@@ -144,7 +146,10 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
         Foam::count_from_front_plus_one
     );
 
-    InitStrategyPtr init_faces(new InitIndexComp("mesh", "faces"));
+    InitStrategyPtr init_faces
+    (
+        new InitIndexComp("mesh", pathname, "faces")
+    );
     meshSlice.node("faceStarts")->add
     (
         "mesh",
@@ -165,11 +170,15 @@ void Foam::sliceMesh::readMesh(const fileName& pathname)
     );
     meshSlice.decorate<Foam::SliceDecorator>("pointOffsets");
 
+    InitStrategyPtr init_points
+    (
+        new InitPrimitivesFromADIOS<pointField>("mesh", pathname, "points")
+    );
     meshSlice.node("pointOffsets")->add<FieldComponent<pointField>>
     (
         "mesh",
         "points",
-        nullptr,
+        std::move(init_points),
         Foam::start_from_front,
         Foam::count_from_front
     );
-- 
GitLab