| 161 | //----------------------------------------------------------------------------- |
| 162 | template <std::floating_point U> |
| 163 | void xdmf_mesh::add_geometry_data(MPI_Comm comm, pugi::xml_node& xml_node, |
| 164 | hid_t h5_id, const std::string& path_prefix, |
| 165 | const mesh::Geometry<U>& geometry) |
| 166 | { |
| 167 | spdlog::info("Adding geometry data to node \"{}\"", xml_node.path('/')); |
| 168 | auto map = geometry.index_map(); |
| 169 | assert(map); |
| 170 | |
| 171 | // Compute number of points (global) in mesh (equal to number of vertices |
| 172 | // for affine meshes) |
| 173 | const std::int64_t num_points = map->size_global(); |
| 174 | const std::int32_t num_points_local = map->size_local(); |
| 175 | |
| 176 | // Add geometry node and attributes |
| 177 | int gdim = geometry.dim(); |
| 178 | pugi::xml_node geometry_node = xml_node.append_child("Geometry"); |
| 179 | assert(geometry_node); |
| 180 | assert(gdim > 0 and gdim <= 3); |
| 181 | const std::string geometry_type = (gdim == 3) ? "XYZ" : "XY"; |
| 182 | geometry_node.append_attribute("GeometryType") = geometry_type.c_str(); |
| 183 | |
| 184 | // Increase 1D to 2D because XDMF has no "X" geometry, use "XY" |
| 185 | const int width = (gdim == 1) ? 2 : gdim; |
| 186 | |
| 187 | std::span<const U> _x = geometry.x(); |
| 188 | |
| 189 | int num_values = num_points_local * width; |
| 190 | std::vector<U> x(num_values, 0); |
| 191 | |
| 192 | if (width == 3) |
| 193 | std::copy_n(_x.data(), num_values, x.begin()); |
| 194 | else |
| 195 | { |
| 196 | for (int i = 0; i < num_points_local; ++i) |
| 197 | { |
| 198 | std::copy_n(std::next(_x.begin(), 3 * i), gdim, |
| 199 | std::next(x.begin(), width * i)); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Add geometry DataItem node |
| 204 | const std::string h5_path = path_prefix + std::string("/geometry"); |
| 205 | const std::vector<std::int64_t> shape = {num_points, width}; |
| 206 | |
| 207 | const std::int64_t num_local = num_points_local; |
| 208 | std::int64_t offset = 0; |
| 209 | MPI_Exscan(&num_local, &offset, 1, MPI_INT64_T, MPI_SUM, comm); |
| 210 | const bool use_mpi_io = (dolfinx::MPI::size(comm) > 1); |
| 211 | xdmf_utils::add_data_item(geometry_node, h5_id, h5_path, |
| 212 | std::span<const U>(x), offset, shape, "", |
| 213 | use_mpi_io); |
| 214 | } |
| 215 | //---------------------------------------------------------------------------- |
| 216 | template <std::floating_point U> |
| 217 | void xdmf_mesh::add_mesh(MPI_Comm comm, pugi::xml_node& xml_node, hid_t h5_id, |
nothing calls this directly
no test coverage detected