From 3062a30946f9437d1bef27d49621491830730b77 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sun, 27 Oct 2024 15:58:05 -0400 Subject: [PATCH 01/29] moved named multimesh to from the input component to the multimesh component --- .../src/wmtk/components/input/CMakeLists.txt | 10 ++----- .../input/src/wmtk/components/input/input.cpp | 4 +-- .../input/src/wmtk/components/input/input.hpp | 4 +-- .../components/input/utils/get_attribute.hpp | 26 ------------------- components/input/tests/CMakeLists.txt | 2 +- components/multimesh/CMakeLists.txt | 2 +- .../wmtk/components/multimesh/CMakeLists.txt | 10 +++++++ .../components/multimesh}/MeshCollection.cpp | 14 +++++----- .../components/multimesh}/MeshCollection.hpp | 6 ++--- .../components/multimesh}/NamedMultiMesh.cpp | 4 +-- .../components/multimesh}/NamedMultiMesh.hpp | 4 +-- .../multimesh}/internal/split_path.hpp | 4 +-- .../multimesh}/utils/get_attribute.cpp | 6 ++--- .../multimesh/utils/get_attribute.hpp | 26 +++++++++++++++++++ components/multimesh/tests/CMakeLists.txt | 4 +++ .../tests/named_multimesh.cpp | 16 ++++++------ 16 files changed, 75 insertions(+), 67 deletions(-) delete mode 100644 components/input/src/wmtk/components/input/utils/get_attribute.hpp rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/MeshCollection.cpp (86%) rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/MeshCollection.hpp (78%) rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/NamedMultiMesh.cpp (98%) rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/NamedMultiMesh.hpp (93%) rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/internal/split_path.hpp (88%) rename components/{input/src/wmtk/components/input => multimesh/src/wmtk/components/multimesh}/utils/get_attribute.cpp (94%) create mode 100644 components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.hpp create mode 100644 components/multimesh/tests/CMakeLists.txt rename components/{input => multimesh}/tests/named_multimesh.cpp (88%) diff --git a/components/input/src/wmtk/components/input/CMakeLists.txt b/components/input/src/wmtk/components/input/CMakeLists.txt index 2d33f4221a..957c4de6ec 100644 --- a/components/input/src/wmtk/components/input/CMakeLists.txt +++ b/components/input/src/wmtk/components/input/CMakeLists.txt @@ -10,13 +10,6 @@ set(SRC_FILES mesh_with_tag_from_image.hpp input.cpp input.hpp - NamedMultiMesh.hpp - NamedMultiMesh.cpp - utils/get_attribute.hpp - utils/get_attribute.cpp - - MeshCollection.hpp - MeshCollection.cpp ) include(stb) @@ -25,5 +18,6 @@ include(stb) target_compile_features(wmtk_${COMPONENT_NAME} PUBLIC cxx_std_20) target_sources(wmtk_${COMPONENT_NAME} PRIVATE ${SRC_FILES}) -target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image) +target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image nlohmann_json) +target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image nlohmann_json PUBLIC wmtk::multimesh) diff --git a/components/input/src/wmtk/components/input/input.cpp b/components/input/src/wmtk/components/input/input.cpp index 2c5d54f81d..52610aedb7 100644 --- a/components/input/src/wmtk/components/input/input.cpp +++ b/components/input/src/wmtk/components/input/input.cpp @@ -22,7 +22,7 @@ std::shared_ptr input( return input(options).root().shared_from_this(); } -NamedMultiMesh input(const InputOptions& options) +multimesh::NamedMultiMesh input(const InputOptions& options) { if (!std::filesystem::exists(options.file)) { log_and_throw_error("file [{}] not found", options.file.string()); @@ -49,7 +49,7 @@ NamedMultiMesh input(const InputOptions& options) assert(mesh->is_connectivity_valid()); - NamedMultiMesh mm; + multimesh::NamedMultiMesh mm; mm.set_mesh(*mesh); mm.set_names(options.name_spec); diff --git a/components/input/src/wmtk/components/input/input.hpp b/components/input/src/wmtk/components/input/input.hpp index 1ba272f1fe..68dff06636 100644 --- a/components/input/src/wmtk/components/input/input.hpp +++ b/components/input/src/wmtk/components/input/input.hpp @@ -4,7 +4,7 @@ #include -#include "NamedMultiMesh.hpp" +#include namespace wmtk::components::input { class InputOptions; @@ -25,6 +25,6 @@ std::shared_ptr input( const bool ignore_z_if_zero = false, const std::vector& tetrahedron_attributes = {}); -NamedMultiMesh input(const InputOptions& options); +multimesh::NamedMultiMesh input(const InputOptions& options); } // namespace wmtk::components::input diff --git a/components/input/src/wmtk/components/input/utils/get_attribute.hpp b/components/input/src/wmtk/components/input/utils/get_attribute.hpp deleted file mode 100644 index b89ec22b32..0000000000 --- a/components/input/src/wmtk/components/input/utils/get_attribute.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include - -namespace wmtk { -class Mesh; -namespace components::input { -class MeshCollection; -} -} // namespace wmtk - -namespace wmtk::components::input::utils { - // - // desires json that has - // * name (str for attribute name) - // * mesh (mesh path, mesh only only overload does not use this) - // * type (str double/int/char/rational - // * simplex (int, dimension attribute belongs to - // if type and simplex are missing code will search in lexicographical of (primitive_type, type) - // where double < int < char < rational for type - -wmtk::attribute::MeshAttributeHandle get_attribute(const Mesh& m, const nlohmann::json& js); -wmtk::attribute::MeshAttributeHandle get_attribute( - const wmtk::components::input::MeshCollection& m, - const nlohmann::json& js); -} // namespace wmtk::components::input::utils diff --git a/components/input/tests/CMakeLists.txt b/components/input/tests/CMakeLists.txt index 17a060a640..dc4810ae3f 100644 --- a/components/input/tests/CMakeLists.txt +++ b/components/input/tests/CMakeLists.txt @@ -1,2 +1,2 @@ -add_component_test(wmtk::${COMPONENT_NAME} input.cpp named_multimesh.cpp) +add_component_test(wmtk::${COMPONENT_NAME} input.cpp ) diff --git a/components/multimesh/CMakeLists.txt b/components/multimesh/CMakeLists.txt index 3c50b8528c..fd6bd15574 100644 --- a/components/multimesh/CMakeLists.txt +++ b/components/multimesh/CMakeLists.txt @@ -1,3 +1,3 @@ set(COMPONENT_NAME multimesh) add_subdirectory("src/wmtk/components/${COMPONENT_NAME}") -#add_subdirectory("tests") +add_subdirectory("tests") diff --git a/components/multimesh/src/wmtk/components/multimesh/CMakeLists.txt b/components/multimesh/src/wmtk/components/multimesh/CMakeLists.txt index bf1997a0bd..226c9f200a 100644 --- a/components/multimesh/src/wmtk/components/multimesh/CMakeLists.txt +++ b/components/multimesh/src/wmtk/components/multimesh/CMakeLists.txt @@ -20,6 +20,15 @@ set(SRC_FILES multimesh.hpp multimesh.cpp + + NamedMultiMesh.hpp + NamedMultiMesh.cpp + utils/get_attribute.hpp + utils/get_attribute.cpp + internal/split_path.hpp + + MeshCollection.hpp + MeshCollection.cpp ) include(stb) @@ -28,3 +37,4 @@ include(stb) target_compile_features(wmtk_${COMPONENT_NAME} PUBLIC cxx_std_20) target_sources(wmtk_${COMPONENT_NAME} PRIVATE ${SRC_FILES}) +target_link_libraries(wmtk_${COMPONENT_NAME} PRIVATE stb::image nlohmann_json) diff --git a/components/input/src/wmtk/components/input/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp similarity index 86% rename from components/input/src/wmtk/components/input/MeshCollection.cpp rename to components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index c0c13de43f..13d5499885 100644 --- a/components/input/src/wmtk/components/input/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -3,9 +3,9 @@ #include "internal/split_path.hpp" #include -#include "input.hpp" +#include "multimesh.hpp" -namespace wmtk::components::input { +namespace wmtk::components::multimesh { NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) @@ -14,10 +14,10 @@ NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) return it->second; } -NamedMultiMesh& MeshCollection::add_mesh(const InputOptions& opts) -{ - return add_mesh(input(opts)); -} +//NamedMultiMesh& MeshCollection::add_mesh(const InputOptions& opts) +//{ +// return add_mesh(multimesh(opts)); +//} const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) const @@ -49,4 +49,4 @@ NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path } return m_meshes.at(nmm_name); } -} // namespace wmtk::components::input +} // namespace wmtk::components::multimesh diff --git a/components/input/src/wmtk/components/input/MeshCollection.hpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp similarity index 78% rename from components/input/src/wmtk/components/input/MeshCollection.hpp rename to components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp index cde4552606..cd1b59dbcf 100644 --- a/components/input/src/wmtk/components/input/MeshCollection.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp @@ -2,14 +2,14 @@ #include #include "NamedMultiMesh.hpp" -namespace wmtk::components::input { +namespace wmtk::components::multimesh { class InputOptions; class MeshCollection { public: NamedMultiMesh& add_mesh(NamedMultiMesh o); - NamedMultiMesh& add_mesh(const InputOptions& opts); + //NamedMultiMesh& add_mesh(const InputOptions& opts); const NamedMultiMesh& get_named_multimesh(const std::string_view& path) const; const Mesh& get_mesh(const std::string_view& path) const; @@ -22,4 +22,4 @@ class MeshCollection private: std::map m_meshes; }; -} // namespace wmtk::components::input +} // namespace wmtk::components::multimesh diff --git a/components/input/src/wmtk/components/input/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp similarity index 98% rename from components/input/src/wmtk/components/input/NamedMultiMesh.cpp rename to components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index b4b8ca5dbe..357a5b4c27 100644 --- a/components/input/src/wmtk/components/input/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -4,7 +4,7 @@ #include #include #include "internal/split_path.hpp" -namespace wmtk::components::input { +namespace wmtk::components::multimesh { struct NamedMultiMesh::Node { @@ -147,4 +147,4 @@ NamedMultiMesh::NamedMultiMesh(const NamedMultiMesh& o) : m_root(o.m_root) , m_name_root(std::make_unique(*o.m_name_root)) {} -} // namespace wmtk::components::input +} // namespace wmtk::components::multimesh diff --git a/components/input/src/wmtk/components/input/NamedMultiMesh.hpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp similarity index 93% rename from components/input/src/wmtk/components/input/NamedMultiMesh.hpp rename to components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp index fd3eda3b0b..a24658ca1b 100644 --- a/components/input/src/wmtk/components/input/NamedMultiMesh.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp @@ -7,7 +7,7 @@ class Mesh; } -namespace wmtk::components::input { +namespace wmtk::components::multimesh { // allows for accessing a mesh by a string ID // The IDs are loaded through a json format, and hte root node can either have a name or be hte @@ -44,4 +44,4 @@ class NamedMultiMesh std::unique_ptr m_name_root; }; -} // namespace wmtk::components::input +} // namespace wmtk::components::multimesh diff --git a/components/input/src/wmtk/components/input/internal/split_path.hpp b/components/multimesh/src/wmtk/components/multimesh/internal/split_path.hpp similarity index 88% rename from components/input/src/wmtk/components/input/internal/split_path.hpp rename to components/multimesh/src/wmtk/components/multimesh/internal/split_path.hpp index cd660ecae6..12ebf1a7b2 100644 --- a/components/input/src/wmtk/components/input/internal/split_path.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/internal/split_path.hpp @@ -3,7 +3,7 @@ #include #include -namespace wmtk::components::input::internal { +namespace wmtk::components::multimesh::internal { inline auto split_path(const std::string_view& view) { @@ -34,4 +34,4 @@ inline auto split_path(const std::string_view& view) return tokens; #endif } -} // namespace wmtk::components::input::internal +} // namespace wmtk::components::multimesh::internal diff --git a/components/input/src/wmtk/components/input/utils/get_attribute.cpp b/components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.cpp similarity index 94% rename from components/input/src/wmtk/components/input/utils/get_attribute.cpp rename to components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.cpp index 79e1156c2d..ea404b6dc6 100644 --- a/components/input/src/wmtk/components/input/utils/get_attribute.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.cpp @@ -3,7 +3,7 @@ #include #include "..//MeshCollection.hpp" #include "wmtk/utils/Logger.hpp" -namespace wmtk::components::input::utils { +namespace wmtk::components::multimesh::utils { wmtk::attribute::MeshAttributeHandle get_attribute(const Mesh& mesh, const nlohmann::json& js) { @@ -77,11 +77,11 @@ wmtk::attribute::MeshAttributeHandle get_attribute(const Mesh& mesh, const nlohm } wmtk::attribute::MeshAttributeHandle get_attribute( - const wmtk::components::input::MeshCollection& mc, + const wmtk::components::multimesh::MeshCollection& mc, const nlohmann::json& js) { const std::string name = js.contains("mesh") ? js["mesh"] : ""; const auto& mesh = mc.get_mesh(name); return get_attribute(mesh, js); } -} // namespace wmtk::components::input::utils +} // namespace wmtk::components::multimesh::utils diff --git a/components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.hpp b/components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.hpp new file mode 100644 index 0000000000..3cd780b5b7 --- /dev/null +++ b/components/multimesh/src/wmtk/components/multimesh/utils/get_attribute.hpp @@ -0,0 +1,26 @@ +#pragma once +#include +#include + +namespace wmtk { +class Mesh; +namespace components::multimesh { +class MeshCollection; +} +} // namespace wmtk + +namespace wmtk::components::multimesh::utils { +// +// desires json that has +// * name (str for attribute name) +// * mesh (mesh path, mesh only only overload does not use this) +// * type (str double/int/char/rational +// * simplex (int, dimension attribute belongs to +// if type and simplex are missing code will search in lexicographical of (primitive_type, type) +// where double < int < char < rational for type + +wmtk::attribute::MeshAttributeHandle get_attribute(const Mesh& m, const nlohmann::json& js); +wmtk::attribute::MeshAttributeHandle get_attribute( + const wmtk::components::multimesh::MeshCollection& m, + const nlohmann::json& js); +} // namespace wmtk::components::multimesh::utils diff --git a/components/multimesh/tests/CMakeLists.txt b/components/multimesh/tests/CMakeLists.txt new file mode 100644 index 0000000000..919b8f4eda --- /dev/null +++ b/components/multimesh/tests/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_component_test(wmtk::${COMPONENT_NAME} named_multimesh.cpp) + +target_link_libraries(${WMTK_COMPONENT_TEST_TARGET} PRIVATE wmtk::input) diff --git a/components/input/tests/named_multimesh.cpp b/components/multimesh/tests/named_multimesh.cpp similarity index 88% rename from components/input/tests/named_multimesh.cpp rename to components/multimesh/tests/named_multimesh.cpp index e8be17e978..558c21e267 100644 --- a/components/input/tests/named_multimesh.cpp +++ b/components/multimesh/tests/named_multimesh.cpp @@ -4,7 +4,7 @@ #include #include #include "tools/TriMesh_examples.hpp" -#include "wmtk/components/input/NamedMultiMesh.hpp" +#include "wmtk/components/multimesh/NamedMultiMesh.hpp" #include @@ -21,7 +21,7 @@ auto make_mesh() auto make_child(wmtk::Mesh& m, const std::vector& path) { if (path.size() == 0) { - // input root mesh already exists so nothing to be done + // multimesh root mesh already exists so nothing to be done return; } for (size_t j = 0; j < path.size(); ++j) { @@ -40,11 +40,11 @@ auto make_child(wmtk::Mesh& m, const std::vector& path) } // namespace -TEST_CASE("named_multimesh_parse", "[components][input]") +TEST_CASE("named_multimesh_parse", "[components][multimesh]") { { auto m = make_mesh(); - wmtk::components::input::NamedMultiMesh named_mm; + wmtk::components::multimesh::NamedMultiMesh named_mm; named_mm.set_mesh(*m); named_mm.set_name("roo"); @@ -60,7 +60,7 @@ TEST_CASE("named_multimesh_parse", "[components][input]") make_child(*m, {0}); - wmtk::components::input::NamedMultiMesh named_mm; + wmtk::components::multimesh::NamedMultiMesh named_mm; named_mm.set_mesh(*m); { nlohmann::json js; @@ -76,7 +76,7 @@ TEST_CASE("named_multimesh_parse", "[components][input]") named_mm.get_mesh("roo.child").shared_from_this()); } { - wmtk::components::input::NamedMultiMesh named_mm; + wmtk::components::multimesh::NamedMultiMesh named_mm; nlohmann::json js; js["roo"] = nlohmann::json("child"); named_mm.set_names(js); @@ -84,7 +84,7 @@ TEST_CASE("named_multimesh_parse", "[components][input]") CHECK(std::vector{0} == named_mm.get_id("roo.child")); } { - wmtk::components::input::NamedMultiMesh named_mm; + wmtk::components::multimesh::NamedMultiMesh named_mm; nlohmann::json js; js["roo"]["child"] = {}; named_mm.set_names(js); @@ -93,7 +93,7 @@ TEST_CASE("named_multimesh_parse", "[components][input]") } { - wmtk::components::input::NamedMultiMesh named_mm; + wmtk::components::multimesh::NamedMultiMesh named_mm; auto m = make_mesh(); { make_child(*m, {0}); From d6f06f45ab97d45507d0fe8152eba9dd7b440ab5 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sun, 27 Oct 2024 16:26:11 -0400 Subject: [PATCH 02/29] preparing output component to output named multimesh stuff --- .../components/multimesh/NamedMultiMesh.hpp | 2 ++ .../wmtk/components/output/CMakeLists.txt | 1 + .../wmtk/components/output/OutputOptions.cpp | 34 ++++++++----------- .../wmtk/components/output/OutputOptions.hpp | 14 +++----- .../output/wmtk/components/output/output.cpp | 9 +++++ .../output/wmtk/components/output/output.hpp | 7 ++++ components/utils/CMakeLists.txt | 3 +- .../wmtk/components/utils/json_macros.hpp | 16 +++++++++ 8 files changed, 57 insertions(+), 29 deletions(-) create mode 100644 components/utils/wmtk/components/utils/json_macros.hpp diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp index a24658ca1b..130b2ef6f3 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp @@ -27,6 +27,8 @@ class NamedMultiMesh void set_names(const nlohmann::json& js); void set_root(Mesh& m); + void get_names(nlohmann::json& js); + std::string_view root_name() const; std::string name(const std::vector& id) const; diff --git a/components/output/wmtk/components/output/CMakeLists.txt b/components/output/wmtk/components/output/CMakeLists.txt index 5f011b6d00..33adb82588 100644 --- a/components/output/wmtk/components/output/CMakeLists.txt +++ b/components/output/wmtk/components/output/CMakeLists.txt @@ -14,3 +14,4 @@ set(SRC_FILES target_sources(wmtk_${COMPONENT_NAME} PRIVATE ${SRC_FILES}) +target_link_libraries(wmtk_${COMPONENT_NAME} PUBLIC wmtk::multimesh) diff --git a/components/output/wmtk/components/output/OutputOptions.cpp b/components/output/wmtk/components/output/OutputOptions.cpp index 4f99da9333..1a81591dc9 100644 --- a/components/output/wmtk/components/output/OutputOptions.cpp +++ b/components/output/wmtk/components/output/OutputOptions.cpp @@ -7,18 +7,14 @@ namespace wmtk::components::output { -//bool OutputOptions::operator==(const OutputOptions& o) const = default; -} - -namespace nlohmann { -void adl_serializer::to_json(json& j, const Type& v) +WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(OutputOptions) { // - j["file"] = v.file.string(); + nlohmann_json_j["file"] = nlohmann_json_t.file.string(); - j["type"] = v.type; + nlohmann_json_j["type"] = nlohmann_json_t.type; - j["position_attribute"] = std::visit( + nlohmann_json_j["position_attribute"] = std::visit( [](const auto& attr) -> std::string { using T = std::decay_t; if constexpr (std::is_same_v) { @@ -27,23 +23,23 @@ void adl_serializer::to_json(json& j, c return attr.mesh().get_attribute_name(attr.handle()); } }, - v.position_attribute); + nlohmann_json_t.position_attribute); } -void adl_serializer::from_json(const json& j, Type& v) +WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(OutputOptions) { - if (j.is_string()) { - v.file = j.get(); + if (nlohmann_json_j.is_string()) { + nlohmann_json_t.file = nlohmann_json_j.get(); } else { - v.file = j["file"].get(); + nlohmann_json_t.file = nlohmann_json_j["file"].get(); } - if (j.contains("type")) { - v.type = j["type"]; + if (nlohmann_json_j.contains("type")) { + nlohmann_json_t.type = nlohmann_json_j["type"]; } else { - v.type = v.file.extension().string(); - wmtk::logger().debug("Guessing extension type of [{}] is [{}]", v.file, v.type); + nlohmann_json_t.type = nlohmann_json_t.file.extension().string(); + wmtk::logger().debug("Guessing extension type of [{}] is [{}]", nlohmann_json_t.file, nlohmann_json_t.type); } - if (j.contains("position_attribute")) { - v.position_attribute = j["position_attribute"]; + if (nlohmann_json_j.contains("position_attribute")) { + nlohmann_json_t.position_attribute = nlohmann_json_j["position_attribute"]; } } } // namespace nlohmann diff --git a/components/output/wmtk/components/output/OutputOptions.hpp b/components/output/wmtk/components/output/OutputOptions.hpp index 025e0f1346..4765c05f39 100644 --- a/components/output/wmtk/components/output/OutputOptions.hpp +++ b/components/output/wmtk/components/output/OutputOptions.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace wmtk::components::output { @@ -14,19 +15,14 @@ struct OutputOptions // some formats (?msh?) have a dedicated slot for positions std::variant position_attribute; + std::optional mesh_name_path; // This was intended to be implemenetd easily with default, too lazy to properly implement now without c++20 //bool operator==(const OutputOptions& o) const; + + + WMTK_NLOHMANN_JSON_FRIEND_DECLARATION(OutputOptions) }; } // namespace wmtk::components::output -namespace nlohmann { -template <> -struct adl_serializer -{ - using Type = wmtk::components::output::OutputOptions; - static void to_json(json& j, const Type& v); - static void from_json(const json& j, Type& v); -}; -} // namespace nlohmann diff --git a/components/output/wmtk/components/output/output.cpp b/components/output/wmtk/components/output/output.cpp index dd2131e9b9..365911459b 100644 --- a/components/output/wmtk/components/output/output.cpp +++ b/components/output/wmtk/components/output/output.cpp @@ -8,6 +8,7 @@ #include #include #include "OutputOptions.hpp" +#include namespace wmtk::components::output { @@ -80,4 +81,12 @@ void output( opts.file, opts.type)); } +void output( + const multimesh::NamedMultiMesh& mesh, + const OutputOptions& opts) +{ + output(mesh.root(), opts); + +} + } // namespace wmtk::components diff --git a/components/output/wmtk/components/output/output.hpp b/components/output/wmtk/components/output/output.hpp index 282021a475..c84c8212bc 100644 --- a/components/output/wmtk/components/output/output.hpp +++ b/components/output/wmtk/components/output/output.hpp @@ -6,6 +6,9 @@ namespace wmtk::components { + namespace multimesh { + class NamedMultiMesh; + } namespace output { struct OutputOptions; @@ -63,6 +66,10 @@ void output( const Mesh& mesh, const OutputOptions&); +void output( + const multimesh::NamedMultiMesh& mesh, + const OutputOptions&); + /** * @brief Write the mesh to file. * diff --git a/components/utils/CMakeLists.txt b/components/utils/CMakeLists.txt index 9c069cf98f..6307508d00 100644 --- a/components/utils/CMakeLists.txt +++ b/components/utils/CMakeLists.txt @@ -8,6 +8,7 @@ set(SRC_FILES wmtk/components/utils/resolve_path.cpp wmtk/components/utils/resolve_path.hpp + wmtk/components/utils/json_macros.hpp ) add_library(wmtk_component_utils ${SRC_FILES}) @@ -21,4 +22,4 @@ add_library(wmtk::component_utils ALIAS wmtk_component_utils) file(GLOB_RECURSE COMPONENTS_FILES_FOR_SOURCE_GROUP "${CMAKE_CURRENT_SOURCE_DIR}/wmtk/components/utils/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/wmtk/components/utils/*.hpp") source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/wmtk/components/utils" PREFIX "src" FILES ${COMPONENTS_FILES_FOR_SOURCE_GROUP}) -set_target_properties(wmtk_component_utils PROPERTIES FOLDER wmtk_components) \ No newline at end of file +set_target_properties(wmtk_component_utils PROPERTIES FOLDER wmtk_components) diff --git a/components/utils/wmtk/components/utils/json_macros.hpp b/components/utils/wmtk/components/utils/json_macros.hpp new file mode 100644 index 0000000000..b57ae456a1 --- /dev/null +++ b/components/utils/wmtk/components/utils/json_macros.hpp @@ -0,0 +1,16 @@ +#pragma once +#include + + +// place these in the class for which serialization is desired +#define WMTK_NLOHMANN_JSON_FRIEND_DECLARATION(Type)\ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t);\ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t); + + +// place this to define the prototype of the to_json function +#define WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(Type)\ + void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) +// place this to define the prototype of the from_json function +#define WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(Type)\ + void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) From 293c7b4e8f522b77d4e2127bb5c768a9b7af847a Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 28 Oct 2024 21:02:43 -0400 Subject: [PATCH 03/29] making input/output both support writing json for name data --- .../wmtk/components/input/InputOptions.cpp | 12 ++++-- .../wmtk/components/input/InputOptions.hpp | 1 + .../components/multimesh/NamedMultiMesh.cpp | 38 +++++++++++++++---- .../components/multimesh/NamedMultiMesh.hpp | 2 +- .../wmtk/components/output/OutputOptions.cpp | 24 +++++++++--- .../wmtk/components/output/OutputOptions.hpp | 7 ++-- .../output/wmtk/components/output/output.cpp | 6 +++ .../wmtk/components/utils/json_macros.hpp | 8 ++++ 8 files changed, 77 insertions(+), 21 deletions(-) diff --git a/components/input/src/wmtk/components/input/InputOptions.cpp b/components/input/src/wmtk/components/input/InputOptions.cpp index 2fda00a752..1c7278cf97 100644 --- a/components/input/src/wmtk/components/input/InputOptions.cpp +++ b/components/input/src/wmtk/components/input/InputOptions.cpp @@ -1,5 +1,6 @@ #include "InputOptions.hpp" #include +#include namespace wmtk::components::input { @@ -11,13 +12,16 @@ namespace nlohmann { void adl_serializer::to_json(json& j, const Type& v) { // + j["file"] = v.file; j["file"] = v.file.string(); if (!v.name_spec.is_null()) { + assert(!v.name_spec_file.has_value()); j["name_spec"] = v.name_spec; } if (v.old_mode) { j["old_mode"] = true; - j["ignore_z"] = v.ignore_z_if_zero; + j["ignore_z"] = v.ignore_z_if_zero; // keep around for deprecation purposes + //j["ignore_z_if_zero"] = v.ignore_z_if_zero; if (v.imported_attributes.has_value()) { const auto& imported_attrs = v.imported_attributes.value(); if (imported_attrs.size() > 3) { @@ -33,10 +37,10 @@ void adl_serializer::to_json(json& j, con void adl_serializer::from_json(const json& j, Type& v) { if (j.is_string()) { - v.file = j.get(); + v.file = j.get(); return; } - v.file = j["file"].get(); + v.file = j["file"].get(); if (j.contains("name_spec")) { v.name_spec = j["name_spec"]; } @@ -58,6 +62,8 @@ void adl_serializer::from_json(const json if (v.old_mode) { v.ignore_z_if_zero = j.contains("ignore_z") ? bool(j["ignore_z"]) : false; + // overwrite old ignore_z + //v.ignore_z_if_zero = j.contains("ignore_z_if_zero") ? bool(j["ignore_z_if_zero"]) : false; if (j.contains("tetrahedron_attributes")) { v.imported_attributes = { {}, diff --git a/components/input/src/wmtk/components/input/InputOptions.hpp b/components/input/src/wmtk/components/input/InputOptions.hpp index fc59291995..fc336f659b 100644 --- a/components/input/src/wmtk/components/input/InputOptions.hpp +++ b/components/input/src/wmtk/components/input/InputOptions.hpp @@ -16,6 +16,7 @@ class InputOptions nlohmann::json name_spec; + std::optional name_spec_file; bool old_mode = false; bool ignore_z_if_zero = false; diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index 357a5b4c27..8abeb79d25 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -53,8 +53,19 @@ struct NamedMultiMesh::Node m_child_indexer.emplace(m_children[j]->name, j); } } + friend void to_json( + nlohmann::json& nlohmann_json_j, + const NamedMultiMesh::Node& nlohmann_json_t) + { + nlohmann::json arr = nlohmann::json::array(); + for (const auto& c_ptr : nlohmann_json_t.m_children) { + arr.emplace_back(*c_ptr); + } + nlohmann_json_j["name"] = arr; + } }; + void NamedMultiMesh::set_root(Mesh& m) { m_root = m.shared_from_this(); @@ -74,11 +85,10 @@ Mesh& NamedMultiMesh::get_mesh(const std::string_view& path) const auto NamedMultiMesh::get_id(const std::string_view& path) const -> std::vector { - #if defined(WMTK_ENABLED_CPP20) std::ranges::view auto split = internal::split_path(path); #else - auto split = internal::split_path(path); + auto split = internal::split_path(path); #endif std::vector indices; @@ -136,15 +146,27 @@ std::string NamedMultiMesh::name(const std::vector& id) const NamedMultiMesh::NamedMultiMesh() = default; NamedMultiMesh::~NamedMultiMesh() = default; -//NamedMultiMesh::NamedMultiMesh(NamedMultiMesh&&) = default; -//auto NamedMultiMesh::operator=(NamedMultiMesh&&) -> NamedMultiMesh& = default; -auto NamedMultiMesh::operator=(const NamedMultiMesh& o) -> NamedMultiMesh& { - m_root = o.m_root; - m_name_root=std::make_unique(*o.m_name_root); - return *this; +// NamedMultiMesh::NamedMultiMesh(NamedMultiMesh&&) = default; +// auto NamedMultiMesh::operator=(NamedMultiMesh&&) -> NamedMultiMesh& = default; +auto NamedMultiMesh::operator=(const NamedMultiMesh& o) -> NamedMultiMesh& +{ + m_root = o.m_root; + m_name_root = std::make_unique(*o.m_name_root); + return *this; } NamedMultiMesh::NamedMultiMesh(const NamedMultiMesh& o) : m_root(o.m_root) , m_name_root(std::make_unique(*o.m_name_root)) {} + + +std::unique_ptr NamedMultiMesh::get_names_json() const +{ + auto js_ptr = std::make_unique(); + auto& js = *js_ptr; + js = *m_name_root; + + + return js_ptr; +} } // namespace wmtk::components::multimesh diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp index 130b2ef6f3..1ee3d38b5c 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp @@ -27,7 +27,7 @@ class NamedMultiMesh void set_names(const nlohmann::json& js); void set_root(Mesh& m); - void get_names(nlohmann::json& js); + std::unique_ptr get_names_json() const; std::string_view root_name() const; std::string name(const std::vector& id) const; diff --git a/components/output/wmtk/components/output/OutputOptions.cpp b/components/output/wmtk/components/output/OutputOptions.cpp index 1a81591dc9..a99a676bfc 100644 --- a/components/output/wmtk/components/output/OutputOptions.cpp +++ b/components/output/wmtk/components/output/OutputOptions.cpp @@ -2,6 +2,7 @@ #include "OutputOptions.hpp" #include #include +#include #include @@ -9,10 +10,14 @@ namespace wmtk::components::output { WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(OutputOptions) { + WMTK_NLOHMANN_ASSIGN_TYPE_TO_JSON(file, type) + if (nlohmann_json_t.mesh_name_path.has_value()) { + nlohmann_json_j["mesh_name_path"] = nlohmann_json_t.mesh_name_path.value(); + } // - nlohmann_json_j["file"] = nlohmann_json_t.file.string(); + // nlohmann_json_j["file"] = nlohmann_json_t.file.string(); - nlohmann_json_j["type"] = nlohmann_json_t.type; + // nlohmann_json_j["type"] = nlohmann_json_t.type; nlohmann_json_j["position_attribute"] = std::visit( [](const auto& attr) -> std::string { @@ -28,18 +33,25 @@ WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(OutputOptions) WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(OutputOptions) { if (nlohmann_json_j.is_string()) { - nlohmann_json_t.file = nlohmann_json_j.get(); + nlohmann_json_t.file = nlohmann_json_j.get(); } else { - nlohmann_json_t.file = nlohmann_json_j["file"].get(); + nlohmann_json_t.file = nlohmann_json_j["file"].get(); } if (nlohmann_json_j.contains("type")) { nlohmann_json_t.type = nlohmann_json_j["type"]; } else { nlohmann_json_t.type = nlohmann_json_t.file.extension().string(); - wmtk::logger().debug("Guessing extension type of [{}] is [{}]", nlohmann_json_t.file, nlohmann_json_t.type); + wmtk::logger().debug( + "Guessing extension type of [{}] is [{}]", + nlohmann_json_t.file, + nlohmann_json_t.type); } if (nlohmann_json_j.contains("position_attribute")) { nlohmann_json_t.position_attribute = nlohmann_json_j["position_attribute"]; } + + if (nlohmann_json_j.contains("mesh_name_path")) { + nlohmann_json_t.mesh_name_path = nlohmann_json_j["mesh_name_path"]; + } } -} // namespace nlohmann +} // namespace wmtk::components::output diff --git a/components/output/wmtk/components/output/OutputOptions.hpp b/components/output/wmtk/components/output/OutputOptions.hpp index 4765c05f39..f3b7565af6 100644 --- a/components/output/wmtk/components/output/OutputOptions.hpp +++ b/components/output/wmtk/components/output/OutputOptions.hpp @@ -15,14 +15,15 @@ struct OutputOptions // some formats (?msh?) have a dedicated slot for positions std::variant position_attribute; + // mesh name info will be serialized to a json file if available std::optional mesh_name_path; - // This was intended to be implemenetd easily with default, too lazy to properly implement now without c++20 - //bool operator==(const OutputOptions& o) const; + // This was intended to be implemenetd easily with default, too lazy to properly implement now + // without c++20 + // bool operator==(const OutputOptions& o) const; WMTK_NLOHMANN_JSON_FRIEND_DECLARATION(OutputOptions) }; } // namespace wmtk::components::output - diff --git a/components/output/wmtk/components/output/output.cpp b/components/output/wmtk/components/output/output.cpp index 365911459b..511d84b5a4 100644 --- a/components/output/wmtk/components/output/output.cpp +++ b/components/output/wmtk/components/output/output.cpp @@ -87,6 +87,12 @@ void output( { output(mesh.root(), opts); + if(opts.mesh_name_path.has_value()) { + const auto& path = opts.mesh_name_path.value(); + std::ofstream ofs(path); + ofs<< *mesh.get_names_json(); + } + } } // namespace wmtk::components diff --git a/components/utils/wmtk/components/utils/json_macros.hpp b/components/utils/wmtk/components/utils/json_macros.hpp index b57ae456a1..45725f786a 100644 --- a/components/utils/wmtk/components/utils/json_macros.hpp +++ b/components/utils/wmtk/components/utils/json_macros.hpp @@ -14,3 +14,11 @@ // place this to define the prototype of the from_json function #define WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(Type)\ void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) + +#define WMTK_NLOHMANN_ASSIGN_TYPE_TO_JSON(...) \ + { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } + +#define WMTK_NLOHMANN_ASSIGN_TYPE_FROM_JSON(...) \ + { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + + From 5efcc0c54cf2bd4343b6fcd669c330d13510aff8 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 11:33:00 -0400 Subject: [PATCH 04/29] Updating input slightly --- .../input/src/wmtk/components/input/InputOptions.cpp | 6 ++++++ .../input/src/wmtk/components/input/InputOptions.hpp | 1 + components/input/src/wmtk/components/input/input.cpp | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/components/input/src/wmtk/components/input/InputOptions.cpp b/components/input/src/wmtk/components/input/InputOptions.cpp index 1c7278cf97..f1b515db37 100644 --- a/components/input/src/wmtk/components/input/InputOptions.cpp +++ b/components/input/src/wmtk/components/input/InputOptions.cpp @@ -17,6 +17,9 @@ void adl_serializer::to_json(json& j, con if (!v.name_spec.is_null()) { assert(!v.name_spec_file.has_value()); j["name_spec"] = v.name_spec; + } else if(v.name_spec_file.has_value()) { + j["name_spec_file"] = v.name_spec_file.value(); + } if (v.old_mode) { j["old_mode"] = true; @@ -44,6 +47,9 @@ void adl_serializer::from_json(const json if (j.contains("name_spec")) { v.name_spec = j["name_spec"]; } + if (j.contains("name_spec_file")) { + v.name_spec_file = j["name_spec_file"]; + } v.old_mode = false; if (j.contains("old_mode")) { diff --git a/components/input/src/wmtk/components/input/InputOptions.hpp b/components/input/src/wmtk/components/input/InputOptions.hpp index fc336f659b..8a6c339236 100644 --- a/components/input/src/wmtk/components/input/InputOptions.hpp +++ b/components/input/src/wmtk/components/input/InputOptions.hpp @@ -15,6 +15,7 @@ class InputOptions std::optional>> imported_attributes; + // either you can have a name spec in json or you can have it in a file nlohmann::json name_spec; std::optional name_spec_file; diff --git a/components/input/src/wmtk/components/input/input.cpp b/components/input/src/wmtk/components/input/input.cpp index 52610aedb7..87ca64edc0 100644 --- a/components/input/src/wmtk/components/input/input.cpp +++ b/components/input/src/wmtk/components/input/input.cpp @@ -4,6 +4,7 @@ #include #include #include "InputOptions.hpp" +#include namespace wmtk::components::input { @@ -51,7 +52,14 @@ multimesh::NamedMultiMesh input(const InputOptions& options) multimesh::NamedMultiMesh mm; mm.set_mesh(*mesh); + if(!options.name_spec.is_null()) { mm.set_names(options.name_spec); + } else if(options.name_spec_file.has_value()) { + std::ifstream ifs(options.name_spec_file.value()); + nlohmann::json js; + ifs >> js; + mm.set_names(js); + } return mm; } From 1e68032df13d9d2e94a479719344d329b413c48b Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 12:06:12 -0400 Subject: [PATCH 05/29] fixing keys when htere are multiple meshes --- .../wmtk/components/multimesh/MeshCollection.cpp | 15 ++++++++------- .../wmtk/components/multimesh/MeshCollection.hpp | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index 13d5499885..045613c83c 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -3,15 +3,16 @@ #include "internal/split_path.hpp" #include -#include "multimesh.hpp" namespace wmtk::components::multimesh { NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) { - auto [it, did] = m_meshes.emplace(m.root_name(), std::move(m)); - return it->second; + auto mptr = std::make_unique(std::move(m)); + auto [it, did] = m_meshes.emplace(mptr->root_name(), std::move(mptr)); + + return *it->second; } //NamedMultiMesh& MeshCollection::add_mesh(const InputOptions& opts) @@ -26,9 +27,9 @@ const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view const auto nmm_name = *internal::split_path(path).begin(); if(nmm_name.empty() && m_meshes.size() == 1) { wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so assuming that is the right mesh"); - return m_meshes.begin()->second; + return *m_meshes.begin()->second; } - return m_meshes.at(nmm_name); + return *m_meshes.at(nmm_name); } const Mesh& MeshCollection::get_mesh(const std::string_view& path) const { @@ -45,8 +46,8 @@ NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path const std::string_view nmm_name = *internal::split_path(path).begin(); if(nmm_name.empty() && m_meshes.size() == 1) { wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so assuming that is the right mesh"); - return m_meshes.begin()->second; + return *m_meshes.begin()->second; } - return m_meshes.at(nmm_name); + return *m_meshes.at(nmm_name); } } // namespace wmtk::components::multimesh diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp index cd1b59dbcf..b4a5ae9ba7 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp @@ -1,6 +1,7 @@ #pragma once #include #include "NamedMultiMesh.hpp" +#include namespace wmtk::components::multimesh { @@ -20,6 +21,6 @@ class MeshCollection private: - std::map m_meshes; + std::map> m_meshes; }; } // namespace wmtk::components::multimesh From 39e3c815b439141bbce7990705c76c5c6de4805f Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 12:06:21 -0400 Subject: [PATCH 06/29] adding convert app --- applications/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt index 4155541590..0bfac16430 100644 --- a/applications/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -32,6 +32,7 @@ add_application(triwild ON) add_application(cdt_sec ON) add_application(shortest_edge_collapse ON) add_application(insertion ON) +add_application(convert ON) From 645032721de0d55d919016f72c9065c8ed9bbc13 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 12:06:58 -0400 Subject: [PATCH 07/29] adding basic convert app --- applications/convert/CMakeLists.txt | 23 ++++ applications/convert/main.cpp | 151 ++++++++++++++++++++++++++ applications/convert/test_config.json | 7 ++ 3 files changed, 181 insertions(+) create mode 100644 applications/convert/CMakeLists.txt create mode 100644 applications/convert/main.cpp create mode 100644 applications/convert/test_config.json diff --git a/applications/convert/CMakeLists.txt b/applications/convert/CMakeLists.txt new file mode 100644 index 0000000000..f3ca185da9 --- /dev/null +++ b/applications/convert/CMakeLists.txt @@ -0,0 +1,23 @@ +include(wmtk_add_application) +include(wmtk_register_jse_json) +wmtk_add_application(convert_app + main.cpp + ) + +target_compile_features(convert_app PUBLIC cxx_std_20) + #register_jse_json(APPLICATION_NAME convert INPUT convert_spec.json ) + +# convert requires the output component and the convert component +target_link_libraries(convert_app PRIVATE +wmtk::input +wmtk::output +wmtk::multimesh +wmtk::application_utils +) + +wmtk_register_integration_test( + EXEC_NAME convert_app + CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_config.json + CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/examples + EXTRA_ARGUMENTS run +) diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp new file mode 100644 index 0000000000..a77338e0a4 --- /dev/null +++ b/applications/convert/main.cpp @@ -0,0 +1,151 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include "CLI/CLI.hpp" +#include "wmtk/components/multimesh/MeshCollection.hpp" +#include "wmtk/components/multimesh/from_boundary.hpp" +#include "wmtk/components/multimesh/from_facet_bijection.hpp" + +using namespace wmtk::components; +using namespace wmtk::applications; +using namespace wmtk; +namespace fs = std::filesystem; + +namespace { +void merge_meshes(wmtk::components::multimesh::MeshCollection& mc, const nlohmann::json& js) +{ + for (const auto& [parent, child_datas] : js.items()) { + auto& parent_mesh = mc.get_mesh(parent); + if (child_datas.is_string()) { + auto& child_mesh = mc.get_mesh(child_datas.get()); + components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + + } else if (child_datas.is_object()) { + const std::string type = child_datas["type"]; + + if (type == "facet_bijection") { + const std::string child_name = child_datas["name"]; + auto& child_mesh = mc.get_mesh(child_name); + components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + + } else if (type == "boundary") { + const int64_t dimension = child_datas["dimension"]; + std::string boundary_attr_name = fmt::format("boundary_{}", dimension); + if (child_datas.contains("boundary_attribute_name")) { + boundary_attr_name = child_datas["boundary_attribute_name"]; + } + components::multimesh::from_boundary( + parent_mesh, + wmtk::get_primitive_type_from_id(dimension), + boundary_attr_name); + } + } + } +} +} // namespace + +int run(const fs::path& config_path /*, const std::optional& name_spec_file*/) +{ + nlohmann::json j; + { + std::ifstream ifs(config_path); + j = nlohmann::json::parse(ifs); + // if (name_spec_file.has_value()) { + // j["name"] = nlohmann::json::parse(std::ifstream(name_spec_file.value())); + // } + } + + wmtk::components::multimesh::MeshCollection meshes; + if (j["input"].is_array()) { + for (const auto& in_opts_js : j["input"]) { + wmtk::components::input::InputOptions opts = in_opts_js; + meshes.add_mesh(wmtk::components::input::input(opts)); + } + merge_meshes(meshes, j["tree"]); + + } else { + wmtk::components::input::InputOptions opts = j["input"]; + meshes.add_mesh(wmtk::components::input::input(opts)); + } + + + if (!j.contains("output")) { + wmtk::logger().info("convert: No output path provided"); + } else { + } + + + // if (j.contains("report")) { + // const std::string report = j["report"]; + // if (!report.empty()) { + // nlohmann::json out_json; + // out_json.update(wmtk::applications::utils::element_count_report_named(*mesh)); + // j.erase("report"); + // out_json["input"] = j; + + + // std::ofstream ofs(report); + // ofs << out_json; + // } + //} + return 0; +} + + +int main(int argc, char* argv[]) +{ + CLI::App app{argv[0]}; + + app.ignore_case(); + + fs::path json_input_file; + std::optional name_spec_file; + + CLI::App* run_cmd; // = app.add_subcommand("run", "Run application"); + run_cmd = &app; + run_cmd->add_option("-j, --json", json_input_file, "json specification file") + ->required(true) + ->check(CLI::ExistingFile); + + // run_cmd->add_option("-n, --name_spec", name_spec_file, "json specification file") + // ->check(CLI::ExistingFile); + + CLI11_PARSE(app, argc, argv); + + // someday may add other suboptions + assert(run_cmd->parsed()); + + // if (!json_input_file.has_value() && !fill_config_path.has_value()) { + // wmtk::logger().error("An input json file with [-j] is required unless blank config " + // "generation is being used with [--fill-config]"); + // return 1; + // } + + int exit_mode = -1; + + // run_cmd->callback([&]() { + // spdlog::warn("YOW!"); + // assert(json_input_file.has_value()); + // exit_mode = run(json_input_file.value()); + // }); + exit_mode = run(json_input_file /*, name_spec_file*/); + + + assert(exit_mode != -1); // "Some subcommand should have updated the exit mode" + return exit_mode; +} diff --git a/applications/convert/test_config.json b/applications/convert/test_config.json new file mode 100644 index 0000000000..00d824156b --- /dev/null +++ b/applications/convert/test_config.json @@ -0,0 +1,7 @@ +{ + "tests": [ + ], + "input_tag": "input", + "oracle_tag": "report", + "input_directory_tag": "root" +} From cce6badaa867378e7f9aaa3a9638c385e437dad8 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 12:12:34 -0400 Subject: [PATCH 08/29] making convert output meshes potentially --- applications/convert/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp index a77338e0a4..b7dcbdf9c9 100644 --- a/applications/convert/main.cpp +++ b/applications/convert/main.cpp @@ -27,13 +27,16 @@ using namespace wmtk; namespace fs = std::filesystem; namespace { -void merge_meshes(wmtk::components::multimesh::MeshCollection& mc, const nlohmann::json& js) +std::shared_ptr merge_meshes( + wmtk::components::multimesh::MeshCollection& mc, + const nlohmann::json& js) { for (const auto& [parent, child_datas] : js.items()) { auto& parent_mesh = mc.get_mesh(parent); if (child_datas.is_string()) { auto& child_mesh = mc.get_mesh(child_datas.get()); components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + return parent_mesh.shared_from_this(); } else if (child_datas.is_object()) { const std::string type = child_datas["type"]; @@ -42,6 +45,7 @@ void merge_meshes(wmtk::components::multimesh::MeshCollection& mc, const nlohman const std::string child_name = child_datas["name"]; auto& child_mesh = mc.get_mesh(child_name); components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + return parent_mesh.shared_from_this(); } else if (type == "boundary") { const int64_t dimension = child_datas["dimension"]; @@ -53,9 +57,11 @@ void merge_meshes(wmtk::components::multimesh::MeshCollection& mc, const nlohman parent_mesh, wmtk::get_primitive_type_from_id(dimension), boundary_attr_name); + return parent_mesh.shared_from_this(); } } } + return nullptr; } } // namespace @@ -71,22 +77,27 @@ int run(const fs::path& config_path /*, const std::optional& name_spec } wmtk::components::multimesh::MeshCollection meshes; + std::shared_ptr output_mesh; if (j["input"].is_array()) { for (const auto& in_opts_js : j["input"]) { wmtk::components::input::InputOptions opts = in_opts_js; meshes.add_mesh(wmtk::components::input::input(opts)); } - merge_meshes(meshes, j["tree"]); + output_mesh = merge_meshes(meshes, j["tree"]); } else { wmtk::components::input::InputOptions opts = j["input"]; - meshes.add_mesh(wmtk::components::input::input(opts)); + output_mesh = + meshes.add_mesh(wmtk::components::input::input(opts)).root().shared_from_this(); } if (!j.contains("output")) { wmtk::logger().info("convert: No output path provided"); } else { + auto opts = j["output"].get(); + + wmtk::components::output::output(*output_mesh, opts); } From 8751e61b2d7696bc39c222cdcc35c006266f360b Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 29 Oct 2024 12:46:15 -0400 Subject: [PATCH 09/29] adding example usage of convert app --- .../convert/examples/make_boundary.json | 22 ++++++++++++++++++ applications/convert/examples/merge_uv.json | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 applications/convert/examples/make_boundary.json create mode 100644 applications/convert/examples/merge_uv.json diff --git a/applications/convert/examples/make_boundary.json b/applications/convert/examples/make_boundary.json new file mode 100644 index 0000000000..e81488d812 --- /dev/null +++ b/applications/convert/examples/make_boundary.json @@ -0,0 +1,22 @@ +{ + "input": [ + { + "file": "_pos.msh", + "name_spec": "position" + } + ], + "tree": { + "position": { + "type": "boundary", + "dimension": 1 + } + + }, + + "output": { + "file": "ogre_boundary.hdf5", + "type": ".hdf5" + } + + +} diff --git a/applications/convert/examples/merge_uv.json b/applications/convert/examples/merge_uv.json new file mode 100644 index 0000000000..30627f7585 --- /dev/null +++ b/applications/convert/examples/merge_uv.json @@ -0,0 +1,23 @@ +{ + "input": [ + { + "file": "_pos.msh", + "name_spec": "position" + }, + { + "file": "_tex.msh", + "name_spec": "uv" + } + ], + "tree": { + "position": "uv" + + }, + + "output": { + "file": "ogre.hdf5", + "type": ".hdf5" + } + + +} From 2a09c8df518d45d5908f975c60760b06ad1c5b0e Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Wed, 30 Oct 2024 11:04:02 -0400 Subject: [PATCH 10/29] updating convert to support output better --- applications/convert/examples/split_uv.json | 19 +++++++++++++++++++ applications/convert/main.cpp | 12 +++++++++--- .../input/src/wmtk/components/input/input.cpp | 8 ++++---- .../components/multimesh/NamedMultiMesh.cpp | 4 ++-- 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 applications/convert/examples/split_uv.json diff --git a/applications/convert/examples/split_uv.json b/applications/convert/examples/split_uv.json new file mode 100644 index 0000000000..b07f00a404 --- /dev/null +++ b/applications/convert/examples/split_uv.json @@ -0,0 +1,19 @@ +{ + "input": { + "file": "ogre.hdf5", + "name_spec": + { + "position": "uv" + } + }, + "output": { + "position": { + "file": "ogre_pos.vtu", + "position_attribute": "vertices" + }, + "position.uv": { + "file": "ogre_uv.vtu", + "position_attribute": "vertices" + } + } +} diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp index b7dcbdf9c9..2848330c9d 100644 --- a/applications/convert/main.cpp +++ b/applications/convert/main.cpp @@ -83,20 +83,26 @@ int run(const fs::path& config_path /*, const std::optional& name_spec wmtk::components::input::InputOptions opts = in_opts_js; meshes.add_mesh(wmtk::components::input::input(opts)); } - output_mesh = merge_meshes(meshes, j["tree"]); - } else { wmtk::components::input::InputOptions opts = j["input"]; output_mesh = meshes.add_mesh(wmtk::components::input::input(opts)).root().shared_from_this(); } + if (j.contains("tree")) { + output_mesh = merge_meshes(meshes, j["tree"]); + } if (!j.contains("output")) { wmtk::logger().info("convert: No output path provided"); + } else if (j["output"].is_object()) { + for (const auto& [mesh_path, out_opts_js] : j["output"].items()) { + auto opts = out_opts_js.get(); + + wmtk::components::output::output(meshes.get_mesh(mesh_path), opts); + } } else { auto opts = j["output"].get(); - wmtk::components::output::output(*output_mesh, opts); } diff --git a/components/input/src/wmtk/components/input/input.cpp b/components/input/src/wmtk/components/input/input.cpp index 87ca64edc0..bd5d08577d 100644 --- a/components/input/src/wmtk/components/input/input.cpp +++ b/components/input/src/wmtk/components/input/input.cpp @@ -1,10 +1,10 @@ #include "input.hpp" +#include #include #include #include #include "InputOptions.hpp" -#include namespace wmtk::components::input { @@ -52,9 +52,9 @@ multimesh::NamedMultiMesh input(const InputOptions& options) multimesh::NamedMultiMesh mm; mm.set_mesh(*mesh); - if(!options.name_spec.is_null()) { - mm.set_names(options.name_spec); - } else if(options.name_spec_file.has_value()) { + if (!options.name_spec.is_null()) { + mm.set_names(options.name_spec); + } else if (options.name_spec_file.has_value()) { std::ifstream ifs(options.name_spec_file.value()); nlohmann::json js; ifs >> js; diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index 8abeb79d25..8a206f0ab0 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -61,7 +61,7 @@ struct NamedMultiMesh::Node for (const auto& c_ptr : nlohmann_json_t.m_children) { arr.emplace_back(*c_ptr); } - nlohmann_json_j["name"] = arr; + nlohmann_json_j[nlohmann_json_t.name] = arr; } }; @@ -144,7 +144,7 @@ std::string NamedMultiMesh::name(const std::vector& id) const return fmt::format("{}", fmt::join(names, ".")); } -NamedMultiMesh::NamedMultiMesh() = default; +NamedMultiMesh::NamedMultiMesh(): m_name_root(std::make_unique()) {} NamedMultiMesh::~NamedMultiMesh() = default; // NamedMultiMesh::NamedMultiMesh(NamedMultiMesh&&) = default; // auto NamedMultiMesh::operator=(NamedMultiMesh&&) -> NamedMultiMesh& = default; From c78b88fddd37cabed7da22d84c441e1dfd247ac8 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sun, 3 Nov 2024 08:05:52 -0500 Subject: [PATCH 11/29] being more explicit when fetching std::optional from json in input component --- components/input/src/wmtk/components/input/InputOptions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/input/src/wmtk/components/input/InputOptions.cpp b/components/input/src/wmtk/components/input/InputOptions.cpp index f1b515db37..ec2e166231 100644 --- a/components/input/src/wmtk/components/input/InputOptions.cpp +++ b/components/input/src/wmtk/components/input/InputOptions.cpp @@ -48,7 +48,7 @@ void adl_serializer::from_json(const json v.name_spec = j["name_spec"]; } if (j.contains("name_spec_file")) { - v.name_spec_file = j["name_spec_file"]; + v.name_spec_file = j["name_spec_file"].get(); } v.old_mode = false; From 03ccb0e21fd5e528d698a8f0e8cbe10a87743e45 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sun, 3 Nov 2024 08:59:14 -0500 Subject: [PATCH 12/29] adding a data dir for convert --- applications/convert/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/convert/CMakeLists.txt b/applications/convert/CMakeLists.txt index f3ca185da9..712d4533f7 100644 --- a/applications/convert/CMakeLists.txt +++ b/applications/convert/CMakeLists.txt @@ -19,5 +19,7 @@ wmtk_register_integration_test( EXEC_NAME convert_app CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_config.json CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/examples + GIT_REPOSITORY "https://github.com/wildmeshing/data.git" + GIT_TAG 152a561697a6e923451ca8535309cbe1e116a9fa EXTRA_ARGUMENTS run ) From ea83f615a27f07485b0324b5dfcfcba9f874f60c Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sun, 3 Nov 2024 09:35:21 -0500 Subject: [PATCH 13/29] update on output component for windows std::optional to json --- components/output/wmtk/components/output/OutputOptions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/output/wmtk/components/output/OutputOptions.cpp b/components/output/wmtk/components/output/OutputOptions.cpp index a99a676bfc..05507e6501 100644 --- a/components/output/wmtk/components/output/OutputOptions.cpp +++ b/components/output/wmtk/components/output/OutputOptions.cpp @@ -51,7 +51,7 @@ WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(OutputOptions) } if (nlohmann_json_j.contains("mesh_name_path")) { - nlohmann_json_t.mesh_name_path = nlohmann_json_j["mesh_name_path"]; + nlohmann_json_t.mesh_name_path = nlohmann_json_j["mesh_name_path"].get(); } } } // namespace wmtk::components::output From 4be06a532b782b7efdae35344523165ee1f1ec46 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Tue, 5 Nov 2024 11:57:25 -0500 Subject: [PATCH 14/29] updating named mesh tooling for getting all meshes --- .../components/multimesh/MeshCollection.hpp | 1 + .../components/multimesh/NamedMultiMesh.cpp | 31 ++++++++++++++++++- .../components/multimesh/NamedMultiMesh.hpp | 12 +++++-- src/wmtk/Mesh.hpp | 5 +++ src/wmtk/Mesh_multimesh.cpp | 19 ++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp index b4a5ae9ba7..4d282fddb7 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp @@ -19,6 +19,7 @@ class MeshCollection Mesh& get_mesh(const std::string_view& path); + std::map> all_meshes() const; private: std::map> m_meshes; diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index 8a206f0ab0..705c3e5ee7 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -1,6 +1,7 @@ #include "NamedMultiMesh.hpp" #include #include +#include #include #include #include "internal/split_path.hpp" @@ -46,6 +47,16 @@ struct NamedMultiMesh::Node update_child_names(); } + void get_name_tokens(const std::span& t, std::vector& toks) const + { + toks.emplace_back(name); + if (!t.empty()) { + const auto& child = *m_children[t.front()]; + child.get_name_tokens(t.subspan<1>(), toks); + } + } + + void update_child_names() { m_child_indexer.clear(); @@ -144,7 +155,9 @@ std::string NamedMultiMesh::name(const std::vector& id) const return fmt::format("{}", fmt::join(names, ".")); } -NamedMultiMesh::NamedMultiMesh(): m_name_root(std::make_unique()) {} +NamedMultiMesh::NamedMultiMesh() + : m_name_root(std::make_unique()) +{} NamedMultiMesh::~NamedMultiMesh() = default; // NamedMultiMesh::NamedMultiMesh(NamedMultiMesh&&) = default; // auto NamedMultiMesh::operator=(NamedMultiMesh&&) -> NamedMultiMesh& = default; @@ -169,4 +182,20 @@ std::unique_ptr NamedMultiMesh::get_names_json() const return js_ptr; } + +std::map> NamedMultiMesh::all_meshes() const +{ + std::map> meshes; + for (const auto& mptr : m_root->get_all_meshes()) { + meshes.emplace(get_name(*mptr), mptr); + } + return meshes; +} +std::string NamedMultiMesh::get_name(const Mesh& m) const +{ + std::vector toks; + auto id = m.absolute_multi_mesh_id(); + m_name_root->get_name_tokens(id, toks); + return fmt::format("{}", fmt::join(toks, ".")); +} } // namespace wmtk::components::multimesh diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp index 1ee3d38b5c..a387cbf193 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp @@ -17,11 +17,11 @@ class NamedMultiMesh { public: NamedMultiMesh(); - //NamedMultiMesh(NamedMultiMesh&&); + // NamedMultiMesh(NamedMultiMesh&&); NamedMultiMesh(const NamedMultiMesh&); ~NamedMultiMesh(); - // auto operator=(NamedMultiMesh&&) -> NamedMultiMesh&; - auto operator=(const NamedMultiMesh&) -> NamedMultiMesh&; + // auto operator=(NamedMultiMesh&&) -> NamedMultiMesh&; + auto operator=(const NamedMultiMesh&) -> NamedMultiMesh&; void set_name(const std::string_view& root_name = ""); void set_names(const nlohmann::json& js); @@ -40,6 +40,12 @@ class NamedMultiMesh Mesh& root() { return *m_root; } const Mesh& root() const { return *m_root; } + + std::map> all_meshes() const; + + // returns the name of a mesh if it lies in this multimesh + std::string get_name(const Mesh& m) const; + private: struct Node; std::shared_ptr m_root; diff --git a/src/wmtk/Mesh.hpp b/src/wmtk/Mesh.hpp index a7ddb8aab3..924b8fa057 100644 --- a/src/wmtk/Mesh.hpp +++ b/src/wmtk/Mesh.hpp @@ -497,6 +497,11 @@ class Mesh : public std::enable_shared_from_this, public wmtk::utils::Merk */ std::vector> get_all_child_meshes() const; + /** + * @brief returns all meshes in multimesh + */ + std::vector> get_all_meshes() const; + /** * @brief returns a unique identifier for this mesh within a single multimesh structure diff --git a/src/wmtk/Mesh_multimesh.cpp b/src/wmtk/Mesh_multimesh.cpp index 27233f6241..0435a7a39f 100644 --- a/src/wmtk/Mesh_multimesh.cpp +++ b/src/wmtk/Mesh_multimesh.cpp @@ -1,4 +1,5 @@ #include "Mesh.hpp" +#include #include #include @@ -237,4 +238,22 @@ std::vector> Mesh::get_all_child_meshes() const } return children; } + +std::vector> Mesh::get_all_meshes() const +{ + std::vector> meshes; + std::queue> queue; + //std::queue queue; + meshes.emplace_back(this); + while(!queue.empty()) { + const auto& cur = queue.front(); + //Mesh const* cur = queue.front(); + queue.pop(); + meshes.emplace_back(cur->shared_from_this()); + for(const auto& m: cur->get_child_meshes()) { + queue.emplace(m.get()); + } + } + return meshes; +} } // namespace wmtk From 5fc0f1961724947f7814e9c70f667557dfff83a9 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Wed, 6 Nov 2024 12:55:32 -0500 Subject: [PATCH 15/29] updates --- applications/convert/CMakeLists.txt | 2 +- applications/convert/examples/raw/camel.json | 20 ++++++++++++ .../convert/examples/raw/make_boundary.json | 22 +++++++++++++ .../convert/examples/raw/merge_uv.json | 23 ++++++++++++++ .../convert/examples/raw/split_uv.json | 19 ++++++++++++ applications/convert/main.cpp | 27 +++++++++------- applications/integration_test.py | 17 ++++++++-- .../components/multimesh/MeshCollection.cpp | 31 +++++++++++++------ 8 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 applications/convert/examples/raw/camel.json create mode 100644 applications/convert/examples/raw/make_boundary.json create mode 100644 applications/convert/examples/raw/merge_uv.json create mode 100644 applications/convert/examples/raw/split_uv.json diff --git a/applications/convert/CMakeLists.txt b/applications/convert/CMakeLists.txt index 712d4533f7..5dc7a37141 100644 --- a/applications/convert/CMakeLists.txt +++ b/applications/convert/CMakeLists.txt @@ -21,5 +21,5 @@ wmtk_register_integration_test( CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/examples GIT_REPOSITORY "https://github.com/wildmeshing/data.git" GIT_TAG 152a561697a6e923451ca8535309cbe1e116a9fa - EXTRA_ARGUMENTS run + #EXTRA_ARGUMENTS run ) diff --git a/applications/convert/examples/raw/camel.json b/applications/convert/examples/raw/camel.json new file mode 100644 index 0000000000..430a7e42ca --- /dev/null +++ b/applications/convert/examples/raw/camel.json @@ -0,0 +1,20 @@ +{ + "input": [ + { + "file": "unit_test/meshes/camel.msh", + "name_spec": "position" + }, + { + "file": "unit_test/meshes/cameluv.msh", + "name_spec": "uv" + } + ], + "tree": { + "position": "uv" + }, + "output": { + "file": "camel.hdf5", + "type": ".hdf5" + } + +} diff --git a/applications/convert/examples/raw/make_boundary.json b/applications/convert/examples/raw/make_boundary.json new file mode 100644 index 0000000000..e81488d812 --- /dev/null +++ b/applications/convert/examples/raw/make_boundary.json @@ -0,0 +1,22 @@ +{ + "input": [ + { + "file": "_pos.msh", + "name_spec": "position" + } + ], + "tree": { + "position": { + "type": "boundary", + "dimension": 1 + } + + }, + + "output": { + "file": "ogre_boundary.hdf5", + "type": ".hdf5" + } + + +} diff --git a/applications/convert/examples/raw/merge_uv.json b/applications/convert/examples/raw/merge_uv.json new file mode 100644 index 0000000000..30627f7585 --- /dev/null +++ b/applications/convert/examples/raw/merge_uv.json @@ -0,0 +1,23 @@ +{ + "input": [ + { + "file": "_pos.msh", + "name_spec": "position" + }, + { + "file": "_tex.msh", + "name_spec": "uv" + } + ], + "tree": { + "position": "uv" + + }, + + "output": { + "file": "ogre.hdf5", + "type": ".hdf5" + } + + +} diff --git a/applications/convert/examples/raw/split_uv.json b/applications/convert/examples/raw/split_uv.json new file mode 100644 index 0000000000..b07f00a404 --- /dev/null +++ b/applications/convert/examples/raw/split_uv.json @@ -0,0 +1,19 @@ +{ + "input": { + "file": "ogre.hdf5", + "name_spec": + { + "position": "uv" + } + }, + "output": { + "position": { + "file": "ogre_pos.vtu", + "position_attribute": "vertices" + }, + "position.uv": { + "file": "ogre_uv.vtu", + "position_attribute": "vertices" + } + } +} diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp index 2848330c9d..6b66b09971 100644 --- a/applications/convert/main.cpp +++ b/applications/convert/main.cpp @@ -76,6 +76,8 @@ int run(const fs::path& config_path /*, const std::optional& name_spec // } } + spdlog::warn("{}", j.dump(2)); + wmtk::components::multimesh::MeshCollection meshes; std::shared_ptr output_mesh; if (j["input"].is_array()) { @@ -107,19 +109,22 @@ int run(const fs::path& config_path /*, const std::optional& name_spec } - // if (j.contains("report")) { - // const std::string report = j["report"]; - // if (!report.empty()) { - // nlohmann::json out_json; - // out_json.update(wmtk::applications::utils::element_count_report_named(*mesh)); - // j.erase("report"); - // out_json["input"] = j; + if (j.contains("report")) { + const std::string report = j["report"]; + if (!report.empty()) { + nlohmann::json out_json; + auto& stats = out_json["stats"]; + for(const auto& [name, meshptr]: meshes.all_meshes()) { + stats[name] = wmtk::applications::utils::element_count_report_named(*meshptr); + } + j.erase("report"); + out_json["input"] = j; - // std::ofstream ofs(report); - // ofs << out_json; - // } - //} + std::ofstream ofs(report); + ofs << out_json; + } + } return 0; } diff --git a/applications/integration_test.py b/applications/integration_test.py index f54382cc05..2ec64e924a 100644 --- a/applications/integration_test.py +++ b/applications/integration_test.py @@ -28,6 +28,10 @@ def __init__(self, name, test_config, configs_to_run = None, run_all = False): self.run_all = run_all self.data_folder = None if "data_folder" not in test_config else test_config["data_folder"] + if self.data_folder is None: + self.data_folder = None if "input_directory_tag" not in test_config else test_config["input_directory_tag"] + print(f"Data folder {self.data_folder}") + self.config_folder = self.data_folder if "config_folder" not in test_config else test_config["config_folder"] msg = 'all (slow and fast)' if self.run_all else 'fast' print(f'Loading integration test [{name}] in {self.working_dir}, running {msg} tests', flush=True) @@ -44,6 +48,14 @@ def __init__(self, name, test_config, configs_to_run = None, run_all = False): if "test_directory" in config: self.config_folder = os.path.join(self.config_folder, config["test_directory"]) + if "test_data_directory" not in config: + # some applications assume taht these follow together + self.data_folder = os.path.join(self.data_folder, config["test_directory"]) + if "test_data_directory" in config: + self.data_folder = os.path.join(self.data_folder, config["test_directory"]) + + print(f"Data folder {self.data_folder}") + self.executable = os.path.abspath(os.path.join(IntegrationTest.BINARY_FOLDER, self.name)) @@ -119,9 +131,10 @@ def run_one(self, test_file): if root_tag in input_js: if not os.path.isabs(input_js[root_tag]): - input_js[root_tag] = os.path.join(self.config_folder, input_js[root_tag]) + + input_js[root_tag] = os.path.join(self.data_folder, input_js[root_tag]) else: - input_js[root_tag] = self.config_folder + input_js[root_tag] = self.data_folder with tempfile.NamedTemporaryFile(mode='w', delete=False) as input_json: json.dump(input_js, input_json) diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index 045613c83c..a8deee078b 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -1,7 +1,7 @@ #include "MeshCollection.hpp" -#include "internal/split_path.hpp" #include +#include "internal/split_path.hpp" namespace wmtk::components::multimesh { @@ -15,18 +15,19 @@ NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) return *it->second; } -//NamedMultiMesh& MeshCollection::add_mesh(const InputOptions& opts) +// NamedMultiMesh& MeshCollection::add_mesh(const InputOptions& opts) //{ -// return add_mesh(multimesh(opts)); -//} +// return add_mesh(multimesh(opts)); +// } const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) const { using namespace std; const auto nmm_name = *internal::split_path(path).begin(); - if(nmm_name.empty() && m_meshes.size() == 1) { - wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so assuming that is the right mesh"); + if (nmm_name.empty() && m_meshes.size() == 1) { + wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " + "assuming that is the right mesh"); return *m_meshes.begin()->second; } return *m_meshes.at(nmm_name); @@ -36,18 +37,28 @@ const Mesh& MeshCollection::get_mesh(const std::string_view& path) const return get_named_multimesh(path).get_mesh(path); } -Mesh& MeshCollection::get_mesh(const std::string_view& path) +Mesh& MeshCollection::get_mesh(const std::string_view& path) { return get_named_multimesh(path).get_mesh(path); } -NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) +NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) { using namespace std; const std::string_view nmm_name = *internal::split_path(path).begin(); - if(nmm_name.empty() && m_meshes.size() == 1) { - wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so assuming that is the right mesh"); + if (nmm_name.empty() && m_meshes.size() == 1) { + wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " + "assuming that is the right mesh"); return *m_meshes.begin()->second; } return *m_meshes.at(nmm_name); } +std::map> MeshCollection::all_meshes() const +{ + std::map> meshes; + for (const auto& [name, nnptr] : m_meshes) { + const auto pr = nnptr->all_meshes(); + meshes.insert(pr.begin(), pr.end()); + } + return meshes; +} } // namespace wmtk::components::multimesh From 74d6ea345d0fdd99669e5e1a0429a3f46504b257 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 8 Nov 2024 11:39:03 -0500 Subject: [PATCH 16/29] Adding a path resolver class to encapsulate path stuff from json --- components/utils/CMakeLists.txt | 3 + .../wmtk/components/utils/PathResolver.cpp | 102 ++++++++++++++++++ .../wmtk/components/utils/PathResolver.hpp | 41 +++++++ 3 files changed, 146 insertions(+) create mode 100644 components/utils/wmtk/components/utils/PathResolver.cpp create mode 100644 components/utils/wmtk/components/utils/PathResolver.hpp diff --git a/components/utils/CMakeLists.txt b/components/utils/CMakeLists.txt index 6307508d00..9cfbf157d5 100644 --- a/components/utils/CMakeLists.txt +++ b/components/utils/CMakeLists.txt @@ -9,6 +9,9 @@ set(SRC_FILES wmtk/components/utils/resolve_path.cpp wmtk/components/utils/resolve_path.hpp wmtk/components/utils/json_macros.hpp + + wmtk/components/utils/PathResolver.cpp + wmtk/components/utils/PathResolver.hpp ) add_library(wmtk_component_utils ${SRC_FILES}) diff --git a/components/utils/wmtk/components/utils/PathResolver.cpp b/components/utils/wmtk/components/utils/PathResolver.cpp new file mode 100644 index 0000000000..cf8860d73a --- /dev/null +++ b/components/utils/wmtk/components/utils/PathResolver.cpp @@ -0,0 +1,102 @@ +#include "PathResolver.hpp" +#include "json_utils.hpp" +#include "resolve_path.hpp" + + +namespace fs = std::filesystem; +namespace wmtk::components::utils { + +std::pair PathResolver::try_resolving_path( + const std::filesystem::path& potential_base, + const std::filesystem::path& path) +{ + if (path.is_absolute()) { + return {path, true}; + } + + const fs::path root_abs = fs::absolute(potential_base); + + if (!fs::is_directory(root_abs)) { + return {path, false}; + } + + + const fs::path resolved_path = fs::weakly_canonical(potential_base / path); + + return {resolved_path, true}; +} + +struct PathResolver::Impl +{ + Impl() = default; + Impl(Impl&&) = default; + Impl(const Impl&) = default; + Impl& operator=(Impl&&) = default; + Impl& operator=(const Impl&) = default; + + void add_path(const std::filesystem::path& path) { m_paths.emplace_back(path); } + + std::pair resolve(const std::filesystem::path& path) + { + for (const auto& p : path) { + auto res = try_resolving_path(p, path); + const auto& [new_path, succeeded] = res; + if (succeeded) { + return res; + } + } + return {path, false}; + } + + + std::vector m_paths; +}; + + +PathResolver::PathResolver() + : m_impl(std::make_unique()) +{} +PathResolver::PathResolver(PathResolver&& o) = default; +PathResolver::PathResolver(const PathResolver& o) + : m_impl(std::make_unique(*o.m_impl)) +{} +PathResolver& PathResolver::operator=(PathResolver&&) = default; +PathResolver& PathResolver::operator=(const PathResolver& o) +{ + *m_impl = *o.m_impl; + return *this; +} +PathResolver::~PathResolver() = default; + +void PathResolver::add_path(const std::filesystem::path& path) +{ + m_impl->add_path(path); +} + +std::pair PathResolver::resolve(const std::filesystem::path& path) +{ + return m_impl->resolve(path); +} + +std::vector PathResolver::get_paths() const +{ + return m_impl->m_paths; +} + +WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(PathResolver) +{ + nlohmann_json_j = nlohmann_json_t.m_impl->m_paths; +} +WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(PathResolver) +{ + nlohmann_json_t.m_impl->m_paths.clear(); + if (nlohmann_json_j.is_string()) { + nlohmann_json_t.add_path(nlohmann_json_j.get()); + } else if (nlohmann_json_j.is_array()) { + for (const auto& p : nlohmann_json_j) { + nlohmann_json_t.add_path(nlohmann_json_j.get()); + } + } +} + +} // namespace wmtk::components::utils diff --git a/components/utils/wmtk/components/utils/PathResolver.hpp b/components/utils/wmtk/components/utils/PathResolver.hpp new file mode 100644 index 0000000000..c33f200545 --- /dev/null +++ b/components/utils/wmtk/components/utils/PathResolver.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include +#include +#include "json_macros.hpp" + +namespace wmtk::components::utils { + + +// a more portable abstraction of the resolve_path class +class PathResolver +{ +public: + PathResolver(); + ~PathResolver(); + PathResolver(PathResolver&&); + PathResolver(const PathResolver&); + PathResolver& operator=(PathResolver&&); + PathResolver& operator=(const PathResolver&); + + void add_path(const std::filesystem::path& path); + + // always returns a weakly_canonical upon success + std::pair resolve(const std::filesystem::path& path); + + std::vector get_paths() const; + + // always returns a weakly_canonical path upon success + static std::pair try_resolving_path( + const std::filesystem::path& potential_base, + const std::filesystem::path& path); + + // json expects either a single string or an array of strings + WMTK_NLOHMANN_JSON_FRIEND_DECLARATION(PathResolver) + +private: + struct Impl; + std::unique_ptr m_impl; +}; +} // namespace wmtk::components::utils From 5834c11982989cae2b7ff6b5e0302d59244ed464 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Sat, 9 Nov 2024 18:35:29 -0500 Subject: [PATCH 17/29] fixing path resolver usage --- applications/integration_test.py | 22 +++++++++---- .../wmtk/components/input/InputOptions.cpp | 20 +++++++---- .../wmtk/components/input/InputOptions.hpp | 8 +++++ .../input/src/wmtk/components/input/input.cpp | 33 +++++++++++++++---- .../input/src/wmtk/components/input/input.hpp | 14 ++++++-- .../wmtk/components/utils/PathResolver.cpp | 18 ++++++++-- .../wmtk/components/utils/PathResolver.hpp | 5 ++- 7 files changed, 95 insertions(+), 25 deletions(-) diff --git a/applications/integration_test.py b/applications/integration_test.py index 2ec64e924a..fbf9517fbc 100644 --- a/applications/integration_test.py +++ b/applications/integration_test.py @@ -78,6 +78,16 @@ def execute_json(self, json_file_path): print(res.stdout.decode('utf-8'), flush=True) return res + def get_root_path(self, input_js): + root_tag = self.config["input_directory_tag"] + if root_tag in input_js: + if not os.path.isabs(input_js[root_tag]): + + return os.path.join(self.data_folder, input_js[root_tag]) + + return self.data_folder + + def create_reporter(self, input_json_file, output_json_file): # load the input json @@ -86,9 +96,11 @@ def create_reporter(self, input_json_file, output_json_file): # prepare it with reporter data - input_tag = self.config["input_tag"] oracle_tag = self.config["oracle_tag"] + root_tag = self.config["input_directory_tag"] + input_js[oracle_tag] = os.path.abspath(os.path.join(self.config_folder, output_json_file)) + input_js[root_tag ] = self.get_root_path(input_js) with tempfile.NamedTemporaryFile(mode='w', delete=True) as input_json: json.dump(input_js, input_json) @@ -129,12 +141,8 @@ def run_one(self, test_file): input_js[oracle_tag] = oracle_file.name - if root_tag in input_js: - if not os.path.isabs(input_js[root_tag]): - - input_js[root_tag] = os.path.join(self.data_folder, input_js[root_tag]) - else: - input_js[root_tag] = self.data_folder + + input_js[root_tag] = self.get_root_path(input_js) with tempfile.NamedTemporaryFile(mode='w', delete=False) as input_json: json.dump(input_js, input_json) diff --git a/components/input/src/wmtk/components/input/InputOptions.cpp b/components/input/src/wmtk/components/input/InputOptions.cpp index ec2e166231..73e986337d 100644 --- a/components/input/src/wmtk/components/input/InputOptions.cpp +++ b/components/input/src/wmtk/components/input/InputOptions.cpp @@ -1,12 +1,16 @@ #include "InputOptions.hpp" -#include +#include #include +#include namespace wmtk::components::input { +InputOptions::InputOptions() = default; +InputOptions::~InputOptions() = default; bool InputOptions::operator==(const InputOptions& o) const = default; -} + +} // namespace wmtk::components::input namespace nlohmann { void adl_serializer::to_json(json& j, const Type& v) @@ -17,14 +21,15 @@ void adl_serializer::to_json(json& j, con if (!v.name_spec.is_null()) { assert(!v.name_spec_file.has_value()); j["name_spec"] = v.name_spec; - } else if(v.name_spec_file.has_value()) { + } else if (v.name_spec_file.has_value()) { j["name_spec_file"] = v.name_spec_file.value(); - } + + if (v.old_mode) { j["old_mode"] = true; j["ignore_z"] = v.ignore_z_if_zero; // keep around for deprecation purposes - //j["ignore_z_if_zero"] = v.ignore_z_if_zero; + // j["ignore_z_if_zero"] = v.ignore_z_if_zero; if (v.imported_attributes.has_value()) { const auto& imported_attrs = v.imported_attributes.value(); if (imported_attrs.size() > 3) { @@ -51,6 +56,7 @@ void adl_serializer::from_json(const json v.name_spec_file = j["name_spec_file"].get(); } + v.old_mode = false; if (j.contains("old_mode")) { v.old_mode = bool(j["old_mode"]); @@ -69,7 +75,8 @@ void adl_serializer::from_json(const json if (v.old_mode) { v.ignore_z_if_zero = j.contains("ignore_z") ? bool(j["ignore_z"]) : false; // overwrite old ignore_z - //v.ignore_z_if_zero = j.contains("ignore_z_if_zero") ? bool(j["ignore_z_if_zero"]) : false; + // v.ignore_z_if_zero = j.contains("ignore_z_if_zero") ? bool(j["ignore_z_if_zero"]) : + // false; if (j.contains("tetrahedron_attributes")) { v.imported_attributes = { {}, @@ -84,4 +91,5 @@ void adl_serializer::from_json(const json } } } + } // namespace nlohmann diff --git a/components/input/src/wmtk/components/input/InputOptions.hpp b/components/input/src/wmtk/components/input/InputOptions.hpp index 8a6c339236..a9ebbf0f61 100644 --- a/components/input/src/wmtk/components/input/InputOptions.hpp +++ b/components/input/src/wmtk/components/input/InputOptions.hpp @@ -6,11 +6,18 @@ #include #include +namespace wmtk::components { + namespace utils { + class PathResolver; + } +} namespace wmtk::components::input { class InputOptions { public: + InputOptions(); + ~InputOptions(); std::filesystem::path file; std::optional>> imported_attributes; @@ -23,6 +30,7 @@ class InputOptions bool ignore_z_if_zero = false; bool operator==(const InputOptions& o) const; + }; diff --git a/components/input/src/wmtk/components/input/input.cpp b/components/input/src/wmtk/components/input/input.cpp index bd5d08577d..9822a30351 100644 --- a/components/input/src/wmtk/components/input/input.cpp +++ b/components/input/src/wmtk/components/input/input.cpp @@ -1,6 +1,7 @@ #include "input.hpp" #include +#include #include #include #include @@ -23,10 +24,30 @@ std::shared_ptr input( return input(options).root().shared_from_this(); } + multimesh::NamedMultiMesh input(const InputOptions& options) { - if (!std::filesystem::exists(options.file)) { - log_and_throw_error("file [{}] not found", options.file.string()); + return input(options, {}); +} +multimesh::NamedMultiMesh input( + const InputOptions& options, + const components::utils::PathResolver& resolver) +{ + const auto [file_path, found] = resolver.resolve(options.file); + if (!found) { + const auto& paths = resolver.get_paths(); + std::vector path_strs; + std::transform( + paths.begin(), + paths.end(), + std::back_inserter(path_strs), + [](const std::filesystem::path& p) { return p.string(); }); + + log_and_throw_error( + "file [{}] not found (input path was [{}], paths searched were [{}]", + file_path.string(), + options.file.string(), + fmt::join(path_strs, ",")); } std::shared_ptr mesh; @@ -34,17 +55,17 @@ multimesh::NamedMultiMesh input(const InputOptions& options) if (options.old_mode) { if (options.imported_attributes.has_value()) { mesh = wmtk::io::read_mesh( - options.file, + file_path, options.ignore_z_if_zero, options.imported_attributes->at(3)); } else { - mesh = wmtk::io::read_mesh(options.file, options.ignore_z_if_zero); + mesh = wmtk::io::read_mesh(file_path, options.ignore_z_if_zero); } } else { if (options.imported_attributes.has_value()) { - mesh = wmtk::io::read_mesh(options.file, options.imported_attributes.value()); + mesh = wmtk::io::read_mesh(file_path, options.imported_attributes.value()); } else { - mesh = wmtk::io::read_mesh(options.file); + mesh = wmtk::io::read_mesh(file_path); } } assert(mesh->is_connectivity_valid()); diff --git a/components/input/src/wmtk/components/input/input.hpp b/components/input/src/wmtk/components/input/input.hpp index 68dff06636..1761d2f60b 100644 --- a/components/input/src/wmtk/components/input/input.hpp +++ b/components/input/src/wmtk/components/input/input.hpp @@ -5,7 +5,12 @@ #include #include -namespace wmtk::components::input { +namespace wmtk::components { +namespace utils { +class PathResolver; +} + +namespace input { class InputOptions; @@ -25,6 +30,11 @@ std::shared_ptr input( const bool ignore_z_if_zero = false, const std::vector& tetrahedron_attributes = {}); +multimesh::NamedMultiMesh input( + const InputOptions& options, + const components::utils::PathResolver& resolver); + multimesh::NamedMultiMesh input(const InputOptions& options); -} // namespace wmtk::components::input +} // namespace input +} // namespace wmtk::components diff --git a/components/utils/wmtk/components/utils/PathResolver.cpp b/components/utils/wmtk/components/utils/PathResolver.cpp index cf8860d73a..f7c7291ab5 100644 --- a/components/utils/wmtk/components/utils/PathResolver.cpp +++ b/components/utils/wmtk/components/utils/PathResolver.cpp @@ -36,7 +36,7 @@ struct PathResolver::Impl void add_path(const std::filesystem::path& path) { m_paths.emplace_back(path); } - std::pair resolve(const std::filesystem::path& path) + std::pair resolve(const std::filesystem::path& path) const { for (const auto& p : path) { auto res = try_resolving_path(p, path); @@ -54,8 +54,14 @@ struct PathResolver::Impl PathResolver::PathResolver() - : m_impl(std::make_unique()) + : PathResolver(".") {} + +PathResolver::PathResolver(const std::filesystem::path& path) + : m_impl(std::make_unique()) +{ + m_impl->add_path(path); +} PathResolver::PathResolver(PathResolver&& o) = default; PathResolver::PathResolver(const PathResolver& o) : m_impl(std::make_unique(*o.m_impl)) @@ -68,12 +74,18 @@ PathResolver& PathResolver::operator=(const PathResolver& o) } PathResolver::~PathResolver() = default; + +void PathResolver::clear_paths() +{ + m_impl->m_paths.clear(); +} void PathResolver::add_path(const std::filesystem::path& path) { m_impl->add_path(path); } -std::pair PathResolver::resolve(const std::filesystem::path& path) +std::pair PathResolver::resolve( + const std::filesystem::path& path) const { return m_impl->resolve(path); } diff --git a/components/utils/wmtk/components/utils/PathResolver.hpp b/components/utils/wmtk/components/utils/PathResolver.hpp index c33f200545..155d918852 100644 --- a/components/utils/wmtk/components/utils/PathResolver.hpp +++ b/components/utils/wmtk/components/utils/PathResolver.hpp @@ -12,7 +12,9 @@ namespace wmtk::components::utils { class PathResolver { public: + // defaults to the path ".", i.e the working directory PathResolver(); + PathResolver(const std::filesystem::path& path); ~PathResolver(); PathResolver(PathResolver&&); PathResolver(const PathResolver&); @@ -20,9 +22,10 @@ class PathResolver PathResolver& operator=(const PathResolver&); void add_path(const std::filesystem::path& path); + void clear_paths(); // always returns a weakly_canonical upon success - std::pair resolve(const std::filesystem::path& path); + std::pair resolve(const std::filesystem::path& path) const; std::vector get_paths() const; From a4f7c7b86d76287cf6bc3d7ab48dba900b60e880 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 09:02:25 -0500 Subject: [PATCH 18/29] cnovert seems to work --- applications/convert/examples/raw/camel.json | 6 ++++-- applications/convert/main.cpp | 11 +++++++++-- .../src/wmtk/components/multimesh/NamedMultiMesh.cpp | 12 ++++++++++-- .../utils/wmtk/components/utils/PathResolver.cpp | 5 ++--- src/wmtk/multimesh/MultiMeshManager.hpp | 4 ++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/applications/convert/examples/raw/camel.json b/applications/convert/examples/raw/camel.json index 430a7e42ca..9ef4ef1d0c 100644 --- a/applications/convert/examples/raw/camel.json +++ b/applications/convert/examples/raw/camel.json @@ -13,8 +13,10 @@ "position": "uv" }, "output": { - "file": "camel.hdf5", - "type": ".hdf5" + "position": { + "file": "camel.hdf5", + "type": ".hdf5" + } } } diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp index 6b66b09971..1e19fccf1d 100644 --- a/applications/convert/main.cpp +++ b/applications/convert/main.cpp @@ -20,6 +20,7 @@ #include "wmtk/components/multimesh/MeshCollection.hpp" #include "wmtk/components/multimesh/from_boundary.hpp" #include "wmtk/components/multimesh/from_facet_bijection.hpp" +#include "wmtk/components/utils/PathResolver.hpp" using namespace wmtk::components; using namespace wmtk::applications; @@ -79,16 +80,22 @@ int run(const fs::path& config_path /*, const std::optional& name_spec spdlog::warn("{}", j.dump(2)); wmtk::components::multimesh::MeshCollection meshes; + components::utils::PathResolver path_resolver; + + if(j.contains("root")) { + path_resolver = j["root"]; + } + std::shared_ptr output_mesh; if (j["input"].is_array()) { for (const auto& in_opts_js : j["input"]) { wmtk::components::input::InputOptions opts = in_opts_js; - meshes.add_mesh(wmtk::components::input::input(opts)); + meshes.add_mesh(wmtk::components::input::input(opts, path_resolver)); } } else { wmtk::components::input::InputOptions opts = j["input"]; output_mesh = - meshes.add_mesh(wmtk::components::input::input(opts)).root().shared_from_this(); + meshes.add_mesh(wmtk::components::input::input(opts, path_resolver)).root().shared_from_this(); } if (j.contains("tree")) { diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index 705c3e5ee7..bb70921808 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -1,5 +1,6 @@ #include "NamedMultiMesh.hpp" #include +#include #include #include #include @@ -51,7 +52,11 @@ struct NamedMultiMesh::Node { toks.emplace_back(name); if (!t.empty()) { - const auto& child = *m_children[t.front()]; + const size_t index = t.front(); + assert(index >= 0); + assert(index < m_children.size()); + assert(bool(m_children[index])); + const auto& child = *m_children[index]; child.get_name_tokens(t.subspan<1>(), toks); } } @@ -194,7 +199,10 @@ std::map> NamedMultiMesh::all_meshes() std::string NamedMultiMesh::get_name(const Mesh& m) const { std::vector toks; - auto id = m.absolute_multi_mesh_id(); + auto id = wmtk::multimesh::MultiMeshManager::relative_id( + m_root->absolute_multi_mesh_id(), + + m.absolute_multi_mesh_id()); m_name_root->get_name_tokens(id, toks); return fmt::format("{}", fmt::join(toks, ".")); } diff --git a/components/utils/wmtk/components/utils/PathResolver.cpp b/components/utils/wmtk/components/utils/PathResolver.cpp index f7c7291ab5..d74923de65 100644 --- a/components/utils/wmtk/components/utils/PathResolver.cpp +++ b/components/utils/wmtk/components/utils/PathResolver.cpp @@ -1,6 +1,5 @@ #include "PathResolver.hpp" #include "json_utils.hpp" -#include "resolve_path.hpp" namespace fs = std::filesystem; @@ -23,7 +22,7 @@ std::pair PathResolver::try_resolving_path( const fs::path resolved_path = fs::weakly_canonical(potential_base / path); - return {resolved_path, true}; + return {resolved_path, fs::exists(resolved_path)}; } struct PathResolver::Impl @@ -38,7 +37,7 @@ struct PathResolver::Impl std::pair resolve(const std::filesystem::path& path) const { - for (const auto& p : path) { + for (const auto& p : m_paths) { auto res = try_resolving_path(p, path); const auto& [new_path, succeeded] = res; if (succeeded) { diff --git a/src/wmtk/multimesh/MultiMeshManager.hpp b/src/wmtk/multimesh/MultiMeshManager.hpp index 63a8803507..9eda9624dc 100644 --- a/src/wmtk/multimesh/MultiMeshManager.hpp +++ b/src/wmtk/multimesh/MultiMeshManager.hpp @@ -13,7 +13,6 @@ #include "utils/check_map_valid.hpp" - namespace wmtk { class Mesh; @@ -40,7 +39,7 @@ template class MultiMeshVisitorExecutor; namespace utils { - class MapValidator; +class MapValidator; } } // namespace multimesh @@ -533,6 +532,7 @@ class MultiMeshManager : public wmtk::utils::MerkleTreeInteriorNode const std::vector& local_id_path) const; +public: static std::vector least_upper_bound_id( const std::vector& a, const std::vector& b); From 1fec8f22237525e6f9ac4b0f4fef5459bcc5b295 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 13:53:32 -0500 Subject: [PATCH 19/29] naming works better now with convert app --- applications/convert/examples/camel.json | 35 +++++++ .../convert/examples/make_boundary.json | 41 +++++--- .../convert/examples/raw/make_boundary.json | 12 +-- applications/convert/main.cpp | 47 ++++++--- applications/integration_test.py | 1 + .../components/multimesh/MeshCollection.cpp | 36 ++++++- .../components/multimesh/MeshCollection.hpp | 18 +++- .../components/multimesh/NamedMultiMesh.cpp | 96 +++++++++++++++++-- .../components/multimesh/NamedMultiMesh.hpp | 8 +- src/wmtk/EdgeMesh.cpp | 1 + src/wmtk/EdgeMesh.hpp | 1 + src/wmtk/Mesh_multimesh.cpp | 30 +++--- src/wmtk/PointMesh.cpp | 1 + src/wmtk/PointMesh.hpp | 1 + src/wmtk/TetMesh.cpp | 1 + src/wmtk/TetMesh.hpp | 1 + src/wmtk/TriMesh.cpp | 4 + src/wmtk/TriMesh.hpp | 1 + 18 files changed, 270 insertions(+), 65 deletions(-) create mode 100644 applications/convert/examples/camel.json diff --git a/applications/convert/examples/camel.json b/applications/convert/examples/camel.json new file mode 100644 index 0000000000..fcb95a58c9 --- /dev/null +++ b/applications/convert/examples/camel.json @@ -0,0 +1,35 @@ +{ + "input": { + "input": [ + { + "file": "unit_test/meshes/camel.msh", + "name_spec": "position" + }, + { + "file": "unit_test/meshes/cameluv.msh", + "name_spec": "uv" + } + ], + "output": { + "position": { + "file": "camel.hdf5", + "type": ".hdf5" + } + }, + "tree": { + "position": "uv" + } + }, + "stats": { + "position": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + }, + "position.uv": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + } + } +} diff --git a/applications/convert/examples/make_boundary.json b/applications/convert/examples/make_boundary.json index e81488d812..49d393144d 100644 --- a/applications/convert/examples/make_boundary.json +++ b/applications/convert/examples/make_boundary.json @@ -1,22 +1,33 @@ { + "input": { "input": [ - { - "file": "_pos.msh", - "name_spec": "position" - } + { + "file": "blub_open.msh", + "name_spec": "position" + } ], - "tree": { - "position": { - "type": "boundary", - "dimension": 1 - } - - }, - "output": { - "file": "ogre_boundary.hdf5", + "position": { + "file": "blub.hdf5", "type": ".hdf5" + } + }, + "tree": { + "position": { + "dimension": 1, + "type": "boundary" + } + } + }, + "stats": { + "position": { + "edges": 17504, + "faces": 11648, + "vertices": 5857 + }, + "position.boundary_1": { + "edges": 64, + "vertices": 64 } - - + } } diff --git a/applications/convert/examples/raw/make_boundary.json b/applications/convert/examples/raw/make_boundary.json index e81488d812..dceb25da3f 100644 --- a/applications/convert/examples/raw/make_boundary.json +++ b/applications/convert/examples/raw/make_boundary.json @@ -1,7 +1,7 @@ { "input": [ { - "file": "_pos.msh", + "file": "blub_open.msh", "name_spec": "position" } ], @@ -10,13 +10,11 @@ "type": "boundary", "dimension": 1 } - }, - "output": { - "file": "ogre_boundary.hdf5", - "type": ".hdf5" + "position": { + "file": "blub.hdf5", + "type": ".hdf5" + } } - - } diff --git a/applications/convert/main.cpp b/applications/convert/main.cpp index 1e19fccf1d..3fb759ff58 100644 --- a/applications/convert/main.cpp +++ b/applications/convert/main.cpp @@ -34,9 +34,13 @@ std::shared_ptr merge_meshes( { for (const auto& [parent, child_datas] : js.items()) { auto& parent_mesh = mc.get_mesh(parent); + auto& parent_named_mesh = mc.get_named_multimesh(parent); if (child_datas.is_string()) { - auto& child_mesh = mc.get_mesh(child_datas.get()); + const auto child_name = child_datas.get(); + auto& child_mesh = mc.get_mesh(child_name); + auto& child_named_mesh = mc.get_named_multimesh(child_name); components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + parent_named_mesh.append_child_mesh_names(parent_mesh, child_named_mesh); return parent_mesh.shared_from_this(); } else if (child_datas.is_object()) { @@ -45,7 +49,9 @@ std::shared_ptr merge_meshes( if (type == "facet_bijection") { const std::string child_name = child_datas["name"]; auto& child_mesh = mc.get_mesh(child_name); + auto& child_named_mesh = mc.get_named_multimesh(child_name); components::multimesh::from_facet_bijection(parent_mesh, child_mesh); + parent_named_mesh.append_child_mesh_names(parent_mesh, child_named_mesh); return parent_mesh.shared_from_this(); } else if (type == "boundary") { @@ -54,10 +60,19 @@ std::shared_ptr merge_meshes( if (child_datas.contains("boundary_attribute_name")) { boundary_attr_name = child_datas["boundary_attribute_name"]; } - components::multimesh::from_boundary( + + std::string boundary_mesh_name = fmt::format("boundary_{}", dimension); + if (child_datas.contains("boundary_mesh_name")) { + boundary_mesh_name = child_datas["boundary_mesh_name"]; + } + auto mptr = components::multimesh::from_boundary( parent_mesh, wmtk::get_primitive_type_from_id(dimension), boundary_attr_name); + + auto& child_named_mesh = mc.emplace_mesh(*mptr, boundary_mesh_name); + parent_named_mesh.append_child_mesh_names(parent_mesh, child_named_mesh); + return parent_mesh.shared_from_this(); } } @@ -82,7 +97,7 @@ int run(const fs::path& config_path /*, const std::optional& name_spec wmtk::components::multimesh::MeshCollection meshes; components::utils::PathResolver path_resolver; - if(j.contains("root")) { + if (j.contains("root")) { path_resolver = j["root"]; } @@ -94,8 +109,9 @@ int run(const fs::path& config_path /*, const std::optional& name_spec } } else { wmtk::components::input::InputOptions opts = j["input"]; - output_mesh = - meshes.add_mesh(wmtk::components::input::input(opts, path_resolver)).root().shared_from_this(); + output_mesh = meshes.add_mesh(wmtk::components::input::input(opts, path_resolver)) + .root() + .shared_from_this(); } if (j.contains("tree")) { @@ -116,16 +132,17 @@ int run(const fs::path& config_path /*, const std::optional& name_spec } - if (j.contains("report")) { - const std::string report = j["report"]; - if (!report.empty()) { - nlohmann::json out_json; - auto& stats = out_json["stats"]; - for(const auto& [name, meshptr]: meshes.all_meshes()) { - stats[name] = wmtk::applications::utils::element_count_report_named(*meshptr); - } - j.erase("report"); - out_json["input"] = j; + if (j.contains("report")) { + const std::string report = j["report"]; + meshes.make_canonical(); + if (!report.empty()) { + nlohmann::json out_json; + auto& stats = out_json["stats"]; + for (const auto& [name, mesh] : meshes.all_meshes()) { + stats[name] = wmtk::applications::utils::element_count_report_named(mesh); + } + j.erase("report"); + out_json["input"] = j; std::ofstream ofs(report); diff --git a/applications/integration_test.py b/applications/integration_test.py index fbf9517fbc..67389b276f 100644 --- a/applications/integration_test.py +++ b/applications/integration_test.py @@ -131,6 +131,7 @@ def run_one(self, test_file): with open(test_file) as f: try: test_oracle = json.load(f) + f.close() except Exception as e: print(f"Caught exception while loading file {test_file}: {e}", flush=True) raise e diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index a8deee078b..2d0beaf61a 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -1,5 +1,6 @@ #include "MeshCollection.hpp" +#include #include #include "internal/split_path.hpp" @@ -41,6 +42,24 @@ Mesh& MeshCollection::get_mesh(const std::string_view& path) { return get_named_multimesh(path).get_mesh(path); } +bool MeshCollection::has_named_multimesh(const std::string_view& path) const +{ + const std::string_view nmm_name = *internal::split_path(path).begin(); + if (nmm_name.empty() && m_meshes.size() == 1) { + return true; + } + return m_meshes.find(nmm_name) != m_meshes.end(); +} +bool MeshCollection::has_mesh(const std::string_view& path) const +{ + if (!has_named_multimesh(path)) { + return false; + } else { + const auto& nmm = get_named_multimesh(path); + return nmm.has_mesh(path); + } +} + NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) { using namespace std; @@ -52,13 +71,26 @@ NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path } return *m_meshes.at(nmm_name); } -std::map> MeshCollection::all_meshes() const +std::map MeshCollection::all_meshes() const +// std::map> MeshCollection::all_meshes() const { - std::map> meshes; + // std::map> meshes; + std::map meshes; for (const auto& [name, nnptr] : m_meshes) { const auto pr = nnptr->all_meshes(); meshes.insert(pr.begin(), pr.end()); } return meshes; } + +void MeshCollection::make_canonical() +{ + for (auto it = m_meshes.begin(); it != m_meshes.end();) { + if (it->second->root().is_multi_mesh_root()) { + ++it; + } else { + it = m_meshes.erase(it); + } + } +} } // namespace wmtk::components::multimesh diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp index 4d282fddb7..e3feb91d49 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.hpp @@ -1,25 +1,35 @@ #pragma once #include -#include "NamedMultiMesh.hpp" #include +#include "NamedMultiMesh.hpp" namespace wmtk::components::multimesh { - class InputOptions; +class InputOptions; class MeshCollection { public: NamedMultiMesh& add_mesh(NamedMultiMesh o); - //NamedMultiMesh& add_mesh(const InputOptions& opts); + template + NamedMultiMesh& emplace_mesh(Args&&... args) + { + return add_mesh(NamedMultiMesh(std::forward(args)...)); + } + // NamedMultiMesh& add_mesh(const InputOptions& opts); const NamedMultiMesh& get_named_multimesh(const std::string_view& path) const; const Mesh& get_mesh(const std::string_view& path) const; + bool has_mesh(const std::string_view& path) const; + bool has_named_multimesh(const std::string_view& path) const; NamedMultiMesh& get_named_multimesh(const std::string_view& path); Mesh& get_mesh(const std::string_view& path); + // over time meshes can merge and have aliases + // Thsi operation removes meshes whose naming structure aren't the root of a naming tree + void make_canonical(); - std::map> all_meshes() const; + std::map all_meshes() const; private: std::map> m_meshes; diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index bb70921808..f52c481d0a 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -21,6 +21,17 @@ struct NamedMultiMesh::Node std::back_inserter(m_children), [&](const std::unique_ptr& n) { return std::make_unique(*n); }); } + Node& operator=(const Node& o) + { + m_children.clear(); + std::ranges::transform( + o.m_children, + std::back_inserter(m_children), + [&](const std::unique_ptr& n) { return std::make_unique(*n); }); + + update_child_names(); + return *this; + } std::string name; std::vector> m_children; @@ -48,12 +59,12 @@ struct NamedMultiMesh::Node update_child_names(); } - void get_name_tokens(const std::span& t, std::vector& toks) const + void get_name_tokens(const std::span& t, std::vector& toks) + const { toks.emplace_back(name); if (!t.empty()) { const size_t index = t.front(); - assert(index >= 0); assert(index < m_children.size()); assert(bool(m_children[index])); const auto& child = *m_children[index]; @@ -81,6 +92,21 @@ struct NamedMultiMesh::Node } }; +NamedMultiMesh::NamedMultiMesh(Mesh& m, const std::string& root_name) +{ + set_mesh(m); + set_name(root_name); +} +NamedMultiMesh::NamedMultiMesh(Mesh& m, const std::string_view& root_name) +{ + set_mesh(m); + set_name(root_name); +} +NamedMultiMesh::NamedMultiMesh(Mesh& m, const nlohmann::json& root_name) +{ + set_mesh(m); + set_names(root_name); +} void NamedMultiMesh::set_root(Mesh& m) { @@ -89,7 +115,8 @@ void NamedMultiMesh::set_root(Mesh& m) void NamedMultiMesh::set_mesh(Mesh& m) { - set_root(m.get_multi_mesh_root()); + set_root(m); + // set_root(m.get_multi_mesh_root()); } @@ -98,6 +125,25 @@ Mesh& NamedMultiMesh::get_mesh(const std::string_view& path) const const auto id = get_id(path); return m_root->get_multi_mesh_child_mesh(id); } +bool NamedMultiMesh::has_mesh(const std::string_view& path) const +{ +#if defined(WMTK_ENABLED_CPP20) + std::ranges::view auto split = internal::split_path(path); +#else + auto split = internal::split_path(path); +#endif + Node const* cur_mesh = m_name_root.get(); + assert(*split.begin() == cur_mesh->name || *split.begin() == ""); + for (const auto& token : std::ranges::views::drop(split, 1)) { + auto it = cur_mesh->m_child_indexer.find(token); + if (it == cur_mesh->m_child_indexer.end()) { + return false; + } else { + cur_mesh = cur_mesh->m_children[it->second].get(); + } + } + return true; +} auto NamedMultiMesh::get_id(const std::string_view& path) const -> std::vector { @@ -119,6 +165,14 @@ auto NamedMultiMesh::get_id(const std::string_view& path) const -> std::vector NamedMultiMesh::get_id(const Mesh& m) const +{ + return wmtk::multimesh::MultiMeshManager::relative_id( + m_root->absolute_multi_mesh_id(), + + m.absolute_multi_mesh_id()); +} + void NamedMultiMesh::set_name(const std::string_view& root_name) { set_names(nlohmann::json(root_name)); @@ -188,22 +242,46 @@ std::unique_ptr NamedMultiMesh::get_names_json() const return js_ptr; } -std::map> NamedMultiMesh::all_meshes() const +std::map NamedMultiMesh::all_meshes() const +// std::map> NamedMultiMesh::all_meshes() const { - std::map> meshes; + std::map meshes; for (const auto& mptr : m_root->get_all_meshes()) { - meshes.emplace(get_name(*mptr), mptr); + meshes.emplace(get_name(*mptr), *mptr); } return meshes; } std::string NamedMultiMesh::get_name(const Mesh& m) const { std::vector toks; - auto id = wmtk::multimesh::MultiMeshManager::relative_id( - m_root->absolute_multi_mesh_id(), - m.absolute_multi_mesh_id()); + const auto id = get_id(m); m_name_root->get_name_tokens(id, toks); return fmt::format("{}", fmt::join(toks, ".")); } +void NamedMultiMesh::append_child_mesh_names(const Mesh& parent, const NamedMultiMesh& o) +{ + const std::vector parent_id = get_id(parent); + Node* cur_mesh = m_name_root.get(); + for (const auto& index : parent_id) { + cur_mesh = cur_mesh->m_children[index].get(); + } + + const auto child_relid = wmtk::multimesh::MultiMeshManager::relative_id( + parent.absolute_multi_mesh_id(), + o.root().absolute_multi_mesh_id()); + spdlog::error( + "{} {} {}", + fmt::join(parent.absolute_multi_mesh_id(), ","), + fmt::join(o.root().absolute_multi_mesh_id(), ","), + fmt::join(child_relid, ",")); + assert(child_relid.size() == 1); + + const int64_t& id = child_relid[0]; + if (const size_t child_size = cur_mesh->m_children.size(); child_size == id) { + cur_mesh->m_children.emplace_back(std::make_unique(*o.m_name_root)); + } else if (child_size < id) { + *cur_mesh->m_children[id] = *o.m_name_root; + } +} } // namespace wmtk::components::multimesh diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp index a387cbf193..2dd276bf35 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.hpp @@ -17,6 +17,9 @@ class NamedMultiMesh { public: NamedMultiMesh(); + explicit NamedMultiMesh(Mesh& m, const std::string& root_name); + NamedMultiMesh(Mesh& m, const std::string_view& root_name); + explicit NamedMultiMesh(Mesh& m, const nlohmann::json& root_name); // NamedMultiMesh(NamedMultiMesh&&); NamedMultiMesh(const NamedMultiMesh&); ~NamedMultiMesh(); @@ -26,6 +29,7 @@ class NamedMultiMesh void set_name(const std::string_view& root_name = ""); void set_names(const nlohmann::json& js); void set_root(Mesh& m); + void append_child_mesh_names(const Mesh& parent, const NamedMultiMesh& o); std::unique_ptr get_names_json() const; @@ -35,13 +39,15 @@ class NamedMultiMesh /// Navigates to the root of the multimesh void set_mesh(Mesh& m); Mesh& get_mesh(const std::string_view& path) const; + bool has_mesh(const std::string_view& path) const; std::vector get_id(const std::string_view& path) const; + std::vector get_id(const Mesh& m) const; Mesh& root() { return *m_root; } const Mesh& root() const { return *m_root; } - std::map> all_meshes() const; + std::map all_meshes() const; // returns the name of a mesh if it lies in this multimesh std::string get_name(const Mesh& m) const; diff --git a/src/wmtk/EdgeMesh.cpp b/src/wmtk/EdgeMesh.cpp index a80fb42e41..7c3b5c3d8c 100644 --- a/src/wmtk/EdgeMesh.cpp +++ b/src/wmtk/EdgeMesh.cpp @@ -5,6 +5,7 @@ #include #include namespace wmtk { + EdgeMesh::~EdgeMesh() = default; EdgeMesh::EdgeMesh() : MeshCRTP(1) , m_ve_handle(register_attribute_typed("m_ve", PrimitiveType::Vertex, 1, false, -1)) diff --git a/src/wmtk/EdgeMesh.hpp b/src/wmtk/EdgeMesh.hpp index b827ff1b91..692d1eecb6 100644 --- a/src/wmtk/EdgeMesh.hpp +++ b/src/wmtk/EdgeMesh.hpp @@ -22,6 +22,7 @@ class EdgeMesh : public MeshCRTP friend class operations::utils::MultiMeshEdgeCollapseFunctor; friend class operations::utils::UpdateEdgeOperationMultiMeshMapFunctor; EdgeMesh(); + ~EdgeMesh() override; EdgeMesh(const EdgeMesh& o) = delete; EdgeMesh(EdgeMesh&& o) = default; EdgeMesh& operator=(const EdgeMesh& o) = delete; diff --git a/src/wmtk/Mesh_multimesh.cpp b/src/wmtk/Mesh_multimesh.cpp index 0435a7a39f..166f2ec389 100644 --- a/src/wmtk/Mesh_multimesh.cpp +++ b/src/wmtk/Mesh_multimesh.cpp @@ -241,19 +241,25 @@ std::vector> Mesh::get_all_child_meshes() const std::vector> Mesh::get_all_meshes() const { - std::vector> meshes; - std::queue> queue; - //std::queue queue; - meshes.emplace_back(this); - while(!queue.empty()) { - const auto& cur = queue.front(); - //Mesh const* cur = queue.front(); - queue.pop(); - meshes.emplace_back(cur->shared_from_this()); - for(const auto& m: cur->get_child_meshes()) { - queue.emplace(m.get()); - } + auto meshes2 = get_all_child_meshes(); + std::vector> meshes; + meshes.emplace_back(shared_from_this()); + for(const auto& m: meshes2) { + meshes.emplace_back(m); } return meshes; + //std::queue> queue; + ////std::queue queue; + //meshes.emplace_back(this); + //while(!queue.empty()) { + // const auto& cur = queue.front(); + // //Mesh const* cur = queue.front(); + // queue.pop(); + // meshes.emplace_back(cur->shared_from_this()); + // for(const auto& m: cur->get_child_meshes()) { + // queue.emplace(m.get()); + // } + //} + //return meshes; } } // namespace wmtk diff --git a/src/wmtk/PointMesh.cpp b/src/wmtk/PointMesh.cpp index 6eadada074..686e1ef8e8 100644 --- a/src/wmtk/PointMesh.cpp +++ b/src/wmtk/PointMesh.cpp @@ -6,6 +6,7 @@ Tuple PointMesh::vertex_tuple_from_id(int64_t id) const return Tuple(-1, -1, -1, id); } +PointMesh::~PointMesh() = default; PointMesh::PointMesh() : MeshCRTP(0) {} diff --git a/src/wmtk/PointMesh.hpp b/src/wmtk/PointMesh.hpp index 30df459ff4..b6dd8bd8fe 100644 --- a/src/wmtk/PointMesh.hpp +++ b/src/wmtk/PointMesh.hpp @@ -18,6 +18,7 @@ class PointMesh : public MeshCRTP template friend class attribute::Accessor; PointMesh(); + ~PointMesh() override; PointMesh(int64_t size); PointMesh(const PointMesh& o) = delete; PointMesh(PointMesh&& o) = default; diff --git a/src/wmtk/TetMesh.cpp b/src/wmtk/TetMesh.cpp index 193a7d4f4d..2e986d8371 100644 --- a/src/wmtk/TetMesh.cpp +++ b/src/wmtk/TetMesh.cpp @@ -13,6 +13,7 @@ namespace wmtk { using namespace autogen; +TetMesh::~TetMesh() = default; TetMesh::TetMesh() : MeshCRTP(3) diff --git a/src/wmtk/TetMesh.hpp b/src/wmtk/TetMesh.hpp index d1d9ceb8be..ff17b83e65 100644 --- a/src/wmtk/TetMesh.hpp +++ b/src/wmtk/TetMesh.hpp @@ -20,6 +20,7 @@ class TetMesh : public MeshCRTP template friend class attribute::Accessor; TetMesh(); + ~TetMesh() override; TetMesh(const TetMesh& o) = delete; TetMesh(TetMesh&& o); TetMesh& operator=(const TetMesh& o) = delete; diff --git a/src/wmtk/TriMesh.cpp b/src/wmtk/TriMesh.cpp index f37a8d33e2..8895de510d 100644 --- a/src/wmtk/TriMesh.cpp +++ b/src/wmtk/TriMesh.cpp @@ -7,6 +7,8 @@ #include namespace wmtk { + + TriMesh::~TriMesh() = default; TriMesh::TriMesh() : MeshCRTP(2) , m_vf_handle(register_attribute_typed("m_vf", PrimitiveType::Vertex, 1, false, -1)) @@ -15,6 +17,7 @@ TriMesh::TriMesh() , m_fe_handle(register_attribute_typed("m_fe", PrimitiveType::Triangle, 3, false, -1)) , m_ff_handle(register_attribute_typed("m_ff", PrimitiveType::Triangle, 3, false, -1)) { + spdlog::warn("Trimesh constructor {}", fmt::ptr(this)); make_cached_accessors(); } @@ -30,6 +33,7 @@ void TriMesh::make_cached_accessors() TriMesh::TriMesh(TriMesh&& o) : MeshCRTP(std::move(o)) { + spdlog::warn("Trimesh constructor {}", fmt::ptr(this)); m_vf_handle = o.m_vf_handle; m_ef_handle = o.m_ef_handle; m_fv_handle = o.m_fv_handle; diff --git a/src/wmtk/TriMesh.hpp b/src/wmtk/TriMesh.hpp index 6e67fd1209..57aa8d5730 100644 --- a/src/wmtk/TriMesh.hpp +++ b/src/wmtk/TriMesh.hpp @@ -31,6 +31,7 @@ class TriMesh : public MeshCRTP TriMesh& operator=(const TriMesh& o) = delete; TriMesh(TriMesh&& o); TriMesh& operator=(TriMesh&& o); + ~TriMesh() override; void make_cached_accessors(); From 5868840ca22b85ba9972a2bf5d7615ff6a1581c5 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 15:04:55 -0500 Subject: [PATCH 20/29] updates --- .../convert/examples/raw/split_uv.json | 20 +++++++---- applications/convert/examples/split_uv.json | 34 +++++++++++++++---- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/applications/convert/examples/raw/split_uv.json b/applications/convert/examples/raw/split_uv.json index b07f00a404..8628dea543 100644 --- a/applications/convert/examples/raw/split_uv.json +++ b/applications/convert/examples/raw/split_uv.json @@ -1,11 +1,17 @@ { - "input": { - "file": "ogre.hdf5", - "name_spec": - { - "position": "uv" - } - }, + "input": [ + { + "file": "unit_test/meshes/camel.msh", + "name_spec": "position" + }, + { + "file": "unit_test/meshes/cameluv.msh", + "name_spec": "uv" + } + ], + "tree": { + "position": "uv" + }, "output": { "position": { "file": "ogre_pos.vtu", diff --git a/applications/convert/examples/split_uv.json b/applications/convert/examples/split_uv.json index b07f00a404..ffbdd4eff5 100644 --- a/applications/convert/examples/split_uv.json +++ b/applications/convert/examples/split_uv.json @@ -1,11 +1,15 @@ { - "input": { - "file": "ogre.hdf5", - "name_spec": - { - "position": "uv" - } - }, + "input": { + "input": [ + { + "file": "unit_test/meshes/camel.msh", + "name_spec": "position" + }, + { + "file": "unit_test/meshes/cameluv.msh", + "name_spec": "uv" + } + ], "output": { "position": { "file": "ogre_pos.vtu", @@ -16,4 +20,20 @@ "position_attribute": "vertices" } } + "tree": { + "position": "uv" + } + }, + "stats": { + "position": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + }, + "position.uv": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + } + } } From 17e97a5116187fab4e258c6813d87f03b201941d Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 20:02:17 -0500 Subject: [PATCH 21/29] removing data dir printout --- applications/integration_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/integration_test.py b/applications/integration_test.py index 67389b276f..407e35141b 100644 --- a/applications/integration_test.py +++ b/applications/integration_test.py @@ -54,7 +54,6 @@ def __init__(self, name, test_config, configs_to_run = None, run_all = False): if "test_data_directory" in config: self.data_folder = os.path.join(self.data_folder, config["test_directory"]) - print(f"Data folder {self.data_folder}") self.executable = os.path.abspath(os.path.join(IntegrationTest.BINARY_FOLDER, self.name)) From cbee74aefa153c2b8b023a261c008cf49307224a Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 20:12:19 -0500 Subject: [PATCH 22/29] updates --- applications/convert/CMakeLists.txt | 2 +- .../convert/examples/camel_split_uv.json | 0 applications/convert/examples/merge_uv.json | 23 ------------------- applications/convert/examples/split_uv.json | 19 +++++++-------- .../components/multimesh/NamedMultiMesh.cpp | 2 ++ 5 files changed, 13 insertions(+), 33 deletions(-) create mode 100644 applications/convert/examples/camel_split_uv.json delete mode 100644 applications/convert/examples/merge_uv.json diff --git a/applications/convert/CMakeLists.txt b/applications/convert/CMakeLists.txt index 5dc7a37141..ed5933a236 100644 --- a/applications/convert/CMakeLists.txt +++ b/applications/convert/CMakeLists.txt @@ -20,6 +20,6 @@ wmtk_register_integration_test( CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test_config.json CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/examples GIT_REPOSITORY "https://github.com/wildmeshing/data.git" - GIT_TAG 152a561697a6e923451ca8535309cbe1e116a9fa + GIT_TAG 363f8e860673a4e4f68df6465b99e86809c96283 #EXTRA_ARGUMENTS run ) diff --git a/applications/convert/examples/camel_split_uv.json b/applications/convert/examples/camel_split_uv.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/applications/convert/examples/merge_uv.json b/applications/convert/examples/merge_uv.json deleted file mode 100644 index 30627f7585..0000000000 --- a/applications/convert/examples/merge_uv.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "input": [ - { - "file": "_pos.msh", - "name_spec": "position" - }, - { - "file": "_tex.msh", - "name_spec": "uv" - } - ], - "tree": { - "position": "uv" - - }, - - "output": { - "file": "ogre.hdf5", - "type": ".hdf5" - } - - -} diff --git a/applications/convert/examples/split_uv.json b/applications/convert/examples/split_uv.json index ffbdd4eff5..1762b3f1ec 100644 --- a/applications/convert/examples/split_uv.json +++ b/applications/convert/examples/split_uv.json @@ -11,15 +11,16 @@ } ], "output": { - "position": { - "file": "ogre_pos.vtu", - "position_attribute": "vertices" - }, - "position.uv": { - "file": "ogre_uv.vtu", - "position_attribute": "vertices" - } - } + "position": { + "file": "ogre_pos.vtu", + "position_attribute": "vertices" + }, + "position.uv": { + "file": "ogre_uv.vtu", + "position_attribute": "vertices" + } + }, + "root": "/home/mtao/.local/cpm/wmtk_data/aa0abd4658bb064515ee7cc2a7be87aa", "tree": { "position": "uv" } diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index f52c481d0a..033ce4eeb8 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -283,5 +283,7 @@ void NamedMultiMesh::append_child_mesh_names(const Mesh& parent, const NamedMult } else if (child_size < id) { *cur_mesh->m_children[id] = *o.m_name_root; } + cur_mesh->update_child_names(); + } } // namespace wmtk::components::multimesh From c86b1dc5a4eb016b87c589d24d7bb91e520f21f4 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 20:50:04 -0500 Subject: [PATCH 23/29] adding unit tests for convert app --- applications/convert/test_config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/applications/convert/test_config.json b/applications/convert/test_config.json index 00d824156b..845b0624e0 100644 --- a/applications/convert/test_config.json +++ b/applications/convert/test_config.json @@ -1,5 +1,9 @@ { "tests": [ + "camel.json", + "camel_split_uv.json", + "make_boundary.json", + "split_uv.json" ], "input_tag": "input", "oracle_tag": "report", From 5f5c15e798e0896bf027f419c2b296fd348568dc Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 20:50:31 -0500 Subject: [PATCH 24/29] removing temporary test filesl --- applications/convert/examples/raw/camel.json | 22 ---------------- .../convert/examples/raw/make_boundary.json | 20 --------------- .../convert/examples/raw/merge_uv.json | 23 ----------------- .../convert/examples/raw/split_uv.json | 25 ------------------- 4 files changed, 90 deletions(-) delete mode 100644 applications/convert/examples/raw/camel.json delete mode 100644 applications/convert/examples/raw/make_boundary.json delete mode 100644 applications/convert/examples/raw/merge_uv.json delete mode 100644 applications/convert/examples/raw/split_uv.json diff --git a/applications/convert/examples/raw/camel.json b/applications/convert/examples/raw/camel.json deleted file mode 100644 index 9ef4ef1d0c..0000000000 --- a/applications/convert/examples/raw/camel.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "input": [ - { - "file": "unit_test/meshes/camel.msh", - "name_spec": "position" - }, - { - "file": "unit_test/meshes/cameluv.msh", - "name_spec": "uv" - } - ], - "tree": { - "position": "uv" - }, - "output": { - "position": { - "file": "camel.hdf5", - "type": ".hdf5" - } - } - -} diff --git a/applications/convert/examples/raw/make_boundary.json b/applications/convert/examples/raw/make_boundary.json deleted file mode 100644 index dceb25da3f..0000000000 --- a/applications/convert/examples/raw/make_boundary.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "input": [ - { - "file": "blub_open.msh", - "name_spec": "position" - } - ], - "tree": { - "position": { - "type": "boundary", - "dimension": 1 - } - }, - "output": { - "position": { - "file": "blub.hdf5", - "type": ".hdf5" - } - } -} diff --git a/applications/convert/examples/raw/merge_uv.json b/applications/convert/examples/raw/merge_uv.json deleted file mode 100644 index 30627f7585..0000000000 --- a/applications/convert/examples/raw/merge_uv.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "input": [ - { - "file": "_pos.msh", - "name_spec": "position" - }, - { - "file": "_tex.msh", - "name_spec": "uv" - } - ], - "tree": { - "position": "uv" - - }, - - "output": { - "file": "ogre.hdf5", - "type": ".hdf5" - } - - -} diff --git a/applications/convert/examples/raw/split_uv.json b/applications/convert/examples/raw/split_uv.json deleted file mode 100644 index 8628dea543..0000000000 --- a/applications/convert/examples/raw/split_uv.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "input": [ - { - "file": "unit_test/meshes/camel.msh", - "name_spec": "position" - }, - { - "file": "unit_test/meshes/cameluv.msh", - "name_spec": "uv" - } - ], - "tree": { - "position": "uv" - }, - "output": { - "position": { - "file": "ogre_pos.vtu", - "position_attribute": "vertices" - }, - "position.uv": { - "file": "ogre_uv.vtu", - "position_attribute": "vertices" - } - } -} From 241468dcd4ab43b7730110ab96cad32d14e9d2cf Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Mon, 11 Nov 2024 21:05:02 -0500 Subject: [PATCH 25/29] fixing camel split --- .../convert/examples/camel_split_uv.json | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/applications/convert/examples/camel_split_uv.json b/applications/convert/examples/camel_split_uv.json index e69de29bb2..1b75de3730 100644 --- a/applications/convert/examples/camel_split_uv.json +++ b/applications/convert/examples/camel_split_uv.json @@ -0,0 +1,34 @@ +{ + "input": { + "input": { + "file": "multimesh/camel.hdf5", + "name_spec": { + "position": "uv" + } + }, + "output": { + "position": { + "file": "camel_pos", + "position_attribute": "vertices", + "type": ".vtu" + }, + "position.uv": { + "file": "camel_uv", + "position_attribute": "vertices", + "type": ".vtu" + } + } + }, + "stats": { + "position": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + }, + "position.uv": { + "edges": 5607, + "faces": 3576, + "vertices": 2032 + } + } +} From f2be66e6e66d6b3c2f03959b3bed6727f3d2ee23 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Thu, 14 Nov 2024 15:02:28 -0500 Subject: [PATCH 26/29] updating path for diff versions of split_path --- .../src/wmtk/components/multimesh/MeshCollection.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index 2d0beaf61a..fa76195780 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -25,7 +25,12 @@ NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) const { using namespace std; - const auto nmm_name = *internal::split_path(path).begin(); +#if defined(WMTK_ENABLED_CPP20) + std::ranges::view auto split = internal::split_path(path); +#else + auto split = internal::split_path(path); +#endif + const auto nmm_name = *split.begin(); if (nmm_name.empty() && m_meshes.size() == 1) { wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " "assuming that is the right mesh"); From 87c1efe071a8b7d69b35fb089ad0b83429aa41d2 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 15 Nov 2024 12:33:35 -0500 Subject: [PATCH 27/29] removing spurious print statements --- src/wmtk/TriMesh.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/wmtk/TriMesh.cpp b/src/wmtk/TriMesh.cpp index 8895de510d..88a086433d 100644 --- a/src/wmtk/TriMesh.cpp +++ b/src/wmtk/TriMesh.cpp @@ -8,7 +8,7 @@ namespace wmtk { - TriMesh::~TriMesh() = default; +TriMesh::~TriMesh() = default; TriMesh::TriMesh() : MeshCRTP(2) , m_vf_handle(register_attribute_typed("m_vf", PrimitiveType::Vertex, 1, false, -1)) @@ -17,7 +17,6 @@ TriMesh::TriMesh() , m_fe_handle(register_attribute_typed("m_fe", PrimitiveType::Triangle, 3, false, -1)) , m_ff_handle(register_attribute_typed("m_ff", PrimitiveType::Triangle, 3, false, -1)) { - spdlog::warn("Trimesh constructor {}", fmt::ptr(this)); make_cached_accessors(); } @@ -33,7 +32,6 @@ void TriMesh::make_cached_accessors() TriMesh::TriMesh(TriMesh&& o) : MeshCRTP(std::move(o)) { - spdlog::warn("Trimesh constructor {}", fmt::ptr(this)); m_vf_handle = o.m_vf_handle; m_ef_handle = o.m_ef_handle; m_fv_handle = o.m_fv_handle; From 19f442899ee90ef0994e68c97187347058f1de6c Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 15 Nov 2024 12:36:37 -0500 Subject: [PATCH 28/29] missing cpp20 check --- .../components/multimesh/MeshCollection.cpp | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp index fa76195780..f9cc6cb773 100644 --- a/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/MeshCollection.cpp @@ -22,22 +22,6 @@ NamedMultiMesh& MeshCollection::add_mesh(NamedMultiMesh m) // } -const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) const -{ - using namespace std; -#if defined(WMTK_ENABLED_CPP20) - std::ranges::view auto split = internal::split_path(path); -#else - auto split = internal::split_path(path); -#endif - const auto nmm_name = *split.begin(); - if (nmm_name.empty() && m_meshes.size() == 1) { - wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " - "assuming that is the right mesh"); - return *m_meshes.begin()->second; - } - return *m_meshes.at(nmm_name); -} const Mesh& MeshCollection::get_mesh(const std::string_view& path) const { return get_named_multimesh(path).get_mesh(path); @@ -65,10 +49,32 @@ bool MeshCollection::has_mesh(const std::string_view& path) const } } +const NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) const +{ + using namespace std; +#if defined(WMTK_ENABLED_CPP20) + std::ranges::view auto split = internal::split_path(path); +#else + auto split = internal::split_path(path); +#endif + const auto nmm_name = *split.begin(); + if (nmm_name.empty() && m_meshes.size() == 1) { + wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " + "assuming that is the right mesh"); + return *m_meshes.begin()->second; + } + return *m_meshes.at(nmm_name); +} NamedMultiMesh& MeshCollection::get_named_multimesh(const std::string_view& path) { using namespace std; - const std::string_view nmm_name = *internal::split_path(path).begin(); + using namespace std; +#if defined(WMTK_ENABLED_CPP20) + std::ranges::view auto split = internal::split_path(path); +#else + auto split = internal::split_path(path); +#endif + const auto nmm_name = *split.begin(); if (nmm_name.empty() && m_meshes.size() == 1) { wmtk::logger().debug("MeshCollection accessed with an empty name, but has only 1 mesh so " "assuming that is the right mesh"); From b63a823926d01a71ac300668b445fee460a3a5c8 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Fri, 15 Nov 2024 17:34:42 -0500 Subject: [PATCH 29/29] giving up on string_view for now --- .../src/wmtk/components/multimesh/NamedMultiMesh.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp index 033ce4eeb8..defb15b2a8 100644 --- a/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp +++ b/components/multimesh/src/wmtk/components/multimesh/NamedMultiMesh.cpp @@ -35,7 +35,7 @@ struct NamedMultiMesh::Node std::string name; std::vector> m_children; - std::map m_child_indexer; + std::map m_child_indexer; void set_names(const nlohmann::json& js) { if (js.is_null()) { @@ -135,7 +135,7 @@ bool NamedMultiMesh::has_mesh(const std::string_view& path) const Node const* cur_mesh = m_name_root.get(); assert(*split.begin() == cur_mesh->name || *split.begin() == ""); for (const auto& token : std::ranges::views::drop(split, 1)) { - auto it = cur_mesh->m_child_indexer.find(token); + auto it = cur_mesh->m_child_indexer.find(std::string(token)); if (it == cur_mesh->m_child_indexer.end()) { return false; } else { @@ -157,7 +157,7 @@ auto NamedMultiMesh::get_id(const std::string_view& path) const -> std::vectorname || *split.begin() == ""); for (const auto& token : std::ranges::views::drop(split, 1)) { - int64_t index = cur_mesh->m_child_indexer.at(token); + int64_t index = cur_mesh->m_child_indexer.at(std::string(token)); indices.emplace_back(index); cur_mesh = cur_mesh->m_children[index].get(); } @@ -284,6 +284,5 @@ void NamedMultiMesh::append_child_mesh_names(const Mesh& parent, const NamedMult *cur_mesh->m_children[id] = *o.m_name_root; } cur_mesh->update_child_names(); - } } // namespace wmtk::components::multimesh