PolyFEM
Loading...
Searching...
No Matches
CMesh2D.cpp
Go to the documentation of this file.
3
8
9#include <cassert>
10#include <array>
11#include <unordered_map>
12#include <type_traits>
13
14namespace polyfem
15{
16 using namespace utils;
17
18 namespace mesh
19 {
20 void CMesh2D::remove_elements(const std::vector<bool> &keep)
21 {
22 assert(keep.size() == n_faces());
23
24 std::unordered_map<std::pair<int, int>, int, utils::HashPair> old_edge_ids;
25 std::unordered_map<std::pair<int, int>, EdgeNodes, utils::HashPair> old_edge_nodes;
26 for (int e = 0; e < n_edges(); ++e)
27 {
28 const std::pair<int, int> key = std::minmax(edge_vertex(e, 0), edge_vertex(e, 1));
29 if (has_boundary_ids())
30 old_edge_ids[key] = boundary_ids_[e];
31 if (e < edge_nodes_.size())
32 old_edge_nodes[key] = edge_nodes_[e];
33 }
34
35 auto filter_nodes = [&keep](auto &nodes) {
36 if (nodes.size() != keep.size())
37 return;
38 std::decay_t<decltype(nodes)> filtered;
39 for (int i = 0; i < keep.size(); ++i)
40 if (keep[i])
41 filtered.push_back(nodes[i]);
42 nodes = std::move(filtered);
43 };
44 filter_nodes(face_nodes_);
45 filter_nodes(cell_nodes_);
47
48 // All vertices are kept (as CMesh3D does), so vertex indices and the
49 // vertex-keyed maps above stay valid.
50 std::vector<bool> to_delete(mesh_.n_facets(), false);
51 for (int f = 0; f < keep.size(); ++f)
52 to_delete[f] = !keep[f];
53 mesh_.delete_facets(to_delete);
54
56
57 if (!old_edge_ids.empty())
58 {
59 boundary_ids_.resize(n_edges());
60 for (int e = 0; e < n_edges(); ++e)
61 {
62 const std::pair<int, int> key = std::minmax(edge_vertex(e, 0), edge_vertex(e, 1));
63 const auto it = old_edge_ids.find(key);
64 boundary_ids_[e] = it == old_edge_ids.end() ? get_default_boundary_id(e) : it->second;
65 }
66 }
67 else
68 boundary_ids_.clear();
69
70 edge_nodes_.clear();
71 if (!old_edge_nodes.empty())
72 {
73 edge_nodes_.resize(n_edges());
74 for (int e = 0; e < n_edges(); ++e)
75 {
76 const std::pair<int, int> key = std::minmax(edge_vertex(e, 0), edge_vertex(e, 1));
77 const auto it = old_edge_nodes.find(key);
78 if (it != old_edge_nodes.end())
79 edge_nodes_[e] = it->second;
80 }
81 }
82
83 in_ordered_edges_.resize(n_edges(), 2);
84 for (int e = 0; e < n_edges(); ++e)
85 in_ordered_edges_.row(e) << edge_vertex(e, 0), edge_vertex(e, 1);
87 }
88
89 void CMesh2D::refine(const int n_refinement, const double t)
90 {
91 // return;
92 if (n_refinement <= 0)
93 {
94 return;
95 }
96
98
99 bool all_simplicial = true;
100 for (int e = 0; e < n_elements(); ++e)
101 {
102 all_simplicial &= is_simplex(e);
103 }
104
105 for (int i = 0; i < n_refinement; ++i)
106 {
107 const PolygonMesh mesh = std::move(mesh_);
108 mesh_.clear();
109
110 // TODO add tags to the refinement
111 if (all_simplicial)
112 {
114 }
115 else if (t <= 0)
116 {
118 }
119 else
120 {
122 }
123
125 }
126
129
130 in_ordered_vertices_ = Eigen::VectorXi::LinSpaced(mesh_.n_vertices(), 0, mesh_.n_vertices() - 1);
131 assert(in_ordered_vertices_[0] == 0);
132 assert(in_ordered_vertices_[1] == 1);
133 assert(in_ordered_vertices_[2] == 2);
134 assert(in_ordered_vertices_[in_ordered_vertices_.size() - 1] == mesh_.n_vertices() - 1);
135
136 in_ordered_edges_.resize(mesh_.n_edges(), 2);
137
138 for (int e = 0; e < mesh_.n_edges(); ++e)
139 {
140 for (int lv = 0; lv < 2; ++lv)
141 {
142 in_ordered_edges_(e, lv) = mesh_.edge_vertex(e, lv);
143 }
144 assert(in_ordered_edges_(e, 0) != in_ordered_edges_(e, 1));
145 }
146 assert(in_ordered_edges_.size() > 0);
147
148 in_ordered_faces_.resize(0, 0);
149 }
150
152 {
153 const Eigen::MatrixXd &V = data.vertices;
154 const Eigen::MatrixXi &F = data.elements;
155 edge_nodes_.clear();
156 face_nodes_.clear();
157 cell_nodes_.clear();
158
159 mesh_.clear();
160 mesh_.create_vertices(V.rows());
161 for (int i = 0; i < V.rows(); ++i)
162 {
164 point[0] = V(i, 0);
165 point[1] = V(i, 1);
166 point[2] = 0;
167 }
168 for (int i = 0; i < F.rows(); ++i)
169 {
170 std::vector<int> vertices;
171 vertices.reserve(F.cols());
172 for (int j = 0; j < F.cols() && F(i, j) >= 0; ++j)
173 vertices.push_back(F(i, j));
174 if (vertices.size() < 3)
175 return false;
176 mesh_.create_polygon(vertices);
177 }
178
181
183 return true;
184 }
185
186 void CMesh2D::attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector<std::vector<int>> &nodes)
187 {
188 edge_nodes_.clear();
189 face_nodes_.clear();
190 cell_nodes_.clear();
191
192 edge_nodes_.resize(n_edges());
193 face_nodes_.resize(n_faces());
194
195 orders_.setOnes(n_faces(), 1);
196
197 assert(nodes.size() == n_faces());
198
199 for (int f = 0; f < n_faces(); ++f)
200 {
201 auto index = get_index_from_face(f);
202
203 const auto &nodes_ids = nodes[f];
204
205 // Only triangles can be curved. Mesh::append lists the plain
206 // vertices of the linear quads and polygons it merges with curved
207 // triangles, so a node list as long as the vertex list is linear.
208 if (n_face_vertices(f) != 3)
209 {
210 if (nodes_ids.size() != size_t(n_face_vertices(f)))
211 log_and_throw_error("Element {} is a curved polygon with {} vertices and {} nodes; only triangles can be curved.", f, n_face_vertices(f), nodes_ids.size());
212 continue;
213 }
214
215 if (nodes_ids.size() == 3)
216 {
217 orders_(f) = 1;
218 continue;
219 }
220 // P2
221 else if (nodes_ids.size() == 6)
222 {
223 orders_(f) = 2;
224
225 for (int le = 0; le < 3; ++le)
226 {
227 auto &n = edge_nodes_[index.edge];
228
229 // nodes not aleardy created
230 if (n.nodes.size() <= 0)
231 {
232 n.v1 = index.vertex;
233 n.v2 = switch_vertex(index).vertex;
234
235 int node_index = 0;
236 if ((n.v1 == nodes_ids[0] && n.v2 == nodes_ids[1]) || (n.v2 == nodes_ids[0] && n.v1 == nodes_ids[1]))
237 node_index = 3;
238 else if ((n.v1 == nodes_ids[1] && n.v2 == nodes_ids[2]) || (n.v2 == nodes_ids[1] && n.v1 == nodes_ids[2]))
239 node_index = 4;
240 else
241 node_index = 5;
242
243 n.nodes.resize(1, 2);
244 n.nodes << V(nodes_ids[node_index], 0), V(nodes_ids[node_index], 1);
245 n.nodes_ids.push_back(nodes_ids[node_index]);
246 }
247 index = next_around_face(index);
248 }
249 }
250 // P3
251 else if (nodes_ids.size() == 10)
252 {
253 orders_(f) = 3;
254
255 for (int le = 0; le < 3; ++le)
256 {
257 auto &n = edge_nodes_[index.edge];
258
259 // nodes not aleardy created
260 if (n.nodes.size() <= 0)
261 {
262 n.v1 = index.vertex;
263 n.v2 = switch_vertex(index).vertex;
264
265 int node_index1 = 0;
266 int node_index2 = 0;
267 if (n.v1 == nodes_ids[0] && n.v2 == nodes_ids[1])
268 {
269 node_index1 = 3;
270 node_index2 = 4;
271 }
272 else if (n.v2 == nodes_ids[0] && n.v1 == nodes_ids[1])
273 {
274 node_index1 = 4;
275 node_index2 = 3;
276 }
277 else if (n.v1 == nodes_ids[1] && n.v2 == nodes_ids[2])
278 {
279 node_index1 = 5;
280 node_index2 = 6;
281 }
282 else if (n.v2 == nodes_ids[1] && n.v1 == nodes_ids[2])
283 {
284 node_index1 = 6;
285 node_index2 = 5;
286 }
287 else if (n.v1 == nodes_ids[2] && n.v2 == nodes_ids[0])
288 {
289 node_index1 = 7;
290 node_index2 = 8;
291 }
292 else
293 {
294 assert(n.v2 == nodes_ids[2] && n.v1 == nodes_ids[0]);
295 node_index1 = 8;
296 node_index2 = 7;
297 }
298
299 n.nodes.resize(2, 2);
300 n.nodes.row(0) << V(nodes_ids[node_index1], 0), V(nodes_ids[node_index1], 1);
301 n.nodes.row(1) << V(nodes_ids[node_index2], 0), V(nodes_ids[node_index2], 1);
302
303 n.nodes_ids.push_back(nodes_ids[node_index1]);
304 n.nodes_ids.push_back(nodes_ids[node_index2]);
305 }
306 index = next_around_face(index);
307 }
308
309 {
310 auto &n = face_nodes_[f];
311 n.v1 = mesh_.facet_vertex(f, 0);
312 n.v2 = mesh_.facet_vertex(f, 1);
313 n.v3 = mesh_.facet_vertex(f, 2);
314 n.nodes.resize(1, 2);
315 n.nodes << V(nodes_ids[9], 0), V(nodes_ids[9], 1);
316 n.nodes_ids.push_back(nodes_ids[9]);
317 }
318 }
319 // unsupported (including P4, which has no geometric mapping yet)
320 else
321 {
322 log_and_throw_error("Unsupported higher-order triangle with {} nodes (supported: 3, 6, 10).", nodes_ids.size());
323 }
324 }
325
326 if (orders_.maxCoeff() == 1)
327 orders_.resize(0, 0);
328 }
329
330 std::pair<RowVectorNd, int> CMesh2D::edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const
331 {
332 if (orders_.size() <= 0 || orders_(index.face) == 1 || edge_nodes_.empty() || edge_nodes_[index.edge].nodes.rows() != n_new_nodes)
333 {
334 const auto v1 = point(index.vertex);
335 const auto v2 = point(switch_vertex(index).vertex);
336
337 const double t = i / (n_new_nodes + 1.0);
338
339 return std::make_pair((1 - t) * v1 + t * v2, -1);
340 }
341
342 const auto &n = edge_nodes_[index.edge];
343 if (n.v1 == index.vertex)
344 return std::make_pair(n.nodes.row(i - 1), n.nodes_ids[i - 1]);
345 else
346 {
347 assert(n.v2 == index.vertex);
348 return std::make_pair(n.nodes.row(n.nodes.rows() - i), n.nodes_ids[n.nodes_ids.size() - i]);
349 }
350 }
351
352 std::pair<RowVectorNd, int> CMesh2D::face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const
353 {
354 if (is_simplex(index.face))
355 {
356 if (orders_.size() <= 0 || orders_(index.face) == 1 || orders_(index.face) == 2 || face_nodes_.empty() || face_nodes_[index.face].nodes.rows() != n_new_nodes)
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(index)).vertex);
361
362 const double b2 = i / (n_new_nodes + 2.0);
363 const double b3 = j / (n_new_nodes + 2.0);
364 const double b1 = 1 - b3 - b2;
365 assert(b3 < 1);
366 assert(b3 > 0);
367
368 return std::make_pair(b1 * v1 + b2 * v2 + b3 * v3, -1);
369 }
370
371 assert(orders_(index.face) == 3);
372 // unsupported P4 for geometry
373 const auto &n = face_nodes_[index.face];
374 return std::make_pair(n.nodes.row(0), n.nodes_ids[0]);
375 }
376 else if (is_cube(index.face))
377 {
378 // supports only blilinear quads
379 assert(orders_.size() <= 0 || orders_(index.face) == 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
386 const double b1 = i / (n_new_nodes + 1.0);
387 const double b2 = j / (n_new_nodes + 1.0);
388
389 return std::make_pair(v1 * (1 - b1) * (1 - b2) + v2 * b1 * (1 - b2) + v3 * b1 * b2 + v4 * (1 - b1) * b2, -1);
390 }
391
392 assert(false);
393 return std::make_pair(RowVectorNd(2, 1), -1);
394 }
395
397 {
398 PolygonMesh::Point min_corner, max_corner;
399 mesh_.bounding_box(min_corner, max_corner);
400 min.resize(2);
401 max.resize(2);
402
403 min(0) = min_corner[0];
404 min(1) = min_corner[1];
405
406 max(0) = max_corner[0];
407 max(1) = max_corner[1];
408 }
409
411 {
412
413 PolygonMesh::Point min_corner, max_corner;
414 mesh_.bounding_box(min_corner, max_corner);
415 PolygonMesh::Point extent = max_corner - min_corner;
416 double scaling = std::max(extent[0], std::max(extent[1], extent[2]));
417 // const PolygonMesh::Point origin = 0.5 * (min_corner + max_corner);
418 const PolygonMesh::Point origin = min_corner;
419 for (int v = 0; v < mesh_.n_vertices(); ++v)
420 {
421 mesh_.point(v) = (mesh_.point(v) - origin) / scaling;
422 }
423 Eigen::RowVector2d shift;
424 shift << origin[0], origin[1];
425 for (auto &n : edge_nodes_)
426 {
427 if (n.nodes.size() > 0)
428 n.nodes = (n.nodes.rowwise() - shift) / scaling;
429 }
430 for (auto &n : face_nodes_)
431 {
432 if (n.nodes.size() > 0)
433 n.nodes = (n.nodes.rowwise() - shift) / scaling;
434 }
435 Eigen::Vector2d normalization_translation;
436 normalization_translation << -origin[0] / scaling, -origin[1] / scaling;
438 Eigen::Matrix2d::Identity() / scaling,
439 normalization_translation);
440
441 logger().debug("-- bbox before normalization:");
442 logger().debug(" min : {} {}", min_corner[0], min_corner[1]);
443 logger().debug(" max : {} {}", max_corner[0], max_corner[1]);
444 logger().debug(" extent: {} {}", max_corner[0] - min_corner[0], max_corner[1] - min_corner[1]);
445 mesh_.bounding_box(min_corner, max_corner);
446 logger().debug("-- bbox after normalization:");
447 logger().debug(" min : {} {}", min_corner[0], min_corner[1]);
448 logger().debug(" max : {} {}", max_corner[0], max_corner[1]);
449 logger().debug(" extent: {} {}", max_corner[0] - min_corner[0], max_corner[1] - min_corner[1]);
450
451 Eigen::MatrixXd p0, p1, p;
452 get_edges(p0, p1);
453 p = p0 - p1;
454 logger().debug("-- edge length after normalization:");
455 logger().debug(" min: {}", p.rowwise().norm().minCoeff());
456 logger().debug(" max: {}", p.rowwise().norm().maxCoeff());
457 logger().debug(" avg: {}", p.rowwise().norm().mean());
458 }
459
460 double CMesh2D::edge_length(const int gid) const
461 {
462 const int v0 = mesh_.edge_vertex(gid, 0);
463 const int v1 = mesh_.edge_vertex(gid, 1);
464
465 return (point(v0) - point(v1)).norm();
466 }
467
468 void CMesh2D::set_point(const int global_index, const RowVectorNd &p)
469 {
470 mesh_.point(global_index)[0] = p(0);
471 mesh_.point(global_index)[1] = p(1);
472 }
473
474 RowVectorNd CMesh2D::point(const int global_index) const
475 {
476 const PolygonMesh::Point &pt = mesh_.point(global_index);
477 RowVectorNd p(2);
478 p(0) = pt[0];
479 p(1) = pt[1];
480 return p;
481 }
482
483 bool CMesh2D::is_boundary_element(const int element_global_id) const
484 {
485 auto index = get_index_from_face(element_global_id);
486
487 for (int i = 0; i < n_face_vertices(element_global_id); ++i)
488 {
489 if (is_boundary_edge(index.edge))
490 return true;
491
492 index = next_around_face(index);
493 }
494
495 return false;
496 }
497
498 // void CMesh2D::triangulate_faces(Eigen::MatrixXi &tris, Eigen::MatrixXd &pts, std::vector<int> &ranges) const
499 // {
500 // ranges.clear();
501
502 // std::vector<Eigen::MatrixXi> local_tris(mesh_.facets.nb());
503 // std::vector<Eigen::MatrixXd> local_pts(mesh_.facets.nb());
504
505 // int total_tris = 0;
506 // int total_pts = 0;
507
508 // ranges.push_back(0);
509
510 // for (GEO::index_t f = 0; f < mesh_.facets.nb(); ++f)
511 // {
512 // const int n_vertices = mesh_.facets.nb_vertices(f);
513
514 // Eigen::MatrixXd face_pts(n_vertices, 2);
515 // // Eigen::MatrixXi edges(n_vertices,2);
516 // local_tris[f].resize(n_vertices - 2, 3);
517
518 // for (int i = 0; i < n_vertices; ++i)
519 // {
520 // const int vertex = mesh_.facets.vertex(f, i);
521 // const double *pt = mesh_.vertices.point_ptr(vertex);
522 // face_pts(i, 0) = pt[0];
523 // face_pts(i, 1) = pt[1];
524
525 // // edges(i, 0) = i;
526 // // edges(i, 1) = (i+1) % n_vertices;
527 // }
528
529 // for (int i = 1; i < n_vertices - 1; ++i)
530 // {
531 // local_tris[f].row(i - 1) << 0, i, i + 1;
532 // }
533
534 // local_pts[f] = face_pts;
535
536 // total_tris += local_tris[f].rows();
537 // total_pts += local_pts[f].rows();
538
539 // ranges.push_back(total_tris);
540
541 // assert(local_pts[f].rows() == face_pts.rows());
542 // }
543
544 // tris.resize(total_tris, 3);
545 // pts.resize(total_pts, 2);
546
547 // int tri_index = 0;
548 // int pts_index = 0;
549 // for (std::size_t i = 0; i < local_tris.size(); ++i)
550 // {
551 // tris.block(tri_index, 0, local_tris[i].rows(), local_tris[i].cols()) = local_tris[i].array() + pts_index;
552 // tri_index += local_tris[i].rows();
553
554 // pts.block(pts_index, 0, local_pts[i].rows(), local_pts[i].cols()) = local_pts[i];
555 // pts_index += local_pts[i].rows();
556 // }
557 // }
558
564
569
571 {
572 const int v0 = mesh_.edge_vertex(index, 0);
573 const int v1 = mesh_.edge_vertex(index, 1);
574
575 return 0.5 * (point(v0) + point(v1));
576 }
577
578 void CMesh2D::compute_body_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &)> &marker)
579 {
580 body_ids_.resize(n_elements());
581 std::fill(body_ids_.begin(), body_ids_.end(), -1);
582
583 for (int e = 0; e < n_elements(); ++e)
584 {
585 const auto bary = face_barycenter(e);
586 body_ids_[e] = marker(e, element_vertices(e), bary);
587 }
588 }
589
590 void CMesh2D::compute_boundary_ids(const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &marker)
591 {
592 boundary_ids_.resize(n_edges());
593
594 for (int e = 0; e < n_edges(); ++e)
595 {
596 bool is_boundary = is_boundary_edge(e);
597 const auto p = edge_barycenter(e);
598 std::vector<int> vs = {edge_vertex(e, 0), edge_vertex(e, 1)};
599 std::sort(vs.begin(), vs.end());
600 boundary_ids_[e] = marker(e, vs, p, is_boundary);
601 }
602 }
603
604 void CMesh2D::append(const Mesh &mesh)
605 {
606 assert(typeid(mesh) == typeid(CMesh2D));
607 Mesh::append(mesh);
608
609 const CMesh2D &mesh2d = dynamic_cast<const CMesh2D &>(mesh);
610
611 const int n_v = n_vertices();
612 const int n_f = n_faces();
613
615 for (int i = n_v; i < mesh_.n_vertices(); ++i)
616 {
617 set_point(i, mesh2d.point(i - n_v));
618 }
619
620 std::vector<int> indices;
621 for (int i = 0; i < mesh2d.n_faces(); ++i)
622 {
623 indices.clear();
624 for (int j = 0; j < mesh2d.mesh_.n_facet_vertices(i); ++j)
625 indices.push_back(mesh2d.mesh_.facet_vertex(i, j) + n_v);
626
627 mesh_.create_polygon(indices);
628 }
629
630 assert(n_vertices() == n_v + mesh2d.n_vertices());
631 assert(n_faces() == n_f + mesh2d.n_faces());
632
634 }
635
636 std::unique_ptr<Mesh> CMesh2D::copy() const
637 {
638 return std::make_unique<CMesh2D>(*this);
639 }
640 } // namespace mesh
641} // namespace polyfem
int V
Eigen::RowVectorXd point
Conforming 2D mesh of arbitrary polygons, stored in a PolygonMesh.
Definition CMesh2D.hpp:24
virtual RowVectorNd edge_barycenter(const int index) const override
edge barycenter
Definition CMesh2D.cpp:570
Navigation::Index switch_edge(Navigation::Index idx) const override
Definition CMesh2D.hpp:87
void normalize() override
normalize the mesh
Definition CMesh2D.cpp:410
void compute_elements_tag() override
compute element types, see ElementType
Definition CMesh2D.cpp:559
int n_faces() const override
number of faces
Definition CMesh2D.hpp:37
int n_face_vertices(const int f_id) const override
number of vertices of a face
Definition CMesh2D.hpp:41
int n_vertices() const override
number of vertices
Definition CMesh2D.hpp:39
int n_edges() const override
number of edges
Definition CMesh2D.hpp:38
bool is_boundary_element(const int element_global_id) const override
is cell boundary
Definition CMesh2D.cpp:483
double edge_length(const int gid) const override
edge length
Definition CMesh2D.cpp:460
std::pair< RowVectorNd, int > edge_node(const Navigation::Index &index, const int n_new_nodes, const int i) const override
Definition CMesh2D.cpp:330
std::unique_ptr< Mesh > copy() const override
Create a copy of the mesh.
Definition CMesh2D.cpp:636
Navigation::Index switch_vertex(Navigation::Index idx) const override
Definition CMesh2D.hpp:86
void compute_boundary_ids(const std::function< int(const size_t, const std::vector< int > &, const RowVectorNd &, bool)> &marker) override
computes boundary selections based on a function
Definition CMesh2D.cpp:590
void set_point(const int global_index, const RowVectorNd &p) override
Set the point.
Definition CMesh2D.cpp:468
bool build_topology(const MeshData &data) override
Construct only the dimension-specific topology.
Definition CMesh2D.cpp:151
bool is_boundary_edge(const int edge_global_id) const override
is edge boundary
Definition CMesh2D.hpp:51
std::pair< RowVectorNd, int > face_node(const Navigation::Index &index, const int n_new_nodes, const int i, const int j) const override
Definition CMesh2D.cpp:352
void append(const Mesh &mesh) override
appends a new mesh to the end of this
Definition CMesh2D.cpp:604
int edge_vertex(const int e_id, const int lv_id) const override
id of the edge vertex
Definition CMesh2D.hpp:44
Navigation::Index get_index_from_face(int f, int lv=0) const override
Definition CMesh2D.hpp:83
virtual void bounding_box(RowVectorNd &min, RowVectorNd &max) const override
computes the bbox of the mesh
Definition CMesh2D.cpp:396
void remove_elements(const std::vector< bool > &keep) override
Remove all top-dimensional elements whose mask entry is false.
Definition CMesh2D.cpp:20
void attach_higher_order_nodes(const Eigen::MatrixXd &V, const std::vector< std::vector< int > > &nodes) override
attach high order nodes
Definition CMesh2D.cpp:186
void refine(const int n_refinement, const double t) override
refine the mesh
Definition CMesh2D.cpp:89
void compute_body_ids(const std::function< int(const size_t, const std::vector< int > &, const RowVectorNd &)> &marker) override
computes boundary selections based on a function
Definition CMesh2D.cpp:578
virtual RowVectorNd point(const int global_index) const override
point coordinates
Definition CMesh2D.cpp:474
virtual void update_elements_tag() override
Update elements types.
Definition CMesh2D.cpp:565
RowVectorNd face_barycenter(const int index) const override
face barycenter
Definition Mesh2D.cpp:64
Navigation::Index next_around_face(Navigation::Index idx) const
Definition Mesh2D.hpp:63
void get_edges(Eigen::MatrixXd &p0, Eigen::MatrixXd &p1) const override
Get all the edges.
Definition Mesh2D.cpp:16
Class to store the high-order edge nodes.
Definition Mesh.hpp:81
Format-independent input used to construct a runtime Mesh.
Definition MeshData.hpp:12
Eigen::MatrixXd vertices
Definition MeshData.hpp:21
Eigen::MatrixXi elements
Definition MeshData.hpp:22
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:77
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
Definition Mesh.hpp:181
Eigen::MatrixXi orders_
list of geometry orders, one per cell
Definition Mesh.hpp:728
std::vector< ElementType > elements_tag_
list of element types
Definition Mesh.hpp:718
void clear_data_lost_by_refinement()
Drop the labels and the higher-order geometry before a conforming refinement.
Definition Mesh.cpp:702
bool has_boundary_ids() const
checks if surface selections are available
Definition Mesh.hpp:557
bool is_cube(const int el_id) const
checks if element is cube compatible
Definition Mesh.cpp:361
Eigen::MatrixXi in_ordered_faces_
Order of the input faces, TODO: change to std::vector of Eigen::Vector.
Definition Mesh.hpp:754
bool is_simplex(const int el_id) const
checks if element is simplex
Definition Mesh.cpp:392
std::vector< int > boundary_ids_
list of surface labels
Definition Mesh.hpp:722
std::vector< CellNodes > cell_nodes_
high-order nodes associates to cells
Definition Mesh.hpp:737
std::vector< int > element_vertices(const int el_id) const
list of vids of an element
Definition Mesh.hpp:249
std::vector< int > body_ids_
list of volume labels
Definition Mesh.hpp:724
virtual int get_default_boundary_id(const int primitive) const
Get the default boundary selection of an element (face in 3d, edge in 2d)
Definition Mesh.hpp:487
void transform_higher_order_data(const MatrixNd &A, const VectorNd &b)
Definition Mesh.cpp:723
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
void filter_element_data(const std::vector< bool > &keep)
Definition Mesh.cpp:49
Eigen::MatrixXi in_ordered_edges_
Order of the input edges.
Definition Mesh.hpp:752
virtual void append(const Mesh &mesh)
appends a new mesh to the end of this
Definition Mesh.cpp:474
Eigen::VectorXi in_ordered_vertices_
Order of the input vertices.
Definition Mesh.hpp:750
Minimal polygonal surface mesh used as the storage of CMesh2D.
const Point & point(const int v) const
void clear()
Removes all vertices, facets and edges.
int create_polygon(const std::vector< int > &vertices)
Appends a polygon (not glued to its neighbors) and returns its index.
void bounding_box(Point &min, Point &max) const
Bounding box of the vertices (min/max are initialized to the largest and lowest doubles,...
int facet_vertex(const int f, const int lv) const
int n_facet_vertices(const int f) const
int edge_vertex(const int e, const int lv) const
int create_vertices(int n)
Appends n vertices at the origin and returns the index of the first one.
void delete_facets(const std::vector< bool > &to_delete)
Removes the facets f with to_delete[f], keeping all vertices, and renumbers the remaining facets (and...
void prepare_mesh(PolygonMesh &M)
SplitFunction catmul_clark_split_func()
SplitFunction polar_split_func(double t)
Helper function.
void refine_triangle_mesh(const PolygonMesh &M_in, PolygonMesh &M_out)
Refine a triangle mesh.
void refine_polygonal_mesh(const PolygonMesh &M_in, PolygonMesh &M_out, Polygons::SplitFunction split_func)
Refine a polygonal mesh.
void compute_element_tags(const PolygonMesh &M, std::vector< ElementType > &element_tags)
Compute the type of each facet in a surface mesh.
Definition MeshUtils.cpp:65
void orient_normals_2d(PolygonMesh &M)
Orient facets of a 2D mesh so that each connected component has positive volume.
void generate_edges(PolygonMesh &M)
Creates the edges of M (sorted by vertex pair) if it has none yet.
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:44
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13
void log_and_throw_error(const std::string &msg)
Definition Logger.cpp:73