14 std::vector<bool> interface_edges(
const Mesh2D &mesh)
16 std::vector<bool> is_interface(mesh.n_edges(),
false);
17 for (
int f = 0;
f < mesh.n_faces(); ++
f)
24 auto index = mesh.get_index_from_face(f, 0);
25 for (
int lv = 0; lv < mesh.n_face_vertices(f); ++lv)
27 auto index2 = mesh.switch_face(index);
30 is_interface[index.edge] =
true;
32 index = mesh.next_around_face(index);
38 std::vector<bool> interface_faces(
const Mesh3D &mesh)
40 std::vector<bool> is_interface(mesh.n_faces(),
false);
41 for (
int c = 0; c < mesh.n_cells(); ++c)
48 for (
int lf = 0; lf < mesh.n_cell_faces(c); ++lf)
50 auto index = mesh.get_index_from_element(c, lf, 0);
51 auto index2 = mesh.switch_element(index);
52 if (index2.element >= 0)
54 is_interface[index.face] =
true;
65 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)
66 : 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)
69 max_nodes_per_edge_(max_nodes_per_edge), max_nodes_per_face_(max_nodes_per_face), max_nodes_per_cell_(max_nodes_per_cell)
91 for (
int e = 0; e < mesh.
n_edges(); ++e)
95 for (
int tmp = 0; tmp < max_nodes_per_edge; ++tmp)
100 for (
int f = 0; f < mesh.
n_faces(); ++f)
103 for (
int tmp = 0; tmp < max_nodes_per_face; ++tmp)
117 for (
int c = 0; c < mesh.
n_cells(); ++c)
119 for (
int tmp = 0; tmp < max_nodes_per_cell; ++tmp)
132 const Mesh3D *mesh3d =
dynamic_cast<const Mesh3D *
>(&mesh);
134 auto is_interface_face = interface_faces(*mesh3d);
135 for (
int f = 0; f < mesh.
n_faces(); ++f)
137 for (
int tmp = 0; tmp < max_nodes_per_face; ++tmp)
143 const Mesh2D *mesh2d =
dynamic_cast<const Mesh2D *
>(&mesh);
145 auto is_interface_edge = interface_edges(*mesh2d);
146 for (
int e = 0; e < mesh.
n_edges(); ++e)
148 for (
int tmp = 0; tmp < max_nodes_per_edge; ++tmp)
182 std::vector<int> res;
183 if (n_new_nodes <= 0)
206 assert(start_node_id < 0);
211 for (
int i = 1; i <= n_new_nodes; ++i)
215 const int primitive_id = start + i - 1;
218 const auto [node, node_id] = mesh2d->
edge_node(index, n_new_nodes, i);
226 nodes_.row(primitive_id) = node;
234 const auto [v, _] = mesh2d->
edge_node(index, n_new_nodes, 1);
238 for (
int i = 0; i < n_new_nodes; ++i)
240 const int primitive_id = start + i;
246 for (
int i = n_new_nodes - 1; i >= 0; --i)
248 const int primitive_id = start + i;
254 assert(res.size() ==
size_t(n_new_nodes));
260 std::vector<int> res;
261 if (n_new_nodes <= 0)
269 if (start_node_id < 0)
271 for (
int i = 1; i <= n_new_nodes; ++i)
273 const auto [node, node_id] = mesh3d->
edge_node(index, n_new_nodes, i);
275 const int primitive_id = start + i - 1;
282 nodes_.row(primitive_id) = node;
290 const auto [v, _] = mesh3d->
edge_node(index, n_new_nodes, 1);
293 for (
int i = 0; i < n_new_nodes; ++i)
295 const int primitive_id = start + i;
301 for (
int i = n_new_nodes - 1; i >= 0; --i)
303 const int primitive_id = start + i;
309 assert(res.size() ==
size_t(n_new_nodes));
315 std::vector<int> res;
316 if (n_new_nodes <= 0)
328 for (
int i = 1; i <= n_new_nodes; ++i)
330 const int end = mesh2d->
is_simplex(index.
face) ? (n_new_nodes - i + 1) : n_new_nodes;
331 for (
int j = 1; j <= end; ++j)
333 const auto [node, node_id] = mesh2d->
face_node(index, n_new_nodes, i, j);
335 const int primitive_id = start + loc_index;
342 nodes_.row(primitive_id) = node;
359 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
361 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
368 std::vector<int> res;
369 if (n_new_nodes <= 0)
391 assert(start_node_id < 0);
398 for (
int i = 1; i <= n_new_nodes; ++i)
400 const int end = mesh3d->
is_simplex(index.
element) ? (n_new_nodes - i + 1) : n_new_nodes;
401 for (
int j = 1; j <= end; ++j)
403 const int primitive_id = start + loc_index;
404 const auto [node, node_id] = mesh3d->
face_node(index, n_new_nodes, i, j);
412 nodes_.row(primitive_id) = node;
423 if (n_new_nodes == 1)
425 res.push_back(start_node_id);
429 const int total_nodes = mesh3d->
is_simplex(index.
element) ? (n_new_nodes * (n_new_nodes + 1) / 2) : (n_new_nodes * n_new_nodes);
430 for (
int i = 1; i <= n_new_nodes; ++i)
432 const int end = mesh3d->
is_simplex(index.
element) ? (n_new_nodes - i + 1) : n_new_nodes;
433 for (
int j = 1; j <= end; ++j)
435 const auto [p, _] = mesh3d->
face_node(index, n_new_nodes, i, j);
438 for (
int k = start; k < start + total_nodes; ++k)
440 const double dist = (
nodes_.row(k) - p).norm();
457 assert(res.size() ==
size_t(n_new_nodes * (n_new_nodes + 1) / 2));
459 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes));
466 std::vector<int> res;
473 for (
int i = 1; i <= n_new_nodes; ++i)
475 const int endj = (n_new_nodes - i + 1);
476 for (
int j = 1; j <= endj; ++j)
478 const int endk = (n_new_nodes - i - j + 2);
479 for (
int k = 1; k <= endk; ++k)
481 const int primitive_id = start + loc_index;
483 auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
491 nodes_.row(primitive_id) = node;
503 for (
int i = 1; i <= n_new_nodes; ++i)
505 for (
int j = 1; j <= n_new_nodes; ++j)
507 for (
int k = 1; k <= n_new_nodes; ++k)
509 const int primitive_id = start + loc_index;
511 const auto [node, node_id] = mesh3d->
cell_node(index, n_new_nodes, i, j, k);
518 nodes_.row(primitive_id) = node;
532 assert(idx == res.front());
539 int n_cell_nodes = 0;
540 for (
int pp = 0; pp <= n_new_nodes; ++pp)
541 n_cell_nodes += (pp * (pp + 1) / 2);
542 assert(res.size() ==
size_t(n_cell_nodes));
545 assert(res.size() ==
size_t(n_new_nodes * n_new_nodes * n_new_nodes));
605 std::vector<int> res;
612 res.push_back(node_id);
621 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
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 simples compatible
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
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_