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 save(const std::string &path) const override;
57
58 bool build_from_matrices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) override;
59
60 void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector<std::vector<int>> &nodes) override;
61 RowVectorNd edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override;
62 RowVectorNd face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const override;
63
64 void normalize() override;
65
66 double edge_length(const int gid) const override;
67
68 void compute_elements_tag() override;
69 virtual void update_elements_tag() override;
70
71 void set_point(const int global_index, const RowVectorNd &p) override;
72
73 virtual RowVectorNd point(const int global_index) const override;
74 virtual RowVectorNd edge_barycenter(const int index) const override;
75
76 virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override;
77
78 void compute_boundary_ids(const double eps) override;
79 void compute_boundary_ids(const std::function<int(const RowVectorNd &)> &marker) override;
80 void compute_boundary_ids(const std::function<int(const RowVectorNd &, bool)> &marker) override;
81 void compute_boundary_ids(const std::function<int(const size_t, const RowVectorNd &, bool)> &marker) override;
82 void compute_boundary_ids(const std::function<int(const std::vector<int> &, bool)> &marker) override;
83 void compute_boundary_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker) override;
84
85 void compute_body_ids(const std::function<int(const size_t, const RowVectorNd &)> &marker) override;
86
87 // Navigation wrapper
88 inline Navigation::Index get_index_from_face(int f, int lv = 0) const override { return Navigation::get_index_from_face(mesh_, *c2e_, f, lv); }
89
90 // Navigation in a surface mesh
94
95 void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const override;
96
97 void append(const Mesh &mesh) override;
98
99 std::unique_ptr<Mesh> copy() const override;
100
101 protected:
102 bool load(const std::string &path) override;
103 bool load(const GEO::Mesh &mesh) override;
104
105 private:
106 GEO::Mesh mesh_;
107 std::unique_ptr<GEO::Attribute<GEO::index_t>> c2e_;
108 std::unique_ptr<GEO::Attribute<bool>> boundary_vertices_;
109 std::unique_ptr<GEO::Attribute<bool>> boundary_edges_;
110 };
111 } // namespace mesh
112} // namespace polyfem
int V
virtual RowVectorNd edge_barycenter(const int index) const override
edge barycenter
Definition CMesh2D.cpp:568
Navigation::Index switch_edge(Navigation::Index idx) const override
Definition CMesh2D.hpp:92
CMesh2D & operator=(const CMesh2D &)=delete
bool load(const std::string &path) override
loads a mesh from the path
Definition CMesh2D.cpp:96
void normalize() override
normalize the mesh
Definition CMesh2D.cpp:413
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh2D.cpp:557
virtual ~CMesh2D()=default
CMesh2D(CMesh2D &&)=delete
RowVectorNd edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override
Definition CMesh2D.cpp:333
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
void compute_boundary_ids(const double eps) override
computes the selection based on the bbx of the mesh.
Definition CMesh2D.cpp:588
int n_edges() const override
number of edges
Definition CMesh2D.hpp:34
Navigation::Index switch_face(Navigation::Index idx) const override
Definition CMesh2D.hpp:93
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh2D.cpp:481
double edge_length(const int gid) const override
edge length
Definition CMesh2D.cpp:458
std::unique_ptr< GEO::Attribute< bool > > boundary_edges_
Definition CMesh2D.hpp:109
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh2D.cpp:725
Navigation::Index switch_vertex(Navigation::Index idx) const override
Definition CMesh2D.hpp:91
int face_vertex(const int f_id, const int lv_id) const override
id of the face vertex
Definition CMesh2D.hpp:39
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh2D.cpp:466
CMesh2D(const CMesh2D &)=delete
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:107
void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector< int > &ranges) const override
generate a triangular representation of every face
Definition CMesh2D.cpp:496
std::unique_ptr< GEO::Attribute< bool > > boundary_vertices_
Definition CMesh2D.hpp:108
CMesh2D & operator=(CMesh2D &&)=delete
void compute_body_ids(const std::function< int(const size_t, const RowVectorNd &)> &marker) override
computes boundary selections based on a function
Definition CMesh2D.cpp:576
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh2D.cpp:686
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:88
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh2D.cpp:399
bool is_boundary_vertex(const int vertex_global_id) const override
is vertex boundary
Definition CMesh2D.hpp:43
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:197
bool build_from_matrices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) override
build a mesh from matrices
Definition CMesh2D.cpp:173
void refine(const int n_refinement, const double t) override
refine the mesh
Definition CMesh2D.cpp:25
bool save(const std::string &path) const override
Definition CMesh2D.cpp:165
bool is_conforming() const override
if the mesh is conforming
Definition CMesh2D.hpp:31
virtual RowVectorNd point(const int global_index) const override
point coordinates
Definition CMesh2D.cpp:472
RowVectorNd face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const override
Definition CMesh2D.cpp:355
virtual void update_elements_tag() override
Update elements types.
Definition CMesh2D.cpp:563
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
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:11