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_face(const Navigation3D::Index &index, const int n_new_nodes, const int n_new_nodesq);
38 std::vector<int> node_ids_from_cell(const Navigation3D::Index &index, const int n_new_nodes);
39
40 // Packed id of the first slot of a primitive (each edge/face/cell owns
41 // max_nodes_per_* consecutive slots)
42 int primitive_from_vertex(int v) const { return v; }
43 int primitive_from_edge(int e) const { return edge_offset_ + e * max_nodes_per_edge_; }
44 int primitive_from_face(int f) const { return face_offset_ + f * max_nodes_per_face_; }
45 int primitive_from_cell(int c) const { return cell_offset_ + c * max_nodes_per_cell_; }
46
47 bool is_vertex_node(int i) const { return i >= 0 && i < edge_offset_; }
48 bool is_edge_node(int i) const { return i >= edge_offset_ && i < face_offset_; }
49 bool is_face_node(int i) const { return i >= face_offset_ && i < cell_offset_; }
50 bool is_cell_node(int i) const { return i >= cell_offset_; }
51
56
57 // Primitive id from node id
58 int vertex_from_node_id(int node_id) const;
59 int edge_from_node_id(int node_id) const;
60 int face_from_node_id(int node_id) const;
61 int cell_from_node_id(int node_id) const;
62
63 const std::vector<int> &primitive_to_node() const { return primitive_to_node_; }
64 const std::vector<int> &node_to_primitive_gid() const { return node_to_primitive_gid_; }
65 const std::vector<int> &node_to_primitive() const { return node_to_primitive_; }
66 const std::vector<int> &in_ordered_vertices() const { return in_ordered_vertices_; }
67
68 // Node position from node id
69 RowVectorNd node_position(int node_id) const { return nodes_.row(node_to_primitive_[node_id]); }
70
73 void finalize();
77 int node_tag(const int node_id) const
78 {
79 return node_id >= 0 && node_id < int(node_tags_.size()) ? node_tags_[node_id] : -1;
80 }
81 bool has_node_tags() const { return !node_tags_.empty(); }
82
83 // Whether a node is on the mesh boundary or not
84 bool is_boundary(int node_id) const { return is_boundary_[node_to_primitive_[node_id]]; }
85 bool is_primitive_boundary(int primitive) const { return is_boundary_[primitive]; }
86
87 // Whether an edge node (in 2D) or face node (in 3D) is at the interface with a polytope
88 bool is_interface(int node_id) const { return is_interface_[node_to_primitive_[node_id]]; }
89 bool is_primitive_interface(int primitive) const { return is_interface_[primitive]; }
90
91 // Either boundary or interface
92 bool is_boundary_or_interface(const int node_id) const { return is_boundary(node_id) || is_interface(node_id); }
93
94 // Retrieve a list of nodes which are marked as boundary
95 std::vector<int> boundary_nodes() const;
96
97 private:
98 int count_nonnegative_nodes(int start_i, int end_i) const;
99
100 const Mesh &mesh_;
101 const bool connect_nodes_;
102 // Offset to pack primitives ids into a single vector
103 const int edge_offset_;
104 const int face_offset_;
105 const int cell_offset_;
106
110
111 // Map primitives to nodes back and forth
112 std::vector<int> primitive_to_node_; // #v + #e + #f + #c
113 std::vector<int> node_to_primitive_; // #assigned nodes
114 std::vector<int> node_to_primitive_gid_; // #assigned nodes
115
116 // Precomputed node data (#v + #e + #f + #c)
117 Eigen::MatrixXd nodes_;
118 std::vector<bool> is_boundary_;
119 std::vector<bool> is_interface_;
120
121 // Store the input nodes ids
122 std::vector<int> in_ordered_vertices_;
123
124 // Point-selection ids per node (see node_tag)
125 std::vector<int> node_tags_;
126 };
127 } // namespace mesh
128} // namespace polyfem
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:77
bool is_boundary(int node_id) const
Definition MeshNodes.hpp:84
bool has_node_tags() const
Definition MeshNodes.hpp:81
int node_id_from_primitive(int primitive_id)
bool is_boundary_or_interface(const int node_id) const
Definition MeshNodes.hpp:92
std::vector< int > primitive_to_node_
void finalize()
Called once all the nodes are created (at the end of the basis construction): computes the node tags ...
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:69
std::vector< int > node_to_primitive_gid_
Eigen::MatrixXd nodes_
std::vector< int > in_ordered_vertices_
int num_vertex_nodes() const
Definition MeshNodes.hpp:52
int primitive_from_face(int f) const
Definition MeshNodes.hpp:44
bool is_face_node(int i) const
Definition MeshNodes.hpp:49
int face_from_node_id(int node_id) const
bool is_cell_node(int i) const
Definition MeshNodes.hpp:50
bool is_edge_node(int i) const
Definition MeshNodes.hpp:48
int vertex_from_node_id(int node_id) const
const std::vector< int > & primitive_to_node() const
Definition MeshNodes.hpp:63
const std::vector< int > & node_to_primitive_gid() const
Definition MeshNodes.hpp:64
bool is_vertex_node(int i) const
Definition MeshNodes.hpp:47
int count_nonnegative_nodes(int start_i, int end_i) const
std::vector< int > boundary_nodes() const
const std::vector< int > & in_ordered_vertices() const
Definition MeshNodes.hpp:66
bool is_primitive_interface(int primitive) const
Definition MeshNodes.hpp:89
int primitive_from_vertex(int v) const
Definition MeshNodes.hpp:42
int primitive_from_cell(int c) const
Definition MeshNodes.hpp:45
std::vector< int > node_tags_
int primitive_from_edge(int e) const
Definition MeshNodes.hpp:43
const std::vector< int > & node_to_primitive() const
Definition MeshNodes.hpp:65
int edge_from_node_id(int node_id) const
std::vector< int > node_to_primitive_
bool is_interface(int node_id) const
Definition MeshNodes.hpp:88
std::vector< int > node_ids_from_edge(const Navigation::Index &index, const int n_new_nodes)
std::vector< bool > is_boundary_
int node_tag(const int node_id) const
Point-selection id of a node (Mesh::get_node_id of its vertex): -1 for nodes that are not on a vertex...
Definition MeshNodes.hpp:77
std::vector< bool > is_interface_
bool is_primitive_boundary(int primitive) const
Definition MeshNodes.hpp:85
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13