Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2023 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 :
4 : // This library is free software; you can redistribute it and/or
5 : // modify it under the terms of the GNU Lesser General Public
6 : // License as published by the Free Software Foundation; either
7 : // version 2.1 of the License, or (at your option) any later version.
8 :
9 : // This library is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : // Lesser General Public License for more details.
13 :
14 : // You should have received a copy of the GNU Lesser General Public
15 : // License along with this library; if not, write to the Free Software
16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 :
18 : #include "libmesh/libmesh_config.h"
19 :
20 :
21 : // C++ includes
22 : #include <sstream>
23 :
24 : // Local includes
25 : #include "libmesh/mesh_tet_interface.h"
26 :
27 : #include "libmesh/boundary_info.h"
28 : #include "libmesh/elem.h"
29 : #include "libmesh/elem_range.h"
30 : #include "libmesh/mesh_modification.h"
31 : #include "libmesh/mesh_serializer.h"
32 : #include "libmesh/mesh_tools.h"
33 : #include "libmesh/remote_elem.h"
34 : #include "libmesh/unstructured_mesh.h"
35 :
36 : #include "timpi/parallel_implementation.h"
37 :
38 : namespace {
39 : using namespace libMesh;
40 :
41 : std::unordered_set<Elem *>
42 923 : flood_component (std::unordered_set<Elem *> & all_components,
43 : Elem * elem)
44 : {
45 26 : libmesh_assert(!all_components.count(elem));
46 :
47 26 : std::unordered_set<Elem *> current_component;
48 :
49 1044 : std::unordered_set<Elem *> elements_to_consider = {elem};
50 :
51 6316 : while (!elements_to_consider.empty())
52 : {
53 298 : std::unordered_set<Elem *> next_elements_to_consider;
54 :
55 46478 : for (Elem * considering : elements_to_consider)
56 : {
57 1062 : all_components.insert(considering);
58 1062 : current_component.insert(considering);
59 :
60 164198 : for (auto s : make_range(considering->n_sides()))
61 : {
62 123184 : Elem * neigh = considering->neighbor_ptr(s);
63 :
64 123255 : libmesh_error_msg_if
65 : (!neigh,
66 : "Tet generation encountered a 2D element with a null neighbor, but a\n"
67 : "boundary must be a 2D closed manifold (surface).\n");
68 :
69 123113 : if (all_components.find(neigh) == all_components.end())
70 1453 : next_elements_to_consider.insert(neigh);
71 : }
72 : }
73 147 : elements_to_consider = next_elements_to_consider;
74 : }
75 :
76 876 : return current_component;
77 : }
78 :
79 : // Returns six times the signed volume of a tet formed by the given
80 : // 3 points and the origin
81 33228 : Real six_times_signed_tet_volume (const Point & p1,
82 : const Point & p2,
83 : const Point & p3)
84 : {
85 33228 : return p1(0)*p2(1)*p3(2)
86 33228 : - p1(0)*p3(1)*p2(2)
87 33228 : - p2(0)*p1(1)*p3(2)
88 33228 : + p2(0)*p3(1)*p1(2)
89 33228 : + p3(0)*p1(1)*p2(2)
90 33228 : - p3(0)*p2(1)*p1(2);
91 : }
92 :
93 : // Returns six times the signed volume of the space defined by the
94 : // manifold of surface elements in component
95 852 : Real six_times_signed_volume (const std::unordered_set<Elem *> component)
96 : {
97 24 : Real six_vol = 0;
98 :
99 34080 : for (const Elem * elem: component)
100 : {
101 936 : libmesh_assert_equal_to(elem->dim(), 2);
102 66456 : for (auto n : make_range(elem->n_vertices()-2))
103 35100 : six_vol += six_times_signed_tet_volume(elem->point(0),
104 : elem->point(n+1),
105 : elem->point(n+2));
106 : }
107 :
108 852 : return six_vol;
109 : }
110 : }
111 :
112 : namespace libMesh
113 : {
114 :
115 : //----------------------------------------------------------------------
116 : // MeshTetInterface class members
117 809 : MeshTetInterface::MeshTetInterface (UnstructuredMesh & mesh) :
118 737 : _verbosity(0), _desired_volume(0), _smooth_after_generating(false),
119 809 : _elem_type(TET4), _mesh(mesh)
120 : {
121 809 : }
122 :
123 :
124 737 : MeshTetInterface::~MeshTetInterface() = default;
125 :
126 :
127 142 : void MeshTetInterface::attach_hole_list
128 : (std::unique_ptr<std::vector<std::unique_ptr<UnstructuredMesh>>> holes)
129 : {
130 4 : _holes = std::move(holes);
131 142 : }
132 :
133 :
134 923 : BoundingBox MeshTetInterface::volume_to_surface_mesh(UnstructuredMesh & mesh)
135 : {
136 : // If we've been handed an unprepared mesh then we need to be made
137 : // aware of that and fix that; we're relying on neighbor pointers.
138 923 : MeshTools::libmesh_assert_valid_is_prepared(mesh);
139 :
140 923 : if (!mesh.is_prepared())
141 71 : mesh.prepare_for_use();
142 :
143 : // We'll return a bounding box for use by subclasses in basic sanity checks.
144 897 : BoundingBox surface_bb;
145 :
146 : // First convert all volume boundaries to surface elements; this
147 : // gives us a manifold bounding the mesh, though it may not be a
148 : // connected manifold even if the volume mesh was connected.
149 : {
150 : // Make sure ids are in sync and valid on a DistributedMesh
151 923 : const dof_id_type max_orig_id = mesh.max_elem_id();
152 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
153 923 : const unique_id_type max_unique_id = mesh.parallel_max_unique_id();
154 : #endif
155 :
156 : // Change this if we add arbitrary polyhedra...
157 26 : const dof_id_type max_sides = 6;
158 :
159 52 : std::unordered_set<Elem *> elems_to_delete;
160 :
161 78 : std::vector<std::unique_ptr<Elem>> elems_to_add;
162 :
163 : // Convert all faces to surface elements
164 515108 : for (auto * elem : mesh.active_element_ptr_range())
165 : {
166 267548 : libmesh_error_msg_if (elem->dim() < 2,
167 : "Cannot use meshes with 0D or 1D elements to define a volume");
168 :
169 : // If we've already got 2D elements then those are (part of)
170 : // our surface.
171 267548 : if (elem->dim() == 2)
172 4731 : continue;
173 :
174 : // 3D elements will be removed after we've extracted their
175 : // surface faces.
176 10762 : elems_to_delete.insert(elem);
177 :
178 1313517 : for (auto s : make_range(elem->n_sides()))
179 : {
180 : // If there's a neighbor on this side then there's not a
181 : // boundary
182 1093894 : if (elem->neighbor_ptr(s))
183 : {
184 : // We're not supporting AMR meshes here yet
185 1031260 : if (elem->level() != elem->neighbor_ptr(s)->level())
186 0 : libmesh_not_implemented_msg
187 : ("Tetrahedralizaton of adapted meshes is not currently supported");
188 989004 : continue;
189 946748 : }
190 :
191 38368 : elems_to_add.push_back(elem->build_side_ptr(s));
192 796 : Elem * side_elem = elems_to_add.back().get();
193 :
194 : // Wipe the interior_parent before it can become a
195 : // dangling pointer later
196 19582 : side_elem->set_interior_parent(nullptr);
197 :
198 : // If the mesh is replicated then its automatic id
199 : // setting is fine. If not, then we need unambiguous ids
200 : // independent of element traversal.
201 19582 : if (!mesh.is_replicated())
202 : {
203 16796 : side_elem->set_id(max_orig_id + max_sides*elem->id() + s);
204 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
205 16796 : side_elem->set_unique_id(max_unique_id + max_sides*elem->id() + s);
206 : #endif
207 : }
208 : }
209 871 : }
210 :
211 : // If the mesh is replicated then its automatic neighbor finding
212 : // is fine. If not, then we need to insert them ourselves, but
213 : // it's easy because we can use the fact (from our implementation
214 : // above) that our new elements have no parents or children, plus
215 : // the fact (from the tiny fraction of homology I understand) that
216 : // a manifold boundary is a manifold with no boundary.
217 : //
218 : // See UnstructuredMesh::find_neighbors() for more explanation of
219 : // (a more complicated version of) the algorithm here.
220 923 : if (!mesh.is_replicated())
221 : {
222 : typedef dof_id_type key_type;
223 : typedef std::pair<Elem *, unsigned char> val_type;
224 : typedef std::unordered_multimap<key_type, val_type> map_type;
225 0 : map_type side_to_elem_map;
226 :
227 832 : std::unique_ptr<Elem> my_side, their_side;
228 :
229 17628 : for (auto & elem : elems_to_add)
230 : {
231 67568 : for (auto s : elem->side_index_range())
232 : {
233 50772 : if (elem->neighbor_ptr(s))
234 0 : continue;
235 50772 : const dof_id_type key = elem->low_order_key(s);
236 0 : auto bounds = side_to_elem_map.equal_range(key);
237 50772 : if (bounds.first != bounds.second)
238 : {
239 0 : elem->side_ptr(my_side, s);
240 0 : while (bounds.first != bounds.second)
241 : {
242 0 : Elem * potential_neighbor = bounds.first->second.first;
243 0 : const unsigned int ns = bounds.first->second.second;
244 0 : potential_neighbor->side_ptr(their_side, ns);
245 0 : if (*my_side == *their_side)
246 : {
247 0 : elem->set_neighbor(s, potential_neighbor);
248 0 : potential_neighbor->set_neighbor(ns, elem.get());
249 0 : side_to_elem_map.erase (bounds.first);
250 0 : break;
251 : }
252 0 : ++bounds.first;
253 : }
254 :
255 0 : if (!elem->neighbor_ptr(s))
256 : side_to_elem_map.emplace
257 0 : (key, std::make_pair(elem.get(), cast_int<unsigned char>(s)));
258 : }
259 : }
260 : }
261 :
262 : // At this point we *should* have a match for everything, so
263 : // anything we don't have a match for is remote.
264 17628 : for (auto & elem : elems_to_add)
265 67568 : for (auto s : elem->side_index_range())
266 50772 : if (!elem->neighbor_ptr(s))
267 50772 : elem->set_neighbor(s, const_cast<RemoteElem*>(remote_elem));
268 832 : }
269 :
270 : // Remove volume and edge elements
271 263598 : for (Elem * elem : elems_to_delete)
272 262675 : mesh.delete_elem(elem);
273 :
274 : // Add the new elements outside the loop so we don't risk
275 : // invalidating iterators.
276 20505 : for (auto & elem : elems_to_add)
277 21174 : mesh.add_elem(std::move(elem));
278 871 : }
279 :
280 : // Fix up neighbor pointers, element counts, etc.
281 923 : mesh.prepare_for_use();
282 :
283 : // We're making tets; we need to start with tris
284 923 : MeshTools::Modification::all_tri(mesh);
285 :
286 : // Partition surface into connected components. At this point I'm
287 : // finally going to give up and serialize, because at least we got
288 : // from 3D down to 2D first, and because I don't want to have to
289 : // turn flood_component into a while loop with a parallel sync in
290 : // the middle, and because we do have to serialize *eventually*
291 : // anyways unless we get a parallel tetrahedralizer backend someday.
292 975 : MeshSerializer mesh_serializer(mesh);
293 :
294 78 : std::vector<std::unordered_set<Elem *>> components;
295 52 : std::unordered_set<Elem *> in_component;
296 :
297 98771 : for (auto * elem : mesh.element_ptr_range())
298 1876 : if (!in_component.count(elem))
299 2622 : components.emplace_back(flood_component(in_component, elem));
300 :
301 24 : const std::unordered_set<Elem *> * biggest_component = nullptr;
302 24 : Real biggest_six_vol = 0;
303 1704 : for (const auto & component : components)
304 : {
305 1749 : Real six_vol = six_times_signed_volume(component);
306 852 : if (std::abs(six_vol) > std::abs(biggest_six_vol))
307 : {
308 24 : biggest_six_vol = six_vol;
309 24 : biggest_component = &component;
310 : }
311 : }
312 :
313 852 : if (!biggest_component)
314 0 : libmesh_error_msg("No non-zero-volume component found among " <<
315 : components.size() << " boundary components");
316 :
317 1704 : for (const auto & component : components)
318 852 : if (&component != biggest_component)
319 : {
320 0 : for (Elem * elem: component)
321 0 : mesh.delete_elem(elem);
322 : }
323 : else
324 : {
325 34080 : for (Elem * elem: component)
326 : {
327 33228 : if (biggest_six_vol < 0)
328 1168 : elem->flip(&mesh.get_boundary_info());
329 :
330 136888 : for (auto & node : elem->node_ref_range())
331 100740 : surface_bb.union_with(node);
332 : }
333 : }
334 :
335 852 : mesh.prepare_for_use();
336 :
337 876 : return surface_bb;
338 938 : }
339 :
340 :
341 716 : std::set<MeshTetInterface::SurfaceIntegrity> MeshTetInterface::check_hull_integrity() const
342 : {
343 : // Check for easy return: if the Mesh is empty (i.e. if
344 : // somebody called triangulate_conformingDelaunayMesh on
345 : // a Mesh with no elements, then hull integrity check must
346 : // fail...
347 716 : if (_mesh.n_elem() == 0)
348 0 : return {EMPTY_MESH};
349 :
350 48 : std::set<MeshTetInterface::SurfaceIntegrity> returnval;
351 :
352 716 : const BoundingBox bb = MeshTools::create_bounding_box(this->_mesh);
353 24 : const Point extents = bb.max() - bb.min();
354 716 : if (extents(0) == 0 ||
355 1432 : extents(1) == 0 ||
356 24 : extents(2) == 0)
357 0 : returnval.insert(DEGENERATE_MESH);
358 :
359 : // Figure a area to use for relative tolerances when detecting
360 : // degenerate elements
361 716 : const Real ref_area = std::abs(extents(0) * extents(1)) +
362 716 : std::abs(extents(0) * extents(2)) +
363 716 : std::abs(extents(1) * extents(2));
364 :
365 692 : struct TriChecker {
366 : std::set<MeshTetInterface::SurfaceIntegrity> my_returnval;
367 : const Real my_ref_area;
368 : const unsigned int my_verbosity;
369 :
370 716 : TriChecker (Real ref_area, unsigned int verbosity) :
371 670 : my_returnval(), my_ref_area(ref_area),
372 716 : my_verbosity(verbosity) {}
373 0 : TriChecker (TriChecker & other, Threads::split) :
374 0 : my_returnval(), my_ref_area(other.my_ref_area),
375 0 : my_verbosity(other.my_verbosity) {}
376 :
377 716 : void operator()(const ConstElemRange & range) {
378 :
379 3940 : for (const Elem * elem : range)
380 : {
381 : // Check for proper element type
382 3224 : if (elem->type() != TRI3)
383 : {
384 0 : if (my_verbosity >= 50)
385 0 : std::cerr << "Non-Tri3: " << elem->get_info() << std::endl;
386 0 : my_returnval.insert(NON_TRI3);
387 : }
388 :
389 : // Make sure it's a decent element.
390 3224 : if (elem->volume() < my_ref_area * TOLERANCE * TOLERANCE)
391 : {
392 0 : if (my_verbosity >= 50)
393 0 : std::cerr << "Degenerate element: " << elem->get_info() << std::endl;
394 0 : my_returnval.insert(DEGENERATE_ELEMENT);
395 : }
396 :
397 12896 : for (auto s : elem->side_index_range())
398 : {
399 9672 : const Elem * const neigh = elem->neighbor_ptr(s);
400 :
401 9672 : if (neigh == nullptr)
402 : {
403 0 : if (my_verbosity >= 50)
404 0 : std::cerr << "Element missing neighbor " << s << ": " << elem->get_info() << std::endl;
405 0 : my_returnval.insert(MISSING_NEIGHBOR);
406 0 : continue;
407 : }
408 :
409 : // Make sure our neighbor points back to us
410 9672 : const unsigned int nn = neigh->which_neighbor_am_i(elem);
411 :
412 9672 : if (nn >= 3)
413 : {
414 0 : if (my_verbosity >= 50)
415 0 : std::cerr << "Element missing backlink " << s << ": " << elem->get_info() << std::endl;
416 0 : my_returnval.insert(MISSING_BACKLINK);
417 0 : continue;
418 : }
419 :
420 : // Our neighbor should have the same the edge nodes we do on
421 : // the neighboring edgei
422 1632 : const Node * const n1 = elem->node_ptr(s);
423 9672 : const Node * const n2 = elem->node_ptr((s+1)%3);
424 :
425 9672 : const unsigned int i1 = neigh->local_node(n1->id());
426 9672 : const unsigned int i2 = neigh->local_node(n2->id());
427 9672 : if (i1 >= 3 || i2 >= 3)
428 : {
429 0 : if (my_verbosity >= 50)
430 0 : std::cerr << "Element with bad neighbor " << s << " nodes: " << elem->get_info() << std::endl;
431 0 : my_returnval.insert(BAD_NEIGHBOR_NODES);
432 0 : continue;
433 : }
434 :
435 : // It should have those edge nodes in the opposite order
436 : // (because they have the same orientation we do)
437 9672 : if ((i2 + 1)%3 != i1)
438 : {
439 144 : if (my_verbosity >= 50)
440 0 : std::cerr << "Element orientation mismatch with neighbor " << s << ": " << elem->get_info() << std::endl;
441 144 : my_returnval.insert(NON_ORIENTED);
442 144 : continue;
443 : }
444 :
445 : // And it should have those edge nodes in the expected
446 : // places relative to its neighbor link
447 9528 : if (i2 != nn)
448 : {
449 0 : if (my_verbosity >= 50)
450 0 : std::cerr << "Element with bad links on neighbor " << s << ": " << elem->get_info() << std::endl;
451 0 : my_returnval.insert(BAD_NEIGHBOR_LINKS);
452 0 : continue;
453 : }
454 : }
455 : }
456 716 : }
457 :
458 0 : void join(TriChecker & other) {
459 0 : my_returnval.merge(other.my_returnval);
460 0 : }
461 : };
462 :
463 740 : TriChecker checker (ref_area, this->_verbosity);
464 :
465 : // Don't grab a non-Const range by mistake
466 716 : const MeshBase & mesh = this->_mesh;
467 :
468 : Threads::parallel_reduce
469 716 : (mesh.active_local_element_stored_range(), checker);
470 :
471 : // Join problems found in threaded loop
472 24 : returnval.merge(checker.my_returnval);
473 :
474 : // Join problems found on other ranks
475 48 : std::set<char> int_set;
476 : std::transform
477 670 : (returnval.begin(), returnval.end(),
478 : std::inserter<std::set<char>>(int_set, int_set.end()),
479 48 : [](SurfaceIntegrity i){return int(i);});
480 716 : _mesh.comm().set_union(int_set);
481 : std::transform
482 670 : (int_set.begin(), int_set.end(),
483 : std::inserter<std::set<SurfaceIntegrity>>(returnval, returnval.end()),
484 115 : [](int i){return SurfaceIntegrity(i);});
485 :
486 24 : return returnval;
487 : }
488 :
489 :
490 :
491 714 : std::set<MeshTetInterface::SurfaceIntegrity> MeshTetInterface::improve_hull_integrity()
492 : {
493 : // We don't really do anything parallel here, but we aspire to.
494 22 : libmesh_parallel_only(this->_mesh.comm());
495 :
496 : std::set<MeshTetInterface::SurfaceIntegrity> integrityproblems =
497 736 : this->check_hull_integrity();
498 :
499 : // If we have no problem, or a problem we can't fix, we're done.
500 22 : if (integrityproblems.empty() ||
501 716 : integrityproblems.count(NON_TRI3) ||
502 694 : integrityproblems.count(EMPTY_MESH))
503 20 : return integrityproblems;
504 :
505 : // Possibly the user gave us an unprepared mesh with missing or bad
506 : // neighbor links?
507 69 : if (integrityproblems.count(MISSING_NEIGHBOR) ||
508 71 : integrityproblems.count(MISSING_BACKLINK) ||
509 71 : integrityproblems.count(BAD_NEIGHBOR_LINKS))
510 : {
511 0 : this->_mesh.find_neighbors();
512 0 : integrityproblems = this->check_hull_integrity();
513 : }
514 :
515 : // If find_neighbors() doesn't fix these, I give up.
516 69 : if (integrityproblems.count(MISSING_NEIGHBOR) ||
517 71 : integrityproblems.count(MISSING_BACKLINK) ||
518 71 : integrityproblems.count(BAD_NEIGHBOR_LINKS))
519 0 : return integrityproblems;
520 :
521 : // find_neighbors() might have fixed everything
522 71 : if (integrityproblems.empty())
523 0 : return integrityproblems;
524 :
525 : // A non-oriented (but orientable!) surface is the only thing we
526 : // shouldn't have fixed or given up on by now.
527 2 : libmesh_assert_equal_to(integrityproblems.size(), 1);
528 2 : libmesh_assert_equal_to(integrityproblems.count(NON_ORIENTED), 1);
529 :
530 : // We need one known-good triangle to start from. We'll pick the
531 : // most-negative-x normal among the triangles on the most-negative-x
532 : // point.
533 :
534 : // We'll just implement this in serial for now.
535 75 : MeshSerializer mesh_serializer(this->_mesh);
536 :
537 : // I don't see why we'd need boundary info here, but maybe we'll
538 : // want to preserve edge/node conditions eventually?
539 71 : BoundaryInfo & bi = this->_mesh.get_boundary_info();
540 :
541 140 : const Node * lowest_point = (*this->_mesh.elements_begin())->node_ptr(0);
542 :
543 : // Index by ids, not pointers, for consistency in parallel
544 4 : std::unordered_set<dof_id_type> attached_elements;
545 :
546 1260 : for (Elem * elem : this->_mesh.element_ptr_range())
547 : {
548 2272 : for (const Node & node : elem->node_ref_range())
549 : {
550 1704 : if (node(0) < (*lowest_point)(0))
551 : {
552 2 : lowest_point = &node;
553 2 : attached_elements.clear();
554 : }
555 1704 : if (&node == lowest_point)
556 390 : attached_elements.insert(elem->id());
557 : }
558 67 : }
559 :
560 2 : Elem * best_elem = nullptr;
561 2 : Real best_abs_normal_0 = 0;
562 :
563 355 : for (dof_id_type id : attached_elements)
564 : {
565 284 : Elem * elem = this->_mesh.elem_ptr(id);
566 16 : const Point e01 = elem->point(1) - elem->point(0);
567 8 : const Point e02 = elem->point(2) - elem->point(0);
568 284 : const Point normal = e01.cross(e02).unit();
569 276 : const Real abs_normal_0 = std::abs(normal(0));
570 :
571 284 : if (!best_elem || abs_normal_0 > best_abs_normal_0)
572 : {
573 2 : best_elem = elem;
574 2 : best_abs_normal_0 = abs_normal_0;
575 :
576 : // Make sure that element is actually a good one, by
577 : // flipping it if it's not.
578 71 : if (abs_normal_0 == normal(0))
579 0 : elem->flip(&bi);
580 : }
581 : }
582 :
583 : // Now flood-fill from that element to get a consistent orientation
584 : // for the others.
585 73 : std::unordered_set<dof_id_type> frontier_elements{best_elem->id()},
586 73 : finished_elements{};
587 :
588 639 : while (!frontier_elements.empty())
589 : {
590 568 : const dof_id_type elem_id = *frontier_elements.begin();
591 568 : Elem & elem = this->_mesh.elem_ref(elem_id);
592 2272 : for (auto s : elem.side_index_range())
593 : {
594 1704 : Elem * neigh = elem.neighbor_ptr(s);
595 48 : libmesh_assert(neigh);
596 48 : libmesh_assert_less(neigh->which_neighbor_am_i(&elem), 3);
597 :
598 96 : const Node * const n1 = elem.node_ptr(s);
599 1704 : const Node * const n2 = elem.node_ptr((s+1)%3);
600 1704 : const unsigned int i1 = neigh->local_node(n1->id());
601 1704 : const unsigned int i2 = neigh->local_node(n2->id());
602 48 : libmesh_assert_less(i1, 3);
603 48 : libmesh_assert_less(i2, 3);
604 :
605 1704 : const dof_id_type neigh_id = neigh->id();
606 :
607 48 : const bool frontier_neigh = frontier_elements.count(neigh_id);
608 48 : const bool finished_neigh = finished_elements.count(neigh_id);
609 :
610 : // Are we flipped?
611 1704 : if ((i2 + 1)%3 != i1)
612 : {
613 : // Are we a Moebius strip??? We give up.
614 142 : if (frontier_neigh || finished_neigh)
615 0 : return integrityproblems;
616 :
617 142 : neigh->flip(&bi);
618 : }
619 :
620 1704 : if (!frontier_neigh && !finished_neigh)
621 14 : frontier_elements.insert(neigh_id);
622 : }
623 :
624 16 : finished_elements.insert(elem_id);
625 16 : frontier_elements.erase(elem_id);
626 : }
627 :
628 71 : this->_mesh.find_neighbors();
629 :
630 2 : libmesh_assert(this->check_hull_integrity().empty());
631 :
632 71 : return {};
633 67 : }
634 :
635 :
636 714 : void MeshTetInterface::process_hull_integrity_result
637 : (const std::set<MeshTetInterface::SurfaceIntegrity> & result) const
638 : {
639 736 : std::ostringstream err_msg;
640 :
641 714 : if (result.empty()) // success
642 736 : return;
643 :
644 0 : err_msg << "Error! Conforming Delaunay mesh tetrahedralization requires a convex hull." << std::endl;
645 :
646 0 : if (result.count(NON_TRI3))
647 : {
648 0 : err_msg << "At least one non-Tri3 element was found in the input boundary mesh. ";
649 0 : err_msg << "Our constrained Delaunay tetrahedralization boundary must be a triangulation of Tri3 elements." << std::endl;
650 : }
651 0 : if (result.count(MISSING_NEIGHBOR))
652 : {
653 0 : err_msg << "At least one triangle without three neighbors was found in the input boundary mesh. ";
654 0 : err_msg << "A constrained Delaunay tetrahedralization boundary must be a triangular manifold without boundary." << std::endl;
655 : }
656 0 : if (result.count(EMPTY_MESH))
657 : {
658 0 : err_msg << "The input boundary mesh was empty!" << std::endl;
659 0 : err_msg << "Our constrained Delaunay tetrahedralization boundary must be a triangulation of Tri3 elements." << std::endl;
660 : }
661 0 : if (result.count(MISSING_BACKLINK))
662 : {
663 0 : err_msg << "At least one triangle neighbor without a return neighbor link was found in the input boundary mesh. ";
664 0 : err_msg << "A constrained Delaunay tetrahedralization boundary must be a conforming and non-adaptively-refined mesh." << std::endl;
665 : }
666 0 : if (result.count(BAD_NEIGHBOR_NODES))
667 : {
668 0 : err_msg << "At least one triangle neighbor without expected node links was found in the input boundary mesh. ";
669 0 : err_msg << "A constrained Delaunay tetrahedralization boundary must be a conforming and non-adaptively-refined mesh." << std::endl;
670 : }
671 0 : if (result.count(NON_ORIENTED))
672 : {
673 0 : err_msg << "At least one triangle neighbor with an inconsistent orientation was found in the input boundary mesh. ";
674 0 : err_msg << "A constrained Delaunay tetrahedralization boundary must be an oriented Tri3 mesh." << std::endl;
675 : }
676 0 : if (result.count(BAD_NEIGHBOR_LINKS))
677 0 : err_msg << "At least one triangle neighbor with inconsistent node and neighbor links was found in the input boundary mesh." << std::endl;
678 0 : if (result.count(DEGENERATE_ELEMENT))
679 0 : err_msg << "At least one input triangle is degenerate, with near-zero area relative to the manifold." << std::endl;
680 0 : if (result.count(DEGENERATE_MESH))
681 0 : err_msg << "The input mesh is degenerate, with zero thickness in at least one direction." << std::endl;
682 :
683 0 : libmesh_error_msg(err_msg.str());
684 670 : }
685 :
686 :
687 :
688 4 : void MeshTetInterface::delete_2D_hull_elements()
689 : {
690 10078 : for (auto & elem : this->_mesh.element_ptr_range())
691 : {
692 : // Check for proper element type. Yes, we legally delete elements while
693 : // iterating over them because no entries from the underlying container
694 : // are actually erased.
695 10072 : if (elem->type() == TRI3)
696 96 : _mesh.delete_elem(elem);
697 0 : }
698 :
699 : // We just removed any boundary info associated with hull element
700 : // edges, so let's update the boundary id caches.
701 6 : this->_mesh.get_boundary_info().regenerate_id_sets();
702 4 : }
703 :
704 :
705 :
706 284 : void MeshTetInterface::increase_tet_order()
707 : {
708 284 : switch (_elem_type)
709 : {
710 0 : case TET4:
711 0 : return;
712 142 : case TET10:
713 142 : _mesh.all_second_order();
714 142 : break;
715 142 : case TET14:
716 142 : _mesh.all_complete_order();
717 142 : break;
718 0 : default:
719 0 : libmesh_not_implemented();
720 : }
721 : }
722 :
723 :
724 :
725 : } // namespace libMesh
|