6#include <wmtk/TriMesh.h>
7#include <wmtk/TetMesh.h>
8#include <wmtk/ExecutionScheduler.hpp>
25 template <
class WMTKMesh>
34 static constexpr int DIM = [] {
35 if constexpr (std::is_same_v<wmtk::TriMesh, WMTKMesh>)
42 if constexpr (std::is_same_v<wmtk::TriMesh, WMTKMesh>)
49 if constexpr (std::is_same_v<wmtk::TriMesh, WMTKMesh>)
56 if constexpr (std::is_same_v<wmtk::TriMesh, WMTKMesh>)
62 using VectorNd = Eigen::Matrix<double, DIM, 1>;
64 using Tuple =
typename WMTKMesh::Tuple;
77 const Eigen::MatrixXd &obstacle_vals,
103 const size_t num_vertices,
104 const Eigen::MatrixXi &
elements)
override;
141 bool invariants(
const std::vector<Tuple> &new_tris)
override;
161 Eigen::MatrixXi
edges()
const override;
163 Eigen::MatrixXi
elements()
const override;
173 std::vector<int>
body_ids()
const override;
175 std::vector<int>
boundary_nodes(
const Eigen::VectorXi &vertex_to_basis)
const override;
195 void set_fixed(
const std::vector<bool> &fixed)
override;
251 const std::array<size_t, VERTICES_PER_ELEMENT> &conn,
const size_t v0)
const;
283 return e.switch_edge(*this).switch_vertex(*
this);
292 using Operations = std::vector<std::pair<std::string, Tuple>>;
294 const std::string &op,
const std::vector<Tuple> &tris)
const {
return {}; }
413 wmtk::ExecutePass<WildRemesher, EXECUTION_POLICY>
executor;
418 typename std::conditional<
419 std::is_same<WMTKMesh, wmtk::TriMesh>::value,
420 std::shared_ptr<TriOperationCache>,
421 std::shared_ptr<TetOperationCache>>::type
op_cache;
main class that contains the polyfem solver and all its state
const Eigen::MatrixXd & obstacle_displacements() const
Get a reference to the collision obstacles' displacements.
std::unordered_map< std::array< size_t, 2 >, T, polyfem::utils::HashUnorderedArray< size_t, 2 >, polyfem::utils::EqualUnorderedArray< size_t, 2 > > EdgeMap
Map from a (sorted) edge to an integer (ID)
const double current_time
Current time.
const double starting_energy
Starting energy.
std::variant< EdgeMap< T >, FaceMap< T > > BoundaryMap
const State & state
Reference to the simulation state.
static constexpr int VERTICES_PER_ELEMENT
BoundaryMap< int > boundary_ids() const override
Exports boundary ids of the stored mesh.
wmtk::AttributeCollection< EdgeAttributes > edge_attrs
virtual bool collapse_edge_after(const Tuple &t) override
bool is_body_boundary_vertex(const Tuple &v) const
Is the given vertex tuple on the boundary of a body?
std::vector< Tuple > get_one_ring_boundary_edges_for_vertex(const Tuple &v) const
std::array< size_t, VERTICES_PER_ELEMENT > element_vids(const Tuple &t) const
Get the vertex ids of an element.
Eigen::MatrixXi elements() const override
Exports elements of the stored mesh.
void map_edge_split_boundary_attributes(const Tuple &t)
Eigen::MatrixXi edges() const override
Exports edges of the stored mesh.
Eigen::MatrixXd projection_quantities() const override
Exports projected quantities of the stored mesh.
std::conditional< std::is_same< WMTKMesh, wmtk::TriMesh >::value, std::shared_ptr< TriOperationCache >, std::shared_ptr< TetOperationCache > >::type op_cache
Eigen::MatrixXd rest_positions() const override
Exports rest positions of the stored mesh.
void init_attributes_and_connectivity(const size_t num_vertices, const Eigen::MatrixXi &elements) override
Create an internal mesh representation and associate attributes.
double deformed_edge_length(const Tuple &e) const
CollapseEdgeTo collapse_boundary_edge_to(const Tuple &e) const
Determine where to collapse an edge to.
void set_projection_quantities(const Eigen::MatrixXd &projection_quantities) override
Set projected quantities of the stored mesh.
wmtk::AttributeCollection< ElementAttributes > element_attrs
void write_edge_ranks_mesh(const EdgeMap< typename EdgeAttributes::EnergyRank > &elastic_ranks, const EdgeMap< typename EdgeAttributes::EnergyRank > &contact_ranks) const
Eigen::MatrixXi boundary_faces() const override
Exports boundary faces of the stored mesh.
size_t facet_id(const Tuple &t) const
Get the id of a facet (edge for triangle, triangle for tetrahedra)
virtual Operations renew_neighbor_tuples(const std::string &op, const std::vector< Tuple > &tris) const
bool is_boundary_vertex(const Tuple &v) const
Is the given vertex tuple on the boundary of the mesh?
std::vector< Tuple > boundary_facets(std::vector< int > *boundary_ids=nullptr) const
Get the boundary facets of the mesh.
std::array< Tuple, DIM > facet_vertices(const Tuple &t) const
Get the vertex tuples of a facet.
std::vector< std::pair< std::string, Tuple > > Operations
void set_body_ids(const std::vector< int > &body_ids) override
Set the body IDs of all elements.
wmtk::ExecutePass< WildRemesher, EXECUTION_POLICY > executor
wmtk::AttributeCollection< BoundaryAttributes > boundary_attrs
Tuple tuple_from_facet(size_t elem_id, int local_facet_id) const
Get a tuple of an element with a local facet.
virtual void init(const Eigen::MatrixXd &rest_positions, const Eigen::MatrixXd &positions, const Eigen::MatrixXi &elements, const Eigen::MatrixXd &projection_quantities, const BoundaryMap< int > &boundary_to_id, const std::vector< int > &body_ids, const EdgeMap< double > &elastic_energy, const EdgeMap< double > &contact_energy) override
Initialize the mesh.
std::array< size_t, DIM > facet_vids(const Tuple &t) const
Get the vertex ids of a facet.
bool is_body_boundary_edge(const Tuple &e) const
Is the given edge tuple on the boundary of a body?
std::array< Tuple, VERTICES_PER_ELEMENT > element_vertices(const Tuple &t) const
Get the vertex tuples of an element.
void set_rest_positions(const Eigen::MatrixXd &positions) override
Set rest positions of the stored mesh.
int n_quantities() const override
Number of projection quantities (not including the position)
virtual bool smooth_before(const Tuple &t) override
typename WMTKMesh::Tuple Tuple
void set_positions(const Eigen::MatrixXd &positions) override
Set deformed positions of the stored mesh.
bool is_rest_inverted(const Tuple &loc) const
Check if a triangle's rest shape is inverted.
wmtk::AttributeCollection< VertexAttributes > vertex_attrs
virtual void smooth_vertices()
void set_boundary_ids(const BoundaryMap< int > &boundary_to_id) override
Set the boundary IDs of all edges.
std::vector< Tuple > get_edges_for_elements(const std::vector< Tuple > &elements) const
bool is_boundary_facet(const Tuple &t) const
Is the given tuple on the boundary of the mesh?
std::array< size_t, VERTICES_PER_ELEMENT > orient_preserve_element_reorder(const std::array< size_t, VERTICES_PER_ELEMENT > &conn, const size_t v0) const
Reorder the element vertices so that the first vertex is v0.
bool execute() override
Execute the remeshing.
double rest_edge_length(const Tuple &e) const
Compute the length of an edge.
bool is_inverted(const Tuple &loc) const
Check if a triangle's rest and deformed shapes are inverted.
virtual ~WildRemesher()=default
Eigen::MatrixXd positions() const override
Exports displacements of the stored mesh.
VectorNd rest_edge_center(const Tuple &e) const
Compute the center of the edge.
std::vector< Tuple > get_one_ring_elements_for_vertex(const Tuple &t) const
Get the one ring of elements around a vertex.
std::array< Tuple, 2 > get_boundary_faces_for_edge(const Tuple &e) const
static constexpr wmtk::ExecutionPolicy EXECUTION_POLICY
Current execuation policy (sequencial or parallel)
std::vector< int > body_ids() const override
Exports body ids of the stored mesh.
void element_aabb(const Tuple &t, polyfem::VectorNd &el_min, polyfem::VectorNd &el_max) const
Get a AABB for an element.
std::vector< int > boundary_nodes(const Eigen::VectorXi &vertex_to_basis) const override
Get the boundary nodes of the stored mesh.
bool is_boundary_edge(const Tuple &e) const
Is the given edge tuple on the boundary of the mesh?
void map_edge_collapse_boundary_attributes(const Tuple &t)
void cache_split_edge(const Tuple &e)
Cache the split edge operation.
Eigen::VectorXd edge_adjacent_element_volumes(const Tuple &e) const
std::vector< Tuple > get_facets() const
Get a vector of all facets (edges or triangles)
int dim() const override
Dimension of the mesh.
virtual void collapse_edges()=0
Tuple tuple_from_element(size_t elem_id) const
Get a tuple of an element.
std::vector< Tuple > get_incident_elements_for_edge(const Tuple &t) const
Get the incident elements for an edge.
virtual void split_edges()=0
EdgeAttributes & edge_attr(const size_t e_id)
Get a reference to an edge's attributes.
Eigen::MatrixXi boundary_edges() const override
Exports boundary edges of the stored mesh.
void map_edge_swap_element_attributes(const Tuple &t)
static constexpr int FACETS_PER_ELEMENT
void map_edge_collapse_vertex_attributes(const Tuple &t)
void extend_local_patch(std::vector< Tuple > &patch) const
Extend the local patch by including neighboring elements.
virtual bool swap_edge_before(const Tuple &t) override
std::vector< Tuple > get_elements() const
Get a vector of all elements (triangles or tetrahedra)
size_t element_id(const Tuple &t) const
Get the id of an element (triangle or tetrahedra)
void map_edge_swap_edge_attributes(const Tuple &t)
void map_edge_collapse_edge_attributes(const Tuple &t)
Eigen::Matrix< double, DIM, 1 > VectorNd
double element_volume(const Tuple &e) const
Compute the volume (area) of an tetrahedron (triangle) element.
bool is_boundary_op() const
Is the currently cached operation a boundary operation?
virtual bool split_edge_after(const Tuple &t) override
void map_edge_split_edge_attributes(const Tuple &t)
void set_fixed(const std::vector< bool > &fixed) override
Set if a vertex is fixed.
virtual bool smooth_after(const Tuple &t) override
virtual bool split_edge_before(const Tuple &t) override
void cache_swap_edge(const Tuple &e)
Cache the edge swap operation.
void map_edge_split_element_attributes(const Tuple &t)
std::vector< Tuple > get_one_ring_boundary_faces_for_vertex(const Tuple &v) const
Tuple opposite_vertex_on_face(const Tuple &e) const
Get the opposite vertex on a face.
const EdgeAttributes & edge_attr(const size_t e_id) const
Get a const reference to an edge's attributes.
bool invariants(const std::vector< Tuple > &new_tris) override
Check if invariants are satisfied.
Eigen::MatrixXd displacements() const override
Exports positions of the stored mesh.
VectorNd deformed_edge_center(const Tuple &e) const
virtual void swap_edges()
WildRemesher< WMTKMesh > This
static constexpr int EDGES_PER_ELEMENT
virtual bool swap_edge_after(const Tuple &t) override
void cache_collapse_edge(const Tuple &e, const CollapseEdgeTo collapse_to)
Cache the edge collapse operation.
virtual bool collapse_edge_before(const Tuple &t) override
WildTetRemesher::Tuple Tuple
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
void log_and_throw_error(const std::string &msg)
Eigen::MatrixXd projection_quantities
Quantities to be projected (dim × n_quantities)
static VertexAttributes edge_collapse(const VertexAttributes &v0, const VertexAttributes &v1, const CollapseEdgeTo collapse_to)
VectorNd prev_position(const int i) const
Previous position of the vertex.
VectorNd position_i(const int i) const
Get the position of the vertex at different times.
VectorNd displacement() const
Current displacement from rest position to current position.
WildRemesher< WMTKMesh >::VectorNd VectorNd