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 <iostream>
9#include <Eigen/Dense>
10#include <vector>
11#include <array>
12
13namespace polyfem
14{
15 namespace mesh
16 {
17 struct StandardCell;
18
33 class CMesh3D : public Mesh3D
34 {
35 public:
36 CMesh3D() = default;
37 virtual ~CMesh3D() = default;
38 CMesh3D(CMesh3D &&) = default;
39 CMesh3D &operator=(CMesh3D &&) = default;
40 CMesh3D(const CMesh3D &) = default;
41 CMesh3D &operator=(const CMesh3D &) = default;
42
43 bool is_conforming() const override { return true; }
44
45 void refine(const int n_refinement, const double t) override;
46
47 int n_cells() const override { return int(mesh_.n_cells()); }
48 int n_faces() const override { return int(mesh_.n_faces()); }
49 int n_edges() const override { return int(mesh_.n_edges()); }
50 int n_vertices() const override { return int(mesh_.points.cols()); }
51
52 inline int n_face_vertices(const int f_id) const override { return mesh_.face_vs[f_id].size(); }
53 inline int n_cell_vertices(const int c_id) const override { return mesh_.cell_vs[c_id].size(); }
54 inline int n_cell_edges(const int c_id) const override { return mesh_.cell_es[c_id].size(); }
55 inline int n_cell_faces(const int c_id) const override { return mesh_.cell_fs[c_id].size(); }
56 inline int cell_vertex(const int c_id, const int lv_id) const override
57 {
58 return mesh_.cell_input_vs.row_size(c_id) == 0 ? mesh_.cell_vs[c_id][lv_id] : mesh_.cell_input_vs[c_id][lv_id];
59 }
60 inline int cell_face(const int c_id, const int lf_id) const override { return mesh_.cell_fs[c_id][lf_id]; }
61 inline int cell_face_orientation(const int c_id, const int lf_id) const override { return mesh_.cell_fs_flag[c_id][lf_id]; }
62 inline int cell_edge(const int c_id, const int le_id) const override { return mesh_.cell_es[c_id][le_id]; }
63 inline int face_vertex(const int f_id, const int lv_id) const override { return mesh_.face_vs[f_id][lv_id]; }
64 inline int edge_vertex(const int e_id, const int lv_id) const override { return mesh_.edge_vs[e_id][lv_id]; }
65
66 void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override;
67
68 bool is_boundary_vertex(const int vertex_global_id) const override { return mesh_.vertex_boundary[vertex_global_id]; }
69 bool is_boundary_edge(const int edge_global_id) const override { return mesh_.edge_boundary[edge_global_id]; }
70 bool is_boundary_face(const int face_global_id) const override { return mesh_.face_boundary[face_global_id]; }
71 bool is_boundary_element(const int element_global_id) const override;
72
73 bool build_topology(const MeshData &data) override;
74
75 void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector<std::vector<int>> &nodes) override;
76
77 void normalize() override;
78
79 double quad_area(const int gid) const override;
80
81 void compute_elements_tag() override;
82
83 RowVectorNd kernel(const int cell_id) const override;
84 RowVectorNd point(const int vertex_id) const override;
85 void set_point(const int global_index, const RowVectorNd &p) override;
86 RowVectorNd edge_barycenter(const int e) const override;
87 RowVectorNd face_barycenter(const int f) const override;
88 RowVectorNd cell_barycenter(const int c) const override;
89
90 void bounding_box(RowVectorNd &min, RowVectorNd &max) const override;
91
92 // navigation wrapper
93 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); }
95
96 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); }
97 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); }
98
99 inline std::vector<uint32_t> vertex_neighs(const int v_gid) const override { return mesh_.vertex_hs[v_gid].to_vector(); }
100 inline std::vector<uint32_t> edge_neighs(const int e_gid) const override { return mesh_.edge_hs[e_gid].to_vector(); }
101
102 // Navigation in a surface mesh
107
108 // Iterate in a mesh
111
112 void get_vertex_elements_neighs(const int v_id, std::vector<int> &ids) const override
113 {
114 ids.clear();
115 ids.insert(ids.begin(), mesh_.vertex_hs[v_id].begin(), mesh_.vertex_hs[v_id].end());
116 }
117 void get_edge_elements_neighs(const int e_id, std::vector<int> &ids) const override
118 {
119 ids.clear();
120 ids.insert(ids.begin(), mesh_.edge_hs[e_id].begin(), mesh_.edge_hs[e_id].end());
121 }
122
123 void compute_boundary_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker) override;
124
125 void compute_body_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &)> &marker) override;
126
127 // void triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const override;
128
129 // used for sweeping 2D mesh
131 {
132 std::cerr << "never user this function" << std::endl;
133 return mesh_;
134 }
135
136 void append(const Mesh &mesh) override;
137
140 void apply_affine_transformation(const MatrixNd &A, const VectorNd &b) override;
141
142 std::unique_ptr<Mesh> copy() const override;
143
144 protected:
145 void remove_elements(const std::vector<bool> &keep) override;
146
147 private:
148 bool build_storage_from_cells(const Eigen::MatrixXd &V, const std::vector<StandardCell> &cells);
150 };
151 } // namespace mesh
152} // namespace polyfem
int V
Eigen::RowVectorXd point
Conforming 3D mesh of tetrahedra, hexahedra, prisms, pyramids and general polyhedra,...
Definition CMesh3D.hpp:34
void get_edge_elements_neighs(const int e_id, std::vector< int > &ids) const override
Definition CMesh3D.hpp:117
RowVectorNd cell_barycenter(const int c) const override
cell barycenter
Definition CMesh3D.cpp:1479
RowVectorNd edge_barycenter(const int e) const override
edge barycenter
Definition CMesh3D.cpp:1458
Navigation3D::Index get_index_from_element_face(int hi, int v0, int v1, int v2) const override
Definition CMesh3D.hpp:97
int n_cell_faces(const int c_id) const override
Definition CMesh3D.hpp:55
Navigation3D::Index get_index_from_element(int hi) const override
Definition CMesh3D.hpp:94
int cell_face(const int c_id, const int lf_id) const override
Definition CMesh3D.hpp:60
bool build_topology(const MeshData &data) override
Construct only the dimension-specific topology.
Definition CMesh3D.cpp:341
int cell_edge(const int c_id, const int le_id) const override
Definition CMesh3D.hpp:62
void normalize() override
normalize the mesh
Definition CMesh3D.cpp:976
bool is_conforming() const override
if the mesh is conforming
Definition CMesh3D.hpp:43
int edge_vertex(const int e_id, const int lv_id) const override
id of the edge vertex
Definition CMesh3D.hpp:64
int n_cell_edges(const int c_id) const override
Definition CMesh3D.hpp:54
Navigation3D::Index switch_element(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:106
void refine(const int n_refinement, const double t) override
refine the mesh
Definition CMesh3D.cpp:154
int n_edges() const override
number of edges
Definition CMesh3D.hpp:49
int face_vertex(const int f_id, const int lv_id) const override
id of the face vertex
Definition CMesh3D.hpp:63
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:1167
CMesh3D(CMesh3D &&)=default
RowVectorNd face_barycenter(const int f) const override
face barycenter
Definition CMesh3D.cpp:1465
CMesh3D & operator=(CMesh3D &&)=default
int n_vertices() const override
number of vertices
Definition CMesh3D.hpp:50
Mesh3DStorage mesh_
Definition CMesh3D.hpp:149
bool is_boundary_face(const int face_global_id) const override
is face boundary
Definition CMesh3D.hpp:70
CMesh3D & operator=(const CMesh3D &)=default
bool is_boundary_edge(const int edge_global_id) const override
is edge boundary
Definition CMesh3D.hpp:69
void apply_affine_transformation(const MatrixNd &A, const VectorNd &b) override
Also moves the kernel points of the elements, used by polyhedral quadrature and refinement.
Definition CMesh3D.cpp:1197
double quad_area(const int gid) const override
area of a quad face of an hex mesh
Definition CMesh3D.cpp:1437
std::vector< uint32_t > vertex_neighs(const int v_gid) const override
Definition CMesh3D.hpp:99
void get_vertex_elements_neighs(const int v_id, std::vector< int > &ids) const override
Definition CMesh3D.hpp:112
Navigation3D::Index next_around_face(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:110
bool is_boundary_vertex(const int vertex_global_id) const override
is vertex boundary
Definition CMesh3D.hpp:68
Mesh3DStorage & mesh_storge()
Definition CMesh3D.hpp:130
RowVectorNd kernel(const int cell_id) const override
Definition CMesh3D.cpp:1221
Navigation3D::Index next_around_edge(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:109
void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector< std::vector< int > > &nodes) override
attach high order nodes
Definition CMesh3D.cpp:455
int cell_face_orientation(const int c_id, const int lf_id) const override
Definition CMesh3D.hpp:61
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh3D.cpp:1210
void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh3D.cpp:969
virtual ~CMesh3D()=default
bool build_storage_from_cells(const Eigen::MatrixXd &V, const std::vector< StandardCell > &cells)
Definition CMesh3D.cpp:215
Navigation3D::Index get_index_from_element_edge(int hi, int v0, int v1) const override
Definition CMesh3D.hpp:96
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh3D.cpp:1507
int n_cells() const override
number of cells
Definition CMesh3D.hpp:47
int n_faces() const override
number of faces
Definition CMesh3D.hpp:48
Navigation3D::Index switch_vertex(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:103
std::vector< uint32_t > edge_neighs(const int e_gid) const override
Definition CMesh3D.hpp:100
Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const override
Definition CMesh3D.hpp:93
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh3D.cpp:1519
void remove_elements(const std::vector< bool > &keep) override
Remove all top-dimensional elements whose mask entry is false.
Definition CMesh3D.cpp:18
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh3D.cpp:1228
Navigation3D::Index switch_edge(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:104
int n_cell_vertices(const int c_id) const override
number of vertices of a cell
Definition CMesh3D.hpp:53
Navigation3D::Index switch_face(Navigation3D::Index idx) const override
Definition CMesh3D.hpp:105
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:1493
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh3D.cpp:1146
int n_face_vertices(const int f_id) const override
number of vertices of a face
Definition CMesh3D.hpp:52
int cell_vertex(const int c_id, const int lv_id) const override
id of the vertex of a cell
Definition CMesh3D.hpp:56
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:1185
int size() const
Number of rows (a moved-from array has none).
int row_size(const int i) const
3D mesh interface: the elements are the cells (tetrahedra, hexahedra, prisms, pyramids or general pol...
Definition Mesh3D.hpp:22
Topology of a conforming 3D mesh (used by CMesh3D), stored as flat arrays indexed by entity id.
JaggedArray< uint8_t > cell_fs_flag
JaggedArray< uint32_t > cell_input_vs
input order (rows may be empty)
std::vector< uint8_t > vertex_boundary
Eigen::MatrixXd points
Vertex positions, 3 x #vertices.
JaggedArray< uint32_t > face_vs
std::vector< uint8_t > face_boundary
JaggedArray< uint32_t > cell_vs
navigation order (see above)
JaggedArray< uint32_t > cell_es
JaggedArray< uint32_t > vertex_hs
JaggedArray< uint32_t > edge_hs
std::vector< std::array< uint32_t, 2 > > edge_vs
JaggedArray< uint32_t > cell_fs
std::vector< uint8_t > edge_boundary
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:77
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, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
Definition Types.hpp:11
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, 3, 3 > MatrixNd
Definition Types.hpp:14
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13