PolyFEM
Loading...
Searching...
No Matches
LocalMesh.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <Eigen/Core>
8
9namespace polyfem::mesh
10{
11 template <typename M>
13 {
14 protected:
15 using Tuple = typename M::Tuple;
16
17 public:
19 const M &m,
20 const std::vector<Tuple> &element_tuples,
21 const bool include_global_boundary);
22
24 static std::vector<Tuple> n_ring(
25 const M &m,
26 const Tuple &center,
27 const int n);
28 static std::vector<Tuple> n_ring(
29 const M &m,
30 const std::vector<Tuple> &one_ring,
31 const int n);
32
34 static std::vector<Tuple> flood_fill_n_ring(
35 const M &m,
36 const Tuple &center,
37 const double area);
38
39 static std::vector<Tuple> ball_selection(
40 const M &m,
41 const VectorNd &center,
42 const double rel_radius,
43 const int n_ring_size);
44
48 int num_vertices() const { return m_rest_positions.rows(); }
50 int num_elements() const { return m_elements.rows(); }
51
53 const Eigen::MatrixXd &rest_positions() const { return m_rest_positions; }
55 const Eigen::MatrixXd &positions() const { return m_positions; }
56
58 Eigen::MatrixXd displacements() const { return m_positions - m_rest_positions; }
59
61 const Eigen::MatrixXd &projection_quantities() const { return m_projection_quantities; }
62
64 const Eigen::MatrixXi &elements() const { return m_elements; }
66 const Eigen::MatrixXi &boundary_edges() const { return m_boundary_edges; }
68 const Eigen::MatrixXi &boundary_faces() const { return m_boundary_faces; }
69
71 const std::unordered_map<int, int> &global_to_local() const { return m_global_to_local; }
72
74 const std::vector<int> &local_to_global() const { return m_local_to_global; }
75
77 const std::vector<int> &fixed_vertices() const { return m_fixed_vertices; }
78
81
83 const std::vector<int> &body_ids() const { return m_body_ids; }
84
87 Eigen::MatrixXi &boundary_facets();
88 const Eigen::MatrixXi &boundary_facets() const;
89
94 std::vector<polyfem::basis::ElementBases> build_bases(const std::string &formulation);
95
98 void reorder_vertices(const Eigen::VectorXi &permutation);
99
103 void write_mesh(const std::string &path, const Eigen::MatrixXd &sol) const;
104
105 protected:
108 void init_vertex_attributes(const M &m);
109
111 Eigen::MatrixXd m_rest_positions;
112
114 Eigen::MatrixXd m_positions;
115
117 Eigen::MatrixXd m_projection_quantities;
118
120 Eigen::MatrixXi m_elements;
121
123 Eigen::MatrixXi m_boundary_edges;
124
126 Eigen::MatrixXi m_boundary_faces;
127
130
132 std::unordered_map<int, int> m_global_to_local;
133
135 std::vector<int> m_local_to_global;
136
138 std::vector<int> m_fixed_vertices;
139
142
144 std::vector<int> m_body_ids;
145 };
146} // namespace polyfem::mesh
void write_mesh(const std::string &path, const Eigen::MatrixXd &sol) const
Write the local mesh to a VTU file.
typename M::Tuple Tuple
Definition LocalMesh.hpp:15
const std::vector< int > & local_to_global() const
Map from local vertex index to global vertex index.
Definition LocalMesh.hpp:74
Eigen::MatrixXd m_positions
Deformed positions of the vertices.
Eigen::MatrixXd displacements() const
Displacements of the vertices.
Definition LocalMesh.hpp:58
std::vector< polyfem::basis::ElementBases > build_bases(const std::string &formulation)
Build the ElementBases for the local mesh.
void init_vertex_attributes(const M &m)
const Eigen::MatrixXd & projection_quantities() const
Projection quantaties for each vertex.
Definition LocalMesh.hpp:61
const Eigen::MatrixXd & rest_positions() const
Rest positions of the vertices.
Definition LocalMesh.hpp:53
Eigen::MatrixXd m_projection_quantities
Projection quantaties for each vertex.
int num_vertices() const
Number of vertices in the local mesh.
Definition LocalMesh.hpp:48
const std::unordered_map< int, int > & global_to_local() const
Map from global vertex index to local vertex index.
Definition LocalMesh.hpp:71
Remesher::BoundaryMap< int > m_boundary_ids
Map from boundary elements (all edges for TriMesh or faces in TetMesh) to their boundary id.
std::unordered_map< int, int > m_global_to_local
Map from global vertex index to local vertex index.
static std::vector< Tuple > n_ring(const M &m, const Tuple &center, const int n)
Construct a local mesh as an n-ring around a vertex.
const Remesher::BoundaryMap< int > & boundary_ids() const
Map from boundary elements (all edges for TriMesh or faces in TetMesh) to their boundary id.
Definition LocalMesh.hpp:80
static std::vector< Tuple > flood_fill_n_ring(const M &m, const Tuple &center, const double area)
Construct a local mesh as an n-ring around a vertex.
Eigen::MatrixXi & boundary_facets()
Get a reference to the boundary facets (edges in 2D or faces in 3D).
int m_num_local_vertices
Number of vertices in the local mesh (not including extra global boundary vertices).
Eigen::MatrixXi m_boundary_faces
Faces on the boundary (not set for TriMesh).
const std::vector< int > & fixed_vertices() const
Fixed vertices.
Definition LocalMesh.hpp:77
const Eigen::MatrixXd & positions() const
Deformed positions of the vertices.
Definition LocalMesh.hpp:55
void reorder_vertices(const Eigen::VectorXi &permutation)
Reorder the vertices of the local mesh.
std::vector< int > m_local_to_global
Map from local vertex index to global vertex index.
std::vector< int > m_body_ids
One body id per element.
const Eigen::MatrixXi & boundary_edges() const
Edged on the boundary.
Definition LocalMesh.hpp:66
int num_local_vertices() const
Number of vertices in the local mesh (not including extra global boundary vertices).
Definition LocalMesh.hpp:46
const Eigen::MatrixXi & boundary_faces() const
Faces on the boundary (not set for TriMesh).
Definition LocalMesh.hpp:68
Eigen::MatrixXd m_rest_positions
Rest positions of the vertices.
Eigen::MatrixXi m_boundary_edges
Edged on the boundary.
const Eigen::MatrixXi & elements() const
Elements in the local mesh.
Definition LocalMesh.hpp:64
int num_elements() const
Number of elements.
Definition LocalMesh.hpp:50
const std::vector< int > & body_ids() const
One body id per element.
Definition LocalMesh.hpp:83
Eigen::MatrixXi m_elements
Elements in the local mesh.
static std::vector< Tuple > ball_selection(const M &m, const VectorNd &center, const double rel_radius, const int n_ring_size)
std::vector< int > m_fixed_vertices
Fixed vertices.
std::variant< EdgeMap< T >, FaceMap< T > > BoundaryMap
Definition Remesher.hpp:42
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
Definition Types.hpp:11