Write xdmf and h5 file with geometry and topology data.
85{
86
87
88
89
90
91
92
93
94
95
96
97 auto const transform_ogs_mesh_data_to_xdmf_conforming_data =
98 [&n_files, &chunk_size_bytes](auto const& mesh)
99 {
101
103 mesh, flattened_geometry_values.data(), n_files, chunk_size_bytes);
104 auto const [flattened_topology_values, parent_data_type] =
106 return std::make_unique<TransformedMeshData>(TransformedMeshData{
107 std::move(flattened_geometry_values),
108 std::move(flattened_topology_values), parent_data_type});
109 };
110
111
112 auto const transform_to_meta_data =
113 [&output_variable_names,
114 &transform_ogs_mesh_data_to_xdmf_conforming_data, &n_files,
115 &chunk_size_bytes](auto const& mesh)
116 {
117
118
119 std::unique_ptr<TransformedMeshData> xdmf_conforming_data =
120 transform_ogs_mesh_data_to_xdmf_conforming_data(mesh);
122 mesh, xdmf_conforming_data->flattened_geometry_values.data(),
123 n_files, chunk_size_bytes);
125 xdmf_conforming_data->flattened_topology_values,
126 xdmf_conforming_data->parent_data_type, n_files, chunk_size_bytes);
128 n_files, chunk_size_bytes);
129 return XdmfHdfMesh{std::move(geometry), std::move(topology),
130 std::move(attributes), mesh.get().getName(),
131 std::move(xdmf_conforming_data)};
132 };
134 output_variable_names, static_attribute_names);
135
136
137 auto const transform_metamesh_to_hdf =
138 [&isVariableHdfAttribute](auto const& metamesh)
139 {
140
141 std::vector<HdfData> hdf_data_attributes = {metamesh.geometry.hdf,
142 metamesh.topology.hdf};
143
144 hdf_data_attributes.reserve(hdf_data_attributes.size() +
145 metamesh.attributes.size());
146 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
147 std::back_inserter(hdf_data_attributes),
148 [](XdmfHdfData att) -> HdfData { return att.hdf; });
149
151 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
152 back_inserter(constant_attributes),
153 std::not_fn(isVariableHdfAttribute));
155 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
156 back_inserter(variable_attributes),
157 isVariableHdfAttribute);
158
159 return MeshHdfData{
160 .constant_attributes = std::move(constant_attributes),
161 .variable_attributes = std::move(variable_attributes),
162 .name = std::move(metamesh.name)};
163 };
164
165
166 std::vector<XdmfHdfMesh> xdmf_hdf_meshes;
167 xdmf_hdf_meshes.reserve(meshes.size());
168 std::transform(meshes.begin(), meshes.end(),
169 std::back_inserter(xdmf_hdf_meshes), transform_to_meta_data);
170
171 std::vector<MeshHdfData> hdf_meshes;
172 hdf_meshes.reserve(xdmf_hdf_meshes.size());
173 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
174 std::back_inserter(hdf_meshes), transform_metamesh_to_hdf);
175
176
177 std::filesystem::path const hdf_filepath =
178 filepath.parent_path() / (filepath.stem().string() + ".h5");
179 std::filesystem::path const static_hdf_filepath =
180 filepath.parent_path() / (filepath.stem().string() + "_static.h5");
181
183
184 if (store_static_data_separately)
185 {
186
187
188 std::vector<MeshHdfData> static_hdf_meshes;
189 std::vector<MeshHdfData> dynamic_hdf_meshes;
190 for (auto& m : hdf_meshes)
191 {
192 static_hdf_meshes.push_back(MeshHdfData{
193 .constant_attributes = std::move(m.constant_attributes),
194 .variable_attributes = {},
195 .name = m.name});
196 dynamic_hdf_meshes.push_back(MeshHdfData{
197 .constant_attributes = {},
198 .variable_attributes = std::move(m.variable_attributes),
199 .name = std::move(m.name)});
200 }
201
203 std::move(static_hdf_meshes), time_step, initial_time,
204 static_hdf_filepath, use_compression, is_file_manager, n_files,
205 true);
207 std::move(dynamic_hdf_meshes), time_step, initial_time,
208 hdf_filepath, use_compression, is_file_manager, n_files, false);
209 }
210 else
211 {
212
213
215 std::move(hdf_meshes), time_step, initial_time, hdf_filepath,
216 use_compression, is_file_manager, n_files, false);
217 }
218
219
220
221 if (!is_file_manager)
222 {
223 return;
224 }
225
227 output_variable_names, static_attribute_names);
228
229
230 auto const transform_metamesh_to_xdmf =
231 [&isVariableXdmfAttribute, &filepath, &hdf_filepath,
232 &static_hdf_filepath, &initial_time,
233 store_static_data_separately](XdmfHdfMesh& metamesh)
234 {
235 std::string const xdmf_name = metamesh.name;
236 std::filesystem::path const xdmf_filepath =
237 filepath.parent_path() /
238 (filepath.stem().string() + "_" + xdmf_name + ".xdmf");
239
240 std::vector<XdmfData> xdmf_attributes;
241 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
242 std::back_inserter(xdmf_attributes),
243 [](XdmfHdfData const& att) -> XdmfData
244 { return att.xdmf; });
245
246 std::vector<XdmfData> xdmf_variable_attributes;
247 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
248 back_inserter(xdmf_variable_attributes),
249 isVariableXdmfAttribute);
250 std::vector<XdmfData> xdmf_constant_attributes;
251 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
252 back_inserter(xdmf_constant_attributes),
253 std::not_fn(isVariableXdmfAttribute));
254
255
256
257 auto const static_fn = store_static_data_separately
258 ? static_hdf_filepath.filename().string()
259 : hdf_filepath.filename().string();
260 auto const xdmf_writer_fn =
261 write_xdmf(metamesh.geometry.xdmf, metamesh.topology.xdmf,
262 xdmf_constant_attributes, xdmf_variable_attributes,
263 static_fn, hdf_filepath.filename().string(),
265 auto xdmf_writer = std::make_unique<XdmfWriter>(xdmf_filepath.string(),
266 xdmf_writer_fn);
267 xdmf_writer->addTimeStep(initial_time);
268 return xdmf_writer;
269 };
270
271 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
273 transform_metamesh_to_xdmf);
274}
std::unique_ptr< HdfWriter > _hdf_writer
std::vector< std::unique_ptr< XdmfWriter > > _xdmf_writer
std::unique_ptr< HdfWriter > _static_hdf_writer
GITINFOLIB_EXPORT const std::string ogs_version
std::function< std::string(std::vector< double >)> write_xdmf(XdmfData const &geometry, XdmfData const &topology, std::vector< XdmfData > const &constant_attributes, std::vector< XdmfData > const &variable_attributes, std::string const &static_h5filename, std::string const &dynamic_h5filename, std::string const &ogs_version, std::string const &mesh_name)
Generator function that creates a function capturing the spatial data of a mesh Temporal data can lat...
std::function< bool(Data)> isVariableAttribute(std::set< std::string > const &output_variable_names, std::set< std::string > const &static_attribute_names)
std::vector< HdfData > HDFAttributes
std::pair< std::vector< std::size_t >, ParentDataType > transformToXDMFTopology(MeshLib::Mesh const &mesh, std::size_t const offset)
Copies all cells into a new vector. Contiguous data used for writing. The topology is specific to xdm...
std::vector< double > transformToXDMFGeometry(MeshLib::Mesh const &mesh)
Copies all node points into a new vector. Contiguous data used for writing. Conform with XDMF standar...
XdmfHdfData transformGeometry(MeshLib::Mesh const &mesh, double const *data_ptr, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for geometry used for hdf5 and xdmf.
std::vector< XdmfHdfData > transformAttributes(MeshLib::Mesh const &mesh, std::set< std::string > const &output_variable_names, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for attributes used for hdf5 and xdmf.
XdmfHdfData transformTopology(std::vector< std::size_t > const &values, ParentDataType const parent_data_type, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for topology used for HDF5 and XDMF.