ECOGEN 6.0
Evolutive, Compressible, Open, Genuine, Easy, N-phase
Loading...
Searching...
No Matches
OutputVTKHDF.h
Go to the documentation of this file.
1//
2// ,---. ,--, .---. ,--, ,---. .-. .-.
3// | .-' .' .') / .-. ) .' .' | .-' | \| |
4// | `-. | |(_) | | |(_) | | __ | `-. | | |
5// | .-' \ \ | | | | \ \ ( _) | .-' | |\ |
6// | `--. \ `-. \ `-' / \ `-) ) | `--. | | |)|
7// /( __.' \____\ )---' )\____/ /( __.' /( (_)
8// (__) (_) (__) (__) (__)
9// Official webSite: https://code-mphi.github.io/ECOGEN/
10//
11// This file is part of ECOGEN.
12//
13// ECOGEN is the legal property of its developers, whose names
14// are listed in the copyright file included with this source
15// distribution.
16//
17// ECOGEN is free software: you can redistribute it and/or modify
18// it under the terms of the GNU General Public License as published
19// by the Free Software Foundation, either version 3 of the License,
20// or (at your option) any later version.
21//
22// ECOGEN is distributed in the hope that it will be useful,
23// but WITHOUT ANY WARRANTY; without even the implied warranty of
24// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25// GNU General Public License for more details.
26//
27// You should have received a copy of the GNU General Public License
28// along with ECOGEN (file LICENSE).
29// If not, see <http://www.gnu.org/licenses/>.
30
31#ifndef OUTPUTVTKHDF_H_
32#define OUTPUTVTKHDF_H_
33
34#include <hdf5.h>
35
36#include "Output.h"
37
38class OutputVTKHDF : public Output
39{
40 public:
41 OutputVTKHDF(std::string casTest, std::string run, tinyxml2::XMLElement* element, std::string fileName, Input* entree);
42 OutputVTKHDF(std::string nameRun, int fileNumberRestartMeshMapping, Input* input, const H5FD_mpio_xfer_t& transfer_mode);
43 ~OutputVTKHDF() override;
44
45 virtual void initializeSpecificOutput() override;
46 virtual void writeResults(Mesh* mesh, std::vector<Cell*>* cellsLvl) override;
47 virtual void readResults(Mesh* mesh, std::vector<Cell*>* cellsLvl, int cpu = -1) override;
48
50 virtual const void* getTransferMode() const override { return (void*)&m_transfer_mode; }
51
52 protected:
55 // restarting a simulation with mesh mapping. This method gather the code needed by both constructors: the output type assignement and the
56 // setting of the main hdf5 properties.
58 void initializeProperties(const H5FD_mpio_xfer_t& transfer_mode);
59
66 int readScalarVTKHDF(hid_t group_id, const std::string& dataset_name, std::vector<size_t>& scalar_array) const;
67
75 template <size_t N>
77 hid_t group_id, std::string dataset_name, std::vector<double>& dataset, const hsize_t (&local_dims)[N], const hsize_t (&offsets)[N]);
78
88 template <size_t N>
90 Mesh* mesh, std::vector<Cell*>* cellsLvl, hid_t group_id, const hsize_t (&count_scalar)[N], const hsize_t (&start_scalar)[N]);
91
98 int ReadPhysicalDataVTKHDF(Mesh* mesh, std::vector<Cell*>* cellsLvl, hid_t group_id, int cpu, const std::vector<size_t>& numberCells);
99
100 std::string createFilenameVTKHDF(const char* name, int numFile = -1, std::string nameVariable = "defaut") const;
101
107 int openFileVTKHDF(hid_t& file_id, bool parallel_access, bool create) const;
108
111 void writeTimeseriesVTKHDF(int numFile);
112
115 void writeXDMF(Mesh* mesh, int numFile);
116
125 static void writeDataXDMF(std::ofstream& fileStream,
126 const std::string& dataFile,
127 const std::string& dataName,
128 const std::string& dataType,
129 int numberCellsX,
130 int numberCellsY,
131 int numberCellsZ,
132 int dimData);
133
137 void writeResultsVTKHDF(Mesh* mesh, std::vector<Cell*>* cellsLvl);
138
149 int writePhysicalDataVTKHDF(hid_t& file, const Mesh* mesh, std::vector<Cell*>* cellsLvl, hid_t& vtkhdf_group_id, size_t numberCells) const;
150
165 template <size_t N, typename T>
166 int writePhysicalDataVTKHDF(const Mesh* mesh,
167 std::vector<Cell*>* cellsLvl,
168 hid_t vtkhdf_group_id,
169 size_t numberCells,
170 const hsize_t (&dimsf_scalar)[N],
171 const hsize_t (&count_scalar)[N],
172 const hsize_t (&start_scalar)[N],
173 const hsize_t (&chunk_scalar)[N]) const;
174
186 int writeScalarVTKHDF(const hid_t& group_id, const std::string& dataset_name, const size_t& scalar_val) const;
187
195 static void unstructuredFirstRangeLayout(const size_t& line_count, hsize_t* dimsf, hsize_t* count, hsize_t* start);
196
202 const void* getOutputBuffer(const std::vector<double>& double_buffer, std::vector<float>& float_buffer) const;
203
204 template <typename T>
205 int writeConnectivity(Mesh* mesh, std::vector<Cell*>* cellsLvl, hid_t& vtkhdf_group_id, size_t& numberCells, const size_t& numberNodes) const;
206
225 template <typename T>
226 int writeUnstructuredArrayVTKHDF(const hid_t& group_id,
227 const std::string& dataset_name,
228 hid_t hdf_file_dtype,
229 hid_t hdf_mem_dtype,
230 const std::vector<T>& dataset,
231 const size_t& line_count,
232 size_t column_count = 1) const;
233
255 template <size_t N, typename T>
256 int writeArrayVTKHDF(const hid_t& group_id,
257 const std::string& dataset_name,
258 hid_t hdf_mem_dtype,
259 hid_t hdf_file_dtype,
260 hid_t parallel_x_properties,
261 const std::vector<T>& dataset,
262 const hsize_t (&global_dims)[N],
263 const hsize_t (&local_dims)[N],
264 const hsize_t (&offsets)[N],
265 const hsize_t (&chunk_dims)[N]) const;
266
273 int writeArrayAttribute(const hid_t& group_id, const std::string& attribute_name, const hsize_t& nitem, const int* array) const;
274
281 int writeHeaderVTKHDF(const hid_t& group_id, const std::string& mesh_type) const;
282
283 // Depends on mesh type
284
292 // https://discourse.vtk.org/t/support-for-rectilineargrids-and-structuredgrids-in-vtkhdf-file-format/14283/6
293 // An additional xmdf file is required for Paraview to interpret data.
295 int writeMeshRectilinearVTKHDF(Mesh* mesh, hid_t& file, hid_t& vtkhdf_group_id, size_t& numberCells);
296
305 int writeMeshUnstructuredVTKHDF(Mesh* mesh, std::vector<Cell*>* cellsLvl, hid_t& file, hid_t& vtkhdf_group_id, size_t& numberCells) const;
306
307 void writeDataset(std::vector<double> /*dataset*/, std::ofstream& /*fileStream*/, TypeData /*typeData*/) const
308 {
309 throw ErrorECOGEN("'writeDataset' not available for VTKHDF output format: use 'writeArrayVTKHDF' instead.");
310 };
311
312 static void getDataset(std::istringstream& /*data*/, std::vector<double>& /*dataset*/)
313 {
314 throw ErrorECOGEN("'getDataset' not available for VTKHDF output format: use 'readArrayVTKHDF' instead.");
315 };
316
317 virtual void prepareErrorFiles() const override;
318 virtual void writeErrorInFile(std::vector<Errors>& v, const int& ErrorType, const int& iteration, bool& warn) const override;
327 virtual void printTree(Mesh* mesh, const std::vector<Cell*>* cellsLvl, int m_resumeAMRsaveFreq) const override;
328
329 virtual void readTree(Mesh* mesh,
330 TypeMeshContainer<Cell*>* cellsLvl,
331 TypeMeshContainer<Cell*>* cellsLvlGhost,
332 TypeMeshContainer<CellInterface*>* const cellInterfacesLvl,
333 const std::vector<AddPhys*>& addPhys,
334 int& nbCellsTotalAMR) override;
335
336 private:
339
342
346
347 H5FD_mpio_xfer_t m_transfer_mode;
348
349 static constexpr size_t DIM_OUTPUT{3};
350 static constexpr int VTKHDF_VERSION[2] = {2, 4};
351 static constexpr int ERROR_VALUE = -1;
352 static constexpr int SUCCESS_VALUE = 0;
353};
354
355#endif // OUTPUTVTKHDF_H_
TypeData
Enumeration for the type of data (FLOAT, DOUBLE, INT, CHAR).
Definition Tools.h:73
std::vector< Type > TypeMeshContainer
Template for the type of the mesh container (std::list for now, but may change to something else if w...
Definition Tools.h:194
Definition Errors.h:120
Definition Input.h:55
Abstract class for a mesh.
Definition Mesh.h:55
int writeScalarVTKHDF(const hid_t &group_id, const std::string &dataset_name, const size_t &scalar_val) const
Write a distributed scalar array using parallel HDF5.
Definition OutputVTKHDF.cpp:1404
int writeHeaderVTKHDF(const hid_t &group_id, const std::string &mesh_type) const
Write header of VTKHDF file.
Definition OutputVTKHDF.cpp:1344
void initializeProperties(const H5FD_mpio_xfer_t &transfer_mode)
Initialize fields needed by the two constructors that are provided (m_type and m_data_transfer) and a...
Definition OutputVTKHDF.cpp:148
virtual void readTree(Mesh *mesh, TypeMeshContainer< Cell * > *cellsLvl, TypeMeshContainer< Cell * > *cellsLvlGhost, TypeMeshContainer< CellInterface * > *const cellInterfacesLvl, const std::vector< AddPhys * > &addPhys, int &nbCellsTotalAMR) override
Read 'meshInfo' file that stores for each cell its subdivision status (1 if subdivided,...
Definition OutputVTKHDF.cpp:1925
virtual void writeErrorInFile(std::vector< Errors > &v, const int &ErrorType, const int &iteration, bool &warn) const override
Definition OutputVTKHDF.cpp:1834
int writeMeshUnstructuredVTKHDF(Mesh *mesh, std::vector< Cell * > *cellsLvl, hid_t &file, hid_t &vtkhdf_group_id, size_t &numberCells) const
Write unstructured mesh at VTKHDF file format.
Definition OutputVTKHDF.cpp:1764
std::string createFilenameVTKHDF(const char *name, int numFile=-1, std::string nameVariable="defaut") const
Definition OutputVTKHDF.cpp:598
static constexpr int SUCCESS_VALUE
Success value.
Definition OutputVTKHDF.h:352
hid_t m_dataset_creation_properties
Properties for hdf5 dataset creation.
Definition OutputVTKHDF.h:344
void writeDataset(std::vector< double >, std::ofstream &, TypeData) const
Definition OutputVTKHDF.h:307
int writeArrayAttribute(const hid_t &group_id, const std::string &attribute_name, const hsize_t &nitem, const int *array) const
Write array attribute in VTKHDF file.
Definition OutputVTKHDF.cpp:1308
hid_t m_h5_file_intType
Hdf5 integer type to write in file depending on the precision asked by user.
Definition OutputVTKHDF.h:338
static void unstructuredFirstRangeLayout(const size_t &line_count, hsize_t *dimsf, hsize_t *count, hsize_t *start)
Compute size, position and offset of writing area from 'line_count' and 'column_count' data.
Definition OutputVTKHDF.cpp:1533
static void getDataset(std::istringstream &, std::vector< double > &)
Definition OutputVTKHDF.h:312
int writeArrayVTKHDF(const hid_t &group_id, const std::string &dataset_name, hid_t hdf_mem_dtype, hid_t hdf_file_dtype, hid_t parallel_x_properties, const std::vector< T > &dataset, const hsize_t(&global_dims)[N], const hsize_t(&local_dims)[N], const hsize_t(&offsets)[N], const hsize_t(&chunk_dims)[N]) const
Write a N-dimensional array of C++ type T and hdf5 type hdf_type using parallel HDF5.
Definition OutputVTKHDF.cpp:1464
int writeConnectivity(Mesh *mesh, std::vector< Cell * > *cellsLvl, hid_t &vtkhdf_group_id, size_t &numberCells, const size_t &numberNodes) const
Definition OutputVTKHDF.cpp:1703
static void writeDataXDMF(std::ofstream &fileStream, const std::string &dataFile, const std::string &dataName, const std::string &dataType, int numberCellsX, int numberCellsY, int numberCellsZ, int dimData)
Write data array at XDMF format.
Definition OutputVTKHDF.cpp:739
int writeMeshRectilinearVTKHDF(Mesh *mesh, hid_t &file, hid_t &vtkhdf_group_id, size_t &numberCells)
Write cartesian mesh at VTKHDF file format.
Definition OutputVTKHDF.cpp:1588
OutputVTKHDF(std::string casTest, std::string run, tinyxml2::XMLElement *element, std::string fileName, Input *entree)
Definition OutputVTKHDF.cpp:48
void writeResultsVTKHDF(Mesh *mesh, std::vector< Cell * > *cellsLvl)
Write results at VTKHDF file format for current time step.
Definition OutputVTKHDF.cpp:662
virtual void prepareErrorFiles() const override
Definition OutputVTKHDF.cpp:1821
static constexpr int ERROR_VALUE
Error value.
Definition OutputVTKHDF.h:351
H5FD_mpio_xfer_t m_transfer_mode
Perform collective (default or H5FD_MPIO_COLLECTIVE) or independent (H5FD_MPIO_INDEPENDENT) parallel ...
Definition OutputVTKHDF.h:347
int readArrayVTKHDF(hid_t group_id, std::string dataset_name, std::vector< double > &dataset, const hsize_t(&local_dims)[N], const hsize_t(&offsets)[N])
Read an array of dimensions local_dims at offset offsets using parallel HDF5.
Definition OutputVTKHDF.cpp:288
int openFileVTKHDF(hid_t &file_id, bool parallel_access, bool create) const
Create or open a hdf5 file.
Definition OutputVTKHDF.cpp:623
hid_t m_h5_mem_intType
Hdf5 integer type in memory space: must match architecture (LE, BE) and the size of the data in memor...
Definition OutputVTKHDF.h:341
virtual void writeResults(Mesh *mesh, std::vector< Cell * > *cellsLvl) override
Definition OutputVTKHDF.cpp:208
void writeXDMF(Mesh *mesh, int numFile)
Write a XDMF file to visualize cartesian VTKHDF outputs while VTKHDF file format is not yet specified...
Definition OutputVTKHDF.cpp:757
const void * getOutputBuffer(const std::vector< double > &double_buffer, std::vector< float > &float_buffer) const
Get buffer to write at suitable format for hdf5 (float or double).
int writeUnstructuredArrayVTKHDF(const hid_t &group_id, const std::string &dataset_name, hid_t hdf_file_dtype, hid_t hdf_mem_dtype, const std::vector< T > &dataset, const size_t &line_count, size_t column_count=1) const
Write a 2-dimensional array of an unstructured mesh using parallel HDF5.
Definition OutputVTKHDF.cpp:1561
static constexpr int VTKHDF_VERSION[2]
VTKHDF format version: set to version 2.4 in .cpp file.
Definition OutputVTKHDF.h:350
hid_t m_group_creation_properties
Properties for hdf5 group creation.
Definition OutputVTKHDF.h:343
hid_t m_h5_mem_floatType
Hdf5 floating type in memory space: must match architecture (LE, BE) and the size of the data in memo...
Definition OutputVTKHDF.h:340
hid_t m_h5_file_floatType
Hdf5 floating type to write in file depending on the precision asked by user.
Definition OutputVTKHDF.h:337
int writePhysicalDataVTKHDF(hid_t &file, const Mesh *mesh, std::vector< Cell * > *cellsLvl, hid_t &vtkhdf_group_id, size_t numberCells) const
Write physical data fields at VTKHDF file format in file hdf5 object.
Definition OutputVTKHDF.cpp:1209
virtual void readResults(Mesh *mesh, std::vector< Cell * > *cellsLvl, int cpu=-1) override
Read results of a previous simulation to resume from it.
Definition OutputVTKHDF.cpp:337
int readScalarVTKHDF(hid_t group_id, const std::string &dataset_name, std::vector< size_t > &scalar_array) const
Read a scalar array using parallel HDF5.
Definition OutputVTKHDF.cpp:237
~OutputVTKHDF() override
Definition OutputVTKHDF.cpp:139
hid_t m_parallel_x_properties
Properties for hdf5 raw data transfer.
Definition OutputVTKHDF.h:345
virtual void initializeSpecificOutput() override
Definition OutputVTKHDF.cpp:176
virtual const void * getTransferMode() const override
Get transfer_mode field (collective or independent hdf5 and MPI I/O mode for raw data transfer).
Definition OutputVTKHDF.h:50
virtual void printTree(Mesh *mesh, const std::vector< Cell * > *cellsLvl, int m_resumeAMRsaveFreq) const override
Write 'meshInfo' file that stores for each cell its subdivision status (1 if subdivided,...
Definition OutputVTKHDF.cpp:1876
int ReadPhysicalDataVTKHDF(Mesh *mesh, std::vector< Cell * > *cellsLvl, hid_t group_id, const hsize_t(&count_scalar)[N], const hsize_t(&start_scalar)[N])
Read the list of ECOGEN physical data in a VTKHDF file with dimensions and offsets of area to read pr...
Definition OutputVTKHDF.cpp:447
static constexpr size_t DIM_OUTPUT
Always write 3D-coordinates in output files.
Definition OutputVTKHDF.h:349
void writeTimeseriesVTKHDF(int numFile)
Write a Paraview .series file for time series visualization of VTKHDF outputs.
Definition OutputVTKHDF.cpp:715
Output()
Default constructor for specific output without specific needs.
Definition Output.cpp:40
Definition tinyxml2.h:1148