34 #include <boost/algorithm/string/predicate.hpp>
35 #include <boost/property_tree/ptree.hpp>
36 #include <boost/property_tree/xml_parser.hpp>
52 bool write_array_rank1(hid_t loc_id,
string name,
void const* data, hid_t type_id, hsize_t dim_1);
53 bool write_array_rank1(hid_t loc_id,
string name,
const vector<string>& data);
54 bool write_array_rank2(hid_t loc_id,
string name,
void const* data, hid_t type_id, hsize_t dim_1, hsize_t dim_2);
59 bool read_array_rank1(hid_t loc_id,
string name, T** data, hid_t type_id,
size_t* dim_1,
bool optional =
false);
62 bool read_array_rank2(hid_t loc_id,
string name, T** data, hid_t type_id,
size_t* dim_1,
size_t* dim_2,
bool optional =
false);
65 list<string> find_matching_links(hid_t loc_id,
function<
bool(
string)> match);
70 bool write_array_rank1(hid_t loc_id,
string name,
void const* data, hid_t type_id, hsize_t dim_1) {
72 if (0 == H5Lexists(loc_id, name.c_str(), H5P_DEFAULT)) {
74 hid_t dspace = H5Screate_simple(1, &dim_1, 0);
76 hid_t dset = H5Dcreate(loc_id, name.c_str(), type_id, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
78 hid_t mem_type_id = H5Tget_native_type(type_id, H5T_DIR_ASCEND);
79 H5Dwrite(dset, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
81 H5Tclose(mem_type_id);
90 bool write_array_rank1(hid_t loc_id,
string name,
const vector<string>& data) {
92 if (0 == H5Lexists(loc_id, name.c_str(), H5P_DEFAULT)) {
94 hid_t dtype = H5Tcopy(H5T_C_S1);
95 H5Tset_size(dtype, H5T_VARIABLE);
97 hsize_t dim_1 = data.size();
98 hid_t dspace = H5Screate_simple(1, &dim_1, 0);
100 hid_t dset = H5Dcreate(loc_id, name.c_str(), dtype, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
102 vector<const char*> raw_string_ptrs;
103 for (
const string & s : data) raw_string_ptrs.push_back(s.c_str());
104 H5Dwrite(dset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, raw_string_ptrs.data());
115 bool write_array_rank2(hid_t loc_id,
string name,
void const* data, hid_t type_id, hsize_t dim_1, hsize_t dim_2) {
117 if (0 == H5Lexists(loc_id, name.c_str(), H5P_DEFAULT)) {
119 hsize_t dims[2] = {dim_1, dim_2};
120 hid_t dspace = H5Screate_simple(2, dims, 0);
122 hid_t dset = H5Dcreate(loc_id, name.c_str(), type_id, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
124 hid_t mem_type_id = H5Tget_native_type(type_id, H5T_DIR_ASCEND);
125 H5Dwrite(dset, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
127 H5Tclose(mem_type_id);
160 template <
typename T>
161 bool read_array_rank1(hid_t loc_id,
string name, T** data, hid_t mem_type_id,
size_t* dim_1,
bool optional) {
166 if (0 == H5Lexists(loc_id, name.c_str(), H5P_DEFAULT)) {
170 string errmsg = string(
"No dataset \'") + name + string(
"\'");
171 throw runtime_error(errmsg);
176 hid_t dset = H5Dopen(loc_id, name.c_str(), H5P_DEFAULT);
181 string errmsg = string(
"Could not open dataset \'") + name + string(
"\'");
182 throw runtime_error(errmsg);
187 hid_t dspace = H5Dget_space(dset);
188 int ndims = H5Sget_simple_extent_ndims(dspace);
190 string errmsg = string(
"Dataset \'") + name + string(
"\' must be rank 1");
191 throw runtime_error(errmsg);
196 H5Sget_simple_extent_dims(dspace, &_dim_1, 0);
197 *dim_1 =
static_cast<size_t>(_dim_1);
200 *data =
new T[_dim_1];
203 h5_status = H5Dread(dset, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, *data);
205 string errmsg = string(
"Could not read dataset \'") + name + string(
"\'");
206 throw runtime_error(errmsg);
217 template <
typename T>
218 bool read_array_rank2(hid_t loc_id,
string name, T** data, hid_t mem_type_id,
size_t* dim_1,
size_t* dim_2,
bool optional) {
223 if (0 == H5Lexists(loc_id, name.c_str(), H5P_DEFAULT)) {
227 string errmsg = string(
"No dataset \'") + name + string(
"\'");
228 throw runtime_error(errmsg);
233 hid_t dset = H5Dopen(loc_id, name.c_str(), H5P_DEFAULT);
238 string errmsg = string(
"Could not open dataset \'") + name + string(
"\'");
239 throw runtime_error(errmsg);
244 hid_t dspace = H5Dget_space(dset);
245 int ndims = H5Sget_simple_extent_ndims(dspace);
247 string errmsg = string(
"Dataset \'") + name + string(
"\' must be rank 2");
248 throw runtime_error(errmsg);
253 H5Sget_simple_extent_dims(dspace, _dims, 0);
254 *dim_1 =
static_cast<size_t>(_dims[0]);
255 *dim_2 =
static_cast<size_t>(_dims[1]);
258 *data =
new T[_dims[0] * _dims[1]];
261 h5_status = H5Dread(dset, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, *data);
263 string errmsg = string(
"Could not read dataset \'") + name + string(
"\'");
264 throw runtime_error(errmsg);
276 herr_t collect_link_names(hid_t ,
const char* name,
const H5L_info_t* ,
void* op_data) {
277 list<string>* link_names =
static_cast<list<string>*
>(op_data);
278 link_names->push_back(
string(name));
282 list<string> find_matching_links(hid_t loc_id,
function<
bool(
string)> match) {
284 list<string> link_names;
285 H5Literate(loc_id, H5_INDEX_NAME, H5_ITER_NATIVE, 0, &collect_link_names, &link_names);
287 link_names.remove_if([&](
string name)->
bool{
return !match(name); });
295 using boost::property_tree::ptree;
302 : m_file_id(-1), m_file_path(
"") {}
305 : m_file_id(-1), m_file_path(
"")
321 if (m_file_id >= 0) {
341 return (m_file_path !=
"") && (m_file_id != -1);
346 string const here = string(VL_HERE) +
"> ";
349 bool successful =
true;
350 bool new_file =
false;
356 if (file_path !=
"") {
360 herr_t (*old_func)(hid_t,
void*);
361 void *old_client_data;
362 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
363 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
364 htri_t is_hdf5 = H5Fis_hdf5(file_path.c_str());
366 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
369 m_file_id = H5Fopen(file_path.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
372 cerr << here <<
"[Hdf5File] Error: \'" << file_path <<
"\' seems to be valid HDF5 but could not be opened.\
373 Might be you don\'t have r/w permissions." << endl;
378 m_file_path = file_path;
380 }
else if (0 == is_hdf5) {
382 cerr << here <<
"[Hdf5File] Error: \'" << file_path <<
"\' is not a valid HDF5 file.\
383 I can neither open it, nor will I truncate it." << endl;
387 m_file_id = H5Fcreate(file_path.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
390 cerr << here <<
"[Hdf5File] Error: \'" << file_path <<
"\' could not be created nor opened.\
391 Check your r/w permissions." << endl;
396 m_file_path = file_path;
404 if (successful && new_file) {
409 hsize_t time_steps_dims = 0;
410 hsize_t time_steps_max_dims = H5S_UNLIMITED;
413 hid_t time_steps_dspace = H5Screate_simple(1, &time_steps_dims, &time_steps_max_dims);
416 hid_t time_steps_dset_props = H5Pcreate(H5P_DATASET_CREATE);
417 hsize_t time_steps_chunk_dims = 10;
418 H5Pset_chunk(time_steps_dset_props, 1, &time_steps_chunk_dims);
421 hid_t time_steps_dset = H5Dcreate(m_file_id,
"/time_steps", H5T_IEEE_F64LE,
422 time_steps_dspace, H5P_DEFAULT, time_steps_dset_props, H5P_DEFAULT);
423 if (time_steps_dset < 0) {
424 cerr << here <<
"[Hdf5File] Error: could not create \'/time_steps\' dataset." << endl;
429 hid_t time_steps_idx_dset = H5Dcreate(m_file_id,
"/time_steps_idx", H5T_STD_I32LE,
430 time_steps_dspace, H5P_DEFAULT, time_steps_dset_props, H5P_DEFAULT);
431 if (time_steps_idx_dset < 0) {
432 cerr << here <<
"[Hdf5File] Error: could not create \'/time_steps_idx\' dataset." << endl;
437 H5Dclose(time_steps_dset);
438 H5Dclose(time_steps_idx_dset);
439 H5Sclose(time_steps_dspace);
440 H5Pclose(time_steps_dset_props);
446 SimState Hdf5File::Read(
int step_idx)
449 throw runtime_error(
"[Hdf5File]: File needs to be open prior to reading.");
458 double* time_steps_data =
nullptr;
459 size_t time_steps_dim1 = 0;
460 read_array_rank1(m_file_id,
"time_steps", &time_steps_data, H5T_NATIVE_DOUBLE, &time_steps_dim1);
462 int* time_steps_idx_data =
nullptr;
463 size_t time_steps_idx_dim1 = 0;
464 read_array_rank1(m_file_id,
"time_steps_idx", &time_steps_idx_data, H5T_NATIVE_INT, &time_steps_idx_dim1);
467 if (time_steps_dim1 != time_steps_idx_dim1) {
468 string errmsg = string(
"Error reading file \'") + m_file_path
469 + string(
"\': The /time_steps and /time_steps_idx datasets must be the same size. File might be corrupted.");
471 delete[] time_steps_data;
472 delete[] time_steps_idx_data;
473 throw runtime_error(errmsg);
476 if (-1 == step_idx) {
478 step_idx = time_steps_idx_dim1 - 1;
481 const size_t sim_step = time_steps_idx_data[step_idx];
482 const double sim_time = time_steps_data[step_idx];
485 string step_grp_name = string(
"/step_") + to_string(sim_step);
486 hid_t step_grp_id = H5Gopen(m_file_id, step_grp_name.c_str(), H5P_DEFAULT);
487 if (step_grp_id < 0) {
488 string errmsg = string(
"Error reading file \'") + m_file_path
489 + string(
"\': The group /step_") + to_string(sim_step)
490 + string(
" does not exist. File might be corrupted.");
492 delete[] time_steps_data;
493 delete[] time_steps_idx_data;
494 throw runtime_error(errmsg);
498 delete[] time_steps_data;
499 delete[] time_steps_idx_data;
503 ReadNodes(step_grp_id, mstate);
504 ReadCells(step_grp_id, mstate);
505 ReadBPNodes(step_grp_id, mstate);
508 if (1 < mstate.GetNumCells()) {
509 ReadWalls(step_grp_id, mstate);
510 ReadBPWalls(step_grp_id, mstate);
513 ptree params = ReadPtreeFromStringAttribute(step_grp_id,
"parameters");
514 ptree re_state = ReadPtreeFromStringAttribute(step_grp_id,
"random_engine");
516 sstate.SetTimeStep(sim_step);
517 sstate.SetTime(sim_time);
518 sstate.SetParameters(params);
519 sstate.SetRandomEngineState(re_state);
520 sstate.SetMeshState(mstate);
525 void Hdf5File::ReadNodes(hid_t loc_id, MeshState& mstate)
528 int* nodes_id_data =
nullptr;
529 size_t nodes_id_dim1 = 0;
530 read_array_rank1(loc_id,
"nodes_id", &nodes_id_data, H5T_NATIVE_INT, &nodes_id_dim1);
532 const size_t& num_nodes = nodes_id_dim1;
535 double* nodes_xy_data =
nullptr;
536 size_t nodes_xy_dim1 = 0;
537 size_t nodes_xy_dim2 = 0;
538 read_array_rank2(loc_id,
"nodes_xy", &nodes_xy_data, H5T_NATIVE_DOUBLE, &nodes_xy_dim1, &nodes_xy_dim2);
541 if (2 != nodes_xy_dim2) {
542 string errmsg = string(
"Error reading file \'") + m_file_path
543 + string(
"\': Second dimension of the /step_*/nodes_xy dataset must equal 2. File might be corrupted.");
545 delete[] nodes_id_data;
546 delete[] nodes_xy_data;
547 throw runtime_error(errmsg);
549 if (num_nodes != nodes_xy_dim1) {
550 string errmsg = string(
"Error reading file \'") + m_file_path
551 + string(
"\': Dimensions of \'nodes_xy\' and \'nodes_id\' datasets don\'t match. File might be corrupted.");
553 delete[] nodes_id_data;
554 delete[] nodes_xy_data;
555 throw runtime_error(errmsg);
559 mstate.SetNumNodes(num_nodes);
560 for (
size_t node_idx = 0; node_idx < num_nodes; ++node_idx) {
561 assert( node_idx == static_cast<unsigned int>(nodes_id_data[node_idx]) &&
"Error for node ids");
562 mstate.SetNodeID(node_idx, nodes_id_data[node_idx]);
563 mstate.SetNodeX(node_idx, nodes_xy_data[2 * node_idx]);
564 mstate.SetNodeY(node_idx, nodes_xy_data[2 * node_idx + 1]);
568 delete[] nodes_id_data;
569 delete[] nodes_xy_data;
572 list<string> attr_names = find_matching_links(loc_id, [](
string name)->
bool{
573 return boost::starts_with(name,
"nodes_attr_");
577 for (
string long_name : attr_names) {
579 string short_name = long_name.substr(11, string::npos);
583 H5Oget_info_by_name(loc_id, long_name.c_str(), &obj_info, H5P_DEFAULT);
584 if (H5O_TYPE_DATASET == obj_info.type) {
586 hid_t dset = H5Dopen(loc_id, long_name.c_str(), H5P_DEFAULT);
589 hid_t dspace = H5Dget_space(dset);
591 const int ndims = H5Sget_simple_extent_ndims(dspace);
598 H5Sget_simple_extent_dims(dspace, &dims, 0);
599 if (num_nodes != dims) {
605 hid_t dtype = H5Dget_type(dset);
606 H5T_class_t dtype_class = H5Tget_class(dtype);
608 if (H5T_INTEGER == dtype_class) {
610 vector<int> attr_values(num_nodes);
611 H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
613 mstate.NodeAttributeContainer().Add<
int>(short_name);
614 mstate.NodeAttributeContainer().SetAll<
int>(short_name, attr_values);
615 }
else if (H5T_FLOAT == dtype_class) {
617 vector<double> attr_values(num_nodes);
618 H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
620 mstate.NodeAttributeContainer().Add<
double>(short_name);
621 mstate.NodeAttributeContainer().SetAll<
double>(short_name, attr_values);
622 }
else if (H5T_STRING == dtype_class) {
624 vector<char*> raw_attr_values(num_nodes);
625 hid_t ntype = H5Tcopy(H5T_C_S1);
626 H5Tset_size(ntype, H5T_VARIABLE);
627 H5Dread(dset, ntype, H5S_ALL, H5S_ALL, H5P_DEFAULT, raw_attr_values.data());
631 vector<string> attr_values(raw_attr_values.begin(), raw_attr_values.end());
634 mstate.NodeAttributeContainer().Add<
string>(short_name);
635 mstate.NodeAttributeContainer().SetAll<
string>(short_name, attr_values);
646 void Hdf5File::ReadCells(hid_t loc_id, MeshState& mstate)
649 int* cells_id_data =
nullptr;
650 size_t cells_id_dim1 = 0;
651 read_array_rank1(loc_id,
"cells_id", &cells_id_data, H5T_NATIVE_INT, &cells_id_dim1);
653 const size_t & num_cells = cells_id_dim1;
656 int* cells_num_nodes_data =
nullptr;
657 size_t cells_num_nodes_dim1 = 0;
658 read_array_rank1(loc_id,
"cells_num_nodes", &cells_num_nodes_data, H5T_NATIVE_INT, &cells_num_nodes_dim1);
661 int* cells_nodes_data =
nullptr;
662 size_t cells_nodes_dim1 = 0, cells_nodes_dim2 = 0;
663 read_array_rank2(loc_id,
"cells_nodes", &cells_nodes_data, H5T_NATIVE_INT, &cells_nodes_dim1, &cells_nodes_dim2);
664 const size_t & max_num_cell_nodes = cells_nodes_dim2;
667 int* cells_num_walls_data =
nullptr;
668 size_t cells_num_walls_dim1 = 0;
669 read_array_rank1(loc_id,
"cells_num_walls", &cells_num_walls_data, H5T_NATIVE_INT, &cells_num_walls_dim1);
673 int* cells_walls_data =
nullptr;
674 size_t cells_walls_dim1 = 0, cells_walls_dim2 = 0;
675 if (1 != num_cells) {
676 read_array_rank2(loc_id,
"cells_walls", &cells_walls_data, H5T_NATIVE_INT, &cells_walls_dim1, &cells_walls_dim2);
678 const size_t & max_num_cell_walls = cells_walls_dim2;
681 if (num_cells != cells_num_nodes_dim1) {
682 string errmsg = string(
"Error reading file \'") + m_file_path
683 + string(
"\': Dimensions of \'cells_num_nodes\' and \'cells_id\' datasets don\'t match. File might be corrupted.");
685 delete[] cells_id_data;
686 delete[] cells_num_nodes_data;
687 delete[] cells_nodes_data;
688 delete[] cells_num_walls_data;
689 delete[] cells_walls_data;
690 throw runtime_error(errmsg);
692 if (num_cells != cells_nodes_dim1) {
693 string errmsg = string(
"Error reading file \'") + m_file_path
694 + string(
"\': Dimensions of \'cells_nodes\' and \'cells_id\' datasets don\'t match. File might be corrupted.");
696 delete[] cells_id_data;
697 delete[] cells_num_nodes_data;
698 delete[] cells_nodes_data;
699 delete[] cells_num_walls_data;
700 delete[] cells_walls_data;
701 throw runtime_error(errmsg);
703 if (num_cells != cells_num_walls_dim1) {
704 string errmsg = string(
"Error reading file \'") + m_file_path
705 + string(
"\': Dimensions of \'cells_num_walls\' and \'cells_id\' datasets don\'t match. File might be corrupted.");
707 delete[] cells_id_data;
708 delete[] cells_num_nodes_data;
709 delete[] cells_nodes_data;
710 delete[] cells_num_walls_data;
711 delete[] cells_walls_data;
712 throw runtime_error(errmsg);
716 if (1 != num_cells && num_cells != cells_walls_dim1) {
717 string errmsg = string(
"Error reading file \'") + m_file_path
718 + string(
"\': Dimensions of \'cells_walls\' and \'cells_id\' datasets don\'t match. File might be corrupted.");
720 delete[] cells_id_data;
721 delete[] cells_num_nodes_data;
722 delete[] cells_nodes_data;
723 delete[] cells_num_walls_data;
724 delete[] cells_walls_data;
725 throw runtime_error(errmsg);
729 mstate.SetNumCells(num_cells);
730 for (
size_t cell_idx = 0; cell_idx < num_cells; ++cell_idx) {
732 assert(cell_idx == static_cast<unsigned int>(cells_id_data[cell_idx]) &&
"Error for cell ids");
733 mstate.SetCellID(cell_idx, cells_id_data[cell_idx]);
735 vector<int> cell_nodes;
736 for (
size_t cell_node_idx = 0; cell_node_idx < static_cast<size_t>(cells_num_nodes_data[cell_idx]);
743 size_t idx = cell_node_idx + (cell_idx * max_num_cell_nodes);
744 cell_nodes.push_back(cells_nodes_data[idx]);
747 mstate.SetCellNodes(cell_idx, cell_nodes);
749 vector<int> cell_walls;
750 for (
size_t cell_wall_idx = 0; cell_wall_idx < static_cast<size_t>(cells_num_walls_data[cell_idx]);
757 size_t idx = cell_wall_idx + (cell_idx * max_num_cell_walls);
758 cell_walls.push_back(cells_walls_data[idx]);
761 mstate.SetCellWalls(cell_idx, cell_walls);
765 delete[] cells_id_data;
766 delete[] cells_num_nodes_data;
767 delete[] cells_nodes_data;
768 delete[] cells_num_walls_data;
769 delete[] cells_walls_data;
772 list<string> attr_names = find_matching_links(loc_id, [](
string name)->
bool {
773 return boost::starts_with(name,
"cells_attr_");
777 for (
string long_name : attr_names) {
779 string short_name = long_name.substr(11, string::npos);
783 H5Oget_info_by_name(loc_id, long_name.c_str(), &obj_info, H5P_DEFAULT);
784 if (H5O_TYPE_DATASET == obj_info.type) {
786 hid_t dset = H5Dopen(loc_id, long_name.c_str(), H5P_DEFAULT);
789 hid_t dspace = H5Dget_space(dset);
791 const int ndims = H5Sget_simple_extent_ndims(dspace);
798 H5Sget_simple_extent_dims(dspace, &dims, 0);
799 if (num_cells != dims) {
805 hid_t dtype = H5Dget_type(dset);
806 H5T_class_t dtype_class = H5Tget_class(dtype);
808 if (H5T_INTEGER == dtype_class) {
810 vector<int> attr_values(num_cells);
811 H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
813 mstate.CellAttributeContainer().Add<
int>(short_name);
814 mstate.CellAttributeContainer().SetAll<
int>(short_name, attr_values);
815 }
else if (H5T_FLOAT == dtype_class) {
817 vector<double> attr_values(num_cells);
818 H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
820 mstate.CellAttributeContainer().Add<
double>(short_name);
821 mstate.CellAttributeContainer().SetAll<
double>(short_name, attr_values);
822 }
else if (H5T_STRING == dtype_class) {
824 vector<char*> raw_attr_values(num_cells);
825 hid_t ntype = H5Tcopy(H5T_C_S1);
826 H5Tset_size(ntype, H5T_VARIABLE);
827 H5Dread(dset, ntype, H5S_ALL, H5S_ALL, H5P_DEFAULT, raw_attr_values.data());
831 vector < string > attr_values(raw_attr_values.begin(), raw_attr_values.end());
834 mstate.CellAttributeContainer().Add<
string>(short_name);
835 mstate.CellAttributeContainer().SetAll<
string>(short_name, attr_values);
846 void Hdf5File::ReadBPNodes(hid_t loc_id, MeshState& mstate)
849 int* bp_nodes_data = 0;
850 size_t bp_nodes_dim1 = 0;
851 read_array_rank1(loc_id,
"bp_nodes", &bp_nodes_data, H5T_NATIVE_INT, &bp_nodes_dim1);
854 vector<int> bp_nodes(bp_nodes_dim1);
855 for (
size_t node_idx = 0; node_idx < bp_nodes_dim1; ++node_idx) {
856 bp_nodes[node_idx] = bp_nodes_data[node_idx];
860 mstate.SetBoundaryPolygonNodes(bp_nodes);
863 delete[] bp_nodes_data;
866 void Hdf5File::ReadBPWalls(hid_t loc_id, MeshState& mstate)
869 int* bp_walls_data =
nullptr;
870 size_t bp_walls_dim1 = 0;
871 read_array_rank1(loc_id,
"bp_walls", &bp_walls_data, H5T_NATIVE_INT, &bp_walls_dim1);
874 vector<int> bp_walls(bp_walls_dim1);
875 for (
size_t wall_idx = 0; wall_idx < bp_walls_dim1; ++wall_idx) {
876 bp_walls[wall_idx] = bp_walls_data[wall_idx];
880 mstate.SetBoundaryPolygonWalls(bp_walls);
883 delete[] bp_walls_data;
886 void Hdf5File::ReadWalls(hid_t loc_id, MeshState& mstate)
889 int* walls_id_data =
nullptr;
890 size_t walls_id_dim1 = 0;
891 read_array_rank1(loc_id,
"walls_id", &walls_id_data, H5T_NATIVE_INT, &walls_id_dim1);
893 const size_t & num_walls = walls_id_dim1;
896 int* walls_cells_data =
nullptr;
897 size_t walls_cells_dim1 = 0, walls_cells_dim2 = 0;
898 read_array_rank2(loc_id,
"walls_cells", &walls_cells_data, H5T_NATIVE_INT, &walls_cells_dim1,
902 int* walls_nodes_data =
nullptr;
903 size_t walls_nodes_dim1 = 0, walls_nodes_dim2 = 0;
904 read_array_rank2(loc_id,
"walls_nodes", &walls_nodes_data, H5T_NATIVE_INT, &walls_nodes_dim1,
908 if (2 != walls_cells_dim2) {
909 string errmsg = string(
"Error reading file \'") + m_file_path
910 + string(
"\': Second dimension of the /step_*/walls_cells dataset must equal 2. File might be corrupted.");
912 delete[] walls_id_data;
913 delete[] walls_cells_data;
914 delete[] walls_nodes_data;
915 throw runtime_error(errmsg);
917 if (2 != walls_nodes_dim2) {
918 string errmsg = string(
"Error reading file \'") + m_file_path
919 + string(
"\': Second dimension of the /step_*/walls_nodes dataset must equal 2. File might be corrupted.");
921 delete[] walls_id_data;
922 delete[] walls_cells_data;
923 delete[] walls_nodes_data;
924 throw runtime_error(errmsg);
926 if (num_walls != walls_cells_dim1) {
927 string errmsg = string(
"Error reading file \'") + m_file_path
928 + string(
"\': Dimensions of \'walls_id\' and \'walls_cells\' datasets don\'t match. File might be corrupted.");
930 delete[] walls_id_data;
931 delete[] walls_cells_data;
932 delete[] walls_nodes_data;
933 throw runtime_error(errmsg);
935 if (num_walls != walls_nodes_dim1) {
936 string errmsg = string(
"Error reading file \'") + m_file_path
937 + string(
"\': Dimensions of \'walls_id\' and \'walls_nodes\' datasets don\'t match. File might be corrupted.");
939 delete[] walls_id_data;
940 delete[] walls_cells_data;
941 delete[] walls_nodes_data;
942 throw runtime_error(errmsg);
946 mstate.SetNumWalls(num_walls);
947 for (
size_t wall_idx = 0; wall_idx < num_walls; ++wall_idx) {
949 assert(wall_idx == static_cast<unsigned int>(walls_id_data[wall_idx]) &&
"Error for wall ids");
950 mstate.SetWallID(wall_idx, walls_id_data[wall_idx]);
956 mstate.SetWallCells(wall_idx,
957 make_pair(walls_cells_data[2 * wall_idx], walls_cells_data[2 * wall_idx + 1]));
958 mstate.SetWallNodes(wall_idx,
959 make_pair(walls_nodes_data[2 * wall_idx], walls_nodes_data[2 * wall_idx + 1]));
963 delete[] walls_id_data;
964 delete[] walls_cells_data;
965 delete[] walls_nodes_data;
968 list < string > attr_names = find_matching_links(loc_id, [](
string name)->
bool {
969 return boost::starts_with(name,
"walls_attr_");
973 for (
string long_name : attr_names) {
975 string short_name = long_name.substr(11, string::npos);
979 H5Oget_info_by_name(loc_id, long_name.c_str(), &obj_info, H5P_DEFAULT);
980 if (H5O_TYPE_DATASET == obj_info.type) {
982 hid_t dset = H5Dopen(loc_id, long_name.c_str(), H5P_DEFAULT);
985 hid_t dspace = H5Dget_space(dset);
987 const int ndims = H5Sget_simple_extent_ndims(dspace);
994 H5Sget_simple_extent_dims(dspace, &dims, 0);
995 if (num_walls != dims) {
1001 hid_t dtype = H5Dget_type(dset);
1002 H5T_class_t dtype_class = H5Tget_class(dtype);
1004 if (H5T_INTEGER == dtype_class) {
1006 vector<int> attr_values(num_walls);
1007 H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
1009 mstate.WallAttributeContainer().Add<
int>(short_name);
1010 mstate.WallAttributeContainer().SetAll<
int>(short_name, attr_values);
1011 }
else if (H5T_FLOAT == dtype_class) {
1013 vector<double> attr_values(num_walls);
1014 H5Dread(dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, attr_values.data());
1016 mstate.WallAttributeContainer().Add<
double>(short_name);
1017 mstate.WallAttributeContainer().SetAll<
double>(short_name, attr_values);
1018 }
else if (H5T_STRING == dtype_class) {
1020 vector<char*> raw_attr_values(num_walls);
1021 hid_t ntype = H5Tcopy(H5T_C_S1);
1022 H5Tset_size(ntype, H5T_VARIABLE);
1023 H5Dread(dset, ntype, H5S_ALL, H5S_ALL, H5P_DEFAULT, raw_attr_values.data());
1027 vector < string > attr_values(raw_attr_values.begin(), raw_attr_values.end());
1030 mstate.WallAttributeContainer().Add<
string>(short_name);
1031 mstate.WallAttributeContainer().SetAll<
string>(short_name, attr_values);
1042 ptree Hdf5File::ReadParameters(hid_t loc_id)
1044 hid_t param_grp_id = H5Gopen(loc_id,
"parameters", H5P_DEFAULT);
1045 if (param_grp_id < 0) {
1046 string errmsg = string(
"Error reading file \'") + m_file_path
1047 + string(
"\': The group \'/step_*/parameters\' does not exist. File might be corrupted.");
1048 throw runtime_error(errmsg);
1051 H5Gclose(param_grp_id);
1055 ptree Hdf5File::ReadPtreeFromStringAttribute(hid_t loc_id,
const string& attr_name)
1061 hid_t attr_id = H5Aopen(loc_id, attr_name.c_str(), H5P_DEFAULT);
1065 hid_t attr_dtype = H5Aget_type(attr_id);
1066 hid_t attr_dspace = H5Aget_space(attr_id);
1069 if (H5T_STRING == H5Tget_class(attr_dtype)) {
1073 hid_t attr_ntype = H5Tcopy(H5T_C_S1);
1074 H5Tset_size(attr_ntype, H5T_VARIABLE);
1075 H5Aread(attr_id, attr_ntype, &attr_value);
1076 H5Tclose(attr_ntype);
1079 stringstream pt_strm;
1080 pt_strm << attr_value;
1081 read_xml(pt_strm, pt, trim_whitespace);
1084 H5Dvlen_reclaim(attr_ntype, attr_dspace, H5P_DEFAULT, attr_value);
1088 H5Sclose(attr_dspace);
1089 H5Tclose(attr_dtype);
1099 throw runtime_error(
"[Hdf5File]: File needs to be open prior to reading.");
1104 double* time_steps_data =
nullptr;
1105 size_t time_steps_dim1 = 0;
1106 read_array_rank1(m_file_id,
"time_steps", &time_steps_data, H5T_NATIVE_DOUBLE, &time_steps_dim1);
1108 int* time_steps_idx_data =
nullptr;
1109 size_t time_steps_idx_dim1 = 0;
1110 read_array_rank1(m_file_id,
"time_steps_idx", &time_steps_idx_data, H5T_NATIVE_INT, &time_steps_idx_dim1);
1113 if (time_steps_dim1 != time_steps_idx_dim1) {
1114 string errmsg = string(
"Error reading file \'") + m_file_path
1115 + string(
"\': The /time_steps and /time_steps_idx datasets must be the same size. File might be corrupted.");
1117 delete[] time_steps_data;
1118 delete[] time_steps_idx_data;
1119 throw runtime_error(errmsg);
1122 vector<pair<int, double>> time_steps(time_steps_dim1);
1123 for (
size_t i = 0; i < time_steps_dim1; ++i) {
1124 time_steps[i] = make_pair(time_steps_idx_data[i], time_steps_data[i]);
1128 delete[] time_steps_data;
1129 delete[] time_steps_idx_data;
1138 WriteState(sim->GetState());
1141 void Hdf5File::WriteCells(hid_t loc_id,
const MeshState& mstate)
1168 const vector<int> cells_id = mstate.
GetCellsID();
1169 write_array_rank1(loc_id,
"cells_id", cells_id.data(), H5T_STD_I32LE, num_cells);
1172 size_t max_cells_num_nodes = 0;
1174 for (
size_t cell_num_nodes : cells_num_nodes) {
1175 if (cell_num_nodes > max_cells_num_nodes) {
1176 max_cells_num_nodes = cell_num_nodes;
1181 size_t max_cells_num_walls = 0;
1183 for (
size_t cell_num_walls : cells_num_walls) {
1184 if (cell_num_walls > max_cells_num_walls) {
1185 max_cells_num_walls = cell_num_walls;
1190 int* cells_num_nodes_data =
new int[num_cells];
1191 int* cells_nodes_data =
new int[num_cells * max_cells_num_nodes];
1192 int* cells_num_walls_data =
new int[num_cells];
1193 int* cells_walls_data =
new int[num_cells * max_cells_num_walls];
1195 for (
size_t cell_idx = 0; cell_idx < num_cells; ++cell_idx) {
1197 cells_num_nodes_data[cell_idx] = cells_num_nodes[cell_idx];
1199 size_t cell_node_idx = 0;
1200 for (
const int cell_node_id : mstate.
GetCellNodes(cell_idx)) {
1201 cells_nodes_data[(cell_idx * max_cells_num_nodes) + cell_node_idx] = cell_node_id;
1205 while (cell_node_idx < max_cells_num_nodes) {
1206 cells_nodes_data[(cell_idx * max_cells_num_nodes) + cell_node_idx] = -1;
1211 cells_num_walls_data[cell_idx] = cells_num_walls[cell_idx];
1213 size_t cell_wall_idx = 0;
1214 for (
const int cell_wall_id : mstate.
GetCellWalls(cell_idx)) {
1215 cells_walls_data[(cell_idx * max_cells_num_walls) + cell_wall_idx] = cell_wall_id;
1219 while (cell_wall_idx < max_cells_num_walls) {
1220 cells_walls_data[(cell_idx * max_cells_num_walls) + cell_wall_idx] = -1;
1227 write_array_rank1(loc_id,
"cells_num_nodes", cells_num_nodes_data, H5T_STD_I32LE, num_cells);
1228 write_array_rank2(loc_id,
"cells_nodes", cells_nodes_data, H5T_STD_I32LE, num_cells, max_cells_num_nodes);
1229 write_array_rank1(loc_id,
"cells_num_walls", cells_num_walls_data, H5T_STD_I32LE, num_cells);
1230 if (1 != num_cells) {
1231 write_array_rank2(loc_id,
"cells_walls", cells_walls_data, H5T_STD_I32LE, num_cells, max_cells_num_walls);
1235 delete[] cells_num_nodes_data;
1236 delete[] cells_nodes_data;
1237 delete[] cells_num_walls_data;
1238 delete[] cells_walls_data;
1243 string attr_name_hdf5 = string(
"cells_attr_") + attr_name;
1244 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_STD_I32LE, num_cells);
1250 string attr_name_hdf5 = string(
"cells_attr_") + attr_name;
1251 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_IEEE_F64LE, num_cells);
1257 string attr_name_hdf5 = string(
"cells_attr_") + attr_name;
1258 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values);
1262 void Hdf5File::WriteBPNodes(hid_t loc_id,
const MeshState& mstate)
1264 vector<int> bp_nodes = mstate.GetBoundaryPolygonNodes();
1265 write_array_rank1(loc_id,
"bp_nodes", bp_nodes.data(), H5T_STD_I32LE, bp_nodes.size());
1268 void Hdf5File::WriteBPWalls(hid_t loc_id,
const MeshState& mstate)
1270 vector<int> bp_walls = mstate.GetBoundaryPolygonWalls();
1271 write_array_rank1(loc_id,
"bp_walls", bp_walls.data(), H5T_STD_I32LE, bp_walls.size());
1274 void Hdf5File::WriteMesh(hid_t loc_id,
const MeshState& mstate)
1276 string const here = string(VL_HERE) +
"> ";
1278 WriteNodes(loc_id, mstate);
1279 WriteCells(loc_id, mstate);
1280 WriteBPNodes(loc_id, mstate);
1283 const size_t num_cells = mstate.GetNumCells();
1284 const size_t num_walls = mstate.GetNumWalls();
1285 if (num_cells > 1 && num_walls > 0) {
1286 WriteWalls(loc_id, mstate);
1287 WriteBPWalls(loc_id, mstate);
1288 }
else if ((num_cells == 1 && num_walls != 0) || (num_cells > 1 && num_walls == 0)) {
1290 <<
"[Hdf5File] Error: inconsistent number of cells and walls: (#cells > 1) iff (#walls > 0)"
1296 void Hdf5File::WriteNodes(hid_t loc_id,
const MeshState& mstate)
1298 const size_t num_nodes = mstate.GetNumNodes();
1302 vector<int> nodes_id = mstate.GetNodesID();
1303 write_array_rank1(loc_id,
"nodes_id", nodes_id.data(), H5T_STD_I32LE, num_nodes);
1306 double* nodes_xy_data =
new double[2 * num_nodes];
1307 for (
size_t node_idx = 0; node_idx < num_nodes; ++node_idx) {
1308 nodes_xy_data[2 * node_idx] = mstate.GetNodeX(node_idx);
1309 nodes_xy_data[2 * node_idx + 1] = mstate.GetNodeY(node_idx);
1311 write_array_rank2(loc_id,
"nodes_xy", nodes_xy_data, H5T_IEEE_F64LE, num_nodes, 2);
1312 delete[] nodes_xy_data;
1315 for (
string attr_name : mstate.NodeAttributeContainer().GetNames<
int>()) {
1316 vector<int> attr_values = mstate.NodeAttributeContainer().GetAll<
int>(attr_name);
1317 string attr_name_hdf5 = string(
"nodes_attr_") + attr_name;
1318 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_STD_I32LE, num_nodes);
1322 for (
string attr_name : mstate.NodeAttributeContainer().GetNames<
double>()) {
1323 vector<double> attr_values = mstate.NodeAttributeContainer().GetAll<
double>(attr_name);
1324 string attr_name_hdf5 = string(
"nodes_attr_") + attr_name;
1325 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_IEEE_F64LE, num_nodes);
1329 for (
string attr_name : mstate.NodeAttributeContainer().GetNames<
string>()) {
1330 vector < string > attr_values = mstate.NodeAttributeContainer().GetAll<
string>(attr_name);
1331 string attr_name_hdf5 = string(
"nodes_attr_") + attr_name;
1332 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values);
1336 void Hdf5File::WriteParameters(hid_t loc_id,
const ptree& params)
1340 hid_t param_grp = H5Gcreate(loc_id,
"parameters", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1343 ptree2hdf5(params, param_grp);
1345 H5Gclose(param_grp);
1348 void Hdf5File::WritePtreeToStringAttribute(hid_t loc_id,
const string& attr_name,
const ptree& pt)
1351 stringstream pt_strm;
1352 write_xml(pt_strm, pt, XmlWriterSettings::GetTab());
1353 string pt_str = pt_strm.str();
1354 const char* pt_cstr = pt_str.c_str();
1357 hid_t attr_dspace = H5Screate(H5S_SCALAR);
1358 hid_t attr_dtype = H5Tcopy(H5T_C_S1);
1359 H5Tset_size(attr_dtype, H5T_VARIABLE);
1360 hid_t attr_id = H5Acreate(loc_id, attr_name.c_str(), attr_dtype, attr_dspace, H5P_DEFAULT, H5P_DEFAULT);
1361 H5Awrite(attr_id, attr_dtype, &pt_cstr);
1363 H5Sclose(attr_dspace);
1364 H5Tclose(attr_dtype);
1367 void Hdf5File::WriteState(
const SimState& sstate)
1369 const string here = string(VL_HERE) +
"> ";
1383 double* time_steps_data =
nullptr;
1384 size_t time_steps_dim1 = 0;
1385 read_array_rank1(m_file_id,
"time_steps", &time_steps_data, H5T_NATIVE_DOUBLE, &time_steps_dim1);
1387 int* time_steps_idx_data =
nullptr;
1388 size_t time_steps_idx_dim1 = 0;
1389 read_array_rank1(m_file_id,
"time_steps_idx", &time_steps_idx_data, H5T_NATIVE_INT, &time_steps_idx_dim1);
1392 if (time_steps_dim1 != time_steps_idx_dim1) {
1394 delete[] time_steps_data;
1395 delete[] time_steps_idx_data;
1396 throw runtime_error(
"[Hdf5File] Error: dim of time_steps and time_steps_idx do not match.");
1400 size_t& num_time_steps = time_steps_dim1;
1401 const double sim_time = sstate.GetTime();
1402 const int sim_step = sstate.GetTimeStep();
1403 string step_grp_name = string(
"/step_") + to_string(sim_step);
1411 if (num_time_steps != 0 && sim_step <= time_steps_idx_data[num_time_steps - 1]) {
1415 size_t i = num_time_steps - 1;
1417 while (static_cast<int>(i) >= 0 && sim_step <= time_steps_idx_data[i]) {
1419 string name = string(
"step_") + to_string(time_steps_idx_data[i]);
1422 H5Ldelete(m_file_id, name.c_str(), H5P_DEFAULT);
1431 hid_t dset = H5Dopen(m_file_id,
"time_steps", H5P_DEFAULT);
1433 hid_t dspace = H5Dget_space(dset);
1434 H5Sget_simple_extent_dims(dspace, &dims, 0);
1436 H5Dset_extent(dset, &dims);
1441 hid_t dset = H5Dopen(m_file_id,
"time_steps_idx", H5P_DEFAULT);
1443 hid_t dspace = H5Dget_space(dset);
1444 H5Sget_simple_extent_dims(dspace, &dims, 0);
1446 H5Dset_extent(dset, &dims);
1453 delete[] time_steps_data;
1454 delete[] time_steps_idx_data;
1461 hid_t time_steps_dset = H5Dopen(m_file_id,
"time_steps", H5P_DEFAULT);
1465 hsize_t time_steps_dims;
1466 hid_t time_steps_dspace = H5Dget_space(time_steps_dset);
1467 H5Sget_simple_extent_dims(time_steps_dspace, &time_steps_dims, 0);
1469 H5Dset_extent(time_steps_dset, &time_steps_dims);
1483 hsize_t last_time_step_coord = time_steps_dims - 1;
1484 H5Sselect_elements(time_steps_dspace, H5S_SELECT_SET, 1, &last_time_step_coord);
1486 hsize_t curr_time_step_dims[] = { 1 };
1487 hid_t curr_time_step_dspace = H5Screate_simple(1, curr_time_step_dims, NULL);
1489 H5Dwrite(time_steps_dset, H5T_IEEE_F64LE, curr_time_step_dspace, time_steps_dspace, H5P_DEFAULT, &sim_time);
1491 H5Sclose(curr_time_step_dspace);
1492 H5Sclose(time_steps_dspace);
1493 H5Dclose(time_steps_dset);
1497 hid_t time_steps_idx_dset = H5Dopen(m_file_id,
"time_steps_idx", H5P_DEFAULT);
1501 hsize_t time_steps_idx_dims;
1502 hid_t time_steps_idx_dspace = H5Dget_space(time_steps_idx_dset);
1503 H5Sget_simple_extent_dims(time_steps_idx_dspace, &time_steps_idx_dims, 0);
1504 time_steps_idx_dims++;
1505 H5Dset_extent(time_steps_idx_dset, &time_steps_idx_dims);
1519 hsize_t last_time_step_idx_coord = time_steps_idx_dims - 1;
1520 H5Sselect_elements(time_steps_idx_dspace, H5S_SELECT_SET, 1, &last_time_step_idx_coord);
1522 hsize_t curr_time_step_idx_dims[] = { 1 };
1523 hid_t curr_time_step_idx_dspace = H5Screate_simple(1, curr_time_step_idx_dims, NULL);
1525 H5Dwrite(time_steps_idx_dset, H5T_STD_I32LE, curr_time_step_idx_dspace, time_steps_idx_dspace, H5P_DEFAULT,
1528 H5Sclose(curr_time_step_idx_dspace);
1529 H5Sclose(time_steps_idx_dspace);
1530 H5Dclose(time_steps_idx_dset);
1534 hid_t step_grp = H5Gcreate(m_file_id, step_grp_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1536 WriteMesh(step_grp, sstate.GetMeshState());
1542 WritePtreeToStringAttribute(step_grp,
"parameters", sstate.GetParameters());
1544 WritePtreeToStringAttribute(step_grp,
"random_engine", sstate.GetRandomEngineState());
1550 void Hdf5File::WriteWalls(hid_t loc_id,
const MeshState& mstate)
1552 const size_t num_walls = mstate.GetNumWalls();
1563 const vector<int> walls_id = mstate.GetWallsID();
1564 write_array_rank1(loc_id,
"walls_id", walls_id.data(), H5T_STD_I32LE, num_walls);
1567 int* walls_cells_data =
new int[2 * num_walls];
1568 int* walls_nodes_data =
new int[2 * num_walls];
1570 for (
size_t wall_idx = 0; wall_idx < num_walls; ++wall_idx) {
1572 pair<int, int> cells_ids = mstate.GetWallCells(wall_idx);
1573 walls_cells_data[2 * wall_idx] = cells_ids.first;
1574 walls_cells_data[2 * wall_idx + 1] = cells_ids.second;
1576 pair<int, int> nodes_ids = mstate.GetWallNodes(wall_idx);
1577 walls_nodes_data[2 * wall_idx] = nodes_ids.first;
1578 walls_nodes_data[2 * wall_idx + 1] = nodes_ids.second;
1582 write_array_rank2(loc_id,
"walls_cells", walls_cells_data, H5T_STD_I32LE, num_walls, 2);
1583 write_array_rank2(loc_id,
"walls_nodes", walls_nodes_data, H5T_STD_I32LE, num_walls, 2);
1586 delete[] walls_cells_data;
1587 delete[] walls_nodes_data;
1590 for (
string attr_name : mstate.WallAttributeContainer().GetNames<
int>()) {
1591 const vector<int> attr_values = mstate.WallAttributeContainer().GetAll<
int>(attr_name);
1592 string attr_name_hdf5 = string(
"walls_attr_") + attr_name;
1593 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_STD_I32LE, num_walls);
1597 for (
string attr_name : mstate.WallAttributeContainer().GetNames<
double>()) {
1598 const vector<double> attr_values = mstate.WallAttributeContainer().GetAll<
double>(attr_name);
1599 string attr_name_hdf5 = string(
"walls_attr_") + attr_name;
1600 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values.data(), H5T_IEEE_F64LE, num_walls);
1604 for (
string attr_name : mstate.WallAttributeContainer().GetNames<
string>()) {
1605 const vector<string> attr_values = mstate.WallAttributeContainer().GetAll<
string>(attr_name);
1606 string attr_name_hdf5 = string(
"walls_attr_") + attr_name;
1607 write_array_rank1(loc_id, attr_name_hdf5.c_str(), attr_values);
size_t GetNumCells() const
Returns the number of cells in the mesh.
std::vector< T > GetAll(const std::string &name) const
Returns all values of a named attribute.
Namespace for miscellaneous utilities.
Simulator: mesh & parameters, model & algorithms.
void Write(std::shared_ptr< const SimPT_Sim::Sim > sim)
Writes the mesh state to the HDF5 file currently associated with exporter object. ...
Namespace for SimPT shell package.
Interface for VirtualLeaf::Hdf5File.
Macro defs for debug and logging.
std::vector< size_t > GetCellsNumNodes() const
Returns the number of nodes for all cells.
std::vector< std::pair< int, double > > TimeSteps()
Reads the time steps contained in the HDF5 file.
std::vector< int > GetCellNodes(size_t cell_idx) const
Returns the IDs of the nodes that form the polygon of a particular cell.
std::vector< int > GetCellsID() const
Returns the IDs of all cells.
bool IsOpen()
Returns true if exporter is associated with a HDF5 file that has been successfully opened...
virtual ~Hdf5File()
Cleans up HDF5 storage: makes sure files are closed properly.
std::vector< size_t > GetCellsNumWalls() const
Returns the number of walls for all cells.
Sim, the actual simulator.
bool Close()
Closes the HDF5 file associated with exporter, dissociates it from this exporter object and returns t...
Contains the state of the whole Simulator at a given simulation step.
Interface of AttributeContainer.
bool Open(const std::string &file_path)
Creates an HDF5 file and binds the exporter object to it.
std::vector< std::string > GetNames() const
Returns a vector containing the names of attributes of type T.
ptree hdf52ptree(hid_t loc_id)
Return the ptree that represents the groups of attributes in HDF5.
Contains the state of the whole Mesh at a given simulation step.
Hdf5File()
Creates an empty HDF5 mesh exporter with no file association.
Xml writer settings class.
std::string GetFilePath()
Return file path for HDF5 file associated with the exporter object, if any.
AttributeContainer & CellAttributeContainer()
Adds a new named attribute of type T for the nodes.
static std::string GetFileExtension()
Return file extension for HDF5 format.
std::vector< int > GetCellWalls(size_t cell_idx) const
Returns the IDs of walls of a particular cell.