Line data Source code
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 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 : // library configuration
21 : #include "libmesh/libmesh_config.h"
22 :
23 : // Local includes
24 : #include "libmesh/boundary_info.h"
25 : #include "libmesh/libmesh_logging.h"
26 : #include "libmesh/elem.h"
27 : #include "libmesh/ghost_point_neighbors.h"
28 : #include "libmesh/mesh_base.h"
29 : #include "libmesh/mesh_communication.h"
30 : #include "libmesh/mesh_serializer.h"
31 : #include "libmesh/mesh_tools.h"
32 : #include "libmesh/parallel.h"
33 : #include "libmesh/parallel_algebra.h"
34 : #include "libmesh/parallel_fe_type.h"
35 : #include "libmesh/partitioner.h"
36 : #include "libmesh/point_locator_base.h"
37 : #include "libmesh/sparse_matrix.h"
38 : #include "libmesh/threads.h"
39 : #include "libmesh/enum_elem_type.h"
40 : #include "libmesh/enum_point_locator_type.h"
41 : #include "libmesh/enum_to_string.h"
42 : #include "libmesh/point_locator_nanoflann.h"
43 : #include "libmesh/elem_side_builder.h"
44 : #include "libmesh/elem_range.h"
45 : #include "libmesh/node_range.h"
46 :
47 : // C++ includes
48 : #include <algorithm> // for std::min
49 : #include <map> // for std::multimap
50 : #include <memory>
51 : #include <sstream> // for std::ostringstream
52 : #include <unordered_map>
53 :
54 : #include "libmesh/periodic_boundaries.h"
55 : #include "libmesh/periodic_boundary.h"
56 :
57 : namespace libMesh
58 : {
59 :
60 :
61 :
62 : // ------------------------------------------------------------
63 : // MeshBase class member functions
64 33976 : MeshBase::MeshBase (const Parallel::Communicator & comm_in,
65 33976 : unsigned char d) :
66 : ParallelObject (comm_in),
67 33976 : boundary_info (new BoundaryInfo(*this)), // BoundaryInfo has protected ctor, can't use std::make_unique
68 14332 : _n_parts (1),
69 14332 : _default_mapping_type(LAGRANGE_MAP),
70 14332 : _default_mapping_data(0),
71 14332 : _preparation (),
72 14332 : _element_stored_range (),
73 14332 : _const_active_local_element_stored_range (),
74 14332 : _point_locator (),
75 14332 : _count_lower_dim_elems_in_point_locator(true),
76 14332 : _partitioner (),
77 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
78 14332 : _next_unique_id(DofObject::invalid_unique_id),
79 : #endif
80 14332 : _interior_mesh(this),
81 14332 : _skip_noncritical_partitioning(false),
82 43798 : _skip_all_partitioning(libMesh::on_command_line("--skip-partitioning")),
83 14332 : _skip_renumber_nodes_and_elements(false),
84 14332 : _skip_find_neighbors(false),
85 14332 : _skip_detect_interior_parents(false),
86 14332 : _allow_remote_element_removal(true),
87 14332 : _allow_node_and_elem_unique_id_overlap(false),
88 14332 : _spatial_dimension(d),
89 33976 : _default_ghosting(std::make_unique<GhostPointNeighbors>(*this)),
90 151038 : _point_locator_close_to_point_tol(0.)
91 : {
92 24154 : _elem_dims.insert(d);
93 33976 : _ghosting_functors.push_back(_default_ghosting.get());
94 9822 : libmesh_assert_less_equal (LIBMESH_DIM, 3);
95 9822 : libmesh_assert_greater_equal (LIBMESH_DIM, d);
96 9822 : libmesh_assert (libMesh::initialized());
97 33976 : }
98 :
99 :
100 :
101 2640 : MeshBase::MeshBase (const MeshBase & other_mesh) :
102 : ParallelObject (other_mesh),
103 2640 : boundary_info (new BoundaryInfo(*this)), // BoundaryInfo has protected ctor, can't use std::make_unique
104 2640 : _n_parts (other_mesh._n_parts),
105 2640 : _default_mapping_type(other_mesh._default_mapping_type),
106 2640 : _default_mapping_data(other_mesh._default_mapping_data),
107 1040 : _preparation (other_mesh._preparation),
108 1040 : _element_stored_range (),
109 1040 : _const_active_local_element_stored_range (),
110 1040 : _point_locator (),
111 2640 : _count_lower_dim_elems_in_point_locator(other_mesh._count_lower_dim_elems_in_point_locator),
112 1040 : _partitioner (),
113 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
114 2640 : _next_unique_id(other_mesh._next_unique_id),
115 : #endif
116 : // If the other mesh interior_parent pointers just go back to
117 : // itself, so should we
118 2640 : _interior_mesh((other_mesh._interior_mesh == &other_mesh) ?
119 : this : other_mesh._interior_mesh),
120 2640 : _skip_noncritical_partitioning(other_mesh._skip_noncritical_partitioning),
121 2640 : _skip_all_partitioning(other_mesh._skip_all_partitioning),
122 2640 : _skip_renumber_nodes_and_elements(other_mesh._skip_renumber_nodes_and_elements),
123 2640 : _skip_find_neighbors(other_mesh._skip_find_neighbors),
124 2640 : _skip_detect_interior_parents(other_mesh._skip_detect_interior_parents),
125 2640 : _allow_remote_element_removal(other_mesh._allow_remote_element_removal),
126 2640 : _allow_node_and_elem_unique_id_overlap(other_mesh._allow_node_and_elem_unique_id_overlap),
127 812 : _elem_dims(other_mesh._elem_dims),
128 812 : _elem_default_orders(other_mesh._elem_default_orders),
129 2640 : _supported_nodal_order(other_mesh._supported_nodal_order),
130 812 : _mesh_subdomains(other_mesh._mesh_subdomains),
131 812 : _elemset_codes_inverse_map(other_mesh._elemset_codes_inverse_map),
132 812 : _all_elemset_ids(other_mesh._all_elemset_ids),
133 2640 : _spatial_dimension(other_mesh._spatial_dimension),
134 2640 : _default_ghosting(std::make_unique<GhostPointNeighbors>(*this)),
135 12924 : _point_locator_close_to_point_tol(other_mesh._point_locator_close_to_point_tol)
136 : {
137 812 : const GhostingFunctor * const other_default_ghosting = other_mesh._default_ghosting.get();
138 :
139 8572 : for (GhostingFunctor * const gf : other_mesh._ghosting_functors)
140 : {
141 : // If the other mesh is using default ghosting, then we will use our own
142 : // default ghosting
143 5932 : if (gf == other_default_ghosting)
144 : {
145 2640 : _ghosting_functors.push_back(_default_ghosting.get());
146 2640 : continue;
147 : }
148 :
149 5568 : std::shared_ptr<GhostingFunctor> clone_gf = gf->clone();
150 : // Some subclasses of GhostingFunctor might not override the
151 : // clone function yet. If this is the case, GhostingFunctor will
152 : // return nullptr by default. The clone function should be overridden
153 : // in all derived classes. This following code ("else") is written
154 : // for API upgrade. That will allow users gradually to update their code.
155 : // Once the API upgrade is done, we will come back and delete "else."
156 3292 : if (clone_gf)
157 : {
158 3292 : clone_gf->set_mesh(this);
159 5568 : add_ghosting_functor(clone_gf);
160 : }
161 : else
162 : {
163 : libmesh_deprecated();
164 0 : add_ghosting_functor(*gf);
165 : }
166 : }
167 :
168 2640 : if (other_mesh._partitioner.get())
169 4468 : _partitioner = other_mesh._partitioner->clone();
170 :
171 : #ifdef LIBMESH_ENABLE_PERIODIC
172 : // Deep copy of all periodic boundaries
173 2640 : if (other_mesh._disjoint_neighbor_boundary_pairs)
174 : {
175 8 : _disjoint_neighbor_boundary_pairs = std::make_unique<PeriodicBoundaries>();
176 :
177 21 : for (const auto & [id, pb] : *other_mesh._disjoint_neighbor_boundary_pairs)
178 14 : if (pb)
179 24 : (*_disjoint_neighbor_boundary_pairs)[id] = pb->clone();
180 : }
181 : #endif
182 :
183 : // _elemset_codes stores pointers to entries in _elemset_codes_inverse_map,
184 : // so it is not possible to simply copy it directly from other_mesh
185 2640 : for (const auto & [set, code] : _elemset_codes_inverse_map)
186 0 : _elemset_codes.emplace(code, &set);
187 2640 : }
188 :
189 42 : MeshBase& MeshBase::operator= (MeshBase && other_mesh)
190 : {
191 12 : LOG_SCOPE("operator=(&&)", "MeshBase");
192 :
193 : // Move assign as a ParallelObject.
194 12 : this->ParallelObject::operator=(other_mesh);
195 :
196 42 : _n_parts = other_mesh.n_partitions();
197 42 : _default_mapping_type = other_mesh.default_mapping_type();
198 42 : _default_mapping_data = other_mesh.default_mapping_data();
199 42 : _preparation = other_mesh._preparation;
200 12 : _element_stored_range = std::move(other_mesh._element_stored_range);
201 12 : _const_active_local_element_stored_range = std::move(other_mesh._const_active_local_element_stored_range);
202 12 : _point_locator = std::move(other_mesh._point_locator);
203 42 : _count_lower_dim_elems_in_point_locator = other_mesh.get_count_lower_dim_elems_in_point_locator();
204 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
205 42 : _next_unique_id = other_mesh.next_unique_id();
206 : #endif
207 : // If the other mesh interior_parent pointers just go back to
208 : // itself, so should we
209 42 : _interior_mesh = (other_mesh._interior_mesh == &other_mesh) ?
210 : this : other_mesh._interior_mesh;
211 42 : _skip_noncritical_partitioning = other_mesh.skip_noncritical_partitioning();
212 42 : _skip_all_partitioning = other_mesh.skip_partitioning();
213 42 : _skip_renumber_nodes_and_elements = !(other_mesh.allow_renumbering());
214 42 : _skip_find_neighbors = !(other_mesh.allow_find_neighbors());
215 42 : _skip_detect_interior_parents = !(other_mesh.allow_detect_interior_parents());
216 42 : _allow_remote_element_removal = other_mesh.allow_remote_element_removal();
217 42 : _allow_node_and_elem_unique_id_overlap = other_mesh.allow_node_and_elem_unique_id_overlap();
218 12 : _block_id_to_name = std::move(other_mesh._block_id_to_name);
219 12 : _elem_dims = std::move(other_mesh.elem_dimensions());
220 12 : _elem_default_orders = std::move(other_mesh.elem_default_orders());
221 42 : _supported_nodal_order = other_mesh.supported_nodal_order();
222 12 : _mesh_subdomains = other_mesh._mesh_subdomains;
223 12 : _elemset_codes = std::move(other_mesh._elemset_codes);
224 12 : _elemset_codes_inverse_map = std::move(other_mesh._elemset_codes_inverse_map);
225 12 : _all_elemset_ids = std::move(other_mesh._all_elemset_ids);
226 42 : _spatial_dimension = other_mesh.spatial_dimension();
227 42 : _elem_integer_names = std::move(other_mesh._elem_integer_names);
228 42 : _elem_integer_default_values = std::move(other_mesh._elem_integer_default_values);
229 42 : _node_integer_names = std::move(other_mesh._node_integer_names);
230 42 : _node_integer_default_values = std::move(other_mesh._node_integer_default_values);
231 42 : _point_locator_close_to_point_tol = other_mesh.get_point_locator_close_to_point_tol();
232 :
233 : #ifdef LIBMESH_ENABLE_PERIODIC
234 : // Deep copy of all periodic boundaries:
235 : // We must clone each PeriodicBoundaryBase in the source map,
236 : // since unique_ptr cannot be copied and we need independent instances
237 42 : if (other_mesh._disjoint_neighbor_boundary_pairs)
238 : {
239 0 : _disjoint_neighbor_boundary_pairs = std::make_unique<PeriodicBoundaries>();
240 :
241 0 : for (const auto & [id, pb] : *other_mesh._disjoint_neighbor_boundary_pairs)
242 0 : if (pb)
243 0 : (*_disjoint_neighbor_boundary_pairs)[id] = pb->clone();
244 : }
245 : #endif
246 :
247 : // This relies on our subclasses *not* invalidating pointers when we
248 : // do their portion of the move assignment later!
249 12 : boundary_info = std::move(other_mesh.boundary_info);
250 12 : boundary_info->set_mesh(*this);
251 :
252 : #ifdef DEBUG
253 : // Make sure that move assignment worked for pointers
254 12 : for (const auto & [set, code] : _elemset_codes_inverse_map)
255 : {
256 0 : auto it = _elemset_codes.find(code);
257 0 : libmesh_assert_msg(it != _elemset_codes.end(),
258 : "Elemset code " << code << " not found in _elmset_codes container.");
259 0 : libmesh_assert_equal_to(it->second, &set);
260 : }
261 : #endif
262 :
263 : // We're *not* really done at this point, but we have the problem
264 : // that some of our data movement might be expecting subclasses data
265 : // movement to happen first. We'll let subclasses handle that by
266 : // calling our post_dofobject_moves()
267 54 : return *this;
268 : }
269 :
270 :
271 2111 : bool MeshBase::operator== (const MeshBase & other_mesh) const
272 : {
273 1078 : LOG_SCOPE("operator==()", "MeshBase");
274 :
275 2111 : bool is_equal = this->locally_equals(other_mesh);
276 2111 : this->comm().min(is_equal);
277 3189 : return is_equal;
278 : }
279 :
280 :
281 2111 : bool MeshBase::locally_equals (const MeshBase & other_mesh) const
282 : {
283 : // Check whether (almost) everything in the base is equal
284 : //
285 : // We don't check _next_unique_id here, because it's expected to
286 : // change in a DistributedMesh prepare_for_use(); it's conceptually
287 : // "mutable".
288 : //
289 : // We use separate if statements instead of logical operators here,
290 : // to make it easy to see the failing condition when using a
291 : // debugger to figure out why a MeshTools::valid_is_prepared(mesh)
292 : // is failing.
293 2111 : if (_n_parts != other_mesh._n_parts)
294 0 : return false;
295 2111 : if (_default_mapping_type != other_mesh._default_mapping_type)
296 0 : return false;
297 2111 : if (_default_mapping_data != other_mesh._default_mapping_data)
298 0 : return false;
299 2111 : if (_preparation != other_mesh._preparation)
300 0 : return false;
301 3597 : if (_count_lower_dim_elems_in_point_locator !=
302 2111 : other_mesh._count_lower_dim_elems_in_point_locator)
303 0 : return false;
304 :
305 : // We should either both have our own interior parents or both not;
306 : // but if we both don't then we can't really assert anything else
307 : // because pointing at the same interior mesh is fair but so is
308 : // pointing at two different copies of "the same" interior mesh.
309 3597 : if ((_interior_mesh == this) !=
310 2111 : (other_mesh._interior_mesh == &other_mesh))
311 0 : return false;
312 :
313 2111 : if (_skip_noncritical_partitioning != other_mesh._skip_noncritical_partitioning)
314 0 : return false;
315 2111 : if (_skip_all_partitioning != other_mesh._skip_all_partitioning)
316 0 : return false;
317 2111 : if (_skip_renumber_nodes_and_elements != other_mesh._skip_renumber_nodes_and_elements)
318 0 : return false;
319 2111 : if (_skip_find_neighbors != other_mesh._skip_find_neighbors)
320 0 : return false;
321 2111 : if (_skip_detect_interior_parents != other_mesh._skip_detect_interior_parents)
322 0 : return false;
323 2111 : if (_allow_remote_element_removal != other_mesh._allow_remote_element_removal)
324 0 : return false;
325 2111 : if (_allow_node_and_elem_unique_id_overlap != other_mesh._allow_node_and_elem_unique_id_overlap)
326 0 : return false;
327 2111 : if (_spatial_dimension != other_mesh._spatial_dimension)
328 0 : return false;
329 2111 : if (_point_locator_close_to_point_tol != other_mesh._point_locator_close_to_point_tol)
330 0 : return false;
331 2111 : if (_block_id_to_name != other_mesh._block_id_to_name)
332 0 : return false;
333 2111 : if (_elem_dims != other_mesh._elem_dims)
334 0 : return false;
335 2111 : if (_elem_default_orders != other_mesh._elem_default_orders)
336 0 : return false;
337 2111 : if (_supported_nodal_order != other_mesh._supported_nodal_order)
338 0 : return false;
339 2111 : if (_mesh_subdomains != other_mesh._mesh_subdomains)
340 6 : return false;
341 2090 : if (_all_elemset_ids != other_mesh._all_elemset_ids)
342 0 : return false;
343 2090 : if (_elem_integer_names != other_mesh._elem_integer_names)
344 0 : return false;
345 2492 : if (_elem_integer_default_values != other_mesh._elem_integer_default_values)
346 0 : return false;
347 2090 : if (_node_integer_names != other_mesh._node_integer_names)
348 0 : return false;
349 2492 : if (_node_integer_default_values != other_mesh._node_integer_default_values)
350 0 : return false;
351 2090 : if (static_cast<bool>(_default_ghosting) != static_cast<bool>(other_mesh._default_ghosting))
352 0 : return false;
353 2090 : if (static_cast<bool>(_partitioner) != static_cast<bool>(other_mesh._partitioner))
354 0 : return false;
355 2090 : if (*boundary_info != *other_mesh.boundary_info)
356 6 : return false;
357 :
358 : // First check whether the "existence" of the two pointers differs (one present, one absent)
359 3135 : if (static_cast<bool>(_disjoint_neighbor_boundary_pairs) !=
360 1066 : static_cast<bool>(other_mesh._disjoint_neighbor_boundary_pairs))
361 0 : return false;
362 : // If both exist, compare the contents (Weak Test: just compare sizes like `_ghosting_functors`)
363 2073 : if (_disjoint_neighbor_boundary_pairs &&
364 1070 : (_disjoint_neighbor_boundary_pairs->size() != other_mesh._disjoint_neighbor_boundary_pairs->size()))
365 0 : return false;
366 :
367 : const constraint_rows_type & other_rows =
368 1066 : other_mesh.get_constraint_rows();
369 17324 : for (const auto & [node, row] : this->_constraint_rows)
370 : {
371 15255 : const dof_id_type node_id = node->id();
372 15255 : const Node * other_node = other_mesh.query_node_ptr(node_id);
373 15255 : if (!other_node)
374 0 : return false;
375 :
376 6416 : auto it = other_rows.find(other_node);
377 15255 : if (it == other_rows.end())
378 0 : return false;
379 :
380 6416 : const auto & other_row = it->second;
381 21671 : if (row.size() != other_row.size())
382 0 : return false;
383 :
384 56494 : for (auto i : index_range(row))
385 : {
386 18096 : const auto & [elem_pair, coef] = row[i];
387 18096 : const auto & [other_elem_pair, other_coef] = other_row[i];
388 18096 : libmesh_assert(elem_pair.first);
389 18096 : libmesh_assert(other_elem_pair.first);
390 41239 : if (elem_pair.first->id() !=
391 64382 : other_elem_pair.first->id() ||
392 41239 : elem_pair.second !=
393 59335 : other_elem_pair.second ||
394 41239 : coef != other_coef)
395 0 : return false;
396 : }
397 : }
398 :
399 2069 : for (const auto & [elemset_code, elemset_ptr] : this->_elemset_codes)
400 0 : if (const auto it = other_mesh._elemset_codes.find(elemset_code);
401 0 : it == other_mesh._elemset_codes.end() || *elemset_ptr != *it->second)
402 0 : return false;
403 :
404 : // FIXME: we have no good way to compare ghosting functors, since
405 : // they're in a vector of pointers, and we have no way *at all*
406 : // to compare ghosting functors, since they don't have operator==
407 : // defined and we encourage users to subclass them. We can check if
408 : // we have the same number, is all.
409 3531 : if (_ghosting_functors.size() !=
410 1462 : other_mesh._ghosting_functors.size())
411 0 : return false;
412 :
413 : // Same deal for partitioners. We tested that we both have one or
414 : // both don't, but are they equivalent? Let's guess "yes".
415 :
416 : // Now let the subclasses decide whether everything else is equal
417 2069 : return this->subclass_locally_equals(other_mesh);
418 : }
419 :
420 :
421 47226 : MeshBase::~MeshBase()
422 : {
423 36616 : this->MeshBase::clear();
424 :
425 10634 : libmesh_exceptionless_assert (!libMesh::closed());
426 82732 : }
427 :
428 :
429 :
430 2797346 : unsigned int MeshBase::mesh_dimension() const
431 : {
432 2797346 : if (!_elem_dims.empty())
433 2797346 : return cast_int<unsigned int>(*_elem_dims.rbegin());
434 0 : return 0;
435 : }
436 :
437 :
438 :
439 0 : void MeshBase::set_elem_dimensions(std::set<unsigned char> elem_dims)
440 : {
441 : #ifdef DEBUG
442 : // In debug mode, we call cache_elem_data() and then make sure
443 : // the result actually agrees with what the user specified.
444 0 : parallel_object_only();
445 :
446 0 : this->cache_elem_data();
447 0 : libmesh_assert_msg(_elem_dims == elem_dims, \
448 : "Specified element dimensions does not match true element dimensions!");
449 : #endif
450 :
451 0 : _elem_dims = std::move(elem_dims);
452 0 : }
453 :
454 :
455 :
456 175 : void MeshBase::add_elemset_code(dof_id_type code, MeshBase::elemset_type id_set)
457 : {
458 : // Populate inverse map, stealing id_set's resources
459 125 : auto [it1, inserted1] = _elemset_codes_inverse_map.emplace(std::move(id_set), code);
460 :
461 : // Reference to the newly inserted (or previously existing) id_set
462 175 : const auto & inserted_id_set = it1->first;
463 :
464 : // Keep track of all elemset ids ever added for O(1) n_elemsets()
465 : // performance. Only need to do this if we didn't know about this
466 : // id_set before...
467 175 : if (inserted1)
468 175 : _all_elemset_ids.insert(inserted_id_set.begin(), inserted_id_set.end());
469 :
470 : // Take the address of the newly emplaced set to use in
471 : // _elemset_codes, avoid duplicating std::set storage
472 175 : auto [it2, inserted2] = _elemset_codes.emplace(code, &inserted_id_set);
473 :
474 : // Throw an error if this code already exists with a pointer to a
475 : // different set of ids.
476 175 : libmesh_error_msg_if(!inserted2 && it2->second != &inserted_id_set,
477 : "The elemset code " << code << " already exists with a different id_set.");
478 175 : }
479 :
480 :
481 :
482 1431 : unsigned int MeshBase::n_elemsets() const
483 : {
484 1431 : return _all_elemset_ids.size();
485 : }
486 :
487 371 : void MeshBase::get_elemsets(dof_id_type elemset_code, MeshBase::elemset_type & id_set_to_fill) const
488 : {
489 : // If we don't recognize this elemset_code, hand back an empty set
490 102 : id_set_to_fill.clear();
491 :
492 371 : if (const auto it = _elemset_codes.find(elemset_code);
493 102 : it != _elemset_codes.end())
494 162 : id_set_to_fill.insert(it->second->begin(), it->second->end());
495 371 : }
496 :
497 84 : dof_id_type MeshBase::get_elemset_code(const MeshBase::elemset_type & id_set) const
498 : {
499 24 : auto it = _elemset_codes_inverse_map.find(id_set);
500 84 : return (it == _elemset_codes_inverse_map.end()) ? DofObject::invalid_id : it->second;
501 : }
502 :
503 837 : std::vector<dof_id_type> MeshBase::get_elemset_codes() const
504 : {
505 240 : std::vector<dof_id_type> ret;
506 837 : ret.reserve(_elemset_codes.size());
507 914 : for (const auto & pr : _elemset_codes)
508 77 : ret.push_back(pr.first);
509 837 : return ret;
510 : }
511 :
512 28 : void MeshBase::change_elemset_code(dof_id_type old_code, dof_id_type new_code)
513 : {
514 : // Look up elemset ids for old_code
515 8 : auto it = _elemset_codes.find(old_code);
516 :
517 : // If we don't have the old_code, then do nothing. Alternatively, we
518 : // could throw an error since trying to change an elemset code you
519 : // don't have could indicate there's a problem...
520 28 : if (it == _elemset_codes.end())
521 0 : return;
522 :
523 : // Make copy of the set of elemset ids. We are not changing these,
524 : // only updating the elemset code it corresponds to.
525 28 : elemset_type id_set_copy = *(it->second);
526 :
527 : // Look up the corresponding entry in the inverse map. Note: we want
528 : // the iterator because we are going to remove it.
529 8 : auto inverse_it = _elemset_codes_inverse_map.find(id_set_copy);
530 28 : libmesh_error_msg_if(inverse_it == _elemset_codes_inverse_map.end(),
531 : "Expected _elemset_codes_inverse_map entry for elemset code " << old_code);
532 :
533 : // Erase entry from inverse map
534 20 : _elemset_codes_inverse_map.erase(inverse_it);
535 :
536 : // Erase entry from forward map
537 20 : _elemset_codes.erase(it);
538 :
539 : // Add new code with original set of ids.
540 48 : this->add_elemset_code(new_code, id_set_copy);
541 :
542 : // We can't update any actual elemset codes if there is no extra integer defined for it.
543 28 : if (!this->has_elem_integer("elemset_code"))
544 0 : return;
545 :
546 : // Get index of elemset_code extra integer
547 28 : unsigned int elemset_index = this->get_elem_integer_index("elemset_code");
548 :
549 : // Loop over all elems and update code
550 : Threads::parallel_for
551 28 : (this->element_stored_range(),
552 472 : [elemset_index, old_code, new_code](const ElemRange & range)
553 : {
554 518 : for (Elem * elem : range)
555 : {
556 : dof_id_type elemset_code =
557 490 : elem->get_extra_integer(elemset_index);
558 :
559 490 : if (elemset_code == old_code)
560 175 : elem->set_extra_integer(elemset_index, new_code);
561 : }
562 28 : });
563 : }
564 :
565 28 : void MeshBase::change_elemset_id(elemset_id_type old_id, elemset_id_type new_id)
566 : {
567 : // Early return if we don't have old_id
568 8 : if (!_all_elemset_ids.count(old_id))
569 0 : return;
570 :
571 : // Throw an error if the new_id is already used
572 8 : libmesh_error_msg_if(_all_elemset_ids.count(new_id),
573 : "Cannot change elemset id " << old_id <<
574 : " to " << new_id << ", " << new_id << " already exists.");
575 :
576 : // We will build up a new version of the inverse map so we can iterate over
577 : // the current one without invalidating anything.
578 16 : std::map<MeshBase::elemset_type, dof_id_type> new_elemset_codes_inverse_map;
579 84 : for (const auto & [id_set, elemset_code] : _elemset_codes_inverse_map)
580 : {
581 32 : auto id_set_copy = id_set;
582 16 : if (id_set_copy.count(old_id))
583 : {
584 : // Remove old_id, insert new_id
585 8 : id_set_copy.erase(old_id);
586 20 : id_set_copy.insert(new_id);
587 : }
588 :
589 : // Store in new version of map
590 40 : new_elemset_codes_inverse_map.emplace(id_set_copy, elemset_code);
591 : }
592 :
593 : // Swap existing map with newly-built one
594 8 : _elemset_codes_inverse_map.swap(new_elemset_codes_inverse_map);
595 :
596 : // Reconstruct _elemset_codes map
597 8 : _elemset_codes.clear();
598 84 : for (const auto & [id_set, elemset_code] : _elemset_codes_inverse_map)
599 56 : _elemset_codes.emplace(elemset_code, &id_set);
600 :
601 : // Update _all_elemset_ids
602 8 : _all_elemset_ids.erase(old_id);
603 20 : _all_elemset_ids.insert(new_id);
604 : }
605 :
606 26524 : unsigned int MeshBase::spatial_dimension () const
607 : {
608 34830 : return cast_int<unsigned int>(_spatial_dimension);
609 : }
610 :
611 :
612 :
613 27666 : void MeshBase::set_spatial_dimension(unsigned char d)
614 : {
615 : // The user can set the _spatial_dimension however they wish,
616 : // libMesh will only *increase* the spatial dimension, however,
617 : // never decrease it.
618 27666 : _spatial_dimension = d;
619 27666 : }
620 :
621 :
622 :
623 492 : unsigned int MeshBase::add_elem_integer(std::string name,
624 : bool allocate_data,
625 : dof_id_type default_value)
626 : {
627 664 : for (auto i : index_range(_elem_integer_names))
628 136 : if (_elem_integer_names[i] == name)
629 : {
630 8 : libmesh_assert_less(i, _elem_integer_default_values.size());
631 28 : _elem_integer_default_values[i] = default_value;
632 28 : return i;
633 : }
634 :
635 136 : libmesh_assert_equal_to(_elem_integer_names.size(),
636 : _elem_integer_default_values.size());
637 464 : _elem_integer_names.push_back(std::move(name));
638 464 : _elem_integer_default_values.push_back(default_value);
639 464 : if (allocate_data)
640 388 : this->size_elem_extra_integers();
641 600 : return _elem_integer_names.size()-1;
642 : }
643 :
644 :
645 :
646 4029 : std::vector<unsigned int> MeshBase::add_elem_integers(const std::vector<std::string> & names,
647 : bool allocate_data,
648 : const std::vector<dof_id_type> * default_values)
649 : {
650 1216 : libmesh_assert(!default_values || default_values->size() == names.size());
651 1216 : libmesh_assert_equal_to(_elem_integer_names.size(), _elem_integer_default_values.size());
652 :
653 2432 : std::unordered_map<std::string, std::size_t> name_indices;
654 4113 : for (auto i : index_range(_elem_integer_names))
655 84 : name_indices[_elem_integer_names[i]] = i;
656 :
657 5221 : std::vector<unsigned int> returnval(names.size());
658 :
659 1216 : bool added_an_integer = false;
660 4294 : for (auto i : index_range(names))
661 : {
662 156 : const std::string & name = names[i];
663 265 : if (const auto it = name_indices.find(name);
664 78 : it != name_indices.end())
665 : {
666 42 : returnval[i] = it->second;
667 54 : _elem_integer_default_values[it->second] =
668 42 : default_values ? (*default_values)[i] : DofObject::invalid_id;
669 : }
670 : else
671 : {
672 289 : returnval[i] = _elem_integer_names.size();
673 223 : name_indices[name] = returnval[i];
674 223 : _elem_integer_names.push_back(name);
675 : _elem_integer_default_values.push_back
676 259 : (default_values ? (*default_values)[i] : DofObject::invalid_id);
677 66 : added_an_integer = true;
678 : }
679 : }
680 :
681 4029 : if (allocate_data && added_an_integer)
682 105 : this->size_elem_extra_integers();
683 :
684 5245 : return returnval;
685 : }
686 :
687 :
688 :
689 326 : unsigned int MeshBase::get_elem_integer_index(std::string_view name) const
690 : {
691 410 : for (auto i : index_range(_elem_integer_names))
692 317 : if (_elem_integer_names[i] == name)
693 326 : return i;
694 :
695 0 : libmesh_error_msg("Unknown elem integer " << name);
696 : return libMesh::invalid_uint;
697 : }
698 :
699 :
700 :
701 2631 : bool MeshBase::has_elem_integer(std::string_view name) const
702 : {
703 2729 : for (auto & entry : _elem_integer_names)
704 239 : if (entry == name)
705 40 : return true;
706 :
707 640 : return false;
708 : }
709 :
710 :
711 :
712 2284 : unsigned int MeshBase::add_node_integer(std::string name,
713 : bool allocate_data,
714 : dof_id_type default_value)
715 : {
716 4441 : for (auto i : index_range(_node_integer_names))
717 1440 : if (_node_integer_names[i] == name)
718 : {
719 16 : libmesh_assert_less(i, _node_integer_default_values.size());
720 56 : _node_integer_default_values[i] = default_value;
721 56 : return i;
722 : }
723 :
724 702 : libmesh_assert_equal_to(_node_integer_names.size(),
725 : _node_integer_default_values.size());
726 2228 : _node_integer_names.push_back(std::move(name));
727 2228 : _node_integer_default_values.push_back(default_value);
728 2228 : if (allocate_data)
729 720 : this->size_node_extra_integers();
730 2930 : return _node_integer_names.size()-1;
731 : }
732 :
733 :
734 :
735 4015 : std::vector<unsigned int> MeshBase::add_node_integers(const std::vector<std::string> & names,
736 : bool allocate_data,
737 : const std::vector<dof_id_type> * default_values)
738 : {
739 1212 : libmesh_assert(!default_values || default_values->size() == names.size());
740 1212 : libmesh_assert_equal_to(_node_integer_names.size(), _node_integer_default_values.size());
741 :
742 2424 : std::unordered_map<std::string, std::size_t> name_indices;
743 4071 : for (auto i : index_range(_node_integer_names))
744 56 : name_indices[_node_integer_names[i]] = i;
745 :
746 5203 : std::vector<unsigned int> returnval(names.size());
747 :
748 1212 : bool added_an_integer = false;
749 4343 : for (auto i : index_range(names))
750 : {
751 192 : const std::string & name = names[i];
752 328 : if (const auto it = name_indices.find(name);
753 96 : it != name_indices.end())
754 : {
755 0 : returnval[i] = it->second;
756 0 : _node_integer_default_values[it->second] =
757 0 : default_values ? (*default_values)[i] : DofObject::invalid_id;
758 : }
759 : else
760 : {
761 424 : returnval[i] = _node_integer_names.size();
762 328 : name_indices[name] = returnval[i];
763 328 : _node_integer_names.push_back(name);
764 : _node_integer_default_values.push_back
765 396 : (default_values ? (*default_values)[i] : DofObject::invalid_id);
766 96 : added_an_integer = true;
767 : }
768 : }
769 :
770 4015 : if (allocate_data && added_an_integer)
771 114 : this->size_node_extra_integers();
772 :
773 5227 : return returnval;
774 : }
775 :
776 :
777 :
778 70 : unsigned int MeshBase::get_node_integer_index(std::string_view name) const
779 : {
780 196 : for (auto i : index_range(_node_integer_names))
781 176 : if (_node_integer_names[i] == name)
782 70 : return i;
783 :
784 0 : libmesh_error_msg("Unknown node integer " << name);
785 : return libMesh::invalid_uint;
786 : }
787 :
788 :
789 :
790 112 : bool MeshBase::has_node_integer(std::string_view name) const
791 : {
792 318 : for (auto & entry : _node_integer_names)
793 318 : if (entry == name)
794 32 : return true;
795 :
796 0 : return false;
797 : }
798 :
799 :
800 :
801 4700 : void MeshBase::remove_orphaned_nodes ()
802 : {
803 2796 : LOG_SCOPE("remove_orphaned_nodes()", "MeshBase");
804 :
805 : // Will hold the set of nodes that are currently connected to elements
806 1398 : std::unordered_set<Node *> connected_nodes;
807 :
808 : // Loop over the elements. Find which nodes are connected to at
809 : // least one of them.
810 664368 : for (const auto & element : this->element_ptr_range())
811 4378528 : for (auto & n : element->node_ref_range())
812 3776551 : connected_nodes.insert(&n);
813 :
814 1750404 : for (const auto & node : this->node_ptr_range())
815 725862 : if (!connected_nodes.count(node))
816 9884 : this->delete_node(node);
817 :
818 4700 : _preparation.has_removed_orphaned_nodes = true;
819 4700 : }
820 :
821 :
822 :
823 : #ifdef LIBMESH_ENABLE_DEPRECATED
824 0 : void MeshBase::prepare_for_use (const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
825 : {
826 : libmesh_deprecated();
827 :
828 : // We only respect the users wish if they tell us to skip renumbering. If they tell us not to
829 : // skip renumbering but someone previously called allow_renumbering(false), then the latter takes
830 : // precedence
831 0 : if (skip_renumber_nodes_and_elements)
832 0 : this->allow_renumbering(false);
833 :
834 : // We always accept the user's value for skip_find_neighbors, in contrast to skip_renumber
835 0 : const bool old_allow_find_neighbors = this->allow_find_neighbors();
836 0 : this->allow_find_neighbors(!skip_find_neighbors);
837 :
838 0 : this->prepare_for_use();
839 :
840 0 : this->allow_find_neighbors(old_allow_find_neighbors);
841 0 : }
842 :
843 0 : void MeshBase::prepare_for_use (const bool skip_renumber_nodes_and_elements)
844 : {
845 : libmesh_deprecated();
846 :
847 : // We only respect the users wish if they tell us to skip renumbering. If they tell us not to
848 : // skip renumbering but someone previously called allow_renumbering(false), then the latter takes
849 : // precedence
850 0 : if (skip_renumber_nodes_and_elements)
851 0 : this->allow_renumbering(false);
852 :
853 0 : this->prepare_for_use();
854 0 : }
855 : #endif // LIBMESH_ENABLE_DEPRECATED
856 :
857 :
858 :
859 :
860 45187 : void MeshBase::prepare_for_use ()
861 : {
862 : // Mark everything as unprepared, except for those things we've been
863 : // told we don't need to prepare, for backwards compatibility
864 45187 : this->clear_point_locator();
865 45187 : this->clear_stored_ranges();
866 45187 : _preparation = false;
867 45187 : _preparation.has_neighbor_ptrs = _skip_find_neighbors;
868 45187 : _preparation.has_removed_remote_elements = !_allow_remote_element_removal;
869 :
870 45187 : this->complete_preparation();
871 45187 : }
872 :
873 :
874 64618 : void MeshBase::complete_preparation()
875 : {
876 37612 : LOG_SCOPE("complete_preparation()", "MeshBase");
877 :
878 18806 : parallel_object_only();
879 :
880 18806 : libmesh_assert(this->comm().verify(this->is_serial()));
881 :
882 : // If we don't go into this method with valid constraint rows, we're
883 : // only going to be able to make that worse.
884 : #ifdef DEBUG
885 18806 : MeshTools::libmesh_assert_valid_constraint_rows(*this);
886 : #endif
887 :
888 : // A distributed mesh may have processors with no elements (or
889 : // processors with no elements of higher dimension, if we ever
890 : // support mixed-dimension meshes), but we want consistent
891 : // mesh_dimension anyways.
892 : //
893 : // cache_elem_data() should get the elem_dimensions() and
894 : // mesh_dimension() correct later, and we don't need it earlier.
895 :
896 :
897 : // Renumber the nodes and elements so that they in contiguous
898 : // blocks. By default, _skip_renumber_nodes_and_elements is false.
899 : //
900 : // Instances where you if prepare_for_use() should not renumber the nodes
901 : // and elements include reading in e.g. an xda/r or gmv file. In
902 : // this case, the ordering of the nodes may depend on an accompanying
903 : // solution, and the node ordering cannot be changed.
904 :
905 :
906 : // Mesh modification operations might not leave us with consistent
907 : // id counts, or might leave us with orphaned nodes we're no longer
908 : // using, but our partitioner might need that consistency and/or
909 : // might be confused by orphaned nodes.
910 64618 : if (!_skip_renumber_nodes_and_elements)
911 : {
912 59680 : if (!_preparation.has_removed_orphaned_nodes ||
913 19172 : !_preparation.has_synched_id_counts)
914 40508 : this->renumber_nodes_and_elements();
915 : }
916 : else
917 : {
918 4938 : if (!_preparation.has_removed_orphaned_nodes)
919 4700 : this->remove_orphaned_nodes();
920 4938 : if (!_preparation.has_synched_id_counts)
921 4700 : this->update_parallel_id_counts();
922 : }
923 :
924 : // Let all the elements find their neighbors
925 64618 : if (!_skip_find_neighbors && !_preparation.has_neighbor_ptrs)
926 44008 : this->find_neighbors();
927 :
928 : // The user may have set boundary conditions. We require that the
929 : // boundary conditions were set consistently. Because we examine
930 : // neighbors when evaluating non-raw boundary condition IDs, this
931 : // assert is only valid when our neighbor links are in place.
932 : #ifdef DEBUG
933 18806 : MeshTools::libmesh_assert_valid_boundary_ids(*this);
934 : #endif
935 :
936 : // Search the mesh for all the dimensions of the elements
937 : // and cache them.
938 64618 : if (!_preparation.has_cached_elem_data)
939 63519 : this->cache_elem_data();
940 :
941 : // libMesh expects every processor to know about every subdomain
942 : // name, but distributed mesh generators may only have set names for
943 : // the part of the mesh they know about, so make sure the map is
944 : // consistent everywhere.
945 64618 : if (!_preparation.has_synched_subdomain_name_map)
946 45187 : this->sync_subdomain_name_map();
947 :
948 : // Search the mesh for elements that have a neighboring element
949 : // of dim+1 and set that element as the interior parent
950 64618 : if (!_preparation.has_interior_parent_ptrs)
951 : {
952 45187 : if (!_skip_detect_interior_parents)
953 45187 : this->detect_interior_parents();
954 : else
955 : {
956 : // We must set the flag that says "interior parent pointers have been set up"
957 : // even though we skip detect_interior_parents().
958 0 : _preparation.has_interior_parent_ptrs = true;
959 : }
960 : }
961 :
962 : // Fix up node unique ids in case mesh generation code didn't take
963 : // exceptional care to do so.
964 : // MeshCommunication().make_node_unique_ids_parallel_consistent(*this);
965 :
966 : // We're going to still require that mesh generation code gets
967 : // element unique ids consistent.
968 : #if defined(DEBUG) && defined(LIBMESH_ENABLE_UNIQUE_ID)
969 18806 : MeshTools::libmesh_assert_valid_unique_ids(*this);
970 : #endif
971 :
972 : // Allow our GhostingFunctor objects to reinit if necessary.
973 : // Do this before partitioning and redistributing, and before
974 : // deleting remote elements.
975 64618 : if (!_preparation.has_reinit_ghosting_functors)
976 45208 : this->reinit_ghosting_functors();
977 :
978 : // Partition the mesh unless *all* partitioning is to be skipped.
979 : // If only noncritical partitioning is to be skipped, the
980 : // partition() call will still check for orphaned nodes.
981 64618 : if (!skip_partitioning() && !_preparation.is_partitioned)
982 13142 : this->partition();
983 39562 : else if (!this->n_unpartitioned_elem() &&
984 5664 : !this->n_unpartitioned_nodes())
985 19781 : _preparation.is_partitioned = true;
986 :
987 : // If we're using DistributedMesh, we'll probably want it
988 : // parallelized.
989 64618 : if (this->_allow_remote_element_removal &&
990 62713 : !_preparation.has_removed_remote_elements)
991 43240 : this->delete_remote_elements();
992 : else
993 21378 : _preparation.has_removed_remote_elements = true;
994 :
995 : // Much of our boundary info may have been for now-remote parts of the mesh,
996 : // in which case we don't want to keep local copies of data meant to be
997 : // local. On the other hand we may have deleted, or the user may have added in
998 : // a distributed fashion, boundary data that is meant to be global. So we
999 : // handle both of those scenarios here
1000 64618 : if (!_preparation.has_boundary_id_sets)
1001 44018 : this->get_boundary_info().regenerate_id_sets();
1002 :
1003 64618 : if (!_skip_renumber_nodes_and_elements)
1004 59680 : this->renumber_nodes_and_elements();
1005 :
1006 : // The mesh is now prepared for use, with the possible exception of
1007 : // partitioning that was supposed to be skipped, and it should know
1008 : // it.
1009 : #ifndef NDEBUG
1010 18806 : Preparation completed_preparation = _preparation;
1011 18806 : if (skip_partitioning())
1012 192 : completed_preparation.is_partitioned = true;
1013 18806 : libmesh_assert(completed_preparation);
1014 : #endif
1015 :
1016 : #ifdef DEBUG
1017 18806 : MeshTools::libmesh_assert_valid_boundary_ids(*this);
1018 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
1019 18806 : MeshTools::libmesh_assert_valid_unique_ids(*this);
1020 : #endif
1021 : #endif
1022 64618 : }
1023 :
1024 : void
1025 45208 : MeshBase::reinit_ghosting_functors()
1026 : {
1027 101976 : for (auto & gf : _ghosting_functors)
1028 : {
1029 16798 : libmesh_assert(gf);
1030 56768 : gf->mesh_reinit();
1031 : }
1032 :
1033 45208 : _preparation.has_reinit_ghosting_functors = true;
1034 45208 : }
1035 :
1036 104891 : void MeshBase::clear ()
1037 : {
1038 : // Reset the number of partitions
1039 104891 : _n_parts = 1;
1040 :
1041 : // Reset the preparation flags
1042 104891 : _preparation = false;
1043 :
1044 : // Clear boundary information
1045 104891 : if (boundary_info)
1046 104765 : boundary_info->clear();
1047 :
1048 : // Clear cached element data
1049 30781 : _elem_dims.clear();
1050 30781 : _elem_default_orders.clear();
1051 104891 : _supported_nodal_order = MAXIMUM;
1052 :
1053 30781 : _elemset_codes.clear();
1054 30781 : _elemset_codes_inverse_map.clear();
1055 :
1056 30781 : _constraint_rows.clear();
1057 :
1058 : // Clear our point locator.
1059 104891 : this->clear_point_locator();
1060 104891 : this->clear_stored_ranges();
1061 104891 : }
1062 :
1063 :
1064 33346 : bool MeshBase::is_prepared() const
1065 : {
1066 33346 : return static_cast<bool>(_preparation);
1067 : }
1068 :
1069 :
1070 203 : void MeshBase::unset_is_prepared()
1071 : {
1072 203 : _preparation = false;
1073 203 : this->clear_point_locator();
1074 203 : this->clear_stored_ranges();
1075 203 : }
1076 :
1077 :
1078 99577 : void MeshBase::add_ghosting_functor(GhostingFunctor & ghosting_functor)
1079 : {
1080 : // We used to implicitly support duplicate inserts to std::set
1081 : #ifdef LIBMESH_ENABLE_DEPRECATED
1082 : _ghosting_functors.erase
1083 42205 : (std::remove(_ghosting_functors.begin(),
1084 : _ghosting_functors.end(),
1085 99577 : &ghosting_functor),
1086 86058 : _ghosting_functors.end());
1087 : #endif
1088 :
1089 : // We shouldn't have two copies of the same functor
1090 28686 : libmesh_assert(std::find(_ghosting_functors.begin(),
1091 : _ghosting_functors.end(),
1092 : &ghosting_functor) ==
1093 : _ghosting_functors.end());
1094 :
1095 99577 : _ghosting_functors.push_back(&ghosting_functor);
1096 99577 : }
1097 :
1098 :
1099 :
1100 96299 : void MeshBase::remove_ghosting_functor(GhostingFunctor & ghosting_functor)
1101 : {
1102 40951 : auto raw_it = std::find(_ghosting_functors.begin(),
1103 123973 : _ghosting_functors.end(), &ghosting_functor);
1104 :
1105 : // The DofMap has a "to_mesh" parameter that tells it to avoid
1106 : // registering a new functor with the mesh, but it doesn't keep
1107 : // track of which functors weren't added, so we'll support "remove a
1108 : // functor that isn't there" just like we did with set::erase
1109 : // before.
1110 96299 : if (raw_it != _ghosting_functors.end())
1111 96208 : _ghosting_functors.erase(raw_it);
1112 :
1113 : // We shouldn't have had two copies of the same functor
1114 27674 : libmesh_assert(std::find(_ghosting_functors.begin(),
1115 : _ghosting_functors.end(),
1116 : &ghosting_functor) ==
1117 : _ghosting_functors.end());
1118 :
1119 96299 : if (const auto it = _shared_functors.find(&ghosting_functor);
1120 27674 : it != _shared_functors.end())
1121 5 : _shared_functors.erase(it);
1122 96299 : }
1123 :
1124 :
1125 :
1126 3672 : void MeshBase::subdomain_ids (std::set<subdomain_id_type> & ids, const bool global /* = true */) const
1127 : {
1128 : // This requires an inspection on every processor
1129 1298 : if (global)
1130 1298 : parallel_object_only();
1131 :
1132 34 : struct SBDInserter {
1133 : std::set<subdomain_id_type> my_ids;
1134 :
1135 1298 : SBDInserter () {}
1136 36 : SBDInserter (SBDInserter &, Threads::split) {}
1137 :
1138 3778 : void operator()(const ConstElemRange & range) {
1139 696331 : for (const Elem * elem : range)
1140 692553 : my_ids.insert(elem->subdomain_id());
1141 3778 : }
1142 :
1143 36 : void join(SBDInserter & other) {
1144 36 : my_ids.merge(other.my_ids);
1145 36 : }
1146 : };
1147 :
1148 2596 : SBDInserter inserter;
1149 3672 : Threads::parallel_reduce(this->active_local_element_stored_range(), inserter);
1150 :
1151 1298 : ids.swap(inserter.my_ids);
1152 :
1153 3672 : if (global)
1154 : {
1155 : // Only include the unpartitioned elements if the user requests the global IDs.
1156 : // In the case of the local subdomain IDs, it doesn't make sense to include the
1157 : // unpartitioned elements because said elements do not have a sense of locality.
1158 9520 : for (const auto & elem : this->active_unpartitioned_element_ptr_range())
1159 4550 : ids.insert(elem->subdomain_id());
1160 :
1161 : // Some subdomains may only live on other processors
1162 3672 : this->comm().set_union(ids);
1163 : }
1164 3672 : }
1165 :
1166 :
1167 :
1168 43038 : void MeshBase::redistribute()
1169 : {
1170 : // We now have all elements and nodes redistributed; our ghosting
1171 : // functors should be ready to redistribute and/or recompute any
1172 : // cached data they use too.
1173 46210 : for (auto & gf : as_range(this->ghosting_functors_begin(),
1174 124759 : this->ghosting_functors_end()))
1175 52409 : gf->redistribute();
1176 43038 : }
1177 :
1178 :
1179 :
1180 29467 : void MeshBase::update_post_partitioning()
1181 : {
1182 : // A range over all elements might still be fine here, but any range
1183 : // over local elements is obsolete if our partitioner changed the
1184 : // definition of "local".
1185 9882 : _const_active_local_element_stored_range.reset(nullptr);
1186 29467 : }
1187 :
1188 :
1189 :
1190 2031 : subdomain_id_type MeshBase::n_subdomains() const
1191 : {
1192 : // This requires an inspection on every processor
1193 596 : parallel_object_only();
1194 :
1195 1192 : std::set<subdomain_id_type> ids;
1196 :
1197 2031 : this->subdomain_ids (ids);
1198 :
1199 2627 : return cast_int<subdomain_id_type>(ids.size());
1200 : }
1201 :
1202 :
1203 :
1204 0 : subdomain_id_type MeshBase::n_local_subdomains() const
1205 : {
1206 0 : std::set<subdomain_id_type> ids;
1207 :
1208 0 : this->subdomain_ids (ids, /* global = */ false);
1209 :
1210 0 : return cast_int<subdomain_id_type>(ids.size());
1211 : }
1212 :
1213 :
1214 :
1215 :
1216 34795 : dof_id_type MeshBase::n_nodes_on_proc (const processor_id_type proc_id) const
1217 : {
1218 : // We're either counting a processor's nodes or unpartitioned
1219 : // nodes
1220 11340 : libmesh_assert (proc_id < this->n_processors() ||
1221 : proc_id == DofObject::invalid_processor_id);
1222 :
1223 58250 : return static_cast<dof_id_type>(std::distance (this->pid_nodes_begin(proc_id),
1224 93045 : this->pid_nodes_end (proc_id)));
1225 : }
1226 :
1227 :
1228 :
1229 79675 : dof_id_type MeshBase::n_elem_on_proc (const processor_id_type proc_id) const
1230 : {
1231 : // We're either counting a processor's elements or unpartitioned
1232 : // elements
1233 24492 : libmesh_assert (proc_id < this->n_processors() ||
1234 : proc_id == DofObject::invalid_processor_id);
1235 :
1236 134858 : return static_cast<dof_id_type>(std::distance (this->pid_elements_begin(proc_id),
1237 214533 : this->pid_elements_end (proc_id)));
1238 : }
1239 :
1240 :
1241 :
1242 5981 : dof_id_type MeshBase::n_active_elem_on_proc (const processor_id_type proc_id) const
1243 : {
1244 2184 : libmesh_assert_less (proc_id, this->n_processors());
1245 9778 : return static_cast<dof_id_type>(std::distance (this->active_pid_elements_begin(proc_id),
1246 15759 : this->active_pid_elements_end (proc_id)));
1247 : }
1248 :
1249 :
1250 :
1251 0 : dof_id_type MeshBase::n_sub_elem () const
1252 : {
1253 0 : dof_id_type ne=0;
1254 :
1255 0 : for (const auto & elem : this->element_ptr_range())
1256 0 : ne += elem->n_sub_elem();
1257 :
1258 0 : return ne;
1259 : }
1260 :
1261 :
1262 :
1263 4210 : dof_id_type MeshBase::n_active_sub_elem () const
1264 : {
1265 1575 : dof_id_type ne=0;
1266 :
1267 2296668 : for (const auto & elem : this->active_element_ptr_range())
1268 2290883 : ne += elem->n_sub_elem();
1269 :
1270 4210 : return ne;
1271 : }
1272 :
1273 :
1274 :
1275 1424 : std::string MeshBase::get_info(const unsigned int verbosity /* = 0 */, const bool global /* = true */) const
1276 : {
1277 2264 : std::ostringstream oss;
1278 :
1279 1424 : oss << " Mesh Information:" << '\n';
1280 :
1281 1424 : if (!_elem_dims.empty())
1282 : {
1283 1424 : oss << " elem_dimensions()={";
1284 1424 : std::copy(_elem_dims.begin(),
1285 420 : --_elem_dims.end(), // --end() is valid if the set is non-empty
1286 1004 : std::ostream_iterator<unsigned int>(oss, ", "));
1287 1424 : oss << cast_int<unsigned int>(*_elem_dims.rbegin());
1288 1424 : oss << "}";
1289 1424 : if (!this->preparation().has_cached_elem_data)
1290 0 : oss << " (may be out of date)";
1291 1424 : oss << '\n';
1292 : }
1293 :
1294 1424 : if (!_elem_default_orders.empty())
1295 : {
1296 1424 : oss << " elem_default_orders()={";
1297 1424 : std::transform(_elem_default_orders.begin(),
1298 420 : --_elem_default_orders.end(),
1299 1424 : std::ostream_iterator<std::string>(oss, ", "),
1300 8 : [](Order o)
1301 20 : { return Utility::enum_to_string<Order>(o); });
1302 1424 : oss << Utility::enum_to_string<Order>(*_elem_default_orders.rbegin());
1303 1424 : oss << "}";
1304 1424 : if (!this->preparation().has_cached_elem_data)
1305 0 : oss << " (may be out of date)";
1306 1424 : oss << '\n';
1307 : }
1308 :
1309 1424 : oss << " supported_nodal_order()=" << this->_supported_nodal_order;
1310 1424 : if (!this->preparation().has_cached_elem_data)
1311 0 : oss << " (may be out of date)";
1312 1424 : oss << '\n';
1313 :
1314 1424 : oss << " spatial_dimension()=" << int(this->_spatial_dimension);
1315 1424 : if (!this->preparation().has_cached_elem_data)
1316 0 : oss << " (may be out of date)";
1317 1424 : oss << '\n';
1318 :
1319 1424 : oss << " n_nodes()=" << this->n_nodes() << '\n'
1320 1424 : << " n_local_nodes()=" << this->n_local_nodes() << '\n'
1321 1844 : << " n_elem()=" << this->n_elem() << '\n'
1322 2428 : << " n_local_elem()=" << this->n_local_elem() << '\n';
1323 : #ifdef LIBMESH_ENABLE_AMR
1324 2008 : oss << " n_active_elem()=" << this->n_active_elem() << '\n';
1325 : #endif
1326 1424 : if (global)
1327 1844 : oss << " n_subdomains()=" << static_cast<std::size_t>(this->n_subdomains()) << '\n';
1328 : else
1329 0 : oss << " n_local_subdomains()= " << static_cast<std::size_t>(this->n_local_subdomains()) << '\n';
1330 1844 : oss << " n_elemsets()=" << static_cast<std::size_t>(this->n_elemsets()) << '\n';
1331 1424 : if (!_elemset_codes.empty())
1332 0 : oss << " n_elemset_codes=" << _elemset_codes.size() << '\n';
1333 1424 : oss << " n_partitions()=" << static_cast<std::size_t>(this->n_partitions()) << '\n'
1334 2264 : << " n_processors()=" << static_cast<std::size_t>(this->n_processors()) << '\n'
1335 1844 : << " n_threads()=" << static_cast<std::size_t>(libMesh::n_threads()) << '\n'
1336 2264 : << " processor_id()=" << static_cast<std::size_t>(this->processor_id()) << '\n'
1337 1844 : << " is_prepared()=" << (this->is_prepared() ? "true" : "false") << '\n'
1338 3272 : << " is_replicated()=" << (this->is_replicated() ? "true" : "false") << '\n';
1339 :
1340 1424 : if (verbosity > 0)
1341 : {
1342 28 : if (global)
1343 : {
1344 8 : libmesh_parallel_only(this->comm());
1345 36 : if (this->processor_id() != 0)
1346 12 : oss << "\n Detailed global get_info() (verbosity > 0) is reduced and output to only rank 0.";
1347 : }
1348 :
1349 : // Helper for printing element types
1350 224 : const auto elem_type_helper = [](const std::set<int> & elem_types) {
1351 336 : std::stringstream ss;
1352 448 : for (auto it = elem_types.begin(); it != elem_types.end();)
1353 : {
1354 392 : ss << Utility::enum_to_string((ElemType)*it);
1355 224 : if (++it != elem_types.end())
1356 0 : ss << ", ";
1357 : }
1358 280 : return ss.str();
1359 112 : };
1360 :
1361 : // Helper for whether or not the given DofObject is to be included. If we're doing
1362 : // a global reduction, we also count unpartitioned objects on rank 0.
1363 248680 : const auto include_object = [this, &global](const DofObject & dof_object) {
1364 355712 : return this->processor_id() == dof_object.processor_id() ||
1365 48840 : (global &&
1366 31744 : this->processor_id() == 0 &&
1367 223852 : dof_object.processor_id() == DofObject::invalid_processor_id);
1368 20 : };
1369 :
1370 8 : Real volume = 0;
1371 :
1372 : // Add bounding box information
1373 28 : const auto bbox = global ? MeshTools::create_bounding_box(*this) : MeshTools::create_local_bounding_box(*this);
1374 28 : if (!global || this->processor_id() == 0)
1375 : oss << "\n " << (global ? "" : "Local ") << "Mesh Bounding Box:\n"
1376 16 : << " Minimum: " << bbox.min() << "\n"
1377 12 : << " Maximum: " << bbox.max() << "\n"
1378 24 : << " Delta: " << (bbox.max() - bbox.min()) << "\n";
1379 :
1380 : // Obtain the global or local element types
1381 16 : std::set<int> elem_types;
1382 16432 : for (const Elem * elem : this->active_local_element_ptr_range())
1383 16396 : elem_types.insert(elem->type());
1384 28 : if (global)
1385 : {
1386 : // Pick up unpartitioned elems on rank 0
1387 36 : if (this->processor_id() == 0)
1388 28 : for (const Elem * elem : this->active_unpartitioned_element_ptr_range())
1389 8 : elem_types.insert(elem->type());
1390 :
1391 28 : this->comm().set_union(elem_types);
1392 : }
1393 :
1394 : // Add element types
1395 28 : if (!global || this->processor_id() == 0)
1396 : oss << "\n " << (global ? "" : "Local ") << "Mesh Element Type(s):\n "
1397 44 : << elem_type_helper(elem_types) << "\n";
1398 :
1399 : // Reduce the nodeset ids
1400 16 : auto nodeset_ids = this->get_boundary_info().get_node_boundary_ids();
1401 28 : if (global)
1402 28 : this->comm().set_union(nodeset_ids);
1403 :
1404 : // Accumulate local information for each nodeset
1405 72 : struct NodesetInfo
1406 : {
1407 : std::size_t num_nodes = 0;
1408 : BoundingBox bbox;
1409 : };
1410 16 : std::map<boundary_id_type, NodesetInfo> nodeset_info_map;
1411 28420 : for (const auto & [node, id] : this->get_boundary_info().get_nodeset_map())
1412 : {
1413 28392 : if (!include_object(*node))
1414 8112 : continue;
1415 :
1416 16224 : NodesetInfo & info = nodeset_info_map[id];
1417 :
1418 16224 : ++info.num_nodes;
1419 :
1420 16224 : if (verbosity > 1)
1421 16224 : info.bbox.union_with(*node);
1422 : }
1423 :
1424 : // Add nodeset info
1425 28 : if (!global || this->processor_id() == 0)
1426 : {
1427 16 : oss << "\n " << (global ? "" : "Local ") << "Mesh Nodesets:\n";
1428 16 : if (nodeset_ids.empty())
1429 0 : oss << " None\n";
1430 : }
1431 :
1432 8 : const auto & nodeset_name_map = this->get_boundary_info().get_nodeset_name_map();
1433 196 : for (const auto id : nodeset_ids)
1434 : {
1435 168 : NodesetInfo & info = nodeset_info_map[id];
1436 :
1437 : // Reduce the local information for this nodeset if required
1438 168 : if (global)
1439 : {
1440 168 : this->comm().sum(info.num_nodes);
1441 168 : if (verbosity > 1)
1442 : {
1443 216 : this->comm().min(info.bbox.min());
1444 216 : this->comm().max(info.bbox.max());
1445 : }
1446 : }
1447 :
1448 168 : const bool has_name = nodeset_name_map.count(id) && nodeset_name_map.at(id).size();
1449 264 : const std::string name = has_name ? nodeset_name_map.at(id) : "";
1450 96 : if (global)
1451 48 : libmesh_assert(this->comm().verify(name));
1452 :
1453 168 : if (global ? this->processor_id() == 0 : info.num_nodes > 0)
1454 : {
1455 96 : oss << " Nodeset " << id;
1456 96 : if (has_name)
1457 144 : oss << " (" << name << ")";
1458 120 : oss << ", " << info.num_nodes << " " << (global ? "" : "local ") << "nodes\n";
1459 :
1460 96 : if (verbosity > 1)
1461 : {
1462 96 : oss << " " << (global ? "Bounding" : "Local bounding") << " box minimum: "
1463 96 : << info.bbox.min() << "\n"
1464 96 : << " " << (global ? "Bounding" : "Local bounding") << " box maximum: "
1465 96 : << info.bbox.max() << "\n"
1466 96 : << " " << (global ? "Bounding" : "Local bounding") << " box delta: "
1467 96 : << (info.bbox.max() - info.bbox.min()) << "\n";
1468 : }
1469 : }
1470 : }
1471 :
1472 : // Reduce the sideset ids
1473 16 : auto sideset_ids = this->get_boundary_info().get_side_boundary_ids();
1474 28 : if (global)
1475 28 : this->comm().set_union(sideset_ids);
1476 :
1477 : // Accumulate local information for each sideset
1478 : struct SidesetInfo
1479 : {
1480 : std::size_t num_sides = 0;
1481 : Real volume = 0;
1482 : std::set<int> side_elem_types;
1483 : std::set<int> elem_types;
1484 : std::set<dof_id_type> elem_ids;
1485 : std::set<dof_id_type> node_ids;
1486 : BoundingBox bbox;
1487 : };
1488 16 : ElemSideBuilder side_builder;
1489 16 : std::map<boundary_id_type, SidesetInfo> sideset_info_map;
1490 23324 : for (const auto & pair : this->get_boundary_info().get_sideset_map())
1491 : {
1492 23296 : const Elem * elem = pair.first;
1493 16640 : if (!include_object(*elem))
1494 9984 : continue;
1495 :
1496 13312 : const auto id = pair.second.second;
1497 13312 : SidesetInfo & info = sideset_info_map[id];
1498 :
1499 13312 : const auto s = pair.second.first;
1500 13312 : const Elem & side = side_builder(*elem, s);
1501 :
1502 13312 : ++info.num_sides;
1503 13312 : info.side_elem_types.insert(side.type());
1504 13312 : info.elem_types.insert(elem->type());
1505 13312 : info.elem_ids.insert(elem->id());
1506 :
1507 66560 : for (const Node & node : side.node_ref_range())
1508 39936 : if (include_object(node))
1509 52672 : info.node_ids.insert(node.id());
1510 :
1511 13312 : if (verbosity > 1)
1512 : {
1513 13312 : info.volume += side.volume();
1514 13312 : info.bbox.union_with(side.loose_bounding_box());
1515 : }
1516 : }
1517 :
1518 : // Add sideset info
1519 28 : if (!global || this->processor_id() == 0)
1520 : {
1521 16 : oss << "\n " << (global ? "" : "Local ") << "Mesh Sidesets:\n";
1522 16 : if (sideset_ids.empty())
1523 0 : oss << " None\n";
1524 : }
1525 8 : const auto & sideset_name_map = this->get_boundary_info().get_sideset_name_map();
1526 196 : for (const auto id : sideset_ids)
1527 : {
1528 168 : SidesetInfo & info = sideset_info_map[id];
1529 :
1530 168 : auto num_elems = info.elem_ids.size();
1531 168 : auto num_nodes = info.node_ids.size();
1532 :
1533 : // Reduce the local information for this sideset if required
1534 168 : if (global)
1535 : {
1536 168 : this->comm().sum(info.num_sides);
1537 168 : this->comm().set_union(info.side_elem_types, 0);
1538 168 : this->comm().sum(num_elems);
1539 168 : this->comm().set_union(info.elem_types, 0);
1540 168 : this->comm().sum(num_nodes);
1541 168 : if (verbosity > 1)
1542 : {
1543 168 : this->comm().sum(info.volume);
1544 216 : this->comm().min(info.bbox.min());
1545 216 : this->comm().max(info.bbox.max());
1546 : }
1547 : }
1548 :
1549 168 : const bool has_name = sideset_name_map.count(id) && sideset_name_map.at(id).size();
1550 264 : const std::string name = has_name ? sideset_name_map.at(id) : "";
1551 96 : if (global)
1552 48 : libmesh_assert(this->comm().verify(name));
1553 :
1554 168 : if (global ? this->processor_id() == 0 : info.num_sides > 0)
1555 : {
1556 96 : oss << " Sideset " << id;
1557 96 : if (has_name)
1558 144 : oss << " (" << name << ")";
1559 168 : oss << ", " << info.num_sides << " sides (" << elem_type_helper(info.side_elem_types) << ")"
1560 288 : << ", " << num_elems << " " << (global ? "" : "local ") << "elems (" << elem_type_helper(info.elem_types) << ")"
1561 216 : << ", " << num_nodes << " " << (global ? "" : "local ") << "nodes\n";
1562 :
1563 96 : if (verbosity > 1)
1564 : {
1565 120 : oss << " " << (global ? "Side" : "Local side") << " volume: " << info.volume << "\n"
1566 96 : << " " << (global ? "Bounding" : "Local bounding") << " box minimum: "
1567 96 : << info.bbox.min() << "\n"
1568 96 : << " " << (global ? "Bounding" : "Local bounding") << " box maximum: "
1569 96 : << info.bbox.max() << "\n"
1570 96 : << " " << (global ? "Bounding" : "Local bounding") << " box delta: "
1571 96 : << (info.bbox.max() - info.bbox.min()) << "\n";
1572 : }
1573 : }
1574 : }
1575 :
1576 : // Reduce the edgeset ids
1577 16 : auto edgeset_ids = this->get_boundary_info().get_edge_boundary_ids();
1578 28 : if (global)
1579 28 : this->comm().set_union(edgeset_ids);
1580 :
1581 : // Accumulate local information for each edgeset
1582 0 : struct EdgesetInfo
1583 : {
1584 : std::size_t num_edges = 0;
1585 : std::set<int> edge_elem_types;
1586 : BoundingBox bbox;
1587 : };
1588 16 : std::map<boundary_id_type, EdgesetInfo> edgeset_info_map;
1589 28 : std::unique_ptr<const Elem> edge;
1590 :
1591 28 : for (const auto & pair : this->get_boundary_info().get_edgeset_map())
1592 : {
1593 0 : const Elem * elem = pair.first;
1594 0 : if (!include_object(*elem))
1595 0 : continue;
1596 :
1597 0 : const auto id = pair.second.second;
1598 0 : EdgesetInfo & info = edgeset_info_map[id];
1599 :
1600 0 : elem->build_edge_ptr(edge, pair.second.first);
1601 :
1602 0 : ++info.num_edges;
1603 0 : info.edge_elem_types.insert(edge->type());
1604 :
1605 0 : if (verbosity > 1)
1606 0 : info.bbox.union_with(edge->loose_bounding_box());
1607 : }
1608 :
1609 : // Add edgeset info
1610 28 : if (!global || this->processor_id() == 0)
1611 : {
1612 16 : oss << "\n " << (global ? "" : "Local ") << "Mesh Edgesets:\n";
1613 16 : if (edgeset_ids.empty())
1614 16 : oss << " None\n";
1615 : }
1616 :
1617 8 : const auto & edgeset_name_map = this->get_boundary_info().get_edgeset_name_map();
1618 28 : for (const auto id : edgeset_ids)
1619 : {
1620 0 : EdgesetInfo & info = edgeset_info_map[id];
1621 :
1622 : // Reduce the local information for this edgeset if required
1623 0 : if (global)
1624 : {
1625 0 : this->comm().sum(info.num_edges);
1626 0 : this->comm().set_union(info.edge_elem_types, 0);
1627 0 : if (verbosity > 1)
1628 : {
1629 0 : this->comm().min(info.bbox.min());
1630 0 : this->comm().min(info.bbox.max());
1631 : }
1632 : }
1633 :
1634 0 : const bool has_name = edgeset_name_map.count(id) && edgeset_name_map.at(id).size();
1635 0 : const std::string name = has_name ? edgeset_name_map.at(id) : "";
1636 0 : if (global)
1637 0 : libmesh_assert(this->comm().verify(name));
1638 :
1639 0 : if (global ? this->processor_id() == 0 : info.num_edges > 0)
1640 : {
1641 0 : oss << " Edgeset " << id;
1642 0 : if (has_name)
1643 0 : oss << " (" << name << ")";
1644 0 : oss << ", " << info.num_edges << " " << (global ? "" : "local ") << "edges ("
1645 0 : << elem_type_helper(info.edge_elem_types) << ")\n";
1646 :
1647 0 : if (verbosity > 1)
1648 : {
1649 0 : oss << " " << (global ? "Bounding" : "Local bounding") << " box minimum: "
1650 0 : << info.bbox.min() << "\n"
1651 0 : << " " << (global ? "Bounding" : "Local bounding") << " box maximum: "
1652 0 : << info.bbox.max() << "\n"
1653 0 : << " " << (global ? "Bounding" : "Local bounding") << " box delta: "
1654 0 : << (info.bbox.max() - info.bbox.min()) << "\n";
1655 : }
1656 : }
1657 : }
1658 :
1659 : // Reduce the block IDs and block names
1660 16 : std::set<subdomain_id_type> subdomains;
1661 49200 : for (const Elem * elem : this->active_element_ptr_range())
1662 20480 : if (include_object(*elem))
1663 16396 : subdomains.insert(elem->subdomain_id());
1664 28 : if (global)
1665 28 : this->comm().set_union(subdomains);
1666 :
1667 : // Accumulate local information for each subdomain
1668 0 : struct SubdomainInfo
1669 : {
1670 : std::size_t num_elems = 0;
1671 : Real volume = 0;
1672 : std::set<int> elem_types;
1673 : std::set<dof_id_type> active_node_ids;
1674 : #ifdef LIBMESH_ENABLE_AMR
1675 : std::size_t num_active_elems = 0;
1676 : #endif
1677 : BoundingBox bbox;
1678 : };
1679 16 : std::map<subdomain_id_type, SubdomainInfo> subdomain_info_map;
1680 49200 : for (const Elem * elem : this->element_ptr_range())
1681 20480 : if (include_object(*elem))
1682 : {
1683 16384 : SubdomainInfo & info = subdomain_info_map[elem->subdomain_id()];
1684 :
1685 16384 : ++info.num_elems;
1686 16384 : info.elem_types.insert(elem->type());
1687 :
1688 : #ifdef LIBMESH_ENABLE_AMR
1689 4096 : if (elem->active())
1690 16384 : ++info.num_active_elems;
1691 : #endif
1692 :
1693 147456 : for (const Node & node : elem->node_ref_range())
1694 130560 : if (include_object(node) && node.active())
1695 129536 : info.active_node_ids.insert(node.id());
1696 :
1697 16384 : if (verbosity > 1 && elem->active())
1698 : {
1699 16384 : info.volume += elem->volume();
1700 16384 : info.bbox.union_with(elem->loose_bounding_box());
1701 : }
1702 12 : }
1703 :
1704 : // Add subdomain info
1705 28 : oss << "\n " << (global ? "" : "Local ") << "Mesh Subdomains:\n";
1706 8 : const auto & subdomain_name_map = this->get_subdomain_name_map();
1707 56 : for (const auto id : subdomains)
1708 : {
1709 28 : SubdomainInfo & info = subdomain_info_map[id];
1710 :
1711 28 : auto num_active_nodes = info.active_node_ids.size();
1712 :
1713 : // Reduce the information for this subdomain if needed
1714 28 : if (global)
1715 : {
1716 28 : this->comm().sum(info.num_elems);
1717 : #ifdef LIBMESH_ENABLE_AMR
1718 28 : this->comm().sum(info.num_active_elems);
1719 : #endif
1720 28 : this->comm().sum(num_active_nodes);
1721 28 : this->comm().set_union(info.elem_types, 0);
1722 28 : if (verbosity > 1)
1723 : {
1724 36 : this->comm().min(info.bbox.min());
1725 36 : this->comm().max(info.bbox.max());
1726 28 : this->comm().sum(info.volume);
1727 : }
1728 : }
1729 28 : if (verbosity > 1)
1730 28 : volume += info.volume;
1731 :
1732 8 : const bool has_name = subdomain_name_map.count(id);
1733 36 : const std::string name = has_name ? subdomain_name_map.at(id) : "";
1734 16 : if (global)
1735 8 : libmesh_assert(this->comm().verify(name));
1736 :
1737 28 : if (!global || this->processor_id() == 0)
1738 : {
1739 16 : oss << " Subdomain " << id;
1740 16 : if (has_name)
1741 0 : oss << " (" << name << ")";
1742 16 : oss << ": " << info.num_elems << " " << (global ? "" : "local ") << "elems "
1743 24 : << "(" << elem_type_helper(info.elem_types);
1744 : #ifdef LIBMESH_ENABLE_AMR
1745 16 : oss << ", " << info.num_active_elems << " active";
1746 : #endif
1747 20 : oss << "), " << num_active_nodes << " " << (global ? "" : "local ") << "active nodes\n";
1748 16 : if (verbosity > 1)
1749 : {
1750 20 : oss << " " << (global ? "Volume" : "Local volume") << ": " << info.volume << "\n";
1751 16 : oss << " " << (global ? "Bounding" : "Local bounding") << " box minimum: "
1752 16 : << info.bbox.min() << "\n"
1753 16 : << " " << (global ? "Bounding" : "Local bounding") << " box maximum: "
1754 16 : << info.bbox.max() << "\n"
1755 16 : << " " << (global ? "Bounding" : "Local bounding") << " box delta: "
1756 16 : << (info.bbox.max() - info.bbox.min()) << "\n";
1757 : }
1758 : }
1759 : }
1760 :
1761 48 : oss << " " << (global ? "Global" : "Local") << " mesh volume = " << volume << "\n";
1762 :
1763 12 : }
1764 :
1765 1844 : return oss.str();
1766 584 : }
1767 :
1768 :
1769 1424 : void MeshBase::print_info(std::ostream & os, const unsigned int verbosity /* = 0 */, const bool global /* = true */) const
1770 : {
1771 1844 : os << this->get_info(verbosity, global)
1772 420 : << std::endl;
1773 1424 : }
1774 :
1775 :
1776 0 : std::ostream & operator << (std::ostream & os, const MeshBase & m)
1777 : {
1778 0 : m.print_info(os);
1779 0 : return os;
1780 : }
1781 :
1782 :
1783 44921 : void MeshBase::partition (const unsigned int n_parts)
1784 : {
1785 : // If we get here and we have unpartitioned elements, we need that
1786 : // fixed.
1787 44921 : if (this->n_unpartitioned_elem() > 0)
1788 : {
1789 9576 : libmesh_assert (partitioner().get());
1790 9576 : libmesh_assert (this->is_serial());
1791 32784 : partitioner()->partition (*this, n_parts);
1792 : }
1793 : // A nullptr partitioner or a skip_partitioning(true) call or a
1794 : // skip_noncritical_partitioning(true) call means don't repartition;
1795 : // skip_noncritical_partitioning() checks all these.
1796 3590 : else if (!skip_noncritical_partitioning())
1797 : {
1798 11552 : partitioner()->partition (*this, n_parts);
1799 : }
1800 : else
1801 : {
1802 : // Adaptive coarsening may have "orphaned" nodes on processors
1803 : // whose elements no longer share them. We need to check for
1804 : // and possibly fix that.
1805 585 : MeshTools::correct_node_proc_ids(*this);
1806 :
1807 : // Make sure locally cached partition count is correct
1808 585 : this->recalculate_n_partitions();
1809 :
1810 : // Make sure any other locally cached data is correct
1811 585 : this->update_post_partitioning();
1812 : }
1813 :
1814 44921 : _preparation.is_partitioned = true;
1815 44921 : }
1816 :
1817 1916 : void MeshBase::all_second_order (const bool full_ordered)
1818 : {
1819 1916 : this->all_second_order_range(this->element_ptr_range(), full_ordered);
1820 1916 : }
1821 :
1822 1509 : void MeshBase::all_complete_order ()
1823 : {
1824 1509 : this->all_complete_order_range(this->element_ptr_range());
1825 1509 : }
1826 :
1827 585 : unsigned int MeshBase::recalculate_n_partitions()
1828 : {
1829 : // This requires an inspection on every processor
1830 170 : parallel_object_only();
1831 :
1832 585 : unsigned int max_proc_id=0;
1833 :
1834 69322 : for (const auto & elem : this->active_local_element_ptr_range())
1835 68725 : max_proc_id = std::max(max_proc_id, static_cast<unsigned int>(elem->processor_id()));
1836 :
1837 : // The number of partitions is one more than the max processor ID.
1838 585 : _n_parts = max_proc_id+1;
1839 :
1840 585 : this->comm().max(_n_parts);
1841 :
1842 585 : return _n_parts;
1843 : }
1844 :
1845 :
1846 :
1847 181005 : std::unique_ptr<PointLocatorBase> MeshBase::sub_point_locator () const
1848 : {
1849 : // If there's no master point locator, then we need one.
1850 181005 : if (_point_locator.get() == nullptr)
1851 : {
1852 : // PointLocator construction may not be safe within threads
1853 760 : libmesh_assert(!Threads::in_threads);
1854 :
1855 : // And it may require parallel communication
1856 760 : parallel_object_only();
1857 :
1858 : #ifdef LIBMESH_ENABLE_NANOFLANN_POINTLOCATOR
1859 : _point_locator = PointLocatorBase::build(NANOFLANN, *this);
1860 : #else
1861 3360 : _point_locator = PointLocatorBase::build(TREE_ELEMENTS, *this);
1862 : #endif
1863 :
1864 2440 : if (_point_locator_close_to_point_tol > 0.)
1865 0 : _point_locator->set_close_to_point_tol(_point_locator_close_to_point_tol);
1866 : }
1867 :
1868 : // Otherwise there was a master point locator, and we can grab a
1869 : // sub-locator easily.
1870 : return
1871 : #ifdef LIBMESH_ENABLE_NANOFLANN_POINTLOCATOR
1872 : PointLocatorBase::build(NANOFLANN, *this, _point_locator.get());
1873 : #else
1874 181005 : PointLocatorBase::build(TREE_ELEMENTS, *this, _point_locator.get());
1875 : #endif
1876 : }
1877 :
1878 :
1879 :
1880 5182269 : void MeshBase::clear_point_locator ()
1881 : {
1882 1570023 : _point_locator.reset(nullptr);
1883 5182269 : }
1884 :
1885 :
1886 :
1887 0 : void MeshBase::set_count_lower_dim_elems_in_point_locator(bool count_lower_dim_elems)
1888 : {
1889 0 : _count_lower_dim_elems_in_point_locator = count_lower_dim_elems;
1890 0 : }
1891 :
1892 :
1893 :
1894 1564877 : bool MeshBase::get_count_lower_dim_elems_in_point_locator() const
1895 : {
1896 1564877 : return _count_lower_dim_elems_in_point_locator;
1897 : }
1898 :
1899 :
1900 : #ifdef LIBMESH_ENABLE_DEPRECATED
1901 14 : std::string & MeshBase::subdomain_name(subdomain_id_type id)
1902 : {
1903 : // Use set_subdomain_name() instead
1904 : libmesh_deprecated();
1905 :
1906 : // We'd like to do this so our preparation isn't invalidated by a
1907 : // write, but for all we know the user is just reading from a
1908 : // non-const mesh!
1909 : // this->unset_has_synched_subdomain_name_map();
1910 :
1911 14 : return _block_id_to_name[id];
1912 : }
1913 : #endif // LIBMESH_ENABLE_DEPRECATED
1914 :
1915 :
1916 5503 : const std::string & MeshBase::subdomain_name(subdomain_id_type id) const
1917 : {
1918 : // An empty string to return when no matching subdomain name is found
1919 5503 : static const std::string empty;
1920 :
1921 5503 : if (const auto iter = _block_id_to_name.find(id);
1922 1627 : iter == _block_id_to_name.end())
1923 1421 : return empty;
1924 : else
1925 828 : return iter->second;
1926 : }
1927 :
1928 159167 : void MeshBase::set_subdomain_name(const subdomain_id_type id,
1929 : const std::string & name,
1930 : const bool synchronous)
1931 : {
1932 159167 : if (synchronous)
1933 0 : parallel_object_only();
1934 : else
1935 45264 : this->unset_has_synched_subdomain_name_map();
1936 159167 : _block_id_to_name[id] = name;
1937 159167 : }
1938 :
1939 :
1940 0 : subdomain_id_type MeshBase::get_id_by_name(std::string_view name) const
1941 : {
1942 : // Linear search over the map values.
1943 0 : for (const auto & [sbd_id, sbd_name] : _block_id_to_name)
1944 0 : if (sbd_name == name)
1945 0 : return sbd_id;
1946 :
1947 : // If we made it here without returning, we don't have a subdomain
1948 : // with the requested name, so return Elem::invalid_subdomain_id.
1949 0 : return Elem::invalid_subdomain_id;
1950 : }
1951 :
1952 :
1953 159013 : const ElemRange & MeshBase::element_stored_range()
1954 : {
1955 159013 : if (!_element_stored_range)
1956 : {
1957 : // Range construction may not be safe within threads
1958 14224 : libmesh_assert(!Threads::in_threads);
1959 :
1960 : _element_stored_range =
1961 115666 : std::make_unique<ElemRange>(this->elements_begin(),
1962 110284 : this->elements_end());
1963 : }
1964 :
1965 159013 : return *_element_stored_range;
1966 : }
1967 :
1968 30930 : const ConstElemRange & MeshBase::active_local_element_stored_range() const
1969 : {
1970 30930 : if (!_const_active_local_element_stored_range)
1971 : {
1972 : // Range construction may not be safe within threads
1973 1766 : libmesh_assert(!Threads::in_threads);
1974 :
1975 : _const_active_local_element_stored_range =
1976 11720 : std::make_unique<ConstElemRange>(this->active_local_elements_begin(),
1977 11934 : this->active_local_elements_end());
1978 : }
1979 :
1980 30930 : return *_const_active_local_element_stored_range;
1981 : }
1982 :
1983 5165925 : void MeshBase::clear_stored_ranges()
1984 : {
1985 1566389 : _element_stored_range.reset(nullptr);
1986 1566389 : _const_active_local_element_stored_range.reset(nullptr);
1987 5165925 : }
1988 :
1989 :
1990 : #ifdef LIBMESH_ENABLE_DEPRECATED
1991 0 : void MeshBase::cache_elem_dims()
1992 : {
1993 : libmesh_deprecated();
1994 :
1995 0 : this->cache_elem_data();
1996 0 : }
1997 : #endif // LIBMESH_ENABLE_DEPRECATED
1998 :
1999 70694 : void MeshBase::cache_elem_data()
2000 : {
2001 : // This requires an inspection on every processor
2002 20668 : parallel_object_only();
2003 :
2004 : // Need to clear containers first in case all elements of a
2005 : // particular dimension/order/subdomain have been deleted.
2006 41312 : _elem_dims.clear();
2007 41312 : _elem_default_orders.clear();
2008 41312 : _mesh_subdomains.clear();
2009 70694 : _supported_nodal_order = MAXIMUM;
2010 :
2011 4643397 : for (const auto & elem : this->active_element_ptr_range())
2012 : {
2013 4522677 : _elem_dims.insert(cast_int<unsigned char>(elem->dim()));
2014 4522677 : _elem_default_orders.insert(elem->default_order());
2015 4522677 : _mesh_subdomains.insert(elem->subdomain_id());
2016 4522677 : _supported_nodal_order =
2017 4522677 : static_cast<Order>
2018 9045354 : (std::min(static_cast<int>(_supported_nodal_order),
2019 4572701 : static_cast<int>(elem->supported_nodal_order())));
2020 29382 : }
2021 :
2022 70694 : if (!this->is_serial())
2023 : {
2024 : // Some different dimension/order/subdomain elements may only live
2025 : // on other processors
2026 540 : this->comm().set_union(_elem_dims);
2027 540 : this->comm().set_union(_elem_default_orders);
2028 540 : this->comm().min(_supported_nodal_order);
2029 540 : this->comm().set_union(_mesh_subdomains);
2030 : }
2031 :
2032 : // If the largest element dimension found is larger than the current
2033 : // _spatial_dimension, increase _spatial_dimension.
2034 70694 : unsigned int max_dim = this->mesh_dimension();
2035 70694 : if (max_dim > _spatial_dimension)
2036 5269 : _spatial_dimension = cast_int<unsigned char>(max_dim);
2037 :
2038 : // _spatial_dimension may need to increase from 1->2 or 2->3 if the
2039 : // mesh is full of 1D elements but they are not x-aligned, or the
2040 : // mesh is full of 2D elements but they are not in the x-y plane.
2041 : // If the mesh is x-aligned or x-y planar, we will end up checking
2042 : // every node's coordinates and not breaking out of the loop
2043 : // early...
2044 70694 : if (_spatial_dimension < LIBMESH_DIM)
2045 : {
2046 5443120 : for (const auto & node : this->node_ptr_range())
2047 : {
2048 : // Note: the exact floating point comparison is intentional,
2049 : // we don't want to get tripped up by tolerances.
2050 3849836 : if ((*node)(0) != 0. && _spatial_dimension < 1)
2051 0 : _spatial_dimension = 1;
2052 :
2053 3849836 : if ((*node)(1) != 0. && _spatial_dimension < 2)
2054 : {
2055 292 : _spatial_dimension = 2;
2056 : #if LIBMESH_DIM == 2
2057 : // If libmesh is compiled in 2D mode, this is the
2058 : // largest spatial dimension possible so we can break
2059 : // out.
2060 : break;
2061 : #endif
2062 : }
2063 :
2064 : #if LIBMESH_DIM > 2
2065 3849836 : if ((*node)(2) != 0.)
2066 : {
2067 : // Spatial dimension can't get any higher than this, so
2068 : // we can break out.
2069 1318 : _spatial_dimension = 3;
2070 1318 : break;
2071 : }
2072 : #endif
2073 15567 : }
2074 : }
2075 :
2076 70694 : _preparation.has_cached_elem_data = true;
2077 70694 : }
2078 :
2079 :
2080 50647 : void MeshBase::sync_subdomain_name_map()
2081 : {
2082 : // This requires every processor
2083 14888 : parallel_object_only();
2084 :
2085 50647 : this->comm().set_union(_block_id_to_name);
2086 :
2087 50647 : _preparation.has_synched_subdomain_name_map = true;
2088 50647 : }
2089 :
2090 :
2091 45187 : void MeshBase::detect_interior_parents()
2092 : {
2093 13260 : LOG_SCOPE("detect_interior_parents()", "MeshBase");
2094 :
2095 : // This requires an inspection on every processor
2096 13260 : parallel_object_only();
2097 :
2098 : // This requires up-to-date mesh dimensions, but if we don't have
2099 : // them cached then we can't update them without changing the mesh
2100 : // in unexpected ways that interfere with our tests of
2101 : // partially-prepared meshes in MeshTools::*valid_is_prepared
2102 13260 : std::set<unsigned char> elem_dims_copy;
2103 45187 : if (_preparation.has_cached_elem_data)
2104 13260 : elem_dims_copy = this->elem_dimensions();
2105 : else
2106 : {
2107 0 : for (const auto & elem : this->active_element_ptr_range())
2108 0 : elem_dims_copy.insert(cast_int<unsigned char>(elem->dim()));
2109 0 : if (!this->is_serial())
2110 0 : this->comm().set_union(elem_dims_copy);
2111 : }
2112 :
2113 : // Early return if the mesh is empty or has elements of a single spatial dimension.
2114 45187 : if (elem_dims_copy.size() <= 1)
2115 : {
2116 44518 : _preparation.has_interior_parent_ptrs = true;
2117 44518 : return;
2118 : }
2119 :
2120 : // Convenient elem_dimensions iterators
2121 481 : const auto dim_start = elem_dims_copy.begin();
2122 188 : const auto dim_end = elem_dims_copy.end();
2123 :
2124 : // In this function we find only +1 dimensional interior parents,
2125 : // (so, for a given element el, the interior parent p must satisfy p.dim() == el.dim() + 1).
2126 : // Therefore, we can avoid checking the existence of interior parents
2127 : // for all those elements el such there there is no p with p.dim() == el.dim() + 1.
2128 : // We store whether to skip any given dimension in the construction of interior parents
2129 : // inside the vector in dimensions_to_skip_for_interior_parents.
2130 669 : std::vector<bool> skip_dimension_for_interior_parents(/*count=*/LIBMESH_DIM+1, /*value=*/false);
2131 481 : skip_dimension_for_interior_parents.back() = true;
2132 :
2133 : // Moreover, in the following, we will build a node-to-elem map.
2134 : // It is among the elems of this map that we will look for interior parents.
2135 : // Therefore, we can skip all elems p such that there is no el with el.dim() == p.dim() - 1.
2136 : // We store whether to skip any given dimension in the construction of the node-to-elem map
2137 : // in the vector skip_dimensions_for_node_to_el_map.
2138 669 : std::vector<bool> skip_dimensions_for_node_to_el_map(/*count=*/LIBMESH_DIM+1, /*value=*/false);
2139 669 : skip_dimensions_for_node_to_el_map[*dim_start] = true;
2140 :
2141 : // We also create a flag to know if all dimensions should be skipped,
2142 : // and if we should therefore return early.
2143 188 : bool skip_all_dimensions = true;
2144 :
2145 : // Fill dimensions_to_skip_for_interior_parents and dimensions_to_skip_for_node_to_el_map.
2146 861 : for (auto [it, next] = std::make_tuple(dim_start, std::next(dim_start));
2147 1544 : next != dim_end; ++it, ++next)
2148 : {
2149 683 : if (*it + 1 != *next) // if sequential dimensions differ by exactly 1
2150 : {
2151 80 : skip_dimension_for_interior_parents[*it] = true;
2152 151 : skip_dimensions_for_node_to_el_map[*next] = true;
2153 : }
2154 684 : else if (!skip_dimension_for_interior_parents[*it])
2155 152 : skip_all_dimensions = false;
2156 : }
2157 :
2158 : // There is nothing to do if all dimensions should be
2159 : // skipped. Before returning, we must also set the flag that says
2160 : // "interior parent pointers have been set up" even though we
2161 : // determined there was no work to be done.
2162 669 : if (skip_all_dimensions)
2163 : {
2164 137 : _preparation.has_interior_parent_ptrs = true;
2165 36 : return;
2166 : }
2167 :
2168 : // Do we have interior parent pointers going to a different mesh?
2169 : // If so then we'll still check to make sure that's the only place
2170 : // they go, so we can libmesh_not_implemented() if not.
2171 304 : const bool separate_interior_mesh = (&(this->interior_mesh()) != this);
2172 :
2173 : // This map will be used to set interior parents
2174 152 : std::unordered_map<dof_id_type, std::vector<dof_id_type>> node_to_elem;
2175 :
2176 41642 : for (const auto & elem : this->element_ptr_range())
2177 : {
2178 : // Ignore element if it cannot be interior parent of any other elem.
2179 28511 : if (skip_dimensions_for_node_to_el_map[elem->dim()])
2180 5755 : continue;
2181 :
2182 : // Populating the node_to_elem map, same as MeshTools::build_nodes_to_elem_map
2183 107926 : for (auto n : make_range(elem->n_vertices()))
2184 : {
2185 24992 : libmesh_assert_less (elem->id(), this->max_elem_id());
2186 :
2187 112464 : node_to_elem[elem->node_id(n)].push_back(elem->id());
2188 : }
2189 228 : }
2190 :
2191 : // Automatically set interior parents
2192 41642 : for (const auto & element : this->element_ptr_range())
2193 : {
2194 : // Ignore elements with dimensions to skip
2195 : // or elements that already have an interior parent.
2196 28511 : if (skip_dimension_for_interior_parents[element->dim()] || element->interior_parent())
2197 4641 : continue;
2198 :
2199 : // Start by generating sets of dim+1 dimensional elements that
2200 : // touch each vertex of the current element. If we encounter a
2201 : // vertex not connected to _any_ dim+1 dimensional elements,
2202 : // then we can exit the loop without checking the remaining
2203 : // vertices since an interior parent (if it exists) will be
2204 : // connected to all vertices of the current element.
2205 37510 : std::vector<std::set<dof_id_type>> neighbors( element->n_vertices() );
2206 :
2207 6820 : bool found_interior_parents = true;
2208 :
2209 24185 : for (auto n : make_range(element->n_vertices()))
2210 : {
2211 30969 : auto it = node_to_elem.find(element->node_id(n));
2212 :
2213 : // Check at first that this node is not isolated.
2214 24087 : if (it == node_to_elem.end())
2215 : {
2216 1472 : found_interior_parents = false;
2217 6792 : break; // out of n-loop
2218 : }
2219 :
2220 105399 : for (const auto & vertex_neighbor_id : it->second)
2221 86464 : if (this->elem_ref(vertex_neighbor_id).dim() == element->dim()+1)
2222 861 : neighbors[n].insert(vertex_neighbor_id);
2223 :
2224 24345 : if (neighbors[n].empty())
2225 : {
2226 : // We have found an empty set for one vertex, no reason
2227 : // to continue.
2228 5320 : found_interior_parents = false;
2229 5320 : break; // out of n-loop
2230 : }
2231 : }
2232 :
2233 : // If we have generated a non-empty set of elements for each
2234 : // vertex, we will now look for a vertex_neighbor_id that
2235 : // appears in _all_ of those sets. If found, this is our interior
2236 : // parent id. If multiple such common ids are found, we will
2237 : // take the lowest such id to be the interior parent id.
2238 6820 : if (found_interior_parents)
2239 : {
2240 56 : std::set<dof_id_type> & neighbors_0 = neighbors[0];
2241 161 : for (const auto & interior_parent_id : neighbors_0)
2242 : {
2243 40 : found_interior_parents = false;
2244 259 : for (auto n : make_range(1u, element->n_vertices()))
2245 : {
2246 161 : if (neighbors[n].count(interior_parent_id))
2247 : {
2248 34 : found_interior_parents = true;
2249 : }
2250 : else
2251 : {
2252 12 : found_interior_parents = false;
2253 12 : break;
2254 : }
2255 : }
2256 :
2257 140 : if (found_interior_parents)
2258 : {
2259 77 : element->set_interior_parent(this->elem_ptr(interior_parent_id));
2260 22 : break;
2261 : }
2262 : }
2263 :
2264 : // Do we have a mixed dimensional mesh that contains some of
2265 : // its own interior parents, but we already expect to have
2266 : // interior parents on a different mesh? That's going to
2267 : // take some work to support if anyone needs it.
2268 98 : if (separate_interior_mesh)
2269 0 : libmesh_not_implemented_msg
2270 : ("interior_parent() values in multiple meshes are unsupported.");
2271 : }
2272 10458 : }
2273 :
2274 : // This flag doesn't necessarily mean any Elems actually have
2275 : // interior parent pointers, just that we did all the work to
2276 : // determine whether or not they do.
2277 532 : _preparation.has_interior_parent_ptrs = true;
2278 : }
2279 :
2280 :
2281 :
2282 : #ifdef LIBMESH_ENABLE_PERIODIC
2283 : /**
2284 : * Register a pair of boundaries as disjoint neighbor boundary pairs.
2285 : */
2286 98 : void MeshBase::add_disjoint_neighbor_boundary_pairs(const boundary_id_type b1,
2287 : const boundary_id_type b2,
2288 : const RealVectorValue & translation)
2289 : {
2290 : // Lazily allocate the container the first time it’s needed
2291 98 : if (!_disjoint_neighbor_boundary_pairs)
2292 88 : _disjoint_neighbor_boundary_pairs = std::make_unique<PeriodicBoundaries>();
2293 :
2294 28 : PeriodicBoundaries & db = *_disjoint_neighbor_boundary_pairs;
2295 :
2296 : // Create forward and inverse boundary mappings
2297 126 : PeriodicBoundary forward(translation);
2298 98 : PeriodicBoundary inverse(translation * -1.0);
2299 :
2300 98 : forward.myboundary = b1;
2301 98 : forward.pairedboundary = b2;
2302 98 : inverse.myboundary = b2;
2303 98 : inverse.pairedboundary = b1;
2304 :
2305 : // Add both directions into the container
2306 98 : db.emplace(b1, forward.clone());
2307 126 : db.emplace(b2, inverse.clone());
2308 98 : }
2309 :
2310 48670 : PeriodicBoundaries * MeshBase::get_disjoint_neighbor_boundary_pairs()
2311 : {
2312 48670 : return _disjoint_neighbor_boundary_pairs.get();
2313 : }
2314 :
2315 96076 : const PeriodicBoundaries * MeshBase::get_disjoint_neighbor_boundary_pairs() const
2316 : {
2317 96076 : return _disjoint_neighbor_boundary_pairs.get();
2318 : }
2319 :
2320 21 : void MeshBase::remove_disjoint_boundary_pair(const boundary_id_type b1,
2321 : const boundary_id_type b2)
2322 : {
2323 : // Nothing to remove if not allocated or empty
2324 21 : if (!_disjoint_neighbor_boundary_pairs || _disjoint_neighbor_boundary_pairs->empty())
2325 0 : return;
2326 :
2327 6 : auto & pairs = *_disjoint_neighbor_boundary_pairs;
2328 :
2329 : // Helper to check and erase both directions
2330 18 : auto erase_if_match = [](boundary_id_type key,
2331 : boundary_id_type pair,
2332 24 : PeriodicBoundaries & pb_map)
2333 : {
2334 12 : auto it = pb_map.find(key);
2335 42 : if (it != pb_map.end())
2336 : {
2337 12 : const auto & pb = *(it->second);
2338 : // Check both directions
2339 42 : if ((pb.myboundary == key && pb.pairedboundary == pair) ||
2340 0 : (pb.pairedboundary == key && pb.myboundary == pair))
2341 30 : pb_map.erase(it);
2342 : }
2343 42 : };
2344 :
2345 21 : erase_if_match(b1, b2, pairs);
2346 21 : erase_if_match(b2, b1, pairs);
2347 : }
2348 :
2349 :
2350 : #endif
2351 :
2352 :
2353 :
2354 0 : void MeshBase::set_point_locator_close_to_point_tol(Real val)
2355 : {
2356 0 : _point_locator_close_to_point_tol = val;
2357 0 : if (_point_locator)
2358 : {
2359 0 : if (val > 0.)
2360 0 : _point_locator->set_close_to_point_tol(val);
2361 : else
2362 0 : _point_locator->unset_close_to_point_tol();
2363 : }
2364 0 : }
2365 :
2366 :
2367 :
2368 42 : Real MeshBase::get_point_locator_close_to_point_tol() const
2369 : {
2370 42 : return _point_locator_close_to_point_tol;
2371 : }
2372 :
2373 :
2374 :
2375 535 : void MeshBase::size_elem_extra_integers()
2376 : {
2377 308 : const std::size_t new_size = _elem_integer_names.size();
2378 :
2379 : Threads::parallel_for
2380 535 : (this->element_stored_range(),
2381 1372 : [new_size, this](const ElemRange & range)
2382 : {
2383 1872 : for (Elem * elem : range)
2384 1337 : elem->add_extra_integers(new_size, this->_elem_integer_default_values);
2385 381 : });
2386 535 : }
2387 :
2388 :
2389 :
2390 1714 : void MeshBase::size_node_extra_integers()
2391 : {
2392 966 : const std::size_t new_size = _node_integer_names.size();
2393 45875 : for (auto node : this->node_ptr_range())
2394 30799 : node->add_extra_integers(new_size, _node_integer_default_values);
2395 1714 : }
2396 :
2397 :
2398 : std::pair<std::vector<unsigned int>, std::vector<unsigned int>>
2399 2815 : MeshBase::merge_extra_integer_names(const MeshBase & other)
2400 : {
2401 862 : std::pair<std::vector<unsigned int>, std::vector<unsigned int>> returnval;
2402 2815 : returnval.first = this->add_elem_integers(other._elem_integer_names, true, &other._elem_integer_default_values);
2403 2815 : returnval.second = this->add_node_integers(other._node_integer_names, true, &other._node_integer_default_values);
2404 2815 : return returnval;
2405 : }
2406 :
2407 :
2408 :
2409 : void
2410 42 : MeshBase::post_dofobject_moves(MeshBase && other_mesh)
2411 : {
2412 : // Now that all the DofObject moving is done, we can move the GhostingFunctor objects
2413 : // which include the _default_ghosting,_ghosting_functors and _shared_functors. We also need
2414 : // to set the mesh object associated with these functors to the assignee mesh.
2415 :
2416 : // _default_ghosting
2417 12 : _default_ghosting = std::move(other_mesh._default_ghosting);
2418 42 : _default_ghosting->set_mesh(this);
2419 :
2420 : // _ghosting_functors
2421 42 : _ghosting_functors = std::move(other_mesh._ghosting_functors);
2422 :
2423 84 : for (const auto gf : _ghosting_functors )
2424 : {
2425 42 : gf->set_mesh(this);
2426 : }
2427 :
2428 : // _shared_functors
2429 12 : _shared_functors = std::move(other_mesh._shared_functors);
2430 :
2431 42 : for (const auto & sf : _shared_functors )
2432 : {
2433 0 : (sf.second)->set_mesh(this);
2434 : }
2435 :
2436 : // _constraint_rows
2437 12 : _constraint_rows = std::move(other_mesh._constraint_rows);
2438 :
2439 42 : if (other_mesh.partitioner())
2440 42 : _partitioner = std::move(other_mesh.partitioner());
2441 42 : }
2442 :
2443 :
2444 : void
2445 0 : MeshBase::copy_cached_data(const MeshBase & other_mesh)
2446 : {
2447 0 : this->_spatial_dimension = other_mesh._spatial_dimension;
2448 0 : this->_elem_dims = other_mesh._elem_dims;
2449 0 : this->_elem_default_orders = other_mesh._elem_default_orders;
2450 0 : this->_supported_nodal_order = other_mesh._supported_nodal_order;
2451 0 : this->_mesh_subdomains = other_mesh._mesh_subdomains;
2452 0 : }
2453 :
2454 :
2455 2069 : bool MeshBase::nodes_and_elements_equal(const MeshBase & other_mesh) const
2456 : {
2457 378826 : for (const auto & other_node : other_mesh.node_ptr_range())
2458 : {
2459 312945 : const Node * node = this->query_node_ptr(other_node->id());
2460 312945 : if (!node)
2461 0 : return false;
2462 312945 : if (*other_node != *node)
2463 0 : return false;
2464 607 : }
2465 378826 : for (const auto & node : this->node_ptr_range())
2466 312945 : if (!other_mesh.query_node_ptr(node->id()))
2467 607 : return false;
2468 :
2469 400290 : for (const auto & other_elem : other_mesh.element_ptr_range())
2470 : {
2471 375292 : const Elem * elem = this->query_elem_ptr(other_elem->id());
2472 375292 : if (!elem)
2473 0 : return false;
2474 375292 : if (!other_elem->topologically_equal(*elem))
2475 6 : return false;
2476 607 : }
2477 400254 : for (const auto & elem : this->element_ptr_range())
2478 375271 : if (!other_mesh.query_elem_ptr(elem->id()))
2479 598 : return false;
2480 :
2481 2048 : return true;
2482 : }
2483 :
2484 :
2485 772 : dof_id_type MeshBase::n_constraint_rows() const
2486 : {
2487 772 : dof_id_type n_local_rows=0, n_unpartitioned_rows=0;
2488 772 : for (const auto & [node, node_constraints] : _constraint_rows)
2489 : {
2490 : // Unpartitioned nodes
2491 0 : if (node->processor_id() == DofObject::invalid_processor_id)
2492 0 : n_unpartitioned_rows++;
2493 0 : else if (node->processor_id() == this->processor_id())
2494 0 : n_local_rows++;
2495 : }
2496 :
2497 772 : this->comm().sum(n_local_rows);
2498 :
2499 772 : return n_unpartitioned_rows + n_local_rows;
2500 : }
2501 :
2502 :
2503 : void
2504 2640 : MeshBase::copy_constraint_rows(const MeshBase & other_mesh)
2505 : {
2506 1624 : LOG_SCOPE("copy_constraint_rows(mesh)", "MeshBase");
2507 :
2508 1600 : _constraint_rows.clear();
2509 :
2510 812 : const auto & other_constraint_rows = other_mesh.get_constraint_rows();
2511 14687 : for (const auto & [other_node, other_node_constraints] : other_constraint_rows)
2512 : {
2513 12047 : const Node * const our_node = this->node_ptr(other_node->id());
2514 6416 : constraint_rows_mapped_type our_node_constraints;
2515 44238 : for (const auto & [other_inner_key_pair, constraint_value] : other_node_constraints)
2516 : {
2517 9048 : const auto & [other_elem, local_node_id] = other_inner_key_pair;
2518 32191 : const Elem * const our_elem = this->elem_ptr(other_elem->id());
2519 32191 : our_node_constraints.emplace_back(std::make_pair(our_elem, local_node_id), constraint_value);
2520 : }
2521 12047 : _constraint_rows[our_node] = std::move(our_node_constraints);
2522 : }
2523 2640 : }
2524 :
2525 :
2526 : template <typename T>
2527 : void
2528 53 : MeshBase::copy_constraint_rows(const SparseMatrix<T> & constraint_operator,
2529 : bool precondition_constraint_operator)
2530 : {
2531 32 : LOG_SCOPE("copy_constraint_rows(mat)", "MeshBase");
2532 :
2533 16 : this->_constraint_rows.clear();
2534 :
2535 : // We're not going to support doing this distributed yet; it'd be
2536 : // pointless unless we temporarily had a linear partitioning to
2537 : // better match the constraint operator.
2538 85 : MeshSerializer serialize(*this);
2539 :
2540 : // Our current mesh should already reflect the desired assembly space
2541 53 : libmesh_error_msg_if(this->n_nodes() != constraint_operator.m(),
2542 : "Constraint operator matrix with " <<
2543 : constraint_operator.m() <<
2544 : "rows does not match this mesh with " <<
2545 : this->n_nodes() << " nodes");
2546 :
2547 : // First, find what new unconstrained DoFs we need to add. We can't
2548 : // iterate over columns in a SparseMatrix, so we'll iterate over
2549 : // rows and keep track of columns.
2550 :
2551 : // If we have nodes that will work unconstrained, keep track of
2552 : // their node ids and corresponding column indices.
2553 : // existing_unconstrained_nodes[column_id] = node_id
2554 32 : std::map<dof_id_type, dof_id_type> existing_unconstrained_columns;
2555 32 : std::set<dof_id_type> existing_unconstrained_nodes;
2556 :
2557 : // In case we need new nodes, keep track of their columns.
2558 : // columns[j][k] will be the kth row index and value of column j
2559 : typedef
2560 : std::unordered_map<dof_id_type,
2561 : std::vector<std::pair<dof_id_type, Real>>>
2562 : columns_type;
2563 90 : columns_type columns(constraint_operator.n());
2564 :
2565 : // If we need to precondition the constraint operator (e.g. it's an
2566 : // unpreconditioned extraction operator for a Flex IGA matrix),
2567 : // we'll want to keep track of the sum of each column, because we'll
2568 : // be dividing each column by that sum (Jacobi preconditioning on
2569 : // the right, which then leads to symmetric preconditioning on a
2570 : // physics Jacobian).
2571 32 : std::unordered_map<dof_id_type, Real> column_sums;
2572 :
2573 : // Work in parallel, though we'll have to sync shortly
2574 1044 : for (auto i : make_range(constraint_operator.row_start(),
2575 21 : constraint_operator.row_stop()))
2576 : {
2577 618 : std::vector<numeric_index_type> indices;
2578 618 : std::vector<T> values;
2579 :
2580 991 : constraint_operator.get_row(i, indices, values);
2581 309 : libmesh_assert_equal_to(indices.size(), values.size());
2582 :
2583 1375 : if (indices.size() == 1 &&
2584 225 : values[0] == T(1))
2585 : {
2586 : // If we have multiple simple Ui=Uj constraints, let the
2587 : // first one be our "unconstrained" node and let the others
2588 : // be constrained to it.
2589 258 : if (existing_unconstrained_columns.find(indices[0]) !=
2590 138 : existing_unconstrained_columns.end())
2591 : {
2592 12 : const auto j = indices[0];
2593 12 : columns[j].emplace_back(i, 1);
2594 : }
2595 : else
2596 : {
2597 180 : existing_unconstrained_nodes.insert(i);
2598 246 : existing_unconstrained_columns.emplace(indices[0],i);
2599 : }
2600 : }
2601 : else
2602 6036 : for (auto jj : index_range(indices))
2603 : {
2604 5303 : const auto j = indices[jj];
2605 7062 : const Real coef = libmesh_real(values[jj]);
2606 1759 : libmesh_assert_equal_to(coef, values[jj]);
2607 5303 : columns[j].emplace_back(i, coef);
2608 : }
2609 : }
2610 :
2611 : // Merge data from different processors' slabs of the matrix
2612 53 : this->comm().set_union(existing_unconstrained_nodes);
2613 53 : this->comm().set_union(existing_unconstrained_columns);
2614 :
2615 48 : std::vector<columns_type> all_columns;
2616 53 : this->comm().allgather(columns, all_columns);
2617 :
2618 16 : columns.clear();
2619 154 : for (auto p : index_range(all_columns))
2620 1975 : for (auto & [j, subcol] : all_columns[p])
2621 12475 : for (auto [i, v] : subcol)
2622 10601 : columns[j].emplace_back(i,v);
2623 :
2624 : // Keep track of elements on which unconstrained nodes exist, and
2625 : // their local node indices.
2626 : // node_to_elem_ptrs[node] = [elem_id, local_node_num]
2627 32 : std::unordered_map<const Node *, std::pair<dof_id_type, unsigned int>> node_to_elem_ptrs;
2628 :
2629 : // Find elements attached to any existing nodes that will stay
2630 : // unconstrained. We'll also build a subdomain set here so we don't
2631 : // have to assert that the mesh is already prepared before we pick a
2632 : // new subdomain for any NodeElems we need to add.
2633 32 : std::set<subdomain_id_type> subdomain_ids;
2634 7325 : for (const Elem * elem : this->element_ptr_range())
2635 : {
2636 4298 : subdomain_ids.insert(elem->subdomain_id());
2637 21084 : for (auto n : make_range(elem->n_nodes()))
2638 : {
2639 16786 : const Node * node = elem->node_ptr(n);
2640 16786 : if (existing_unconstrained_nodes.count(node->id()))
2641 1103 : node_to_elem_ptrs.emplace(node, std::make_pair(elem->id(), n));
2642 : }
2643 : }
2644 :
2645 53 : const subdomain_id_type new_sbd_id = *subdomain_ids.rbegin() + 1;
2646 :
2647 1557 : for (auto j : make_range(constraint_operator.n()))
2648 : {
2649 : // If we already have a good node for this then we're done
2650 576 : if (existing_unconstrained_columns.count(j))
2651 444 : continue;
2652 :
2653 : // Get a half-decent spot to place a new NodeElem for
2654 : // unconstrained DoF(s) here. Getting a *fully*-decent spot
2655 : // would require finding a Moore-Penrose pseudoinverse, and I'm
2656 : // not going to do that, but scaling a transpose will at least
2657 : // get us a little uniqueness to make visualization reasonable.
2658 264 : Point newpt;
2659 264 : Real total_scaling = 0;
2660 264 : unsigned int total_entries = 0;
2661 :
2662 : // We'll get a decent initial pid choice here too, if only to
2663 : // aid in later repartitioning.
2664 528 : std::map<processor_id_type, int> pids;
2665 :
2666 264 : auto & column = columns[j];
2667 10486 : for (auto [i, r] : column)
2668 : {
2669 9692 : Node & constrained_node = this->node_ref(i);
2670 9692 : const Point constrained_pt = constrained_node;
2671 3228 : newpt += r*constrained_pt;
2672 9692 : total_scaling += r;
2673 9692 : ++total_entries;
2674 9692 : ++pids[constrained_node.processor_id()];
2675 : }
2676 :
2677 794 : if (precondition_constraint_operator)
2678 0 : column_sums[j] = total_scaling;
2679 :
2680 794 : libmesh_error_msg_if
2681 : (!total_entries,
2682 : "Empty column " << j <<
2683 : " found in constraint operator matrix");
2684 :
2685 : // If we have *cancellation* here then we can end up dividing by
2686 : // zero; try just evenly scaling across all constrained node
2687 : // points instead.
2688 794 : if (total_scaling > TOLERANCE)
2689 264 : newpt /= total_scaling;
2690 : else
2691 0 : newpt /= total_entries;
2692 :
2693 794 : Node *n = this->add_point(newpt);
2694 1058 : std::unique_ptr<Elem> elem = Elem::build(NODEELEM);
2695 794 : elem->set_node(0, n);
2696 794 : elem->subdomain_id() = new_sbd_id;
2697 :
2698 1058 : Elem * added_elem = this->add_elem(std::move(elem));
2699 794 : this->_elem_dims.insert(0);
2700 794 : this->_elem_default_orders.insert(added_elem->default_order());
2701 794 : this->_supported_nodal_order =
2702 266 : static_cast<Order>
2703 1588 : (std::min(static_cast<int>(this->_supported_nodal_order),
2704 794 : static_cast<int>(added_elem->supported_nodal_order())));
2705 530 : this->_mesh_subdomains.insert(new_sbd_id);
2706 794 : node_to_elem_ptrs.emplace(n, std::make_pair(added_elem->id(), 0));
2707 794 : existing_unconstrained_columns.emplace(j,n->id());
2708 :
2709 : // Repartition the new objects *after* adding them, so a
2710 : // DistributedMesh doesn't get confused and think you're not
2711 : // adding them on all processors at once.
2712 264 : int n_pids = 0;
2713 2098 : for (auto [pid, count] : pids)
2714 1304 : if (count >= n_pids)
2715 : {
2716 324 : n_pids = count;
2717 974 : added_elem->processor_id() = pid;
2718 974 : n->processor_id() = pid;
2719 : }
2720 : }
2721 :
2722 : // Calculate constraint rows in an indexed form that's easy for us
2723 : // to allgather
2724 : std::unordered_map<dof_id_type,
2725 : std::vector<std::pair<std::pair<dof_id_type, unsigned int>,Real>>>
2726 32 : indexed_constraint_rows;
2727 :
2728 1044 : for (auto i : make_range(constraint_operator.row_start(),
2729 21 : constraint_operator.row_stop()))
2730 : {
2731 423 : if (existing_unconstrained_nodes.count(i))
2732 246 : continue;
2733 :
2734 486 : std::vector<numeric_index_type> indices;
2735 486 : std::vector<T> values;
2736 :
2737 745 : constraint_operator.get_row(i, indices, values);
2738 :
2739 486 : std::vector<std::pair<std::pair<dof_id_type, unsigned int>, Real>> constraint_row;
2740 :
2741 6060 : for (auto jj : index_range(indices))
2742 : {
2743 7077 : const dof_id_type node_id =
2744 : existing_unconstrained_columns[indices[jj]];
2745 :
2746 5315 : Node & constraining_node = this->node_ref(node_id);
2747 :
2748 1762 : libmesh_assert(node_to_elem_ptrs.count(&constraining_node));
2749 :
2750 5315 : auto p = node_to_elem_ptrs[&constraining_node];
2751 :
2752 5286 : Real coef = libmesh_real(values[jj]);
2753 1762 : libmesh_assert_equal_to(coef, values[jj]);
2754 :
2755 : // If we're preconditioning and we created a nodeelem then
2756 : // we can scale the meaning of that nodeelem's value to give
2757 : // us a better-conditioned matrix after the constraints are
2758 : // applied.
2759 5315 : if (precondition_constraint_operator)
2760 0 : if (auto sum_it = column_sums.find(indices[jj]);
2761 0 : sum_it != column_sums.end())
2762 : {
2763 0 : const Real scaling = sum_it->second;
2764 :
2765 0 : if (scaling > TOLERANCE)
2766 0 : coef /= scaling;
2767 : }
2768 :
2769 7077 : constraint_row.emplace_back(std::make_pair(p, coef));
2770 : }
2771 :
2772 243 : indexed_constraint_rows.emplace(i, std::move(constraint_row));
2773 : }
2774 :
2775 53 : this->comm().set_union(indexed_constraint_rows);
2776 :
2777 : // Add constraint rows as mesh constraint rows
2778 1527 : for (auto & [node_id, indexed_row] : indexed_constraint_rows)
2779 : {
2780 1474 : Node * constrained_node = this->node_ptr(node_id);
2781 :
2782 972 : constraint_rows_mapped_type constraint_row;
2783 :
2784 12075 : for (auto [p, coef] : indexed_row)
2785 : {
2786 10601 : const Elem * elem = this->elem_ptr(p.first);
2787 7048 : constraint_row.emplace_back
2788 14125 : (std::make_pair(std::make_pair(elem, p.second), coef));
2789 : }
2790 :
2791 988 : this->_constraint_rows.emplace(constrained_node,
2792 486 : std::move(constraint_row));
2793 : }
2794 74 : }
2795 :
2796 :
2797 0 : void MeshBase::print_constraint_rows(std::ostream & os,
2798 : bool print_nonlocal) const
2799 : {
2800 0 : parallel_object_only();
2801 :
2802 : std::string local_constraints =
2803 0 : this->get_local_constraints(print_nonlocal);
2804 :
2805 0 : if (this->processor_id())
2806 : {
2807 0 : this->comm().send(0, local_constraints);
2808 : }
2809 : else
2810 : {
2811 0 : os << "Processor 0:\n";
2812 0 : os << local_constraints;
2813 :
2814 0 : for (auto p : IntRange<processor_id_type>(1, this->n_processors()))
2815 : {
2816 0 : this->comm().receive(p, local_constraints);
2817 0 : os << "Processor " << p << ":\n";
2818 0 : os << local_constraints;
2819 : }
2820 : }
2821 0 : }
2822 :
2823 :
2824 :
2825 0 : std::string MeshBase::get_local_constraints(bool print_nonlocal) const
2826 : {
2827 0 : std::ostringstream os;
2828 :
2829 0 : if (print_nonlocal)
2830 0 : os << "All ";
2831 : else
2832 0 : os << "Local ";
2833 :
2834 0 : os << "Mesh Constraint Rows:"
2835 0 : << std::endl;
2836 :
2837 0 : for (const auto & [node, row] : _constraint_rows)
2838 : {
2839 0 : const bool local = (node->processor_id() == this->processor_id());
2840 :
2841 : // Skip non-local dofs if requested
2842 0 : if (!print_nonlocal && !local)
2843 0 : continue;
2844 :
2845 0 : os << "Constraints for " << (local ? "Local" : "Ghost") << " Node " << node->id()
2846 0 : << ": \t";
2847 :
2848 0 : for (const auto & [elem_and_node, coef] : row)
2849 0 : os << " ((" << elem_and_node.first->id() << ',' << elem_and_node.second << "), " << coef << ")\t";
2850 :
2851 0 : os << std::endl;
2852 : }
2853 :
2854 0 : return os.str();
2855 0 : }
2856 :
2857 33976 : MeshBase::Preparation::Preparation() :
2858 14332 : is_partitioned(false),
2859 14332 : has_synched_id_counts(false),
2860 14332 : has_neighbor_ptrs(false),
2861 14332 : has_cached_elem_data(false),
2862 14332 : has_interior_parent_ptrs(false),
2863 14332 : has_removed_remote_elements(false),
2864 14332 : has_removed_orphaned_nodes(false),
2865 14332 : has_boundary_id_sets(false),
2866 14332 : has_reinit_ghosting_functors(false),
2867 33976 : has_synched_subdomain_name_map(false)
2868 33976 : {}
2869 :
2870 52152 : MeshBase::Preparation::operator bool() const
2871 : {
2872 101331 : return is_partitioned &&
2873 49179 : has_synched_id_counts &&
2874 49179 : has_neighbor_ptrs &&
2875 49179 : has_cached_elem_data &&
2876 49173 : has_interior_parent_ptrs &&
2877 49173 : has_removed_remote_elements &&
2878 49173 : has_removed_orphaned_nodes &&
2879 49173 : has_reinit_ghosting_functors &&
2880 148287 : has_boundary_id_sets &&
2881 97023 : has_synched_subdomain_name_map;
2882 : }
2883 :
2884 : MeshBase::Preparation &
2885 150281 : MeshBase::Preparation::operator= (bool set_all)
2886 : {
2887 150281 : is_partitioned = set_all;
2888 150281 : has_synched_id_counts = set_all;
2889 150281 : has_neighbor_ptrs = set_all;
2890 150281 : has_cached_elem_data = set_all;
2891 150281 : has_interior_parent_ptrs = set_all;
2892 150281 : has_removed_remote_elements = set_all;
2893 150281 : has_removed_orphaned_nodes = set_all;
2894 150281 : has_reinit_ghosting_functors = set_all;
2895 150281 : has_boundary_id_sets = set_all;
2896 150281 : has_synched_subdomain_name_map = set_all;
2897 :
2898 150281 : return *this;
2899 : }
2900 :
2901 : bool
2902 2111 : MeshBase::Preparation::operator== (const Preparation & other) const
2903 : {
2904 2111 : if (is_partitioned != other.is_partitioned)
2905 0 : return false;
2906 2111 : if (has_synched_id_counts != other.has_synched_id_counts)
2907 0 : return false;
2908 2111 : if (has_neighbor_ptrs != other.has_neighbor_ptrs)
2909 0 : return false;
2910 2111 : if (has_cached_elem_data != other.has_cached_elem_data)
2911 0 : return false;
2912 2111 : if (has_interior_parent_ptrs != other.has_interior_parent_ptrs)
2913 0 : return false;
2914 2111 : if (has_removed_remote_elements != other.has_removed_remote_elements)
2915 0 : return false;
2916 2111 : if (has_removed_orphaned_nodes != other.has_removed_orphaned_nodes)
2917 0 : return false;
2918 2111 : if (has_reinit_ghosting_functors != other.has_reinit_ghosting_functors)
2919 0 : return false;
2920 2111 : if (has_boundary_id_sets != other.has_boundary_id_sets)
2921 0 : return false;
2922 2111 : if (has_synched_subdomain_name_map != other.has_synched_subdomain_name_map)
2923 0 : return false;
2924 :
2925 1078 : return true;
2926 : }
2927 :
2928 : bool
2929 2111 : MeshBase::Preparation::operator!= (const Preparation & other) const
2930 : {
2931 2111 : return !(*this == other);
2932 : }
2933 :
2934 :
2935 : // Explicit instantiations for our template function
2936 : template LIBMESH_EXPORT void
2937 : MeshBase::copy_constraint_rows(const SparseMatrix<Real> & constraint_operator,
2938 : bool precondition_constraint_operator);
2939 :
2940 : #ifdef LIBMESH_USE_COMPLEX_NUMBERS
2941 : template LIBMESH_EXPORT void
2942 : MeshBase::copy_constraint_rows(const SparseMatrix<Complex> & constraint_operator,
2943 : bool precondition_constraint_operator);
2944 : #endif
2945 :
2946 :
2947 : } // namespace libMesh
|