PolyFEM
Loading...
Searching...
No Matches
Mesh3D.cpp
Go to the documentation of this file.
4
6
7#include <igl/barycentric_coordinates.h>
8
9#include <fstream>
10
11namespace polyfem
12{
13 using namespace utils;
14
15 namespace mesh
16 {
17 double Mesh3D::tri_area(const int gid) const
18 {
19 const int n_vertices = n_face_vertices(gid);
20 assert(n_vertices == 3);
21
22 const auto v1 = point(face_vertex(gid, 0));
23 const auto v2 = point(face_vertex(gid, 1));
24 const auto v3 = point(face_vertex(gid, 2));
25
26 const Eigen::Vector3d e0 = (v2 - v1).transpose();
27 const Eigen::Vector3d e1 = (v3 - v1).transpose();
28
29 return e0.cross(e1).norm() / 2;
30 }
31
32 void Mesh3D::get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const
33 {
34 p0.resize(n_edges(), 3);
35 p1.resize(p0.rows(), p0.cols());
36
37 for (std::size_t e = 0; e < n_edges(); ++e)
38 {
39 const int v0 = edge_vertex(e, 0);
40 const int v1 = edge_vertex(e, 1);
41
42 p0.row(e) = point(v0);
43 p1.row(e) = point(v1);
44 }
45 }
46
47 void Mesh3D::get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1, const std::vector<bool> &valid_elements) const
48 {
49 int count = 0;
50 for (size_t i = 0; i < valid_elements.size(); ++i)
51 {
52 if (valid_elements[i])
53 {
54 count += n_cell_edges(i);
55 }
56 }
57
58 p0.resize(count, 3);
59 p1.resize(count, 3);
60
61 count = 0;
62
63 for (size_t i = 0; i < valid_elements.size(); ++i)
64 {
65 if (!valid_elements[i])
66 continue;
67
68 for (size_t ei = 0; ei < n_cell_edges(i); ++ei)
69 {
70 const int e = cell_edge(i, ei);
71 p0.row(count) = point(edge_vertex(e, 0));
72 p1.row(count) = point(edge_vertex(e, 1));
73
74 ++count;
75 }
76 }
77 }
78
79 std::pair<RowVectorNd, int> Mesh3D::edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const
80 {
81 if (orders_.size() <= 0 || orders_(index.element) == 1 || edge_nodes_.empty() || edge_nodes_[index.edge].nodes.rows() != n_new_nodes)
82 {
83 const auto v1 = point(index.vertex);
84 const auto v2 = point(switch_vertex(index).vertex);
85
86 const double t = i / (n_new_nodes + 1.0);
87
88 return std::make_pair((1 - t) * v1 + t * v2, -1);
89 }
90
91 const auto &n = edge_nodes_[index.edge];
92 if (n.v1 == index.vertex)
93 return std::make_pair(n.nodes.row(i - 1), n.nodes_ids[i - 1]);
94 else
95 return std::make_pair(n.nodes.row(n.nodes.rows() - i), n.nodes_ids[n.nodes_ids.size() - i]);
96 }
97
98 std::pair<RowVectorNd, int> Mesh3D::face_node(const Navigation3D::Index &index, const int n_new_nodes, const int n_new_nodesq, const int i, const int j) const
99 {
100 assert(is_prism(index.element));
101
102 const int tmp = n_new_nodes == 2 ? 3 : n_new_nodes; // ?
103
104 const bool is_prism_tri = n_face_vertices(index.face) == 3;
105 const bool is_prism_quad = n_face_vertices(index.face) == 4;
106
107 // for (int i = 0; i < face_nodes_.size(); ++i)
108 // {
109 // std::cout << "face " << i << ": " << face_nodes_[i].nodes.rows() << " nodes" << std::endl;
110 // }
111 if (is_prism_tri)
112 {
113 if (orders_.size() <= 0 || orders_(index.element) == 1 || orders_(index.element) == 2 || face_nodes_.empty() || face_nodes_[index.face].nodes.rows() != tmp)
114 {
115 const auto v1 = point(index.vertex);
116 const auto v2 = point(switch_vertex(index).vertex);
117 const auto v3 = point(switch_vertex(switch_edge(index)).vertex);
118
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;
122 assert(b3 < 1);
123 assert(b3 > 0);
124
125 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
126 }
127
128 const int ii = i - 1;
129 const int jj = j - 1;
130
131 assert(orders_(index.element) == 3 || orders_(index.element) == 4);
132 const auto &n = face_nodes_[index.face];
133 int lindex = jj * n_new_nodes + ii;
134
135 if (orders_(index.element) == 4) // high order geometric mesh
136 {
137 static const std::array<int, 3> remapping = {{0, 2, 1}};
138 if (n.v1 == index.vertex)
139 {
140 if (n.v2 != next_around_face(index).vertex)
141 {
142 lindex = remapping[lindex];
143 assert(n.v3 == next_around_face(index).vertex);
144 }
145 else
146 {
147 assert(n.v2 == next_around_face(index).vertex);
148 }
149 }
150 else if (n.v2 == index.vertex)
151 {
152
153 if (n.v3 != next_around_face(index).vertex)
154 {
155 lindex = remapping[lindex];
156 assert(n.v1 == next_around_face(index).vertex);
157 }
158 else
159 {
160 assert(n.v3 == switch_vertex(index).vertex);
161 }
162
163 lindex = (lindex + 1) % 3;
164 }
165 else if (n.v3 == index.vertex)
166 {
167
168 if (n.v1 != next_around_face(index).vertex)
169 {
170 lindex = remapping[lindex];
171 assert(n.v2 == next_around_face(index).vertex);
172 }
173 else
174 {
175 assert(n.v1 == switch_vertex(index).vertex);
176 }
177
178 lindex = (lindex + 2) % 3;
179 }
180 else
181 {
182 // assert(false);
183 }
184 }
185
186 return std::make_pair(n.nodes.row(lindex), n.nodes_ids[lindex]);
187 }
188 else if (is_prism_quad)
189 {
190 // supports only blilinear quads
191 assert(orders_.size() <= 0 || orders_(index.element) == 1);
192
193 const int lindex = (j - 1) * n_new_nodes + (i - 1);
194
195 const auto v1 = point(index.vertex);
196 const auto v2 = point(switch_vertex(index).vertex);
197 const auto v3 = point(switch_vertex(switch_edge(switch_vertex(index))).vertex);
198 const auto v4 = point(switch_vertex(switch_edge(index)).vertex);
199
200 if (is_prism_quad)
201 {
202 if (n_face_vertices(switch_face(index).face) == 4)
203 {
204 const double b1 = i / (n_new_nodesq + 1.0);
205 const double b2 = j / (n_new_nodes + 1.0);
206 assert(b1 <= 1);
207 assert(b2 <= 1);
208 assert(b1 >= 0);
209 assert(b2 >= 0);
210 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
211 }
212 else
213 {
214 const double b1 = i / (n_new_nodes + 1.0);
215 const double b2 = j / (n_new_nodesq + 1.0);
216 assert(b1 <= 1);
217 assert(b2 <= 1);
218 assert(b1 >= 0);
219 assert(b2 >= 0);
220 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
221 }
222 }
223 const double b1 = i / (n_new_nodes + 1.0);
224 const double b2 = j / (n_new_nodes + 1.0);
225
226 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
227 }
228
229 assert(false);
230 return std::make_pair(RowVectorNd(3, 1), -1);
231 }
232
233 std::pair<RowVectorNd, int> Mesh3D::face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const
234 {
235 assert(!is_prism(index.element));
236
237 const int tmp = n_new_nodes == 2 ? 3 : n_new_nodes;
238
239 const bool is_pyramid_tri = is_pyramid(index.element) && n_face_vertices(index.face) == 3;
240 const bool is_pyramid_quad = is_pyramid(index.element) && n_face_vertices(index.face) == 4;
241
242 if (is_simplex(index.element) || is_pyramid_tri)
243 {
244 if (orders_.size() <= 0 || orders_(index.element) == 1 || orders_(index.element) == 2 || face_nodes_.empty() || face_nodes_[index.face].nodes.rows() != tmp)
245 {
246 const auto v1 = point(index.vertex);
247 const auto v2 = point(switch_vertex(index).vertex);
248 const auto v3 = point(switch_vertex(switch_edge(index)).vertex);
249
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;
253 assert(b3 < 1);
254 assert(b3 > 0);
255
256 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
257 }
258
259 const int ii = i - 1;
260 const int jj = j - 1;
261
262 assert(orders_(index.element) == 3 || orders_(index.element) == 4);
263 const auto &n = face_nodes_[index.face];
264 int lindex = jj * n_new_nodes + ii;
265
266 if (orders_(index.element) == 4)
267 {
268 static const std::array<int, 3> remapping = {{0, 2, 1}};
269 if (n.v1 == index.vertex)
270 {
271 if (n.v2 != next_around_face(index).vertex)
272 {
273 lindex = remapping[lindex];
274 assert(n.v3 == next_around_face(index).vertex);
275 }
276 else
277 {
278 assert(n.v2 == next_around_face(index).vertex);
279 }
280 }
281 else if (n.v2 == index.vertex)
282 {
283
284 if (n.v3 != next_around_face(index).vertex)
285 {
286 lindex = remapping[lindex];
287 assert(n.v1 == next_around_face(index).vertex);
288 }
289 else
290 {
291 assert(n.v3 == switch_vertex(index).vertex);
292 }
293
294 lindex = (lindex + 1) % 3;
295 }
296 else if (n.v3 == index.vertex)
297 {
298
299 if (n.v1 != next_around_face(index).vertex)
300 {
301 lindex = remapping[lindex];
302 assert(n.v2 == next_around_face(index).vertex);
303 }
304 else
305 {
306 assert(n.v1 == switch_vertex(index).vertex);
307 }
308
309 lindex = (lindex + 2) % 3;
310 }
311 else
312 {
313 // assert(false);
314 }
315 }
316
317 return std::make_pair(n.nodes.row(lindex), n.nodes_ids[lindex]);
318 }
319 else if (is_cube(index.element) || is_pyramid_quad)
320 {
321 // supports only blilinear quads
322 assert(orders_.size() <= 0 || orders_(index.element) == 1);
323
324 const auto v1 = point(index.vertex);
325 const auto v2 = point(switch_vertex(index).vertex);
326 const auto v3 = point(switch_vertex(switch_edge(switch_vertex(index))).vertex);
327 const auto v4 = point(switch_vertex(switch_edge(index)).vertex);
328
329 const double b1 = i / (n_new_nodes + 1.0);
330 const double b2 = j / (n_new_nodes + 1.0);
331
332 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
333 }
334
335 assert(false);
336 return std::make_pair(RowVectorNd(3, 1), -1);
337 }
338
339 std::pair<RowVectorNd, int> Mesh3D::cell_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j, const int k) const
340 {
341 if (is_simplex(index.element) && orders_.size() > 0 && orders_(index.element) == n_new_nodes + 3)
342 {
343 assert(n_new_nodes == 1); // test higher than 4 order meshes
344 const auto &n = cell_nodes_[index.element];
345 assert(n.nodes.rows() == 1);
346 return std::make_pair(n.nodes, n.nodes_ids[0]);
347 }
348
349 if (n_new_nodes == 1)
350 return std::make_pair(cell_barycenter(index.element), -1);
351
352 if (is_simplex(index.element))
353 {
354 if (n_new_nodes == 1)
355 return std::make_pair(cell_barycenter(index.element), -1);
356 else
357 {
358 const auto v1 = point(index.vertex);
359 const auto v2 = point(switch_vertex(index).vertex);
360 const auto v3 = point(switch_vertex(switch_edge(switch_vertex(index))).vertex);
361 const auto v4 = point(switch_vertex(switch_edge(switch_face(index))).vertex);
362
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;
367
368 // return v1 * w3
369 // + v2 * w4
370 // + v3 * w1
371 // + v4 * w2;
372
373 return std::make_pair(w4 * v1 + w1 * v2 + w2 * v3 + w3 * v4, -1);
374 }
375 }
376 else if (is_cube(index.element))
377 {
378 // supports only blilinear hexes
379 assert(orders_.size() <= 0 || orders_(index.element) == 1);
380
381 const auto v1 = point(index.vertex);
382 const auto v2 = point(switch_vertex(index).vertex);
383 const auto v3 = point(switch_vertex(switch_edge(switch_vertex(index))).vertex);
384 const auto v4 = point(switch_vertex(switch_edge(index)).vertex);
385
387 const auto v5 = point(index1.vertex);
388 const auto v6 = point(switch_vertex(index1).vertex);
389 const auto v7 = point(switch_vertex(switch_edge(switch_vertex(index1))).vertex);
390 const auto v8 = point(switch_vertex(switch_edge(index1)).vertex);
391
392 const double b1 = i / (n_new_nodes + 1.0);
393 const double b2 = j / (n_new_nodes + 1.0);
394
395 const double b3 = k / (n_new_nodes + 1.0);
396
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;
399
400 return std::make_pair((1 - b3) * blin1 + b3 * blin2, -1);
401 }
402 else if (is_pyramid(index.element))
403 {
404 // n_new_nodes = p-1, k = z-level (1..n-1), i,j = grid indices
405 const double n = n_new_nodes;
406 const double zv = 1.0 - k / n; // z coordinate
407
408 double xv, yv;
409 if (k == 1) // single node at centroid of slice
410 {
411 xv = 0.5 * (1.0 - zv);
412 yv = 0.5 * (1.0 - zv);
413 }
414 else // k×k grid
415 {
416 const double hk = 1.0 / (k + 1);
417 xv = i * hk * (1.0 - zv);
418 yv = j * hk * (1.0 - zv);
419 }
420
421 const auto vids = get_ordered_vertices_from_pyramid(index.element);
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]);
427
428 const double x = xv;
429 const double y = yv;
430 const double z = zv;
431 const double one_minus_z = 1.0 - z;
432
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;
437 const double N4 = z;
438
439 const RowVectorNd node = N0 * v0 + N1 * v1 + N2 * v2 + N3 * v3 + N4 * v4;
440
441 return std::make_pair(node, -1);
442 }
443
444 assert(false);
445 return std::make_pair(RowVectorNd(3, 1), -1);
446 }
447
448 void Mesh3D::to_face_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 6> &to_face) const
449 {
450 // top
451 to_face[0] = [&](Navigation3D::Index idx) { return switch_face(switch_edge(switch_vertex(switch_edge(switch_face(idx))))); };
452 // bottom
453 to_face[1] = [&](Navigation3D::Index idx) { return idx; };
454
455 // left
456 to_face[2] = [&](Navigation3D::Index idx) { return switch_face(switch_edge(switch_vertex(idx))); };
457 // right
458 to_face[3] = [&](Navigation3D::Index idx) { return switch_face(switch_edge(idx)); };
459
460 // back
461 to_face[4] = [&](Navigation3D::Index idx) { return switch_face(switch_edge(switch_vertex(switch_edge(switch_vertex(idx))))); };
462 // front
463 to_face[5] = [&](Navigation3D::Index idx) { return switch_face(idx); };
464 }
465
466 void Mesh3D::to_vertex_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 8> &to_vertex) const
467 {
468 to_vertex[0] = [&](Navigation3D::Index idx) { return idx; };
469 to_vertex[1] = [&](Navigation3D::Index idx) { return switch_vertex(idx); };
470 to_vertex[2] = [&](Navigation3D::Index idx) { return switch_vertex(switch_edge(switch_vertex(idx))); };
471 to_vertex[3] = [&](Navigation3D::Index idx) { return switch_vertex(switch_edge(idx)); };
472
473 to_vertex[4] = [&](Navigation3D::Index idx) { return switch_vertex(switch_edge(switch_face(idx))); };
474 to_vertex[5] = [&](Navigation3D::Index idx) { return switch_vertex(switch_edge(switch_vertex(switch_edge(switch_face(idx))))); };
476 to_vertex[7] = [&](Navigation3D::Index idx) { return switch_vertex(switch_edge(switch_face(switch_vertex(switch_edge(idx))))); };
477 }
478
479 void Mesh3D::to_edge_functions(std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 12> &to_edge) const
480 {
481 to_edge[0] = [&](Navigation3D::Index idx) { return idx; };
482 to_edge[1] = [&](Navigation3D::Index idx) { return switch_edge(switch_vertex(idx)); };
483 to_edge[2] = [&](Navigation3D::Index idx) { return switch_edge(switch_vertex(switch_edge(switch_vertex(idx)))); };
485
486 to_edge[4] = [&](Navigation3D::Index idx) { return switch_edge(switch_face(idx)); };
487 to_edge[5] = [&](Navigation3D::Index idx) { return switch_edge(switch_face(switch_edge(switch_vertex(idx)))); };
490
491 to_edge[8] = [&](Navigation3D::Index idx) { return switch_edge(switch_vertex(switch_edge(switch_face(idx)))); };
495 }
496
497 // v7────v6
498 // ╱┆ ╱│
499 // v4─┼──v5 │
500 // │v3┄┄┄┼v2
501 // │╱ │╱
502 // v0────v1
503 std::array<int, 8> Mesh3D::get_ordered_vertices_from_hex(const int element_index) const
504 {
505 assert(is_cube(element_index));
506 auto idx = get_index_from_element(element_index);
507 std::array<int, 8> v;
508
509 std::array<std::function<Navigation3D::Index(Navigation3D::Index)>, 8> to_vertex;
510 to_vertex_functions(to_vertex);
511 for (int i = 0; i < 8; ++i)
512 v[i] = to_vertex[i](idx).vertex;
513
514 // for (int lv = 0; lv < 4; ++lv) {
515 // v[lv] = idx.vertex;
516 // idx = next_around_face_of_element(idx);
517 // }
518 // // assert(idx == get_index_from_element(element_index));
519 // idx = switch_face(switch_edge(switch_vertex(switch_edge(switch_face(idx)))));
520 // for (int lv = 0; lv < 4; ++lv) {
521 // v[4+lv] = idx.vertex;
522 // idx = next_around_face_of_element(idx);
523 // }
524 return v;
525 }
526
527 std::array<int, 4> Mesh3D::get_ordered_vertices_from_tet(const int element_index) const
528 {
529 auto idx = get_index_from_element(element_index);
530 std::array<int, 4> v;
531
532 for (int lv = 0; lv < 3; ++lv)
533 {
534 v[lv] = idx.vertex;
535 idx = next_around_face(idx);
536 }
537 // assert(idx == get_index_from_element(element_index));
539 v[3] = idx.vertex;
540
541 return v;
542 }
543
544 // v5
545 // ╱┆ \
546 // v3─┼──v4
547 // │v2 |
548 // │╱ \ │
549 // v0────v1
550 std::array<int, 6> Mesh3D::get_ordered_vertices_from_prism(const int element_index) const
551 {
552 assert(is_prism(element_index));
553 auto idx = get_index_from_element(element_index);
554 std::array<int, 6> v;
555
556 Navigation3D::Index start = idx;
557
558 for (int i = 0; i < 3; ++i)
559 idx = next_around_face(idx);
560
561 if (idx.vertex != start.vertex)
562 start = switch_face(idx);
563
564 for (int i = 0; i < 3; ++i)
565 {
566 v[i] = start.vertex;
567 start = next_around_face(start);
568 }
569 assert(start.vertex == v[0]);
570
572 for (int i = 0; i < 3; ++i)
573 {
574 v[i + 3] = start.vertex;
575 start = next_around_face(start);
576 }
577 assert(start.vertex == v[3]);
578 return v;
579 }
580
581 std::array<int, 5> Mesh3D::get_ordered_vertices_from_pyramid(const int element_index) const
582 {
583 auto idx = get_index_from_element(element_index);
584 std::array<int, 5> v;
585
586 Navigation3D::Index base; // we want to start navigation from base
587 if (n_face_vertices(idx.face) == 4)
588 {
589 base = idx;
590 }
591 else
592 {
593 Navigation3D::Index tmp = idx;
594 bool found = false;
595 for (int k = 0; k < 3; ++k)
596 {
597 auto nb = switch_face(tmp);
598 if (n_face_vertices(nb.face) == 4)
599 {
600 base = nb;
601 found = true;
602 break;
603 }
604 tmp = next_around_face(tmp);
605 }
606 assert(found);
607 }
608
609 idx = base;
610 for (int lv = 0; lv < 4; ++lv)
611 {
612 v[lv] = idx.vertex;
613 idx = next_around_face(idx);
614 }
615 // assert(idx == get_index_from_element(element_index));
617 v[4] = idx.vertex;
618
619 return v;
620 }
621
622 void Mesh3D::elements_boxes(std::vector<std::array<Eigen::Vector3d, 2>> &boxes) const
623 {
624 boxes.resize(n_elements());
625
626 for (int i = 0; i < n_elements(); ++i)
627 {
628 auto &box = boxes[i];
629 box[0].setConstant(std::numeric_limits<double>::max());
630 box[1].setConstant(std::numeric_limits<double>::lowest());
631
632 for (int j = 0; j < n_cell_vertices(i); ++j)
633 {
634 const int v_id = cell_vertex(i, j);
635 for (int d = 0; d < 3; ++d)
636 {
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]);
639 }
640 }
641 }
642 }
643
644 void Mesh3D::barycentric_coords(const RowVectorNd &p, const int el_id, Eigen::MatrixXd &coord) const
645 {
646 assert(is_simplex(el_id));
647
648 const auto indices = get_ordered_vertices_from_tet(el_id);
649
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]);
654
655 igl::barycentric_coordinates(p, A, B, C, D, coord);
656 }
657
658 void Mesh3D::compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
659 {
660 assert(is_simplex(el_id));
661
662 const auto indices = get_ordered_vertices_from_tet(el_id);
663
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]);
668
669 Eigen::MatrixXd coords(4, 4);
670 coords << A, 1, B, 1, C, 1, D, 1;
671 coords.transposeInPlace();
672
673 jacobian = coords * reference_map;
674
675 assert(jacobian.determinant() > 0);
676 }
677
678 } // namespace mesh
679} // namespace polyfem
Eigen::RowVectorXd point
int y
int z
int x
void to_vertex_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 8 > &to_vertex) const
Definition Mesh3D.cpp:466
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
Definition Mesh3D.cpp:17
void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
Definition Mesh3D.cpp:658
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
Definition Mesh3D.cpp:581
void elements_boxes(std::vector< std::array< Eigen::Vector3d, 2 > > &boxes) const override
constructs a box around every element (3d cell, 2d face)
Definition Mesh3D.cpp:622
std::array< int, 8 > get_ordered_vertices_from_hex(const int element_index) const
Definition Mesh3D.cpp:503
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
Definition Mesh3D.cpp:339
void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override
Get all the edges.
Definition Mesh3D.cpp:32
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.
Definition Mesh3D.cpp:644
std::pair< RowVectorNd, int > face_node(const Navigation3D::Index &index, const int n_new_nodes, const int i, const int j) const
Definition Mesh3D.cpp:233
std::pair< RowVectorNd, int > edge_node(const Navigation3D::Index &index, const int n_new_nodes, const int i) const
Definition Mesh3D.cpp:79
virtual std::array< int, 4 > get_ordered_vertices_from_tet(const int element_index) const
Definition Mesh3D.cpp:527
void to_edge_functions(std::array< std::function< Navigation3D::Index(Navigation3D::Index)>, 12 > &to_edge) const
Definition Mesh3D.cpp:479
std::array< int, 6 > get_ordered_vertices_from_prism(const int element_index) const
Definition Mesh3D.cpp:550
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
Definition Mesh3D.cpp:448
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
Definition Mesh.hpp:181
virtual int n_vertices() const =0
number of vertices
Eigen::MatrixXi orders_
list of geometry orders, one per cell
Definition Mesh.hpp:728
bool is_cube(const int el_id) const
checks if element is cube compatible
Definition Mesh.cpp:361
bool is_simplex(const int el_id) const
checks if element is simplex
Definition Mesh.cpp:392
bool is_prism(const int el_id) const
checks if element is a prism
Definition Mesh.cpp:397
std::vector< CellNodes > cell_nodes_
high-order nodes associates to cells
Definition Mesh.hpp:737
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
Definition Mesh.hpp:735
std::vector< EdgeNodes > edge_nodes_
high-order nodes associates to edges
Definition Mesh.hpp:733
bool is_pyramid(const int el_id) const
checks if element is a pyramid
Definition Mesh.cpp:402
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
Definition Types.hpp:13