7#include <igl/barycentric_coordinates.h>
13 using namespace utils;
26 const Eigen::Vector3d e0 = (v2 - v1).transpose();
27 const Eigen::Vector3d e1 = (v3 - v1).transpose();
29 return e0.cross(e1).norm() / 2;
35 p1.resize(p0.rows(), p0.cols());
37 for (std::size_t e = 0; e <
n_edges(); ++e)
42 p0.row(e) =
point(v0);
43 p1.row(e) =
point(v1);
47 void Mesh3D::get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1,
const std::vector<bool> &valid_elements)
const
50 for (
size_t i = 0; i < valid_elements.size(); ++i)
52 if (valid_elements[i])
63 for (
size_t i = 0; i < valid_elements.size(); ++i)
65 if (!valid_elements[i])
86 const double t = i / (n_new_nodes + 1.0);
88 return std::make_pair((1 - t) * v1 + t * v2, -1);
93 return std::make_pair(n.nodes.row(i - 1), n.nodes_ids[i - 1]);
95 return std::make_pair(n.nodes.row(n.nodes.rows() - i), n.nodes_ids[n.nodes_ids.size() - i]);
102 const int tmp = n_new_nodes == 2 ? 3 : n_new_nodes;
119 const double b2 = i / (n_new_nodes + 2.0);
120 const double b3 = j / (n_new_nodes + 2.0);
121 const double b1 = 1 - b3 - b2;
125 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
128 const int ii = i - 1;
129 const int jj = j - 1;
133 int lindex = jj * n_new_nodes + ii;
137 static const std::array<int, 3> remapping = {{0, 2, 1}};
142 lindex = remapping[lindex];
150 else if (n.v2 == index.
vertex)
155 lindex = remapping[lindex];
163 lindex = (lindex + 1) % 3;
165 else if (n.v3 == index.
vertex)
170 lindex = remapping[lindex];
178 lindex = (lindex + 2) % 3;
186 return std::make_pair(n.nodes.row(lindex), n.nodes_ids[lindex]);
188 else if (is_prism_quad)
193 const int lindex = (j - 1) * n_new_nodes + (i - 1);
204 const double b1 = i / (n_new_nodesq + 1.0);
205 const double b2 = j / (n_new_nodes + 1.0);
210 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
214 const double b1 = i / (n_new_nodes + 1.0);
215 const double b2 = j / (n_new_nodesq + 1.0);
220 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
223 const double b1 = i / (n_new_nodes + 1.0);
224 const double b2 = j / (n_new_nodes + 1.0);
226 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
237 const int tmp = n_new_nodes == 2 ? 3 : n_new_nodes;
250 const double b2 = i / (n_new_nodes + 2.0);
251 const double b3 = j / (n_new_nodes + 2.0);
252 const double b1 = 1 - b3 - b2;
256 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
259 const int ii = i - 1;
260 const int jj = j - 1;
264 int lindex = jj * n_new_nodes + ii;
268 static const std::array<int, 3> remapping = {{0, 2, 1}};
273 lindex = remapping[lindex];
281 else if (n.v2 == index.
vertex)
286 lindex = remapping[lindex];
294 lindex = (lindex + 1) % 3;
296 else if (n.v3 == index.
vertex)
301 lindex = remapping[lindex];
309 lindex = (lindex + 2) % 3;
317 return std::make_pair(n.nodes.row(lindex), n.nodes_ids[lindex]);
329 const double b1 = i / (n_new_nodes + 1.0);
330 const double b2 = j / (n_new_nodes + 1.0);
332 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
343 assert(n_new_nodes == 1);
345 assert(n.nodes.rows() == 1);
346 return std::make_pair(n.nodes, n.nodes_ids[0]);
349 if (n_new_nodes == 1)
354 if (n_new_nodes == 1)
363 const double w1 = double(i) / (n_new_nodes + 3);
364 const double w2 = double(j) / (n_new_nodes + 3);
365 const double w3 = double(k) / (n_new_nodes + 3);
366 const double w4 = 1 - w1 - w2 - w3;
373 return std::make_pair(w4 * v1 + w1 * v2 + w2 * v3 + w3 * v4, -1);
392 const double b1 = i / (n_new_nodes + 1.0);
393 const double b2 = j / (n_new_nodes + 1.0);
395 const double b3 = k / (n_new_nodes + 1.0);
397 RowVectorNd blin1 = v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2;
398 RowVectorNd blin2 = v5 * (1 - b1) * (1 - b2) + v6 * b1 * (1 - b2) + v7 * b1 * b2 + v8 * (1 - b1) * b2;
400 return std::make_pair((1 - b3) * blin1 + b3 * blin2, -1);
405 const double n = n_new_nodes;
406 const double zv = 1.0 - k / n;
411 xv = 0.5 * (1.0 - zv);
412 yv = 0.5 * (1.0 - zv);
416 const double hk = 1.0 / (k + 1);
417 xv = i * hk * (1.0 - zv);
418 yv = j * hk * (1.0 - zv);
422 const auto v0 =
point(vids[0]);
423 const auto v1 =
point(vids[1]);
424 const auto v2 =
point(vids[2]);
425 const auto v3 =
point(vids[3]);
426 const auto v4 =
point(vids[4]);
431 const double one_minus_z = 1.0 -
z;
433 const double N0 = (one_minus_z * (one_minus_z -
x -
y) +
x *
y) / one_minus_z;
434 const double N1 =
x * (one_minus_z -
y) / one_minus_z;
435 const double N2 =
x *
y / one_minus_z;
436 const double N3 =
y * (one_minus_z -
x) / one_minus_z;
439 const RowVectorNd node = N0 * v0 + N1 * v1 + N2 * v2 + N3 * v3 + N4 * v4;
441 return std::make_pair(node, -1);
505 assert(
is_cube(element_index));
507 std::array<int, 8> v;
511 for (
int i = 0; i < 8; ++i)
512 v[i] = to_vertex[i](idx).vertex;
530 std::array<int, 4> v;
532 for (
int lv = 0; lv < 3; ++lv)
554 std::array<int, 6> v;
558 for (
int i = 0; i < 3; ++i)
561 if (idx.vertex != start.
vertex)
564 for (
int i = 0; i < 3; ++i)
569 assert(start.
vertex == v[0]);
572 for (
int i = 0; i < 3; ++i)
577 assert(start.
vertex == v[3]);
584 std::array<int, 5> v;
595 for (
int k = 0; k < 3; ++k)
610 for (
int lv = 0; lv < 4; ++lv)
628 auto &box = boxes[i];
629 box[0].setConstant(std::numeric_limits<double>::max());
630 box[1].setConstant(std::numeric_limits<double>::lowest());
635 for (
int d = 0; d < 3; ++d)
637 box[0][d] = std::min(box[0][d],
point(v_id)[d]);
638 box[1][d] = std::max(box[1][d],
point(v_id)[d]);
650 const auto A =
point(indices[0]);
651 const auto B =
point(indices[1]);
652 const auto C =
point(indices[2]);
653 const auto D =
point(indices[3]);
655 igl::barycentric_coordinates(p, A, B, C, D, coord);
664 const auto A =
point(indices[0]);
665 const auto B =
point(indices[1]);
666 const auto C =
point(indices[2]);
667 const auto D =
point(indices[3]);
669 Eigen::MatrixXd coords(4, 4);
670 coords << A, 1, B, 1, C, 1, D, 1;
671 coords.transposeInPlace();
673 jacobian = coords * reference_map;
675 assert(jacobian.determinant() > 0);
void to_vertex_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 8 > &to_vertex) const
virtual Navigation3D::Index get_index_from_element(int hi, int lf, int lv) const =0
double tri_area(const int gid) const override
area of a tri face of a tet mesh
void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
virtual int n_cell_edges(const int c_id) const =0
virtual int cell_edge(const int c_id, const int le_id) const =0
std::array< int, 5 > get_ordered_vertices_from_pyramid(const int element_index) const
void elements_boxes(std::vector< std::array< Eigen::Vector3d, 2 > > &boxes) const override
constructs a box around every element (3d cell, 2d face)
std::array< int, 8 > get_ordered_vertices_from_hex(const int element_index) const
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
void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override
Get all the edges.
virtual Navigation3D::Index switch_edge(Navigation3D::Index idx) const =0
void barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const override
constructs barycentric coodiantes for a point p.
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 std::array< int, 4 > get_ordered_vertices_from_tet(const int element_index) const
void to_edge_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 12 > &to_edge) const
std::array< int, 6 > get_ordered_vertices_from_prism(const int element_index) const
virtual Navigation3D::Index next_around_face(Navigation3D::Index idx) const =0
virtual Navigation3D::Index switch_face(Navigation3D::Index idx) const =0
void to_face_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 6 > &to_face) const
virtual Navigation3D::Index switch_vertex(Navigation3D::Index idx) const =0
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
virtual int n_vertices() const =0
number of vertices
Eigen::MatrixXi orders_
list of geometry orders, one per cell
bool is_cube(const int el_id) const
checks if element is cube compatible
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
std::vector< CellNodes > cell_nodes_
high-order nodes associates to cells
virtual int edge_vertex(const int e_id, const int lv_id) const =0
id of the edge vertex
std::vector< FaceNodes > face_nodes_
high-order nodes associates to faces
std::vector< EdgeNodes > edge_nodes_
high-order nodes associates to edges
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 cell_vertex(const int f_id, const int lv_id) const =0
id of the vertex of a cell
virtual int n_face_vertices(const int f_id) const =0
number of vertices of a face
virtual int n_cell_vertices(const int c_id) const =0
number of vertices of a cell
virtual int face_vertex(const int f_id, const int lv_id) const =0
id of the face vertex
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd