13#include <dolfinx/common/MPI.h>
14#include <dolfinx/mesh/MeshTags.h>
34template <std::
floating_po
int T>
36template <std::
floating_po
int T>
42namespace io::xdmf_mesh
49template <std::
floating_po
int U>
50void add_mesh(MPI_Comm comm, pugi::xml_node& xml_node, hid_t h5_id,
63template <std::
floating_po
int U>
67 std::span<const std::int32_t> entities);
70template <std::
floating_po
int U>
72 std::string path_prefix,
81std::pair<std::variant<std::vector<float>, std::vector<double>>,
82 std::array<std::size_t, 2>>
91std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
95template <
typename T, std::
floating_po
int U>
98 hid_t h5_id,
const std::string& name)
100 LOG(INFO) <<
"XDMF: add meshtags (" << name <<
")";
102 const int dim = meshtags.
dim();
103 std::shared_ptr<const common::IndexMap> entity_map
104 = meshtags.
topology()->index_map(dim);
107 throw std::runtime_error(
"Missing entities. Did you forget to call "
108 "dolfinx::mesh::Topology::create_entities?");
110 const std::int32_t num_local_entities = entity_map->size_local();
113 auto it = std::lower_bound(meshtags.
indices().begin(),
114 meshtags.
indices().end(), num_local_entities);
115 const int num_active_entities = std::distance(meshtags.
indices().begin(), it);
117 const std::string path_prefix =
"/MeshTags/" + name;
119 comm, xml_node, h5_id, path_prefix, *meshtags.
topology(), geometry, dim,
120 std::span<const std::int32_t>(meshtags.
indices().data(),
121 num_active_entities));
124 pugi::xml_node attribute_node = xml_node.append_child(
"Attribute");
125 assert(attribute_node);
126 attribute_node.append_attribute(
"Name") = name.c_str();
127 attribute_node.append_attribute(
"AttributeType") =
"Scalar";
128 attribute_node.append_attribute(
"Center") =
"Cell";
130 std::int64_t global_num_values = 0;
131 const std::int64_t local_num_values = num_active_entities;
132 MPI_Allreduce(&local_num_values, &global_num_values, 1, MPI_INT64_T, MPI_SUM,
134 const std::int64_t num_local = num_active_entities;
135 std::int64_t offset = 0;
136 MPI_Exscan(&num_local, &offset, 1, MPI_INT64_T, MPI_SUM, comm);
138 xdmf_utils::add_data_item(
139 attribute_node, h5_id, path_prefix + std::string(
"/Values"),
140 std::span<const T>(meshtags.
values().data(), num_active_entities), offset,
141 {global_num_values, 1},
"", use_mpi_io);
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:33
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:44
int size(MPI_Comm comm)
Return size of the group (number of processes) associated with the communicator.
Definition MPI.cpp:72
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > read_topology_data(MPI_Comm comm, hid_t h5_id, const pugi::xml_node &node)
Read topology (cell connectivity) data.
Definition xdmf_mesh.cpp:303
std::pair< std::variant< std::vector< float >, std::vector< double > >, std::array< std::size_t, 2 > > read_geometry_data(MPI_Comm comm, hid_t h5_id, const pugi::xml_node &node)
Read geometry (coordinate) data.
Definition xdmf_mesh.cpp:263
void add_meshtags(MPI_Comm comm, const mesh::MeshTags< T > &meshtags, const mesh::Geometry< U > &geometry, pugi::xml_node &xml_node, hid_t h5_id, const std::string &name)
Add mesh tags to XDMF file.
Definition xdmf_mesh.h:96
void add_geometry_data(MPI_Comm comm, pugi::xml_node &xml_node, hid_t h5_id, std::string path_prefix, const mesh::Geometry< U > &geometry)
Add Geometry xml node.
Definition xdmf_mesh.cpp:169
void add_mesh(MPI_Comm comm, pugi::xml_node &xml_node, hid_t h5_id, const mesh::Mesh< U > &mesh, const std::string &path_prefix)
Add Mesh to xml node.
Definition xdmf_mesh.cpp:223
void add_topology_data(MPI_Comm comm, pugi::xml_node &xml_node, hid_t h5_id, std::string path_prefix, const mesh::Topology &topology, const mesh::Geometry< U > &geometry, int cell_dim, std::span< const std::int32_t > entities)
Add Topology xml node.
Definition xdmf_mesh.cpp:23
Top-level namespace.
Definition defines.h:12