From ab80957076b964bdb9384b51a584d085c38ef94a Mon Sep 17 00:00:00 2001
From: Tobias Meisel <tobias.meisel@ufz.de>
Date: Thu, 12 Sep 2024 15:47:22 +0200
Subject: [PATCH] [MeL] XDMFWriter: Introduce parent data type with
 Polyvertex(new) and Mixed

---
 MeshLib/IO/XDMF/MeshPropertyDataType.h | 10 ++++++++++
 MeshLib/IO/XDMF/XdmfData.cpp           |  6 ++++--
 MeshLib/IO/XDMF/XdmfData.h             |  7 +++++--
 MeshLib/IO/XDMF/writeXdmf.cpp          |  3 ++-
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/MeshLib/IO/XDMF/MeshPropertyDataType.h b/MeshLib/IO/XDMF/MeshPropertyDataType.h
index ddfe135dd22..bee2efdf504 100644
--- a/MeshLib/IO/XDMF/MeshPropertyDataType.h
+++ b/MeshLib/IO/XDMF/MeshPropertyDataType.h
@@ -27,4 +27,14 @@ enum class MeshPropertyDataType
     char_native,
     uchar,
     enum_length
+};
+
+
+// See https://www.xdmf.org/index.php/XDMF_Model_and_Format - only relevant of
+// TopologyType(s) added, structure is open to be extended with GridType(s)
+// and ItemType(s).
+enum class ParentDataType
+{
+    Polyvertex=0,
+    Mixed,
 };
\ No newline at end of file
diff --git a/MeshLib/IO/XDMF/XdmfData.cpp b/MeshLib/IO/XDMF/XdmfData.cpp
index c3473970a25..d1aa37793ee 100644
--- a/MeshLib/IO/XDMF/XdmfData.cpp
+++ b/MeshLib/IO/XDMF/XdmfData.cpp
@@ -24,7 +24,8 @@ XdmfData::XdmfData(std::size_t const size_partitioned_dim,
                    std::string const& name,
                    std::optional<MeshLib::MeshItemType> const attribute_center,
                    unsigned int const index,
-                   unsigned int const n_files)
+                   unsigned int const n_files,
+                   std::optional<ParentDataType> const parent_data_type)
     : starts(
           [&size_tuple]()
           {
@@ -52,7 +53,8 @@ XdmfData::XdmfData(std::size_t const size_partitioned_dim,
       data_type(mesh_property_data_type),
       name(name),
       attribute_center(attribute_center),
-      index(index)
+      index(index),
+      parent_data_type(parent_data_type)
 {
     auto partition_info = getPartitionInfo(size_partitioned_dim, n_files);
     // TODO (tm) XdmfLib does not support 64 bit data types so far
diff --git a/MeshLib/IO/XDMF/XdmfData.h b/MeshLib/IO/XDMF/XdmfData.h
index b44a59e4dad..273d0d4a44b 100644
--- a/MeshLib/IO/XDMF/XdmfData.h
+++ b/MeshLib/IO/XDMF/XdmfData.h
@@ -48,13 +48,15 @@ struct XdmfData final
      * Geometry, 3=Topology, 4>=Attribute
      * @param n_files specifies the number of files. If greater than 1 it groups
      * the data of each process to n_files
-     *
+     * @param parent_data_type specifies the type of the parent structure
+     * (e.g. Topology, DataItem, Grid)
      */
     XdmfData(std::size_t size_partitioned_dim, std::size_t size_tuple,
              MeshPropertyDataType mesh_property_data_type,
              std::string const& name,
              std::optional<MeshLib::MeshItemType> attribute_center,
-             unsigned int const index, unsigned int n_files);
+             unsigned int const index, unsigned int n_files,
+             std::optional<ParentDataType> parent_data_type);
     // a hyperslab is defined by starts and strides see
     // https://xdmf.org/index.php/XDMF_Model_and_Format#HyperSlab
     std::vector<XdmfDimType> starts;
@@ -64,6 +66,7 @@ struct XdmfData final
     std::string name;
     std::optional<MeshLib::MeshItemType> attribute_center;
     unsigned int index;
+    std::optional<ParentDataType> parent_data_type;
 };
 
 }  // namespace MeshLib::IO
diff --git a/MeshLib/IO/XDMF/writeXdmf.cpp b/MeshLib/IO/XDMF/writeXdmf.cpp
index c1b1bed1815..ce0a490ad04 100644
--- a/MeshLib/IO/XDMF/writeXdmf.cpp
+++ b/MeshLib/IO/XDMF/writeXdmf.cpp
@@ -205,7 +205,8 @@ std::function<std::string(std::vector<double>)> write_xdmf(
     {
         return fmt::format(
             fmt::runtime("\n\t<Topology Dimensions=\"{dimensions}\" "
-                         "Type=\"Mixed\">{dataitem}\n\t</Topology>"),
+                         "Type={topology_type}>{dataitem}\n\t</Topology>"),
+            "topology_type"_a = "Mixed",
             "dataitem"_a = dataitem_transform(topology),
             "dimensions"_a = fmt::join(topology.global_block_dims, " "));
     };
-- 
GitLab