OGS
MeshLib::IO::XdmfHdfWriter Class Referencefinal

Detailed Description

Definition at line 24 of file XdmfHdfWriter.h.

#include <XdmfHdfWriter.h>

Public Member Functions

 XdmfHdfWriter (std::vector< std::reference_wrapper< const MeshLib::Mesh > > const &meshes, std::filesystem::path const &filepath, unsigned long long time_step, double initial_time, std::set< std::string > const &variable_output_names, bool use_compression, unsigned int n_files, unsigned int chunk_size_bytes)
 Write xdmf and h5 file with geometry and topology data.
 
void writeStep (double time)
 Adds data for either lazy (xdmf) or eager (hdf) writing algorithm.
 

Private Attributes

std::unique_ptr< HdfWriter_hdf_writer
 
std::vector< std::unique_ptr< XdmfWriter > > _xdmf_writer
 

Constructor & Destructor Documentation

◆ XdmfHdfWriter()

MeshLib::IO::XdmfHdfWriter::XdmfHdfWriter ( std::vector< std::reference_wrapper< const MeshLib::Mesh > > const & meshes,
std::filesystem::path const & filepath,
unsigned long long time_step,
double initial_time,
std::set< std::string > const & variable_output_names,
bool use_compression,
unsigned int n_files,
unsigned int chunk_size_bytes )

Write xdmf and h5 file with geometry and topology data.

Parameters
meshesMeshes or NodePartitionedMeshes to be written to file(s)
filepathabsolute or relative filepath to the hdf5 file
time_stepnumber of the step (temporal collection)
initial_timetime in seconds of the first time step
variable_output_namesnames of all process variables (attributes) that change over time
use_compressionif true, zlib compression in HDFWriter component is used
n_filesnumber of hdf5 output files
chunk_size_bytesData will be split into chunks. The parameter specifies the size (in bytes) of the largest chunk.

Definition at line 66 of file XdmfHdfWriter.cpp.

