PolyFEM
Loading...
Searching...
No Matches
CMesh3D.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
5
8#include <geogram/mesh/mesh.h>
9#include <iostream>
10#include <Eigen/Dense>
11#include <vector>
12#include <array>
13
14namespace polyfem
15{
16 namespace mesh
17 {
18 class CMesh3D : public Mesh3D
19 {
20 public:
21 CMesh3D() = default;
22 virtual ~CMesh3D() = default;
23 CMesh3D(CMesh3D &&) = default;
24 CMesh3D &operator=(CMesh3D &&) = default;
25 CMesh3D(const CMesh3D &) = default;
26 CMesh3D &operator=(const CMesh3D &) = default;
27
28 bool is_conforming() const override { return true; }
29
30 void refine(const int n_refinement, const double t) override;
31
32 int n_cells() const override { return int(mesh_.elements.size()); }
33 int n_faces() const override { return int(mesh_.faces.size()); }
34 int n_edges() const override { return int(mesh_.edges.size()); }
35 int n_vertices() const override { return int(mesh_.points.cols()); }
36
37 inline int n_face_vertices(const int f_id) const override { return mesh_.faces[f_id].vs.size(); }
38 inline int n_cell_vertices(const int c_id) const override { return mesh_.elements[c_id].vs.size(); }
39 inline int n_cell_edges(const int c_id) const override { return mesh_.elements[c_id].es.size(); }
40 inline int n_cell_faces(const int c_id) const override { return mesh_.elements[c_id].fs.size(); }
41 inline int cell_vertex(const int c_id, const int lv_id) const override
42 {
43 const auto &element = mesh_.elements[c_id];
44 return element.input_vs.empty() ? element.vs[lv_id] : element.input_vs[lv_id];
45 }
46 inline int cell_face(const int c_id, const int lf_id) const override { return mesh_.elements[c_id].fs[lf_id]; }
47 inline int cell_edge(const int c_id, const int le_id) const override { return mesh_.elements[c_id].es[le_id]; }
48 inline int face_vertex(const int f_id, const int lv_id) const override { return mesh_.faces[f_id].vs[lv_id]; }
49 inline int edge_vertex(const int e_id, const int lv_id) const override { return mesh_.edges[e_id].vs[lv_id]; }
50
51 void elements_boxes(std::vector<std::array<Eigen::Vector3d, 2>> &boxes) const override;
52 void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override;
53
54 bool is_boundary_vertex(const int vertex_global_id) const override { return mesh_.vertices[vertex_global_id].boundary; }
55 bool is_boundary_edge(const int edge_global_id) const override { return mesh_.edges[edge_global_id].boundary; }
56 bool is_boundary_face(const int face_global_id) const override { return mesh_.faces[face_global_id].boundary; }
57 bool is_boundary_element(const int element_global_id) const override;
58
59 bool save(const std::string &path) const override;
60
61 bool build_from_matrices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) override;
62
63 void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector<std::vector<int>> &nodes) override;
64
65 void normalize() override;
66
67 double quad_area(const int gid) const override;
68
69 void compute_elements_tag() override;
70
71 RowVectorNd kernel(const int cell_id) const override;
72 RowVectorNd point(const int vertex_id) const override;
73 void set_point(const int global_index, const RowVectorNd &p) override;
74 RowVectorNd edge_barycenter(const int e) const override;
75 RowVectorNd face_barycenter(const int f) const override;
76 RowVectorNd cell_barycenter(const int c) const override;
77
78 void bounding_box(RowVectorNd &min, RowVectorNd &max) const override;
79
80 // navigation wrapper
81 Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const override { return Navigation3D::get_index_from_element_face(mesh_, hi, lf, lv); }
83
84 Navigation3D::Index get_index_from_element_edge(int hi, int v0, int v1) const override { return Navigation3D::get_index_from_element_edge(mesh_, hi, v0, v1); }
85 Navigation3D::Index get_index_from_element_face(int hi, int v0, int v1, int v2) const override { return Navigation3D::get_index_from_element_tri(mesh_, hi, v0, v1, v2); }
86
87 inline std::vector<uint32_t> vertex_neighs(const int v_gid) const override { return mesh_.vertices[v_gid].neighbor_hs; }
88 inline std::vector<uint32_t> edge_neighs(const int e_gid) const override { return mesh_.edges[e_gid].neighbor_hs; }
89
90 // Navigation in a surface mesh
95
96 // Iterate in a mesh
99
100 void get_vertex_elements_neighs(const int v_id, std::vector<int> &ids) const override
101 {
102 ids.clear();
103 ids.insert(ids.begin(), mesh_.vertices[v_id].neighbor_hs.begin(), mesh_.vertices[v_id].neighbor_hs.end());
104 }
105 void get_edge_elements_neighs(const int e_id, std::vector<int> &ids) const override
106 {
107 ids.clear();
108 ids.insert(ids.begin(), mesh_.edges[e_id].neighbor_hs.begin(), mesh_.edges[e_id].neighbor_hs.end());
109 }
110
111 void compute_boundary_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker) override;
112
113 void compute_body_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &)> &marker) override;
114
115 // void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const override;
116
117 // used for sweeping 2D mesh
119 {
120 std::cerr << "never user this function" << std::endl;
121 return mesh_;
122 }
123 static void geomesh_2_mesh_storage(const GEO::Mesh &gm, Mesh3DStorage &m);
124
125 void append(const Mesh &mesh) override;
126
127 std::unique_ptr<Mesh> copy() const override;
128
129 protected:
130 void remove_elements(const std::vector<bool> &keep) override;
131 bool load(const std::string &path) override;
132 bool load(const GEO::Mesh &M) override;
133
134 private:
136 };
137 } // namespace mesh
138} // namespace polyfem
int V
Eigen::RowVectorXd point
void get_edge_elements_neighs(const int e_id, std::vector< int > &ids) const override
Definition CMesh3D.hpp:105
RowVectorNd cell_barycenter(const int c) const override
cell barycenter
Definition CMesh3D.cpp:1650
RowVectorNd edge_barycenter(const int e) const override
edge barycenter
Definition CMesh3D.cpp:1629
Navigation3D::Index get_index_from_element_face(int hi, int v0, int v1, int v2) const override
Definition CMesh3D.hpp:85
int n_cell_faces(const int c_id) const override
Definition CMesh3D.hpp:40
Navigation3D::Index get_index_from_element(int hi) const override
Definition CMesh3D.hpp:82
bool save(const std::string &path) const override
Definition CMesh3D.cpp:533
int cell_face(const int c_id, const int lf_id) const override
Definition CMesh3D.hpp:46
static void geomesh_2_mesh_storage(const GEO::Mesh &gm, Mesh3DStorage &m)
Definition CMesh3D.cpp:1664
int cell_edge(const int c_id, const int le_id) const override
Definition CMesh3D.hpp:47
void normalize() override
normalize the mesh
Definition CMesh3D.cpp:1160
bool is_conforming() const override
if the mesh is conforming
Definition CMesh3D.hpp:28
int edge_vertex(const int e_id, const int lv_id) const override
id of the edge vertex
Definition CMesh3D.hpp:49
int n_cell_edges(const int c_id) const override
Definition CMesh3D.hpp:39
Navigation3D::Index switch_element(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:94
void refine(const int n_refinement, const double t) override
refine the mesh
Definition CMesh3D.cpp:144
int n_edges() const override
number of edges
Definition CMesh3D.hpp:34
int face_vertex(const int f_id, const int lv_id) const override
id of the face vertex
Definition CMesh3D.hpp:48
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 CMesh3D.cpp:1348
CMesh3D(CMesh3D &&)=default
RowVectorNd face_barycenter(const int f) const override
face barycenter
Definition CMesh3D.cpp:1636
CMesh3D & operator=(CMesh3D &&)=default
int n_vertices() const override
number of vertices
Definition CMesh3D.hpp:35
Mesh3DStorage mesh_
Definition CMesh3D.hpp:135
bool is_boundary_face(const int face_global_id) const override
is face boundary
Definition CMesh3D.hpp:56
CMesh3D & operator=(const CMesh3D &)=default
bool is_boundary_edge(const int edge_global_id) const override
is edge boundary
Definition CMesh3D.hpp:55
double quad_area(const int gid) const override
area of a quad face of an hex mesh
Definition CMesh3D.cpp:1608
std::vector< uint32_t > vertex_neighs(const int v_gid) const override
Definition CMesh3D.hpp:87
void get_vertex_elements_neighs(const int v_id, std::vector< int > &ids) const override
Definition CMesh3D.hpp:100
Navigation3D::Index next_around_face(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:98
bool is_boundary_vertex(const int vertex_global_id) const override
is vertex boundary
Definition CMesh3D.hpp:54
Mesh3DStorage & mesh_storge()
Definition CMesh3D.hpp:118
RowVectorNd kernel(const int cell_id) const override
Definition CMesh3D.cpp:1395
Navigation3D::Index next_around_edge(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:97
void elements_boxes(std::vector< std::array< Eigen::Vector3d, 2 > > &boxes) const override
constructs a box around every element (3d cell, 2d face)
Definition CMesh3D.cpp:1705
void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector< std::vector< int > > &nodes) override
attach high order nodes
Definition CMesh3D.cpp:650
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh3D.cpp:1378
void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh3D.cpp:1153
virtual ~CMesh3D()=default
Navigation3D::Index get_index_from_element_edge(int hi, int v0, int v1) const override
Definition CMesh3D.hpp:84
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh3D.cpp:1741
int n_cells() const override
number of cells
Definition CMesh3D.hpp:32
int n_faces() const override
number of faces
Definition CMesh3D.hpp:33
Navigation3D::Index switch_vertex(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:91
bool load(const std::string &path) override
loads a mesh from the path
Definition CMesh3D.cpp:205
std::vector< uint32_t > edge_neighs(const int e_gid) const override
Definition CMesh3D.hpp:88
Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const override
Definition CMesh3D.hpp:81
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh3D.cpp:1753
void remove_elements(const std::vector< bool > &keep) override
Remove all top-dimensional elements whose mask entry is false.
Definition CMesh3D.cpp:20
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh3D.cpp:1402
Navigation3D::Index switch_edge(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:92
int n_cell_vertices(const int c_id) const override
number of vertices of a cell
Definition CMesh3D.hpp:38
Navigation3D::Index switch_face(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:93
void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override
constructs barycentric coodiantes for a point p.
Definition CMesh3D.cpp:1727
bool build_from_matrices(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F) override
build a mesh from matrices
Definition CMesh3D.cpp:586
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh3D.cpp:1327
int n_face_vertices(const int f_id) const override
number of vertices of a face
Definition CMesh3D.hpp:37
int cell_vertex(const int c_id, const int lv_id) const override
id of the vertex of a cell
Definition CMesh3D.hpp:41
CMesh3D(const CMesh3D &)=default
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 CMesh3D.cpp:1366
std::vector< Element > elements
std::vector< Vertex > vertices
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:49
Index next_around_3Dedge(const Mesh3DStorage &M, Index idx)
Index switch_element(const Mesh3DStorage &M, Index idx)
Index get_index_from_element_tri(const Mesh3DStorage &M, int hi, int v0, int v1, int v2)
Index switch_vertex(const Mesh3DStorage &M, Index idx)
Index get_index_from_element_face(const Mesh3DStorage &M, int hi)
Index get_index_from_element_edge(const Mesh3DStorage &M, int hi, int v0, int v1)
Index switch_edge(const Mesh3DStorage &M, Index idx)
Index next_around_2Dface(const Mesh3DStorage &M, Index idx)
Index switch_face(const Mesh3DStorage &M, Index idx)
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13