108 std::vector<XdmfData>
const& constant_attributes,
109 std::vector<XdmfData>
const& variable_attributes,
110 std::string
const& h5filename, std::string
const& ogs_version,
111 std::string
const& mesh_name)
117 auto const time_dataitem_genfn =
118 [](
unsigned long long const time_step,
int const max_step,
119 std::string
const& h5filename, std::string
const& mesh_name)
122 [time_step, max_step, h5filename, mesh_name](
auto const& xdmfdata)
125 fmt::runtime(
"\n\t\t<DataItem DataType=\"{datatype}\" "
126 "Dimensions=\"{local_dimensions}\" "
128 "Precision=\"{precision}\">"
129 "{filename}:/meshes/{meshname}/{datasetname}|"
130 "{time_step} {starts}:1 {strides}:1 "
131 "{local_dimensions}:{max_step} "
132 "{global_dimensions}</"
135 "local_dimensions"_a =
136 fmt::join(xdmfdata.global_block_dims,
" "),
138 "filename"_a = h5filename,
139 "meshname"_a = mesh_name,
140 "datasetname"_a = xdmfdata.name,
141 "starts"_a = fmt::join(xdmfdata.starts,
" "),
142 "strides"_a = fmt::join(xdmfdata.strides,
" "),
143 "global_dimensions"_a =
144 fmt::join(xdmfdata.global_block_dims,
" "),
145 "time_step"_a = fmt::format(
"{}", time_step),
146 "max_step"_a = fmt::format(
"{}", max_step));
151 auto const string_join_fn = [](
auto const& collection)
152 {
return fmt::to_string(fmt::join(collection,
"")); };
155 auto const m_bind_fn = [](
auto const& transform,
auto const& join)
157 return [join, transform](
auto const& collection)
159 std::vector<std::string> temp;
160 temp.reserve(collection.size());
161 std::transform(collection.begin(), collection.end(),
162 std::back_inserter(temp), transform);
170 auto const pointer_transfrom = [](
auto const& elements)
173 fmt::runtime(
"\n\t<xi:include xpointer=\"element(/{elements})\"/>"),
174 "elements"_a = fmt::join(elements,
"/"));
179 auto const attribute_transform =
180 [](
XdmfData const& attribute,
auto const& dataitem_transform)
183 "\n\t<Attribute Center=\"{center}\" ElementCell=\"\" "
184 "ElementDegree=\"0\" "
185 "ElementFamily=\"\" ItemType=\"\" Name=\"{name}\" "
186 "Type=\"None\">{dataitem}\n\t</Attribute>",
188 "name"_a = attribute.
name,
189 "dataitem"_a = dataitem_transform(attribute));
193 auto const geometry_transform =
194 [](
XdmfData const& geometry,
auto const& dataitem_transform)
197 fmt::runtime(
"\n\t<Geometry Origin=\"\" "
198 "Type=\"XYZ\">{dataitem}\n\t</Geometry>"),
199 "dataitem"_a = dataitem_transform(geometry));
202 auto tag_string = [](
auto const& topology,
int nodes_per_element,
203 auto const& dataitem_transform)
206 fmt::runtime(
"\n\t<Topology Dimensions=\"{dimensions}\" "
207 "Type=\"{topology_type}\" "
208 "NodesPerElement=\"{nodes_per_element}\">{dataitem}"
212 "dataitem"_a = dataitem_transform(topology),
214 "nodes_per_element"_a = nodes_per_element);
218 auto const topology_transform =
219 [&tag_string](
XdmfData const& topology,
auto const& dataitem_transform)
224 return tag_string(topology, 1, dataitem_transform);
226 return tag_string(topology, 2, dataitem_transform);
246 "\n\t<Topology Dimensions=\"{dimensions}\" "
247 "Type=\"{topology_type}\">{dataitem}\n\t</Topology>"),
250 "dataitem"_a = dataitem_transform(topology),
254 OGS_FATAL(
"Could not transform unknown XDMF topology type");
255 return std::string{};
260 auto const grid_transform =
261 [](
double const& time_value,
auto const& geometry,
auto const& topology,
262 auto const& constant_attributes,
auto const& variable_attributes)
266<Grid Name="Grid" GridType="Uniform">
267 <Time Value="{time_value:.{precision}g}"/>
273 "time_value"_a = time_value,
275 "precision"_a = std::numeric_limits<double>::max_digits10,
276 "geometry"_a = geometry,
277 "topology"_a = topology,
278 "fix_attributes"_a = constant_attributes,
279 "variable_attributes"_a = variable_attributes);
283 enum class time_attribute
291 auto const time_step_fn = [time_dataitem_genfn, pointer_transfrom,
293 mesh_name](
auto const& component_transform,
294 unsigned long long const time_step,
296 time_attribute
const variable)
298 return [component_transform, time_dataitem_genfn, pointer_transfrom,
299 variable, time_step, max_step, h5filename,
304 ((time_step > 0 && (variable == time_attribute::variable)) ||
308 auto dataitem = time_dataitem_genfn(time_step, max_step,
309 h5filename, mesh_name);
310 return component_transform(attr, dataitem);
314 std::array<unsigned int, 5> position = {1, 1, 2, 1, attr.index};
315 return pointer_transfrom(position);
324 auto const time_grid_transform =
325 [time_step_fn, m_bind_fn, string_join_fn, grid_transform,
326 geometry_transform, topology_transform, attribute_transform](
327 double const time,
int const step,
int const max_step,
328 auto const& geometry,
auto const& topology,
329 auto const& constant_attributes,
auto const& variable_attributes)
331 auto const time_step_geometry_transform = time_step_fn(
332 geometry_transform, step, max_step, time_attribute::constant);
333 auto const time_step_topology_transform = time_step_fn(
334 topology_transform, step, max_step, time_attribute::constant);
335 auto const time_step_const_attribute_fn = time_step_fn(
336 attribute_transform, step, max_step, time_attribute::constant);
337 auto const time_step_variable_attribute_fn = time_step_fn(
338 attribute_transform, step, max_step, time_attribute::variable);
342 auto const variable_attributes_transform =
343 m_bind_fn(time_step_variable_attribute_fn, string_join_fn);
344 auto const constant_attributes_transform =
345 m_bind_fn(time_step_const_attribute_fn, string_join_fn);
347 return grid_transform(
348 time, time_step_geometry_transform(geometry),
349 time_step_topology_transform(topology),
350 constant_attributes_transform(constant_attributes),
351 variable_attributes_transform(variable_attributes));
357 auto const temporal_grid_collection_transform =
358 [time_grid_transform](
359 auto const& times,
auto const& geometry,
auto const& topology,
360 auto const& constant_attributes,
auto const& variable_attributes)
363 auto const max_step = times.size();
364 std::vector<std::string> grids;
365 grids.reserve(max_step);
366 for (
size_t time_step = 0; time_step < max_step; ++time_step)
368 grids.push_back(time_grid_transform(
369 times[time_step], time_step, max_step, geometry, topology,
370 constant_attributes, variable_attributes));
374 "\n<Grid CollectionType=\"Temporal\" GridType=\"Collection\" "
375 "Name=\"Collection\">{grids}\n</Grid>\n"),
376 "grids"_a = fmt::join(grids,
""));
381 auto const xdmf_writer_fn = [temporal_grid_collection_transform](
382 auto ogs_version,
auto geometry,
383 auto topology,
auto constant_attributes,
384 auto variable_attributes)
389 return [temporal_grid_collection_transform,
390 ogs_version = std::move(ogs_version),
391 geometry = std::move(geometry), topology = std::move(topology),
392 constant_attributes = std::move(constant_attributes),
393 variable_attributes = std::move(variable_attributes)](
394 std::vector<double>
const& times)
397 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Xdmf "
398 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
399 "Version=\"3.0\">\n<Domain>\n<Information Name=\"OGS_VERSION\" "
400 "Value=\"{ogs_version}\"/>{grid_collection}</Domain>\n</Xdmf>",
401 "ogs_version"_a = ogs_version,
402 "grid_collection"_a = temporal_grid_collection_transform(
403 times, geometry, topology, constant_attributes,