From 67db53f8c55cd83b24e15436fe855a164645870e Mon Sep 17 00:00:00 2001 From: Teseo Schneider Date: Mon, 15 Jan 2024 12:39:30 -0800 Subject: [PATCH 01/14] refactoing proj and envelope --- .../tests/test_component_wildmeshing.cpp | 2 +- .../wildmeshing/wildmeshing_spec.json | 2 +- src/wmtk/invariants/EnvelopeInvariant.cpp | 180 ++---------------- src/wmtk/invariants/EnvelopeInvariant.hpp | 28 +-- src/wmtk/invariants/InvariantCollection.cpp | 5 +- .../operations/composite/ProjectOperation.cpp | 54 +++--- .../operations/composite/ProjectOperation.hpp | 11 +- 7 files changed, 54 insertions(+), 228 deletions(-) diff --git a/components/tests/test_component_wildmeshing.cpp b/components/tests/test_component_wildmeshing.cpp index d2f82a4a8c..eaa1498e9b 100644 --- a/components/tests/test_component_wildmeshing.cpp +++ b/components/tests/test_component_wildmeshing.cpp @@ -29,7 +29,7 @@ TEST_CASE("wildmeshing", "[components][wildmeshing][.]") "passes": 10, "input": "mesh", "target_edge_length": 0.01, - "intermediate_output": true, + "intermediate_output": false, "attributes": {"position": "vertices"}, "pass_through": [], "output": "test", diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json index 5ed6598354..f73e2a968f 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json @@ -11,7 +11,7 @@ "pass_through", "passes", "target_edge_length", - "intermediate_output" + "intermediate_output", "track_boundary_child_mesh" ] }, diff --git a/src/wmtk/invariants/EnvelopeInvariant.cpp b/src/wmtk/invariants/EnvelopeInvariant.cpp index 242c96cd77..6425c8e9ec 100644 --- a/src/wmtk/invariants/EnvelopeInvariant.cpp +++ b/src/wmtk/invariants/EnvelopeInvariant.cpp @@ -12,151 +12,28 @@ namespace wmtk::invariants { -EnvelopeInvariant::EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - const Eigen::MatrixXd& vertices, - const Eigen::MatrixXi& faces, - double envelope_size) - : Invariant(m) - , m_coordinate_handle(coordinate) - , m_tag(tag) - , m_value(value) - , m_envelope_size(envelope_size) -{ - logger().warn("Envelope is using tag instead of mm"); - - if (faces.cols() == 3) { - std::vector verticesv(vertices.rows()); - std::vector facesv(faces.rows()); - - for (size_t i = 0; i < verticesv.size(); ++i) verticesv[i] = vertices.row(i); - for (size_t i = 0; i < facesv.size(); ++i) facesv[i] = faces.row(i); - - m_envelope = std::make_shared(verticesv, facesv, envelope_size); - - } else if (faces.cols() == 2) { - logger().warn("Envelope for edge mesh is using sampling"); - - m_bvh = std::make_shared(); - m_bvh->init(vertices, faces, 1e-10); - } else { - throw std::runtime_error("Envelope works only for tri meshes"); - } -} EnvelopeInvariant::EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - double envelope_size) - : Invariant(m) - , m_coordinate_handle(coordinate) - , m_tag(tag) - , m_value(value) + const attribute::MeshAttributeHandle& envelope_mesh_coordinate, + double envelope_size, + const attribute::MeshAttributeHandle& coordinate) + : Invariant(coordinate.mesh()) + , m_coordinate_handle(coordinate.as()) , m_envelope_size(envelope_size) { - logger().warn("Envelope is using tag instead of mm"); - - ConstAccessor accessor = mesh().create_accessor(m_coordinate_handle); - ConstAccessor tag_accessor = mesh().create_accessor(m_tag); - - - if (mesh().top_simplex_type() == PrimitiveType::Tetrahedron) { - std::vector vertices; - std::vector faces; - - int count = 0; - assert(accessor.dimension() == 3); - - const std::vector& facest = m.get_all(wmtk::PrimitiveType::Face); - for (const auto& f : facest) { - if (tag_accessor.const_scalar_attribute(f) != m_value) continue; - - - Eigen::Vector3d p0 = accessor.const_vector_attribute(f); - Eigen::Vector3d p1 = accessor.const_vector_attribute(mesh().switch_vertex(f)); - Eigen::Vector3d p2 = - accessor.const_vector_attribute(mesh().switch_vertex(mesh().switch_edge(f))); - - faces.emplace_back(count, count + 1, count + 2); - vertices.push_back(p0); - vertices.push_back(p1); - vertices.push_back(p2); - - count += 3; - } - - m_envelope = std::make_shared(vertices, faces, envelope_size); - - } else if (mesh().top_simplex_type() == PrimitiveType::Face) { - logger().warn("Envelope for edge mesh is using sampling"); - - - int64_t count = 0; - int64_t index = 0; - - const std::vector& edgest = m.get_all(wmtk::PrimitiveType::Edge); - - Eigen::MatrixXd vertices(2 * edgest.size(), accessor.dimension()); - Eigen::MatrixXi edges(edgest.size(), 2); - - for (const auto& e : edgest) { - if (tag_accessor.const_scalar_attribute(e) != m_value) continue; - - auto p0 = accessor.const_vector_attribute(e); - auto p1 = accessor.const_vector_attribute(mesh().switch_vertex(e)); - - edges.row(index) << count, count + 1; - vertices.row(2 * index) = p0; - vertices.row(2 * index + 1) = p1; - - count += 2; - ++index; - } - - edges.conservativeResize(index, 2); - vertices.conservativeResize(2 * index, vertices.cols()); - - m_bvh = std::make_shared(); - m_bvh->init(vertices, edges, 1e-10); - } else { - throw std::runtime_error("Envelope works only for tri meshes"); - } -} - - -EnvelopeInvariant::EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - const Mesh& envelope_mesh, - const TypedAttributeHandle& envelope_mesh_coordinate, - double envelope_size) - : Invariant(m) - , m_coordinate_handle(coordinate) - , m_tag(tag) - , m_value(value) - , m_envelope_size(envelope_size) -{ - logger().warn("Envelope is using tag instead of mm"); - - ConstAccessor accessor = envelope_mesh.create_accessor(envelope_mesh_coordinate); + const auto& envelope_mesh = envelope_mesh_coordinate.mesh(); + ConstAccessor accessor = + envelope_mesh.create_accessor(envelope_mesh_coordinate.as()); if (envelope_mesh.top_simplex_type() == PrimitiveType::Face) { std::vector vertices; std::vector faces; - int count = 0; assert(accessor.dimension() == 3); - const std::vector& facest = m.get_all(wmtk::PrimitiveType::Face); + const std::vector& facest = envelope_mesh.get_all(wmtk::PrimitiveType::Face); for (const auto& f : facest) { Eigen::Vector3d p0 = accessor.const_vector_attribute(f); Eigen::Vector3d p1 = accessor.const_vector_attribute(envelope_mesh.switch_vertex(f)); @@ -176,11 +53,10 @@ EnvelopeInvariant::EnvelopeInvariant( } else if (envelope_mesh.top_simplex_type() == PrimitiveType::Edge) { logger().warn("Envelope for edge mesh is using sampling"); - int64_t count = 0; int64_t index = 0; - const std::vector& edgest = m.get_all(wmtk::PrimitiveType::Edge); + const std::vector& edgest = envelope_mesh.get_all(wmtk::PrimitiveType::Edge); Eigen::MatrixXd vertices(2 * edgest.size(), accessor.dimension()); Eigen::MatrixXi edges(edgest.size(), 2); @@ -200,7 +76,7 @@ EnvelopeInvariant::EnvelopeInvariant( m_bvh = std::make_shared(); m_bvh->init(vertices, edges, 1e-10); } else { - throw std::runtime_error("Envelope works only for tri meshes"); + throw std::runtime_error("Envelope works only for tri/edges meshes"); } } @@ -209,29 +85,7 @@ bool EnvelopeInvariant::after( const std::vector& top_dimension_tuples_after) const { ConstAccessor accessor = mesh().create_accessor(m_coordinate_handle); - ConstAccessor tag_accessor = mesh().create_accessor(m_tag); - - ////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////// - // hack to use tags - simplex::SimplexCollection sc(mesh()); - const PrimitiveType type = static_cast(mesh().top_cell_dimension() - 1); - for (const auto& t : top_dimension_tuples_after) { - sc.add( - faces_single_dimension(mesh(), simplex::Simplex(mesh().top_simplex_type(), t), type)); - } - sc.sort_and_clean(); - const std::vector all_tuples = sc.simplex_vector_tuples(type); - std::vector tuples; - tuples.reserve(all_tuples.size()); - // filter based on tag - for (const Tuple& tuple : all_tuples) { - if (tag_accessor.const_scalar_attribute(tuple) == m_value) tuples.push_back(tuple); - } - if (tuples.empty()) return true; - ////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////// - + const auto type = mesh().top_simplex_type(); if (m_envelope) { assert(accessor.dimension() == 3); @@ -241,7 +95,7 @@ bool EnvelopeInvariant::after( if (type == PrimitiveType::Face) { std::array triangle; - for (const Tuple& tuple : tuples) { + for (const Tuple& tuple : top_dimension_tuples_after) { faces = faces_single_dimension_tuples( mesh(), simplex::Simplex(type, tuple), @@ -256,7 +110,7 @@ bool EnvelopeInvariant::after( return true; } else if (type == PrimitiveType::Edge) { - for (const Tuple& tuple : tuples) { + for (const Tuple& tuple : top_dimension_tuples_after) { faces = faces_single_dimension_tuples( mesh(), simplex::Simplex(type, tuple), @@ -270,7 +124,7 @@ bool EnvelopeInvariant::after( return true; } else if (type == PrimitiveType::Vertex) { - for (const Tuple& tuple : tuples) { + for (const Tuple& tuple : top_dimension_tuples_after) { Eigen::Vector3d p = accessor.const_vector_attribute(tuple); if (m_envelope->is_outside(p)) return false; @@ -294,7 +148,7 @@ bool EnvelopeInvariant::after( if (type == PrimitiveType::Edge) { std::vector pts; - for (const Tuple& tuple : tuples) { + for (const Tuple& tuple : top_dimension_tuples_after) { SimpleBVH::VectorMax3d p0 = accessor.const_vector_attribute(tuple); SimpleBVH::VectorMax3d p1 = accessor.const_vector_attribute(mesh().switch_vertex(tuple)); @@ -321,7 +175,7 @@ bool EnvelopeInvariant::after( return true; } else if (type == PrimitiveType::Vertex) { - for (const Tuple& tuple : tuples) { + for (const Tuple& tuple : top_dimension_tuples_after) { Eigen::Vector3d p = accessor.const_vector_attribute(tuple); m_bvh->nearest_facet(p, nearest_point, sq_dist); if (sq_dist > m_envelope_size * m_envelope_size) return false; diff --git a/src/wmtk/invariants/EnvelopeInvariant.hpp b/src/wmtk/invariants/EnvelopeInvariant.hpp index da4540d9cd..759dc4f107 100644 --- a/src/wmtk/invariants/EnvelopeInvariant.hpp +++ b/src/wmtk/invariants/EnvelopeInvariant.hpp @@ -19,29 +19,9 @@ class EnvelopeInvariant : public Invariant { public: EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - const Eigen::MatrixXd& vertices, - const Eigen::MatrixXi& faces, - double envelope_size); - - EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - const Mesh& envelope_mesh, - const TypedAttributeHandle& envelope_mesh_coordinate, - double envelope_size); - - EnvelopeInvariant( - const Mesh& m, - const TypedAttributeHandle& coordinate, - const TypedAttributeHandle& tag, - int64_t value, - double envelope_size); + const attribute::MeshAttributeHandle& envelope_mesh_coordinate, + double envelope_size, + const attribute::MeshAttributeHandle& coordinate); bool after( const std::vector& top_dimension_tuples_before, @@ -51,8 +31,6 @@ class EnvelopeInvariant : public Invariant std::shared_ptr m_envelope = nullptr; std::shared_ptr m_bvh = nullptr; const TypedAttributeHandle m_coordinate_handle; - const TypedAttributeHandle m_tag; - const int64_t m_value; const double m_envelope_size; }; } // namespace wmtk::invariants \ No newline at end of file diff --git a/src/wmtk/invariants/InvariantCollection.cpp b/src/wmtk/invariants/InvariantCollection.cpp index 534698b7eb..c9cd9cd915 100644 --- a/src/wmtk/invariants/InvariantCollection.cpp +++ b/src/wmtk/invariants/InvariantCollection.cpp @@ -57,10 +57,7 @@ bool InvariantCollection::after( continue; } auto map = [&](const auto& tuples) { - return mesh().map_tuples( - invariant->mesh(), - mesh().top_simplex_type(), - top_dimension_tuples_after); + return mesh().map_tuples(invariant->mesh(), mesh().top_simplex_type(), tuples); }; const std::vector mapped_tuples_after = invariant_uses_new_state ? map(top_dimension_tuples_after) : std::vector{}; diff --git a/src/wmtk/operations/composite/ProjectOperation.cpp b/src/wmtk/operations/composite/ProjectOperation.cpp index 3ae507d1f2..cbf83d2e34 100644 --- a/src/wmtk/operations/composite/ProjectOperation.cpp +++ b/src/wmtk/operations/composite/ProjectOperation.cpp @@ -6,37 +6,35 @@ #include namespace wmtk::operations::composite { + ProjectOperation::ProjectOperation( - Mesh& m, std::shared_ptr main_op, - const TypedAttributeHandle& coordinates, - const TypedAttributeHandle& proj_tag, - wmtk::PrimitiveType proj_type, - int64_t proj_value) + const attribute::MeshAttributeHandle& project_to_mesh, + Mesh& m, + attribute::MeshAttributeHandle& child_mesh_coordinates) : AttributesUpdate(m) , m_main_op(main_op) - , m_coordinates(coordinates) - , m_tag(proj_tag) - , m_tag_value(proj_value) + , m_coordinates(child_mesh_coordinates.as()) + , m_child_mesh(child_mesh_coordinates.mesh()) { int64_t count = 0; int64_t index = 0; - ConstAccessor accessor = mesh().create_accessor(m_coordinates); - ConstAccessor tag_accessor = mesh().create_accessor(m_tag); + ConstAccessor accessor = + project_to_mesh.mesh().create_accessor(project_to_mesh.as()); - const std::vector& facest = mesh().get_all(proj_type); - const int64_t dim = int64_t(proj_type) + 1; + const std::vector& facest = + project_to_mesh.mesh().get_all(project_to_mesh.mesh().top_simplex_type()); + + const int64_t dim = int64_t(project_to_mesh.mesh().top_simplex_type()) + 1; Eigen::MatrixXd vertices(dim * facest.size(), accessor.dimension()); Eigen::MatrixXi faces(facest.size(), dim); for (const auto& f : facest) { - if (tag_accessor.const_scalar_attribute(f) != m_tag_value) continue; - auto tmp = faces_single_dimension_tuples( - mesh(), - simplex::Simplex(proj_type, f), + project_to_mesh.mesh(), + simplex::Simplex(project_to_mesh.mesh().top_simplex_type(), f), PrimitiveType::Vertex); assert(tmp.size() == dim); @@ -49,9 +47,6 @@ ProjectOperation::ProjectOperation( } ++index; } - faces.conservativeResize(index, faces.cols()); - vertices.conservativeResize(2 * index, vertices.cols()); - m_bvh = std::make_shared(); m_bvh->init(vertices, faces, 1e-10); @@ -64,16 +59,21 @@ std::vector ProjectOperation::execute(const simplex::Simplex& assert(main_simplices.size() == 1); const auto main_tup = main_simplices.front().tuple(); - auto tag_accessor = mesh().create_accessor(m_tag); - auto accessor = mesh().create_accessor(m_coordinates); - if (tag_accessor.const_scalar_attribute(main_tup) != m_tag_value) return main_simplices; + const std::vector mapped_tuples_after = + mesh().map_tuples(m_child_mesh, mesh().top_simplex_type(), {main_tup}); + + if (mapped_tuples_after.empty()) return main_simplices; - auto p = accessor.const_vector_attribute(main_tup); - SimpleBVH::VectorMax3d nearest_point; - double sq_dist; - m_bvh->nearest_facet(p, nearest_point, sq_dist); - accessor.vector_attribute(main_tup) = nearest_point; + auto accessor = mesh().create_accessor(m_coordinates); + + for (const auto& t : mapped_tuples_after) { + auto p = accessor.const_vector_attribute(t); + SimpleBVH::VectorMax3d nearest_point; + double sq_dist; + m_bvh->nearest_facet(p, nearest_point, sq_dist); + accessor.vector_attribute(t) = nearest_point; + } return main_simplices; } diff --git a/src/wmtk/operations/composite/ProjectOperation.hpp b/src/wmtk/operations/composite/ProjectOperation.hpp index fb9c9f70ba..967fd0763e 100644 --- a/src/wmtk/operations/composite/ProjectOperation.hpp +++ b/src/wmtk/operations/composite/ProjectOperation.hpp @@ -13,12 +13,10 @@ class ProjectOperation : public AttributesUpdate { public: ProjectOperation( + std::shared_ptr main_op, + const attribute::MeshAttributeHandle& project_to_mesh, Mesh& m, - std::shared_ptr main_op, - const TypedAttributeHandle& coordinates, - const TypedAttributeHandle& proj_tag, - wmtk::PrimitiveType proj_type, - int64_t proj_value); + attribute::MeshAttributeHandle& child_mesh_coordinates); std::vector execute(const simplex::Simplex& simplex) override; PrimitiveType primitive_type() const override { return m_main_op->primitive_type(); } @@ -27,8 +25,7 @@ class ProjectOperation : public AttributesUpdate private: const std::shared_ptr m_main_op; const TypedAttributeHandle m_coordinates; - const TypedAttributeHandle m_tag; - const int64_t m_tag_value; + Mesh& m_child_mesh; std::shared_ptr m_bvh = nullptr; }; } // namespace wmtk::operations::composite From 3b988928df7d9953b5568ed17fde853ec4730384 Mon Sep 17 00:00:00 2001 From: JcDai Date: Mon, 15 Jan 2024 17:59:59 -0500 Subject: [PATCH 02/14] use new envelope based on multimesh --- .../components/wildmeshing/wildmeshing.cpp | 345 ++++++++++-------- src/wmtk/invariants/EnvelopeInvariant.cpp | 3 +- .../edge_mesh/EdgeOperationData.cpp | 2 +- .../edge_mesh/SplitNewAttributeTopoInfo.cpp | 2 +- 4 files changed, 193 insertions(+), 159 deletions(-) diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index 947abcc91d..f46faa0f5f 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -215,70 +215,105 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // logger().set_level(spdlog::level::level_enum::debug); ////////////////////////////////// - // register child mesh + // mm stuff to refactor + // const bool track_boundary = options.track_boundary_child_mesh; + // std::shared_ptr boundary_child_mesh_ptr; + + + // auto boundary_handle = + // mesh->register_attribute("is_boundary_old", boundary_pt, 1).as(); + // auto boundary_accessor = mesh->create_accessor(boundary_handle); + + // wmtk::attribute::MeshAttributeHandle boundary_child_mesh_position_handle; + + // for (const auto& tuple : mesh->get_all(boundary_pt)) { + // if (mesh->is_boundary(boundary_pt, tuple)) { + // boundary_accessor.scalar_attribute(tuple) = 1; + // } else { + // boundary_accessor.scalar_attribute(tuple) = 0; + // } + // } + + // if (track_boundary) { + // boundary_child_mesh_ptr = + // wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag( + // *mesh, + // "is_boundary", + // 1, + // boundary_pt); + + // // child mesh vertex position update + + // auto boundary_child_mesh_position_handle_register = + // boundary_child_mesh_ptr->register_attribute( + // "vertices", + // PrimitiveType::Vertex, + // 3); + // auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( + // boundary_child_mesh_position_handle_register.as()); + + // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { + // const auto parent_tuple = + // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); + // boundary_child_mesh_position_accessor.vector_attribute(t) = + // pt_accessor.vector_attribute(parent_tuple); + // } + + // wmtk::logger().info("boundary child mesh registered"); + // wmtk::logger().info( + // "boundary child mesh size: {}", + // boundary_child_mesh_ptr->get_all(boundary_pt).size()); + + // boundary_child_mesh_position_handle = + // boundary_child_mesh_ptr->get_attribute_handle( + // "vertices", + // PrimitiveType::Vertex); + // } + + // auto boundary_attribute = mesh->get_attribute_handle("is_boundary", boundary_pt); + // pass_through_attributes.push_back(boundary_attribute); - const bool track_boundary = options.track_boundary_child_mesh; - std::shared_ptr boundary_child_mesh_ptr; + ////////////////////////////////// + // is boundary tag for envelope and boundary child mesh const PrimitiveType boundary_pt = get_primitive_type_from_id(mesh->top_cell_dimension() - 1); - auto boundary_handle = - mesh->register_attribute("is_boundary", boundary_pt, 1).as(); - auto boundary_accessor = mesh->create_accessor(boundary_handle); - wmtk::attribute::MeshAttributeHandle boundary_child_mesh_position_handle; + auto is_boundary_handle = mesh->register_attribute("is_boundary", boundary_pt, 1); + auto is_boundary_accessor = mesh->create_accessor(is_boundary_handle.as()); - for (const auto& tuple : mesh->get_all(boundary_pt)) { - if (mesh->is_boundary(boundary_pt, tuple)) { - boundary_accessor.scalar_attribute(tuple) = 1; - } else { - boundary_accessor.scalar_attribute(tuple) = 0; - } + for (const auto& t : mesh->get_all(boundary_pt)) { + is_boundary_accessor.scalar_attribute(t) = mesh->is_boundary(boundary_pt, t) ? 1 : 0; } - if (track_boundary) { - boundary_child_mesh_ptr = wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag( - *mesh, - "is_boundary", - 1, - boundary_pt); - - // child mesh vertex position update - - auto boundary_child_mesh_position_handle_register = - boundary_child_mesh_ptr->register_attribute( - "vertices", - PrimitiveType::Vertex, - 3); - auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( - boundary_child_mesh_position_handle_register.as()); - - for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - const auto parent_tuple = - boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - boundary_child_mesh_position_accessor.vector_attribute(t) = - pt_accessor.vector_attribute(parent_tuple); - } + // pass through this attribute. this is not used anymore + pass_through_attributes.push_back(is_boundary_handle); - wmtk::logger().info("boundary child mesh registered"); - wmtk::logger().info( - "boundary child mesh size: {}", - boundary_child_mesh_ptr->get_all(boundary_pt).size()); - - boundary_child_mesh_position_handle = boundary_child_mesh_ptr->get_attribute_handle( - "vertices", - PrimitiveType::Vertex); + // extract envelope mesh, set coordinates attribute to it + auto envelope_mesh_ptr = wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag( + *mesh, + "is_boundary", + 1, + boundary_pt); + + auto envelope_position_handle = envelope_mesh_ptr->register_attribute( + "vertices", + PrimitiveType::Vertex, + mesh->top_cell_dimension()); + auto envelope_position_accessor = + envelope_mesh_ptr->create_accessor(envelope_position_handle.as()); + + for (const auto& t : envelope_mesh_ptr->get_all(PrimitiveType::Vertex)) { + const auto& parent_tuple = + envelope_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); + envelope_position_accessor.vector_attribute(t) = pt_accessor.vector_attribute(parent_tuple); } - auto boundary_attribute = mesh->get_attribute_handle("is_boundary", boundary_pt); - pass_through_attributes.push_back(boundary_attribute); + // tmp pass through position of envelope mesh + pass_through_attributes.push_back(envelope_position_handle); // Invariants - auto envelope_invariant = std::make_shared( - *mesh, - pt_attribute.as(), - edge_boundary_attribute.as(), - 1, - 1e-3); + auto envelope_invariant = + std::make_shared(envelope_position_handle, 1e-3, pt_attribute); auto inversion_invariant = std::make_shared(*mesh, pt_attribute.as()); @@ -309,9 +344,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // child boundary mesh // split->set_new_attribute_strategy(boundary_attribute); - if (track_boundary) { - split->set_new_attribute_strategy(boundary_child_mesh_position_handle); - } + // if (track_boundary) { + // split->set_new_attribute_strategy(boundary_child_mesh_position_handle); + // } split->add_transfer_strategy(edge_length_update); for (const auto& attr : pass_through_attributes) { @@ -326,11 +361,11 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c auto collapse = std::make_shared(*mesh); collapse->add_invariant(std::make_shared(*mesh)); - if (track_boundary) { - collapse->add_invariant(std::make_shared(*mesh)); - } else { - collapse->add_invariant(std::make_shared(*mesh)); - } + // if (track_boundary) { + // collapse->add_invariant(std::make_shared(*mesh)); + // } else { + // collapse->add_invariant(std::make_shared(*mesh)); + // } collapse->add_invariant( std::make_shared(*mesh, pt_attribute.as())); @@ -350,16 +385,17 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c collapse->set_new_attribute_strategy(pt_attribute, clps_strat); // child boundary mesh - if (track_boundary) { - auto clps_strat_child = std::make_shared>( - boundary_child_mesh_position_handle); - clps_strat_child->set_simplex_predicate(BasicSimplexPredicate::IsInterior); - clps_strat_child->set_strategy(CollapseBasicStrategy::Default); + // if (track_boundary) { + // auto clps_strat_child = std::make_shared>( + // boundary_child_mesh_position_handle); + // clps_strat_child->set_simplex_predicate(BasicSimplexPredicate::IsInterior); + // clps_strat_child->set_strategy(CollapseBasicStrategy::Default); - // collapse->set_new_attribute_strategy(boundary_attribute); + // // collapse->set_new_attribute_strategy(boundary_attribute); - collapse->set_new_attribute_strategy(boundary_child_mesh_position_handle, clps_strat_child); - } + // collapse->set_new_attribute_strategy(boundary_child_mesh_position_handle, + // clps_strat_child); + // } collapse->add_transfer_strategy(edge_length_update); collapse->set_new_attribute_strategy( @@ -370,12 +406,10 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c collapse->set_new_attribute_strategy(attr); } auto proj_collapse = std::make_shared( - *mesh, collapse, - pt_attribute.as(), - edge_boundary_attribute.as(), - static_cast(mesh->top_cell_dimension() - 1), - 1); + envelope_position_handle, + *mesh, + envelope_position_handle); proj_collapse->add_invariant(envelope_invariant); proj_collapse->add_invariant(inversion_invariant); proj_collapse->add_invariant(function_invariant); @@ -410,12 +444,12 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // child boundary mesh // swap->split().set_new_attribute_strategy(boundary_attribute); - if (track_boundary) { - swap->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - swap->collapse().set_new_attribute_strategy( - boundary_child_mesh_position_handle, - CollapseBasicStrategy::CopyOther); - } + // if (track_boundary) { + // swap->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); + // swap->collapse().set_new_attribute_strategy( + // boundary_child_mesh_position_handle, + // CollapseBasicStrategy::CopyOther); + // } swap->collapse().set_new_attribute_strategy(pt_attribute, CollapseBasicStrategy::CopyOther); @@ -455,12 +489,12 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - if (track_boundary) { - swap44->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - swap44->collapse().set_new_attribute_strategy( - boundary_child_mesh_position_handle, - CollapseBasicStrategy::CopyOther); - } + // if (track_boundary) { + // swap44->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); + // swap44->collapse().set_new_attribute_strategy( + // boundary_child_mesh_position_handle, + // CollapseBasicStrategy::CopyOther); + // } for (const auto& attr : pass_through_attributes) { swap44->split().set_new_attribute_strategy(attr); @@ -492,12 +526,12 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // swap44_2->split().set_new_attribute_strategy(boundary_attribute); // swap44_2->collapse().set_new_attribute_strategy(boundary_attribute); - if (track_boundary) { - swap44_2->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - swap44_2->collapse().set_new_attribute_strategy( - boundary_child_mesh_position_handle, - CollapseBasicStrategy::CopyOther); - } + // if (track_boundary) { + // swap44_2->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); + // swap44_2->collapse().set_new_attribute_strategy( + // boundary_child_mesh_position_handle, + // CollapseBasicStrategy::CopyOther); + // } swap44_2->split().set_new_attribute_strategy(pt_attribute); swap44_2->collapse().set_new_attribute_strategy( @@ -536,12 +570,12 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // swap32->split().set_new_attribute_strategy(boundary_attribute); // swap32->collapse().set_new_attribute_strategy(boundary_attribute); - if (track_boundary) { - swap32->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - swap32->collapse().set_new_attribute_strategy( - boundary_child_mesh_position_handle, - CollapseBasicStrategy::CopyOther); - } + // if (track_boundary) { + // swap32->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); + // swap32->collapse().set_new_attribute_strategy( + // boundary_child_mesh_position_handle, + // CollapseBasicStrategy::CopyOther); + // } for (const auto& attr : pass_through_attributes) { swap32->split().set_new_attribute_strategy(attr); @@ -574,12 +608,12 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // swap23->split().set_new_attribute_strategy(boundary_attribute); // swap23->collapse().set_new_attribute_strategy(boundary_attribute); - if (track_boundary) { - swap23->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - swap23->collapse().set_new_attribute_strategy( - boundary_child_mesh_position_handle, - CollapseBasicStrategy::CopyOther); - } + // if (track_boundary) { + // swap23->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); + // swap23->collapse().set_new_attribute_strategy( + // boundary_child_mesh_position_handle, + // CollapseBasicStrategy::CopyOther); + // } for (const auto& attr : pass_through_attributes) { swap23->split().set_new_attribute_strategy(attr); @@ -598,12 +632,10 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c auto smoothing = std::make_shared(energy); smoothing->add_invariant(inversion_invariant); auto proj_smoothing = std::make_shared( - *mesh, smoothing, - pt_attribute.as(), - edge_boundary_attribute.as(), - static_cast(mesh->top_cell_dimension() - 1), - 1); + envelope_position_handle, + *mesh, + envelope_position_handle); proj_smoothing->add_invariant(envelope_invariant); proj_smoothing->add_transfer_strategy(edge_length_update); proj_smoothing->use_random_priority() = true; @@ -620,30 +652,30 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c 0, options.intermediate_output); - if (track_boundary) { - // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; - // auto boundary_child_mesh_position_handle = - // boundary_child_mesh_ptr->get_attribute_handle("vertices", - // PrimitiveType::Vertex) - // .as(); - auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( - boundary_child_mesh_position_handle.as()); - - for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - const auto parent_tuple = - boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - boundary_child_mesh_position_accessor.vector_attribute(t) = - pt_accessor.vector_attribute(parent_tuple); - } - - write( - boundary_child_mesh_ptr, - paths.output_dir, - options.output + "_boundary", - options.attributes.position, - 0, - options.intermediate_output); - } + // if (track_boundary) { + // // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; + // // auto boundary_child_mesh_position_handle = + // // boundary_child_mesh_ptr->get_attribute_handle("vertices", + // // PrimitiveType::Vertex) + // // .as(); + // auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( + // boundary_child_mesh_position_handle.as()); + + // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { + // const auto parent_tuple = + // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); + // boundary_child_mesh_position_accessor.vector_attribute(t) = + // pt_accessor.vector_attribute(parent_tuple); + // } + + // write( + // boundary_child_mesh_ptr, + // paths.output_dir, + // options.output + "_boundary", + // options.attributes.position, + // 0, + // options.intermediate_output); + // } ////////////////////////////////// // Running all ops in order n times @@ -698,30 +730,31 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c assert(mesh->is_connectivity_valid()); - if (track_boundary) { - // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; - // auto boundary_child_mesh_position_handle = - // boundary_child_mesh_ptr - // ->get_attribute_handle("vertices", PrimitiveType::Vertex) - // .as(); - auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( - boundary_child_mesh_position_handle.as()); - - for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - const auto parent_tuple = - boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - boundary_child_mesh_position_accessor.vector_attribute(t) = - pt_accessor.vector_attribute(parent_tuple); - } - - write( - boundary_child_mesh_ptr, - paths.output_dir, - options.output + "_boundary", - options.attributes.position, - i + 1, - options.intermediate_output); - } + // if (track_boundary) { + // // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; + // // auto boundary_child_mesh_position_handle = + // // boundary_child_mesh_ptr + // // ->get_attribute_handle("vertices", PrimitiveType::Vertex) + // // .as(); + // auto boundary_child_mesh_position_accessor = + // boundary_child_mesh_ptr->create_accessor( + // boundary_child_mesh_position_handle.as()); + + // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { + // const auto parent_tuple = + // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); + // boundary_child_mesh_position_accessor.vector_attribute(t) = + // pt_accessor.vector_attribute(parent_tuple); + // } + + // write( + // boundary_child_mesh_ptr, + // paths.output_dir, + // options.output + "_boundary", + // options.attributes.position, + // i + 1, + // options.intermediate_output); + // } } } } // namespace wmtk::components diff --git a/src/wmtk/invariants/EnvelopeInvariant.cpp b/src/wmtk/invariants/EnvelopeInvariant.cpp index 6425c8e9ec..4508d692f5 100644 --- a/src/wmtk/invariants/EnvelopeInvariant.cpp +++ b/src/wmtk/invariants/EnvelopeInvariant.cpp @@ -85,7 +85,8 @@ bool EnvelopeInvariant::after( const std::vector& top_dimension_tuples_after) const { ConstAccessor accessor = mesh().create_accessor(m_coordinate_handle); - const auto type = mesh().top_simplex_type(); + // const auto type = mesh().top_simplex_type(); + const auto type = get_primitive_type_from_id(mesh().top_cell_dimension() - 1); if (m_envelope) { assert(accessor.dimension() == 3); diff --git a/src/wmtk/operations/edge_mesh/EdgeOperationData.cpp b/src/wmtk/operations/edge_mesh/EdgeOperationData.cpp index 81a68c8181..204e1bc74b 100644 --- a/src/wmtk/operations/edge_mesh/EdgeOperationData.cpp +++ b/src/wmtk/operations/edge_mesh/EdgeOperationData.cpp @@ -14,7 +14,7 @@ std::array EdgeOperationData::split_output_edges(const EdgeMesh& m) co { std::array r; for (size_t j = 0; j < 2; ++j) { - r[j] = tuple_from_id(m, PrimitiveType::Face, m_split_e[j]); + r[j] = tuple_from_id(m, PrimitiveType::Edge, m_split_e[j]); } return r; } diff --git a/src/wmtk/operations/edge_mesh/SplitNewAttributeTopoInfo.cpp b/src/wmtk/operations/edge_mesh/SplitNewAttributeTopoInfo.cpp index b36aadd63e..13ffc3dacc 100644 --- a/src/wmtk/operations/edge_mesh/SplitNewAttributeTopoInfo.cpp +++ b/src/wmtk/operations/edge_mesh/SplitNewAttributeTopoInfo.cpp @@ -58,7 +58,7 @@ std::vector> SplitNewAttributeTopoInfo::output_split_simpli return m_mesh.parent_scope([&]() -> std::vector> { switch (get_primitive_type_id(pt)) { case 0: { - return {ret_data.input_endpoints(m_mesh)}; + return {}; } case 1: { return {ret_data.split_output_edges(m_mesh)}; From 8441f5dd20203d6990c5adf0570a9010bd56cbb0 Mon Sep 17 00:00:00 2001 From: JcDai Date: Mon, 15 Jan 2024 21:42:41 -0500 Subject: [PATCH 03/14] disable multimesh tmp --- .../components/wildmeshing/wildmeshing.cpp | 320 +++++------------- 1 file changed, 84 insertions(+), 236 deletions(-) diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index f46faa0f5f..a0e42be80b 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -104,18 +104,18 @@ void write( } } -std::shared_ptr> -keep_tag_strategy(Mesh& m, const attribute::MeshAttributeHandle& attr, int64_t value) -{ - auto strat = std::make_shared>(attr); - strat->set_simplex_predicate([&m, attr, value](const simplex::Simplex& s) -> bool { - auto acc = m.create_accessor(attr); - return acc.const_scalar_attribute(s.tuple()) != value; - }); - strat->set_strategy(operations::CollapseBasicStrategy::Default); - - return strat; -} +// std::shared_ptr> +// keep_tag_strategy(Mesh& m, const attribute::MeshAttributeHandle& attr, int64_t value) +// { +// auto strat = std::make_shared>(attr); +// strat->set_simplex_predicate([&m, attr, value](const simplex::Simplex& s) -> bool { +// auto acc = m.create_accessor(attr); +// return acc.const_scalar_attribute(s.tuple()) != value; +// }); +// strat->set_strategy(operations::CollapseBasicStrategy::Default); + +// return strat; +// } } // namespace @@ -134,9 +134,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c auto edge_length_accessor = mesh->create_accessor(edge_length_attribute.as()); ////////////////////////////////// - auto edge_boundary_attribute = - mesh->register_attribute("edge_boundary", PrimitiveType::Edge, 1); - auto edge_boundary_accessor = mesh->create_accessor(edge_boundary_attribute.as()); + // auto edge_boundary_attribute = + // mesh->register_attribute("edge_boundary", PrimitiveType::Edge, 1); + // auto edge_boundary_accessor = mesh->create_accessor(edge_boundary_attribute.as()); ////////////////////////////////// @@ -165,7 +165,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c const auto p1 = pt_accessor.vector_attribute(mesh->switch_vertex(e)); edge_length_accessor.scalar_attribute(e) = (p0 - p1).norm(); - edge_boundary_accessor.scalar_attribute(e) = mesh->is_boundary(Simplex::edge(e)) ? 1 : 0; + // edge_boundary_accessor.scalar_attribute(e) = mesh->is_boundary(Simplex::edge(e)) ? 1 : 0; } @@ -215,66 +215,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // logger().set_level(spdlog::level::level_enum::debug); ////////////////////////////////// - // mm stuff to refactor - // const bool track_boundary = options.track_boundary_child_mesh; - // std::shared_ptr boundary_child_mesh_ptr; - - - // auto boundary_handle = - // mesh->register_attribute("is_boundary_old", boundary_pt, 1).as(); - // auto boundary_accessor = mesh->create_accessor(boundary_handle); - - // wmtk::attribute::MeshAttributeHandle boundary_child_mesh_position_handle; - - // for (const auto& tuple : mesh->get_all(boundary_pt)) { - // if (mesh->is_boundary(boundary_pt, tuple)) { - // boundary_accessor.scalar_attribute(tuple) = 1; - // } else { - // boundary_accessor.scalar_attribute(tuple) = 0; - // } - // } - - // if (track_boundary) { - // boundary_child_mesh_ptr = - // wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag( - // *mesh, - // "is_boundary", - // 1, - // boundary_pt); - - // // child mesh vertex position update - - // auto boundary_child_mesh_position_handle_register = - // boundary_child_mesh_ptr->register_attribute( - // "vertices", - // PrimitiveType::Vertex, - // 3); - // auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( - // boundary_child_mesh_position_handle_register.as()); - - // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - // const auto parent_tuple = - // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - // boundary_child_mesh_position_accessor.vector_attribute(t) = - // pt_accessor.vector_attribute(parent_tuple); - // } - - // wmtk::logger().info("boundary child mesh registered"); - // wmtk::logger().info( - // "boundary child mesh size: {}", - // boundary_child_mesh_ptr->get_all(boundary_pt).size()); - - // boundary_child_mesh_position_handle = - // boundary_child_mesh_ptr->get_attribute_handle( - // "vertices", - // PrimitiveType::Vertex); - // } - - // auto boundary_attribute = mesh->get_attribute_handle("is_boundary", boundary_pt); - // pass_through_attributes.push_back(boundary_attribute); - - ////////////////////////////////// - // is boundary tag for envelope and boundary child mesh + // is_boundary tag for envelope and boundary child mesh const PrimitiveType boundary_pt = get_primitive_type_from_id(mesh->top_cell_dimension() - 1); @@ -311,6 +252,28 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c // tmp pass through position of envelope mesh pass_through_attributes.push_back(envelope_position_handle); + // child mesh postion update + + // auto propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::MatrixXd { return P; }; + + // auto envelope_position_update = + // std::make_shared>( + // envelope_position_handle, + // pt_attribute, + // propagate_position); + + // auto compute_edge_length = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { + // assert(P.cols() == 2); + // assert(P.rows() == 2 || P.rows() == 3); + // return Eigen::VectorXd::Constant(1, (P.col(0) - P.col(1)).norm()); + // }; + // auto edge_length_update = + // std::make_shared>( + // edge_length_attribute, + // pt_attribute, + // compute_edge_length); + + ////////////////////////////////// // Invariants auto envelope_invariant = std::make_shared(envelope_position_handle, 1e-3, pt_attribute); @@ -336,23 +299,16 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c edge_length_attribute.as(), 4.0 / 3.0 * target_edge_length)); split->set_priority(long_edges_first); - split->set_new_attribute_strategy( - edge_boundary_attribute, - wmtk::operations::SplitBasicStrategy::Copy, - wmtk::operations::SplitRibBasicStrategy::None); - split->set_new_attribute_strategy(pt_attribute); - // child boundary mesh - // split->set_new_attribute_strategy(boundary_attribute); - // if (track_boundary) { - // split->set_new_attribute_strategy(boundary_child_mesh_position_handle); - // } + split->set_new_attribute_strategy(pt_attribute); split->add_transfer_strategy(edge_length_update); + // split->add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { split->set_new_attribute_strategy(attr); } - split->add_transfer_strategy(edge_length_update); + ops.emplace_back(split); ops_name.emplace_back("split"); @@ -361,46 +317,26 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c auto collapse = std::make_shared(*mesh); collapse->add_invariant(std::make_shared(*mesh)); - // if (track_boundary) { - // collapse->add_invariant(std::make_shared(*mesh)); - // } else { - // collapse->add_invariant(std::make_shared(*mesh)); - // } - - collapse->add_invariant( - std::make_shared(*mesh, pt_attribute.as())); + // collapse->add_invariant( + // std::make_shared(*mesh, pt_attribute.as())); // collapse->add_invariant(std::make_shared(mesh->top_simplex_type(), // amips)); - collapse->add_invariant( - std::make_shared(mesh->top_simplex_type(), amips)); - collapse->add_invariant(std::make_shared( - *mesh, - edge_length_attribute.as(), - 4.0 / 5.0 * target_edge_length)); - collapse->set_priority(short_edges_first); + // collapse->add_invariant( + // std::make_shared(mesh->top_simplex_type(), amips)); + // collapse->add_invariant(std::make_shared( + // *mesh, + // edge_length_attribute.as(), + // 4.0 / 5.0 * target_edge_length)); + // collapse->set_priority(short_edges_first); auto clps_strat = std::make_shared>(pt_attribute); clps_strat->set_simplex_predicate(BasicSimplexPredicate::IsInterior); clps_strat->set_strategy(CollapseBasicStrategy::Default); collapse->set_new_attribute_strategy(pt_attribute, clps_strat); - // child boundary mesh - - // if (track_boundary) { - // auto clps_strat_child = std::make_shared>( - // boundary_child_mesh_position_handle); - // clps_strat_child->set_simplex_predicate(BasicSimplexPredicate::IsInterior); - // clps_strat_child->set_strategy(CollapseBasicStrategy::Default); - // // collapse->set_new_attribute_strategy(boundary_attribute); + // collapse->add_transfer_strategy(edge_length_update); + // collapse->add_transfer_strategy(envelope_position_update); - // collapse->set_new_attribute_strategy(boundary_child_mesh_position_handle, - // clps_strat_child); - // } - - collapse->add_transfer_strategy(edge_length_update); - collapse->set_new_attribute_strategy( - edge_boundary_attribute, - keep_tag_strategy(*mesh, edge_boundary_attribute, 1)); collapse->add_invariant(inversion_invariant); for (const auto& attr : pass_through_attributes) { collapse->set_new_attribute_strategy(attr); @@ -419,6 +355,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c 4.0 / 5.0 * target_edge_length)); proj_collapse->set_priority(short_edges_first); proj_collapse->add_transfer_strategy(edge_length_update); + // proj_collapse->add_transfer_strategy(envelope_position_update); + ops.emplace_back(proj_collapse); ops_name.emplace_back("collapse"); @@ -432,29 +370,13 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap->add_invariant(function_invariant); swap->set_priority(long_edges_first); - swap->collapse().set_new_attribute_strategy( - edge_boundary_attribute, - keep_tag_strategy(*mesh, edge_boundary_attribute, 1)); - swap->split().set_new_attribute_strategy( - edge_boundary_attribute, - wmtk::operations::SplitBasicStrategy::None, - wmtk::operations::SplitRibBasicStrategy::None); - swap->split().set_new_attribute_strategy(pt_attribute); - // child boundary mesh - // swap->split().set_new_attribute_strategy(boundary_attribute); - // if (track_boundary) { - // swap->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - // swap->collapse().set_new_attribute_strategy( - // boundary_child_mesh_position_handle, - // CollapseBasicStrategy::CopyOther); - // } - swap->collapse().set_new_attribute_strategy(pt_attribute, CollapseBasicStrategy::CopyOther); - // child boundary mesh - // swap->collapse().set_new_attribute_strategy(boundary_attribute); + // swap->split().add_transfer_strategy(envelope_position_update); + // swap->collapse().add_transfer_strategy(envelope_position_update); + swap->add_transfer_strategy(edge_length_update); @@ -480,21 +402,14 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44->collapse().set_new_attribute_strategy(edge_length_attribute); swap44->split().set_new_attribute_strategy(edge_length_attribute); - // multimesh - // swap44->split().set_new_attribute_strategy(boundary_attribute); - // swap44->collapse().set_new_attribute_strategy(boundary_attribute); swap44->split().set_new_attribute_strategy(pt_attribute); swap44->collapse().set_new_attribute_strategy( pt_attribute, CollapseBasicStrategy::CopyOther); - // if (track_boundary) { - // swap44->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - // swap44->collapse().set_new_attribute_strategy( - // boundary_child_mesh_position_handle, - // CollapseBasicStrategy::CopyOther); - // } + // swap44->split().add_transfer_strategy(envelope_position_update); + // swap44->collapse().add_transfer_strategy(envelope_position_update); for (const auto& attr : pass_through_attributes) { swap44->split().set_new_attribute_strategy(attr); @@ -522,22 +437,14 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44_2->collapse().set_new_attribute_strategy(edge_length_attribute); swap44_2->split().set_new_attribute_strategy(edge_length_attribute); - // multimesh - // swap44_2->split().set_new_attribute_strategy(boundary_attribute); - // swap44_2->collapse().set_new_attribute_strategy(boundary_attribute); - - // if (track_boundary) { - // swap44_2->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - // swap44_2->collapse().set_new_attribute_strategy( - // boundary_child_mesh_position_handle, - // CollapseBasicStrategy::CopyOther); - // } - swap44_2->split().set_new_attribute_strategy(pt_attribute); swap44_2->collapse().set_new_attribute_strategy( pt_attribute, CollapseBasicStrategy::CopyOther); + // swap44_2->split().add_transfer_strategy(envelope_position_update); + // swap44_2->collapse().add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { swap44_2->split().set_new_attribute_strategy(attr); swap44_2->collapse().set_new_attribute_strategy(attr); @@ -566,16 +473,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // multimesh - // swap32->split().set_new_attribute_strategy(boundary_attribute); - // swap32->collapse().set_new_attribute_strategy(boundary_attribute); - - // if (track_boundary) { - // swap32->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - // swap32->collapse().set_new_attribute_strategy( - // boundary_child_mesh_position_handle, - // CollapseBasicStrategy::CopyOther); - // } + // swap32->split().add_transfer_strategy(envelope_position_update); + // swap32->collapse().add_transfer_strategy(envelope_position_update); for (const auto& attr : pass_through_attributes) { swap32->split().set_new_attribute_strategy(attr); @@ -604,16 +503,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // multimesh - // swap23->split().set_new_attribute_strategy(boundary_attribute); - // swap23->collapse().set_new_attribute_strategy(boundary_attribute); - - // if (track_boundary) { - // swap23->split().set_new_attribute_strategy(boundary_child_mesh_position_handle); - // swap23->collapse().set_new_attribute_strategy( - // boundary_child_mesh_position_handle, - // CollapseBasicStrategy::CopyOther); - // } + // swap23->split().add_transfer_strategy(envelope_position_update); + // swap23->collapse().add_transfer_strategy(envelope_position_update); for (const auto& attr : pass_through_attributes) { swap23->split().set_new_attribute_strategy(attr); @@ -638,6 +529,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c envelope_position_handle); proj_smoothing->add_invariant(envelope_invariant); proj_smoothing->add_transfer_strategy(edge_length_update); + // proj_smoothing->add_transfer_strategy(envelope_position_update); proj_smoothing->use_random_priority() = true; proj_smoothing->add_invariant(inversion_invariant); ops.push_back(proj_smoothing); @@ -652,30 +544,14 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c 0, options.intermediate_output); - // if (track_boundary) { - // // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; - // // auto boundary_child_mesh_position_handle = - // // boundary_child_mesh_ptr->get_attribute_handle("vertices", - // // PrimitiveType::Vertex) - // // .as(); - // auto boundary_child_mesh_position_accessor = boundary_child_mesh_ptr->create_accessor( - // boundary_child_mesh_position_handle.as()); - - // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - // const auto parent_tuple = - // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - // boundary_child_mesh_position_accessor.vector_attribute(t) = - // pt_accessor.vector_attribute(parent_tuple); - // } - - // write( - // boundary_child_mesh_ptr, - // paths.output_dir, - // options.output + "_boundary", - // options.attributes.position, - // 0, - // options.intermediate_output); - // } + write( + envelope_mesh_ptr, + paths.output_dir, + options.output + "_boundary", + options.attributes.position, + 0, + options.intermediate_output); + ////////////////////////////////// // Running all ops in order n times @@ -699,16 +575,6 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c stats.sorting_time, stats.executing_time); ++jj; - - - // write( - // mesh, - // paths.output_dir, - // options.output, - // options.attributes.position, - // iii, - // options.intermediate_output); - // ++iii; }; logger().info( @@ -730,31 +596,13 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c assert(mesh->is_connectivity_valid()); - // if (track_boundary) { - // // auto boundary_child_mesh_ptr = mesh.get_child_meshes()[0]; - // // auto boundary_child_mesh_position_handle = - // // boundary_child_mesh_ptr - // // ->get_attribute_handle("vertices", PrimitiveType::Vertex) - // // .as(); - // auto boundary_child_mesh_position_accessor = - // boundary_child_mesh_ptr->create_accessor( - // boundary_child_mesh_position_handle.as()); - - // for (const auto& t : boundary_child_mesh_ptr->get_all(PrimitiveType::Vertex)) { - // const auto parent_tuple = - // boundary_child_mesh_ptr->map_to_parent_tuple(simplex::Simplex::vertex(t)); - // boundary_child_mesh_position_accessor.vector_attribute(t) = - // pt_accessor.vector_attribute(parent_tuple); - // } - - // write( - // boundary_child_mesh_ptr, - // paths.output_dir, - // options.output + "_boundary", - // options.attributes.position, - // i + 1, - // options.intermediate_output); - // } + write( + envelope_mesh_ptr, + paths.output_dir, + options.output + "_boundary", + options.attributes.position, + i + 1, + options.intermediate_output); } } } // namespace wmtk::components From 5c557f422cd821228b94256a8b99270ef587fa1d Mon Sep 17 00:00:00 2001 From: JcDai Date: Tue, 16 Jan 2024 21:45:03 -0500 Subject: [PATCH 04/14] fix a lot --- .../tests/test_component_wildmeshing.cpp | 8 +- .../components/wildmeshing/wildmeshing.cpp | 98 +++++++++++-------- src/wmtk/invariants/EnvelopeInvariant.cpp | 5 +- src/wmtk/operations/Operation.cpp | 24 ++++- .../AttributeTransferStrategy.hpp | 1 + .../operations/composite/ProjectOperation.cpp | 4 +- ...UpdateEdgeOperationMultiMeshMapFunctor.cpp | 1 + 7 files changed, 90 insertions(+), 51 deletions(-) diff --git a/components/tests/test_component_wildmeshing.cpp b/components/tests/test_component_wildmeshing.cpp index eaa1498e9b..966f55c20b 100644 --- a/components/tests/test_component_wildmeshing.cpp +++ b/components/tests/test_component_wildmeshing.cpp @@ -29,14 +29,13 @@ TEST_CASE("wildmeshing", "[components][wildmeshing][.]") "passes": 10, "input": "mesh", "target_edge_length": 0.01, - "intermediate_output": false, + "intermediate_output": true, "attributes": {"position": "vertices"}, "pass_through": [], "output": "test", "track_boundary_child_mesh": false })"_json; - CHECK_NOTHROW(wmtk::components::wildmeshing(Paths(), input, cache)); } @@ -49,7 +48,8 @@ TEST_CASE("wildmeshing_3d", "[components][wildmeshing][.]") {"name", "mesh"}, // {"input", data_dir / "sphere_coarse_.msh"}, // {"input", data_dir / "tet.msh"}, - {"file", data_dir / "sphere_coarse_005_.msh"}, + // {"file", data_dir / "sphere_coarse_005_.msh"}, + {"file", data_dir / "cube_2.msh"}, {"ignore_z", false}}; wmtk::components::input(Paths(), input_component_json, cache); @@ -58,7 +58,7 @@ TEST_CASE("wildmeshing_3d", "[components][wildmeshing][.]") json input = { {"passes", 10}, {"input", "mesh"}, - {"target_edge_length", 0.1}, + {"target_edge_length", 0.05}, {"intermediate_output", true}, {"output", "test_mm"}, {"track_boundary_child_mesh", false}, diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index a0e42be80b..200896587b 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -250,33 +250,34 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c } // tmp pass through position of envelope mesh - pass_through_attributes.push_back(envelope_position_handle); + // pass_through_attributes.push_back(envelope_position_handle); // child mesh postion update - // auto propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::MatrixXd { return P; }; - - // auto envelope_position_update = - // std::make_shared>( - // envelope_position_handle, - // pt_attribute, - // propagate_position); - - // auto compute_edge_length = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { - // assert(P.cols() == 2); - // assert(P.rows() == 2 || P.rows() == 3); - // return Eigen::VectorXd::Constant(1, (P.col(0) - P.col(1)).norm()); - // }; - // auto edge_length_update = - // std::make_shared>( - // edge_length_attribute, - // pt_attribute, - // compute_edge_length); + auto propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { return P; }; + + auto envelope_position_update = + std::make_shared>( + envelope_position_handle, + pt_attribute, + propagate_position); + + auto reverse_propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { + return P.col(0); + }; + + auto projection_position_update = + std::make_shared>( + pt_attribute, + envelope_position_handle, + reverse_propagate_position); ////////////////////////////////// // Invariants - auto envelope_invariant = - std::make_shared(envelope_position_handle, 1e-3, pt_attribute); + auto envelope_invariant = std::make_shared( + envelope_position_handle, + 1e-3, + envelope_position_handle); auto inversion_invariant = std::make_shared(*mesh, pt_attribute.as()); @@ -301,9 +302,10 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c split->set_priority(long_edges_first); split->set_new_attribute_strategy(pt_attribute); + split->set_new_attribute_strategy(envelope_position_handle); split->add_transfer_strategy(edge_length_update); - // split->add_transfer_strategy(envelope_position_update); + split->add_transfer_strategy(envelope_position_update); for (const auto& attr : pass_through_attributes) { split->set_new_attribute_strategy(attr); @@ -333,14 +335,13 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c clps_strat->set_simplex_predicate(BasicSimplexPredicate::IsInterior); clps_strat->set_strategy(CollapseBasicStrategy::Default); collapse->set_new_attribute_strategy(pt_attribute, clps_strat); - - // collapse->add_transfer_strategy(edge_length_update); - // collapse->add_transfer_strategy(envelope_position_update); + collapse->set_new_attribute_strategy(envelope_position_handle); collapse->add_invariant(inversion_invariant); for (const auto& attr : pass_through_attributes) { collapse->set_new_attribute_strategy(attr); } + collapse->add_transfer_strategy(envelope_position_update); auto proj_collapse = std::make_shared( collapse, envelope_position_handle, @@ -355,7 +356,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c 4.0 / 5.0 * target_edge_length)); proj_collapse->set_priority(short_edges_first); proj_collapse->add_transfer_strategy(edge_length_update); - // proj_collapse->add_transfer_strategy(envelope_position_update); + + proj_collapse->add_transfer_strategy(projection_position_update); ops.emplace_back(proj_collapse); ops_name.emplace_back("collapse"); @@ -374,18 +376,19 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap->collapse().set_new_attribute_strategy(pt_attribute, CollapseBasicStrategy::CopyOther); - // swap->split().add_transfer_strategy(envelope_position_update); - // swap->collapse().add_transfer_strategy(envelope_position_update); - + swap->split().set_new_attribute_strategy(envelope_position_handle); + swap->collapse().set_new_attribute_strategy(envelope_position_handle); swap->add_transfer_strategy(edge_length_update); + for (const auto& attr : pass_through_attributes) { swap->split().set_new_attribute_strategy(attr); swap->collapse().set_new_attribute_strategy(attr); } swap->add_transfer_strategy(edge_length_update); + swap->add_transfer_strategy(envelope_position_update); ops.push_back(swap); ops_name.push_back("swap"); @@ -408,8 +411,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // swap44->split().add_transfer_strategy(envelope_position_update); - // swap44->collapse().add_transfer_strategy(envelope_position_update); + swap44->split().set_new_attribute_strategy(envelope_position_handle); + swap44->collapse().set_new_attribute_strategy(envelope_position_handle); for (const auto& attr : pass_through_attributes) { swap44->split().set_new_attribute_strategy(attr); @@ -417,6 +420,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c } swap44->add_transfer_strategy(edge_length_update); + swap44->add_transfer_strategy(envelope_position_update); ops.push_back(swap44); ops_name.push_back("swap44"); @@ -442,8 +446,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // swap44_2->split().add_transfer_strategy(envelope_position_update); - // swap44_2->collapse().add_transfer_strategy(envelope_position_update); + swap44_2->split().set_new_attribute_strategy(envelope_position_handle); + swap44_2->collapse().set_new_attribute_strategy(envelope_position_handle); + for (const auto& attr : pass_through_attributes) { swap44_2->split().set_new_attribute_strategy(attr); @@ -451,6 +456,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c } swap44_2->add_transfer_strategy(edge_length_update); + swap44_2->add_transfer_strategy(envelope_position_update); ops.push_back(swap44_2); ops_name.push_back("swap44_2"); @@ -473,8 +479,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // swap32->split().add_transfer_strategy(envelope_position_update); - // swap32->collapse().add_transfer_strategy(envelope_position_update); + swap32->split().set_new_attribute_strategy(envelope_position_handle); + swap32->collapse().set_new_attribute_strategy(envelope_position_handle); for (const auto& attr : pass_through_attributes) { swap32->split().set_new_attribute_strategy(attr); @@ -482,6 +488,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c } swap32->add_transfer_strategy(edge_length_update); + swap32->add_transfer_strategy(envelope_position_update); + ops.push_back(swap32); ops_name.push_back("swap32"); @@ -503,8 +511,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pt_attribute, CollapseBasicStrategy::CopyOther); - // swap23->split().add_transfer_strategy(envelope_position_update); - // swap23->collapse().add_transfer_strategy(envelope_position_update); + swap23->split().set_new_attribute_strategy(envelope_position_handle); + swap23->collapse().set_new_attribute_strategy(envelope_position_handle); for (const auto& attr : pass_through_attributes) { swap23->split().set_new_attribute_strategy(attr); @@ -512,6 +520,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c } swap23->add_transfer_strategy(edge_length_update); + swap23->add_transfer_strategy(envelope_position_update); ops.push_back(swap23); ops_name.push_back("swap23"); @@ -522,6 +531,7 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c std::make_shared(*mesh, pt_attribute, *amips); auto smoothing = std::make_shared(energy); smoothing->add_invariant(inversion_invariant); + smoothing->add_transfer_strategy(envelope_position_update); auto proj_smoothing = std::make_shared( smoothing, envelope_position_handle, @@ -529,11 +539,19 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c envelope_position_handle); proj_smoothing->add_invariant(envelope_invariant); proj_smoothing->add_transfer_strategy(edge_length_update); - // proj_smoothing->add_transfer_strategy(envelope_position_update); + proj_smoothing->add_transfer_strategy(projection_position_update); proj_smoothing->use_random_priority() = true; proj_smoothing->add_invariant(inversion_invariant); - ops.push_back(proj_smoothing); - ops_name.push_back("smoothing"); + // ops.push_back(proj_smoothing); + + // smoothing->add_invariant(envelope_invariant); + // smoothing->add_transfer_strategy(edge_length_update); + // smoothing->add_transfer_strategy(projection_position_update); + // smoothing->use_random_priority() = true; + // smoothing->add_invariant(inversion_invariant); + // ops.push_back(smoothing); + + // ops_name.push_back("smoothing"); write( diff --git a/src/wmtk/invariants/EnvelopeInvariant.cpp b/src/wmtk/invariants/EnvelopeInvariant.cpp index 4508d692f5..454226f296 100644 --- a/src/wmtk/invariants/EnvelopeInvariant.cpp +++ b/src/wmtk/invariants/EnvelopeInvariant.cpp @@ -84,9 +84,10 @@ bool EnvelopeInvariant::after( const std::vector& top_dimension_tuples_before, const std::vector& top_dimension_tuples_after) const { + if (top_dimension_tuples_after.empty()) return true; + ConstAccessor accessor = mesh().create_accessor(m_coordinate_handle); - // const auto type = mesh().top_simplex_type(); - const auto type = get_primitive_type_from_id(mesh().top_cell_dimension() - 1); + const auto type = mesh().top_simplex_type(); if (m_envelope) { assert(accessor.dimension() == 3); diff --git a/src/wmtk/operations/Operation.cpp b/src/wmtk/operations/Operation.cpp index 806e6d18b6..af6526c6b0 100644 --- a/src/wmtk/operations/Operation.cpp +++ b/src/wmtk/operations/Operation.cpp @@ -112,10 +112,28 @@ void Operation::apply_attribute_transfer(const std::vector& di for (const auto& s : direct_mods) { all.add(simplex::closed_star(m_mesh, s)); } + all.sort_and_clean(); for (const auto& at_ptr : m_attr_transfer_strategies) { - for (const auto& s : all.simplex_vector()) { - if (s.primitive_type() == at_ptr->primitive_type()) { - at_ptr->run(s); + if (&m_mesh == &(at_ptr->mesh())) { + for (const auto& s : all.simplex_vector()) { + if (s.primitive_type() == at_ptr->primitive_type()) { + at_ptr->run(s); + } + } + } else { + auto& at_mesh = at_ptr->mesh(); + auto at_mesh_simplices = m_mesh.map(at_mesh, direct_mods); + simplex::SimplexCollection at_mesh_all(at_mesh); + for (const auto& s : at_mesh_simplices) { + at_mesh_all.add(simplex::closed_star(at_mesh, s)); + } + + at_mesh_all.sort_and_clean(); + + for (const auto& s : at_mesh_all.simplex_vector()) { + if (s.primitive_type() == at_ptr->primitive_type()) { + at_ptr->run(s); + } } } } diff --git a/src/wmtk/operations/attribute_update/AttributeTransferStrategy.hpp b/src/wmtk/operations/attribute_update/AttributeTransferStrategy.hpp index 3e29408548..ebf0467c3d 100644 --- a/src/wmtk/operations/attribute_update/AttributeTransferStrategy.hpp +++ b/src/wmtk/operations/attribute_update/AttributeTransferStrategy.hpp @@ -140,6 +140,7 @@ void SingleAttributeTransferStrategy::run(const simplex::Sim if (m_functor) { auto [parent_data, simps] = read_parent_values(s); + if (simps.empty()) return; auto acc = mesh().create_accessor(handle().template as()); acc.vector_attribute(s.tuple()) = m_functor(parent_data, simps); diff --git a/src/wmtk/operations/composite/ProjectOperation.cpp b/src/wmtk/operations/composite/ProjectOperation.cpp index cbf83d2e34..2c148478a2 100644 --- a/src/wmtk/operations/composite/ProjectOperation.cpp +++ b/src/wmtk/operations/composite/ProjectOperation.cpp @@ -61,11 +61,11 @@ std::vector ProjectOperation::execute(const simplex::Simplex& const std::vector mapped_tuples_after = - mesh().map_tuples(m_child_mesh, mesh().top_simplex_type(), {main_tup}); + mesh().map_tuples(m_child_mesh, primitive_type(), {main_tup}); if (mapped_tuples_after.empty()) return main_simplices; - auto accessor = mesh().create_accessor(m_coordinates); + auto accessor = m_child_mesh.create_accessor(m_coordinates); for (const auto& t : mapped_tuples_after) { auto p = accessor.const_vector_attribute(t); diff --git a/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp b/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp index 866365209a..242febc2dd 100644 --- a/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp +++ b/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp @@ -831,6 +831,7 @@ void UpdateEdgeOperationMultiMeshMapFunctor::operator()( const simplex::Simplex&, const edge_mesh::EdgeOperationData& parent_emoe) { + return; // if there's a child mesh then lets disallow this #if !defined(NDEBUG) if (parent_mesh.get_child_meshes().size() > 0) { From b2f218d2e0223684e990a8a84ffbf93b4a9d5b40 Mon Sep 17 00:00:00 2001 From: JcDai Date: Wed, 17 Jan 2024 01:43:04 -0500 Subject: [PATCH 05/14] some fix --- .gitignore | 3 +- .../components/wildmeshing/wildmeshing.cpp | 96 ++++++++++++------- src/wmtk/Mesh.cpp | 15 +-- ...UpdateEdgeOperationMultiMeshMapFunctor.cpp | 14 +-- 4 files changed, 78 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index 7d01fe7a69..29202fa350 100644 --- a/.gitignore +++ b/.gitignore @@ -31,8 +31,9 @@ docs/latex *.hdf *.hdf5 *.msh +*.vtu components/spec_include.hpp components/components_include.hpp components/components_map.hpp -components/components.json \ No newline at end of file +components/components.json diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index 200896587b..d43e8498a8 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -311,8 +311,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c split->set_new_attribute_strategy(attr); } - ops.emplace_back(split); - ops_name.emplace_back("split"); + // ops.emplace_back(split); + // ops_name.emplace_back("split"); // 2) EdgeCollapse @@ -359,8 +359,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c proj_collapse->add_transfer_strategy(projection_position_update); - ops.emplace_back(proj_collapse); - ops_name.emplace_back("collapse"); + // ops.emplace_back(proj_collapse); + // ops_name.emplace_back("collapse"); // 3) TriEdgeSwap @@ -414,6 +414,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44->split().set_new_attribute_strategy(envelope_position_handle); swap44->collapse().set_new_attribute_strategy(envelope_position_handle); + swap44->split().add_transfer_strategy(envelope_position_update); + swap44->collapse().add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { swap44->split().set_new_attribute_strategy(attr); swap44->collapse().set_new_attribute_strategy(attr); @@ -422,8 +425,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44->add_transfer_strategy(edge_length_update); swap44->add_transfer_strategy(envelope_position_update); - ops.push_back(swap44); - ops_name.push_back("swap44"); + // ops.push_back(swap44); + // ops_name.push_back("swap44"); // 3 - 1 - 2) TetEdgeSwap 4-4 2 auto swap44_2 = std::make_shared(*mesh, 1); @@ -449,6 +452,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44_2->split().set_new_attribute_strategy(envelope_position_handle); swap44_2->collapse().set_new_attribute_strategy(envelope_position_handle); + swap44_2->split().add_transfer_strategy(envelope_position_update); + swap44_2->collapse().add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { swap44_2->split().set_new_attribute_strategy(attr); @@ -458,8 +464,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44_2->add_transfer_strategy(edge_length_update); swap44_2->add_transfer_strategy(envelope_position_update); - ops.push_back(swap44_2); - ops_name.push_back("swap44_2"); + // ops.push_back(swap44_2); + // ops_name.push_back("swap44_2"); // 3 - 2) TetEdgeSwap 3-2 auto swap32 = std::make_shared(*mesh, 0); @@ -482,6 +488,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap32->split().set_new_attribute_strategy(envelope_position_handle); swap32->collapse().set_new_attribute_strategy(envelope_position_handle); + swap32->split().add_transfer_strategy(envelope_position_update); + swap32->collapse().add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { swap32->split().set_new_attribute_strategy(attr); swap32->collapse().set_new_attribute_strategy(attr); @@ -491,8 +500,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap32->add_transfer_strategy(envelope_position_update); - ops.push_back(swap32); - ops_name.push_back("swap32"); + // ops.push_back(swap32); + // ops_name.push_back("swap32"); // 3 - 3) TetFaceSwap 2-3 @@ -507,13 +516,14 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c std::make_shared(mesh->top_simplex_type(), amips)); swap23->split().set_new_attribute_strategy(pt_attribute); - swap23->collapse().set_new_attribute_strategy( - pt_attribute, - CollapseBasicStrategy::CopyOther); + swap23->collapse().set_new_attribute_strategy(pt_attribute, CollapseBasicStrategy::None); swap23->split().set_new_attribute_strategy(envelope_position_handle); swap23->collapse().set_new_attribute_strategy(envelope_position_handle); + swap23->split().add_transfer_strategy(envelope_position_update); + swap23->collapse().add_transfer_strategy(envelope_position_update); + for (const auto& attr : pass_through_attributes) { swap23->split().set_new_attribute_strategy(attr); swap23->collapse().set_new_attribute_strategy(attr); @@ -522,8 +532,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap23->add_transfer_strategy(edge_length_update); swap23->add_transfer_strategy(envelope_position_update); - ops.push_back(swap23); - ops_name.push_back("swap23"); + // ops.push_back(swap23); + // ops_name.push_back("swap23"); } // 4) Smoothing @@ -542,17 +552,15 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c proj_smoothing->add_transfer_strategy(projection_position_update); proj_smoothing->use_random_priority() = true; proj_smoothing->add_invariant(inversion_invariant); - // ops.push_back(proj_smoothing); + ops.push_back(proj_smoothing); + // smoothing->add_invariant(envelope_invariant); // smoothing->add_transfer_strategy(edge_length_update); - // smoothing->add_transfer_strategy(projection_position_update); // smoothing->use_random_priority() = true; - // smoothing->add_invariant(inversion_invariant); // ops.push_back(smoothing); - // ops_name.push_back("smoothing"); - + ops_name.push_back("smoothing"); write( mesh, @@ -593,7 +601,25 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c stats.sorting_time, stats.executing_time); ++jj; - }; + + write( + mesh, + paths.output_dir, + options.output, + options.attributes.position, + iii + 1, + options.intermediate_output); + + + write( + envelope_mesh_ptr, + paths.output_dir, + options.output + "_boundary", + options.attributes.position, + iii + 1, + options.intermediate_output); + ++iii; + } logger().info( "Executed {} ops (S/F) {}/{}. Time: collecting: {}, sorting: {}, executing: {}", @@ -604,23 +630,23 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c pass_stats.sorting_time, pass_stats.executing_time); - write( - mesh, - paths.output_dir, - options.output, - options.attributes.position, - i + 1, - options.intermediate_output); + // write( + // mesh, + // paths.output_dir, + // options.output, + // options.attributes.position, + // i + 1, + // options.intermediate_output); assert(mesh->is_connectivity_valid()); - write( - envelope_mesh_ptr, - paths.output_dir, - options.output + "_boundary", - options.attributes.position, - i + 1, - options.intermediate_output); + // write( + // envelope_mesh_ptr, + // paths.output_dir, + // options.output + "_boundary", + // options.attributes.position, + // i + 1, + // options.intermediate_output); } } } // namespace wmtk::components diff --git a/src/wmtk/Mesh.cpp b/src/wmtk/Mesh.cpp index 30bb6dbc54..04bc19bd72 100644 --- a/src/wmtk/Mesh.cpp +++ b/src/wmtk/Mesh.cpp @@ -61,12 +61,12 @@ bool Mesh::is_hash_valid(const Tuple& tuple, const ConstAccessor& hash_ { const int64_t cid = tuple.m_global_cid; - const int64_t desired_hash= get_cell_hash(cid, hash_accessor); - if(tuple.m_hash != desired_hash) { - logger().debug("Hash is not valid: {} != {}", tuple.m_hash, desired_hash); - return false; - } - return true; + const int64_t desired_hash = get_cell_hash(cid, hash_accessor); + if (tuple.m_hash != desired_hash) { + logger().debug("Hash is not valid: {} != {}", tuple.m_hash, desired_hash); + return false; + } + return true; } bool Mesh::is_valid_slow(const Tuple& tuple) const @@ -110,7 +110,8 @@ void Mesh::update_cell_hash(const Tuple& cell, Accessor& hash_accessor) } void Mesh::update_cell_hash(const int64_t cid, Accessor& hash_accessor) { - ++hash_accessor.index_access().scalar_attribute(cid); + auto& h = hash_accessor.index_access().scalar_attribute(cid); + h = (h + 1) % (1 << 6); } void Mesh::update_cell_hashes(const std::vector& cells, Accessor& hash_accessor) diff --git a/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp b/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp index 242febc2dd..aea5a6b7e9 100644 --- a/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp +++ b/src/wmtk/operations/utils/UpdateEdgeOperationMultiMeshMapFunctor.cpp @@ -113,7 +113,7 @@ void UpdateEdgeOperationMultiMeshMapFunctor::update_ear_replacement( if (child_ptr->top_cell_dimension() != 1) continue; // only deal with child edgemeshes - auto& child_mmmanager = child_ptr->m_multi_mesh_manager; + const auto& child_mmmanager = child_ptr->m_multi_mesh_manager; int64_t child_id = child_mmmanager.child_id(); auto child_hash_accessor = child_ptr->get_const_cell_hash_accessor(); auto child_to_parent_handle = child_mmmanager.map_to_parent_handle; @@ -208,11 +208,11 @@ void UpdateEdgeOperationMultiMeshMapFunctor::update_ear_replacement( if (child_ptr->top_cell_dimension() == 2) { // handle with child tri mesh // update merge faces here - auto child_mmmanager = child_ptr->m_multi_mesh_manager; - int64_t child_id = child_mmmanager.child_id(); + const auto& child_mmmanager = child_ptr->m_multi_mesh_manager; + const int64_t child_id = child_mmmanager.child_id(); auto child_hash_accessor = child_ptr->get_const_cell_hash_accessor(); - auto child_to_parent_handle = child_mmmanager.map_to_parent_handle; - auto parent_to_child_handle = + const auto child_to_parent_handle = child_mmmanager.map_to_parent_handle; + const auto parent_to_child_handle = parent_mmmanager.children().at(child_id).map_handle; auto child_to_parent_accessor = child_ptr->create_accessor(child_to_parent_handle); @@ -241,7 +241,7 @@ void UpdateEdgeOperationMultiMeshMapFunctor::update_ear_replacement( continue; } - + // change to index access child_tuple = child_ptr->resurrect_tuple(child_tuple, child_hash_accessor); const char child_flag = @@ -306,7 +306,7 @@ void UpdateEdgeOperationMultiMeshMapFunctor::update_ear_replacement( // handle with child edge mesh // update merge edges here // there are three ear edges per side - auto child_mmmanager = child_ptr->m_multi_mesh_manager; + const auto& child_mmmanager = child_ptr->m_multi_mesh_manager; int64_t child_id = child_mmmanager.child_id(); auto child_hash_accessor = child_ptr->get_const_cell_hash_accessor(); auto child_to_parent_handle = child_mmmanager.map_to_parent_handle; From aef119100f14189008ba94ac4a7cb60eb3e8251c Mon Sep 17 00:00:00 2001 From: JcDai Date: Wed, 17 Jan 2024 13:00:37 -0500 Subject: [PATCH 06/14] some hack --- .../wmtk/components/wildmeshing/wildmeshing.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index d43e8498a8..96021b849e 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -263,6 +263,9 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c propagate_position); auto reverse_propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { + std::cout << "-------------------------------" << std::endl; + std::cout << P << std::endl; + // assert(P.cols() == 1); return P.col(0); }; @@ -549,11 +552,16 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c envelope_position_handle); proj_smoothing->add_invariant(envelope_invariant); proj_smoothing->add_transfer_strategy(edge_length_update); + + // proj_smoothing->add_transfer_strategy(envelope_position_update); + proj_smoothing->add_transfer_strategy(projection_position_update); - proj_smoothing->use_random_priority() = true; + proj_smoothing->use_random_priority() = false; proj_smoothing->add_invariant(inversion_invariant); ops.push_back(proj_smoothing); + // 29 parent 3 child + // smoothing->add_invariant(envelope_invariant); // smoothing->add_transfer_strategy(edge_length_update); From 4f5bd02f6dbf3336b8e8afa7e9411fb7964fd6e4 Mon Sep 17 00:00:00 2001 From: Michael Tao Date: Wed, 17 Jan 2024 13:45:58 -0500 Subject: [PATCH 07/14] adding assert to projectoperation --- src/wmtk/operations/composite/ProjectOperation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wmtk/operations/composite/ProjectOperation.cpp b/src/wmtk/operations/composite/ProjectOperation.cpp index 2c148478a2..3f70bdd399 100644 --- a/src/wmtk/operations/composite/ProjectOperation.cpp +++ b/src/wmtk/operations/composite/ProjectOperation.cpp @@ -54,6 +54,8 @@ ProjectOperation::ProjectOperation( std::vector ProjectOperation::execute(const simplex::Simplex& simplex) { + // mesh has to be the same as the main_op mesh + assert(&m_main_op->mesh() == &mesh()); const auto main_simplices = (*m_main_op)(simplex); if (main_simplices.empty()) return {}; assert(main_simplices.size() == 1); @@ -78,4 +80,4 @@ std::vector ProjectOperation::execute(const simplex::Simplex& return main_simplices; } -} // namespace wmtk::operations::composite \ No newline at end of file +} // namespace wmtk::operations::composite From 71c0a162b148e1cdb3917e4e01af5e64863e20fb Mon Sep 17 00:00:00 2001 From: JcDai Date: Wed, 17 Jan 2024 15:38:32 -0500 Subject: [PATCH 08/14] fix bug in multimesh manager --- .../tests/test_component_wildmeshing.cpp | 2 +- .../components/wildmeshing/wildmeshing.cpp | 24 +++---- src/wmtk/MultiMeshManager.cpp | 67 ++----------------- src/wmtk/Tuple.hpp | 9 +-- .../utils/extract_child_mesh_from_tag.cpp | 16 ++++- src/wmtk/operations/Operation.cpp | 4 +- src/wmtk/operations/OptimizationSmoothing.cpp | 14 ++-- 7 files changed, 48 insertions(+), 88 deletions(-) diff --git a/components/tests/test_component_wildmeshing.cpp b/components/tests/test_component_wildmeshing.cpp index ec4255f870..966f55c20b 100644 --- a/components/tests/test_component_wildmeshing.cpp +++ b/components/tests/test_component_wildmeshing.cpp @@ -29,7 +29,7 @@ TEST_CASE("wildmeshing", "[components][wildmeshing][.]") "passes": 10, "input": "mesh", "target_edge_length": 0.01, - "intermediate_output": false, + "intermediate_output": true, "attributes": {"position": "vertices"}, "pass_through": [], "output": "test", diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index 96021b849e..7bb2a482d8 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -314,8 +314,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c split->set_new_attribute_strategy(attr); } - // ops.emplace_back(split); - // ops_name.emplace_back("split"); + ops.emplace_back(split); + ops_name.emplace_back("split"); // 2) EdgeCollapse @@ -362,8 +362,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c proj_collapse->add_transfer_strategy(projection_position_update); - // ops.emplace_back(proj_collapse); - // ops_name.emplace_back("collapse"); + ops.emplace_back(proj_collapse); + ops_name.emplace_back("collapse"); // 3) TriEdgeSwap @@ -428,8 +428,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44->add_transfer_strategy(edge_length_update); swap44->add_transfer_strategy(envelope_position_update); - // ops.push_back(swap44); - // ops_name.push_back("swap44"); + ops.push_back(swap44); + ops_name.push_back("swap44"); // 3 - 1 - 2) TetEdgeSwap 4-4 2 auto swap44_2 = std::make_shared(*mesh, 1); @@ -467,8 +467,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap44_2->add_transfer_strategy(edge_length_update); swap44_2->add_transfer_strategy(envelope_position_update); - // ops.push_back(swap44_2); - // ops_name.push_back("swap44_2"); + ops.push_back(swap44_2); + ops_name.push_back("swap44_2"); // 3 - 2) TetEdgeSwap 3-2 auto swap32 = std::make_shared(*mesh, 0); @@ -503,8 +503,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap32->add_transfer_strategy(envelope_position_update); - // ops.push_back(swap32); - // ops_name.push_back("swap32"); + ops.push_back(swap32); + ops_name.push_back("swap32"); // 3 - 3) TetFaceSwap 2-3 @@ -535,8 +535,8 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c swap23->add_transfer_strategy(edge_length_update); swap23->add_transfer_strategy(envelope_position_update); - // ops.push_back(swap23); - // ops_name.push_back("swap23"); + ops.push_back(swap23); + ops_name.push_back("swap23"); } // 4) Smoothing diff --git a/src/wmtk/MultiMeshManager.cpp b/src/wmtk/MultiMeshManager.cpp index 9f326fc65f..9307c89c1e 100644 --- a/src/wmtk/MultiMeshManager.cpp +++ b/src/wmtk/MultiMeshManager.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -504,60 +505,6 @@ Tuple MultiMeshManager::map_tuple_to_parent_tuple(const Mesh& my_mesh, const Tup return map_tuple_between_meshes(my_mesh, parent_mesh, map_accessor, my_tuple); } -// helper function for map tuple -std::vector get_all_candidate_tuples_for_child_mesh( - PrimitiveType parent_type, - PrimitiveType child_type, - PrimitiveType simplex_type, - const std::vector& parent_tuples) -{ - if (parent_type == child_type || child_type == simplex_type) { - return parent_tuples; - } - - std::vector ret_tuples = parent_tuples; - switch (simplex_type) { - case PrimitiveType::Vertex: - if (parent_type == PrimitiveType::Face) { - for (const Tuple& t : parent_tuples) { - ret_tuples.emplace_back(wmtk::multimesh::utils::local_switch_tuple( - parent_type, - t, - PrimitiveType::Edge)); - } - } - if (parent_type == PrimitiveType::Tetrahedron) { - for (const Tuple& t : parent_tuples) { - ret_tuples.emplace_back(wmtk::multimesh::utils::local_switch_tuple( - parent_type, - t, - PrimitiveType::Edge)); - ret_tuples.emplace_back(wmtk::multimesh::utils::local_switch_tuples( - parent_type, - t, - {PrimitiveType::Face, PrimitiveType::Edge})); - } - } - - break; - case PrimitiveType::Edge: - if (parent_type == PrimitiveType::Tetrahedron) { - for (const Tuple& t : parent_tuples) { - ret_tuples.emplace_back(wmtk::multimesh::utils::local_switch_tuple( - parent_type, - t, - PrimitiveType::Face)); - } - } - break; - case PrimitiveType::Face: - case PrimitiveType::Tetrahedron: - case PrimitiveType::HalfEdge: - default: break; - } - - return ret_tuples; -} std::vector MultiMeshManager::map_to_child_tuples( const Mesh& my_mesh, @@ -573,15 +520,15 @@ std::vector MultiMeshManager::map_to_child_tuples( const auto map_handle = child_data.map_handle; // we will overwrite these tuples inline with the mapped ones while running down the map // functionalities - std::vector tuples = simplex::top_dimension_cofaces_tuples(my_mesh, my_simplex); + + std::vector tuples = simplex::cofaces_single_dimension_tuples( + my_mesh, + my_simplex, + child_mesh.top_simplex_type()); + /* get all tuples of child mesh top simplex type that contain my_simplex */ - tuples = get_all_candidate_tuples_for_child_mesh( - my_mesh.top_simplex_type(), - child_mesh.top_simplex_type(), - my_simplex.primitive_type(), - tuples); auto map_accessor = my_mesh.create_accessor(map_handle); for (Tuple& tuple : tuples) { diff --git a/src/wmtk/Tuple.hpp b/src/wmtk/Tuple.hpp index 4a57105897..f0c11d317f 100644 --- a/src/wmtk/Tuple.hpp +++ b/src/wmtk/Tuple.hpp @@ -12,7 +12,7 @@ class EdgeMesh; class TetMesh; namespace attribute { template - class TupleAccessor; +class TupleAccessor; } namespace utils { class TupleInspector; @@ -53,12 +53,7 @@ class Tuple // friend Mesh::is_ccw(const Tuple& tuple) const; // friend Mesh::switch_tuple(const Tuple& tuple, const PrimitiveType& type) const; - Tuple( - int8_t local_vid, - int8_t local_eid, - int8_t local_fid, - int64_t global_cid, - int8_t hash); + Tuple(int8_t local_vid, int8_t local_eid, int8_t local_fid, int64_t global_cid, int8_t hash); // v2 // / \. diff --git a/src/wmtk/multimesh/utils/extract_child_mesh_from_tag.cpp b/src/wmtk/multimesh/utils/extract_child_mesh_from_tag.cpp index d5ec66f2c4..264954a5d1 100644 --- a/src/wmtk/multimesh/utils/extract_child_mesh_from_tag.cpp +++ b/src/wmtk/multimesh/utils/extract_child_mesh_from_tag.cpp @@ -76,12 +76,26 @@ std::shared_ptr internal::TupleTag::extract_and_register_child_mesh_from_t for (int k = 0; k < 3; k++) { size_t size = parent_to_child_vertex_map.size(); parent_to_child_vertex_map.try_emplace(vs[k], size); - tri_mesh_matrix(i, k) = parent_to_child_vertex_map[vs[k]]; + tri_mesh_matrix(i, k) = parent_to_child_vertex_map.at(vs[k]); } } std::shared_ptr child_ptr = std::make_shared(); auto& child = *child_ptr; child.initialize(tri_mesh_matrix); + +#ifndef NDEUBG + auto face = child.get_all(PrimitiveType::Face); + for (int64_t i = 0; i < face.size(); ++i) { + const std::array vs = { + {child.id(face[i], PrimitiveType::Vertex), + child.id(child.switch_vertex(face[i]), PrimitiveType::Vertex), + child.id(child.switch_vertex(child.switch_edge(face[i])), PrimitiveType::Vertex)}}; + assert(vs[0] == tri_mesh_matrix(i, 0)); + assert(vs[1] == tri_mesh_matrix(i, 1)); + assert(vs[2] == tri_mesh_matrix(i, 2)); + } +#endif + return child_ptr; }; diff --git a/src/wmtk/operations/Operation.cpp b/src/wmtk/operations/Operation.cpp index af6526c6b0..93bd38ae6c 100644 --- a/src/wmtk/operations/Operation.cpp +++ b/src/wmtk/operations/Operation.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // it's ugly but for teh visitor we need these included @@ -110,7 +111,7 @@ void Operation::apply_attribute_transfer(const std::vector& di // TODO: this has no chance of working in multimesh simplex::SimplexCollection all(m_mesh); for (const auto& s : direct_mods) { - all.add(simplex::closed_star(m_mesh, s)); + all.add(simplex::closed_star(m_mesh, s, false)); } all.sort_and_clean(); for (const auto& at_ptr : m_attr_transfer_strategies) { @@ -123,6 +124,7 @@ void Operation::apply_attribute_transfer(const std::vector& di } else { auto& at_mesh = at_ptr->mesh(); auto at_mesh_simplices = m_mesh.map(at_mesh, direct_mods); + simplex::SimplexCollection at_mesh_all(at_mesh); for (const auto& s : at_mesh_simplices) { at_mesh_all.add(simplex::closed_star(at_mesh, s)); diff --git a/src/wmtk/operations/OptimizationSmoothing.cpp b/src/wmtk/operations/OptimizationSmoothing.cpp index a65ae1cd09..a282628ce4 100644 --- a/src/wmtk/operations/OptimizationSmoothing.cpp +++ b/src/wmtk/operations/OptimizationSmoothing.cpp @@ -92,7 +92,7 @@ void OptimizationSmoothing::WMTKProblem::hessian(const TVector& x, Eigen::Matrix void OptimizationSmoothing::WMTKProblem::solution_changed(const TVector& new_x) { - m_accessor.vector_attribute(m_simplex.tuple()) = new_x; + // m_accessor.vector_attribute(m_simplex.tuple()) = new_x; } @@ -140,15 +140,17 @@ void OptimizationSmoothing::create_solver() std::vector OptimizationSmoothing::execute(const simplex::Simplex& simplex) { - WMTKProblem problem( - mesh().create_accessor(m_energy->attribute_handle().as()), - simplex, - m_invariants, - *m_energy); + auto accessor = mesh().create_accessor(m_energy->attribute_handle().as()); + WMTKProblem problem(std::move(accessor), simplex, m_invariants, *m_energy); + + // std::cout << "smoothing: " << simplex.tuple().m_hash << std::endl; auto x = problem.initial_value(); try { m_solver->minimize(problem, x); + + accessor.vector_attribute(simplex.tuple()) = x; + } catch (const std::exception&) { return {}; } From 638de7cee7da3d6efc0df04b68864ca1f719859e Mon Sep 17 00:00:00 2001 From: JcDai Date: Wed, 17 Jan 2024 15:38:42 -0500 Subject: [PATCH 09/14] remove print --- .../wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp index 7bb2a482d8..4b5dc4af49 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing.cpp @@ -263,9 +263,6 @@ void wildmeshing(const base::Paths& paths, const nlohmann::json& j, io::Cache& c propagate_position); auto reverse_propagate_position = [](const Eigen::MatrixXd& P) -> Eigen::VectorXd { - std::cout << "-------------------------------" << std::endl; - std::cout << P << std::endl; - // assert(P.cols() == 1); return P.col(0); }; From a5ed6915aa1d5461fd0d1a7a2e3188e77a3d3a23 Mon Sep 17 00:00:00 2001 From: Teseo Schneider Date: Wed, 17 Jan 2024 14:41:55 -0800 Subject: [PATCH 10/14] upate bvh, data, and removed dead code --- cmake/recipes/bvh.cmake | 2 +- cmake/recipes/tests/wmtk_data.cmake | 2 +- src/wmtk/operations/Operation.cpp | 7 ------- src/wmtk/operations/Operation.hpp | 4 ---- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/cmake/recipes/bvh.cmake b/cmake/recipes/bvh.cmake index 955b2baa33..c83c2415de 100644 --- a/cmake/recipes/bvh.cmake +++ b/cmake/recipes/bvh.cmake @@ -11,7 +11,7 @@ include(CPM) CPMAddPackage( NAME simple_bvh GITHUB_REPOSITORY geometryprocessing/SimpleBVH - GIT_TAG df8812b0c876376886cf73cc64d29e3a7e7be83c + GIT_TAG 995e179142cc30799464b8124b02ff509709bf06 ) set_target_properties(simple_bvh PROPERTIES FOLDER third_party) diff --git a/cmake/recipes/tests/wmtk_data.cmake b/cmake/recipes/tests/wmtk_data.cmake index ae31125b36..2aedec1324 100644 --- a/cmake/recipes/tests/wmtk_data.cmake +++ b/cmake/recipes/tests/wmtk_data.cmake @@ -16,7 +16,7 @@ ExternalProject_Add( SOURCE_DIR ${WMTK_DATA_ROOT} GIT_REPOSITORY https://github.com/wildmeshing/data.git - GIT_TAG 6cfdde9b0928c6d8f1ade9890f1e128a3fd48e44 + GIT_TAG c8e36c24a344e1b335eeca9460e78abfb80bf6dc CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/wmtk/operations/Operation.cpp b/src/wmtk/operations/Operation.cpp index 93bd38ae6c..80e07c0875 100644 --- a/src/wmtk/operations/Operation.cpp +++ b/src/wmtk/operations/Operation.cpp @@ -141,13 +141,6 @@ void Operation::apply_attribute_transfer(const std::vector& di } } -void Operation::update_cell_hashes(const std::vector& cells) -{ - Accessor accessor = hash_accessor(); - - mesh().update_cell_hashes(cells, accessor); -} - Tuple Operation::resurrect_tuple(const Tuple& tuple) const { return mesh().resurrect_tuple(tuple, hash_accessor()); diff --git a/src/wmtk/operations/Operation.hpp b/src/wmtk/operations/Operation.hpp index d634cacd61..e4c7fd2d62 100644 --- a/src/wmtk/operations/Operation.hpp +++ b/src/wmtk/operations/Operation.hpp @@ -84,10 +84,6 @@ class Operation const std::vector& unmods, const std::vector& mods) const; - /// @brief utility for subclasses - /// @param cells - void update_cell_hashes(const std::vector& cells); - /// @brief utility for subclasses /// @param tuple Tuple resurrect_tuple(const Tuple& tuple) const; From 6dfcd7c584df62e4c1a3b3b75b3795b0ca70d6bb Mon Sep 17 00:00:00 2001 From: JcDai Date: Wed, 17 Jan 2024 19:25:47 -0500 Subject: [PATCH 11/14] remove track_boundary flag from spec --- components/tests/test_component_wildmeshing.cpp | 5 +---- .../wmtk/components/wildmeshing/WildmeshingOptions.hpp | 4 +--- .../wmtk/components/wildmeshing/wildmeshing_spec.json | 8 +------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/components/tests/test_component_wildmeshing.cpp b/components/tests/test_component_wildmeshing.cpp index 966f55c20b..993f0dadb0 100644 --- a/components/tests/test_component_wildmeshing.cpp +++ b/components/tests/test_component_wildmeshing.cpp @@ -32,8 +32,7 @@ TEST_CASE("wildmeshing", "[components][wildmeshing][.]") "intermediate_output": true, "attributes": {"position": "vertices"}, "pass_through": [], - "output": "test", - "track_boundary_child_mesh": false + "output": "test" })"_json; CHECK_NOTHROW(wmtk::components::wildmeshing(Paths(), input, cache)); @@ -61,7 +60,6 @@ TEST_CASE("wildmeshing_3d", "[components][wildmeshing][.]") {"target_edge_length", 0.05}, {"intermediate_output", true}, {"output", "test_mm"}, - {"track_boundary_child_mesh", false}, {"pass_through", std::vector()}, {"attributes", attributes}}; @@ -89,7 +87,6 @@ TEST_CASE("wildmeshing_3d_multimesh", "[components][wildmeshing][.]") {"target_edge_length", 0.1}, {"intermediate_output", true}, {"output", "test_multimesh"}, - {"track_boundary_child_mesh", true}, {"pass_through", std::vector()}, {"attributes", attributes}}; diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/WildmeshingOptions.hpp b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/WildmeshingOptions.hpp index 06aaa984f6..30b027cdc9 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/WildmeshingOptions.hpp +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/WildmeshingOptions.hpp @@ -21,7 +21,6 @@ struct WildmeshingOptions int64_t passes; double target_edge_length; bool intermediate_output; - bool track_boundary_child_mesh; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( @@ -32,7 +31,6 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( input, target_edge_length, intermediate_output, - output, - track_boundary_child_mesh); + output); } // namespace wmtk::components diff --git a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json index f73e2a968f..1502cf9888 100644 --- a/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json +++ b/components/wmtk_components/wildmeshing/wmtk/components/wildmeshing/wildmeshing_spec.json @@ -11,8 +11,7 @@ "pass_through", "passes", "target_edge_length", - "intermediate_output", - "track_boundary_child_mesh" + "intermediate_output" ] }, { @@ -58,10 +57,5 @@ "pointer": "/intermediate_output", "type": "bool", "default": false - }, - { - "pointer": "/track_boundary_child_mesh", - "type": "bool", - "default": false } ] \ No newline at end of file From 85c34ffeb0acd781e000b82ab7c82cf8c01d9dd2 Mon Sep 17 00:00:00 2001 From: Teseo Schneider Date: Wed, 17 Jan 2024 16:31:08 -0800 Subject: [PATCH 12/14] porting changes from fast_envelope_cmake_hack_for_windows --- CMakeLists.txt | 14 +++++++++++++ cmake/recipes/fast_envelope.cmake | 11 ++++++++-- tests/CMakeLists.txt | 1 + tests/test_performance.cpp | 35 +++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/test_performance.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e0943c5562..7d8a776646 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,6 +149,12 @@ target_link_libraries(wildmeshing_toolkit PUBLIC simple_bvh::simple_bvh ) + +if(MSVC) + target_compile_options(wildmeshing_toolkit PUBLIC /MP) + target_compile_options(wildmeshing_toolkit PUBLIC $<$:/GL>) +endif() + add_subdirectory(components) @@ -206,5 +212,13 @@ if(WILDMESHING_TOOLKIT_TOPLEVEL_PROJECT) jse::jse ) + + if(MSVC) + target_compile_options(wmtk_app PUBLIC /MP) + target_compile_options(wmtk_app PUBLIC $<$:/GL>) + target_link_options(wmtk_app PRIVATE $<$:/LTCG>) + target_link_options(wmtk_app PRIVATE $<$:/INCREMENTAL:NO>) + endif() + target_compile_definitions(wmtk_app PUBLIC WMTK_APP_INPUT_SPEC="${CMAKE_SOURCE_DIR}/components/wmtk_spec.json") endif() diff --git a/cmake/recipes/fast_envelope.cmake b/cmake/recipes/fast_envelope.cmake index da39dbc701..dc680112d8 100644 --- a/cmake/recipes/fast_envelope.cmake +++ b/cmake/recipes/fast_envelope.cmake @@ -7,8 +7,15 @@ endif() set(FAST_ENVELOPE_WITH_UNIT_TESTS OFF) set(FAST_ENVELOPE_ENABLE_TBB OFF) -set(FAST_ENVELOPE_WITH_GEOGRAM_PREDICATES OFF) -set(FAST_ENVELOPE_WITH_GEOGRAM_PSM_PREDICATES ON) + +# HACK because there is a linker error on Windows otherwise +if(WIN32) + set(FAST_ENVELOPE_WITH_GEOGRAM_PREDICATES ON) + set(FAST_ENVELOPE_WITH_GEOGRAM_PSM_PREDICATES OFF) +else() + set(FAST_ENVELOPE_WITH_GEOGRAM_PREDICATES OFF) + set(FAST_ENVELOPE_WITH_GEOGRAM_PSM_PREDICATES ON) +endif() message(STATUS "Third-party: creating target 'FastEnvelope::FastEnvelope'") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e9eff23e93..2ee23aa772 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -65,6 +65,7 @@ set(TEST_SOURCES test_tuple_metaprogramming.cpp test_local_switch_search.cpp test_primitive.cpp + test_performance.cpp ) add_executable(wmtk_tests ${TEST_SOURCES}) target_link_libraries(wmtk_tests PUBLIC wmtk_test_tools) diff --git a/tests/test_performance.cpp b/tests/test_performance.cpp new file mode 100644 index 0000000000..f57553b403 --- /dev/null +++ b/tests/test_performance.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +using json = nlohmann::json; + +using namespace wmtk; + +const std::filesystem::path data_dir = WMTK_DATA_DIR; + +TEST_CASE("Read_only", "[performance][.]") +{ + const std::filesystem::path meshfile = + data_dir / "adaptive_tessellation_test" / "after_smooth_uv.msh"; + + auto mesh_in = wmtk::read_mesh(meshfile, true); + Mesh& m = *mesh_in; + + auto pos_handle = m.get_attribute_handle("vertices", PrimitiveType::Vertex); + auto pos_acc = m.create_accessor(pos_handle); + + double sum = 0; + + const auto vertices = m.get_all(PrimitiveType::Vertex); + for (int i = 0; i < 10000; ++i) { + for (const Tuple& t : vertices) { + sum += pos_acc.const_vector_attribute(t)[0]; + } + for (const Tuple& t : vertices) { + sum += pos_acc.const_vector_attribute(t)[1]; + } + } + std::cout << "sum = " << sum << std::endl; +} \ No newline at end of file From 15c7a7eed67d5df69e19ac26894615a36aac3142 Mon Sep 17 00:00:00 2001 From: Teseo Schneider Date: Wed, 17 Jan 2024 16:53:37 -0800 Subject: [PATCH 13/14] fixed warning --- src/wmtk/attribute/MeshAttributes.cpp | 12 +++++++----- src/wmtk/operations/Operation.cpp | 3 +-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wmtk/attribute/MeshAttributes.cpp b/src/wmtk/attribute/MeshAttributes.cpp index 53ce735ae3..d2fe14b891 100644 --- a/src/wmtk/attribute/MeshAttributes.cpp +++ b/src/wmtk/attribute/MeshAttributes.cpp @@ -142,18 +142,18 @@ bool MeshAttributes::has_attribute(const std::string& name) const template bool MeshAttributes::operator==(const MeshAttributes& other) const { - if(m_handles != other.m_handles) { + if (m_handles != other.m_handles) { return false; } - if(m_attributes.size() != other.m_attributes.size()) { + if (m_attributes.size() != other.m_attributes.size()) { return false; } - for(size_t j = 0; j < m_attributes.size(); ++j) { - if(!(*m_attributes[j] == *other.m_attributes[j]) ){ + for (size_t j = 0; j < m_attributes.size(); ++j) { + if (!(*m_attributes[j] == *other.m_attributes[j])) { return false; } } - return true; + return true; } @@ -186,6 +186,8 @@ size_t MeshAttributes::attribute_count() const template void MeshAttributes::reserve(const int64_t size) { + assert(size >= m_reserved_size); + m_reserved_size = size; for (auto& attr_ptr : m_attributes) { attr_ptr->reserve(size); diff --git a/src/wmtk/operations/Operation.cpp b/src/wmtk/operations/Operation.cpp index 80e07c0875..e6c1820c39 100644 --- a/src/wmtk/operations/Operation.cpp +++ b/src/wmtk/operations/Operation.cpp @@ -108,7 +108,6 @@ bool Operation::after( void Operation::apply_attribute_transfer(const std::vector& direct_mods) { - // TODO: this has no chance of working in multimesh simplex::SimplexCollection all(m_mesh); for (const auto& s : direct_mods) { all.add(simplex::closed_star(m_mesh, s, false)); @@ -168,7 +167,7 @@ void Operation::reserve_enough_simplices() for (auto& v : cap) { v *= default_preallocation_size; } - m.guarantee_at_least_attributes(cap); + m.reserve_more_attributes(cap); } }; multimesh::MultiMeshVisitor visitor(run); From f7ffe47b316039cd3ece96df51ba49cd2569ce8c Mon Sep 17 00:00:00 2001 From: Teseo Schneider Date: Wed, 17 Jan 2024 17:02:46 -0800 Subject: [PATCH 14/14] ups --- src/wmtk/attribute/MeshAttributes.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wmtk/attribute/MeshAttributes.cpp b/src/wmtk/attribute/MeshAttributes.cpp index d2fe14b891..08ccfa3958 100644 --- a/src/wmtk/attribute/MeshAttributes.cpp +++ b/src/wmtk/attribute/MeshAttributes.cpp @@ -186,8 +186,6 @@ size_t MeshAttributes::attribute_count() const template void MeshAttributes::reserve(const int64_t size) { - assert(size >= m_reserved_size); - m_reserved_size = size; for (auto& attr_ptr : m_attributes) { attr_ptr->reserve(size);