PolyFEM
Loading...
Searching...
No Matches
CMesh2D.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
7
8#include <Eigen/Dense>
9#include <geogram/mesh/mesh.h>
10
12
13namespace polyfem
14{
15 namespace mesh
16 {
17 class CMesh2D : public Mesh2D
18 {
19 public:
20 CMesh2D() = default;
21 virtual ~CMesh2D() = default;
22 // We cannot move or copy CMesh2D because it has unique_ptrs which do
23 // not support copy and GEO::Mesh which does not support move.
24 CMesh2D(CMesh2D &&) = delete;
25 CMesh2D &operator=(CMesh2D &&) = delete;
26 CMesh2D(const CMesh2D &) = delete;
27 CMesh2D &operator=(const CMesh2D &) = delete;
28
29 void refine(const int n_refinement, const double t) override;
30
31 bool is_conforming() const override { return true; }
32
33 int n_faces() const override { return mesh_.facets.nb(); }
34 int n_edges() const override { return mesh_.edges.nb(); }
35 int n_vertices() const override { return mesh_.vertices.nb(); }
36
37 inline int n_face_vertices(const int f_id) const override { return mesh_.facets.nb_vertices(f_id); }
38
39 inline int face_vertex(const int f_id, const int lv_id) const override { return mesh_.facets.vertex(f_id, lv_id); }
40 inline int edge_vertex(const int e_id, const int lv_id) const override { return mesh_.edges.vertex(e_id, lv_id); }
41 inline int cell_vertex(const int f_id, const int lv_id) const override { return mesh_.facets.vertex(f_id, lv_id); }
42
43 bool is_boundary_vertex(const int vertex_global_id) const override
44 {
45 // GEO::Attribute<bool> boundary_vertices(mesh_.vertices.attributes(), "boundary_vertex");
46 return (*boundary_vertices_)[vertex_global_id];
47 }
48 bool is_boundary_edge(const int edge_global_id) const override
49 {
50 // GEO::Attribute<bool> boundary_edges(mesh_.edges.attributes(), "boundary_edge");
51 return (*boundary_edges_)[edge_global_id];
52 }
53
54 bool is_boundary_element(const int element_global_id) const override;
55
56 bool build_topology(const MeshData &data) override;
57
58 void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector<std::vector<int>> &nodes) override;
59 std::pair<RowVectorNd, int> edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override;
60 std::pair<RowVectorNd, int> face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const override;
61
62 void normalize() override;
63
64 double edge_length(const int gid) const override;
65
66 void compute_elements_tag() override;
67 virtual void update_elements_tag() override;
68
69 void set_point(const int global_index, const RowVectorNd &p) override;
70
71 virtual RowVectorNd point(const int global_index) const override;
72 virtual RowVectorNd edge_barycenter(const int index) const override;
73
74 virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override;
75
76 void compute_boundary_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker) override;
77
78 void compute_body_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &)> &marker) override;
79
80 // Navigation wrapper
81 inline Navigation::Index get_index_from_face(int f, int lv = 0) const override { return Navigation::get_index_from_face(mesh_, *c2e_, f, lv); }
82
83 // Navigation in a surface mesh
87
88 // void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const override;
89
90 void append(const Mesh &mesh) override;
91
92 std::unique_ptr<Mesh> copy() const override;
93
94 protected:
95 void remove_elements(const std::vector<bool> &keep) override;
96
97 private:
98 GEO::Mesh mesh_;
99 std::unique_ptr<GEO::Attribute<GEO::index_t>> c2e_;
100 std::unique_ptr<GEO::Attribute<bool>> boundary_vertices_;
101 std::unique_ptr<GEO::Attribute<bool>> boundary_edges_;
102 };
103 } // namespace mesh
104} // namespace polyfem
int V
Eigen::RowVectorXd point
virtual RowVectorNd edge_barycenter(const int index) const override
edge barycenter
Definition CMesh2D.cpp:594
Navigation::Index switch_edge(Navigation::Index idx) const override
Definition CMesh2D.hpp:85
CMesh2D & operator=(const CMesh2D &)=delete
void normalize() override
normalize the mesh
Definition CMesh2D.cpp:434
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh2D.cpp:583
virtual ~CMesh2D()=default
CMesh2D(CMesh2D &&)=delete
int n_faces() const override
number of faces
Definition CMesh2D.hpp:33
int n_face_vertices(const int f_id) const override
number of vertices of a face
Definition CMesh2D.hpp:37
int n_vertices() const override
number of vertices
Definition CMesh2D.hpp:35
int n_edges() const override
number of edges
Definition CMesh2D.hpp:34
Navigation::Index switch_face(Navigation::Index idx) const override
Definition CMesh2D.hpp:86
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh2D.cpp:507
double edge_length(const int gid) const override
edge length
Definition CMesh2D.cpp:484
std::unique_ptr< GEO::Attribute< bool > > boundary_edges_
Definition CMesh2D.hpp:101
std::pair< RowVectorNd, int > edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override
Definition CMesh2D.cpp:354
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh2D.cpp:667
Navigation::Index switch_vertex(Navigation::Index idx) const override
Definition CMesh2D.hpp:84
int face_vertex(const int f_id, const int lv_id) const override
id of the face vertex
Definition CMesh2D.hpp:39
void compute_boundary_ids(const std::function< int(const size_t, const std::vector< int > &, const RowVectorNd &, bool)> &marker) override
computes boundary selections based on a function
Definition CMesh2D.cpp:614
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh2D.cpp:492
CMesh2D(const CMesh2D &)=delete
bool build_topology(const MeshData &data) override
Construct only the dimension-specific topology.
Definition CMesh2D.cpp:170
bool is_boundary_edge(const int edge_global_id) const override
is edge boundary
Definition CMesh2D.hpp:48
std::unique_ptr< GEO::Attribute< GEO::index_t > > c2e_
Definition CMesh2D.hpp:99
std::unique_ptr< GEO::Attribute< bool > > boundary_vertices_
Definition CMesh2D.hpp:100
CMesh2D & operator=(CMesh2D &&)=delete
std::pair< RowVectorNd, int > face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const override
Definition CMesh2D.cpp:376
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh2D.cpp:628
int edge_vertex(const int e_id, const int lv_id) const override
id of the edge vertex
Definition CMesh2D.hpp:40
Navigation::Index get_index_from_face(int f, int lv=0) const override
Definition CMesh2D.hpp:81
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh2D.cpp:420
bool is_boundary_vertex(const int vertex_global_id) const override
is vertex boundary
Definition CMesh2D.hpp:43
void remove_elements(const std::vector< bool > &keep) override
Remove all top-dimensional elements whose mask entry is false.
Definition CMesh2D.cpp:25
int cell_vertex(const int f_id, const int lv_id) const override
id of the vertex of a cell
Definition CMesh2D.hpp:41
void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector< std::vector< int > > &nodes) override
attach high order nodes
Definition CMesh2D.cpp:213
void refine(const int n_refinement, const double t) override
refine the mesh
Definition CMesh2D.cpp:98
void compute_body_ids(const std::function< int(const size_t, const std::vector< int > &, const RowVectorNd &)> &marker) override
computes boundary selections based on a function
Definition CMesh2D.cpp:602
bool is_conforming() const override
if the mesh is conforming
Definition CMesh2D.hpp:31
virtual void update_elements_tag() override
Update elements types.
Definition CMesh2D.cpp:589
Format-independent input used to construct a runtime Mesh.
Definition MeshData.hpp:12
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:50
Index get_index_from_face(const GEO::Mesh &M, const GEO::Attribute< GEO::index_t > &c2e, int f, int lv)
Index switch_face(const GEO::Mesh &M, const GEO::Attribute< GEO::index_t > &c2e, Index idx)
Index switch_edge(const GEO::Mesh &M, const GEO::Attribute< GEO::index_t > &c2e, Index idx)
Index switch_vertex(const GEO::Mesh &M, Index idx)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13