9 #include "HDF5Interface.h"
10 #include "pugixml.hpp"
12 #include <dolfinx/common/utils.h>
13 #include <dolfinx/mesh/cell_types.h>
18 #include <xtl/xspan.hpp>
36 class CoordinateElement;
44 namespace io::xdmf_utils
49 std::pair<std::string, int> get_cell_type(
const pugi::xml_node& topology_node);
53 std::array<std::string, 2> get_hdf5_paths(
const pugi::xml_node& dataitem_node);
56 get_hdf5_filename(
const std::filesystem::path& xdmf_filename);
59 std::vector<std::int64_t> get_dataset_shape(
const pugi::xml_node& dataset_node);
62 std::int64_t get_num_cells(
const pugi::xml_node& topology_node);
66 std::vector<double> get_point_data_values(
const fem::Function<double>& u);
67 std::vector<std::complex<double>>
68 get_point_data_values(
const fem::Function<std::complex<double>>& u);
71 std::vector<double> get_cell_data_values(
const fem::Function<double>& u);
72 std::vector<std::complex<double>>
73 get_cell_data_values(
const fem::Function<std::complex<double>>& u);
76 std::string vtk_cell_type_str(
mesh::CellType cell_type,
int num_nodes);
103 std::pair<std::vector<std::int32_t>, std::vector<std::int32_t>>
104 distribute_entity_data(
const mesh::Mesh& mesh,
int entity_dim,
105 const xtl::span<const std::int64_t>& entities,
106 const xtl::span<const std::int32_t>& data);
109 template <
typename T>
110 void add_data_item(pugi::xml_node& xml_node,
const hid_t h5_id,
111 const std::string& h5_path,
const T& x, std::int64_t offset,
112 const std::vector<std::int64_t>& shape,
113 const std::string& number_type,
bool use_mpi_io)
117 pugi::xml_node data_item_node = xml_node.append_child(
"DataItem");
118 assert(data_item_node);
123 dims += std::to_string(d) + std::string(
" ");
125 data_item_node.append_attribute(
"Dimensions") = dims.c_str();
129 if (!number_type.empty())
130 data_item_node.append_attribute(
"NumberType") = number_type.c_str();
135 data_item_node.append_attribute(
"Format") =
"XML";
136 assert(shape.size() == 2);
137 std::ostringstream s;
139 for (std::size_t i = 0; i < (std::size_t)x.size(); ++i)
141 if ((i + 1) % shape[1] == 0 and shape[1] != 0)
142 s << x.data()[i] << std::endl;
144 s << x.data()[i] <<
" ";
147 data_item_node.append_child(pugi::node_pcdata).set_value(s.str().c_str());
151 data_item_node.append_attribute(
"Format") =
"HDF";
155 const std::filesystem::path filename = p.filename().c_str();
158 const std::string xdmf_path
159 = filename.string() + std::string(
":") + h5_path;
160 data_item_node.append_child(pugi::node_pcdata).set_value(xdmf_path.c_str());
163 std::int64_t local_shape0 = x.size();
164 for (std::size_t i = 1; i < shape.size(); ++i)
166 assert(local_shape0 % shape[i] == 0);
167 local_shape0 /= shape[i];
170 const std::array
local_range{offset, offset + local_shape0};
static std::filesystem::path get_filename(hid_t handle)
Get filename.
Definition: HDF5Interface.cpp:136
static void write_dataset(const hid_t handle, const std::string &dataset_path, const T *data, const std::array< std::int64_t, 2 > &range, const std::vector< std::int64_t > &global_size, bool use_mpi_io, bool use_chunking)
Write data to existing HDF file as defined by range blocks on each process.
constexpr std::array< std::int64_t, 2 > local_range(int rank, std::int64_t N, int size)
Return local range for the calling process, partitioning the global [0, N - 1] range across all ranks...
Definition: MPI.h:82
CellType
Cell type identifier.
Definition: cell_types.h:22