libMesh
Loading...
Searching...
No Matches
unstructured_mesh.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
19
20// Local includes
21#include "libmesh/boundary_info.h"
22#include "libmesh/ghosting_functor.h"
23#include "libmesh/ghost_point_neighbors.h"
24#include "libmesh/unstructured_mesh.h"
25#include "libmesh/libmesh_logging.h"
26#include "libmesh/elem.h"
27#include "libmesh/elem_range.h"
28#include "libmesh/face_polygon.h"
29#include "libmesh/mesh_tools.h" // For n_levels
30#include "libmesh/parallel.h"
31#include "libmesh/remote_elem.h"
32#include "libmesh/namebased_io.h"
33#include "libmesh/partitioner.h"
34#include "libmesh/enum_order.h"
35#include "libmesh/mesh_communication.h"
36#include "libmesh/enum_to_string.h"
37#include "libmesh/mesh_serializer.h"
38#include "libmesh/utility.h"
39
40#ifdef LIBMESH_HAVE_NANOFLANN
41#include "libmesh/nanoflann.hpp"
42#endif
43
44// C++ includes
45#include <algorithm> // std::all_of
46#include <atomic>
47#include <fstream>
48#include <iomanip>
49#include <map>
50#include <sstream>
51#include <unordered_map>
52
53// for disjoint neighbors
54#include "libmesh/periodic_boundaries.h"
55#include "libmesh/periodic_boundary.h"
56
57namespace {
58
59using namespace libMesh;
60
61// Helper functions for all_second_order, all_complete_order
62
63std::map<std::vector<dof_id_type>, Node *>::iterator
64map_hi_order_node(unsigned int hon,
65 const Elem & hi_elem,
66 std::map<std::vector<dof_id_type>, Node *> & adj_vertices_to_ho_nodes)
67{
68 /*
69 * form a vector that will hold the node id's of
70 * the vertices that are adjacent to the nth
71 * higher-order node.
72 */
73 const unsigned int n_adjacent_vertices =
75
76 std::vector<dof_id_type> adjacent_vertices_ids(n_adjacent_vertices);
77
78 for (unsigned int v=0; v<n_adjacent_vertices; v++)
79 adjacent_vertices_ids[v] =
80 hi_elem.node_id( hi_elem.second_order_adjacent_vertex(hon,v) );
81
82 /*
83 * \p adjacent_vertices_ids is now in order of the current
84 * side. sort it, so that comparisons with the
85 * \p adjacent_vertices_ids created through other elements'
86 * sides can match
87 */
88 std::sort(adjacent_vertices_ids.begin(),
89 adjacent_vertices_ids.end());
90
91 // Does this set of vertices already have a mid-node added? If not
92 // we'll want to add it.
93 return adj_vertices_to_ho_nodes.try_emplace(adjacent_vertices_ids, nullptr).first;
94}
95
96void transfer_elem(Elem & lo_elem,
97 std::unique_ptr<Elem> hi_elem,
98#ifdef LIBMESH_ENABLE_UNIQUE_ID
99 unique_id_type max_unique_id,
100 unique_id_type max_new_nodes_per_elem,
101#endif
103 std::map<std::vector<dof_id_type>, Node *> & adj_vertices_to_ho_nodes,
104 std::unordered_map<Elem *, std::vector<Elem *>> & exterior_children_of)
105{
106 libmesh_assert_equal_to (lo_elem.n_vertices(), hi_elem->n_vertices());
107
108 const processor_id_type my_pid = mesh.processor_id();
109 const processor_id_type lo_pid = lo_elem.processor_id();
110
111 /*
112 * Now handle the additional higher-order nodes. This
113 * is simply handled through a map that remembers
114 * the already-added nodes. This map maps the global
115 * ids of the vertices (that uniquely define this
116 * higher-order node) to the new node.
117 * Notation: hon = high-order node
118 */
119 const unsigned int hon_begin = lo_elem.n_nodes();
120 const unsigned int hon_end = hi_elem->n_nodes();
121
122 libmesh_assert_less (hon_begin, hon_end);
123#ifdef LIBMESH_ENABLE_UNIQUE_ID
124 libmesh_assert_less_equal
125 (hon_end-hon_begin, max_new_nodes_per_elem);
126#endif
127
128 for (unsigned int hon=hon_begin; hon<hon_end; hon++)
129 {
130 auto pos = map_hi_order_node(hon, *hi_elem, adj_vertices_to_ho_nodes);
131
132 // no, not added yet
133 if (!pos->second)
134 {
135 const auto & adjacent_vertices_ids = pos->first;
136
137 /*
138 * for this set of vertices, there is no
139 * second_order node yet. Add it.
140 *
141 * compute the location of the new node as
142 * the average over the adjacent vertices.
143 */
144 Point new_location = 0;
145 for (dof_id_type vertex_id : adjacent_vertices_ids)
146 new_location += mesh.point(vertex_id);
147
148 new_location /= static_cast<Real>(adjacent_vertices_ids.size());
149
150 /* Add the new point to the mesh.
151 *
152 * If we are on a serialized mesh, then we're doing this
153 * all in sync, and the node processor_id will be
154 * consistent between processors.
155 *
156 * If we are on a distributed mesh, we can fix
157 * inconsistent processor ids later, but only if every
158 * processor gives new nodes a *locally* consistent
159 * processor id, so we'll give the new node the
160 * processor id of an adjacent element for now and then
161 * we'll update that later if appropriate.
162 */
163 Node * hi_node = mesh.add_point
164 (new_location, DofObject::invalid_id, lo_pid);
165
166 /* Come up with a unique unique_id for a potentially new
167 * node. On a distributed mesh we don't yet know what
168 * processor_id will definitely own it, so we can't let
169 * the pid determine the unique_id. But we're not
170 * adding unpartitioned nodes in sync, so we can't let
171 * the mesh autodetermine a unique_id for a new
172 * unpartitioned node either. So we have to pick unique
173 * unique_id values manually.
174 *
175 * We don't have to pick the *same* unique_id value as
176 * will be picked on other processors, though; we'll
177 * sync up each node later. We just need to make sure
178 * we don't duplicate any unique_id that might be chosen
179 * by the same process elsewhere.
180 */
181#ifdef LIBMESH_ENABLE_UNIQUE_ID
182 unique_id_type new_unique_id = max_unique_id +
183 max_new_nodes_per_elem * lo_elem.id() +
184 hon - hon_begin;
185
186 hi_node->set_unique_id(new_unique_id);
187#endif
188
189 /*
190 * insert the new node with its defining vertex
191 * set into the map, and relocate pos to this
192 * new entry, so that the hi_elem can use
193 * \p pos for inserting the node
194 */
195 pos->second = hi_node;
196
197 hi_elem->set_node(hon, hi_node);
198 }
199 // yes, already added.
200 else
201 {
202 Node * hi_node = pos->second;
203 libmesh_assert(hi_node);
204 libmesh_assert_equal_to(mesh.node_ptr(hi_node->id()), hi_node);
205
206 hi_elem->set_node(hon, hi_node);
207
208 // We need to ensure that the processor who should own a
209 // node *knows* they own the node. And because
210 // Node::choose_processor_id() may depend on Node id,
211 // which may not yet be authoritative, we still have to
212 // use a dumb-but-id-independent partitioning heuristic.
213 processor_id_type chosen_pid =
214 std::min (hi_node->processor_id(), lo_pid);
215
216 // Plus, if we just discovered that we own this node,
217 // then on a distributed mesh we need to make sure to
218 // give it a valid id, not just a placeholder id!
219 if (!mesh.is_replicated() &&
220 hi_node->processor_id() != my_pid &&
221 chosen_pid == my_pid)
222 mesh.own_node(*hi_node);
223
224 hi_node->processor_id() = chosen_pid;
225 }
226 }
227
228 /*
229 * find_neighbors relies on remote_elem neighbor links being
230 * properly maintained. Our own code here relies on ordinary
231 * neighbor links being properly maintained, so let's just keep
232 * everything up to date.
233 */
234 for (auto s : lo_elem.side_index_range())
235 {
236 Elem * neigh = lo_elem.neighbor_ptr(s);
237 if (!neigh)
238 continue;
239
240 if (neigh != remote_elem)
241 {
242 // We don't support AMR even outside our own range yet.
243 libmesh_assert_equal_to (neigh->level(), 0);
244
245 const unsigned int ns = neigh->which_neighbor_am_i(&lo_elem);
246 libmesh_assert_not_equal_to(ns, libMesh::invalid_uint);
247
248 neigh->set_neighbor(ns, hi_elem.get());
249 }
250
251 hi_elem->set_neighbor(s, neigh);
252 }
253
260 Elem * interior_p = lo_elem.interior_parent();
261 if (interior_p)
262 hi_elem->set_interior_parent(interior_p);
263
264 if (auto parent_exterior_it = exterior_children_of.find(interior_p);
265 parent_exterior_it != exterior_children_of.end())
266 {
267 auto & exteriors = parent_exterior_it->second;
268 for (std::size_t i : index_range(exteriors))
269 if (exteriors[i] == &lo_elem)
270 {
271 exteriors[i] = hi_elem.get();
272 break;
273 }
274 }
275
280 if (auto exterior_it = exterior_children_of.find(&lo_elem);
281 exterior_it != exterior_children_of.end())
282 {
283 for (Elem * exterior_elem : exterior_it->second)
284 {
285 libmesh_assert(exterior_elem->interior_parent() == &lo_elem);
286 exterior_elem->set_interior_parent(hi_elem.get());
287 }
288 }
289
302 (mesh.get_boundary_info(), &lo_elem, hi_elem.get());
303
304 /*
305 * The new second-order element is ready.
306 * Inserting it into the mesh will replace and delete
307 * the first-order element.
308 */
309 hi_elem->set_id(lo_elem.id());
310#ifdef LIBMESH_ENABLE_UNIQUE_ID
311 hi_elem->set_unique_id(lo_elem.unique_id());
312#endif
313
314 const unsigned int nei = lo_elem.n_extra_integers();
315 hi_elem->add_extra_integers(nei);
316 for (unsigned int i=0; i != nei; ++i)
317 hi_elem->set_extra_integer(i, lo_elem.get_extra_integer(i));
318
319 hi_elem->inherit_data_from(lo_elem);
320
321 mesh.insert_elem(std::move(hi_elem));
322}
323
324
325template <typename ElemTypeConverter>
326void
327all_increased_order_range (UnstructuredMesh & mesh,
329 const unsigned int max_new_nodes_per_elem,
330 const ElemTypeConverter & elem_type_converter)
331{
332 // This function must be run on all processors at once
333 timpi_parallel_only(mesh.comm());
334
335 /*
336 * The maximum number of new higher-order nodes we might be adding,
337 * for use when picking unique unique_id values later. This variable
338 * is not used unless unique ids are enabled, so libmesh_ignore() it
339 * to avoid warnings in that case.
340 */
341 libmesh_ignore(max_new_nodes_per_elem);
342
343 /*
344 * The mesh should at least be consistent enough for us to add new
345 * nodes consistently.
346 */
348
349 /*
350 * If the mesh is empty then we have nothing to do
351 */
352 if (!mesh.n_elem())
353 return;
354
355 // If every element in the range _on every proc_ is already of the
356 // requested higher order then we have nothing to do. However, if
357 // any proc has some lower-order elements in the range, then _all_
358 // processors need to continue this function because it is
359 // parallel_only().
360 //
361 // Note: std::all_of() returns true for an empty range, which can
362 // happen for example in the DistributedMesh case when there are
363 // more processors than elements. In the case of an empty range we
364 // therefore set already_second_order to true on that proc.
365 auto is_higher_order = [&elem_type_converter](const Elem * elem) {
366 ElemType old_type = elem->type();
367 ElemType new_type = elem_type_converter(old_type);
368 return old_type == new_type;
369 };
370
371 bool already_higher_order =
372 std::all_of(range.begin(), range.end(), is_higher_order);
373
374 // Check with other processors and possibly return early
375 mesh.comm().min(already_higher_order);
376 if (already_higher_order)
377 return;
378
379 /*
380 * this map helps in identifying higher order
381 * nodes. Namely, a higher-order node:
382 * - edge node
383 * - face node
384 * - bubble node
385 * is uniquely defined through a set of adjacent
386 * vertices. This set of adjacent vertices is
387 * used to identify already added higher-order
388 * nodes. We are safe to use node id's since we
389 * make sure that these are correctly numbered.
390 *
391 * We lazily use an ordered map here to avoid having to implement a
392 * good hash for vector<dof_id_type>
393 */
394 std::map<std::vector<dof_id_type>, Node *> adj_vertices_to_ho_nodes;
395
396 /*
397 * This map helps us reset any interior_parent() values from the
398 * lower order element to its higher order replacement. Unlike with
399 * neighbor pointers, we don't have backlinks here, so we have to
400 * iterate over the mesh to track forward links.
401 */
402 std::unordered_map<Elem *, std::vector<Elem *>> exterior_children_of;
403
404 /*
405 * max_new_nodes_per_elem is the maximum number of new higher order
406 * nodes we might be adding, for use when picking unique unique_id
407 * values later. This variable is not used unless unique ids are
408 * enabled.
409 */
410#ifdef LIBMESH_ENABLE_UNIQUE_ID
412#endif
413
420 dof_id_type n_unpartitioned_elem = 0;
421
436 auto track_if_necessary = [&adj_vertices_to_ho_nodes,
437 &exterior_children_of,
438 &elem_type_converter](Elem * elem) {
439 if (elem && elem != remote_elem)
440 {
441 if (elem->default_order() != FIRST)
442 for (unsigned int hon : make_range(elem->n_vertices(), elem->n_nodes()))
443 {
444 auto pos = map_hi_order_node(hon, *elem, adj_vertices_to_ho_nodes);
445 pos->second = elem->node_ptr(hon);
446 }
447
448 const ElemType old_type = elem->type();
449 const ElemType new_type = elem_type_converter(old_type);
450 if (old_type != new_type)
451 exterior_children_of.emplace(elem, std::vector<Elem *>());
452 }
453 };
454
455 // If we're in the common case then just track everything; otherwise
456 // find point neighbors to track
457 if (range.begin() == mesh.elements_begin() &&
458 range.end() == mesh.elements_end())
459 {
460 for (auto & elem : range)
461 track_if_necessary(elem);
462 }
463 else
464 {
465 GhostingFunctor::map_type point_neighbor_elements;
466
467 GhostPointNeighbors point_neighbor_finder(mesh);
468 point_neighbor_finder(range.begin(), range.end(),
470 point_neighbor_elements);
471
472 for (auto & [elem, coupling_map] : point_neighbor_elements)
473 {
474 libmesh_ignore(coupling_map);
475 track_if_necessary(const_cast<Elem *>(elem));
476 }
477 }
478
483 for (auto & elem : mesh.element_ptr_range())
484 if (auto exterior_map_it = exterior_children_of.find(elem->interior_parent());
485 exterior_map_it != exterior_children_of.end())
486 exterior_map_it->second.push_back(elem);
487
494 for (auto & lo_elem : range)
495 {
496 // Now we can skip the elements in the range that are already
497 // higher-order.
498 const ElemType old_type = lo_elem->type();
499 const ElemType new_type = elem_type_converter(old_type);
500
501 if (old_type == new_type)
502 continue;
503
504 // this does _not_ work for refined elements
505 libmesh_assert_equal_to (lo_elem->level(), 0);
506
508 ++n_unpartitioned_elem;
509
510 /*
511 * Build the higher-order equivalent; add to
512 * the new_elements list.
513 */
514 auto ho_elem = Elem::build (new_type);
515
516 libmesh_assert_equal_to (lo_elem->n_vertices(), ho_elem->n_vertices());
517
518 /*
519 * By definition the initial nodes of the lower and higher order
520 * element are identically numbered. Transfer these.
521 */
522 for (unsigned int v=0, lnn=lo_elem->n_nodes(); v < lnn; v++)
523 ho_elem->set_node(v, lo_elem->node_ptr(v));
524
525 transfer_elem(*lo_elem, std::move(ho_elem),
526#ifdef LIBMESH_ENABLE_UNIQUE_ID
527 max_unique_id, max_new_nodes_per_elem,
528#endif
529 mesh, adj_vertices_to_ho_nodes,
530 exterior_children_of);
531 } // end for (auto & lo_elem : range)
532
533 // we can clear the map at this point.
534 adj_vertices_to_ho_nodes.clear();
535
536#ifdef LIBMESH_ENABLE_UNIQUE_ID
537 const unique_id_type new_max_unique_id = max_unique_id +
538 max_new_nodes_per_elem * mesh.n_elem();
539 mesh.set_next_unique_id(new_max_unique_id);
540#endif
541
542 // On a DistributedMesh our ghost node processor ids may be bad,
543 // the ids of nodes touching remote elements may be inconsistent,
544 // unique_ids of newly added non-local nodes remain unset, and our
545 // partitioning of new nodes may not be well balanced.
546 //
547 // make_nodes_parallel_consistent() will fix all this.
548 if (!mesh.is_replicated())
549 {
550 dof_id_type max_unpartitioned_elem = n_unpartitioned_elem;
551 mesh.comm().max(max_unpartitioned_elem);
552 if (max_unpartitioned_elem)
553 {
554 // We'd better be effectively serialized here. In theory we
555 // could support more complicated cases but for now we
556 // only support "completely partitioned" and/or "serialized"
557 if (mesh.is_serial())
558 libmesh_assert(mesh.comm().verify(n_unpartitioned_elem));
559 else
560 libmesh_not_implemented();
561 }
562 else
563 {
565 }
566 }
567
568 // renumber nodes, repartition nodes, etc. We may no longer need a
569 // find_neighbors() here since we're keeping neighbor links intact
570 // ourselves, *except* that if we're not already prepared we may
571 // have user code that was expecting this call to prepare neighbors.
572 const bool old_find_neighbors = mesh.allow_find_neighbors();
573 if (mesh.is_prepared())
576 mesh.allow_find_neighbors(old_find_neighbors);
577}
578
579
580} // anonymous namespace
581
582
583namespace libMesh
584{
585
586// This class adapts a vector of Nodes (represented by a pair of a Point and a dof_id_type)
587// for use in a nanoflann KD-Tree
588
590{
591private:
592 const std::vector<std::pair<Point, dof_id_type>> _nodes;
593
594public:
595 VectorOfNodesAdaptor(const std::vector<std::pair<Point, dof_id_type>> & nodes) :
596 _nodes(nodes)
597 {}
598
602 inline size_t kdtree_get_point_count() const { return _nodes.size(); }
603
609 inline Real kdtree_get_pt(const size_t idx, int dim) const
610 {
611 libmesh_assert_less (idx, _nodes.size());
612 libmesh_assert_less (dim, 3);
613
614 const Point & p(_nodes[idx].first);
615
616 if (dim==0) return p(0);
617 if (dim==1) return p(1);
618 return p(2);
619 }
620
621 /*
622 * Optional bounding-box computation
623 */
624 template <class BBOX>
625 bool kdtree_get_bbox(BBOX & /* bb */) const { return false; }
626};
627
628
629// ------------------------------------------------------------
630// UnstructuredMesh class member functions
632 unsigned char d) :
633 MeshBase (comm_in,d)
634{
636}
637
638
639
641 MeshBase (other_mesh)
642{
644}
645
646
647
649 const bool skip_find_neighbors,
650 dof_id_type element_id_offset,
651 dof_id_type node_id_offset,
653#ifdef LIBMESH_ENABLE_UNIQUE_ID
654 unique_id_offset
655#endif
656 ,
657 std::unordered_map<subdomain_id_type, subdomain_id_type> *
658 id_remapping,
659 const bool skip_preparation)
660{
661 LOG_SCOPE("copy_nodes_and_elements()", "UnstructuredMesh");
662
663 // If we're asked to skip all preparation, we should be skipping
664 // find_neighbors specifically.
665 libmesh_assert(!skip_preparation || skip_find_neighbors);
666
667 std::pair<std::vector<unsigned int>, std::vector<unsigned int>>
668 extra_int_maps = this->merge_extra_integer_names(other_mesh);
669
670 const unsigned int n_old_node_ints = extra_int_maps.second.size(),
671 n_new_node_ints = _node_integer_names.size(),
672 n_old_elem_ints = extra_int_maps.first.size(),
673 n_new_elem_ints = _elem_integer_names.size();
674
675 // If we are partitioned into fewer parts than the incoming mesh has
676 // processors to handle, then we need to "wrap" the other Mesh's
677 // processor ids to fit within our range. This can happen, for
678 // example, while stitching meshes with small numbers of elements in
679 // parallel...
680 bool wrap_proc_ids = (this->n_processors() <
681 other_mesh.n_partitions());
682
683 // We're assuming the other mesh has proper element number ordering,
684 // so that we add parents before their children, and that the other
685 // mesh is consistently partitioned. We're not assuming that node
686 // proc ids are topologically consistent, so we don't just
687 // libmesh_assert_valid_procids.
688#ifdef DEBUG
691#endif
692
693 //Copy in Nodes
694 {
695 //Preallocate Memory if necessary
696 this->reserve_nodes(other_mesh.n_nodes());
697
698 for (const auto & oldn : other_mesh.node_ptr_range())
699 {
700 processor_id_type added_pid = cast_int<processor_id_type>
701 (wrap_proc_ids ? oldn->processor_id() % this->n_processors() : oldn->processor_id());
702
703 // Add new nodes in old node Point locations
704 Node * newn =
705 this->add_point(*oldn,
706 oldn->id() + node_id_offset,
707 added_pid);
708
709 newn->add_extra_integers(n_new_node_ints);
710 for (unsigned int i = 0; i != n_old_node_ints; ++i)
711 newn->set_extra_integer(extra_int_maps.second[i],
712 oldn->get_extra_integer(i));
713
714#ifdef LIBMESH_ENABLE_UNIQUE_ID
715 newn->set_unique_id(oldn->unique_id() + unique_id_offset);
716#endif
717 }
718 }
719
720 //Copy in Elements
721 {
722 //Preallocate Memory if necessary
723 this->reserve_elem(other_mesh.n_elem());
724
725 // Declare a map linking old and new elements, needed to copy the neighbor lists
726 typedef std::unordered_map<const Elem *, Elem *> map_type;
727 map_type old_elems_to_new_elems, ip_map;
728
729 // Loop over the elements
730 for (const auto & old : other_mesh.element_ptr_range())
731 {
732 // Build a new element
733 Elem * newparent = old->parent() ?
734 this->elem_ptr(old->parent()->id() + element_id_offset) :
735 nullptr;
736 auto el = old->disconnected_clone();
737 el->set_parent(newparent);
738
739 subdomain_id_type sbd_id = old->subdomain_id();
740 if (id_remapping)
741 {
742 auto remapping_it = id_remapping->find(sbd_id);
743 if (remapping_it != id_remapping->end())
744 sbd_id = remapping_it->second;
745 }
746 el->subdomain_id() = sbd_id;
747
748 // Hold off on trying to set the interior parent because we may actually
749 // add lower dimensional elements before their interior parents
750 if (old->interior_parent())
751 ip_map[old] = el.get();
752
753#ifdef LIBMESH_ENABLE_AMR
754 if (old->has_children())
755 for (unsigned int c = 0, nc = old->n_children(); c != nc; ++c)
756 if (old->child_ptr(c) == remote_elem)
757 el->add_child(const_cast<RemoteElem *>(remote_elem), c);
758
759 //Create the parent's child pointers if necessary
760 if (newparent)
761 {
762 unsigned int oldc = old->parent()->which_child_am_i(old);
763 newparent->add_child(el.get(), oldc);
764 }
765
766 // Copy the refinement flags
767 el->set_refinement_flag(old->refinement_flag());
768
769 // Use hack_p_level since we may not have sibling elements
770 // added yet
771 el->hack_p_level(old->p_level());
772
773 el->set_p_refinement_flag(old->p_refinement_flag());
774#endif // #ifdef LIBMESH_ENABLE_AMR
775
776 //Assign all the nodes
777 for (auto i : el->node_index_range())
778 el->set_node(i,
779 this->node_ptr(old->node_id(i) + node_id_offset));
780
781 // And start it off with the same processor id (mod _n_parts).
782 el->processor_id() = cast_int<processor_id_type>
783 (wrap_proc_ids ? old->processor_id() % this->n_processors() : old->processor_id());
784
785 // Give it the same element and unique ids
786 el->set_id(old->id() + element_id_offset);
787
788 el->add_extra_integers(n_new_elem_ints);
789 for (unsigned int i = 0; i != n_old_elem_ints; ++i)
790 el->set_extra_integer(extra_int_maps.first[i],
791 old->get_extra_integer(i));
792
793#ifdef LIBMESH_ENABLE_UNIQUE_ID
794 el->set_unique_id(old->unique_id() + unique_id_offset);
795#endif
796
797 //Hold onto it
798 if (!skip_find_neighbors)
799 {
800 for (auto s : old->side_index_range())
801 if (old->neighbor_ptr(s) == remote_elem)
802 el->set_neighbor(s, const_cast<RemoteElem *>(remote_elem));
803 this->add_elem(std::move(el));
804 }
805 else
806 {
807 Elem * new_el = this->add_elem(std::move(el));
808 old_elems_to_new_elems[old] = new_el;
809 }
810 }
811
812 // If the other_mesh had some interior parents, we may need to
813 // copy those pointers (if they're to elements in a third mesh),
814 // or create new equivalent pointers (if they're to elements we
815 // just copied), or scream and die (if the other mesh had interior
816 // parents from a third mesh but we already have interior parents
817 // that aren't to that same third mesh.
818 if (!ip_map.empty())
819 {
820 std::atomic<bool> existing_interior_parents{false};
821
823 (this->element_stored_range(),
824 [&existing_interior_parents](const ElemRange & range)
825 {
826 for (Elem * elem : range)
827 if (elem->interior_parent())
828 {
829 existing_interior_parents = true;
830 break;
831 }
832 });
833
834 MeshBase * other_interior_mesh =
835 const_cast<MeshBase *>(&other_mesh.interior_mesh());
836
837 // If we don't already have interior parents, then we can just
838 // use whatever interior_mesh we need for the incoming
839 // elements.
840 if (!existing_interior_parents)
841 {
842 if (other_interior_mesh == &other_mesh)
843 this->set_interior_mesh(*this);
844 else
845 this->set_interior_mesh(*other_interior_mesh);
846 }
847
848 if (other_interior_mesh == &other_mesh &&
849 _interior_mesh == this)
850 for (auto & elem_pair : ip_map)
851 elem_pair.second->set_interior_parent(
852 this->elem_ptr(elem_pair.first->interior_parent()->id() + element_id_offset));
853 else if (other_interior_mesh == _interior_mesh)
854 for (auto & elem_pair : ip_map)
855 {
856 Elem * ip = const_cast<Elem *>(elem_pair.first->interior_parent());
858 ip == other_interior_mesh->elem_ptr(ip->id()));
859 elem_pair.second->set_interior_parent(ip);
860 }
861 else
862 libmesh_error_msg("Cannot copy boundary elements between meshes with different interior meshes");
863 }
864
865 // Loop (again) over the elements to fill in the neighbors
866 if (skip_find_neighbors)
867 {
868 old_elems_to_new_elems[remote_elem] = const_cast<RemoteElem*>(remote_elem);
869
870 for (const auto & old_elem : other_mesh.element_ptr_range())
871 {
872 Elem * new_elem = old_elems_to_new_elems[old_elem];
873 for (auto s : old_elem->side_index_range())
874 {
875 const Elem * old_neighbor = old_elem->neighbor_ptr(s);
876 Elem * new_neighbor = old_elems_to_new_elems[old_neighbor];
877 new_elem->set_neighbor(s, new_neighbor);
878 }
879 }
880 }
881 }
882
883#ifdef LIBMESH_ENABLE_UNIQUE_ID
884 // We set the unique ids of nodes after adding them to the mesh such that our value of
885 // _next_unique_id may be wrong. So we amend that here
886 this->set_next_unique_id(other_mesh.parallel_max_unique_id() + unique_id_offset + 1);
887#endif
888
889 // Finally, partially prepare the new Mesh for use, if that isn't
890 // being skipped.
891 // Even the default behavior here is for backwards compatibility,
892 // and we don't want to prepare everything.
893
894 if (!skip_preparation)
895 {
896 // Keep the same numbering and partitioning and distribution
897 // status for now, but save our original policies to restore
898 // later.
899 const bool allowed_renumbering = this->allow_renumbering();
900 const bool allowed_find_neighbors = this->allow_find_neighbors();
901 const bool allowed_elem_removal = this->allow_remote_element_removal();
902 const bool allowed_detect_detect_interior_parents = this->allow_detect_interior_parents();
903 this->allow_renumbering(false);
904 this->allow_remote_element_removal(false);
905 this->allow_find_neighbors(!skip_find_neighbors);
907
908 // We should generally be able to skip *all* partitioning here
909 // because we're only adding one already-consistent mesh to
910 // another.
911 const bool skipped_partitioning = this->skip_partitioning();
912 this->skip_partitioning(true);
913
914 const bool was_prepared = this->is_prepared();
915 this->prepare_for_use();
916
917 //But in the long term, don't change our policies.
918 this->allow_find_neighbors(allowed_find_neighbors);
919 this->allow_renumbering(allowed_renumbering);
920 this->allow_remote_element_removal(allowed_elem_removal);
921 this->skip_partitioning(skipped_partitioning);
922 this->allow_detect_interior_parents(allowed_detect_detect_interior_parents);
923
924 // That prepare_for_use() call marked us as prepared, but we
925 // specifically avoided some important preparation, so we might not
926 // actually be prepared now.
927 if (skip_find_neighbors ||
928 !was_prepared || !other_mesh.is_prepared())
929 this->unset_is_prepared();
930 }
931
932 // In general we've just invalidated just about everything, and we'd
933 // like to unset_is_prepared(), but specific use cases might know a
934 // priori that they're still partitioned well, or that they've
935 // copied in a disjoint mesh component and don't need new neighbor
936 // pointers, or that they're not adding anything that would change
937 // cached subdomain/element/boundary sets, etc., so we'll rely on
938 // users of the "advanced" skip_preparation option to also set what
939 // preparation they still need.
940
941 // else
942 // this->unset_is_prepared();
943}
944
945
946
948{
949 // this->clear (); // Nothing to clear at this level
950
951 libmesh_exceptionless_assert (!libMesh::closed());
952}
953
954
955
956namespace {
971bool sides_are_the_same_elem(const Elem & a, const Elem & b)
972{
973 if (a == b)
974 return true;
975
976 // The check above would have been sufficient if they were both
977 // polygons or both not. If just one is a polygon, we need to check the nodes
978 if (!a.runtime_topology() && !b.runtime_topology())
979 return false;
980
981 const unsigned int nv = a.n_vertices();
982 if (nv != b.n_vertices())
983 return false;
984
985 std::vector<dof_id_type> a_ids(nv), b_ids(nv);
986 for (unsigned int v = 0; v != nv; ++v)
987 {
988 a_ids[v] = a.node_id(v);
989 b_ids[v] = b.node_id(v);
990 }
991 std::sort(a_ids.begin(), a_ids.end());
992 std::sort(b_ids.begin(), b_ids.end());
993 return a_ids == b_ids;
994}
995}
996
997
998
999void UnstructuredMesh::find_neighbors (const bool reset_remote_elements,
1000 const bool reset_current_list,
1001 const bool assert_valid,
1002 const bool check_non_remote)
1003{
1004 // We might actually want to run this on an empty mesh
1005 // (e.g. the boundary mesh for a nonexistent bcid!)
1006 // libmesh_assert_not_equal_to (this->n_nodes(), 0);
1007 // libmesh_assert_not_equal_to (this->n_elem(), 0);
1008
1009 // This function must be run on all processors at once
1010 parallel_object_only();
1011
1012 LOG_SCOPE("find_neighbors()", "Mesh");
1013
1014 //TODO:[BSK] This should be removed later?!
1015 if (reset_current_list)
1017 (this->element_stored_range(),
1018 [reset_remote_elements](const ElemRange & range)
1019 {
1020 for (Elem * e : range)
1021 for (auto s : e->side_index_range())
1022 if (e->neighbor_ptr(s) != remote_elem || reset_remote_elements)
1023 e->set_neighbor(s, nullptr);
1024 });
1025
1026 // Find neighboring elements by first finding elements
1027 // with identical side keys and then check to see if they
1028 // are neighbors
1029 {
1030 // data structures -- Use the hash_multimap if available
1031 typedef dof_id_type key_type;
1032 typedef std::pair<Elem *, unsigned char> val_type;
1033 typedef std::unordered_multimap<key_type, val_type> map_type;
1034
1035 // A map from side keys to corresponding elements & side numbers
1036 map_type side_to_elem_map;
1037
1038 // Pull objects out of the loop to reduce heap operations
1039 std::unique_ptr<Elem> my_side, their_side;
1040
1041 for (const auto & element : this->element_ptr_range())
1042 {
1043 for (auto ms : element->side_index_range())
1044 {
1045 next_side:
1046 // If we haven't yet found a neighbor on this side, try.
1047 // Even if we think our neighbor is remote, that
1048 // information may be out of date.
1049 //
1050 // If we're only checking remote neighbors, after a
1051 // redistribution, then we'll skip the non-remote ones
1052 if ((element->neighbor_ptr(ms) == nullptr && check_non_remote) ||
1053 element->neighbor_ptr(ms) == remote_elem)
1054 {
1055 // Get the key for the side of this element. Use the
1056 // low_order_key so we can find neighbors in
1057 // mixed-order meshes if necessary.
1058 const dof_id_type key = element->low_order_key(ms);
1059
1060 // Look for elements that have an identical side key
1061 auto bounds = side_to_elem_map.equal_range(key);
1062
1063 // May be multiple keys, check all the possible
1064 // elements which _might_ be neighbors.
1065 if (bounds.first != bounds.second)
1066 {
1067 // Get the side for this element
1068 element->side_ptr(my_side, ms);
1069
1070 // Look at all the entries with an equivalent key
1071 while (bounds.first != bounds.second)
1072 {
1073 // Get the potential element
1074 Elem * neighbor = bounds.first->second.first;
1075
1076 // Get the side for the neighboring element
1077 const unsigned int ns = bounds.first->second.second;
1078 neighbor->side_ptr(their_side, ns);
1079 //libmesh_assert(my_side.get());
1080 //libmesh_assert(their_side.get());
1081
1082 // If found a match with my side
1083 //
1084 // In 1D, since parents and children have an
1085 // equal side (i.e. a node) we need to check
1086 // for matching level() to avoid setting our
1087 // neighbor pointer to any of our neighbor's
1088 // descendants.
1089 if (sides_are_the_same_elem(*my_side, *their_side) &&
1090 (element->level() == neighbor->level()))
1091 {
1092 // So share a side. Is this a mixed pair
1093 // of subactive and active/ancestor
1094 // elements?
1095 // If not, then we're neighbors.
1096 // If so, then the subactive's neighbor is
1097
1098 if (element->subactive() ==
1099 neighbor->subactive())
1100 {
1101 // an element is only subactive if it has
1102 // been coarsened but not deleted
1103 element->set_neighbor (ms,neighbor);
1104 neighbor->set_neighbor(ns,element);
1105 }
1106 else if (element->subactive())
1107 {
1108 element->set_neighbor(ms,neighbor);
1109 }
1110 else if (neighbor->subactive())
1111 {
1112 neighbor->set_neighbor(ns,element);
1113 }
1114 side_to_elem_map.erase (bounds.first);
1115
1116 // get out of this nested crap
1117 goto next_side;
1118 }
1119
1120 ++bounds.first;
1121 }
1122 }
1123
1124 // didn't find a match...
1125 // Build the map entry for this element
1126 side_to_elem_map.emplace
1127 (key, std::make_pair(element, cast_int<unsigned char>(ms)));
1128 }
1129 }
1130 }
1131 }
1132
1133#ifdef LIBMESH_ENABLE_PERIODIC
1134 // Get the disjoint neighbor boundary pairs object (from periodic BCs)
1135 auto * db = this->get_disjoint_neighbor_boundary_pairs();
1136
1137 if (db)
1138 {
1139 // Obtain a point locator
1140 std::unique_ptr<PointLocatorBase> point_locator = this->sub_point_locator();
1141
1142 for (const auto & element : this->element_ptr_range())
1143 {
1144 for (auto ms : element->side_index_range())
1145 {
1146 // Skip if this side already has a valid neighbor (including remote neighbors)
1147 if (element->neighbor_ptr(ms) != nullptr &&
1148 element->neighbor_ptr(ms) != remote_elem)
1149 continue;
1150
1151 for (const auto & [id, boundary_ptr] : *db)
1152 {
1153 if (!this->get_boundary_info().has_boundary_id(element, ms, id))
1154 continue;
1155
1156 unsigned int neigh_side;
1157 const Elem * neigh =
1158 db->neighbor(id, *point_locator, element, ms, &neigh_side);
1159
1160 if (neigh && neigh != remote_elem && neigh != element)
1161 {
1162 auto neigh_changeable = this->elem_ptr(neigh->id());
1163 element->set_neighbor(ms, neigh_changeable);
1164 neigh_changeable->set_neighbor(neigh_side, element);
1165 }
1166 }
1167 }
1168 }
1169 }
1170#endif // LIBMESH_ENABLE_PERIODIC
1171
1172#ifdef LIBMESH_ENABLE_AMR
1173
1201 const unsigned int n_levels = MeshTools::n_levels(*this);
1202 for (unsigned int level = 1; level < n_levels; ++level)
1203 {
1204 for (auto & current_elem : as_range(level_elements_begin(level),
1205 level_elements_end(level)))
1206 {
1207 libmesh_assert(current_elem);
1208 Elem * parent = current_elem->parent();
1209 libmesh_assert(parent);
1210 const unsigned int my_child_num = parent->which_child_am_i(current_elem);
1211
1212 for (auto s : current_elem->side_index_range())
1213 {
1214 if (current_elem->neighbor_ptr(s) == nullptr ||
1215 (current_elem->neighbor_ptr(s) == remote_elem &&
1216 parent->is_child_on_side(my_child_num, s)))
1217 {
1218 Elem * neigh = parent->neighbor_ptr(s);
1219
1220 // If neigh was refined and had non-subactive children
1221 // made remote earlier, then our current elem should
1222 // actually have one of those remote children as a
1223 // neighbor
1224 if (neigh &&
1225 (neigh->ancestor() ||
1226 // If neigh has subactive children which should have
1227 // matched as neighbors of the current element but
1228 // did not, then those likewise must be remote
1229 // children.
1230 (current_elem->subactive() && neigh->has_children() &&
1231 (neigh->level()+1) == current_elem->level())))
1232 {
1233#ifdef DEBUG
1234 // Let's make sure that "had children made remote"
1235 // situation is actually the case
1236 libmesh_assert(neigh->has_children());
1237 bool neigh_has_remote_children = false;
1238 for (auto & child : neigh->child_ref_range())
1239 if (&child == remote_elem)
1240 neigh_has_remote_children = true;
1241 libmesh_assert(neigh_has_remote_children);
1242
1243 // And let's double-check that we don't have
1244 // a remote_elem neighboring an active local element
1245 if (current_elem->active())
1246 libmesh_assert_not_equal_to (current_elem->processor_id(),
1247 this->processor_id());
1248#endif // DEBUG
1249 neigh = const_cast<RemoteElem *>(remote_elem);
1250 }
1251 // If neigh and current_elem are more than one level
1252 // apart, figuring out whether we have a remote
1253 // neighbor here becomes much harder.
1254 else if (neigh && (current_elem->subactive() &&
1255 neigh->has_children()))
1256 {
1257 // Find the deepest descendant of neigh which
1258 // we could consider for a neighbor. If we run
1259 // out of neigh children, then that's our
1260 // neighbor. If we find a potential neighbor
1261 // with remote_children and we don't find any
1262 // potential neighbors among its non-remote
1263 // children, then our neighbor must be remote.
1264 while (neigh != remote_elem &&
1265 neigh->has_children())
1266 {
1267 bool found_neigh = false;
1268 for (unsigned int c = 0, nc = neigh->n_children();
1269 !found_neigh && c != nc; ++c)
1270 {
1271 Elem * child = neigh->child_ptr(c);
1272 if (child == remote_elem)
1273 continue;
1274 for (auto ncn : child->neighbor_ptr_range())
1275 {
1276 if (ncn != remote_elem &&
1277 ncn->is_ancestor_of(current_elem))
1278 {
1279 neigh = ncn;
1280 found_neigh = true;
1281 break;
1282 }
1283 }
1284 }
1285 if (!found_neigh)
1286 neigh = const_cast<RemoteElem *>(remote_elem);
1287 }
1288 }
1289 current_elem->set_neighbor(s, neigh);
1290#ifdef DEBUG
1291 if (neigh != nullptr && neigh != remote_elem)
1292 // We ignore subactive elements here because
1293 // we don't care about neighbors of subactive element.
1294 if ((!neigh->active()) && (!current_elem->subactive()))
1295 {
1296 libMesh::err << "On processor " << this->processor_id()
1297 << std::endl;
1298 libMesh::err << "Bad element ID = " << current_elem->id()
1299 << ", Side " << s << ", Bad neighbor ID = " << neigh->id() << std::endl;
1300 libMesh::err << "Bad element proc_ID = " << current_elem->processor_id()
1301 << ", Bad neighbor proc_ID = " << neigh->processor_id() << std::endl;
1302 libMesh::err << "Bad element size = " << current_elem->hmin()
1303 << ", Bad neighbor size = " << neigh->hmin() << std::endl;
1304 libMesh::err << "Bad element center = " << current_elem->vertex_average()
1305 << ", Bad neighbor center = " << neigh->vertex_average() << std::endl;
1306 libMesh::err << "ERROR: "
1307 << (current_elem->active()?"Active":"Ancestor")
1308 << " Element at level "
1309 << current_elem->level() << std::endl;
1310 libMesh::err << "with "
1311 << (parent->active()?"active":
1312 (parent->subactive()?"subactive":"ancestor"))
1313 << " parent share "
1314 << (neigh->subactive()?"subactive":"ancestor")
1315 << " neighbor at level " << neigh->level()
1316 << std::endl;
1317 NameBasedIO(*this).write ("bad_mesh.gmv");
1318 libmesh_error_msg("Problematic mesh written to bad_mesh.gmv.");
1319 }
1320#endif // DEBUG
1321 }
1322 }
1323
1324 // We can skip to the next element if we're full-dimension
1325 // and therefore don't have any interior parents
1326 if (current_elem->dim() >= LIBMESH_DIM)
1327 continue;
1328
1329 // We have no interior parents unless we can find one later
1330 current_elem->set_interior_parent(nullptr);
1331
1332 Elem * pip = parent->interior_parent();
1333
1334 if (!pip)
1335 continue;
1336
1337 // If there's no interior_parent children, whether due to a
1338 // remote element or a non-conformity, then there's no
1339 // children to search.
1340 if (pip == remote_elem || pip->active())
1341 {
1342 current_elem->set_interior_parent(pip);
1343 continue;
1344 }
1345
1346 // For node comparisons we'll need a sensible tolerance
1347 Real node_tolerance = current_elem->hmin() * TOLERANCE;
1348
1349 // Otherwise our interior_parent should be a child of our
1350 // parent's interior_parent.
1351 for (auto & child : pip->child_ref_range())
1352 {
1353 // If we have a remote_elem, that might be our
1354 // interior_parent. We'll set it provisionally now and
1355 // keep trying to find something better.
1356 if (&child == remote_elem)
1357 {
1358 current_elem->set_interior_parent
1359 (const_cast<RemoteElem *>(remote_elem));
1360 continue;
1361 }
1362
1363 bool child_contains_our_nodes = true;
1364 for (auto & n : current_elem->node_ref_range())
1365 {
1366 bool child_contains_this_node = false;
1367 for (auto & cn : child.node_ref_range())
1368 if (cn.absolute_fuzzy_equals
1369 (n, node_tolerance))
1370 {
1371 child_contains_this_node = true;
1372 break;
1373 }
1374 if (!child_contains_this_node)
1375 {
1376 child_contains_our_nodes = false;
1377 break;
1378 }
1379 }
1380 if (child_contains_our_nodes)
1381 {
1382 current_elem->set_interior_parent(&child);
1383 break;
1384 }
1385 }
1386
1387 // We should have found *some* interior_parent at this
1388 // point, whether semilocal or remote.
1389 libmesh_assert(current_elem->interior_parent());
1390 }
1391 }
1392#endif // AMR
1393
1394#ifdef DEBUG
1395 if (assert_valid)
1396 {
1398 !reset_remote_elements);
1400 }
1401#else
1402 libmesh_ignore(assert_valid);
1403#endif
1404
1405 this->_preparation.has_neighbor_ptrs = true;
1406}
1407
1408
1409
1410void UnstructuredMesh::read (const std::string & name,
1411 void *,
1412 bool skip_renumber_nodes_and_elements,
1413 bool skip_find_neighbors,
1414 bool skip_detect_interior_parents)
1415{
1416 // Set the skip_renumber_nodes_and_elements flag on all processors
1417 // if necessary.
1418 // This ensures that renumber_nodes_and_elements is *not* called
1419 // during prepare_for_use() for certain types of mesh files.
1420 // This is required in cases where there is an associated solution
1421 // file which expects a certain ordering of the nodes.
1422 if (Utility::ends_with(name, ".gmv"))
1423 this->allow_renumbering(false);
1424
1425 NameBasedIO(*this).read(name);
1426
1427 if (skip_renumber_nodes_and_elements)
1428 {
1429 // Use MeshBase::allow_renumbering() yourself instead.
1430 libmesh_deprecated();
1431 this->allow_renumbering(false);
1432 }
1433
1434 // Done reading the mesh. Now prepare it for use.
1435 const bool old_allow_find_neighbors = this->allow_find_neighbors();
1436 const bool old_allow_detect_interior_parents = this->allow_detect_interior_parents();
1437
1438 this->allow_find_neighbors(!skip_find_neighbors);
1439 this->allow_detect_interior_parents(!skip_detect_interior_parents);
1440
1441 this->prepare_for_use();
1442
1443 this->allow_find_neighbors(old_allow_find_neighbors);
1444 this->allow_detect_interior_parents(old_allow_detect_interior_parents);
1445}
1446
1447
1448
1449void UnstructuredMesh::write (const std::string & name) const
1450{
1451 LOG_SCOPE("write()", "Mesh");
1452
1453 NameBasedIO(*this).write(name);
1454}
1455
1456
1457
1458void UnstructuredMesh::write (const std::string & name,
1459 const std::vector<Number> & v,
1460 const std::vector<std::string> & vn) const
1461{
1462 LOG_SCOPE("write()", "Mesh");
1463
1464 NameBasedIO(*this).write_nodal_data(name, v, vn);
1465}
1466
1467
1468
1469
1470
1472 const processor_id_type pid) const
1473{
1474
1475 // Issue a warning if the number the number of processors
1476 // currently available is less that that requested for
1477 // partitioning. This is not necessarily an error since
1478 // you may run on one processor and still partition the
1479 // mesh into several partitions.
1480#ifdef DEBUG
1481 if (this->n_processors() < pid)
1482 {
1483 libMesh::out << "WARNING: You are creating a "
1484 << "mesh for a processor id (="
1485 << pid
1486 << ") greater than "
1487 << "the number of processors available for "
1488 << "the calculation. (="
1489 << this->n_processors()
1490 << ")."
1491 << std::endl;
1492 }
1493#endif
1494
1495 this->create_submesh (pid_mesh,
1496 this->active_pid_elements_begin(pid),
1497 this->active_pid_elements_end(pid));
1498}
1499
1500
1501
1502
1503
1504
1505
1507 const const_element_iterator & it,
1508 const const_element_iterator & it_end) const
1509{
1510 // Just in case the subdomain_mesh already has some information
1511 // in it, get rid of it.
1512 new_mesh.clear();
1513
1514 // If we're not serial, our submesh isn't either.
1515 // There are no remote elements to delete on an empty mesh, but
1516 // calling the method to do so marks the mesh as parallel.
1517 if (!this->is_serial())
1518 new_mesh.delete_remote_elements();
1519
1520 // Fail if (*this == new_mesh), we cannot create a submesh inside ourself!
1521 // This may happen if the user accidentally passes the original mesh into
1522 // this function! We will check this by making sure we did not just
1523 // clear ourself.
1524 libmesh_assert_not_equal_to (this->n_nodes(), 0);
1525 libmesh_assert_not_equal_to (this->n_elem(), 0);
1526
1527 // Container to catch boundary IDs handed back by BoundaryInfo
1528 std::vector<boundary_id_type> bc_ids;
1529
1530 // Put any extra integers on the new mesh too
1531 new_mesh.merge_extra_integer_names(*this);
1532 const unsigned int n_node_ints = _node_integer_names.size();
1533
1534 for (const auto & old_elem : as_range(it, it_end))
1535 {
1536 // Add an equivalent element type to the new_mesh.
1537 // disconnected_clone() copies ids, extra element integers, etc.
1538 auto uelem = old_elem->disconnected_clone();
1539 Elem * new_elem = new_mesh.add_elem(std::move(uelem));
1540 libmesh_assert(new_elem);
1541
1542 // Loop over the nodes on this element.
1543 for (auto n : old_elem->node_index_range())
1544 {
1545 const dof_id_type this_node_id = old_elem->node_id(n);
1546
1547 // Add this node to the new mesh if it's not there already
1548 if (!new_mesh.query_node_ptr(this_node_id))
1549 {
1550 Node * newn =
1551 new_mesh.add_point (old_elem->point(n),
1552 this_node_id,
1553 old_elem->node_ptr(n)->processor_id());
1554
1555 newn->add_extra_integers(n_node_ints);
1556 for (unsigned int i = 0; i != n_node_ints; ++i)
1557 newn->set_extra_integer(i, old_elem->node_ptr(n)->get_extra_integer(i));
1558
1559#ifdef LIBMESH_ENABLE_UNIQUE_ID
1560 newn->set_unique_id(old_elem->node_ptr(n)->unique_id());
1561#endif
1562 }
1563
1564 // Define this element's connectivity on the new mesh
1565 new_elem->set_node(n, new_mesh.node_ptr(this_node_id));
1566 }
1567
1568 // Maybe add boundary conditions for this element
1569 for (auto s : old_elem->side_index_range())
1570 {
1571 this->get_boundary_info().boundary_ids(old_elem, s, bc_ids);
1572 new_mesh.get_boundary_info().add_side (new_elem, s, bc_ids);
1573 }
1574 } // end loop over elements
1575
1576 // Prepare the new_mesh for use
1577 new_mesh.prepare_for_use();
1578}
1579
1580
1581
1582#ifdef LIBMESH_ENABLE_AMR
1584{
1585 LOG_SCOPE ("contract()", "Mesh");
1586
1587 // Flag indicating if this call actually changes the mesh
1588 bool mesh_changed = false;
1589
1590#ifdef DEBUG
1591 for (const auto & elem : this->element_ptr_range())
1592 libmesh_assert(elem->active() || elem->subactive() || elem->ancestor());
1593#endif
1594
1595 // Loop over the elements.
1596 for (auto & elem : this->element_ptr_range())
1597 {
1598 // Delete all the subactive ones
1599 if (elem->subactive())
1600 {
1601 // No level-0 element should be subactive.
1602 // Note that we CAN'T test elem->level(), as that
1603 // touches elem->parent()->dim(), and elem->parent()
1604 // might have already been deleted!
1605 libmesh_assert(elem->parent());
1606
1607 // Delete the element
1608 // This just sets a pointer to nullptr, and doesn't
1609 // invalidate any iterators
1610 this->delete_elem(elem);
1611
1612 // the mesh has certainly changed
1613 mesh_changed = true;
1614 }
1615 else
1616 {
1617 // Compress all the active ones
1618 if (elem->active())
1619 elem->contract();
1620 else
1621 libmesh_assert (elem->ancestor());
1622 }
1623 }
1624
1625 // Strip any newly-created nullptr voids out of the element array
1627
1628 // FIXME: Need to understand why deleting subactive children
1629 // invalidates the point locator. For now we will clear it explicitly
1630 this->clear_point_locator();
1631
1632 // Allow our GhostingFunctor objects to reinit if necessary.
1633 for (auto & gf : as_range(this->ghosting_functors_begin(),
1634 this->ghosting_functors_end()))
1635 {
1636 libmesh_assert(gf);
1637 gf->mesh_reinit();
1638 }
1639
1640 return mesh_changed;
1641}
1642#endif // #ifdef LIBMESH_ENABLE_AMR
1643
1644
1645
1647{
1648 LOG_SCOPE("all_first_order()", "Mesh");
1649
1653 std::vector<bool> node_touched_by_me(this->max_node_id(), false);
1654
1655 // Loop over the high-ordered elements.
1656 // First make sure they _are_ indeed high-order, and then replace
1657 // them with an equivalent first-order element.
1658 for (auto & so_elem : element_ptr_range())
1659 {
1660 libmesh_assert(so_elem);
1661
1662 /*
1663 * build the first-order equivalent, add to
1664 * the new_elements list.
1665 */
1666 auto lo_elem = Elem::build
1668 (so_elem->type()), so_elem->parent());
1669
1670 const unsigned short n_sides = so_elem->n_sides();
1671
1672 for (unsigned short s=0; s != n_sides; ++s)
1673 if (so_elem->neighbor_ptr(s) == remote_elem)
1674 lo_elem->set_neighbor(s, const_cast<RemoteElem *>(remote_elem));
1675
1676#ifdef LIBMESH_ENABLE_AMR
1677 /*
1678 * Reset the parent links of any child elements
1679 */
1680 if (so_elem->has_children())
1681 for (unsigned int c = 0, nc = so_elem->n_children(); c != nc; ++c)
1682 {
1683 Elem * child = so_elem->child_ptr(c);
1684 if (child != remote_elem)
1685 child->set_parent(lo_elem.get());
1686 lo_elem->add_child(child, c);
1687 }
1688
1689 /*
1690 * Reset the child link of any parent element
1691 */
1692 if (so_elem->parent())
1693 {
1694 unsigned int c =
1695 so_elem->parent()->which_child_am_i(so_elem);
1696 lo_elem->parent()->replace_child(lo_elem.get(), c);
1697 }
1698
1699 /*
1700 * Copy as much data to the new element as makes sense
1701 */
1702 lo_elem->set_p_level(so_elem->p_level());
1703 lo_elem->set_refinement_flag(so_elem->refinement_flag());
1704 lo_elem->set_p_refinement_flag(so_elem->p_refinement_flag());
1705#endif
1706
1707 libmesh_assert_equal_to (lo_elem->n_vertices(), so_elem->n_vertices());
1708
1709 /*
1710 * By definition the vertices of the linear and
1711 * second order element are identically numbered.
1712 * transfer these.
1713 */
1714 for (unsigned int v=0, snv=so_elem->n_vertices(); v < snv; v++)
1715 {
1716 lo_elem->set_node(v, so_elem->node_ptr(v));
1717 node_touched_by_me[lo_elem->node_id(v)] = true;
1718 }
1719
1720 /*
1721 * find_neighbors relies on remote_elem neighbor links being
1722 * properly maintained.
1723 */
1724 for (unsigned short s=0; s != n_sides; s++)
1725 {
1726 if (so_elem->neighbor_ptr(s) == remote_elem)
1727 lo_elem->set_neighbor(s, const_cast<RemoteElem*>(remote_elem));
1728 }
1729
1737 (this->get_boundary_info(), so_elem, lo_elem.get());
1738
1739 /*
1740 * The new first-order element is ready.
1741 * Inserting it into the mesh will replace and delete
1742 * the second-order element.
1743 */
1744 lo_elem->set_id(so_elem->id());
1745#ifdef LIBMESH_ENABLE_UNIQUE_ID
1746 lo_elem->set_unique_id(so_elem->unique_id());
1747#endif
1748
1749 const unsigned int nei = so_elem->n_extra_integers();
1750 lo_elem->add_extra_integers(nei);
1751 for (unsigned int i=0; i != nei; ++i)
1752 lo_elem->set_extra_integer(i, so_elem->get_extra_integer(i));
1753
1754 lo_elem->inherit_data_from(*so_elem);
1755
1756 this->insert_elem(std::move(lo_elem));
1757 }
1758
1759 // Deleting nodes does not invalidate iterators, so this is safe.
1760 for (const auto & node : this->node_ptr_range())
1761 if (!node_touched_by_me[node->id()])
1762 this->delete_node(node);
1763
1764 // If crazy people applied boundary info to non-vertices and then
1765 // deleted those non-vertices, we should make sure their boundary id
1766 // caches are correct.
1768
1769 // On hanging nodes that used to also be second order nodes, we
1770 // might now have an invalid nodal processor_id()
1772
1773 // delete or renumber nodes if desired
1774 this->prepare_for_use();
1775}
1776
1777
1778
1779void
1781 const bool full_ordered)
1782{
1783 LOG_SCOPE("all_second_order_range()", "Mesh");
1784
1785 /*
1786 * The maximum number of new second order nodes we might be adding,
1787 * for use when picking unique unique_id values later. This variable
1788 * is not used unless unique ids are enabled.
1789 */
1790 unsigned int max_new_nodes_per_elem;
1791
1792 /*
1793 * For speed-up of the \p add_point() method, we
1794 * can reserve memory. Guess the number of additional
1795 * nodes based on the element spatial dimensions and the
1796 * total number of nodes in the mesh as an upper bound.
1797 */
1798 switch (this->mesh_dimension())
1799 {
1800 case 1:
1801 /*
1802 * in 1D, there can only be order-increase from Edge2
1803 * to Edge3. Something like 1/2 of n_nodes() have
1804 * to be added
1805 */
1806 max_new_nodes_per_elem = 3 - 2;
1807 this->reserve_nodes(static_cast<unsigned int>
1808 (1.5*static_cast<double>(this->n_nodes())));
1809 break;
1810
1811 case 2:
1812 /*
1813 * in 2D, either refine from Tri3 to Tri6 (double the nodes)
1814 * or from Quad4 to Quad8 (again, double) or Quad9 (2.25 that much)
1815 */
1816 max_new_nodes_per_elem = 9 - 4;
1817 this->reserve_nodes(static_cast<unsigned int>
1818 (2*static_cast<double>(this->n_nodes())));
1819 break;
1820
1821
1822 case 3:
1823 /*
1824 * in 3D, either refine from Tet4 to Tet10 (factor = 2.5) up to
1825 * Hex8 to Hex27 (something > 3). Since in 3D there _are_ already
1826 * quite some nodes, and since we do not want to overburden the memory by
1827 * a too conservative guess, use the lower bound
1828 */
1829 max_new_nodes_per_elem = 27 - 8;
1830 this->reserve_nodes(static_cast<unsigned int>
1831 (2.5*static_cast<double>(this->n_nodes())));
1832 break;
1833
1834 default:
1835 // Hm?
1836 libmesh_error_msg("Unknown mesh dimension " << this->mesh_dimension());
1837 }
1838
1839 // All the real work is done in the helper function
1840 all_increased_order_range(*this, range, max_new_nodes_per_elem,
1841 [full_ordered](ElemType t) {
1842 return Elem::second_order_equivalent_type(t, full_ordered);
1843 });
1844}
1845
1846
1847
1849{
1850 LOG_SCOPE("all_complete_order()", "Mesh");
1851
1852 /*
1853 * The maximum number of new higher-order nodes we might be adding,
1854 * for use when picking unique unique_id values later. This variable
1855 * is not used unless unique ids are enabled.
1856 */
1857 unsigned int max_new_nodes_per_elem;
1858
1859 /*
1860 * for speed-up of the \p add_point() method, we
1861 * can reserve memory. Guess the number of additional
1862 * nodes based on the element spatial dimensions and the
1863 * total number of nodes in the mesh as an upper bound.
1864 */
1865 switch (this->mesh_dimension())
1866 {
1867 case 1:
1868 /*
1869 * in 1D, there can only be order-increase from Edge2
1870 * to Edge3. Something like 1/2 of n_nodes() have
1871 * to be added
1872 */
1873 max_new_nodes_per_elem = 3 - 2;
1874 this->reserve_nodes(static_cast<unsigned int>
1875 (1.5*static_cast<double>(this->n_nodes())));
1876 break;
1877
1878 case 2:
1879 /*
1880 * in 2D, we typically refine from Tri3 or Tri6 to Tri7 (2.3333
1881 * or 1.1667 times the nodes) but might refine from Quad4 to
1882 * Quad9 (2.25 times the nodes)
1883 */
1884 max_new_nodes_per_elem = 9 - 4;
1885 this->reserve_nodes(static_cast<unsigned int>
1886 (2*static_cast<double>(this->n_nodes())));
1887 break;
1888
1889
1890 case 3:
1891 /*
1892 * in 3D, we typically refine from Tet10 to Tet14 (factor = 1.4)
1893 * but may go Hex8 to Hex27 or Tet4 to Tet14 (something > 3).
1894 * Since in 3D there _are_ already quite some nodes, and since
1895 * we do not want to overburden the memory by a too-conservative
1896 * guess, use a moderate bound
1897 */
1898 max_new_nodes_per_elem = 27 - 8;
1899 this->reserve_nodes(static_cast<unsigned int>
1900 (2.5*static_cast<double>(this->n_nodes())));
1901 break;
1902
1903 default:
1904 // Hm?
1905 libmesh_error_msg("Unknown mesh dimension " << this->mesh_dimension());
1906 }
1907
1908 // All the real work is done in the helper function
1909 all_increased_order_range(*this, range, max_new_nodes_per_elem,
1910 [](ElemType t) {
1912 });
1913}
1914
1915
1916std::size_t
1918 boundary_id_type this_mesh_boundary_id,
1919 boundary_id_type other_mesh_boundary_id,
1920 Real tol,
1921 bool clear_stitched_boundary_ids,
1922 bool verbose,
1923 bool use_binary_search,
1924 bool enforce_all_nodes_match_on_boundaries,
1925 bool merge_boundary_nodes_all_or_nothing,
1926 bool remap_subdomain_ids,
1927 bool prepare_after_stitching)
1928{
1929 LOG_SCOPE("stitch_meshes()", "UnstructuredMesh");
1930 return stitching_helper(&other_mesh,
1931 this_mesh_boundary_id,
1932 other_mesh_boundary_id,
1933 tol,
1934 clear_stitched_boundary_ids,
1935 verbose,
1936 use_binary_search,
1937 enforce_all_nodes_match_on_boundaries,
1938 true,
1939 merge_boundary_nodes_all_or_nothing,
1940 remap_subdomain_ids,
1941 prepare_after_stitching);
1942}
1943
1944
1945std::size_t
1947 boundary_id_type boundary_id_2,
1948 Real tol,
1949 bool clear_stitched_boundary_ids,
1950 bool verbose,
1951 bool use_binary_search,
1952 bool enforce_all_nodes_match_on_boundaries,
1953 bool merge_boundary_nodes_all_or_nothing,
1954 bool prepare_after_stitching)
1955
1956{
1957 return stitching_helper(nullptr,
1958 boundary_id_1,
1959 boundary_id_2,
1960 tol,
1961 clear_stitched_boundary_ids,
1962 verbose,
1963 use_binary_search,
1964 enforce_all_nodes_match_on_boundaries,
1965 /* skip_find_neighbors = */ true,
1966 merge_boundary_nodes_all_or_nothing,
1967 /* remap_subdomain_ids = */ false,
1968 prepare_after_stitching);
1969}
1970
1971
1972std::size_t
1974 boundary_id_type this_mesh_boundary_id,
1975 boundary_id_type other_mesh_boundary_id,
1976 Real tol,
1977 bool clear_stitched_boundary_ids,
1978 bool verbose,
1979 bool use_binary_search,
1980 bool enforce_all_nodes_match_on_boundaries,
1981 bool skip_find_neighbors,
1982 bool merge_boundary_nodes_all_or_nothing,
1983 bool remap_subdomain_ids,
1984 bool prepare_after_stitching)
1985{
1986#ifdef DEBUG
1987 // We rely on neighbor links here
1989#endif
1990
1991 bool is_valid_disjoint_pair_to_stitch = false;
1992
1993#ifdef LIBMESH_ENABLE_PERIODIC
1994 auto * this_db = this->get_disjoint_neighbor_boundary_pairs();
1995 auto * other_db = (other_mesh ? other_mesh->get_disjoint_neighbor_boundary_pairs() : nullptr);
1996 const bool have_disc_bdys =
1997 (this_db && !this_db->empty()) || (other_db && !other_db->empty());
1998
1999 if (have_disc_bdys)
2000 {
2001 const boundary_id_type a = this_mesh_boundary_id;
2002 const boundary_id_type b = other_mesh_boundary_id;
2003
2004 auto get_pb = [](const PeriodicBoundaries * db, boundary_id_type id)
2005 {
2006 return db ? db->boundary(id) : nullptr;
2007 };
2008
2009 // this mesh
2010 const auto * pb_this_a = get_pb(this_db, a);
2011 const auto * pb_this_b = get_pb(this_db, b);
2012 const bool in_this =
2013 (pb_this_a && pb_this_a->pairedboundary == b) ||
2014 (pb_this_b && pb_this_b->pairedboundary == a);
2015
2016 // other mesh
2017 const auto * pb_other_b = get_pb(other_db, b);
2018 const auto * pb_other_a = get_pb(other_db, a);
2019 const bool in_other =
2020 (pb_other_b && pb_other_b->pairedboundary == a) ||
2021 (pb_other_a && pb_other_a->pairedboundary == b);
2022
2023 // Conflict conditions:
2024 // Case 1: On "this" mesh, a or b exist but are not paired,
2025 // while the other mesh pairs them.
2026 if (!in_this && (pb_this_a || pb_this_b) && in_other)
2027 libmesh_error_msg("Disjoint neighbor boundary pairing mismatch: on 'this' mesh, "
2028 "boundary (" << a << " or " << b
2029 << ") exists but is not paired; on 'other' mesh the pair is present.");
2030
2031 // Case 2: On "other" mesh, a or b exist but are not paired,
2032 // while this mesh pairs them.
2033 if (!in_other && (pb_other_a || pb_other_b) && in_this)
2034 libmesh_error_msg("Disjoint neighbor boundary pairing mismatch: on 'other' mesh, "
2035 "boundary (" << a << " or " << b
2036 << ") exists but is not paired; on 'this' mesh the pair is present.");
2037
2038 // Legal conditions: either side has a correct pairing
2039 if (in_this || in_other)
2040 is_valid_disjoint_pair_to_stitch = true;
2041 }
2042#endif // LIBMESH_ENABLE_PERIODIC
2043
2044 // We can't even afford any unset neighbor links here.
2045 if (!this->is_prepared())
2046 this->find_neighbors();
2047
2048 // FIXME: make distributed mesh support efficient.
2049 // Yes, we currently suck.
2050 MeshSerializer serialize(*this);
2051
2052 // *Badly*.
2053 std::unique_ptr<MeshSerializer> serialize_other;
2054 if (other_mesh)
2055 serialize_other = std::make_unique<MeshSerializer>
2056 (*const_cast<MeshBase *>(other_mesh));
2057
2058 std::map<dof_id_type, dof_id_type> node_to_node_map, other_to_this_node_map; // The second is the inverse map of the first
2059 std::map<dof_id_type, std::vector<dof_id_type>> node_to_elems_map;
2060
2061 typedef dof_id_type key_type;
2062 typedef std::pair<const Elem *, unsigned char> val_type;
2063 typedef std::pair<key_type, val_type> key_val_pair;
2064 typedef std::unordered_multimap<key_type, val_type> map_type;
2065 // Mapping between all side keys in this mesh and elements+side numbers relevant to the boundary in this mesh as well.
2066 map_type side_to_elem_map;
2067
2068 // If there is only one mesh (i.e. other_mesh == nullptr), then loop over this mesh twice
2069 if (!other_mesh)
2070 {
2071 other_mesh = this;
2072 }
2073
2074 if ((this_mesh_boundary_id != BoundaryInfo::invalid_id) &&
2075 (other_mesh_boundary_id != BoundaryInfo::invalid_id))
2076 {
2077 LOG_SCOPE("stitch_meshes node merging", "UnstructuredMesh");
2078
2079 // While finding nodes on the boundary, also find the minimum edge length
2080 // of all faces on both boundaries. This will later be used in relative
2081 // distance checks when stitching nodes.
2082 Real h_min = std::numeric_limits<Real>::max();
2083 bool h_min_updated = false;
2084
2085 // Loop below fills in these sets for the two meshes.
2086 std::set<dof_id_type> this_boundary_node_ids, other_boundary_node_ids;
2087
2088 // Pull objects out of the loop to reduce heap operations
2089 std::unique_ptr<const Elem> side;
2090
2091 {
2092 // Make temporary fixed-size arrays for loop
2093 boundary_id_type id_array[2] = {this_mesh_boundary_id, other_mesh_boundary_id};
2094 std::set<dof_id_type> * set_array[2] = {&this_boundary_node_ids, &other_boundary_node_ids};
2095 const MeshBase * mesh_array[2] = {this, other_mesh};
2096
2097 for (unsigned i=0; i<2; ++i)
2098 {
2099 // First we deal with node boundary IDs. We only enter
2100 // this loop if we have at least one nodeset. Note that we
2101 // do not attempt to make an h_min determination here.
2102 // The h_min determination is done while looping over the
2103 // Elems and checking their sides and edges for boundary
2104 // information, below.
2105 if (mesh_array[i]->get_boundary_info().n_nodeset_conds() > 0)
2106 {
2107 // build_node_list() returns a vector of (node-id, bc-id) tuples
2108 for (const auto & t : mesh_array[i]->get_boundary_info().build_node_list())
2109 {
2110 boundary_id_type node_bc_id = std::get<1>(t);
2111 if (node_bc_id == id_array[i])
2112 {
2113 dof_id_type this_node_id = std::get<0>(t);
2114 set_array[i]->insert( this_node_id );
2115 }
2116 }
2117 }
2118
2119 // Container to catch boundary IDs passed back from BoundaryInfo.
2120 std::vector<boundary_id_type> bc_ids;
2121
2122 // Pointers to boundary NodeElems encountered while looping over the entire Mesh
2123 // and checking side and edge boundary ids. The Nodes associated with NodeElems
2124 // may be in a boundary nodeset, but not connected to any other Elems. In this
2125 // case, we also consider the "minimum node separation distance" amongst all
2126 // NodeElems when determining the relevant h_min value for this mesh.
2127 std::vector<const Elem *> boundary_node_elems;
2128
2129 for (auto & el : mesh_array[i]->element_ptr_range())
2130 {
2131 // Now check whether elem has a face on the specified boundary
2132 for (auto side_id : el->side_index_range())
2133 {
2134 bool should_stitch_this_side =
2135 (el->neighbor_ptr(side_id) == nullptr) ||
2136 (is_valid_disjoint_pair_to_stitch &&
2137 mesh_array[i]->get_boundary_info().has_boundary_id(el, side_id, id_array[i]));
2138
2139 if (should_stitch_this_side)
2140 {
2141 // Get *all* boundary IDs on this side, not just the first one!
2142 mesh_array[i]->get_boundary_info().boundary_ids (el, side_id, bc_ids);
2143
2144 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
2145 {
2146 el->build_side_ptr(side, side_id);
2147 for (auto & n : side->node_ref_range())
2148 set_array[i]->insert(n.id());
2149
2150 h_min = std::min(h_min, side->hmin());
2151 h_min_updated = true;
2152
2153 // This side is on the boundary, add its information to side_to_elem
2154 if (skip_find_neighbors && (i==0))
2155 {
2156 key_type key = el->low_order_key(side_id);
2157 val_type val;
2158 val.first = el;
2159 val.second = cast_int<unsigned char>(side_id);
2160
2161 key_val_pair kvp;
2162 kvp.first = key;
2163 kvp.second = val;
2164 side_to_elem_map.insert (kvp);
2165 }
2166 }
2167
2168 // Also, check the edges on this side. We don't have to worry about
2169 // updating neighbor info in this case since elements don't store
2170 // neighbor info on edges.
2171 for (auto edge_id : el->edge_index_range())
2172 {
2173 if (el->is_edge_on_side(edge_id, side_id))
2174 {
2175 // Get *all* boundary IDs on this edge, not just the first one!
2176 mesh_array[i]->get_boundary_info().edge_boundary_ids (el, edge_id, bc_ids);
2177
2178 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
2179 {
2180 std::unique_ptr<const Elem> edge (el->build_edge_ptr(edge_id));
2181 for (auto & n : edge->node_ref_range())
2182 set_array[i]->insert( n.id() );
2183
2184 h_min = std::min(h_min, edge->hmin());
2185 h_min_updated = true;
2186 }
2187 }
2188 } // end for (edge_id)
2189 } // end if (should_stitch_this_side)
2190 } // end for (side_id)
2191
2192 // Alternatively, is this a boundary NodeElem? If so,
2193 // add it to a list of NodeElems that will later be
2194 // used to set h_min based on the minimum node
2195 // separation distance between all pairs of boundary
2196 // NodeElems.
2197 if (el->type() == NODEELEM)
2198 {
2199 mesh_array[i]->get_boundary_info().boundary_ids(el->node_ptr(0), bc_ids);
2200 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
2201 {
2202 boundary_node_elems.push_back(el);
2203
2204 // Debugging:
2205 // libMesh::out << "Elem " << el->id() << " is a NodeElem on boundary " << id_array[i] << std::endl;
2206 }
2207 } // end if (el->type() == NODEELEM)
2208 } // end for (el)
2209
2210 // Compute the minimum node separation distance amongst
2211 // all boundary NodeElem pairs.
2212 {
2213 const auto N = boundary_node_elems.size();
2214 for (auto node_elem_i : make_range(N))
2215 for (auto node_elem_j : make_range(node_elem_i+1, N))
2216 {
2217 Real node_sep =
2218 (boundary_node_elems[node_elem_i]->point(0) - boundary_node_elems[node_elem_j]->point(0)).norm();
2219
2220 // We only want to consider non-coincident
2221 // boundary NodeElem pairs when determining the
2222 // minimum node separation distance.
2223 if (node_sep > 0.)
2224 {
2225 h_min = std::min(h_min, node_sep);
2226 h_min_updated = true;
2227 }
2228 } // end for (node_elem_j)
2229 } // end minimum NodeElem separation scope
2230 } // end for (i)
2231 } // end scope
2232
2233 if (verbose)
2234 {
2235 libMesh::out << "In UnstructuredMesh::stitch_meshes:\n"
2236 << "This mesh has " << this_boundary_node_ids.size()
2237 << " nodes on boundary `"
2238 << this->get_boundary_info().get_sideset_name(this_mesh_boundary_id)
2239 << "' (" << this_mesh_boundary_id << ").\n"
2240 << "Other mesh has " << other_boundary_node_ids.size()
2241 << " nodes on boundary `"
2242 << other_mesh->get_boundary_info().get_sideset_name(other_mesh_boundary_id)
2243 << "' (" << other_mesh_boundary_id << ").\n";
2244
2245 if (h_min_updated)
2246 {
2247 libMesh::out << "Minimum edge length on both surfaces is " << h_min << ".\n";
2248 }
2249 else
2250 {
2251 libMesh::out << "No minimum edge length determined on specified surfaces." << std::endl;
2252 }
2253 }
2254
2255 // At this point, if h_min==0 it means that there were at least two coincident
2256 // nodes on the surfaces being stitched, and we don't currently support that case.
2257 // (It might be possible to support, but getting it exactly right would be tricky
2258 // and probably not worth the extra complications to the "normal" case.)
2259 libmesh_error_msg_if(h_min < std::numeric_limits<Real>::epsilon(),
2260 "Coincident nodes detected on source and/or target "
2261 "surface, stitching meshes is not possible.");
2262
2263 // We require nanoflann for the "binary search" (really kd-tree)
2264 // option to work. If it's not available, turn that option off,
2265 // warn the user, and fall back on the N^2 search algorithm.
2266 if (use_binary_search)
2267 {
2268#ifndef LIBMESH_HAVE_NANOFLANN
2269 use_binary_search = false;
2270 libmesh_warning("The use_binary_search option in the "
2271 "UnstructuredMesh stitching algorithms requires nanoflann "
2272 "support. Falling back on N^2 search algorithm.");
2273#endif
2274 }
2275
2276 if (!this_boundary_node_ids.empty())
2277 {
2278 if (use_binary_search)
2279 {
2280#ifdef LIBMESH_HAVE_NANOFLANN
2281 typedef nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<Real, VectorOfNodesAdaptor>,
2282 VectorOfNodesAdaptor, 3, std::size_t> kd_tree_t;
2283
2284 // Create the dataset needed to build the kd tree with nanoflann
2285 std::vector<std::pair<Point, dof_id_type>> this_mesh_nodes(this_boundary_node_ids.size());
2286
2287 for (auto [it, ctr] = std::make_tuple(this_boundary_node_ids.begin(), 0u);
2288 it != this_boundary_node_ids.end(); ++it, ++ctr)
2289 {
2290 this_mesh_nodes[ctr].first = this->point(*it);
2291 this_mesh_nodes[ctr].second = *it;
2292 }
2293
2294 VectorOfNodesAdaptor vec_nodes_adaptor(this_mesh_nodes);
2295
2296 kd_tree_t this_kd_tree(3, vec_nodes_adaptor, 10);
2297 this_kd_tree.buildIndex();
2298
2299 // Storage for nearest neighbor in the loop below
2300 std::size_t ret_index;
2301 Real ret_dist_sqr;
2302
2303 // Loop over other mesh. For each node, find its nearest neighbor in this mesh, and fill in the maps.
2304 for (const auto & node_id : other_boundary_node_ids)
2305 {
2306 const auto & p = other_mesh->point(node_id);
2307 const Real query_pt[] = {p(0), p(1), p(2)};
2308 this_kd_tree.knnSearch(&query_pt[0], 1, &ret_index, &ret_dist_sqr);
2309
2310 // TODO: here we should use the user's specified tolerance
2311 // and the previously determined value of h_min in the
2312 // distance comparison, not just TOLERANCE^2.
2313 if (ret_dist_sqr < TOLERANCE*TOLERANCE)
2314 {
2315 node_to_node_map[this_mesh_nodes[ret_index].second] = node_id;
2316 other_to_this_node_map[node_id] = this_mesh_nodes[ret_index].second;
2317 }
2318 }
2319
2320 // If the two maps don't have the same size, it means one
2321 // node in this mesh is the nearest neighbor of several
2322 // nodes in other mesh. Since the stitching is ambiguous in
2323 // this case, we throw an error.
2324 libmesh_error_msg_if(node_to_node_map.size() != other_to_this_node_map.size(),
2325 "Error: Found multiple matching nodes in stitch_meshes");
2326#endif
2327 }
2328 else // !use_binary_search
2329 {
2330 // In the unlikely event that two meshes composed entirely of
2331 // NodeElems are being stitched together, we will not have
2332 // selected a valid h_min value yet, and the distance
2333 // comparison below will be true for essentially any two
2334 // nodes. In this case we simply fall back on an absolute
2335 // distance check.
2336 if (!h_min_updated)
2337 {
2338 libmesh_warning("No valid h_min value was found, falling back on "
2339 "absolute distance check in the N^2 search algorithm.");
2340 h_min = 1.;
2341 }
2342
2343 // Otherwise, use a simple N^2 search to find the closest matching points. This can be helpful
2344 // in the case that we have tolerance issues which cause mismatch between the two surfaces
2345 // that are being stitched.
2346 for (const auto & this_node_id : this_boundary_node_ids)
2347 {
2348 Node & this_node = this->node_ref(this_node_id);
2349
2350 bool found_matching_nodes = false;
2351
2352 for (const auto & other_node_id : other_boundary_node_ids)
2353 {
2354 const Node & other_node = other_mesh->node_ref(other_node_id);
2355
2356 Real node_distance = (this_node - other_node).norm();
2357
2358 if (node_distance < tol*h_min)
2359 {
2360 // Make sure we didn't already find a matching node!
2361 libmesh_error_msg_if(found_matching_nodes,
2362 "Error: Found multiple matching nodes in stitch_meshes");
2363
2364 node_to_node_map[this_node_id] = other_node_id;
2365 other_to_this_node_map[other_node_id] = this_node_id;
2366
2367 found_matching_nodes = true;
2368 }
2369 }
2370 }
2371 }
2372 }
2373
2374 // Build up the node_to_elems_map, using only one loop over other_mesh
2375 for (auto & el : other_mesh->element_ptr_range())
2376 {
2377 // For each node on the element, find the corresponding node
2378 // on "this" Mesh, 'this_node_id', if it exists, and push
2379 // the current element ID back onto node_to_elems_map[this_node_id].
2380 // For that we will use the reverse mapping we created at
2381 // the same time as the forward mapping.
2382 for (auto & n : el->node_ref_range())
2383 if (const auto it = other_to_this_node_map.find(/*other_node_id=*/n.id());
2384 it != other_to_this_node_map.end())
2385 node_to_elems_map[/*this_node_id=*/it->second].push_back( el->id() );
2386 }
2387
2388 if (verbose)
2389 {
2390 libMesh::out << "In UnstructuredMesh::stitch_meshes:\n"
2391 << "Found " << node_to_node_map.size()
2392 << " matching nodes.\n"
2393 << std::endl;
2394 }
2395
2396 if (enforce_all_nodes_match_on_boundaries)
2397 {
2398 std::size_t n_matching_nodes = node_to_node_map.size();
2399 std::size_t this_mesh_n_nodes = this_boundary_node_ids.size();
2400 std::size_t other_mesh_n_nodes = other_boundary_node_ids.size();
2401 libmesh_error_msg_if((n_matching_nodes != this_mesh_n_nodes) || (n_matching_nodes != other_mesh_n_nodes),
2402 "Error: We expected the number of nodes to match.");
2403 }
2404
2405 if (merge_boundary_nodes_all_or_nothing)
2406 {
2407 std::size_t n_matching_nodes = node_to_node_map.size();
2408 std::size_t this_mesh_n_nodes = this_boundary_node_ids.size();
2409 std::size_t other_mesh_n_nodes = other_boundary_node_ids.size();
2410 if ((n_matching_nodes != this_mesh_n_nodes) || (n_matching_nodes != other_mesh_n_nodes))
2411 {
2412 if (verbose)
2413 {
2414 libMesh::out << "Skipping node merging in "
2415 "UnstructuredMesh::stitch_meshes because not "
2416 "all boundary nodes were matched."
2417 << std::endl;
2418 }
2419 node_to_node_map.clear();
2420 other_to_this_node_map.clear();
2421 node_to_elems_map.clear();
2422 }
2423 }
2424 }
2425 else
2426 {
2427 if (verbose)
2428 {
2429 libMesh::out << "Skip node merging in UnstructuredMesh::stitch_meshes:" << std::endl;
2430 }
2431 }
2432
2433 dof_id_type node_delta = this->max_node_id();
2434 dof_id_type elem_delta = this->max_elem_id();
2435
2436 unique_id_type unique_delta =
2437#ifdef LIBMESH_ENABLE_UNIQUE_ID
2438 this->parallel_max_unique_id();
2439#else
2440 0;
2441#endif
2442
2443 // If other_mesh != nullptr, then we have to do a bunch of work
2444 // in order to copy it to this mesh
2445 if (this!=other_mesh)
2446 {
2447 LOG_SCOPE("stitch_meshes copying", "UnstructuredMesh");
2448
2449#ifdef LIBMESH_ENABLE_PERIODIC
2450 // Copy disjoint neighbor boundary pairs (PeriodicBoundary objects)
2451 // from `other_mesh` to `this` mesh
2452 if (other_db && !other_db->empty())
2453 {
2454 for (const auto & [bdy_id, pb_ptr] : *other_db)
2455 {
2456 const auto & pb = *pb_ptr;
2457 const boundary_id_type a = pb.myboundary;
2458 const boundary_id_type b = pb.pairedboundary;
2459
2460 if (this_db)
2461 {
2462 // Skip if identical pair already exists
2463 if (const auto * existing_pb = this_db->boundary(a))
2464 if ((existing_pb->myboundary == a && existing_pb->pairedboundary == b) ||
2465 (existing_pb->myboundary == b && existing_pb->pairedboundary == a))
2466 continue;
2467
2468 // If both boundary ids exist on this mesh but aren't paired here, refuse to create a new pair
2469 const auto & bdy_ids = this->get_boundary_info().get_boundary_ids();
2470 const bool a_exists = bdy_ids.count(a);
2471 const bool b_exists = bdy_ids.count(b);
2472 // If a and b already exist on `this`, we should be screaming and dying
2473 // unless they already have PeriodicBoundary objects connecting them too
2474 if (a_exists && b_exists && !this_db->boundary(a))
2475 libmesh_error_msg("Conflict: boundaries " << a << " and " << b
2476 << " already exist on this mesh but are not paired.");
2477 }
2478
2479 this->add_disjoint_neighbor_boundary_pairs(a, b, pb.get_corresponding_pos(Point(0.0,0.0,0.0)));
2480 }
2481 }
2482#endif // LIBMESH_ENABLE_PERIODIC
2483
2484
2485 // Increment the node_to_node_map and node_to_elems_map
2486 // to account for id offsets
2487 for (auto & pr : node_to_node_map)
2488 pr.second += node_delta;
2489
2490 for (auto & pr : node_to_elems_map)
2491 for (auto & entry : pr.second)
2492 entry += elem_delta;
2493
2494 // We run into problems when the libMesh subdomain standard (the
2495 // id defines the subdomain; the name was an afterthought) and
2496 // the MOOSE standard (the name defines the subdomain; the id
2497 // might be autogenerated) clash.
2498 //
2499 // Subdomain ids with the same name in both meshes are surely
2500 // meant to represent the same subdomain. We can just merge
2501 // them.
2502 //
2503 // Subdomain ids which don't have a name in either mesh are
2504 // almost surely meant to represent the same subdomain. We'll
2505 // just merge them.
2506 //
2507 // Subdomain ids with different names in different meshes, or
2508 // names with different ids in different meshes, are trickier.
2509 // For backwards compatibility we default to the old "just copy
2510 // all the subdomain ids over" behavior, but if requested we'll
2511 // remap any ids that appear to be clear conflicts, and we'll
2512 // scream and die if we see any ids that are ambiguous due to
2513 // being named in one mesh but not the other.
2514 std::unordered_map<subdomain_id_type, subdomain_id_type> id_remapping;
2515 if (remap_subdomain_ids)
2516 {
2517 const auto & this_map = this->get_subdomain_name_map();
2518 const auto & other_map = other_mesh->get_subdomain_name_map();
2519 std::unordered_map<std::string, subdomain_id_type> other_map_reversed;
2520 for (auto & [sid, sname] : other_map)
2521 other_map_reversed.emplace(sname, sid);
2522
2523 std::unordered_map<std::string, subdomain_id_type> this_map_reversed;
2524 for (auto & [sid, sname] : this_map)
2525 this_map_reversed.emplace(sname, sid);
2526
2527 // We don't require either mesh to be prepared, but that
2528 // means we need to check for subdomains manually.
2529 auto get_subdomains = [](const MeshBase & mesh) {
2530 std::set<subdomain_id_type> all_subdomains;
2531 for (auto & el : mesh.element_ptr_range())
2532 all_subdomains.insert(el->subdomain_id());
2533 return all_subdomains;
2534 };
2535
2536 const auto this_subdomains = get_subdomains(*this);
2537 const auto other_subdomains = get_subdomains(*other_mesh);
2538
2539 for (auto & [sid, sname] : this_map)
2540 {
2541 // The same name with the same id means we're fine. The
2542 // same name with another id means we remap their id to
2543 // ours
2544 if (const auto other_reverse_it = other_map_reversed.find(sname);
2545 other_reverse_it != other_map_reversed.end() && other_reverse_it->second != sid)
2546 id_remapping[other_reverse_it->second] = sid;
2547
2548 // The same id with a different name, we'll get to
2549 // later. The same id without any name means we don't
2550 // know what the user wants.
2551 if (other_subdomains.count(sid) && !other_map.count(sid))
2552 libmesh_error_msg("Can't safely stitch with a mesh sharing subdomain id "
2553 << sid << " but not subdomain name " << sname);
2554 }
2555
2556 subdomain_id_type next_free_id = 0;
2557 // We might try to stitch empty meshes ...
2558 if (!this_subdomains.empty())
2559 next_free_id = *this_subdomains.rbegin() + 1;
2560 if (!other_subdomains.empty())
2561 next_free_id =
2562 std::max(next_free_id,
2563 cast_int<subdomain_id_type>
2564 (*other_subdomains.rbegin() + 1));
2565
2566 for (auto & [sid, sname] : other_map)
2567 {
2568 // At this point we've figured out any remapping
2569 // necessary for an sname that we share. And we don't
2570 // need to remap any sid we don't share.
2571 if (!this_map_reversed.count(sname))
2572 {
2573 // But if we don't have this sname and we do have this
2574 // sid then we can't just merge into that.
2575 if (this_subdomains.count(sid))
2576 {
2577 // If we have this sid with no name, we don't
2578 // know what the user wants.
2579 if (!this_map.count(sid))
2580 libmesh_error_msg("Can't safely stitch with a mesh sharing subdomain id "
2581 << sid << " but under subdomain name " << sname);
2582
2583 // We have this sid under a different name, so
2584 // we just need to give the other elements a new
2585 // id.
2586
2587 // Users might have done crazy things with id
2588 // choice so let's make sure they didn't get too
2589 // crazy.
2590 libmesh_error_msg_if ((!this_subdomains.empty() &&
2591 next_free_id < *this_subdomains.rbegin()) ||
2592 (!other_subdomains.empty() &&
2593 next_free_id < *other_subdomains.rbegin()),
2594 "Subdomain id overflow");
2595
2596 id_remapping[sid] = next_free_id++;
2597 this->set_subdomain_name(next_free_id, sname);
2598 }
2599 // If we don't have this subdomain id, well, we're
2600 // about to, so we should have its name too.
2601 else
2602 this->set_subdomain_name(sid, sname);
2603 }
2604 }
2605 }
2606
2607 // Copy mesh data. If we skip the call to find_neighbors(), the lists
2608 // of neighbors will be copied verbatim from the other mesh
2609 this->copy_nodes_and_elements(*other_mesh, skip_find_neighbors,
2610 elem_delta, node_delta,
2611 unique_delta, &id_remapping);
2612
2613 // Copy BoundaryInfo from other_mesh too. We do this via the
2614 // list APIs rather than element-by-element for speed.
2615 BoundaryInfo & boundary = this->get_boundary_info();
2616 const BoundaryInfo & other_boundary = other_mesh->get_boundary_info();
2617
2618 for (const auto & t : other_boundary.build_node_list())
2619 boundary.add_node(std::get<0>(t) + node_delta,
2620 std::get<1>(t));
2621
2622 for (const auto & t : other_boundary.build_side_list())
2623 boundary.add_side(std::get<0>(t) + elem_delta,
2624 std::get<1>(t),
2625 std::get<2>(t));
2626
2627 for (const auto & t : other_boundary.build_edge_list())
2628 boundary.add_edge(std::get<0>(t) + elem_delta,
2629 std::get<1>(t),
2630 std::get<2>(t));
2631
2632 for (const auto & t : other_boundary.build_shellface_list())
2633 boundary.add_shellface(std::get<0>(t) + elem_delta,
2634 std::get<1>(t),
2635 std::get<2>(t));
2636
2637 const auto & other_ns_id_to_name = other_boundary.get_nodeset_name_map();
2638 auto & ns_id_to_name = boundary.set_nodeset_name_map();
2639 ns_id_to_name.insert(other_ns_id_to_name.begin(), other_ns_id_to_name.end());
2640
2641 const auto & other_ss_id_to_name = other_boundary.get_sideset_name_map();
2642 auto & ss_id_to_name = boundary.set_sideset_name_map();
2643 ss_id_to_name.insert(other_ss_id_to_name.begin(), other_ss_id_to_name.end());
2644
2645 const auto & other_es_id_to_name = other_boundary.get_edgeset_name_map();
2646 auto & es_id_to_name = boundary.set_edgeset_name_map();
2647 es_id_to_name.insert(other_es_id_to_name.begin(), other_es_id_to_name.end());
2648
2649 // Merge other_mesh's elemset information with ours. Throw an
2650 // error if this and other_mesh have overlapping elemset codes
2651 // that refer to different elemset ids.
2652 std::vector<dof_id_type> this_elemset_codes = this->get_elemset_codes();
2653 MeshBase::elemset_type this_id_set_to_fill, other_id_set_to_fill;
2654 for (const auto & elemset_code : other_mesh->get_elemset_codes())
2655 {
2656 // Get the elemset ids for this elemset_code on other_mesh
2657 other_mesh->get_elemsets(elemset_code, other_id_set_to_fill);
2658
2659 // Check that this elemset code does not already exist
2660 // in this mesh, or if it does, that it has the same elemset
2661 // ids associated with it.
2662 //
2663 // Note: get_elemset_codes() is guaranteed to return a
2664 // sorted vector, so we can binary search in it.
2665 auto it = Utility::binary_find(this_elemset_codes.begin(),
2666 this_elemset_codes.end(),
2667 elemset_code);
2668
2669 if (it != this_elemset_codes.end())
2670 {
2671 // This mesh has the same elemset code. Does it refer to
2672 // the same elemset ids?
2673 this->get_elemsets(elemset_code, this_id_set_to_fill);
2674
2675 // Throw an error if they don't match, otherwise we
2676 // don't need to do anything
2677 libmesh_error_msg_if(other_id_set_to_fill != this_id_set_to_fill,
2678 "Attempted to stitch together meshes with conflicting elemset codes.");
2679 }
2680 else
2681 {
2682 // Add other_mesh's elemset code to this mesh
2683 this->add_elemset_code(elemset_code, other_id_set_to_fill);
2684 }
2685 }
2686
2687 } // end if (other_mesh)
2688
2689 // Finally, we need to "merge" the overlapping nodes
2690 // We do this by iterating over node_to_elems_map and updating
2691 // the elements so that they "point" to the nodes that came
2692 // from this mesh, rather than from other_mesh.
2693 // Then we iterate over node_to_node_map and delete the
2694 // duplicate nodes that came from other_mesh.
2695
2696 {
2697 LOG_SCOPE("stitch_meshes node updates", "UnstructuredMesh");
2698
2699 // Container to catch boundary IDs passed back from BoundaryInfo.
2700 std::vector<boundary_id_type> bc_ids;
2701
2702 for (const auto & [target_node_id, elem_vec] : node_to_elems_map)
2703 {
2704 dof_id_type other_node_id = node_to_node_map[target_node_id];
2705 Node & target_node = this->node_ref(target_node_id);
2706
2707 std::size_t n_elems = elem_vec.size();
2708 for (std::size_t i=0; i<n_elems; i++)
2709 {
2710 dof_id_type elem_id = elem_vec[i];
2711 Elem * el = this->elem_ptr(elem_id);
2712
2713 // find the local node index that we want to update
2714 unsigned int local_node_index = el->local_node(other_node_id);
2715 libmesh_assert_not_equal_to(local_node_index, libMesh::invalid_uint);
2716
2717 // We also need to copy over the nodeset info here,
2718 // because the node will get deleted below
2719 this->get_boundary_info().boundary_ids(el->node_ptr(local_node_index), bc_ids);
2720 el->set_node(local_node_index, &target_node);
2721 this->get_boundary_info().add_node(&target_node, bc_ids);
2722 }
2723 }
2724 }
2725
2726 {
2727 LOG_SCOPE("stitch_meshes node deletion", "UnstructuredMesh");
2728 for (const auto & [other_node_id, this_node_id] : node_to_node_map)
2729 {
2730 // In the case that this==other_mesh, the two nodes might be the same (e.g. if
2731 // we're stitching a "sliver"), hence we need to skip node deletion in that case.
2732 if ((this == other_mesh) && (this_node_id == other_node_id))
2733 continue;
2734
2735 this->delete_node( this->node_ptr(this_node_id) );
2736 }
2737 }
2738
2739 // If find_neighbors() wasn't called in prepare_for_use(), we need to
2740 // manually loop once more over all elements adjacent to the stitched boundary
2741 // and fix their lists of neighbors.
2742 // This is done according to the following steps:
2743 // 1. Loop over all copied elements adjacent to the boundary using node_to_elems_map (trying to avoid duplicates)
2744 // 2. Look at all their sides with a nullptr neighbor and update them using side_to_elem_map if necessary
2745 // 3. Update the corresponding side in side_to_elem_map as well
2746 if (skip_find_neighbors)
2747 {
2748 LOG_SCOPE("stitch_meshes neighbor fixes", "UnstructuredMesh");
2749
2750 // Pull objects out of the loop to reduce heap operations
2751 std::unique_ptr<const Elem> my_side, their_side;
2752
2753 std::set<dof_id_type> fixed_elems;
2754 for (const auto & pr : node_to_elems_map)
2755 {
2756 std::size_t n_elems = pr.second.size();
2757 for (std::size_t i=0; i<n_elems; i++)
2758 {
2759 dof_id_type elem_id = pr.second[i];
2760 if (!fixed_elems.count(elem_id))
2761 {
2762 Elem * el = this->elem_ptr(elem_id);
2763 fixed_elems.insert(elem_id);
2764 for (auto s : el->side_index_range())
2765 {
2766 bool has_real_neighbor = (el->neighbor_ptr(s) != nullptr);
2767 bool has_disdjoint_neighbor = is_valid_disjoint_pair_to_stitch &&
2768 (this->get_boundary_info().has_boundary_id(el, s, this_mesh_boundary_id)
2769 || this->get_boundary_info().has_boundary_id(el, s, other_mesh_boundary_id));
2770
2771 if (!has_real_neighbor || has_disdjoint_neighbor)
2772 {
2773 key_type key = el->low_order_key(s);
2774 auto bounds = side_to_elem_map.equal_range(key);
2775
2776 if (bounds.first != bounds.second)
2777 {
2778 // Get the side for this element
2779 el->side_ptr(my_side, s);
2780
2781 // Look at all the entries with an equivalent key
2782 while (bounds.first != bounds.second)
2783 {
2784 // Get the potential element
2785 Elem * neighbor = const_cast<Elem *>(bounds.first->second.first);
2786
2787 // Get the side for the neighboring element
2788 const unsigned int ns = bounds.first->second.second;
2789 neighbor->side_ptr(their_side, ns);
2790 //libmesh_assert(my_side.get());
2791 //libmesh_assert(their_side.get());
2792
2793 // If found a match with my side
2794 //
2795 // We need special tests here for 1D:
2796 // since parents and children have an equal
2797 // side (i.e. a node), we need to check
2798 // ns != ms, and we also check level() to
2799 // avoid setting our neighbor pointer to
2800 // any of our neighbor's descendants
2801 if ((*my_side == *their_side) &&
2802 (el->level() == neighbor->level()) &&
2803 ((el->dim() != 1) || (ns != s)))
2804 {
2805 // So share a side. Is this a mixed pair
2806 // of subactive and active/ancestor
2807 // elements?
2808 // If not, then we're neighbors.
2809 // If so, then the subactive's neighbor is
2810
2811 if (el->subactive() ==
2812 neighbor->subactive())
2813 {
2814 // an element is only subactive if it has
2815 // been coarsened but not deleted
2816 el->set_neighbor (s,neighbor);
2817 neighbor->set_neighbor(ns,el);
2818 }
2819 else if (el->subactive())
2820 {
2821 el->set_neighbor(s,neighbor);
2822 }
2823 else if (neighbor->subactive())
2824 {
2825 neighbor->set_neighbor(ns,el);
2826 }
2827 // It's OK to invalidate the
2828 // bounds.first iterator here,
2829 // as we are immediately going
2830 // to break out of this while
2831 // loop. bounds.first will
2832 // therefore not be used for
2833 // anything else.
2834 side_to_elem_map.erase (bounds.first);
2835 break;
2836 }
2837
2838 ++bounds.first;
2839 }
2840 }
2841 }
2842 }
2843 }
2844 }
2845 }
2846 }
2847
2848#ifdef LIBMESH_ENABLE_PERIODIC
2849 // Remove only the disjoint pair that was actually stitched.
2850 // Safe because `is_valid_disjoint_pair_to_stitch` is true
2851 // only if this exact (a,b) pair exists in the registry.
2852 // Other disjoint pairs remain untouched.
2853 if (is_valid_disjoint_pair_to_stitch)
2854 this->remove_disjoint_boundary_pair(this_mesh_boundary_id, other_mesh_boundary_id);
2855#endif
2856
2857 if (prepare_after_stitching)
2858 {
2859 // We set our new neighbor pointers already
2860 const bool old_allow_find_neighbors = this->allow_find_neighbors();
2861 this->allow_find_neighbors(!skip_find_neighbors);
2862
2863 // We haven't newly remoted any elements
2864 const bool old_allow_remote_element_removal = this->allow_remote_element_removal();
2865 this->allow_remote_element_removal(false);
2866
2867 this->prepare_for_use();
2868
2869 this->allow_find_neighbors(old_allow_find_neighbors);
2870 this->allow_remote_element_removal(old_allow_remote_element_removal);
2871 }
2872
2873 // After the stitching, we may want to clear boundary IDs from element
2874 // faces that are now internal to the mesh
2875 if (clear_stitched_boundary_ids)
2876 {
2877 LOG_SCOPE("stitch_meshes clear bcids", "UnstructuredMesh");
2878
2880 this_mesh_boundary_id, other_mesh_boundary_id, /*clear_nodeset_data=*/true);
2881 }
2882
2883 // Return the number of nodes which were merged.
2884 return node_to_node_map.size();
2885}
2886
2887
2888} // namespace libMesh
unsigned int dim
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
timpi_pure bool verify(const T &r) const
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void add_shellface(const dof_id_type elem, const unsigned short int shellface, const boundary_id_type id)
Add shell face shellface of element number elem with boundary id id to the boundary information data ...
void add_edge(const dof_id_type elem, const unsigned short int edge, const boundary_id_type id)
Add edge edge of element number elem with boundary id id to the boundary information data structure.
std::vector< BCTuple > build_side_list(BCTupleSortBy sort_by=BCTupleSortBy::ELEM_ID) const
std::vector< NodeBCTuple > build_node_list(NodeBCTupleSortBy sort_by=NodeBCTupleSortBy::NODE_ID) const
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
void edge_boundary_ids(const Elem *const elem, const unsigned short int edge, std::vector< boundary_id_type > &vec_to_fill) const
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
Fills a user-provided std::vector with the boundary ids associated with Node node.
void clear_stitched_boundary_side_ids(boundary_id_type sideset_id, boundary_id_type other_sideset_id, bool clear_nodeset_data=false)
Clear sideset information along a stitched mesh interface.
std::map< boundary_id_type, std::string > & set_sideset_name_map()
std::vector< BCTuple > build_shellface_list() const
Create a list of (element_id, shellface_id, boundary_id) tuples for all relevant shellfaces.
void copy_boundary_ids(const BoundaryInfo &old_boundary_info, const Elem *const old_elem, const Elem *const new_elem)
const std::set< boundary_id_type > & get_boundary_ids() const
const std::string & get_sideset_name(boundary_id_type id) const
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
static const boundary_id_type invalid_id
Number used for internal use.
std::map< boundary_id_type, std::string > & set_edgeset_name_map()
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
void regenerate_id_sets()
Clears and regenerates the cached sets of ids.
std::vector< BCTuple > build_edge_list() const
Create a list of (element_id, edge_id, boundary_id) tuples for all relevant edges.
const std::map< boundary_id_type, std::string > & get_edgeset_name_map() const
const std::map< boundary_id_type, std::string > & get_nodeset_name_map() const
std::map< boundary_id_type, std::string > & set_nodeset_name_map()
const std::map< boundary_id_type, std::string > & get_sideset_name_map() const
dof_id_type get_extra_integer(const unsigned int index) const
Gets the value on this object of the extra integer associated with index, which should have been obta...
unsigned int n_extra_integers() const
Returns how many extra integers are associated to the DofObject.
processor_id_type processor_id() const
Definition dof_object.h:895
dof_id_type & set_id()
Definition dof_object.h:841
void add_extra_integers(const unsigned int n_integers)
Assigns a set of extra integers to this DofObject.
Definition dof_object.C:482
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
unique_id_type unique_id() const
Definition dof_object.h:849
dof_id_type id() const
Definition dof_object.h:833
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition dof_object.h:484
void set_unique_id(unique_id_type new_id)
Sets the unique_id for this DofObject.
Definition dof_object.h:862
void set_extra_integer(const unsigned int index, const dof_id_type value)
Sets the value on this object of the extra integer associated with index, which should have been obta...
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual Node *& set_node(const unsigned int i)
Definition elem.h:2688
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
Definition elem.h:3372
SimpleRange< NeighborPtrIter > neighbor_ptr_range()
Returns a range with all neighbors of an element, usable in range-based for loops.
Definition elem.h:3641
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const =0
bool active() const
Definition elem.h:3079
bool is_ancestor_of(const Elem *descendant) const
Definition elem.h:3147
virtual unsigned int n_vertices() const =0
bool has_children() const
Definition elem.h:3117
virtual std::unique_ptr< Elem > side_ptr(unsigned int i)=0
virtual unsigned int n_nodes() const =0
const Elem * parent() const
Definition elem.h:3168
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
Definition elem.h:2756
static ElemType complete_order_equivalent_type(const ElemType et)
Definition elem.C:3755
const Elem * child_ptr(unsigned int i) const
Definition elem.h:3301
bool ancestor() const
Definition elem.C:2121
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition elem.h:3057
virtual dof_id_type low_order_key(const unsigned int s) const =0
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition elem.C:382
void set_interior_parent(Elem *p)
Sets the pointer to the element's interior_parent.
Definition elem.C:1162
static ElemType first_order_equivalent_type(const ElemType et)
Definition elem.C:3201
virtual unsigned int n_second_order_adjacent_vertices(const unsigned int n) const
Definition elem.C:3175
unsigned int local_node(const dof_id_type i) const
Definition elem.h:2617
unsigned int which_child_am_i(const Elem *e) const
Definition elem.h:3330
virtual Real hmin() const
Definition elem.C:623
static ElemType second_order_equivalent_type(const ElemType et, const bool full_ordered=true)
Definition elem.C:3571
virtual unsigned short dim() const =0
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Definition elem.h:2476
unsigned int level() const
Definition elem.h:3212
virtual bool runtime_topology() const
Definition elem.h:254
void set_parent(Elem *p)
Sets the pointer to the element's parent.
Definition elem.h:3184
const Node * node_ptr(const unsigned int i) const
Definition elem.h:2637
void add_child(Elem *elem)
Adds a child pointer to the array of children of this element.
Definition elem.C:2155
void replace_child(Elem *elem, unsigned int c)
Replaces the child pointer at the specified index in the child array.
Definition elem.C:2201
virtual unsigned int n_children() const =0
virtual ElemType type() const =0
const Elem * interior_parent() const
Definition elem.C:1100
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition elem.h:3356
dof_id_type node_id(const unsigned int i) const
Definition elem.h:2605
bool subactive() const
Definition elem.h:3097
virtual unsigned short int second_order_adjacent_vertex(const unsigned int n, const unsigned int v) const
Definition elem.C:3183
void set_p_level(const unsigned int p)
Sets the value of the p-refinement level for the element.
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736
Point vertex_average() const
Definition elem.C:609
IntRange< unsigned short > side_index_range() const
Definition elem.h:2848
void inherit_data_from(const Elem &src)
A helper function for copying generic element data (mapping, subdomain, processor) from an element to...
Definition elem.h:3477
This class implements the original default geometry ghosting requirements in libMesh: point neighbors...
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
What elements do we care about and what variables do we care about on each element?
This is the MeshBase class.
Definition mesh_base.h:81
void set_subdomain_name(subdomain_id_type id, const std::string &name, bool synchronous=false)
Sets the name for the provided id.
Definition mesh_base.C:1929
virtual const Node & node_ref(const dof_id_type i) const
Definition mesh_base.h:742
virtual const Point & point(const dof_id_type i) const =0
virtual bool is_serial() const
Definition mesh_base.h:357
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
bool is_prepared() const
Definition mesh_base.C:1065
bool allow_renumbering() const
Definition mesh_base.h:1360
virtual const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
Definition mesh_base.C:435
virtual dof_id_type n_elem() const =0
virtual bool is_replicated() const
Definition mesh_base.h:379
virtual void own_node(Node &)
Takes ownership of node n on this partition of a distributed mesh, by setting n.processor_id() to thi...
Definition mesh_base.h:866
virtual Elem * insert_elem(Elem *e)=0
Insert elem e to the element array, preserving its id and replacing/deleting any existing element wit...
bool skip_partitioning() const
Definition mesh_base.h:1435
virtual void renumber_nodes_and_elements()=0
After partitioning a mesh it is useful to renumber the nodes and elements so that they lie in contigu...
bool allow_detect_interior_parents() const
Definition mesh_base.h:1374
void allow_find_neighbors(bool allow)
If false is passed then this mesh will no longer work to find element neighbors when being prepared f...
Definition mesh_base.h:1366
PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs()
Definition mesh_base.C:2311
const std::map< subdomain_id_type, std::string > & get_subdomain_name_map() const
Definition mesh_base.h:1930
virtual void delete_node(Node *n)=0
Removes the Node n from the mesh.
const ElemRange & element_stored_range()
Definition mesh_base.C:1954
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
Definition mesh_base.C:824
std::vector< dof_id_type > get_elemset_codes() const
Return a vector of all elemset codes defined on the mesh.
Definition mesh_base.C:508
virtual dof_id_type n_nodes() const =0
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
virtual dof_id_type max_node_id() const =0
virtual const Node * query_node_ptr(const dof_id_type i) const =0
GhostingFunctorIterator ghosting_functors_begin() const
Beginning of range of ghosting functors.
Definition mesh_base.h:1476
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
virtual const Elem * elem_ptr(const dof_id_type i) const =0
std::vector< std::string > _elem_integer_names
The array of names for integer data associated with each element in the mesh.
Definition mesh_base.h:2383
void prepare_for_use()
Definition mesh_base.C:860
unsigned int n_partitions() const
Definition mesh_base.h:1530
virtual void set_next_unique_id(unique_id_type id)=0
Sets the next available unique id to be used.
virtual dof_id_type max_elem_id() const =0
virtual void delete_remote_elements()
When supported, deletes all nonlocal elements of the mesh except for "ghosts" which touch a local ele...
Definition mesh_base.h:399
MeshBase * _interior_mesh
Defaulting to this, a pointer to the mesh used to generate boundary elements on this.
Definition mesh_base.h:2264
virtual void clear()
Deletes all the element and node data that is currently stored.
Definition mesh_base.C:1036
std::pair< std::vector< unsigned int >, std::vector< unsigned int > > merge_extra_integer_names(const MeshBase &other)
Merge extra-integer arrays from an other mesh.
Definition mesh_base.C:2400
const MeshBase & interior_mesh() const
Definition mesh_base.h:2053
void add_elemset_code(dof_id_type code, MeshBase::elemset_type id_set)
Tabulate a user-defined "code" for elements which belong to the element sets specified in id_set.
Definition mesh_base.C:461
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
bool allow_remote_element_removal() const
Definition mesh_base.h:1383
bool allow_find_neighbors() const
Definition mesh_base.h:1367
void get_elemsets(dof_id_type elemset_code, MeshBase::elemset_type &id_set_to_fill) const
Look up the element sets for a given elemset code and vice-versa.
Definition mesh_base.C:492
void remove_disjoint_boundary_pair(const boundary_id_type b1, const boundary_id_type b2)
Definition mesh_base.C:2321
void clear_point_locator()
Releases the current PointLocator object.
Definition mesh_base.C:1881
virtual void reserve_elem(const dof_id_type ne)=0
Reserves space for a known number of elements.
GhostingFunctorIterator ghosting_functors_end() const
End of range of ghosting functors.
Definition mesh_base.h:1482
std::set< elemset_id_type > elemset_type
Typedef for the "set" container used to store elemset ids.
Definition mesh_base.h:463
std::vector< std::string > _node_integer_names
The array of names for integer data associated with each node in the mesh.
Definition mesh_base.h:2395
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition mesh_base.C:1848
void add_disjoint_neighbor_boundary_pairs(const boundary_id_type b1, const boundary_id_type b2, const RealVectorValue &translation)
Register a pair of boundaries as disjoint neighbor boundary pairs.
Definition mesh_base.C:2287
virtual void update_parallel_id_counts()=0
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors.
Preparation _preparation
Flags indicating in what ways this mesh has been prepared.
Definition mesh_base.h:2207
void set_interior_mesh(MeshBase &int_mesh)
Sets the interior mesh.
Definition mesh_base.h:2063
void allow_detect_interior_parents(bool allow)
If false is passed then this mesh will no longer work to detect interior parents when being prepared ...
Definition mesh_base.h:1373
virtual void reserve_nodes(const dof_id_type nn)=0
Reserves space for a known number of nodes.
void unset_is_prepared()
Tells this we have done some operation where we should no longer consider ourself prepared.
Definition mesh_base.C:1071
virtual unique_id_type parallel_max_unique_id() const =0
This is the MeshCommunication class.
void make_nodes_parallel_consistent(MeshBase &)
Copy processor_ids and ids on ghost nodes from their local processors.
Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.
This class supports simple reads and writes in any libMesh-supported format, by dispatching to one of...
virtual void read(const std::string &mesh_file) override
This method implements reading a mesh from a specified file.
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
virtual void write(const std::string &mesh_file) override
This method implements writing a mesh to a specified file.
A Node is like a Point, but with more information.
Definition node.h:55
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
static void set_node_processor_ids(MeshBase &mesh)
This function is called after partitioning to set the processor IDs for the nodes.
We're using a class instead of a typedef to allow forward declarations and future flexibility.
PeriodicBoundaryBase * boundary(boundary_id_type id)
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
In parallel meshes where a ghost element has neighbors which do not exist on the local processor,...
Definition remote_elem.h:61
The SimpleRange templated class is intended to make it easy to construct ranges from pairs of iterato...
IndexType end() const
IndexType begin() const
The StoredRange class defines a contiguous, divisible set of objects.
The UnstructuredMesh class is derived from the MeshBase class.
virtual void all_second_order_range(const SimpleRange< element_iterator > &range, const bool full_ordered=true) override
Converts a (conforming, non-refined) mesh with linear elements into a mesh with second-order elements...
virtual void all_first_order() override
Converts a mesh with higher-order elements into a mesh with linear elements.
void create_pid_mesh(UnstructuredMesh &pid_mesh, const processor_id_type pid) const
Generates a new mesh containing all the elements which are assigned to processor pid.
virtual void copy_nodes_and_elements(const MeshBase &other_mesh, const bool skip_find_neighbors=false, dof_id_type element_id_offset=0, dof_id_type node_id_offset=0, unique_id_type unique_id_offset=0, std::unordered_map< subdomain_id_type, subdomain_id_type > *id_remapping=nullptr, const bool skip_preparation=false)
Deep copy of nodes and elements from another mesh object (used by subclass copy constructors and by m...
virtual void write(const std::string &name) const override
Write the file specified by name.
std::size_t stitch_meshes(const MeshBase &other_mesh, boundary_id_type this_mesh_boundary, boundary_id_type other_mesh_boundary, Real tol=TOLERANCE, bool clear_stitched_boundary_ids=false, bool verbose=true, bool use_binary_search=true, bool enforce_all_nodes_match_on_boundaries=false, bool merge_boundary_nodes_all_or_nothing=false, bool remap_subdomain_ids=false, bool prepare_after_stitching=true)
Stitch other_mesh to this mesh so that this mesh is the union of the two meshes.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false) override
Reads the file specified by name.
virtual void all_complete_order_range(const SimpleRange< element_iterator > &range) override
Converts a (conforming, non-refined) mesh with linear elements into a mesh with "complete" order elem...
virtual bool contract() override
Delete subactive (i.e.
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true, const bool assert_valid=true, const bool check_non_remote=true) override
Other functions from MeshBase requiring re-definition.
std::size_t stitching_helper(const MeshBase *other_mesh, boundary_id_type boundary_id_1, boundary_id_type boundary_id_2, Real tol, bool clear_stitched_boundary_ids, bool verbose, bool use_binary_search, bool enforce_all_nodes_match_on_boundaries, bool skip_find_neighbors, bool merge_boundary_nodes_all_or_nothing, bool remap_subdomain_ids, bool prepare_after_stitching)
Helper function for stitch_meshes and stitch_surfaces that does the mesh stitching.
void create_submesh(UnstructuredMesh &new_mesh, const const_element_iterator &it, const const_element_iterator &it_end) const
Constructs a mesh called "new_mesh" from the current mesh by iterating over the elements between it a...
UnstructuredMesh(const Parallel::Communicator &comm_in, unsigned char dim=1)
Constructor.
virtual ~UnstructuredMesh()
Destructor.
std::size_t stitch_surfaces(boundary_id_type boundary_id_1, boundary_id_type boundary_id_2, Real tol=TOLERANCE, bool clear_stitched_boundary_ids=false, bool verbose=true, bool use_binary_search=true, bool enforce_all_nodes_match_on_boundaries=false, bool merge_boundary_nodes_all_or_nothing=false, bool prepare_after_stitching=true)
Similar to stitch_meshes, except that we stitch two adjacent surfaces within this mesh.
Real kdtree_get_pt(const size_t idx, int dim) const
size_t kdtree_get_point_count() const
Must return the number of data points.
VectorOfNodesAdaptor(const std::vector< std::pair< Point, dof_id_type > > &nodes)
const std::vector< std::pair< Point, dof_id_type > > _nodes
static const Real b
MeshBase & mesh
void libmesh_assert_valid_neighbors(const MeshBase &mesh, bool assert_valid_remote_elems=true)
A function for verifying that neighbor connectivity is correct (each element is a neighbor of or desc...
void libmesh_assert_valid_amr_interior_parents(const MeshBase &mesh)
A function for verifying that any interior_parent pointers on elements are consistent with AMR (paren...
void libmesh_assert_valid_amr_elem_ids(const MeshBase &mesh)
A function for verifying that ids of elements are correctly sorted for AMR (parents have lower ids th...
unsigned int n_levels(const MeshBase &mesh)
Definition mesh_tools.C:826
void libmesh_assert_parallel_consistent_procids< Node >(const MeshBase &mesh)
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
ForwardIterator binary_find(ForwardIterator first, ForwardIterator last, const T &value)
The STL provides std::binary_search() which returns true or false depending on whether the searched-f...
Definition utility.h:233
bool ends_with(std::string_view superstring, std::string_view suffix)
Look for a substring at the very end of a string.
Definition utility.C:213
The libMesh namespace provides an interface to certain functionality in the library.
OStreamProxy err
uint8_t unique_id_type
Definition id_types.h:86
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
bool closed()
Checks that the library has been closed.
Definition libmesh.C:331
ElemType
Defines an enum for geometric element types.
int8_t boundary_id_type
Definition id_types.h:51
void libmesh_ignore(const Args &...)
libmesh_assert(ctx)
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303
OStreamProxy out
const RemoteElem * remote_elem
Definition remote_elem.C:57
bool initialized()
Checks that library initialization has been done.
Definition libmesh.C:324
static constexpr Real TOLERANCE
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176
const boundary_id_type side_id
The definition of the const_element_iterator struct.
Definition mesh_base.h:2575
const dof_id_type n_nodes
Definition tecplot_io.C:67