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 const std::vector<int> &in_ordered_vertices() const { return in_ordered_vertices_; }
65
66 // Node position from node id
67 RowVectorNd node_position(int node_id) const { return nodes_.row(node_to_primitive_[node_id]); }
68
69 // Whether a node is on the mesh boundary or not
70 bool is_boundary(int node_id) const { return is_boundary_[node_to_primitive_[node_id]]; }
71 bool is_primitive_boundary(int primitive) const { return is_boundary_[primitive]; }
72
73 // Whether an edge node (in 2D) or face node (in 3D) is at the interface with a polytope
74 bool is_interface(int node_id) const { return is_interface_[node_to_primitive_[node_id]]; }
75 bool is_primitive_interface(int primitive) const { return is_interface_[primitive]; }
76
77 // Either boundary or interface
78 bool is_boundary_or_interface(const int node_id) const { return is_boundary(node_id) || is_interface(node_id); }
79
80 // Retrieve a list of nodes which are marked as boundary
81 std::vector<int> boundary_nodes() const;
82
83 private:
84 int count_nonnegative_nodes(int start_i, int end_i) const;
85
86 const Mesh &mesh_;
87 const bool connect_nodes_;
88 // Offset to pack primitives ids into a single vector
89 const int edge_offset_;
90 const int face_offset_;
91 const int cell_offset_;
92
96
97 // Map primitives to nodes back and forth
98 std::vector<int> primitive_to_node_; // #v + #e + #f + #c
99 std::vector<int> node_to_primitive_; // #assigned nodes
100 std::vector<int> node_to_primitive_gid_; // #assigned nodes
101
102 // Precomputed node data (#v + #e + #f + #c)
103 Eigen::MatrixXd nodes_;
104 std::vector<bool> is_boundary_;
105 std::vector<bool> is_interface_;
106
107 // Store the input nodes ids
108 std::vector<int> in_ordered_vertices_;
109 };
110 } // namespace mesh
111} // 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:70
int node_id_from_primitive(int primitive_id)
bool is_boundary_or_interface(const int node_id) const
Definition MeshNodes.hpp:78
std::vector< int > primitive_to_node_
Definition MeshNodes.hpp:98
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:67
std::vector< int > node_to_primitive_gid_
Eigen::MatrixXd nodes_
std::vector< int > in_ordered_vertices_
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
const std::vector< int > & in_ordered_vertices() const
Definition MeshNodes.hpp:64
bool is_primitive_interface(int primitive) const
Definition MeshNodes.hpp:75
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:99
bool is_interface(int node_id) const
Definition MeshNodes.hpp:74
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:71
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13