Wildmeshing Toolkit
named_multimesh.cpp
Go to the documentation of this file.
1 #include <fmt/ranges.h>
2 #include <catch2/catch_test_macros.hpp>
3 #include <nlohmann/json.hpp>
4 #include <wmtk/Mesh.hpp>
9 #include <wmtk/utils/Logger.hpp>
10 
11 #include "utils.hpp"
12 
14 
15 
16 
17 
18 TEST_CASE("named_multimesh_parse", "[components][multimesh]")
19 {
20  {
21  auto m = make_mesh();
23  named_mm.set_mesh(*m);
24 
25  named_mm.set_name("roo");
26 
27  CHECK(std::vector<int64_t>{} == named_mm.get_id("roo"));
28  CHECK(m == named_mm.root().shared_from_this());
29  CHECK(m == named_mm.get_mesh("roo").shared_from_this());
30  }
31 
32 
33  {
34  auto m = make_mesh();
35  make_child(*m, {0});
36 
37 
39  named_mm.set_mesh(*m);
40  {
41  nlohmann::json js;
42  js["roo"] = nlohmann::json::array({"child"});
43  named_mm.set_names(js);
44  }
45  CHECK(std::vector<int64_t>{} == named_mm.get_id("roo"));
46  CHECK(std::vector<int64_t>{0} == named_mm.get_id("roo.child"));
47  CHECK(m == named_mm.root().shared_from_this());
48  CHECK(m == named_mm.get_mesh("roo").shared_from_this());
49  CHECK(
50  m->get_multi_mesh_child_mesh({0}).shared_from_this() ==
51  named_mm.get_mesh("roo.child").shared_from_this());
52  }
53  {
55  nlohmann::json js;
56  js["roo"] = nlohmann::json("child");
57  named_mm.set_names(js);
58  CHECK(std::vector<int64_t>{} == named_mm.get_id("roo"));
59  CHECK(std::vector<int64_t>{0} == named_mm.get_id("roo.child"));
60  }
61  {
63  nlohmann::json js;
64  js["roo"]["child"] = {};
65  named_mm.set_names(js);
66  CHECK(std::vector<int64_t>{} == named_mm.get_id("roo"));
67  CHECK(std::vector<int64_t>{0} == named_mm.get_id("roo.child"));
68  }
69 
70  {
72  auto m = make_mesh();
73  {
74  make_child(*m, {0});
75  make_child(*m, {0, 0, 0});
76  make_child(*m, {1, 1});
77 
78  named_mm.set_mesh(*m);
79  }
80  {
81  nlohmann::json js;
82  js["roo"]["c"]["d"]["e"] = {};
83  js["roo"]["child"] = nlohmann::json::array({"c1", "c2"});
84  named_mm.set_names(js);
85  }
86  CHECK(std::vector<int64_t>{} == named_mm.get_id("roo"));
87  CHECK(std::vector<int64_t>{0, 0, 0} == named_mm.get_id("roo.c.d.e"));
88  CHECK(std::vector<int64_t>{1} == named_mm.get_id("roo.child"));
89  CHECK(std::vector<int64_t>{1, 0} == named_mm.get_id("roo.child.c1"));
90  CHECK(std::vector<int64_t>{1, 1} == named_mm.get_id("roo.child.c2"));
91  CHECK(
92  m->get_multi_mesh_child_mesh({0, 0, 0}).shared_from_this() ==
93  named_mm.get_mesh("roo.c.d.e").shared_from_this());
94  CHECK(
95  m->get_multi_mesh_child_mesh({1, 1}).shared_from_this() ==
96  named_mm.get_mesh("roo.child.c2").shared_from_this());
97 
98  CHECK(
99  m->get_multi_mesh_child_mesh({0, 0, 0}).shared_from_this() ==
100  named_mm.get_mesh(".c.d.e").shared_from_this());
101  CHECK(
102  m->get_multi_mesh_child_mesh({1, 1}).shared_from_this() ==
103  named_mm.get_mesh(".child.c2").shared_from_this());
104  }
105 }
106 
std::vector< int64_t > get_id(const std::string_view &path) const
void set_mesh(Mesh &m)
Navigates to the root of the multimesh.
Mesh & get_mesh(const std::string_view &path) const
void set_names(const nlohmann::json &js)
void set_name(const std::string_view &root_name="")
sets just the name of the root mesh, keeping child names the same
TEST_CASE("named_multimesh_parse", "[components][multimesh]")
nlohmann::json json
nlohmann::json json
Definition: input.cpp:9
auto make_child(wmtk::Mesh &m, const std::vector< int64_t > &path) -> std::vector< std::shared_ptr< wmtk::Mesh >>
Definition: utils.cpp:11
std::shared_ptr< wmtk::Mesh > make_mesh()
Definition: utils.cpp:6