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 Type=\"{topology_type}\" "
207 "NodesPerElement=\"{nodes_per_element}\" "
208 "NumberOfElements=\"{number_of_elements}\">{dataitem}"
212 "dataitem"_a = dataitem_transform(topology),
213 "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);
247 "Type=\"{topology_type}\">{dataitem}\n\t</Topology>"),
250 "dataitem"_a = dataitem_transform(topology));
252 OGS_FATAL(
"Could not transform unknown XDMF topology type");
253 return std::string{};
258 auto const grid_transform =
259 [](
double const& time_value,
auto const& geometry,
auto const& topology,
260 auto const& constant_attributes,
auto const& variable_attributes)
264<Grid Name="Grid" GridType="Uniform">
265 <Time Value="{time_value:.{precision}g}"/>
271 "time_value"_a = time_value,
273 "precision"_a = std::numeric_limits<double>::max_digits10,
274 "geometry"_a = geometry,
275 "topology"_a = topology,
276 "fix_attributes"_a = constant_attributes,
277 "variable_attributes"_a = variable_attributes);
281 enum class time_attribute
289 auto const time_step_fn = [time_dataitem_genfn, pointer_transfrom,
291 mesh_name](
auto const& component_transform,
292 unsigned long long const time_step,
294 time_attribute
const variable)
296 return [component_transform, time_dataitem_genfn, pointer_transfrom,
297 variable, time_step, max_step, h5filename,
302 ((time_step > 0 && (variable == time_attribute::variable)) ||
306 auto dataitem = time_dataitem_genfn(time_step, max_step,
307 h5filename, mesh_name);
308 return component_transform(attr, dataitem);
312 std::array<unsigned int, 5> position = {1, 1, 2, 1, attr.index};
313 return pointer_transfrom(position);
322 auto const time_grid_transform =
323 [time_step_fn, m_bind_fn, string_join_fn, grid_transform,
324 geometry_transform, topology_transform, attribute_transform](
325 double const time,
int const step,
int const max_step,
326 auto const& geometry,
auto const& topology,
327 auto const& constant_attributes,
auto const& variable_attributes)
329 auto const time_step_geometry_transform = time_step_fn(
330 geometry_transform, step, max_step, time_attribute::constant);
331 auto const time_step_topology_transform = time_step_fn(
332 topology_transform, step, max_step, time_attribute::constant);
333 auto const time_step_const_attribute_fn = time_step_fn(
334 attribute_transform, step, max_step, time_attribute::constant);
335 auto const time_step_variable_attribute_fn = time_step_fn(
336 attribute_transform, step, max_step, time_attribute::variable);
340 auto const variable_attributes_transform =
341 m_bind_fn(time_step_variable_attribute_fn, string_join_fn);
342 auto const constant_attributes_transform =
343 m_bind_fn(time_step_const_attribute_fn, string_join_fn);
345 return grid_transform(
346 time, time_step_geometry_transform(geometry),
347 time_step_topology_transform(topology),
348 constant_attributes_transform(constant_attributes),
349 variable_attributes_transform(variable_attributes));
355 auto const temporal_grid_collection_transform =
356 [time_grid_transform](
357 auto const& times,
auto const& geometry,
auto const& topology,
358 auto const& constant_attributes,
auto const& variable_attributes)
361 auto const max_step = times.size();
362 std::vector<std::string> grids;
363 grids.reserve(max_step);
364 for (
size_t time_step = 0; time_step < max_step; ++time_step)
366 grids.push_back(time_grid_transform(
367 times[time_step], time_step, max_step, geometry, topology,
368 constant_attributes, variable_attributes));
372 "\n<Grid CollectionType=\"Temporal\" GridType=\"Collection\" "
373 "Name=\"Collection\">{grids}\n</Grid>\n"),
374 "grids"_a = fmt::join(grids,
""));
379 auto const xdmf_writer_fn = [temporal_grid_collection_transform](
380 auto ogs_version,
auto geometry,
381 auto topology,
auto constant_attributes,
382 auto variable_attributes)
387 return [temporal_grid_collection_transform,
388 ogs_version = std::move(ogs_version),
389 geometry = std::move(geometry), topology = std::move(topology),
390 constant_attributes = std::move(constant_attributes),
391 variable_attributes = std::move(variable_attributes)](
392 std::vector<double>
const& times)
395 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Xdmf "
396 "xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
397 "Version=\"3.0\">\n<Domain>\n<Information Name=\"OGS_VERSION\" "
398 "Value=\"{ogs_version}\"/>{grid_collection}</Domain>\n</Xdmf>",
399 "ogs_version"_a = ogs_version,
400 "grid_collection"_a = temporal_grid_collection_transform(
401 times, geometry, topology, constant_attributes,