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"
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"
40#ifdef LIBMESH_HAVE_NANOFLANN
41#include "libmesh/nanoflann.hpp"
51#include <unordered_map>
54#include "libmesh/periodic_boundaries.h"
55#include "libmesh/periodic_boundary.h"
63std::map<std::vector<dof_id_type>,
Node *>::iterator
64map_hi_order_node(
unsigned int hon,
66 std::map<std::vector<dof_id_type>,
Node *> & adj_vertices_to_ho_nodes)
73 const unsigned int n_adjacent_vertices =
76 std::vector<dof_id_type> adjacent_vertices_ids(n_adjacent_vertices);
78 for (
unsigned int v=0; v<n_adjacent_vertices; v++)
79 adjacent_vertices_ids[v] =
88 std::sort(adjacent_vertices_ids.begin(),
89 adjacent_vertices_ids.end());
93 return adj_vertices_to_ho_nodes.try_emplace(adjacent_vertices_ids,
nullptr).first;
96void transfer_elem(
Elem & lo_elem,
97 std::unique_ptr<Elem> hi_elem,
98#ifdef LIBMESH_ENABLE_UNIQUE_ID
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)
106 libmesh_assert_equal_to (lo_elem.
n_vertices(), hi_elem->n_vertices());
119 const unsigned int hon_begin = lo_elem.
n_nodes();
120 const unsigned int hon_end = hi_elem->n_nodes();
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);
128 for (
unsigned int hon=hon_begin; hon<hon_end; hon++)
130 auto pos = map_hi_order_node(hon, *hi_elem, adj_vertices_to_ho_nodes);
135 const auto & adjacent_vertices_ids = pos->first;
144 Point new_location = 0;
145 for (
dof_id_type vertex_id : adjacent_vertices_ids)
146 new_location +=
mesh.point(vertex_id);
148 new_location /=
static_cast<Real>(adjacent_vertices_ids.size());
181#ifdef LIBMESH_ENABLE_UNIQUE_ID
183 max_new_nodes_per_elem * lo_elem.
id() +
195 pos->second = hi_node;
197 hi_elem->set_node(hon, hi_node);
202 Node * hi_node = pos->second;
206 hi_elem->set_node(hon, hi_node);
221 chosen_pid == my_pid)
234 for (
auto s : lo_elem.side_index_range())
243 libmesh_assert_equal_to (neigh->
level(), 0);
251 hi_elem->set_neighbor(s, neigh);
264 if (
auto parent_exterior_it = exterior_children_of.find(interior_p);
265 parent_exterior_it != exterior_children_of.end())
267 auto & exteriors = parent_exterior_it->second;
269 if (exteriors[i] == &lo_elem)
271 exteriors[i] = hi_elem.get();
280 if (
auto exterior_it = exterior_children_of.find(&lo_elem);
281 exterior_it != exterior_children_of.end())
283 for (
Elem * exterior_elem : exterior_it->second)
286 exterior_elem->set_interior_parent(hi_elem.get());
309 hi_elem->set_id(lo_elem.
id());
310#ifdef LIBMESH_ENABLE_UNIQUE_ID
311 hi_elem->set_unique_id(lo_elem.
unique_id());
315 hi_elem->add_extra_integers(nei);
316 for (
unsigned int i=0; i != nei; ++i)
319 hi_elem->inherit_data_from(lo_elem);
325template <
typename ElemTypeConverter>
329 const unsigned int max_new_nodes_per_elem,
330 const ElemTypeConverter & elem_type_converter)
365 auto is_higher_order = [&elem_type_converter](
const Elem * elem) {
367 ElemType new_type = elem_type_converter(old_type);
368 return old_type == new_type;
371 bool already_higher_order =
372 std::all_of(range.
begin(), range.
end(), is_higher_order);
376 if (already_higher_order)
394 std::map<std::vector<dof_id_type>,
Node *> adj_vertices_to_ho_nodes;
402 std::unordered_map<Elem *, std::vector<Elem *>> exterior_children_of;
410#ifdef LIBMESH_ENABLE_UNIQUE_ID
436 auto track_if_necessary = [&adj_vertices_to_ho_nodes,
437 &exterior_children_of,
438 &elem_type_converter](
Elem * elem) {
441 if (elem->default_order() !=
FIRST)
444 auto pos = map_hi_order_node(hon, *elem, adj_vertices_to_ho_nodes);
445 pos->second = elem->node_ptr(hon);
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 *>());
457 if (range.
begin() ==
mesh.elements_begin() &&
458 range.
end() ==
mesh.elements_end())
460 for (
auto & elem : range)
461 track_if_necessary(elem);
468 point_neighbor_finder(range.
begin(), range.
end(),
470 point_neighbor_elements);
472 for (
auto & [elem, coupling_map] : point_neighbor_elements)
475 track_if_necessary(
const_cast<Elem *
>(elem));
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);
494 for (
auto & lo_elem : range)
499 const ElemType new_type = elem_type_converter(old_type);
501 if (old_type == new_type)
505 libmesh_assert_equal_to (lo_elem->
level(), 0);
508 ++n_unpartitioned_elem;
516 libmesh_assert_equal_to (lo_elem->
n_vertices(), ho_elem->n_vertices());
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));
525 transfer_elem(*lo_elem, std::move(ho_elem),
526#ifdef LIBMESH_ENABLE_UNIQUE_ID
527 max_unique_id, max_new_nodes_per_elem,
529 mesh, adj_vertices_to_ho_nodes,
530 exterior_children_of);
534 adj_vertices_to_ho_nodes.clear();
536#ifdef LIBMESH_ENABLE_UNIQUE_ID
550 dof_id_type max_unpartitioned_elem = n_unpartitioned_elem;
552 if (max_unpartitioned_elem)
560 libmesh_not_implemented();
592 const std::vector<std::pair<Point, dof_id_type>>
_nodes;
611 libmesh_assert_less (idx,
_nodes.size());
612 libmesh_assert_less (
dim, 3);
616 if (
dim==0)
return p(0);
617 if (
dim==1)
return p(1);
624 template <
class BBOX>
649 const bool skip_find_neighbors,
653#ifdef LIBMESH_ENABLE_UNIQUE_ID
657 std::unordered_map<subdomain_id_type, subdomain_id_type> *
659 const bool skip_preparation)
661 LOG_SCOPE(
"copy_nodes_and_elements()",
"UnstructuredMesh");
667 std::pair<std::vector<unsigned int>, std::vector<unsigned int>>
670 const unsigned int n_old_node_ints = extra_int_maps.second.size(),
672 n_old_elem_ints = extra_int_maps.first.size(),
698 for (
const auto & oldn : other_mesh.node_ptr_range())
701 (wrap_proc_ids ? oldn->processor_id() % this->n_processors() : oldn->processor_id());
706 oldn->id() + node_id_offset,
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));
714#ifdef LIBMESH_ENABLE_UNIQUE_ID
715 newn->set_unique_id(oldn->unique_id() + unique_id_offset);
726 typedef std::unordered_map<const Elem *, Elem *> map_type;
727 map_type old_elems_to_new_elems, ip_map;
730 for (
const auto & old : other_mesh.element_ptr_range())
734 this->
elem_ptr(old->parent()->id() + element_id_offset) :
736 auto el = old->disconnected_clone();
737 el->set_parent(newparent);
742 auto remapping_it = id_remapping->find(sbd_id);
743 if (remapping_it != id_remapping->end())
744 sbd_id = remapping_it->second;
746 el->subdomain_id() = sbd_id;
750 if (old->interior_parent())
751 ip_map[old] = el.get();
753#ifdef LIBMESH_ENABLE_AMR
754 if (old->has_children())
755 for (
unsigned int c = 0, nc = old->n_children(); c != nc; ++c)
762 unsigned int oldc = old->parent()->which_child_am_i(old);
767 el->set_refinement_flag(old->refinement_flag());
771 el->hack_p_level(old->p_level());
773 el->set_p_refinement_flag(old->p_refinement_flag());
777 for (
auto i : el->node_index_range())
779 this->node_ptr(old->node_id(i) + node_id_offset));
782 el->processor_id() = cast_int<processor_id_type>
783 (wrap_proc_ids ? old->processor_id() % this->n_processors() : old->processor_id());
786 el->set_id(old->id() + element_id_offset);
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));
793#ifdef LIBMESH_ENABLE_UNIQUE_ID
794 el->set_unique_id(old->unique_id() + unique_id_offset);
798 if (!skip_find_neighbors)
800 for (
auto s : old->side_index_range())
808 old_elems_to_new_elems[old] = new_el;
820 std::atomic<bool> existing_interior_parents{
false};
824 [&existing_interior_parents](
const ElemRange & range)
826 for (
Elem * elem : range)
827 if (elem->interior_parent())
829 existing_interior_parents =
true;
840 if (!existing_interior_parents)
842 if (other_interior_mesh == &other_mesh)
848 if (other_interior_mesh == &other_mesh &&
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));
854 for (
auto & elem_pair : ip_map)
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);
862 libmesh_error_msg(
"Cannot copy boundary elements between meshes with different interior meshes");
866 if (skip_find_neighbors)
870 for (
const auto & old_elem : other_mesh.element_ptr_range())
872 Elem * new_elem = old_elems_to_new_elems[old_elem];
873 for (
auto s : old_elem->side_index_range())
876 Elem * new_neighbor = old_elems_to_new_elems[old_neighbor];
883#ifdef LIBMESH_ENABLE_UNIQUE_ID
894 if (!skip_preparation)
927 if (skip_find_neighbors ||
971bool sides_are_the_same_elem(
const Elem & a,
const Elem &
b)
982 if (nv !=
b.n_vertices())
985 std::vector<dof_id_type> a_ids(nv), b_ids(nv);
986 for (
unsigned int v = 0; v != nv; ++v)
989 b_ids[v] =
b.node_id(v);
991 std::sort(a_ids.begin(), a_ids.end());
992 std::sort(b_ids.begin(), b_ids.end());
993 return a_ids == b_ids;
1000 const bool reset_current_list,
1001 const bool assert_valid,
1002 const bool check_non_remote)
1010 parallel_object_only();
1012 LOG_SCOPE(
"find_neighbors()",
"Mesh");
1015 if (reset_current_list)
1018 [reset_remote_elements](
const ElemRange & range)
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);
1032 typedef std::pair<Elem *, unsigned char> val_type;
1033 typedef std::unordered_multimap<key_type, val_type> map_type;
1036 map_type side_to_elem_map;
1039 std::unique_ptr<Elem> my_side, their_side;
1041 for (
const auto & element : this->element_ptr_range())
1043 for (
auto ms : element->side_index_range())
1052 if ((element->neighbor_ptr(ms) ==
nullptr && check_non_remote) ||
1058 const dof_id_type key = element->low_order_key(ms);
1061 auto bounds = side_to_elem_map.equal_range(key);
1065 if (bounds.first != bounds.second)
1068 element->side_ptr(my_side, ms);
1071 while (bounds.first != bounds.second)
1074 Elem * neighbor = bounds.first->second.first;
1077 const unsigned int ns = bounds.first->second.second;
1078 neighbor->
side_ptr(their_side, ns);
1089 if (sides_are_the_same_elem(*my_side, *their_side) &&
1090 (element->level() == neighbor->
level()))
1098 if (element->subactive() ==
1103 element->set_neighbor (ms,neighbor);
1106 else if (element->subactive())
1108 element->set_neighbor(ms,neighbor);
1114 side_to_elem_map.erase (bounds.first);
1126 side_to_elem_map.emplace
1127 (key, std::make_pair(element, cast_int<unsigned char>(ms)));
1133#ifdef LIBMESH_ENABLE_PERIODIC
1142 for (
const auto & element : this->element_ptr_range())
1144 for (
auto ms : element->side_index_range())
1147 if (element->neighbor_ptr(ms) !=
nullptr &&
1151 for (
const auto & [
id, boundary_ptr] : *db)
1156 unsigned int neigh_side;
1157 const Elem * neigh =
1158 db->neighbor(
id, *point_locator, element, ms, &neigh_side);
1160 if (neigh && neigh !=
remote_elem && neigh != element)
1162 auto neigh_changeable = this->
elem_ptr(neigh->
id());
1163 element->set_neighbor(ms, neigh_changeable);
1164 neigh_changeable->set_neighbor(neigh_side, element);
1172#ifdef LIBMESH_ENABLE_AMR
1202 for (
unsigned int level = 1; level < n_levels; ++level)
1204 for (
auto & current_elem :
as_range(level_elements_begin(level),
1205 level_elements_end(level)))
1212 for (
auto s : current_elem->side_index_range())
1214 if (current_elem->neighbor_ptr(s) ==
nullptr ||
1231 (neigh->
level()+1) == current_elem->level())))
1237 bool neigh_has_remote_children =
false;
1240 neigh_has_remote_children =
true;
1245 if (current_elem->active())
1246 libmesh_assert_not_equal_to (current_elem->processor_id(),
1247 this->processor_id());
1254 else if (neigh && (current_elem->subactive() &&
1267 bool found_neigh =
false;
1268 for (
unsigned int c = 0, nc = neigh->
n_children();
1269 !found_neigh && c != nc; ++c)
1294 if ((!neigh->
active()) && (!current_elem->subactive()))
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;
1307 << (current_elem->active()?
"Active":
"Ancestor")
1308 <<
" Element at level "
1309 << current_elem->level() << std::endl;
1311 << (parent->
active()?
"active":
1312 (parent->
subactive()?
"subactive":
"ancestor"))
1314 << (neigh->
subactive()?
"subactive":
"ancestor")
1315 <<
" neighbor at level " << neigh->
level()
1318 libmesh_error_msg(
"Problematic mesh written to bad_mesh.gmv.");
1326 if (current_elem->dim() >= LIBMESH_DIM)
1330 current_elem->set_interior_parent(
nullptr);
1358 current_elem->set_interior_parent
1363 bool child_contains_our_nodes =
true;
1364 for (
auto & n : current_elem->node_ref_range())
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))
1371 child_contains_this_node =
true;
1374 if (!child_contains_this_node)
1376 child_contains_our_nodes =
false;
1380 if (child_contains_our_nodes)
1382 current_elem->set_interior_parent(&child);
1398 !reset_remote_elements);
1412 bool skip_renumber_nodes_and_elements,
1413 bool skip_find_neighbors,
1414 bool skip_detect_interior_parents)
1427 if (skip_renumber_nodes_and_elements)
1430 libmesh_deprecated();
1451 LOG_SCOPE(
"write()",
"Mesh");
1459 const std::vector<Number> & v,
1460 const std::vector<std::string> & vn)
const
1462 LOG_SCOPE(
"write()",
"Mesh");
1484 <<
"mesh for a processor id (="
1486 <<
") greater than "
1487 <<
"the number of processors available for "
1488 <<
"the calculation. (="
1496 this->active_pid_elements_begin(pid),
1497 this->active_pid_elements_end(pid));
1524 libmesh_assert_not_equal_to (this->
n_nodes(), 0);
1525 libmesh_assert_not_equal_to (this->
n_elem(), 0);
1528 std::vector<boundary_id_type> bc_ids;
1534 for (
const auto & old_elem :
as_range(it, it_end))
1538 auto uelem = old_elem->disconnected_clone();
1543 for (
auto n : old_elem->node_index_range())
1545 const dof_id_type this_node_id = old_elem->node_id(n);
1553 old_elem->node_ptr(n)->processor_id());
1556 for (
unsigned int i = 0; i != n_node_ints; ++i)
1559#ifdef LIBMESH_ENABLE_UNIQUE_ID
1569 for (
auto s : old_elem->side_index_range())
1582#ifdef LIBMESH_ENABLE_AMR
1585 LOG_SCOPE (
"contract()",
"Mesh");
1588 bool mesh_changed =
false;
1591 for (
const auto & elem : this->element_ptr_range())
1592 libmesh_assert(elem->active() || elem->subactive() || elem->ancestor());
1596 for (
auto & elem : this->element_ptr_range())
1599 if (elem->subactive())
1613 mesh_changed =
true;
1640 return mesh_changed;
1648 LOG_SCOPE(
"all_first_order()",
"Mesh");
1653 std::vector<bool> node_touched_by_me(this->
max_node_id(),
false);
1658 for (
auto & so_elem : element_ptr_range())
1668 (so_elem->type()), so_elem->parent());
1670 const unsigned short n_sides = so_elem->n_sides();
1672 for (
unsigned short s=0; s != n_sides; ++s)
1676#ifdef LIBMESH_ENABLE_AMR
1680 if (so_elem->has_children())
1681 for (
unsigned int c = 0, nc = so_elem->n_children(); c != nc; ++c)
1692 if (so_elem->parent())
1695 so_elem->parent()->which_child_am_i(so_elem);
1707 libmesh_assert_equal_to (lo_elem->
n_vertices(), so_elem->n_vertices());
1714 for (
unsigned int v=0, snv=so_elem->n_vertices(); v < snv; v++)
1716 lo_elem->
set_node(v, so_elem->node_ptr(v));
1717 node_touched_by_me[lo_elem->
node_id(v)] =
true;
1724 for (
unsigned short s=0; s != n_sides; s++)
1744 lo_elem->
set_id(so_elem->id());
1745#ifdef LIBMESH_ENABLE_UNIQUE_ID
1749 const unsigned int nei = so_elem->n_extra_integers();
1751 for (
unsigned int i=0; i != nei; ++i)
1760 for (
const auto & node : this->node_ptr_range())
1761 if (!node_touched_by_me[node->id()])
1781 const bool full_ordered)
1783 LOG_SCOPE(
"all_second_order_range()",
"Mesh");
1790 unsigned int max_new_nodes_per_elem;
1806 max_new_nodes_per_elem = 3 - 2;
1808 (1.5*
static_cast<double>(this->
n_nodes())));
1816 max_new_nodes_per_elem = 9 - 4;
1818 (2*
static_cast<double>(this->
n_nodes())));
1829 max_new_nodes_per_elem = 27 - 8;
1831 (2.5*
static_cast<double>(this->
n_nodes())));
1836 libmesh_error_msg(
"Unknown mesh dimension " << this->
mesh_dimension());
1840 all_increased_order_range(*
this, range, max_new_nodes_per_elem,
1850 LOG_SCOPE(
"all_complete_order()",
"Mesh");
1857 unsigned int max_new_nodes_per_elem;
1873 max_new_nodes_per_elem = 3 - 2;
1875 (1.5*
static_cast<double>(this->
n_nodes())));
1884 max_new_nodes_per_elem = 9 - 4;
1886 (2*
static_cast<double>(this->
n_nodes())));
1898 max_new_nodes_per_elem = 27 - 8;
1900 (2.5*
static_cast<double>(this->
n_nodes())));
1905 libmesh_error_msg(
"Unknown mesh dimension " << this->
mesh_dimension());
1909 all_increased_order_range(*
this, range, max_new_nodes_per_elem,
1921 bool clear_stitched_boundary_ids,
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)
1929 LOG_SCOPE(
"stitch_meshes()",
"UnstructuredMesh");
1931 this_mesh_boundary_id,
1932 other_mesh_boundary_id,
1934 clear_stitched_boundary_ids,
1937 enforce_all_nodes_match_on_boundaries,
1939 merge_boundary_nodes_all_or_nothing,
1940 remap_subdomain_ids,
1941 prepare_after_stitching);
1949 bool clear_stitched_boundary_ids,
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)
1961 clear_stitched_boundary_ids,
1964 enforce_all_nodes_match_on_boundaries,
1966 merge_boundary_nodes_all_or_nothing,
1968 prepare_after_stitching);
1977 bool clear_stitched_boundary_ids,
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)
1991 bool is_valid_disjoint_pair_to_stitch =
false;
1993#ifdef LIBMESH_ENABLE_PERIODIC
1996 const bool have_disc_bdys =
1997 (this_db && !this_db->empty()) || (other_db && !other_db->empty());
2006 return db ? db->
boundary(
id) :
nullptr;
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);
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);
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.");
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.");
2039 if (in_this || in_other)
2040 is_valid_disjoint_pair_to_stitch =
true;
2053 std::unique_ptr<MeshSerializer> serialize_other;
2055 serialize_other = std::make_unique<MeshSerializer>
2056 (*
const_cast<MeshBase *
>(other_mesh));
2058 std::map<dof_id_type, dof_id_type> node_to_node_map, other_to_this_node_map;
2059 std::map<dof_id_type, std::vector<dof_id_type>> node_to_elems_map;
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;
2066 map_type side_to_elem_map;
2077 LOG_SCOPE(
"stitch_meshes node merging",
"UnstructuredMesh");
2082 Real h_min = std::numeric_limits<Real>::max();
2083 bool h_min_updated =
false;
2086 std::set<dof_id_type> this_boundary_node_ids, other_boundary_node_ids;
2089 std::unique_ptr<const Elem> side;
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};
2097 for (
unsigned i=0; i<2; ++i)
2111 if (node_bc_id == id_array[i])
2114 set_array[i]->insert( this_node_id );
2120 std::vector<boundary_id_type> bc_ids;
2127 std::vector<const Elem *> boundary_node_elems;
2129 for (
auto & el : mesh_array[i]->element_ptr_range())
2132 for (
auto side_id : el->side_index_range())
2134 bool should_stitch_this_side =
2135 (el->neighbor_ptr(
side_id) ==
nullptr) ||
2136 (is_valid_disjoint_pair_to_stitch &&
2139 if (should_stitch_this_side)
2144 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
2146 el->build_side_ptr(side,
side_id);
2147 for (
auto & n : side->node_ref_range())
2148 set_array[i]->insert(n.id());
2150 h_min = std::min(h_min, side->hmin());
2151 h_min_updated =
true;
2154 if (skip_find_neighbors && (i==0))
2156 key_type key = el->low_order_key(
side_id);
2159 val.second = cast_int<unsigned char>(
side_id);
2164 side_to_elem_map.insert (kvp);
2171 for (
auto edge_id : el->edge_index_range())
2173 if (el->is_edge_on_side(edge_id,
side_id))
2178 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
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() );
2184 h_min = std::min(h_min, edge->hmin());
2185 h_min_updated =
true;
2200 if (std::find(bc_ids.begin(), bc_ids.end(), id_array[i]) != bc_ids.end())
2202 boundary_node_elems.push_back(el);
2213 const auto N = boundary_node_elems.size();
2215 for (
auto node_elem_j :
make_range(node_elem_i+1, N))
2218 (boundary_node_elems[node_elem_i]->point(0) - boundary_node_elems[node_elem_j]->point(0)).norm();
2225 h_min = std::min(h_min, node_sep);
2226 h_min_updated =
true;
2235 libMesh::out <<
"In UnstructuredMesh::stitch_meshes:\n"
2236 <<
"This mesh has " << this_boundary_node_ids.size()
2237 <<
" nodes on boundary `"
2239 <<
"' (" << this_mesh_boundary_id <<
").\n"
2240 <<
"Other mesh has " << other_boundary_node_ids.size()
2241 <<
" nodes on boundary `"
2243 <<
"' (" << other_mesh_boundary_id <<
").\n";
2247 libMesh::out <<
"Minimum edge length on both surfaces is " << h_min <<
".\n";
2251 libMesh::out <<
"No minimum edge length determined on specified surfaces." << std::endl;
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.");
2266 if (use_binary_search)
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.");
2276 if (!this_boundary_node_ids.empty())
2278 if (use_binary_search)
2280#ifdef LIBMESH_HAVE_NANOFLANN
2281 typedef nanoflann::KDTreeSingleIndexAdaptor<nanoflann::L2_Simple_Adaptor<Real, VectorOfNodesAdaptor>,
2285 std::vector<std::pair<Point, dof_id_type>> this_mesh_nodes(this_boundary_node_ids.size());
2287 for (
auto [it, ctr] = std::make_tuple(this_boundary_node_ids.begin(), 0u);
2288 it != this_boundary_node_ids.end(); ++it, ++ctr)
2290 this_mesh_nodes[ctr].first = this->
point(*it);
2291 this_mesh_nodes[ctr].second = *it;
2296 kd_tree_t this_kd_tree(3, vec_nodes_adaptor, 10);
2297 this_kd_tree.buildIndex();
2300 std::size_t ret_index;
2304 for (
const auto & node_id : other_boundary_node_ids)
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);
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;
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");
2338 libmesh_warning(
"No valid h_min value was found, falling back on "
2339 "absolute distance check in the N^2 search algorithm.");
2346 for (
const auto & this_node_id : this_boundary_node_ids)
2350 bool found_matching_nodes =
false;
2352 for (
const auto & other_node_id : other_boundary_node_ids)
2354 const Node & other_node = other_mesh->
node_ref(other_node_id);
2356 Real node_distance = (this_node - other_node).norm();
2358 if (node_distance < tol*h_min)
2361 libmesh_error_msg_if(found_matching_nodes,
2362 "Error: Found multiple matching nodes in stitch_meshes");
2364 node_to_node_map[this_node_id] = other_node_id;
2365 other_to_this_node_map[other_node_id] = this_node_id;
2367 found_matching_nodes =
true;
2375 for (
auto & el : other_mesh->element_ptr_range())
2382 for (
auto & n : el->node_ref_range())
2383 if (
const auto it = other_to_this_node_map.find(n.id());
2384 it != other_to_this_node_map.end())
2385 node_to_elems_map[it->second].push_back( el->id() );
2390 libMesh::out <<
"In UnstructuredMesh::stitch_meshes:\n"
2391 <<
"Found " << node_to_node_map.size()
2392 <<
" matching nodes.\n"
2396 if (enforce_all_nodes_match_on_boundaries)
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.");
2405 if (merge_boundary_nodes_all_or_nothing)
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))
2415 "UnstructuredMesh::stitch_meshes because not "
2416 "all boundary nodes were matched."
2419 node_to_node_map.clear();
2420 other_to_this_node_map.clear();
2421 node_to_elems_map.clear();
2429 libMesh::out <<
"Skip node merging in UnstructuredMesh::stitch_meshes:" << std::endl;
2437#ifdef LIBMESH_ENABLE_UNIQUE_ID
2445 if (
this!=other_mesh)
2447 LOG_SCOPE(
"stitch_meshes copying",
"UnstructuredMesh");
2449#ifdef LIBMESH_ENABLE_PERIODIC
2452 if (other_db && !other_db->empty())
2454 for (
const auto & [bdy_id, pb_ptr] : *other_db)
2456 const auto & pb = *pb_ptr;
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))
2470 const bool a_exists = bdy_ids.count(a);
2471 const bool b_exists = bdy_ids.count(
b);
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.");
2487 for (
auto & pr : node_to_node_map)
2488 pr.second += node_delta;
2490 for (
auto & pr : node_to_elems_map)
2491 for (
auto & entry : pr.second)
2492 entry += elem_delta;
2514 std::unordered_map<subdomain_id_type, subdomain_id_type> id_remapping;
2515 if (remap_subdomain_ids)
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);
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);
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;
2536 const auto this_subdomains = get_subdomains(*
this);
2537 const auto other_subdomains = get_subdomains(*other_mesh);
2539 for (
auto & [sid, sname] : this_map)
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;
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);
2558 if (!this_subdomains.empty())
2559 next_free_id = *this_subdomains.rbegin() + 1;
2560 if (!other_subdomains.empty())
2562 std::max(next_free_id,
2563 cast_int<subdomain_id_type>
2564 (*other_subdomains.rbegin() + 1));
2566 for (
auto & [sid, sname] : other_map)
2571 if (!this_map_reversed.count(sname))
2575 if (this_subdomains.count(sid))
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);
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");
2596 id_remapping[sid] = next_free_id++;
2610 elem_delta, node_delta,
2611 unique_delta, &id_remapping);
2619 boundary.
add_node(std::get<0>(t) + node_delta,
2623 boundary.
add_side(std::get<0>(t) + elem_delta,
2628 boundary.
add_edge(std::get<0>(t) + elem_delta,
2639 ns_id_to_name.insert(other_ns_id_to_name.begin(), other_ns_id_to_name.end());
2643 ss_id_to_name.insert(other_ss_id_to_name.begin(), other_ss_id_to_name.end());
2647 es_id_to_name.insert(other_es_id_to_name.begin(), other_es_id_to_name.end());
2657 other_mesh->
get_elemsets(elemset_code, other_id_set_to_fill);
2666 this_elemset_codes.end(),
2669 if (it != this_elemset_codes.end())
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.");
2697 LOG_SCOPE(
"stitch_meshes node updates",
"UnstructuredMesh");
2700 std::vector<boundary_id_type> bc_ids;
2702 for (
const auto & [target_node_id, elem_vec] : node_to_elems_map)
2704 dof_id_type other_node_id = node_to_node_map[target_node_id];
2707 std::size_t n_elems = elem_vec.size();
2708 for (std::size_t i=0; i<n_elems; i++)
2714 unsigned int local_node_index = el->
local_node(other_node_id);
2720 el->
set_node(local_node_index, &target_node);
2727 LOG_SCOPE(
"stitch_meshes node deletion",
"UnstructuredMesh");
2728 for (
const auto & [other_node_id, this_node_id] : node_to_node_map)
2732 if ((
this == other_mesh) && (this_node_id == other_node_id))
2746 if (skip_find_neighbors)
2748 LOG_SCOPE(
"stitch_meshes neighbor fixes",
"UnstructuredMesh");
2751 std::unique_ptr<const Elem> my_side, their_side;
2753 std::set<dof_id_type> fixed_elems;
2754 for (
const auto & pr : node_to_elems_map)
2756 std::size_t n_elems = pr.second.size();
2757 for (std::size_t i=0; i<n_elems; i++)
2760 if (!fixed_elems.count(elem_id))
2763 fixed_elems.insert(elem_id);
2766 bool has_real_neighbor = (el->
neighbor_ptr(s) !=
nullptr);
2767 bool has_disdjoint_neighbor = is_valid_disjoint_pair_to_stitch &&
2771 if (!has_real_neighbor || has_disdjoint_neighbor)
2774 auto bounds = side_to_elem_map.equal_range(key);
2776 if (bounds.first != bounds.second)
2782 while (bounds.first != bounds.second)
2785 Elem * neighbor =
const_cast<Elem *
>(bounds.first->second.first);
2788 const unsigned int ns = bounds.first->second.second;
2789 neighbor->
side_ptr(their_side, ns);
2801 if ((*my_side == *their_side) &&
2803 ((el->
dim() != 1) || (ns != s)))
2834 side_to_elem_map.erase (bounds.first);
2848#ifdef LIBMESH_ENABLE_PERIODIC
2853 if (is_valid_disjoint_pair_to_stitch)
2857 if (prepare_after_stitching)
2875 if (clear_stitched_boundary_ids)
2877 LOG_SCOPE(
"stitch_meshes clear bcids",
"UnstructuredMesh");
2880 this_mesh_boundary_id, other_mesh_boundary_id,
true);
2884 return node_to_node_map.size();
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
void add_extra_integers(const unsigned int n_integers)
Assigns a set of extra integers to this DofObject.
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
unique_id_type unique_id() const
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
void set_unique_id(unique_id_type new_id)
Sets the unique_id for this DofObject.
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.
virtual Node *& set_node(const unsigned int i)
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
SimpleRange< NeighborPtrIter > neighbor_ptr_range()
Returns a range with all neighbors of an element, usable in range-based for loops.
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const =0
bool is_ancestor_of(const Elem *descendant) const
virtual unsigned int n_vertices() const =0
bool has_children() const
virtual std::unique_ptr< Elem > side_ptr(unsigned int i)=0
virtual unsigned int n_nodes() const =0
const Elem * parent() const
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
static ElemType complete_order_equivalent_type(const ElemType et)
const Elem * child_ptr(unsigned int i) const
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
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)
void set_interior_parent(Elem *p)
Sets the pointer to the element's interior_parent.
static ElemType first_order_equivalent_type(const ElemType et)
virtual unsigned int n_second_order_adjacent_vertices(const unsigned int n) const
unsigned int local_node(const dof_id_type i) const
unsigned int which_child_am_i(const Elem *e) const
virtual Real hmin() const
static ElemType second_order_equivalent_type(const ElemType et, const bool full_ordered=true)
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.
unsigned int level() const
virtual bool runtime_topology() const
void set_parent(Elem *p)
Sets the pointer to the element's parent.
const Node * node_ptr(const unsigned int i) const
void add_child(Elem *elem)
Adds a child pointer to the array of children of this element.
void replace_child(Elem *elem, unsigned int c)
Replaces the child pointer at the specified index in the child array.
virtual unsigned int n_children() const =0
virtual ElemType type() const =0
const Elem * interior_parent() const
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
dof_id_type node_id(const unsigned int i) const
virtual unsigned short int second_order_adjacent_vertex(const unsigned int n, const unsigned int v) const
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
Point vertex_average() const
IntRange< unsigned short > side_index_range() const
void inherit_data_from(const Elem &src)
A helper function for copying generic element data (mapping, subdomain, processor) from an element to...
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.
void set_subdomain_name(subdomain_id_type id, const std::string &name, bool synchronous=false)
Sets the name for the provided id.
virtual const Node & node_ref(const dof_id_type i) const
virtual const Point & point(const dof_id_type i) const =0
virtual bool is_serial() const
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
bool allow_renumbering() const
virtual const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
virtual dof_id_type n_elem() const =0
virtual bool is_replicated() const
virtual void own_node(Node &)
Takes ownership of node n on this partition of a distributed mesh, by setting n.processor_id() to thi...
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
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
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...
PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs()
const std::map< subdomain_id_type, std::string > & get_subdomain_name_map() const
virtual void delete_node(Node *n)=0
Removes the Node n from the mesh.
const ElemRange & element_stored_range()
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.
std::vector< dof_id_type > get_elemset_codes() const
Return a vector of all elemset codes defined on the mesh.
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.
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.
unsigned int n_partitions() const
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...
MeshBase * _interior_mesh
Defaulting to this, a pointer to the mesh used to generate boundary elements on this.
virtual void clear()
Deletes all the element and node data that is currently stored.
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.
const MeshBase & interior_mesh() const
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.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
bool allow_remote_element_removal() const
bool allow_find_neighbors() const
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.
void remove_disjoint_boundary_pair(const boundary_id_type b1, const boundary_id_type b2)
void clear_point_locator()
Releases the current PointLocator object.
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.
std::set< elemset_id_type > elemset_type
Typedef for the "set" container used to store elemset ids.
std::vector< std::string > _node_integer_names
The array of names for integer data associated with each node in the mesh.
std::unique_ptr< PointLocatorBase > sub_point_locator() const
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.
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.
void set_interior_mesh(MeshBase &int_mesh)
Sets the interior mesh.
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 ...
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.
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.
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.
In parallel meshes where a ghost element has neighbors which do not exist on the local processor,...
The SimpleRange templated class is intended to make it easy to construct ranges from pairs of iterato...
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)
bool kdtree_get_bbox(BBOX &) const
const std::vector< std::pair< Point, dof_id_type > > _nodes
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...
bool ends_with(std::string_view superstring, std::string_view suffix)
Look for a substring at the very end of a string.
The libMesh namespace provides an interface to certain functionality in the library.
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...
bool closed()
Checks that the library has been closed.
ElemType
Defines an enum for geometric element types.
void libmesh_ignore(const Args &...)
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
const RemoteElem * remote_elem
bool initialized()
Checks that library initialization has been done.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
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...
const boundary_id_type side_id
The definition of the const_element_iterator struct.
const dof_id_type n_nodes