73{
74 // ogs meshes to vector of Xdmf/HDF meshes (we keep Xdmf and HDF together
75 // because XDMF depends on HDF) to meta
76
77 // if no output name is specified, all data will be assumened to be
78 // variable over the timesteps. The xdmfhdfwriter is an alternative to
79 // other writers, that do not consider the constantness of data Callers
80 // of xdmfwriter (e.g. ogs tools) do not provide these information yet
81 // and indicate with empty list
82
83 // Transform the data to be written into a format conforming with the rules
84 // of xdmf topology and geometry
85 auto const transform_ogs_mesh_data_to_xdmf_conforming_data =
86 [&n_files, &chunk_size_bytes](auto const& mesh)
87 {
88 auto flattened_geometry_values = transformToXDMFGeometry(mesh);
89 // actually this line is only needed to calculate the offset
90 XdmfHdfData const& geometry = transformGeometry(
91 mesh, flattened_geometry_values.data(), n_files, chunk_size_bytes);
92 auto const [flattened_topology_values, parent_data_type] =
93 transformToXDMFTopology(mesh, geometry.hdf.offsets[0]);
94 return std::make_unique<TransformedMeshData>(TransformedMeshData{
95 std::move(flattened_geometry_values),
96 std::move(flattened_topology_values), parent_data_type});
97 };
98
99 // create metadata for transformed data and original ogs mesh data
100 auto const transform_to_meta_data =
101 [&transform_ogs_mesh_data_to_xdmf_conforming_data, &n_files,
102 &chunk_size_bytes](auto const& mesh)
103 {
104 // important: transformed data must survive and be unique, raw pointer
105 // to its memory!
106 std::unique_ptr<TransformedMeshData> xdmf_conforming_data =
107 transform_ogs_mesh_data_to_xdmf_conforming_data(mesh);
108 auto const geometry = transformGeometry(
109 mesh, xdmf_conforming_data->flattened_geometry_values.data(),
110 n_files, chunk_size_bytes);
111 auto const topology = transformTopology(
112 xdmf_conforming_data->flattened_topology_values,
113 xdmf_conforming_data->parent_data_type, n_files, chunk_size_bytes);
114 auto const attributes =
115 transformAttributes(mesh, n_files, chunk_size_bytes);
116 return XdmfHdfMesh{std::move(geometry), std::move(topology),
117 std::move(attributes), mesh.get().getName(),
118 std::move(xdmf_conforming_data)};
119 };
120 auto isVariableHdfAttribute =
121 isVariableAttribute<HdfData>(variable_output_names);
122
123 // extract meta data relevant for HDFWriter
124 auto const transform_metamesh_to_hdf =
125 [&isVariableHdfAttribute](auto const& metamesh)
126 {
127 // topology and geometry can be treated as any other attribute
128 std::vector<HdfData> hdf_data_attributes = {metamesh.geometry.hdf,
129 metamesh.topology.hdf};
130
131 hdf_data_attributes.reserve(hdf_data_attributes.size() +
132 metamesh.attributes.size());
133 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
134 std::back_inserter(hdf_data_attributes),
135 [](XdmfHdfData att) -> HdfData { return att.hdf; });
136
137 HDFAttributes constant_attributes;
138 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
139 back_inserter(constant_attributes),
140 std::not_fn(isVariableHdfAttribute));
141 HDFAttributes variable_attributes;
142 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
143 back_inserter(variable_attributes),
144 isVariableHdfAttribute);
145
146 return MeshHdfData{
147 .constant_attributes = std::move(constant_attributes),
148 .variable_attributes = std::move(variable_attributes),
149 .name = std::move(metamesh.name)};
150 };
151
152 // --------------- XDMF + HDF ---------------------
153 std::vector<XdmfHdfMesh> xdmf_hdf_meshes;
154 xdmf_hdf_meshes.reserve(meshes.size());
155 std::transform(meshes.begin(), meshes.end(),
156 std::back_inserter(xdmf_hdf_meshes), transform_to_meta_data);
157
158 std::vector<MeshHdfData> hdf_meshes;
159 hdf_meshes.reserve(xdmf_hdf_meshes.size());
160 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
161 std::back_inserter(hdf_meshes), transform_metamesh_to_hdf);
162
163 // --------------- HDF ---------------------
164 std::filesystem::path const hdf_filepath =
165 filepath.parent_path() / (filepath.stem().string() + ".h5");
166
167 auto const is_file_manager = isFileManager();
168 _hdf_writer = std::make_unique<HdfWriter>(std::move(hdf_meshes), time_step,
169 hdf_filepath, use_compression,
170 is_file_manager, n_files);
171
172 // --------------- XDMF ---------------------
173 // The light data is only written by just one process
174 if (!is_file_manager)
175 {
176 return;
177 }
178
179 auto isVariableXdmfAttribute =
180 isVariableAttribute<XdmfData>(variable_output_names);
181 // xdmf section
182 // extract meta data relevant for XDMFWriter
183 auto const transform_metamesh_to_xdmf =
184 [&isVariableXdmfAttribute, &filepath, &hdf_filepath,
185 &initial_time](XdmfHdfMesh& metamesh)
186 {
187 std::string const xdmf_name = metamesh.name;
188 std::filesystem::path const xdmf_filepath =
189 filepath.parent_path() /
190 (filepath.stem().string() + "_" + xdmf_name + ".xdmf");
191
192 std::vector<XdmfData> xdmf_attributes;
193 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
194 std::back_inserter(xdmf_attributes),
195 [](XdmfHdfData const& att) -> XdmfData
196 { return att.xdmf; });
197
198 for (std::size_t i = 0; i < metamesh.attributes.size(); ++i)
199 {
200 // index 1 time, index 2 geo, index 3 topology, attributes start at
201 // index 4
202 xdmf_attributes[i].index = i + 4;
203 }
204
205 std::vector<XdmfData> xdmf_variable_attributes;
206 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
207 back_inserter(xdmf_variable_attributes),
208 isVariableXdmfAttribute);
209 std::vector<XdmfData> xdmf_constant_attributes;
210 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
211 back_inserter(xdmf_constant_attributes),
212 std::not_fn(isVariableXdmfAttribute));
213
214 auto const xdmf_writer_fn =
215 write_xdmf(metamesh.geometry.xdmf, metamesh.topology.xdmf,
216 xdmf_constant_attributes, xdmf_variable_attributes,
217 hdf_filepath.filename().string(),
219 auto xdmf_writer = std::make_unique<XdmfWriter>(xdmf_filepath.string(),
220 xdmf_writer_fn);
221 xdmf_writer->addTimeStep(initial_time);
222 return xdmf_writer;
223 };
224
225 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
226 std::back_inserter(_xdmf_writer),
227 transform_metamesh_to_xdmf);
228}
std::unique_ptr< HdfWriter > _hdf_writer
std::vector< std::unique_ptr< XdmfWriter > > _xdmf_writer
GITINFOLIB_EXPORT const std::string ogs_version
std::vector< HdfData > HDFAttributes
Definition HdfWriter.h:25
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...
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 &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...
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::function< bool(Data)> isVariableAttribute(std::set< std::string > const &variable_output_names)
std::vector< XdmfHdfData > transformAttributes(MeshLib::Mesh const &mesh, 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.
bool isFileManager()
Definition partition.cpp:28

References _hdf_writer, _xdmf_writer, MeshLib::IO::MeshHdfData::constant_attributes, MeshLib::IO::XdmfHdfData::hdf, MeshLib::IO::isFileManager(), MeshLib::IO::isVariableAttribute(), MeshLib::IO::HdfData::offsets, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::transformAttributes(), MeshLib::IO::transformGeometry(), MeshLib::IO::transformTopology(), MeshLib::IO::transformToXDMFGeometry(), MeshLib::IO::transformToXDMFTopology(), and MeshLib::IO::write_xdmf().

Member Function Documentation

◆ writeStep()

void MeshLib::IO::XdmfHdfWriter::writeStep ( double time)

Adds data for either lazy (xdmf) or eager (hdf) writing algorithm.

Parameters
timetime value of the current time_step

Definition at line 230 of file XdmfHdfWriter.cpp.

231{
232 // ToDo (tm) time_step will be used for simulation continuation (restart)
233 _hdf_writer->writeStep(time);
234 // The light data is only written by just one process
235 if (isFileManager())
236 {
237 for (auto const& xdmf_writer : _xdmf_writer)
238 {
239 xdmf_writer->addTimeStep(time);
240 }
241 }
242}

References _hdf_writer, _xdmf_writer, and MeshLib::IO::isFileManager().

Member Data Documentation

◆ _hdf_writer

std::unique_ptr<HdfWriter> MeshLib::IO::XdmfHdfWriter::_hdf_writer
private

Definition at line 56 of file XdmfHdfWriter.h.

Referenced by XdmfHdfWriter(), and writeStep().

◆ _xdmf_writer

std::vector<std::unique_ptr<XdmfWriter> > MeshLib::IO::XdmfHdfWriter::_xdmf_writer
private

Definition at line 57 of file XdmfHdfWriter.h.

Referenced by XdmfHdfWriter(), and writeStep().


The documentation for this class was generated from the following files: