16 std::vector<bool> interface_edges(
const Mesh2D &mesh)
18 std::vector<bool> is_interface(mesh.n_edges(),
false);
19 for (
int f = 0;
f < mesh.n_faces(); ++
f)
26 auto index = mesh.get_index_from_face(f, 0);
27 for (
int lv = 0; lv < mesh.n_face_vertices(f); ++lv)
29 auto index2 = mesh.switch_face(index);
32 is_interface[index.edge] =
true;
34 index = mesh.next_around_face(index);
40 std::vector<bool> interface_faces(
const Mesh3D &mesh)
42 std::vector<bool> is_interface(mesh.n_faces(),
false);
43 for (
int c = 0; c < mesh.n_cells(); ++c)
50 for (
int lf = 0; lf < mesh.n_cell_faces(c); ++lf)
52 auto index = mesh.get_index_from_element(c, lf, 0);
53 auto index2 = mesh.switch_element(index);
54 if (index2.element >= 0)
56 is_interface[index.face] =
true;
67 MeshNodes::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)
68 : mesh_(mesh), connect_nodes_(connect_nodes), edge_offset_(mesh.n_vertices()), face_offset_(edge_offset_ + mesh.n_edges() * max_nodes_per_edge), cell_offset_(face_offset_ + mesh.n_faces() * max_nodes_per_face)
71 max_nodes_per_edge_(max_nodes_per_edge), max_nodes_per_face_(max_nodes_per_face), max_nodes_per_cell_(max_nodes_per_cell)
93 for (
int e = 0; e < mesh.
n_edges(); ++e)
97 for (
int tmp = 0; tmp < max_nodes_per_edge; ++tmp)
102 for (
int f = 0; f < mesh.
n_faces(); ++f)
105 for (
int tmp = 0; tmp < max_nodes_per_face; ++tmp)
119 for (
int c = 0; c < mesh.
n_cells(); ++c)
121 for (
int tmp = 0; tmp < max_nodes_per_cell; ++tmp)
134 const Mesh3D *mesh3d =
dynamic_cast<const Mesh3D *
>(&mesh);
136 auto is_interface_face = interface_faces(*mesh3d);
137 for (
int f = 0; f < mesh.
n_faces(); ++f)
139 for (
int tmp = 0; tmp < max_nodes_per_face; ++tmp)
145 const Mesh2D *mesh2d =
dynamic_cast<const Mesh2D *
>(&mesh);
147 auto is_interface_edge = interface_edges(*mesh2d);
148 for (
int e = 0; e < mesh.
n_edges(); ++e)
150 for (
int tmp = 0; tmp < max_nodes_per_edge; ++tmp)
184 std::vector<int> res;
185 if (n_new_nodes <= 0)
208 assert(start_node_id < 0);
213 for (
int i = 1; i <= n_new_nodes; ++i)
217 const int primitive_id = start + i - 1;
220 const auto [node, node_id] = mesh2d->
edge_node(index, n_new_nodes, i);
228 nodes_.row(primitive_id) = node;
236 const auto [v, _] = mesh2d->
edge_node(index, n_new_nodes, 1);
240 for (
int i = 0; i < n_new_nodes; ++i)
242 const int primitive_id = start + i;
248 for (
int i = n_new_nodes - 1; i >= 0; --i)
250 const int primitive_id = start + i;
256 assert(res.size() ==
size_t(n_new_nodes));
262 std::vector<int> res;
263 if (n_new_nodes <= 0)
271 if (start_node_id < 0)
273 for (
int i = 1; i <= n_new_nodes; ++i)
275 const auto [node, node_id] = mesh3d->
edge_node(index, n_new_nodes, i);
277 const int primitive_id = start + i - 1;
284 nodes_.row(primitive_id) = node;
292 const auto [v, _] = mesh3d->
edge_node(index, n_new_nodes, 1);
295 for (
int i = 0; i < n_new_nodes; ++i)
297 const int primitive_id = start + i;
303 for (
int i = n_new_nodes - 1; i >= 0; --i)
305 const int primitive_id = start + i;
311 assert(res.size() ==
size_t(n_new_nodes));
317 std::vector<int> res;
318 if (n_new_nodes <= 0)
329 for (
int i = 1; i <= n_new_nodes; ++i)
331 const int end = mesh2d->
is_simplex(index.
face) ? (n_new_nodes - i + 1) : n_new_nodes;
332 for (
int j = 1; j <= end; ++j)
334 const auto [node, node_id] = mesh2d->
face_node(index, n_new_nodes, i, j);
336 const int primitive_id = start + loc_index;
343 nodes_.row(primitive_id) = node;
360 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
362 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
369 std::vector<int> res;
370 if (n_new_nodes <= 0)
392 assert(start_node_id < 0);
399 for (
int i = 1; i <= n_new_nodes; ++i)
401 const int end = is_tri ? (n_new_nodes - i + 1) : n_new_nodes;
402 for (
int j = 1; j <= end; ++j)
404 const int primitive_id = start + loc_index;
405 const auto [node, node_id] = mesh3d->
face_node(index, n_new_nodes, i, j);
413 nodes_.row(primitive_id) = node;
424 if (n_new_nodes == 1)
426 res.push_back(start_node_id);
430 const int total_nodes = is_tri ? (n_new_nodes * (n_new_nodes + 1) / 2) : (n_new_nodes * n_new_nodes);
431 for (
int i = 1; i <= n_new_nodes; ++i)
433 const int end = is_tri ? (n_new_nodes - i + 1) : n_new_nodes;
434 for (
int j = 1; j <= end; ++j)
436 const auto [p, _] = mesh3d->
face_node(index, n_new_nodes, i, j);
439 for (
int k = start; k < start + total_nodes; ++k)
441 const double dist = (
nodes_.row(k) - p).norm();
458 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
460 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
467 std::vector<int> res;
474 for (
int i = 1; i <= n_new_nodes; ++i)
476 const int endj = (n_new_nodes - i + 1);
477 for (
int j = 1; j <= endj; ++j)
479 const int endk = (n_new_nodes - i - j + 2);
480 for (
int k = 1; k <= endk; ++k)
482 const int primitive_id = start + loc_index;
484 auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
492 nodes_.row(primitive_id) = node;
504 for (
int i = 1; i <= n_new_nodes; ++i)
506 for (
int j = 1; j <= n_new_nodes; ++j)
508 for (
int k = 1; k <= n_new_nodes; ++k)
510 const int primitive_id = start + loc_index;
512 const auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
519 nodes_.row(primitive_id) = node;
539 assert(idx == res.front());
546 int n_cell_nodes = 0;
547 for (
int pp = 0; pp <= n_new_nodes; ++pp)
548 n_cell_nodes += (pp * (pp + 1) / 2);
549 assert(res.size() ==
size_t(n_cell_nodes));
552 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes * n_new_nodes));
612 std::vector<int> res;
619 res.push_back(node_id);
628 for (
int i = start_i; i < end_i; i++)
virtual std::pair< RowVectorNd, int > edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const =0
virtual std::pair< RowVectorNd, int > face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const =0
virtual Navigation::Index switch_face(Navigation::Index idx) const =0
virtual Navigation3D::Index switch_element(Navigation3D::Index idx) const =0
std::pair< RowVectorNd, int > cell_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j, const int k) const
std::pair< RowVectorNd, int > face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const
std::pair< RowVectorNd, int > edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
virtual int n_vertices() const =0
number of vertices
virtual RowVectorNd edge_barycenter(const int e) const =0
edge barycenter
virtual RowVectorNd face_barycenter(const int f) const =0
face barycenter
bool is_cube(const int el_id) const
checks if element is cube compatible
virtual RowVectorNd point(const int global_index) const =0
point coordinates
virtual bool is_boundary_face(const int face_global_id) const =0
is face boundary
virtual bool is_boundary_vertex(const int vertex_global_id) const =0
is vertex boundary
bool is_simplex(const int el_id) const
checks if element is simplex
bool is_prism(const int el_id) const
checks if element is a prism
virtual bool is_volume() const =0
checks if mesh is volume
virtual bool is_boundary_edge(const int edge_global_id) const =0
is edge boundary
int dimension() const
utily for dimension
virtual int n_cells() const =0
number of cells
virtual int n_faces() const =0
number of faces
virtual RowVectorNd cell_barycenter(const int c) const =0
cell barycenter
virtual int n_edges() const =0
number of edges
virtual int n_face_vertices(const int f_id) const =0
number of vertices of a face
bool is_boundary(int node_id) const
int node_id_from_primitive(int primitive_id)
std::vector< int > primitive_to_node_
const bool connect_nodes_
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
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)
std::vector< int > node_to_primitive_gid_
int node_id_from_cell(int c)
int node_id_from_vertex(int v)
std::vector< int > in_ordered_vertices_
const int max_nodes_per_face_
const int max_nodes_per_cell_
int face_from_node_id(int node_id) const
int vertex_from_node_id(int node_id) const
int count_nonnegative_nodes(int start_i, int end_i) const
int node_id_from_face(int f)
std::vector< int > boundary_nodes() const
const int max_nodes_per_edge_
int node_id_from_edge(int e)
int edge_from_node_id(int node_id) const
std::vector< int > node_to_primitive_
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_
void log_and_throw_error(const std::string &msg)