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 std::pair<RowVectorNd, int> edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override;
62 std::pair<RowVectorNd, int> 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 std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker) override;
79
80 void compute_body_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &)> &marker) override;
81
82 // Navigation wrapper
83 inline Navigation::Index get_index_from_face(int f, int lv = 0) const override { return Navigation::get_index_from_face(mesh_, *c2e_, f, lv); }
84
85 // Navigation in a surface mesh
89
90 // void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const override;
91
92 void append(const Mesh &mesh) override;
93
94 std::unique_ptr<Mesh> copy() const override;
95
96 protected:
97 bool load(const std::string &path) override;
98 bool load(const GEO::Mesh &mesh) override;
99
100 private:
101 GEO::Mesh mesh_;
102 std::unique_ptr<GEO::Attribute<GEO::index_t>> c2e_;
103 std::unique_ptr<GEO::Attribute<bool>> boundary_vertices_;
104 std::unique_ptr<GEO::Attribute<bool>> boundary_edges_;
105 };
106 } // namespace mesh
107} // namespace polyfem
int V
virtual RowVectorNd edge_barycenter(const int index) const override
edge barycenter
Definition CMesh2D.cpp:573
Navigation::Index switch_edge(Navigation::Index idx) const override
Definition CMesh2D.hpp:87
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:418
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh2D.cpp:562
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:88
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh2D.cpp:486
double edge_length(const int gid) const override
edge length
Definition CMesh2D.cpp:463
std::unique_ptr< GEO::Attribute< bool > > boundary_edges_
Definition CMesh2D.hpp:104
std::pair< RowVectorNd, int > edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override
Definition CMesh2D.cpp:338
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh2D.cpp:646
Navigation::Index switch_vertex(Navigation::Index idx) const override
Definition CMesh2D.hpp:86
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:593
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh2D.cpp:471
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:102
std::unique_ptr< GEO::Attribute< bool > > boundary_vertices_
Definition CMesh2D.hpp:103
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:360
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh2D.cpp:607
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:83
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh2D.cpp:404
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
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:581
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:477
virtual void update_elements_tag() override
Update elements types.
Definition CMesh2D.cpp:568
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:13