Write xdmf and h5 file with geometry and topology data.
72{
73
74
75
76
77
78
79
80
81
82
83
84 auto const transform_ogs_mesh_data_to_xdmf_conforming_data =
85 [&n_files, &chunk_size_bytes](auto const& mesh)
86 {
88
90 mesh, flattened_geometry_values.data(), n_files, chunk_size_bytes);
91 auto const flattened_topology_values =
93 return std::make_unique<TransformedMeshData>(
94 TransformedMeshData{std::move(flattened_geometry_values),
95 std::move(flattened_topology_values)});
96 };
97
98
99 auto const transform_to_meta_data =
100 [&transform_ogs_mesh_data_to_xdmf_conforming_data, &n_files,
101 &chunk_size_bytes](auto const& mesh)
102 {
103
104
105 std::unique_ptr<TransformedMeshData> xdmf_conforming_data =
106 transform_ogs_mesh_data_to_xdmf_conforming_data(mesh);
108 mesh, xdmf_conforming_data->flattened_geometry_values.data(),
109 n_files, chunk_size_bytes);
110 auto const topology =
112 n_files, chunk_size_bytes);
113 auto const attributes =
115 return XdmfHdfMesh{std::move(geometry), std::move(topology),
116 std::move(attributes), mesh.get().getName(),
117 std::move(xdmf_conforming_data)};
118 };
119 auto isVariableHdfAttribute =
120 isVariableAttribute<HdfData>(variable_output_names);
121
122
123 auto const transform_metamesh_to_hdf =
124 [&isVariableHdfAttribute](auto const& metamesh)
125 {
126
127 std::vector<HdfData> hdf_data_attributes = {metamesh.geometry.hdf,
128 metamesh.topology.hdf};
129
130 hdf_data_attributes.reserve(hdf_data_attributes.size() +
131 metamesh.attributes.size());
132 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
133 std::back_inserter(hdf_data_attributes),
134 [](XdmfHdfData att) -> HdfData { return att.hdf; });
135
137 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
138 back_inserter(constant_attributes),
139 std::not_fn(isVariableHdfAttribute));
141 std::copy_if(hdf_data_attributes.begin(), hdf_data_attributes.end(),
142 back_inserter(variable_attributes),
143 isVariableHdfAttribute);
144
145 return MeshHdfData{
146 .constant_attributes = std::move(constant_attributes),
147 .variable_attributes = std::move(variable_attributes),
148 .name = std::move(metamesh.name)};
149 };
150
151
152 std::vector<XdmfHdfMesh> xdmf_hdf_meshes;
153 xdmf_hdf_meshes.reserve(meshes.size());
154 std::transform(meshes.begin(), meshes.end(),
155 std::back_inserter(xdmf_hdf_meshes), transform_to_meta_data);
156
157 std::vector<MeshHdfData> hdf_meshes;
158 hdf_meshes.reserve(xdmf_hdf_meshes.size());
159 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
160 std::back_inserter(hdf_meshes), transform_metamesh_to_hdf);
161
162
163 std::filesystem::path const hdf_filepath =
164 filepath.parent_path() / (filepath.stem().string() + ".h5");
165
167 _hdf_writer = std::make_unique<HdfWriter>(std::move(hdf_meshes), time_step,
168 hdf_filepath, use_compression,
169 is_file_manager, n_files);
170
171
172
173 if (!is_file_manager)
174 {
175 return;
176 }
177
178 auto isVariableXdmfAttribute =
179 isVariableAttribute<XdmfData>(variable_output_names);
180
181
182 auto const transform_metamesh_to_xdmf =
183 [&isVariableXdmfAttribute, &filepath, &hdf_filepath,
184 &initial_time](XdmfHdfMesh& metamesh)
185 {
186 std::string const xdmf_name = metamesh.name;
187 std::filesystem::path const xdmf_filepath =
188 filepath.parent_path() /
189 (filepath.stem().string() + "_" + xdmf_name + ".xdmf");
190
191 std::vector<XdmfData> xdmf_attributes;
192 std::transform(metamesh.attributes.begin(), metamesh.attributes.end(),
193 std::back_inserter(xdmf_attributes),
194 [](XdmfHdfData const& att) -> XdmfData
195 { return att.xdmf; });
196
197 for (std::size_t i = 0; i < metamesh.attributes.size(); ++i)
198 {
199
200
201 xdmf_attributes[i].index = i + 4;
202 }
203
204 std::vector<XdmfData> xdmf_variable_attributes;
205 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
206 back_inserter(xdmf_variable_attributes),
207 isVariableXdmfAttribute);
208 std::vector<XdmfData> xdmf_constant_attributes;
209 std::copy_if(xdmf_attributes.begin(), xdmf_attributes.end(),
210 back_inserter(xdmf_constant_attributes),
211 std::not_fn(isVariableXdmfAttribute));
212
213 auto const xdmf_writer_fn =
214 write_xdmf(metamesh.geometry.xdmf, metamesh.topology.xdmf,
215 xdmf_constant_attributes, xdmf_variable_attributes,
216 hdf_filepath.filename().string(),
218 auto xdmf_writer = std::make_unique<XdmfWriter>(xdmf_filepath.string(),
219 xdmf_writer_fn);
220 xdmf_writer->addTimeStep(initial_time);
221 return xdmf_writer;
222 };
223
224 std::transform(xdmf_hdf_meshes.begin(), xdmf_hdf_meshes.end(),
226 transform_metamesh_to_xdmf);
227}
std::unique_ptr< HdfWriter > _hdf_writer
std::vector< std::unique_ptr< XdmfWriter > > _xdmf_writer
GITINFOLIB_EXPORT const std::string ogs_version
std::vector< int > 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< HdfData > HDFAttributes
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::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< int > const &values, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for topology used for HDF5 and XDMF.