88 constexpr static int64_t TWO_TUPLE_SIZE = wmtk::multimesh::utils::TWO_TUPLE_SIZE;
89 constexpr static int64_t DEFAULT_TUPLES_VALUES = wmtk::multimesh::utils::DEFAULT_TUPLES_VALUES;
91 h5pp::File hdf5_file(filename, h5pp::FileAccess::READONLY);
95 if (hdf5_file.linkExists(
"WMTK/multimesh")) {
96 std::map<std::vector<int64_t>, std::shared_ptr<Mesh>> meshes;
99 const auto dsets = hdf5_file.findGroups(
"mesh_",
"WMTK/multimesh", -1, 1);
100 for (
auto& s : dsets) {
101 const std::string dataset =
"WMTK/multimesh/" + s;
104 hdf5_file.readAttribute<std::vector<int64_t>>(dataset,
"absolute_id");
105 meshes[absolute_id] =
read_mesh(hdf5_file, dataset);
109 for (
auto& p : meshes) {
110 if (p.first.empty())
continue;
112 const std::vector<int64_t>& child_id = p.first;
113 const auto child_index = child_id.back();
115 std::vector<int64_t> parent_id = child_id;
116 parent_id.pop_back();
118 auto parent_mesh = meshes.at(parent_id);
119 auto child_mesh = p.second;
121 const PrimitiveType child_primitive_type = child_mesh->top_simplex_type();
124 assert(parent_mesh->m_multi_mesh_manager.m_children.size() == child_index);
126 auto child_to_parent_handle =
128 ->get_attribute_handle<int64_t>(
130 child_primitive_type)
133 auto parent_to_child_handle =
135 ->get_attribute_handle<int64_t>(
138 child_primitive_type)
141 child_mesh->m_multi_mesh_manager.m_parent = parent_mesh.get();
142 child_mesh->m_multi_mesh_manager.m_child_id = child_index;
143 child_mesh->m_multi_mesh_manager.map_to_parent_handle = child_to_parent_handle;
145 parent_mesh->m_multi_mesh_manager.m_children.emplace_back();
146 parent_mesh->m_multi_mesh_manager.m_children.back().mesh = child_mesh;
147 parent_mesh->m_multi_mesh_manager.m_children.back().map_handle = parent_to_child_handle;
148 parent_mesh->m_multi_mesh_manager
149 .m_has_child_mesh_in_dimension[child_mesh->top_cell_dimension()] =
true;
150 parent_mesh->assert_capacity_valid();
151 child_mesh->assert_capacity_valid();
155 for (
auto& p : meshes) {
156 assert(p.first == p.second->m_multi_mesh_manager.absolute_id());
168 hdf5_file.readAttribute<
PrimitiveType>(root_dataset,
"top_simplex_type");
170 std::shared_ptr<Mesh> mesh;
172 switch (top_simplex_type) {
180 std::vector<int64_t> capacities =
181 hdf5_file.readAttribute<std::vector<int64_t>>(root_dataset,
"capacities");
184 mesh->set_capacities(capacities);
187 bool found_something =
false;
188 auto searcher = [&](
int dim,
auto&& t) {
189 using T = std::decay_t<
decltype(t)>;
190 const static std::string name = get_type<T>();
192 std::string attr_dset_name =
193 fmt::format(
"{}/ATTRIBUTE_LIST_{}/{}", root_dataset, name, dim);
195 auto names = hdf5_file.readDataset<std::vector<std::string>>(attr_dset_name);
196 for (
const auto& v : names) {
197 found_something =
true;
198 const std::string dataset = fmt::format(
"{}/{}/{}", root_dataset, dim, v);
201 }
catch (
const std::exception& e) {
204 auto search = [&](
int dim) {
205 searcher(dim,
double{});
207 searcher(dim, int64_t{});
208 searcher(dim,
char{});
210 switch (top_simplex_type) {
218 if (found_something) {
225 const auto dsets = hdf5_file.findDatasets(
"", root_dataset, -1, 1);
226 for (
auto& s : dsets) {
227 const std::string dataset = fmt::format(
"{}/{}", root_dataset, s);
234 h5pp::File& hdf5_file,
236 const std::string& dataset,
237 const std::string& name_)
239 const int64_t stride = hdf5_file.readAttribute<int64_t>(dataset,
"stride");
240 const int64_t dimension = hdf5_file.readAttribute<int64_t>(dataset,
"dimension");
241 const std::string type = hdf5_file.readAttribute<std::string>(dataset,
"type");
242 const std::string name =
243 std::regex_replace(name_, std::regex(std::to_string(dimension) +
"/"),
"");
247 if (type ==
"int64_t") {
248 auto v = hdf5_file.readDataset<std::vector<int64_t>>(dataset);
249 const auto default_val = hdf5_file.readAttribute<int64_t>(dataset,
"default_value");
251 set_attribute<int64_t>(default_val, name, pt, stride, v, mesh);
252 }
else if (type ==
"char") {
253 auto tmp = hdf5_file.readDataset<std::vector<short>>(dataset);
254 const auto default_val = char(hdf5_file.readAttribute<
short>(dataset,
"default_value"));
257 v.reserve(tmp.size());
258 for (
auto val : tmp) v.push_back(
char(val));
261 set_attribute<char>(default_val, name, pt, stride, v, mesh);
262 }
else if (type ==
"double") {
263 auto v = hdf5_file.readDataset<std::vector<double>>(dataset);
264 const auto default_val = hdf5_file.readAttribute<
double>(dataset,
"default_value");
267 set_attribute<double>(default_val, name, pt, stride, v, mesh);
268 }
else if (type ==
"rational") {
269 const Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp =
271 .readDataset<Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>(
273 const Eigen::Matrix<char, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp_char =
276 const std::string data = hdf5_file.readAttribute<std::string>(dataset,
"default_value");
280 std::vector<Rational> v;
281 v.reserve(tmp.rows());
282 for (
size_t i = 0; i < tmp.rows(); ++i) {
283 v.emplace_back(tmp_char.row(i));
286 set_attribute<Rational>(default_val, name, pt, stride, v, mesh);
289 logger().error(
"We currently do not support reading the type \"{}\"", type);
void set_attribute(const T &default_val, const std::string &name, PrimitiveType pt, int64_t stride, const std::vector< T > &v, Mesh &mesh)