PolyFEM
Loading...
Searching...
No Matches
MeshNodes.hpp
Go to the documentation of this file.
1#pragma once
2
5
8
9#include <Eigen/Dense>
10
11namespace polyfem
12{
13 namespace mesh
14 {
15
16 // Wrapper for lazy assignment of node ids
18 {
19 public:
20 MeshNodes(const Mesh &mesh, const bool has_poly, const bool connect_nodes, const int max_nodes_per_edge, const int max_nodes_per_face, const int max_nodes_per_cell = 0);
21
22 // Number of currently assigned nodes
23 int n_nodes() const { return node_to_primitive_.size(); }
24
25 // Lazy retrieval of node ids
26 int node_id_from_vertex(int v);
27 int node_id_from_edge(int e);
28 int node_id_from_face(int f);
29 int node_id_from_cell(int c);
30 int node_id_from_primitive(int primitive_id);
31
32 std::vector<int> node_ids_from_edge(const Navigation::Index &index, const int n_new_nodes);
33 std::vector<int> node_ids_from_face(const Navigation::Index &index, const int n_new_nodes);
34
35 std::vector<int> node_ids_from_edge(const Navigation3D::Index &index, const int n_new_nodes);
36 std::vector<int> node_ids_from_face(const Navigation3D::Index &index, const int n_new_nodes);
37 std::vector<int> node_ids_from_cell(const Navigation3D::Index &index, const int n_new_nodes);
38
39 // Packed id from primitive
40 int primitive_from_vertex(int v) const { return v; }
41 int primitive_from_edge(int e) const { return edge_offset_ + e; }
42 int primitive_from_face(int f) const { return face_offset_ + f; }
43 int primitive_from_cell(int c) const { return cell_offset_ + c; }
44
45 bool is_vertex_node(int i) const { return i >= 0 && i < edge_offset_; }
46 bool is_edge_node(int i) const { return i >= edge_offset_ && i < face_offset_; }
47 bool is_face_node(int i) const { return i >= face_offset_ && i < cell_offset_; }
48 bool is_cell_node(int i) const { return i >= cell_offset_; }
49
54
55 // Primitive id from node id
56 int vertex_from_node_id(int node_id) const;
57 int edge_from_node_id(int node_id) const;
58 int face_from_node_id(int node_id) const;
59 int cell_from_node_id(int node_id) const;
60
61 const std::vector<int> &primitive_to_node() const { return primitive_to_node_; }
62 const std::vector<int> &node_to_primitive_gid() const { return node_to_primitive_gid_; }
63 const std::vector<int> &node_to_primitive() const { return node_to_primitive_; }
64
65 // Node position from node id
66 RowVectorNd node_position(int node_id) const { return nodes_.row(node_to_primitive_[node_id]); }
67
68 // Whether a node is on the mesh boundary or not
69 bool is_boundary(int node_id) const { return is_boundary_[node_to_primitive_[node_id]]; }
70 bool is_primitive_boundary(int primitive) const { return is_boundary_[primitive]; }
71
72 // Whether an edge node (in 2D) or face node (in 3D) is at the interface with a polytope
73 bool is_interface(int node_id) const { return is_interface_[node_to_primitive_[node_id]]; }
74 bool is_primitive_interface(int primitive) const { return is_interface_[primitive]; }
75
76 // Either boundary or interface
77 bool is_boundary_or_interface(const int node_id) const { return is_boundary(node_id) || is_interface(node_id); }
78
79 // Retrieve a list of nodes which are marked as boundary
80 std::vector<int> boundary_nodes() const;
81
82 private:
83 int count_nonnegative_nodes(int start_i, int end_i) const;
84
85 const Mesh &mesh_;
86 const bool connect_nodes_;
87 // Offset to pack primitives ids into a single vector
88 const int edge_offset_;
89 const int face_offset_;
90 const int cell_offset_;
91
95
96 // Map primitives to nodes back and forth
97 std::vector<int> primitive_to_node_; // #v + #e + #f + #c
98 std::vector<int> node_to_primitive_; // #assigned nodes
99 std::vector<int> node_to_primitive_gid_; // #assigned nodes
100
101 // Precomputed node data (#v + #e + #f + #c)
102 Eigen::MatrixXd nodes_;
103 std::vector<bool> is_boundary_;
104 std::vector<bool> is_interface_;
105 };
106 } // namespace mesh
107} // namespace polyfem
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
bool is_boundary(int node_id) const
Definition MeshNodes.hpp:69
int node_id_from_primitive(int primitive_id)
bool is_boundary_or_interface(const int node_id) const
Definition MeshNodes.hpp:77
std::vector< int > primitive_to_node_
Definition MeshNodes.hpp:97
std::vector< int > node_ids_from_face(const Navigation::Index &index, const int n_new_nodes)
std::vector< int > node_ids_from_cell(const Navigation3D::Index &index, const int n_new_nodes)
int cell_from_node_id(int node_id) const
RowVectorNd node_position(int node_id) const
Definition MeshNodes.hpp:66
std::vector< int > node_to_primitive_gid_
Definition MeshNodes.hpp:99
Eigen::MatrixXd nodes_
int num_vertex_nodes() const
Definition MeshNodes.hpp:50
int primitive_from_face(int f) const
Definition MeshNodes.hpp:42
bool is_face_node(int i) const
Definition MeshNodes.hpp:47
int face_from_node_id(int node_id) const
bool is_cell_node(int i) const
Definition MeshNodes.hpp:48
bool is_edge_node(int i) const
Definition MeshNodes.hpp:46
int vertex_from_node_id(int node_id) const
const std::vector< int > & primitive_to_node() const
Definition MeshNodes.hpp:61
const std::vector< int > & node_to_primitive_gid() const
Definition MeshNodes.hpp:62
bool is_vertex_node(int i) const
Definition MeshNodes.hpp:45
int count_nonnegative_nodes(int start_i, int end_i) const
std::vector< int > boundary_nodes() const
bool is_primitive_interface(int primitive) const
Definition MeshNodes.hpp:74
int primitive_from_vertex(int v) const
Definition MeshNodes.hpp:40
int primitive_from_cell(int c) const
Definition MeshNodes.hpp:43
int primitive_from_edge(int e) const
Definition MeshNodes.hpp:41
const std::vector< int > & node_to_primitive() const
Definition MeshNodes.hpp:63
int edge_from_node_id(int node_id) const
std::vector< int > node_to_primitive_
Definition MeshNodes.hpp:98
bool is_interface(int node_id) const
Definition MeshNodes.hpp:73
std::vector< int > node_ids_from_edge(const Navigation::Index &index, const int n_new_nodes)
std::vector< bool > is_boundary_
std::vector< bool > is_interface_
bool is_primitive_boundary(int primitive) const
Definition MeshNodes.hpp:70
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:11