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)
189 std::vector<int> res;
190 if (n_new_nodes <= 0)
213 assert(start_node_id < 0);
218 for (
int i = 1; i <= n_new_nodes; ++i)
222 const int primitive_id = start + i - 1;
225 const auto [node, node_id] = mesh2d->
edge_node(index, n_new_nodes, i);
233 nodes_.row(primitive_id) = node;
241 const auto [v, _] = mesh2d->
edge_node(index, n_new_nodes, 1);
245 for (
int i = 0; i < n_new_nodes; ++i)
247 const int primitive_id = start + i;
253 for (
int i = n_new_nodes - 1; i >= 0; --i)
255 const int primitive_id = start + i;
261 assert(res.size() ==
size_t(n_new_nodes));
267 std::vector<int> res;
268 if (n_new_nodes <= 0)
276 if (start_node_id < 0)
278 for (
int i = 1; i <= n_new_nodes; ++i)
280 const auto [node, node_id] = mesh3d->
edge_node(index, n_new_nodes, i);
282 const int primitive_id = start + i - 1;
289 nodes_.row(primitive_id) = node;
297 const auto [v, _] = mesh3d->
edge_node(index, n_new_nodes, 1);
300 for (
int i = 0; i < n_new_nodes; ++i)
302 const int primitive_id = start + i;
308 for (
int i = n_new_nodes - 1; i >= 0; --i)
310 const int primitive_id = start + i;
316 assert(res.size() ==
size_t(n_new_nodes));
322 std::vector<int> res;
323 if (n_new_nodes <= 0)
334 for (
int i = 1; i <= n_new_nodes; ++i)
336 const int end = mesh2d->
is_simplex(index.
face) ? (n_new_nodes - i + 1) : n_new_nodes;
337 for (
int j = 1; j <= end; ++j)
339 const auto [node, node_id] = mesh2d->
face_node(index, n_new_nodes, i, j);
341 const int primitive_id = start + loc_index;
348 nodes_.row(primitive_id) = node;
365 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
367 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
376 std::vector<int> res;
377 if (n_new_nodes <= 0)
401 assert(start_node_id < 0);
411 for (
int i = 1; i <= n_new_nodes; ++i)
413 const int end = n_new_nodes - i + 1;
414 for (
int j = 1; j <= end; ++j)
416 const int primitive_id = start + loc_index;
417 const auto [node, node_id] = mesh3d->
face_node(index, n_new_nodes, -1, i, j);
425 nodes_.row(primitive_id) = node;
441 for (
int i = 1; i <= n_new_nodes; ++i)
443 for (
int j = 1; j <= n_new_nodesq; ++j)
445 const int primitive_id = start + loc_index;
446 const auto [node, node_id] = mesh3d->
face_node(index, n_new_nodes, n_new_nodesq, j, i);
454 nodes_.row(primitive_id) = node;
468 const int total_nodes = n_new_nodes * (n_new_nodes + 1) / 2;
469 for (
int i = 1; i <= n_new_nodes; ++i)
471 const int end = n_new_nodes - i + 1;
472 for (
int j = 1; j <= end; ++j)
474 const auto [p, _] = mesh3d->
face_node(index, n_new_nodes, n_new_nodesq, i, j);
477 for (
int k = start; k < start + total_nodes; ++k)
479 const double dist = (
nodes_.row(k) - p).norm();
499 const int total_nodes = n_new_nodes * n_new_nodesq;
500 for (
int i = 1; i <= n_new_nodes; ++i)
502 const int end = n_new_nodesq;
503 for (
int j = 1; j <= end; ++j)
505 const auto [p, _] = mesh3d->
face_node(index, n_new_nodes, n_new_nodesq, j, i);
508 for (
int k = start; k < start + total_nodes; ++k)
510 const double dist = (
nodes_.row(k) - p).norm();
527 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
529 assert(res.size() ==
size_t(n_new_nodes * n_new_nodesq));
536 std::vector<int> res;
537 if (n_new_nodes <= 0)
561 assert(start_node_id < 0);
568 for (
int i = 1; i <= n_new_nodes; ++i)
570 const int end = is_tri ? (n_new_nodes - i + 1) : n_new_nodes;
571 for (
int j = 1; j <= end; ++j)
573 const int primitive_id = start + loc_index;
574 const auto [node, node_id] = mesh3d->
face_node(index, n_new_nodes, i, j);
582 nodes_.row(primitive_id) = node;
593 if (n_new_nodes == 1)
595 res.push_back(start_node_id);
599 const int total_nodes = is_tri ? (n_new_nodes * (n_new_nodes + 1) / 2) : (n_new_nodes * n_new_nodes);
600 for (
int i = 1; i <= n_new_nodes; ++i)
602 const int end = is_tri ? (n_new_nodes - i + 1) : n_new_nodes;
603 for (
int j = 1; j <= end; ++j)
605 const auto [p, _] = mesh3d->
face_node(index, n_new_nodes, i, j);
608 for (
int k = start; k < start + total_nodes; ++k)
610 const double dist = (
nodes_.row(k) - p).norm();
627 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
629 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
636 std::vector<int> res;
643 for (
int i = 1; i <= n_new_nodes; ++i)
645 const int endj = (n_new_nodes - i + 1);
646 for (
int j = 1; j <= endj; ++j)
648 const int endk = (n_new_nodes - i - j + 2);
649 for (
int k = 1; k <= endk; ++k)
651 const int primitive_id = start + loc_index;
653 auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
661 nodes_.row(primitive_id) = node;
673 for (
int i = 1; i <= n_new_nodes; ++i)
675 for (
int j = 1; j <= n_new_nodes; ++j)
677 for (
int k = 1; k <= n_new_nodes; ++k)
679 const int primitive_id = start + loc_index;
681 const auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
688 nodes_.row(primitive_id) = node;
699 assert(n_new_nodes == 1);
702 const int primitive_id = start + loc_index;
704 const auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, 0, 0, 0);
711 nodes_.row(primitive_id) = node;
719 for (
int k = 1; k < n_new_nodes; ++k)
721 const int grid = (k == 1) ? 1 : k;
722 for (
int i = 1; i <= grid; ++i)
724 for (
int j = 1; j <= grid; ++j)
726 const int primitive_id = start + loc_index;
727 const auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
733 nodes_.row(primitive_id) = node;
747 assert(idx == res.front());
754 int n_cell_nodes = 0;
755 for (
int pp = 0; pp <= n_new_nodes; ++pp)
756 n_cell_nodes += (pp * (pp + 1) / 2);
757 assert(res.size() ==
size_t(n_cell_nodes));
760 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes * n_new_nodes));
826 for (
int n = 0; n <
n_nodes(); ++n)
838 std::vector<int> res;
845 res.push_back(node_id);
854 for (
int i = start_i; i < end_i; i++)
2D mesh interface: the elements are the faces (polygons) and the boundary elements are the edges.
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
3D mesh interface: the elements are the cells (tetrahedra, hexahedra, prisms, pyramids or general pol...
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
virtual Navigation3D::Index next_around_face(Navigation3D::Index idx) const =0
virtual Navigation3D::Index switch_face(Navigation3D::Index idx) const =0
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
bool has_node_ids() const
checks if points selections are available
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
bool is_pyramid(const int el_id) const
checks if element is a pyramid
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
virtual int get_node_id(const int node_id) const
Get the boundary selection of a node.
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_
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
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
bool is_vertex_node(int i) 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)
std::vector< int > node_tags_
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)