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 it and/or
5 : // modify it under the terms of the GNU Lesser General Public
6 : // License as published by the Free Software Foundation; either
7 : // version 2.1 of the License, or (at your option) any later version.
8 :
9 : // This library is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : // Lesser General Public License for more details.
13 :
14 : // You should have received a copy of the GNU Lesser General Public
15 : // License along with this library; if not, write to the Free Software
16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 :
18 :
19 :
20 : #ifndef LIBMESH_MESH_BASE_H
21 : #define LIBMESH_MESH_BASE_H
22 :
23 : // Local Includes
24 : #include "libmesh/dof_object.h" // for invalid_processor_id
25 : #include "libmesh/enum_order.h"
26 : #include "libmesh/int_range.h"
27 : #include "libmesh/libmesh_common.h"
28 : #include "libmesh/multi_predicates.h"
29 : #include "libmesh/point_locator_base.h"
30 : #include "libmesh/variant_filter_iterator.h"
31 : #include "libmesh/parallel_object.h"
32 : #include "libmesh/simple_range.h"
33 :
34 : // C++ Includes
35 : #include <cstddef>
36 : #include <string>
37 : #include <memory>
38 :
39 : #include "libmesh/vector_value.h"
40 :
41 : namespace libMesh
42 : {
43 : // Forward declarations
44 : class BoundaryInfo;
45 : class Elem;
46 : class GhostingFunctor;
47 : class Node;
48 : class Point;
49 : class Partitioner;
50 : class PeriodicBoundary;
51 : class PeriodicBoundaries;
52 :
53 : template <typename T>
54 : class SparseMatrix;
55 :
56 : enum ElemType : int;
57 : enum ElemMappingType : unsigned char;
58 :
59 : template <class MT>
60 : class MeshInput;
61 :
62 : template <typename iterator_type, typename object_type>
63 : class StoredRange;
64 :
65 : /**
66 : * This is the \p MeshBase class. This class provides all the data necessary
67 : * to describe a geometric entity. It allows for the description of a
68 : * \p dim dimensional object that lives in \p LIBMESH_DIM-dimensional space.
69 : * \par
70 : * A mesh is made of nodes and elements, and this class provides data
71 : * structures to store and access both. A mesh may be partitioned into a
72 : * number of subdomains, and this class provides that functionality.
73 : * Furthermore, this class provides functions for reading and writing a
74 : * mesh to disk in various formats.
75 : *
76 : * \author Benjamin S. Kirk
77 : * \date 2002
78 : * \brief Base class for Mesh.
79 : */
80 : class MeshBase : public ParallelObject
81 : {
82 : public:
83 :
84 : /**
85 : * Constructor. Takes \p dim, the dimension of the mesh.
86 : * The mesh dimension can be changed (and may automatically be
87 : * changed by mesh generation/loading) later.
88 : */
89 : MeshBase (const Parallel::Communicator & comm_in,
90 : unsigned char dim=1);
91 :
92 : /**
93 : * Copy-constructor.
94 : */
95 : MeshBase (const MeshBase & other_mesh);
96 :
97 : /**
98 : * Move-constructor - deleted because after a theoretical move-construction
99 : * and then destruction of the moved-from object, the moved \p BoundaryInfo
100 : * would hold an invalid reference to the moved-from mesh
101 : */
102 : MeshBase(MeshBase &&) = delete;
103 :
104 : /**
105 : * Copy and move assignment are not allowed because MeshBase
106 : * subclasses manually manage memory (Elems and Nodes) and therefore
107 : * the default versions of these operators would leak memory. Since
108 : * we don't want to maintain non-default copy and move assignment
109 : * operators at this time, the safest and most self-documenting
110 : * approach is to delete them.
111 : *
112 : * If you need to copy a Mesh, use the clone() method.
113 : */
114 : MeshBase & operator= (const MeshBase &) = delete;
115 : MeshBase & operator= (MeshBase && other_mesh);
116 :
117 : /**
118 : * Shim to allow operator = (&&) to behave like a virtual function
119 : * without having to be one.
120 : */
121 : virtual MeshBase & assign(MeshBase && other_mesh) = 0;
122 :
123 : /**
124 : * This tests for exactly-equal data in all the senses that a
125 : * mathematician would care about (element connectivity, nodal
126 : * coordinates), but in the senses a programmer would care about it
127 : * allows for non-equal equivalence in some ways (we accept
128 : * different Elem/Node addresses in memory) but not others (we do
129 : * not accept different subclass types, nor even different Elem/Node
130 : * ids).
131 : *
132 : * Though this method is non-virtual, its implementation calls the
133 : * virtual function \p subclass_locally_equals() to test for
134 : * equality of subclass-specific data as well.
135 : */
136 : bool operator== (const MeshBase & other_mesh) const;
137 :
138 : bool operator!= (const MeshBase & other_mesh) const
139 : {
140 : return !(*this == other_mesh);
141 : }
142 :
143 : /**
144 : * This behaves the same as operator==, but only for the local and
145 : * ghosted aspects of the mesh; i.e. operator== is true iff local
146 : * equality is true on every rank.
147 : */
148 : bool locally_equals (const MeshBase & other_mesh) const;
149 :
150 : /**
151 : * Virtual "copy constructor". The copy will be of the same
152 : * subclass as \p this, and will satisfy "copy == this" when it is
153 : * created.
154 : */
155 : virtual std::unique_ptr<MeshBase> clone() const = 0;
156 :
157 : /**
158 : * Destructor.
159 : */
160 : virtual ~MeshBase ();
161 :
162 : /**
163 : * A partitioner to use at each partitioning
164 : */
165 481839 : virtual std::unique_ptr<Partitioner> & partitioner() { return _partitioner; }
166 :
167 : /**
168 : * The information about boundary ids on the mesh
169 : */
170 775908 : const BoundaryInfo & get_boundary_info() const { return *boundary_info; }
171 :
172 : /**
173 : * Writable information about boundary ids on the mesh
174 : */
175 1383321 : BoundaryInfo & get_boundary_info() { return *boundary_info; }
176 :
177 : /**
178 : * Deletes all the element and node data that is currently stored.
179 : *
180 : * elem and node extra_integer data is nevertheless *retained* here,
181 : * for better compatibility between that feature and older code's
182 : * use of MeshBase::clear()
183 : */
184 : virtual void clear ();
185 :
186 : /**
187 : * Deletes all the element data that is currently stored.
188 : *
189 : * No Node is removed from the mesh, however even NodeElem elements
190 : * are deleted, so the remaining Nodes will be considered "unused"
191 : * and cleared unless they are reconnected to new elements before
192 : * the next preparation step.
193 : *
194 : * This does not affect BoundaryInfo data; any boundary information
195 : * associated elements should already be cleared.
196 : */
197 : virtual void clear_elems () = 0;
198 :
199 : /**
200 : * \returns \p true if the mesh is marked as having undergone all of
201 : * the preparation done in a call to \p prepare_for_use, \p false
202 : * otherwise.
203 : */
204 : bool is_prepared () const;
205 :
206 : /**
207 : * \returns the \p Preparation structure with details about in what
208 : * ways \p this mesh is currently prepared or unprepared. This
209 : * structure may change in the future when cache designs change.
210 : */
211 : struct Preparation;
212 :
213 2108 : Preparation preparation () const
214 86439 : { return _preparation; }
215 :
216 : #ifdef LIBMESH_ENABLE_DEPRECATED
217 : /**
218 : * Tells this we have done some operation where we should no longer
219 : * consider ourself prepared. This is a very coarse setting; it is
220 : * generally more efficient to mark finer-grained settings instead.
221 : *
222 : * This method name is now deprecated, in part to match the less
223 : * awkward unset_has_ names of the more fine-grained methods, in
224 : * part as a way to prompt older user codes to use the more
225 : * fine-grained methods where they can, to speed up the
226 : * complete_preparation() calls afterward.
227 : */
228 : void set_isnt_prepared()
229 : { libmesh_deprecated(); _preparation = false; }
230 : #endif // LIBMESH_ENABLE_DEPRECATED
231 :
232 : /**
233 : * Tells this we have done some operation where we should no longer
234 : * consider ourself prepared. This is a very coarse setting; it is
235 : * generally more efficient to mark finer-grained settings instead.
236 : */
237 : void unset_is_prepared();
238 :
239 : /**
240 : * Tells this we have done some operation creating unpartitioned
241 : * elements.
242 : *
243 : * User code which adds elements to this mesh must either partition
244 : * them too or call this method.
245 : */
246 : void unset_is_partitioned()
247 : { _preparation.is_partitioned = false; }
248 :
249 : /**
250 : * Tells this we have done some operation (e.g. adding objects to a
251 : * distributed mesh on one processor only) which can lose
252 : * synchronization of id counts.
253 : *
254 : * User code which does distributed additions of nodes or elements
255 : * must call either this method or \p update_parallel_id_counts().
256 : */
257 : void unset_has_synched_id_counts()
258 : { _preparation.has_synched_id_counts = false; }
259 :
260 : /**
261 : * Tells this we have done some operation (e.g. adding elements
262 : * without setting their neighbor pointers, or adding disjoint
263 : * neighbor boundary pairs) which requires neighbor pointers to be
264 : * determined later.
265 : *
266 : * User code which adds new elements to this mesh must call this
267 : * function or manually set neighbor pointer from and to those
268 : * elements.
269 : */
270 2 : void unset_has_neighbor_ptrs()
271 3245 : { _preparation.has_neighbor_ptrs = false; }
272 :
273 : /**
274 : * Tells this we have done some operation (e.g. adding elements with
275 : * a new dimension or subdomain value) which may invalidate cached
276 : * summaries of element data.
277 : *
278 : * User code which adds new elements to this mesh must call this
279 : * function.
280 : */
281 22 : void unset_has_cached_elem_data()
282 380805 : { _preparation.has_cached_elem_data = false; }
283 :
284 : /**
285 : * Tells this we have done some operation (e.g. refining elements
286 : * with interior parents) which requires interior parent pointers to
287 : * be found later.
288 : *
289 : * Most user code will not need to call this method; any user code
290 : * that manipulates interior parents or their boundary elements may
291 : * be an exception.
292 : */
293 : void unset_has_interior_parent_ptrs()
294 : { _preparation.has_interior_parent_ptrs = false; }
295 :
296 : /**
297 : * Tells this we have done some operation (e.g. repartitioning)
298 : * which may have left elements as ghosted which on a distributed
299 : * mesh should be remote.
300 : *
301 : * User code should probably never need to use this; we can set it
302 : * in Partitioner. Any user code which manually repartitions
303 : * elements on distributed meshes may need to call this manually, in
304 : * addition to manually communicating elements with newly-created
305 : * ghosting requirements.
306 : */
307 : void unset_has_removed_remote_elements()
308 : { _preparation.has_removed_remote_elements = false; }
309 :
310 : /**
311 : * Tells this we have done some operation (e.g. coarsening)
312 : * which may have left orphaned nodes in need of removal.
313 : *
314 : * Most user code should probably never need to use this; we can set
315 : * it in MeshRefinement. User code which deletes elements without
316 : * carefully deleting orphaned nodes should call this manually.
317 : */
318 : void unset_has_removed_orphaned_nodes()
319 : { _preparation.has_removed_orphaned_nodes = false; }
320 :
321 : /**
322 : * Tells this we have done some operation (e.g. adding or removing
323 : * elements) which may require a reinit() of custom ghosting
324 : * functors.
325 : *
326 : * User code which adds or removes elements should call this method.
327 : * User code which moves nodes ... should probably call this method,
328 : * in case ghosting functors depending on position exist?
329 : */
330 94 : void unset_has_reinit_ghosting_functors()
331 3337 : { _preparation.has_reinit_ghosting_functors = false; }
332 :
333 : /**
334 : * Tells this we have done some operation which may have invalidated
335 : * our cached boundary id sets.
336 : *
337 : * User code which removes elements, or which adds or removes
338 : * boundary entries, should call this method.
339 : */
340 2 : void unset_has_boundary_id_sets()
341 3245 : { _preparation.has_boundary_id_sets = false; }
342 :
343 : /**
344 : * Tells this we have done some operation which may have left the
345 : * subdomain id to name map inconsistent across processors.
346 : *
347 : * User code which adds or changes subdomain names should call this
348 : * method.
349 : */
350 48660 : void unset_has_synched_subdomain_name_map()
351 1156481 : { _preparation.has_synched_subdomain_name_map = false; }
352 :
353 : /**
354 : * \returns \p true if all elements and nodes of the mesh
355 : * exist on the current processor, \p false otherwise
356 : */
357 841642 : virtual bool is_serial () const
358 841642 : { return true; }
359 :
360 : /**
361 : * \returns \p true if all elements and nodes of the mesh
362 : * exist on the processor 0, \p false otherwise
363 : */
364 1517 : virtual bool is_serial_on_zero () const
365 1517 : { return true; }
366 :
367 : /**
368 : * Asserts that not all elements and nodes of the mesh necessarily
369 : * exist on the current processor. Only valid to call on classes
370 : * which can be created in a distributed form.
371 : */
372 0 : virtual void set_distributed ()
373 0 : { libmesh_error(); }
374 :
375 : /**
376 : * \returns \p true if new elements and nodes can and should be
377 : * created in synchronization on all processors, \p false otherwise
378 : */
379 2499853 : virtual bool is_replicated () const
380 2499853 : { return true; }
381 :
382 : /**
383 : * Gathers all elements and nodes of the mesh onto
384 : * every processor
385 : */
386 2 : virtual void allgather () {}
387 :
388 : /**
389 : * Gathers all elements and nodes of the mesh onto
390 : * processor zero
391 : */
392 0 : virtual void gather_to_zero() {}
393 :
394 : /**
395 : * When supported, deletes all nonlocal elements of the mesh
396 : * except for "ghosts" which touch a local element, and deletes
397 : * all nodes which are not part of a local or ghost element
398 : */
399 72244 : virtual void delete_remote_elements () {
400 72244 : _preparation.has_removed_remote_elements = true;
401 72244 : }
402 :
403 : /**
404 : * Loops over ghosting functors and calls mesh_reinit()
405 : */
406 : void reinit_ghosting_functors();
407 :
408 : /**
409 : * \returns The logical dimension of the mesh; i.e. the manifold
410 : * dimension of the elements in the mesh. When we have
411 : * multi-dimensional meshes (e.g. hexes and quads in the same mesh)
412 : * then this will return the largest such dimension.
413 : */
414 : unsigned int mesh_dimension () const;
415 :
416 : /**
417 : * Resets the logical dimension of the mesh. If the mesh has
418 : * elements of multiple dimensions, this should be set to the largest
419 : * dimension. E.g. if the mesh has 1D and 2D elements, this should
420 : * be set to 2. If the mesh has 2D and 3D elements, this should be
421 : * set to 3.
422 : */
423 10694 : void set_mesh_dimension (unsigned char d)
424 317224 : { _elem_dims.clear(); _elem_dims.insert(d); }
425 :
426 : /**
427 : * \returns A const reference to a std::set of element dimensions
428 : * present in the mesh.
429 : */
430 : const std::set<unsigned char> & elem_dimensions() const;
431 :
432 : /**
433 : * \returns A const reference to a std::set of element default
434 : * orders present in the mesh.
435 : */
436 : const std::set<Order> & elem_default_orders() const;
437 :
438 : /**
439 : * \returns The smallest supported_nodal_order() of any element
440 : * present in the mesh, which is thus the maximum supported nodal
441 : * order on the mesh as a whole.
442 : */
443 : Order supported_nodal_order() const;
444 :
445 : /**
446 : * Most of the time you should not need to call this, as the element
447 : * dimensions will be set automatically by a call to cache_elem_data(),
448 : * therefore only call this if you know what you're doing.
449 : *
450 : * In some specialized situations, for example when adding a single
451 : * Elem on all procs, it can be faster to skip calling cache_elem_data()
452 : * and simply specify the element dimensions manually, which is why this
453 : * setter exists.
454 : */
455 : void set_elem_dimensions(std::set<unsigned char> elem_dims);
456 :
457 : /**
458 : * Typedef for the "set" container used to store elemset ids. The
459 : * main requirements are that the entries be sorted and unique, so
460 : * std::set works for this, but there may be more efficient
461 : * alternatives.
462 : */
463 : typedef std::set<elemset_id_type> elemset_type;
464 :
465 : /**
466 : * Tabulate a user-defined "code" for elements which belong to the element sets
467 : * specified in \p id_set. For example, suppose that we have two elemsets A and
468 : * B with the following Elem ids:
469 : * Elemset A = {1, 3}
470 : * Elemset B = {2, 3}
471 : *
472 : * This implies the following mapping from elem id to elemset id:
473 : * Elem 1 -> {A}
474 : * Elem 2 -> {B}
475 : * Elem 3 -> {A,B}
476 : *
477 : * In this case, we would need to tabulate three different elemset codes, e.g.:
478 : * 0 -> {A}
479 : * 1 -> {B}
480 : * 2 -> {A,B}
481 : *
482 : * Also sets up the inverse mapping, so that if one knows all the
483 : * element sets an Elem belongs to, one can look up the
484 : * corresponding elemset code.
485 : */
486 : void add_elemset_code(dof_id_type code, MeshBase::elemset_type id_set);
487 :
488 : /**
489 : * Returns the number of unique elemset ids which have been added
490 : * via add_elemset_code(), which is the size of the _all_elemset_ids
491 : * set.
492 : */
493 : unsigned int n_elemsets() const;
494 :
495 : /**
496 : * Look up the element sets for a given elemset code and
497 : * vice-versa. The elemset must have been previously stored by
498 : * calling add_elemset_code(). If no such code/set is found, returns
499 : * the empty set or DofObject::invalid_id, respectively.
500 : */
501 : void get_elemsets(dof_id_type elemset_code, MeshBase::elemset_type & id_set_to_fill) const;
502 : dof_id_type get_elemset_code(const MeshBase::elemset_type & id_set) const;
503 :
504 : /**
505 : * Return a vector of all elemset codes defined on the mesh. We get
506 : * this by looping over the _elemset_codes map.
507 : */
508 : std::vector<dof_id_type> get_elemset_codes() const;
509 :
510 : /**
511 : * Replace elemset code "old_code" with "new_code". This function loops over
512 : * all elements and changes the extra integer corresponding to the "elemset_code"
513 : * label, and updates the _elemset_codes and _elemset_codes_inverse_map members.
514 : * Does not change the elemset ids of any of the sets.
515 : */
516 : void change_elemset_code(dof_id_type old_code, dof_id_type new_code);
517 :
518 : /**
519 : * Replace elemset id "old_id" with "new_id". Does not change any of the
520 : * elemset codes, so does not need to loop over the elements themselves.
521 : */
522 : void change_elemset_id(elemset_id_type old_id, elemset_id_type new_id);
523 :
524 : /**
525 : * \returns The "spatial dimension" of the mesh.
526 : *
527 : * The spatial dimension is defined as:
528 : *
529 : * 1 - for an exactly x-aligned mesh of 1D elements
530 : * 2 - for an exactly x-y planar mesh of 2D elements
531 : * 3 - otherwise
532 : *
533 : * No tolerance checks are performed to determine whether the Mesh
534 : * is x-aligned or x-y planar, only strict equality with zero in the
535 : * higher dimensions is checked. Also, x-z and y-z planar meshes are
536 : * considered to have spatial dimension == 3.
537 : *
538 : * The spatial dimension is updated during mesh preparation based
539 : * on the dimensions of the various elements present in the Mesh,
540 : * but is *never automatically decreased*.
541 : *
542 : * For example, if the user calls set_spatial_dimension(2) and then
543 : * later inserts 3D elements into the mesh,
544 : * Mesh::spatial_dimension() will return 3 after the next call to
545 : * prepare_for_use() or complete_preparation(). On the other hand,
546 : * if the user calls set_spatial_dimension(3) and then inserts only
547 : * x-aligned 1D elements into the Mesh, mesh.spatial_dimension()
548 : * will remain 3.
549 : */
550 : unsigned int spatial_dimension () const;
551 :
552 : /**
553 : * Sets the "spatial dimension" of the Mesh. See the documentation
554 : * for Mesh::spatial_dimension() for more information.
555 : */
556 : void set_spatial_dimension(unsigned char d);
557 :
558 : /**
559 : * \returns The number of nodes in the mesh.
560 : *
561 : * This function and others must be defined in derived classes since
562 : * the MeshBase class has no specific storage for nodes or elements.
563 : * The standard \p n_nodes() function may return a cached value on
564 : * distributed meshes, and so can be called by any processor at any
565 : * time.
566 : */
567 : virtual dof_id_type n_nodes () const = 0;
568 :
569 : /**
570 : * \returns The number of nodes in the mesh.
571 : *
572 : * This function and others must be overridden in derived classes since
573 : * the MeshBase class has no specific storage for nodes or elements.
574 : * The \p parallel_n_nodes() function computes a parallel-synchronized
575 : * value on distributed meshes, and so must be called in parallel
576 : * only.
577 : */
578 : virtual dof_id_type parallel_n_nodes () const = 0;
579 :
580 : /**
581 : * \returns The number of nodes on processor \p proc.
582 : */
583 : dof_id_type n_nodes_on_proc (const processor_id_type proc) const;
584 :
585 : /**
586 : * \returns The number of nodes on the local processor.
587 : */
588 496 : dof_id_type n_local_nodes () const
589 2055285 : { return this->n_nodes_on_proc (this->processor_id()); }
590 :
591 : /**
592 : * \returns The number of nodes owned by no processor.
593 : */
594 8760 : dof_id_type n_unpartitioned_nodes () const
595 2260643 : { return this->n_nodes_on_proc (DofObject::invalid_processor_id); }
596 :
597 : /**
598 : * \returns A number one greater than the maximum node id in the
599 : * mesh. A more apt name for this method would be end_node_id
600 : */
601 : virtual dof_id_type max_node_id () const = 0;
602 :
603 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
604 : /**
605 : * \returns The next unique id to be used.
606 : */
607 9591 : unique_id_type next_unique_id() const { return _next_unique_id; }
608 :
609 : /**
610 : * Sets the next available unique id to be used. On a
611 : * ReplicatedMesh, or when adding unpartitioned objects to a
612 : * DistributedMesh, this must be kept in sync on all processors.
613 : *
614 : * On a DistributedMesh, other unique_id values (larger than this
615 : * one) may be chosen next, to allow unique_id assignment without
616 : * communication.
617 : */
618 : virtual void set_next_unique_id(unique_id_type id) = 0;
619 : #endif
620 :
621 : /**
622 : * Reserves space for a known number of nodes.
623 : *
624 : * \note This method may or may not do anything, depending on the
625 : * actual \p Mesh implementation. If you know the number of nodes
626 : * you will add and call this method before repeatedly calling \p
627 : * add_point() the implementation will be more efficient.
628 : */
629 : virtual void reserve_nodes (const dof_id_type nn) = 0;
630 :
631 : /**
632 : * \returns The number of elements in the mesh.
633 : *
634 : * The standard n_elem() function may return a cached value on
635 : * distributed meshes, and so can be called by any processor at any
636 : * time.
637 : */
638 : virtual dof_id_type n_elem () const = 0;
639 :
640 : /**
641 : * \returns The number of elements in the mesh.
642 : *
643 : * The parallel_n_elem() function computes a parallel-synchronized
644 : * value on distributed meshes, and so must be called in parallel
645 : * only.
646 : */
647 : virtual dof_id_type parallel_n_elem () const = 0;
648 :
649 : /**
650 : * \returns A number one greater than the maximum element id in the
651 : * mesh. A more apt name for this method would be end_elem_id
652 : */
653 : virtual dof_id_type max_elem_id () const = 0;
654 :
655 : /**
656 : * \returns A number greater than or equal to the maximum unique_id in the
657 : * mesh.
658 : */
659 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
660 : virtual unique_id_type parallel_max_unique_id () const = 0;
661 : #endif
662 :
663 : /**
664 : * Reserves space for a known number of elements.
665 : *
666 : * \note This method may or may not do anything, depending on the
667 : * actual \p Mesh implementation. If you know the number of
668 : * elements you will add and call this method before repeatedly
669 : * calling \p add_point() the implementation will be more efficient.
670 : */
671 : virtual void reserve_elem (const dof_id_type ne) = 0;
672 :
673 : /**
674 : * Updates parallel caches so that methods like n_elem()
675 : * accurately reflect changes on other processors
676 : */
677 : virtual void update_parallel_id_counts () = 0;
678 :
679 : /**
680 : * \returns The number of active elements in the mesh.
681 : *
682 : * Implemented in terms of active_element_iterators.
683 : */
684 : virtual dof_id_type n_active_elem () const = 0;
685 :
686 : /**
687 : * \returns The number of elements on processor \p proc.
688 : */
689 : dof_id_type n_elem_on_proc (const processor_id_type proc) const;
690 :
691 : /**
692 : * \returns The number of elements on the local processor.
693 : */
694 480 : dof_id_type n_local_elem () const
695 2054266 : { return this->n_elem_on_proc (this->processor_id()); }
696 :
697 : /**
698 : * \returns The number of elements owned by no processor.
699 : */
700 22644 : dof_id_type n_unpartitioned_elem () const
701 2726117 : { return this->n_elem_on_proc (DofObject::invalid_processor_id); }
702 :
703 : /**
704 : * \returns The number of active elements on processor \p proc.
705 : */
706 : dof_id_type n_active_elem_on_proc (const processor_id_type proc) const;
707 :
708 : /**
709 : * \returns The number of active elements on the local processor.
710 : */
711 216 : dof_id_type n_active_local_elem () const
712 1378341 : { return this->n_active_elem_on_proc (this->processor_id()); }
713 :
714 : /**
715 : * \returns The number of elements that will be written
716 : * out in certain I/O formats.
717 : *
718 : * For example, a 9-noded quadrilateral will be broken into 4 linear
719 : * sub-elements for plotting purposes. Thus, for a mesh of 2 \p
720 : * QUAD9 elements \p n_tecplot_elem() will return 8. Implemented in
721 : * terms of element_iterators.
722 : */
723 : dof_id_type n_sub_elem () const;
724 :
725 : /**
726 : * Same as \p n_sub_elem(), but only counts active elements.
727 : */
728 : dof_id_type n_active_sub_elem () const;
729 :
730 : /**
731 : * \returns A constant reference (for reading only) to the
732 : * \f$ i^{th} \f$ point, which should be present in this processor's
733 : * subset of the mesh data structure.
734 : */
735 : virtual const Point & point (const dof_id_type i) const = 0;
736 :
737 : /**
738 : * \returns A constant reference (for reading only) to the
739 : * \f$ i^{th} \f$ node, which should be present in this processor's
740 : * subset of the mesh data structure.
741 : */
742 60176589 : virtual const Node & node_ref (const dof_id_type i) const
743 : {
744 60176589 : return *this->node_ptr(i);
745 : }
746 :
747 : /**
748 : * \returns A reference to the \f$ i^{th} \f$ node, which should be
749 : * present in this processor's subset of the mesh data structure.
750 : */
751 406056179 : virtual Node & node_ref (const dof_id_type i)
752 : {
753 406056179 : return *this->node_ptr(i);
754 : }
755 :
756 : /**
757 : * \returns A pointer to the \f$ i^{th} \f$ node, which should be
758 : * present in this processor's subset of the mesh data structure.
759 : */
760 : virtual const Node * node_ptr (const dof_id_type i) const = 0;
761 :
762 : /**
763 : * \returns A writable pointer to the \f$ i^{th} \f$ node, which
764 : * should be present in this processor's subset of the mesh data
765 : * structure.
766 : */
767 : virtual Node * node_ptr (const dof_id_type i) = 0;
768 :
769 : /**
770 : * \returns A pointer to the \f$ i^{th} \f$ node, or \p nullptr if no such
771 : * node exists in this processor's mesh data structure.
772 : */
773 : virtual const Node * query_node_ptr (const dof_id_type i) const = 0;
774 :
775 : /**
776 : * \returns A writable pointer to the \f$ i^{th} \f$ node, or \p nullptr if
777 : * no such node exists in this processor's mesh data structure.
778 : */
779 : virtual Node * query_node_ptr (const dof_id_type i) = 0;
780 :
781 : /**
782 : * \returns A reference to the \f$ i^{th} \f$ element, which should be
783 : * present in this processor's subset of the mesh data structure.
784 : */
785 5306288 : virtual const Elem & elem_ref (const dof_id_type i) const
786 : {
787 5306288 : return *this->elem_ptr(i);
788 : }
789 :
790 : /**
791 : * \returns A writable reference to the \f$ i^{th} \f$ element, which
792 : * should be present in this processor's subset of the mesh data
793 : * structure.
794 : */
795 306080001 : virtual Elem & elem_ref (const dof_id_type i)
796 : {
797 306080001 : return *this->elem_ptr(i);
798 : }
799 :
800 : /**
801 : * \returns A pointer to the \f$ i^{th} \f$ element, which should be
802 : * present in this processor's subset of the mesh data structure.
803 : */
804 : virtual const Elem * elem_ptr (const dof_id_type i) const = 0;
805 :
806 : /**
807 : * \returns A writable pointer to the \f$ i^{th} \f$ element, which
808 : * should be present in this processor's subset of the mesh data
809 : * structure.
810 : */
811 : virtual Elem * elem_ptr (const dof_id_type i) = 0;
812 :
813 : /**
814 : * \returns A pointer to the \f$ i^{th} \f$ element, or nullptr if no
815 : * such element exists in this processor's mesh data structure.
816 : */
817 : virtual const Elem * query_elem_ptr (const dof_id_type i) const = 0;
818 :
819 : /**
820 : * \returns A writable pointer to the \f$ i^{th} \f$ element, or nullptr
821 : * if no such element exists in this processor's mesh data structure.
822 : */
823 : virtual Elem * query_elem_ptr (const dof_id_type i) = 0;
824 :
825 : /**
826 : * Add a new \p Node at \p Point \p p to the end of the vertex array,
827 : * with processor_id \p procid.
828 : * Use DofObject::invalid_processor_id (default) to add a node to all
829 : * processors, or this->processor_id() to add a node to the local
830 : * processor only.
831 : * If adding a node locally, passing an \p id other than
832 : * DofObject::invalid_id will set that specific node id. Only
833 : * do this in parallel if you are manually keeping ids consistent.
834 : */
835 : virtual Node * add_point (const Point & p,
836 : const dof_id_type id = DofObject::invalid_id,
837 : const processor_id_type proc_id =
838 : DofObject::invalid_processor_id) = 0;
839 :
840 : /**
841 : * Add \p Node \p n to the end of the vertex array.
842 : */
843 : virtual Node * add_node (Node * n) = 0;
844 :
845 : /**
846 : * Version of add_node() taking a std::unique_ptr by value. The version
847 : * taking a dumb pointer will eventually be deprecated in favor of this
848 : * version. This API is intended to indicate that ownership of the Node
849 : * is transferred to the Mesh when this function is called, and it should
850 : * play more nicely with the Node::build() API which has always returned
851 : * a std::unique_ptr.
852 : */
853 : virtual Node * add_node (std::unique_ptr<Node> n) = 0;
854 :
855 : /**
856 : * Removes the Node n from the mesh.
857 : */
858 : virtual void delete_node (Node * n) = 0;
859 :
860 : /**
861 : * Takes ownership of node \p n on this partition of a distributed
862 : * mesh, by setting n.processor_id() to this->processor_id(), as
863 : * well as changing n.id() and moving it in the mesh's internal
864 : * container to give it a new authoritative id.
865 : */
866 0 : virtual void own_node (Node &) {}
867 :
868 : /**
869 : * Changes the id of node \p old_id, both by changing node(old_id)->id() and
870 : * by moving node(old_id) in the mesh's internal container. No element with
871 : * the id \p new_id should already exist.
872 : */
873 : virtual void renumber_node (dof_id_type old_id, dof_id_type new_id) = 0;
874 :
875 : /**
876 : * Add elem \p e to the end of the element array.
877 : * To add an element locally, set e->processor_id() before adding it.
878 : * To ensure a specific element id, call e->set_id() before adding it;
879 : * only do this in parallel if you are manually keeping ids consistent.
880 : *
881 : * Users should call MeshBase::complete_preparation() after elements are
882 : * added to and/or deleted from the mesh.
883 : */
884 : virtual Elem * add_elem (Elem * e) = 0;
885 :
886 : /**
887 : * Version of add_elem() taking a std::unique_ptr by value. The version
888 : * taking a dumb pointer will eventually be deprecated in favor of this
889 : * version. This API is intended to indicate that ownership of the Elem
890 : * is transferred to the Mesh when this function is called, and it should
891 : * play more nicely with the Elem::build() API which has always returned
892 : * a std::unique_ptr.
893 : */
894 : virtual Elem * add_elem (std::unique_ptr<Elem> e) = 0;
895 :
896 : /**
897 : * Insert elem \p e to the element array, preserving its id
898 : * and replacing/deleting any existing element with the same id.
899 : *
900 : * Users should call MeshBase::complete_preparation() after elements are
901 : * added to and/or deleted from the mesh.
902 : */
903 : virtual Elem * insert_elem (Elem * e) = 0;
904 :
905 : /**
906 : * Version of insert_elem() taking a std::unique_ptr by value. The version
907 : * taking a dumb pointer will eventually be deprecated in favor of this
908 : * version. This API is intended to indicate that ownership of the Elem
909 : * is transferred to the Mesh when this function is called, and it should
910 : * play more nicely with the Elem::build() API which has always returned
911 : * a std::unique_ptr.
912 : */
913 : virtual Elem * insert_elem (std::unique_ptr<Elem> e) = 0;
914 :
915 : /**
916 : * Removes element \p e from the mesh. This method must be
917 : * implemented in derived classes in such a way that it does not
918 : * invalidate element iterators. Users should call
919 : * MeshBase::complete_preparation() after elements are added to
920 : * and/or deleted from the mesh.
921 : *
922 : * \note Calling this method may produce isolated nodes, i.e. nodes
923 : * not connected to any element.
924 : */
925 : virtual void delete_elem (Elem * e) = 0;
926 :
927 : /**
928 : * Changes the id of element \p old_id, both by changing elem(old_id)->id()
929 : * and by moving elem(old_id) in the mesh's internal container. No element
930 : * with the id \p new_id should already exist.
931 : */
932 : virtual void renumber_elem (dof_id_type old_id, dof_id_type new_id) = 0;
933 :
934 : /**
935 : * Returns the default master space to physical space mapping basis
936 : * functions to be used on newly added elements.
937 : */
938 859001 : ElemMappingType default_mapping_type () const
939 : {
940 58944590 : return _default_mapping_type;
941 : }
942 :
943 : /**
944 : * Set the default master space to physical space mapping basis
945 : * functions to be used on newly added elements.
946 : */
947 44 : void set_default_mapping_type (const ElemMappingType type)
948 : {
949 16431 : _default_mapping_type = type;
950 44 : }
951 :
952 : /**
953 : * Returns any default data value used by the master space to
954 : * physical space mapping.
955 : */
956 859001 : unsigned char default_mapping_data () const
957 : {
958 58944590 : return _default_mapping_data;
959 : }
960 :
961 : /**
962 : * Set the default master space to physical space mapping basis
963 : * functions to be used on newly added elements.
964 : */
965 44 : void set_default_mapping_data (const unsigned char data)
966 : {
967 16431 : _default_mapping_data = data;
968 44 : }
969 :
970 : /**
971 : * Locate element face (edge in 2D) neighbors. This is done with the help
972 : * of a \p std::map that functions like a hash table.
973 : * After this routine is called all the elements with a \p nullptr neighbor
974 : * pointer are guaranteed to be on the boundary. Thus this routine is
975 : * useful for automatically determining the boundaries of the domain.
976 : *
977 : * If \p reset_remote_elements is left to false, remote neighbor
978 : * links are not reset and searched for in the local mesh.
979 : *
980 : * If \p reset_current_list is left as true, then any existing links
981 : * will be reset before initiating the algorithm, while honoring the
982 : * value of the \p reset_remote_elements flag.
983 : *
984 : * If \p assert_valid is left as true, then in dbg mode extensive
985 : * consistency checking is performed before returning.
986 : */
987 : virtual void find_neighbors (const bool reset_remote_elements = false,
988 : const bool reset_current_list = true,
989 : const bool assert_valid = true) = 0;
990 :
991 : /**
992 : * Removes any orphaned nodes, nodes not connected to any elements.
993 : * Typically done automatically in a preparation step
994 : */
995 : void remove_orphaned_nodes ();
996 :
997 : /**
998 : * After partitioning a mesh it is useful to renumber the nodes and elements
999 : * so that they lie in contiguous blocks on the processors. This method
1000 : * does just that.
1001 : */
1002 : virtual void renumber_nodes_and_elements () = 0;
1003 :
1004 : /**
1005 : * There is no reason for a user to ever call this function.
1006 : *
1007 : * This function restores a previously broken element/node numbering such that
1008 : * \p mesh.node_ref(n).id() == n.
1009 : */
1010 : virtual void fix_broken_node_and_element_numbering () = 0;
1011 :
1012 :
1013 : #ifdef LIBMESH_ENABLE_AMR
1014 : /**
1015 : * Delete subactive (i.e. children of coarsened) elements.
1016 : * This removes all elements descended from currently active
1017 : * elements in the mesh.
1018 : */
1019 : virtual bool contract () = 0;
1020 : #endif
1021 :
1022 : /**
1023 : * Register an integer datum (of type dof_id_type) to be added to
1024 : * each element in the mesh.
1025 : *
1026 : * If the mesh already has elements, data by default is allocated in
1027 : * each of them. This may be expensive to do repeatedly; use
1028 : * add_elem_integers instead. Alternatively, the \p allocate_data
1029 : * option can be manually set to false, but if this is done then a
1030 : * manual call to \p size_elem_extra_integers() will need to be done
1031 : * before the new space is usable.
1032 : *
1033 : * Newly allocated values for the new datum will be initialized to
1034 : * \p default_value
1035 : *
1036 : * \returns The index number for the new datum, or for the existing
1037 : * datum if one by the same name has already been added.
1038 : */
1039 : unsigned int add_elem_integer(std::string name,
1040 : bool allocate_data = true,
1041 : dof_id_type default_value = DofObject::invalid_id);
1042 :
1043 : /**
1044 : * Register integer data (of type dof_id_type) to be added to
1045 : * each element in the mesh, one string name for each new integer.
1046 : *
1047 : * If the mesh already has elements, data by default is allocated in
1048 : * each of them.
1049 : *
1050 : * Newly allocated values for the new datum with name \p names[i]
1051 : * will be initialized to \p default_values[i], or to
1052 : * DofObject::invalid_id if \p default_values is null.
1053 : *
1054 : * \returns The index numbers for the new data, and/or for existing
1055 : * data if data by some of the same names has already been added.
1056 : */
1057 : std::vector<unsigned int> add_elem_integers(const std::vector<std::string> & names,
1058 : bool allocate_data = true,
1059 : const std::vector<dof_id_type> * default_values = nullptr);
1060 :
1061 : /*
1062 : * \returns The index number for the named extra element integer
1063 : * datum, which must have already been added.
1064 : */
1065 : unsigned int get_elem_integer_index(std::string_view name) const;
1066 :
1067 : /*
1068 : * \returns Whether or not the mesh has an element integer with its name.
1069 : */
1070 : bool has_elem_integer(std::string_view name) const;
1071 :
1072 : /*
1073 : * \returns The name for the indexed extra element integer
1074 : * datum, which must have already been added.
1075 : */
1076 19 : const std::string & get_elem_integer_name(unsigned int i) const
1077 38 : { return _elem_integer_names[i]; }
1078 :
1079 : /*
1080 : * \returns The number of extra element integers for which space is
1081 : * being reserved on this mesh.
1082 : *
1083 : * If non-integer data has been associated, each datum of type T
1084 : * counts for sizeof(T)/sizeof(dof_id_type) times in the return
1085 : * value.
1086 : */
1087 916 : unsigned int n_elem_integers() const { return _elem_integer_names.size(); }
1088 :
1089 : /**
1090 : * Register a datum (of type T) to be added to each element in the
1091 : * mesh.
1092 : *
1093 : * If the mesh already has elements, data by default is allocated in
1094 : * each of them. This may be expensive to do repeatedly; use
1095 : * add_elem_data instead. Alternatively, the \p allocate_data
1096 : * option can be manually set to false, but if this is done then a
1097 : * manual call to \p size_elem_extra_integers() will need to be done
1098 : * before the new space is usable.
1099 : *
1100 : * Newly allocated values for the new datum will be initialized to
1101 : * \p *default_value if \p default_value is not null, or to
1102 : * meaningless memcpy output otherwise.
1103 : *
1104 : * \returns The index numbers for the new data, and/or for existing
1105 : * data if data by some of the same names has already been added.
1106 : *
1107 : * If type T is larger than dof_id_type, its data will end up
1108 : * spanning multiple index values, but will be queried with the
1109 : * starting index number.
1110 : *
1111 : * No type checking is done with this function! If you add data of
1112 : * type T, don't try to access it with a call specifying type U.
1113 : */
1114 : template <typename T>
1115 : unsigned int add_elem_datum(const std::string & name,
1116 : bool allocate_data = true,
1117 : const T * default_value = nullptr);
1118 :
1119 : /**
1120 : * Register data (of type T) to be added to each element in the
1121 : * mesh.
1122 : *
1123 : * If the mesh already has elements, data is allocated in each.
1124 : *
1125 : * Newly allocated values for the new datum with name \p names[i]
1126 : * will be initialized to \p default_values[i], or to
1127 : * meaningless memcpy output if \p default_values is null.
1128 : *
1129 : * \returns The starting index number for the new data, or for the
1130 : * existing data if one by the same name has already been added.
1131 : *
1132 : * If type T is larger than dof_id_type, each datum will end up
1133 : * spanning multiple index values, but will be queried with the
1134 : * starting index number.
1135 : *
1136 : * No type checking is done with this function! If you add data of
1137 : * type T, don't try to access it with a call specifying type U.
1138 : */
1139 : template <typename T>
1140 : std::vector<unsigned int> add_elem_data(const std::vector<std::string> & names,
1141 : bool allocate_data = true,
1142 : const std::vector<T> * default_values = nullptr);
1143 :
1144 : /**
1145 : * Register an integer datum (of type dof_id_type) to be added to
1146 : * each node in the mesh.
1147 : *
1148 : * If the mesh already has nodes, data by default is allocated in
1149 : * each of them. This may be expensive to do repeatedly; use
1150 : * add_node_integers instead. Alternatively, the \p allocate_data
1151 : * option can be manually set to false, but if this is done then a
1152 : * manual call to \p size_node_extra_integers() will need to be done
1153 : * before the new space is usable.
1154 : *
1155 : * Newly allocated values for the new datum will be initialized to
1156 : * \p default_value
1157 : *
1158 : * \returns The index number for the new datum, or for the existing
1159 : * datum if one by the same name has already been added.
1160 : */
1161 : unsigned int add_node_integer(std::string name,
1162 : bool allocate_data = true,
1163 : dof_id_type default_value = DofObject::invalid_id);
1164 :
1165 : /**
1166 : * Register integer data (of type dof_id_type) to be added to
1167 : * each node in the mesh.
1168 : *
1169 : * If the mesh already has nodes, data by default is allocated in
1170 : * each.
1171 : *
1172 : * Newly allocated values for the new datum with name \p names[i]
1173 : * will be initialized to \p default_values[i], or to
1174 : * DofObject::invalid_id if \p default_values is null.
1175 : *
1176 : * \returns The index numbers for the new data, and/or for existing
1177 : * data if data by some of the same names has already been added.
1178 : */
1179 : std::vector<unsigned int> add_node_integers(const std::vector<std::string> & names,
1180 : bool allocate_data = true,
1181 : const std::vector<dof_id_type> * default_values = nullptr);
1182 :
1183 : /*
1184 : * \returns The index number for the named extra node integer
1185 : * datum, which must have already been added.
1186 : */
1187 : unsigned int get_node_integer_index(std::string_view name) const;
1188 :
1189 : /*
1190 : * \returns Whether or not the mesh has a node integer with its name.
1191 : */
1192 : bool has_node_integer(std::string_view name) const;
1193 :
1194 : /*
1195 : * \returns The name for the indexed extra node integer
1196 : * datum, which must have already been added.
1197 : */
1198 36 : const std::string & get_node_integer_name(unsigned int i) const
1199 72 : { return _node_integer_names[i]; }
1200 :
1201 : /*
1202 : * \returns The number of extra node integers for which space is
1203 : * being reserved on this mesh.
1204 : *
1205 : * If non-integer data has been associated, each datum of type T
1206 : * counts for sizeof(T)/sizeof(dof_id_type) times in the return
1207 : * value.
1208 : */
1209 916 : unsigned int n_node_integers() const { return _node_integer_names.size(); }
1210 :
1211 : /**
1212 : * Register a datum (of type T) to be added to each node in the
1213 : * mesh.
1214 : *
1215 : * If the mesh already has nodes, data by default is allocated in
1216 : * each of them. This may be expensive to do repeatedly; use
1217 : * add_node_data instead. Alternatively, the \p allocate_data
1218 : * option can be manually set to false, but if this is done then a
1219 : * manual call to \p size_node_extra_integers() will need to be done
1220 : * before the new space is usable.
1221 : *
1222 : * Newly allocated values for the new datum will be initialized to
1223 : * \p *default_value if \p default_value is not null, or to
1224 : * meaningless memcpy output otherwise.
1225 : *
1226 : * \returns The starting index number for the new datum, or for the
1227 : * existing datum if one by the same name has already been added.
1228 : *
1229 : * If type T is larger than dof_id_type, its data will end up
1230 : * spanning multiple index values, but will be queried with the
1231 : * starting index number.
1232 : *
1233 : * No type checking is done with this function! If you add data of
1234 : * type T, don't try to access it with a call specifying type U.
1235 : */
1236 : template <typename T>
1237 : unsigned int add_node_datum(const std::string & name,
1238 : bool allocate_data = true,
1239 : const T * default_value = nullptr);
1240 :
1241 : /**
1242 : * Register data (of type T) to be added to each node in the
1243 : * mesh.
1244 : *
1245 : * If the mesh already has nodes, data by default is allocated in each.
1246 : *
1247 : * Newly allocated values for the new datum with name \p names[i]
1248 : * will be initialized to \p default_values[i], or to
1249 : * meaningless memcpy output if \p default_values is null.
1250 : *
1251 : * \returns The starting index number for the new data, or for the
1252 : * existing data if one by the same name has already been added.
1253 : *
1254 : * If type T is larger than dof_id_type, its data will end up
1255 : * spanning multiple index values, but will be queried with the
1256 : * starting index number.
1257 : *
1258 : * No type checking is done with this function! If you add data of
1259 : * type T, don't try to access it with a call specifying type U.
1260 : */
1261 : template <typename T>
1262 : std::vector<unsigned int> add_node_data(const std::vector<std::string> & name,
1263 : bool allocate_data = true,
1264 : const std::vector<T> * default_values = nullptr);
1265 :
1266 : /**
1267 : * Prepare a newly created (or read) mesh for use.
1268 : * This involves several steps:
1269 : * 1.) renumbering (if enabled)
1270 : * 2.) removing any orphaned nodes
1271 : * 3.) updating parallel id counts
1272 : * 4.) finding neighbor links
1273 : * 5.) caching summarized element data
1274 : * 6.) finding interior parent links
1275 : * 7.) clearing any old point locator
1276 : * 8.) calling reinit() on ghosting functors
1277 : * 9.) repartitioning (if enabled)
1278 : * 10.) removing any remote elements (if enabled)
1279 : * 11.) regenerating summarized boundary id sets
1280 : *
1281 : * For backwards compatibility, prepare_for_use() performs *all* those
1282 : * steps, regardless of the official preparation() state of the
1283 : * mesh. In codes which have maintained a valid preparation() state
1284 : * via methods such as unset_has_synched_id_counts(), calling
1285 : * complete_preparation() will result in a fully-prepared mesh at
1286 : * less cost.
1287 : *
1288 : * The argument to skip renumbering is now deprecated - to prevent a
1289 : * mesh from being renumbered, set allow_renumbering(false). The argument to skip
1290 : * finding neighbors is also deprecated. To prevent find_neighbors, set
1291 : * allow_find_neighbors(false)
1292 : *
1293 : * If this is a distributed mesh, local copies of remote elements
1294 : * will be deleted here - to keep those elements replicated during
1295 : * preparation, set allow_remote_element_removal(false).
1296 : */
1297 : #ifdef LIBMESH_ENABLE_DEPRECATED
1298 : void prepare_for_use (const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors);
1299 : void prepare_for_use (const bool skip_renumber_nodes_and_elements);
1300 : #endif // LIBMESH_ENABLE_DEPRECATED
1301 : void prepare_for_use ();
1302 :
1303 : /*
1304 : * Prepare a newly created or modified mesh for use.
1305 : *
1306 : * Unlike \p prepare_for_use(), \p complete_preparation() performs
1307 : * *only* those preparatory steps that have been marked as
1308 : * necessary in the MeshBase::Preparation state.
1309 : */
1310 : void complete_preparation();
1311 :
1312 : /**
1313 : * Call the default partitioner (currently \p metis_partition()).
1314 : */
1315 : virtual void partition (const unsigned int n_parts);
1316 :
1317 2018 : void partition ()
1318 467088 : { this->partition(this->n_processors()); }
1319 :
1320 : /**
1321 : * Redistribute elements between processors. This gets called
1322 : * automatically by the Partitioner, and merely notifies any
1323 : * GhostingFunctors of redistribution in the case of a
1324 : * ReplicatedMesh or serialized DistributedMesh
1325 : */
1326 : virtual void redistribute ();
1327 :
1328 : /**
1329 : * Recalculate any cached data (or invalidate any caches that are
1330 : * computed on the fly) after elements and nodes have been
1331 : * repartitioned.
1332 : */
1333 : virtual void update_post_partitioning ();
1334 :
1335 : /**
1336 : * If false is passed in then this mesh will no longer be renumbered
1337 : * when being prepared for use. This may slightly adversely affect
1338 : * performance during subsequent element access, particularly when
1339 : * using a distributed mesh.
1340 : *
1341 : * Important! When allow_renumbering(false) is set,
1342 : * ReplicatedMesh::n_elem() and ReplicatedMesh::n_nodes() will
1343 : * return *wrong* values whenever adaptive refinement is followed by
1344 : * adaptive coarsening. (Uniform refinement followed by uniform
1345 : * coarsening is OK.) This is due to the fact that n_elem() and
1346 : * n_nodes() are currently O(1) functions that just return the size
1347 : * of the respective underlying vectors, and this size is wrong when
1348 : * the numbering includes "gaps" from nodes and elements that have
1349 : * been deleted. We plan to implement a caching mechanism in the
1350 : * near future that will fix this incorrect behavior.
1351 : */
1352 77681 : void allow_renumbering(bool allow) { _skip_renumber_nodes_and_elements = !allow; }
1353 48264 : bool allow_renumbering() const { return !_skip_renumber_nodes_and_elements; }
1354 :
1355 : /**
1356 : * If \p false is passed then this mesh will no longer work to find element
1357 : * neighbors when being prepared for use
1358 : */
1359 74785 : void allow_find_neighbors(bool allow) { _skip_find_neighbors = !allow; }
1360 176178 : bool allow_find_neighbors() const { return !_skip_find_neighbors; }
1361 :
1362 : /**
1363 : * If \p false is passed then this mesh will no longer work to detect
1364 : * interior parents when being prepared for use
1365 : */
1366 30457 : void allow_detect_interior_parents(bool allow) { _skip_detect_interior_parents = !allow; }
1367 29683 : bool allow_detect_interior_parents() const { return !_skip_detect_interior_parents; }
1368 :
1369 : /**
1370 : * If false is passed in then this mesh will no longer have remote
1371 : * elements deleted when being prepared for use; i.e. even a
1372 : * DistributedMesh will remain (if it is already) serialized.
1373 : * This may adversely affect performance and memory use.
1374 : */
1375 753516 : void allow_remote_element_removal(bool allow) { _allow_remote_element_removal = allow; }
1376 425674 : bool allow_remote_element_removal() const { return _allow_remote_element_removal; }
1377 :
1378 : /**
1379 : * If \p true is passed, then this mesh will no longer require
1380 : * unique_ids to be unique across the set of all DofObjects. That
1381 : * is, although no two Elems (resp. Nodes) will share the same
1382 : * unique_id, a given Elem and Node might share the same unique_id.
1383 : */
1384 142 : void allow_node_and_elem_unique_id_overlap(bool allow) { _allow_node_and_elem_unique_id_overlap = allow; }
1385 40574 : bool allow_node_and_elem_unique_id_overlap() const { return _allow_node_and_elem_unique_id_overlap; }
1386 :
1387 : /**
1388 : * If true is passed in then the elements on this mesh will no
1389 : * longer be (re)partitioned, and the nodes on this mesh will only
1390 : * be repartitioned if they are found "orphaned" via coarsening or
1391 : * other removal of the last element responsible for their
1392 : * node/element processor id consistency.
1393 : *
1394 : * \note It would probably be a bad idea to call this on a
1395 : * DistributedMesh _before_ the first partitioning has happened...
1396 : * because no elements would get assigned to your processor pool.
1397 : *
1398 : * \note Skipping partitioning can have adverse effects on your
1399 : * performance when using AMR... i.e. you could get large load
1400 : * imbalances. However you might still want to use this if the
1401 : * communication and computation of the rebalance and repartition is
1402 : * too high for your application.
1403 : *
1404 : * It is also possible, for backwards-compatibility purposes, to
1405 : * skip noncritical partitioning by resetting the partitioner()
1406 : * pointer for this mesh.
1407 : */
1408 : void skip_noncritical_partitioning(bool skip)
1409 : { _skip_noncritical_partitioning = skip; }
1410 :
1411 3880 : bool skip_noncritical_partitioning() const
1412 160016 : { return _skip_noncritical_partitioning || _skip_all_partitioning || !_partitioner.get(); }
1413 :
1414 :
1415 : /**
1416 : * If true is passed in then nothing on this mesh will be
1417 : * (re)partitioned.
1418 : *
1419 : * \note The caveats for skip_noncritical_partitioning() still
1420 : * apply, and removing elements from a mesh with this setting
1421 : * enabled can leave node processor ids in an inconsistent state
1422 : * (not matching any attached element), causing failures in other
1423 : * library code. Do not use this setting along with element
1424 : * deletion or coarsening.
1425 : */
1426 29984 : void skip_partitioning(bool skip) { _skip_all_partitioning = skip; }
1427 :
1428 713990 : bool skip_partitioning() const { return _skip_all_partitioning; }
1429 :
1430 : /**
1431 : * Adds a functor which can specify ghosting requirements for use on
1432 : * distributed meshes. Multiple ghosting functors can be added; any
1433 : * element which is required by any functor will be ghosted.
1434 : *
1435 : * GhostingFunctor memory must be managed by the code which calls
1436 : * this function; the GhostingFunctor lifetime is expected to extend
1437 : * until either the functor is removed or the Mesh is destructed.
1438 : */
1439 : void add_ghosting_functor(GhostingFunctor & ghosting_functor);
1440 :
1441 : /**
1442 : * Adds a functor which can specify ghosting requirements for use on
1443 : * distributed meshes. Multiple ghosting functors can be added; any
1444 : * element which is required by any functor will be ghosted.
1445 : *
1446 : * GhostingFunctor memory when using this method is managed by the
1447 : * shared_ptr mechanism.
1448 : */
1449 30768 : void add_ghosting_functor(std::shared_ptr<GhostingFunctor> ghosting_functor)
1450 60548 : { _shared_functors[ghosting_functor.get()] = ghosting_functor;
1451 30768 : this->add_ghosting_functor(*ghosting_functor); }
1452 :
1453 : /**
1454 : * Removes a functor which was previously added to the set of
1455 : * ghosting functors.
1456 : */
1457 : void remove_ghosting_functor(GhostingFunctor & ghosting_functor);
1458 :
1459 : /**
1460 : * Iterator type for ghosting functor ranges. This has changed in
1461 : * the past and may change again; code should use auto or the type
1462 : * here.
1463 : */
1464 : typedef std::vector<GhostingFunctor *>::const_iterator GhostingFunctorIterator;
1465 :
1466 : /**
1467 : * Beginning of range of ghosting functors
1468 : */
1469 2662 : GhostingFunctorIterator ghosting_functors_begin() const
1470 18615 : { return _ghosting_functors.begin(); }
1471 :
1472 : /**
1473 : * End of range of ghosting functors
1474 : */
1475 2662 : GhostingFunctorIterator ghosting_functors_end() const
1476 18615 : { return _ghosting_functors.end(); }
1477 :
1478 : /**
1479 : * Default ghosting functor
1480 : */
1481 6 : GhostingFunctor & default_ghosting() { return *_default_ghosting; }
1482 :
1483 : /**
1484 : * Constructs a list of all subdomain identifiers in the local mesh if
1485 : * \p global == false, and in the global mesh if \p global == true (default).
1486 : * Subdomains correspond to separate subsets of the mesh which could correspond
1487 : * e.g. to different materials in a solid mechanics application,
1488 : * or regions where different physical processes are important. The subdomain
1489 : * mapping is independent from the parallel decomposition.
1490 : *
1491 : * Unpartitioned elements are included in the set in the case that \p
1492 : * global == true. If \p global == false, the unpartitioned elements are not
1493 : * included because unpartitioned elements do not have a sense of locality.
1494 : */
1495 : void subdomain_ids (std::set<subdomain_id_type> & ids, const bool global = true) const;
1496 :
1497 : /**
1498 : * \returns The number of subdomains in the global mesh. Subdomains correspond
1499 : * to separate subsets of the mesh which could correspond e.g. to different
1500 : * materials in a solid mechanics application, or regions where different
1501 : * physical processes are important. The subdomain mapping is independent
1502 : * from the parallel decomposition.
1503 : */
1504 : subdomain_id_type n_subdomains () const;
1505 :
1506 : /**
1507 : * \returns The number of subdomains in the local mesh. Subdomains correspond
1508 : * to separate subsets of the mesh which could correspond e.g. to different
1509 : * materials in a solid mechanics application, or regions where different
1510 : * physical processes are important. The subdomain mapping is independent
1511 : * from the parallel decomposition.
1512 : */
1513 : subdomain_id_type n_local_subdomains () const;
1514 :
1515 : /**
1516 : * \returns The number of partitions which have been defined via
1517 : * a call to either mesh.partition() or by building a Partitioner
1518 : * object and calling partition.
1519 : *
1520 : * \note The partitioner object is responsible for setting this
1521 : * value.
1522 : */
1523 6934 : unsigned int n_partitions () const
1524 56653 : { return _n_parts; }
1525 :
1526 : /**
1527 : * \returns A string containing relevant information
1528 : * about the mesh.
1529 : *
1530 : * \p verbosity sets the verbosity, with 0 being the least and 2 being the greatest.
1531 : * 0 - Dimensions, number of nodes, number of elems, number of subdomains, number of
1532 : * partitions, prepared status.
1533 : * 1 - Adds the mesh bounding box, mesh element types, specific nodesets/edgesets/sidesets
1534 : * with element types, number of nodes/edges/sides.
1535 : * 2 - Adds volume information and bounding boxes to boundary information.
1536 : *
1537 : * The \p global parameter pertains primarily to verbosity levels 1 and above.
1538 : * When \p global == true, information is only output on rank 0 and the information
1539 : * is reduced. When \p global == false, information is output on all ranks that pertains
1540 : * only to that local partition.
1541 : */
1542 : std::string get_info (const unsigned int verbosity = 0, const bool global = true) const;
1543 :
1544 : /**
1545 : * Prints relevant information about the mesh.
1546 : *
1547 : * Take note of the docstring for get_info() for more information pretaining to
1548 : * the \p verbosity and \p global parameters.
1549 : */
1550 : void print_info (std::ostream & os=libMesh::out, const unsigned int verbosity = 0, const bool global = true) const;
1551 :
1552 : /**
1553 : * Equivalent to calling print_info() above, but now you can write:
1554 : * Mesh mesh;
1555 : * libMesh::out << mesh << std::endl;
1556 : */
1557 : friend std::ostream & operator << (std::ostream & os, const MeshBase & m);
1558 :
1559 : /**
1560 : * Interfaces for reading/writing a mesh to/from a file. Must be
1561 : * implemented in derived classes.
1562 : */
1563 : virtual void read (const std::string & name,
1564 : void * mesh_data=nullptr,
1565 : bool skip_renumber_nodes_and_elements=false,
1566 : bool skip_find_neighbors=false,
1567 : bool skip_detect_interior_parents=false) = 0;
1568 : virtual void write (const std::string & name) const = 0;
1569 :
1570 : /**
1571 : * Converts a mesh with higher-order
1572 : * elements into a mesh with linear elements. For
1573 : * example, a mesh consisting of \p Tet10 will be converted
1574 : * to a mesh with \p Tet4 etc.
1575 : */
1576 : virtual void all_first_order () = 0;
1577 :
1578 : /**
1579 : * We need an empty, generic class to act as a predicate for this
1580 : * and derived mesh classes.
1581 : */
1582 : typedef Predicates::multi_predicate Predicate;
1583 :
1584 : /**
1585 : * structs for the element_iterator's.
1586 : *
1587 : * \note These iterators were designed so that derived mesh classes
1588 : * could use the _same_ base class iterators interchangeably. Their
1589 : * definition comes later in the header file.
1590 : */
1591 : struct element_iterator;
1592 : struct const_element_iterator;
1593 :
1594 : /**
1595 : * structs for the node_iterator's.
1596 : *
1597 : * \note These iterators were designed so that derived mesh classes
1598 : * could use the _same_ base class iterators interchangeably. Their
1599 : * definition comes later in the header file.
1600 : */
1601 : struct node_iterator;
1602 : struct const_node_iterator;
1603 :
1604 : /**
1605 : * Converts a set of this Mesh's elements defined by \p range from
1606 : * FIRST order to SECOND order. Must be called on conforming,
1607 : * non-refined meshes. For example, a mesh consisting of \p Tet4
1608 : * will be converted to a mesh with \p Tet10 etc.
1609 : *
1610 : * \note For some elements like \p Hex8 there exist two higher order
1611 : * equivalents, \p Hex20 and \p Hex27. When \p full_ordered is \p
1612 : * true (default), then \p Hex27 is built. Otherwise, \p Hex20 is
1613 : * built. The same holds obviously for \p Quad4, \p Prism6, etc.
1614 : */
1615 : virtual void all_second_order_range(const SimpleRange<element_iterator> & range,
1616 : const bool full_ordered = true) = 0;
1617 :
1618 : /**
1619 : * Calls the range-based version of this function with a range
1620 : * consisting of all elements in the mesh.
1621 : */
1622 : void all_second_order (const bool full_ordered = true);
1623 :
1624 : /**
1625 : * Converts a set of elements in this (conforming, non-refined) mesh
1626 : * into "complete" order elements, i.e. elements which
1627 : * can store degrees of freedom on any vertex, edge, or face. For
1628 : * example, a mesh consisting of \p Tet4 or \p Tet10 will be
1629 : * converted to a mesh with \p Tet14 etc.
1630 : */
1631 : virtual void all_complete_order_range(const SimpleRange<element_iterator> & range) = 0;
1632 :
1633 : /**
1634 : * Calls the range-based version of this function with a range
1635 : * consisting of all elements in the mesh.
1636 : */
1637 : virtual void all_complete_order ();
1638 :
1639 : /**
1640 : * In a few (very rare) cases, the user may have manually tagged the
1641 : * elements with specific processor IDs by hand, without using a
1642 : * partitioner. In this case, the Mesh will not know that the total
1643 : * number of partitions, _n_parts, has changed, unless you call this
1644 : * function. This is an O(N active elements) calculation. The return
1645 : * value is the number of partitions, and _n_parts is also set by
1646 : * this function.
1647 : */
1648 : unsigned int recalculate_n_partitions();
1649 :
1650 : /**
1651 : * \returns A pointer to a subordinate \p PointLocatorBase object
1652 : * for this mesh, constructing a master PointLocator first if
1653 : * necessary. This should not be used in threaded or
1654 : * non-parallel_only code unless the master has already been
1655 : * constructed.
1656 : */
1657 : std::unique_ptr<PointLocatorBase> sub_point_locator () const;
1658 :
1659 : /**
1660 : * Set value used by PointLocatorBase::close_to_point_tol().
1661 : *
1662 : * Defaults to 0.0. If nonzero, calls close_to_point_tol() whenever
1663 : * a new PointLocator is built for use by this Mesh. Since the Mesh
1664 : * controls the creation and destruction of the PointLocator, if
1665 : * there are any parameters we need to customize on it, the Mesh
1666 : * will need to know about them.
1667 : */
1668 : void set_point_locator_close_to_point_tol(Real val);
1669 : Real get_point_locator_close_to_point_tol() const;
1670 :
1671 : /**
1672 : * Releases the current \p PointLocator object.
1673 : */
1674 : void clear_point_locator ();
1675 :
1676 : /**
1677 : * In the point locator, do we count lower dimensional elements
1678 : * when we refine point locator regions? This is relevant in
1679 : * tree-based point locators, for example.
1680 : */
1681 : void set_count_lower_dim_elems_in_point_locator(bool count_lower_dim_elems);
1682 :
1683 : /**
1684 : * Get the current value of _count_lower_dim_elems_in_point_locator.
1685 : */
1686 : bool get_count_lower_dim_elems_in_point_locator() const;
1687 :
1688 : /**
1689 : * Verify id and processor_id consistency of our elements and
1690 : * nodes containers.
1691 : * Calls libmesh_assert() on each possible failure.
1692 : * Currently only implemented on DistributedMesh; a serial data
1693 : * structure is much harder to get out of sync.
1694 : */
1695 292 : virtual void libmesh_assert_valid_parallel_ids() const {}
1696 :
1697 : #ifdef LIBMESH_ENABLE_DEPRECATED
1698 : /**
1699 : * \deprecated
1700 : * \returns A writable reference for setting an optional name for a
1701 : * subdomain. This method is deprecated; use set_subdomain_name()
1702 : * instead.
1703 : */
1704 : std::string & subdomain_name(subdomain_id_type id);
1705 : #endif // LIBMESH_ENABLE_DEPRECATED
1706 :
1707 : /**
1708 : * \returns A reference for getting an optional name for a
1709 : * subdomain.
1710 : */
1711 : const std::string & subdomain_name(subdomain_id_type id) const;
1712 :
1713 : /**
1714 : * Sets the \p name for the provided \p id
1715 : * @param id The subdomain id to set the name for
1716 : * @param name The subdomain name
1717 : * @param synchronous Whether this method is being called across all mesh ranks. If this is true,
1718 : * then we don't have to register this collective container as being out of sync
1719 : */
1720 : void set_subdomain_name(subdomain_id_type id,
1721 : const std::string & name,
1722 : bool synchronous = false);
1723 :
1724 : /**
1725 : * \returns The id of the named subdomain if it exists,
1726 : * \p Elem::invalid_subdomain_id otherwise.
1727 : */
1728 : subdomain_id_type get_id_by_name(std::string_view name) const;
1729 :
1730 : /*
1731 : * We have many combinations of iterators that filter on various
1732 : * characteristics; we use macros to make their abstract base class
1733 : * and their subclass declarations more terse.
1734 : */
1735 : #define ABSTRACT_ELEM_ITERATORS(TYPE, ARGDECL) \
1736 : virtual element_iterator TYPE##elements_begin(ARGDECL) = 0; \
1737 : virtual element_iterator TYPE##elements_end(ARGDECL) = 0; \
1738 : virtual const_element_iterator TYPE##elements_begin(ARGDECL) const = 0; \
1739 : virtual const_element_iterator TYPE##elements_end(ARGDECL) const = 0; \
1740 : virtual SimpleRange<element_iterator> TYPE##element_ptr_range(ARGDECL) = 0; \
1741 : virtual SimpleRange<const_element_iterator> TYPE##element_ptr_range(ARGDECL) const = 0;
1742 :
1743 : #define DECLARE_ELEM_ITERATORS(TYPE, ARGDECL, ARGS) \
1744 : virtual element_iterator TYPE##elements_begin(ARGDECL) override final; \
1745 : virtual element_iterator TYPE##elements_end(ARGDECL) override final; \
1746 : virtual const_element_iterator TYPE##elements_begin(ARGDECL) const override final; \
1747 : virtual const_element_iterator TYPE##elements_end(ARGDECL) const override final; \
1748 : virtual SimpleRange<element_iterator> TYPE##element_ptr_range(ARGDECL) override final { return {TYPE##elements_begin(ARGS), TYPE##elements_end(ARGS)}; } \
1749 : virtual SimpleRange<const_element_iterator> TYPE##element_ptr_range(ARGDECL) const override final { return {TYPE##elements_begin(ARGS), TYPE##elements_end(ARGS)}; }
1750 :
1751 : #define ABSTRACT_NODE_ITERATORS(TYPE, ARGDECL) \
1752 : virtual node_iterator TYPE##nodes_begin(ARGDECL) = 0; \
1753 : virtual node_iterator TYPE##nodes_end(ARGDECL) = 0; \
1754 : virtual const_node_iterator TYPE##nodes_begin(ARGDECL) const = 0; \
1755 : virtual const_node_iterator TYPE##nodes_end(ARGDECL) const = 0; \
1756 : virtual SimpleRange<node_iterator> TYPE##node_ptr_range(ARGDECL) = 0; \
1757 : virtual SimpleRange<const_node_iterator> TYPE##node_ptr_range(ARGDECL) const = 0;
1758 :
1759 : #define DECLARE_NODE_ITERATORS(TYPE, ARGDECL, ARGS) \
1760 : virtual node_iterator TYPE##nodes_begin(ARGDECL) override final; \
1761 : virtual node_iterator TYPE##nodes_end(ARGDECL) override final; \
1762 : virtual const_node_iterator TYPE##nodes_begin(ARGDECL) const override final; \
1763 : virtual const_node_iterator TYPE##nodes_end(ARGDECL) const override final; \
1764 : virtual SimpleRange<node_iterator> TYPE##node_ptr_range(ARGDECL) override final { return {TYPE##nodes_begin(ARGS), TYPE##nodes_end(ARGS)}; } \
1765 : virtual SimpleRange<const_node_iterator> TYPE##node_ptr_range(ARGDECL) const override final { return {TYPE##nodes_begin(ARGS), TYPE##nodes_end(ARGS)}; }
1766 :
1767 : #define LIBMESH_COMMA ,
1768 :
1769 : /*
1770 : * element_iterator accessors
1771 : *
1772 : * The basic elements_begin() and elements_end() iterators iterate
1773 : * over all elements in a mesh, returning element pointers or const
1774 : * element pointers when dereferenced (depending on whether the mesh
1775 : * reference was const). range-for loops can be written using
1776 : * element_ptr_range()
1777 : *
1778 : * Filtered versions of these iterators, which skip over all
1779 : * elements not matching some predicate, are also available, by
1780 : * adding a prefix to the methods above. E.g. local_ (in a form
1781 : * like local_elements_begin() or local_element_ptr_range()) will
1782 : * iterate only over elements whose processor_id() is the current
1783 : * processor, or active_ will iterate only over active elements even
1784 : * if the mesh is refined, or active_local_ will iterate over
1785 : * elements that are both active and local. Negation forms such as
1786 : * not_local_ also exist.
1787 : *
1788 : * For some iterator prefixes, such as type_, an argument is needed
1789 : * for the filter; e.g. the ElemType to select for in that case.
1790 : *
1791 : * All valid prefixes and their corresponding arguments can be found
1792 : * in the macro invocations below.
1793 : */
1794 : ABSTRACT_ELEM_ITERATORS(,) // elements_begin(), element_ptr_range(): all elements
1795 : ABSTRACT_ELEM_ITERATORS(active_,) // Elem::active() == true
1796 : ABSTRACT_ELEM_ITERATORS(ancestor_,) // Elem::ancestor() == true
1797 : ABSTRACT_ELEM_ITERATORS(subactive_,) // Elem::subactive() == true
1798 : ABSTRACT_ELEM_ITERATORS(local_,) // Elem::processor_id() == this processor
1799 : ABSTRACT_ELEM_ITERATORS(unpartitioned_,) // Elem::processor_id() == invalid_processor_id
1800 : ABSTRACT_ELEM_ITERATORS(facelocal_,) // is on or has a neighbor on this processor
1801 : ABSTRACT_ELEM_ITERATORS(level_,unsigned int level) // Elem::level() == level
1802 : ABSTRACT_ELEM_ITERATORS(pid_,processor_id_type pid) // Elem::processor_id() == pid
1803 : ABSTRACT_ELEM_ITERATORS(type_,ElemType type) // Elem::type() == type
1804 :
1805 : ABSTRACT_ELEM_ITERATORS(active_subdomain_,subdomain_id_type sid) // active && Elem::subdomain_id() == sid
1806 : ABSTRACT_ELEM_ITERATORS(active_subdomain_set_,std::set<subdomain_id_type> ss) // active && ss.contains(Elem::subdomain_id())
1807 :
1808 : // Iterators which use negations of filters described above
1809 : ABSTRACT_ELEM_ITERATORS(not_active_,)
1810 : ABSTRACT_ELEM_ITERATORS(not_ancestor_,)
1811 : ABSTRACT_ELEM_ITERATORS(not_subactive_,)
1812 : ABSTRACT_ELEM_ITERATORS(not_local_,)
1813 : ABSTRACT_ELEM_ITERATORS(not_level_,unsigned int level)
1814 :
1815 : // Iterators which combine multiple of the filters described above
1816 : ABSTRACT_ELEM_ITERATORS(active_local_,)
1817 : ABSTRACT_ELEM_ITERATORS(active_not_local_,)
1818 : ABSTRACT_ELEM_ITERATORS(active_unpartitioned_,)
1819 : ABSTRACT_ELEM_ITERATORS(active_type_,ElemType type)
1820 : ABSTRACT_ELEM_ITERATORS(active_pid_,processor_id_type pid)
1821 : ABSTRACT_ELEM_ITERATORS(local_level_,unsigned int level)
1822 : ABSTRACT_ELEM_ITERATORS(local_not_level_,unsigned int level)
1823 : ABSTRACT_ELEM_ITERATORS(active_local_subdomain_,subdomain_id_type sid)
1824 : ABSTRACT_ELEM_ITERATORS(active_local_subdomain_set_,std::set<subdomain_id_type> ss)
1825 :
1826 : // Backwards compatibility
1827 : virtual SimpleRange<element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) = 0;
1828 : virtual SimpleRange<const_element_iterator> active_subdomain_elements_ptr_range(subdomain_id_type sid) const = 0;
1829 : virtual SimpleRange<element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) = 0;
1830 : virtual SimpleRange<const_element_iterator> active_local_subdomain_elements_ptr_range(subdomain_id_type sid) const = 0;
1831 : virtual SimpleRange<element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) = 0;
1832 : virtual SimpleRange<const_element_iterator> active_subdomain_set_elements_ptr_range(std::set<subdomain_id_type> ss) const = 0;
1833 :
1834 : // Discouraged from use - these iterators use outdated
1835 : // pre-GhostingFunctor definitions and should be renamed if not
1836 : // deprecated
1837 : ABSTRACT_ELEM_ITERATORS(semilocal_,) // active && Elem::is_semilocal()
1838 : ABSTRACT_ELEM_ITERATORS(ghost_,) // active && Elem::is_semilocal() && not local discouraged
1839 : ABSTRACT_ELEM_ITERATORS(active_semilocal_,)
1840 :
1841 : // solution can be evaluated, with the given DoF map, for the given
1842 : // variable number, or for all variables by default
1843 : ABSTRACT_ELEM_ITERATORS(evaluable_,const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint)
1844 :
1845 : // solution can be evaluated for all variables of all given DoF maps
1846 : ABSTRACT_ELEM_ITERATORS(multi_evaluable_,std::vector<const DofMap *> dof_maps)
1847 :
1848 : #ifdef LIBMESH_ENABLE_AMR
1849 : ABSTRACT_ELEM_ITERATORS(flagged_,unsigned char rflag) // Elem::refinement_flag() == rflag
1850 :
1851 : // Elem::refinement_flag() == rflag && Elem::processor_id() == pid
1852 : ABSTRACT_ELEM_ITERATORS(flagged_pid_,unsigned char rflag LIBMESH_COMMA processor_id_type pid)
1853 : #endif
1854 :
1855 : /*
1856 : * node_iterator accessors
1857 : *
1858 : * The basic nodes_begin() and nodes_end() iterators iterate
1859 : * over all nodes in a mesh, returning node pointers or const
1860 : * node pointers when dereferenced (depending on whether the mesh
1861 : * reference was const). range-for loops can be written using
1862 : * node_ptr_range()
1863 : *
1864 : * Filtered versions of these iterators, which skip over all
1865 : * nodes not matching some predicate, are also available, by
1866 : * adding a prefix to the methods above. E.g. local_ (in a form
1867 : * like local_nodes_begin() or local_node_ptr_range()) will
1868 : * iterate only over nodes whose processor_id() is the current
1869 : * processor.
1870 : *
1871 : * All valid prefixes and their corresponding arguments can be found
1872 : * in the macro invocations below.
1873 : */
1874 : ABSTRACT_NODE_ITERATORS(,) // nodes_begin(), node_ptr_range(): all nodes
1875 : ABSTRACT_NODE_ITERATORS(active_,) // Node::active() == true; i.e. Node::id() != invalid_id
1876 : ABSTRACT_NODE_ITERATORS(local_,) // Node::processor_id() == this processor
1877 : ABSTRACT_NODE_ITERATORS(bnd_,) // BoundaryInfo::n_boundary_ids(node) > 0
1878 : ABSTRACT_NODE_ITERATORS(pid_,processor_id_type pid) // Node::processor_id() == pid
1879 : ABSTRACT_NODE_ITERATORS(bid_,boundary_id_type bid) // BoundaryInfo::has_boundary_id(node, bid)
1880 :
1881 : // solution can be evaluated, with the given DoF map, for the given
1882 : // variable number, or for all variables by default
1883 : ABSTRACT_NODE_ITERATORS(evaluable_,const DofMap & dof_map LIBMESH_COMMA unsigned int var_num = libMesh::invalid_uint)
1884 :
1885 : // solution can be evaluated for all variables of all given DoF maps
1886 : ABSTRACT_NODE_ITERATORS(multi_evaluable_,std::vector<const DofMap *> dof_maps)
1887 :
1888 : // Technically these define libMesh::MeshBase::*ElemRange, but since
1889 : // those don't conflict with libMesh::*ElemRange they're as good as
1890 : // a real forward declaration, which we can't do here.
1891 : typedef StoredRange<MeshBase::element_iterator, Elem *> ElemRange;
1892 : typedef StoredRange<MeshBase::const_element_iterator, const Elem *> ConstElemRange;
1893 :
1894 : /**
1895 : * \returns A reference to a cached vector copy of a range of
1896 : * pointers to all semilocal elements, suitable for threading.
1897 : *
1898 : * Iterating over all semilocal elements is most useful for
1899 : * modifying the mesh, so we only have a non-const version for now.
1900 : */
1901 : const ElemRange & element_stored_range();
1902 :
1903 : /**
1904 : * \returns A reference to a cached vector copy of a range of
1905 : * pointers to all active local elements, suitable for threading.
1906 : *
1907 : * Iterating over only local elements is most useful for computing
1908 : * on the mesh, so we only have a non-const version for now.
1909 : */
1910 : const ConstElemRange & active_local_element_stored_range() const;
1911 :
1912 : /**
1913 : * Clears stored ranges, to indicate that the mesh has changed and
1914 : * they should be regenerated when next needed.
1915 : */
1916 : void clear_stored_ranges();
1917 :
1918 : /**
1919 : * \returns A writable reference to the whole subdomain name map
1920 : */
1921 1508 : std::map<subdomain_id_type, std::string> & set_subdomain_name_map ()
1922 24199 : { this->unset_has_synched_subdomain_name_map(); return _block_id_to_name; }
1923 445 : const std::map<subdomain_id_type, std::string> & get_subdomain_name_map () const
1924 721 : { return _block_id_to_name; }
1925 :
1926 : typedef std::vector<std::pair<std::pair<const Elem *, unsigned int>, Real>> constraint_rows_mapped_type;
1927 : typedef std::map<const Node *, constraint_rows_mapped_type> constraint_rows_type;
1928 :
1929 : /**
1930 : * Constraint rows accessors
1931 : */
1932 9104 : constraint_rows_type & get_constraint_rows()
1933 205341 : { return _constraint_rows; }
1934 :
1935 32449 : const constraint_rows_type & get_constraint_rows() const
1936 32449 : { return _constraint_rows; }
1937 :
1938 : dof_id_type n_constraint_rows() const;
1939 :
1940 : /**
1941 : * Copy the constraints from the other mesh to this mesh
1942 : */
1943 : void copy_constraint_rows(const MeshBase & other_mesh);
1944 :
1945 : /**
1946 : * Copy the constraints from the given matrix to this mesh. The
1947 : * \p constraint_operator should be an mxn matrix, where
1948 : * m == this->n_nodes() and the operator indexing matches the
1949 : * current node indexing. This may require users to disable mesh
1950 : * renumbering in between loading a mesh file and loading a
1951 : * constraint matrix which matches it.
1952 : *
1953 : * If any "constraint" rows in the matrix are unit vectors, the node
1954 : * corresponding to that row index will be left unconstrained, and
1955 : * will be used to constrain any other nodes which have a non-zero
1956 : * in the column index of that unit vector.
1957 : *
1958 : * For each matrix column index which does not correspond to an
1959 : * existing node, a new NodeElem will be added to the mesh on which
1960 : * to store the new unconstrained degree(s) of freedom.
1961 : *
1962 : * If \p precondition_constraint_operator is true, then the values
1963 : * of those new unconstrained degrees of freedom may be scaled to
1964 : * improve the conditioning of typical PDE matrices integrated on
1965 : * constrained mesh elements.
1966 : *
1967 : * \p T for the constraint_operator in this function should be \p
1968 : * Real or \p Number ... and the data should be \p Real - we just
1969 : * allow complex \p T for the sake of subclasses which have to be
1970 : * configured and compiled with only one runtime option.
1971 : */
1972 : template <typename T>
1973 : void copy_constraint_rows(const SparseMatrix<T> & constraint_operator,
1974 : bool precondition_constraint_operator = false);
1975 :
1976 : /**
1977 : * Prints (from processor 0) all mesh constraint rows. If \p
1978 : * print_nonlocal is true, then each constraint is printed once for
1979 : * each processor that knows about it, which may be useful for \p
1980 : * DistributedMesh debugging.
1981 : */
1982 : void print_constraint_rows(std::ostream & os=libMesh::out,
1983 : bool print_nonlocal=false) const;
1984 :
1985 : /**
1986 : * Gets a string reporting all mesh constraint rows local to
1987 : * this processor. If \p print_nonlocal is true, then nonlocal
1988 : * constraints which are locally known are included.
1989 : */
1990 : std::string get_local_constraints(bool print_nonlocal=false) const;
1991 :
1992 : #ifdef LIBMESH_ENABLE_DEPRECATED
1993 : /**
1994 : * \deprecated This method has ben replaced by \p cache_elem_data which
1995 : * caches data in addition to elem dimensions (e.g. elem subdomain ids)
1996 : * Search the mesh and cache the different dimensions of the elements
1997 : * present in the mesh. This is done in prepare_for_use(), but can
1998 : * be done manually by other classes after major mesh modifications.
1999 : */
2000 : void cache_elem_dims();
2001 : #endif // LIBMESH_ENABLE_DEPRECATED
2002 :
2003 : /*
2004 : * Search the mesh and cache data for the elements
2005 : * present in the mesh. This is done in prepare_for_use(), but can
2006 : * be done manually by other classes after major mesh modifications.
2007 : * Data cached includes:
2008 : * - elem dimensions
2009 : * - elem subdomains
2010 : */
2011 : void cache_elem_data();
2012 :
2013 : /**
2014 : * libMesh often expects all processors to know about names of all
2015 : * subdomain ids, but distributed mesh generators may only know
2016 : * about part of a mesh when creating names. This method can
2017 : * synchronize the subdomain id to name map across processors,
2018 : * assuming no conflicts exist. It is called automatically during
2019 : * complete_preparation() unless the map is already known to be
2020 : * synchronized.
2021 : */
2022 : void sync_subdomain_name_map();
2023 :
2024 : /**
2025 : * Search the mesh for elements that have a neighboring element
2026 : * of dim+1 and set that element as the interior parent
2027 : */
2028 : void detect_interior_parents();
2029 :
2030 : /**
2031 : * \return A mesh that may own interior parents of elements in this
2032 : * mesh. In most cases this mesh includes its own interior parents,
2033 : * but in cases where a separate "interior" mesh was used to create
2034 : * this mesh as a distinct lower-dimensional boundary (or boundary
2035 : * subset) mesh, the original mesh will be returned here.
2036 : */
2037 156 : const MeshBase & interior_mesh() const { return *_interior_mesh; }
2038 :
2039 : /**
2040 : * \return A writeable reference to the interior mesh.
2041 : */
2042 34188 : MeshBase & interior_mesh() { return *_interior_mesh; }
2043 :
2044 : /**
2045 : * Sets the interior mesh. For advanced use only.
2046 : */
2047 3493 : void set_interior_mesh(MeshBase & int_mesh) { _interior_mesh = &int_mesh; }
2048 :
2049 : /**
2050 : * \return The cached mesh subdomains. As long as the mesh is prepared, this
2051 : * should contain all the subdomain ids across processors. Relies on the mesh
2052 : * being prepared
2053 : */
2054 : const std::set<subdomain_id_type> & get_mesh_subdomains() const;
2055 :
2056 : #ifdef LIBMESH_ENABLE_PERIODIC
2057 : /**
2058 : * Register a pair of boundaries as disjoint neighbor boundary pairs.
2059 : */
2060 : void add_disjoint_neighbor_boundary_pairs(const boundary_id_type b1,
2061 : const boundary_id_type b2,
2062 : const RealVectorValue & translation);
2063 :
2064 : PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs();
2065 :
2066 : const PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs() const;
2067 :
2068 : void remove_disjoint_boundary_pair(const boundary_id_type b1,
2069 : const boundary_id_type b2);
2070 : #endif
2071 :
2072 : /**
2073 : * Flags indicating in what ways a mesh has been prepared for use.
2074 : */
2075 : struct Preparation
2076 : {
2077 : /**
2078 : * Constructor. Initializes all flags to false.
2079 : */
2080 : Preparation();
2081 :
2082 : /**
2083 : * Returns true iff all the flags are true.
2084 : */
2085 : explicit operator bool() const;
2086 :
2087 : /**
2088 : * Set all flags to the "set_all" value.
2089 : */
2090 : Preparation & operator= (bool set_all);
2091 :
2092 : /**
2093 : * Two Preparation objects are equivalent iff all the flags match,
2094 : * regardless of the true/false status of any given flag.
2095 : */
2096 : bool operator== (const Preparation & other) const;
2097 : bool operator!= (const Preparation & other) const;
2098 :
2099 : bool is_partitioned;
2100 : bool has_synched_id_counts;
2101 : bool has_neighbor_ptrs;
2102 : bool has_cached_elem_data;
2103 : bool has_interior_parent_ptrs;
2104 : bool has_removed_remote_elements;
2105 : bool has_removed_orphaned_nodes;
2106 : bool has_boundary_id_sets;
2107 : bool has_reinit_ghosting_functors;
2108 : bool has_synched_subdomain_name_map;
2109 : };
2110 :
2111 : protected:
2112 :
2113 : #ifdef LIBMESH_ENABLE_PERIODIC
2114 : /// @brief The disjoint neighbor boundary id pairs.
2115 : std::unique_ptr<PeriodicBoundaries> _disjoint_neighbor_boundary_pairs;
2116 : #endif
2117 :
2118 : /**
2119 : * This class holds the boundary information. It can store nodes, edges,
2120 : * and faces with a corresponding id that facilitates setting boundary
2121 : * conditions.
2122 : *
2123 : * Direct access to this class is now officially deprecated and will
2124 : * be removed in future libMesh versions. Use the \p get_boundary_info()
2125 : * accessor instead.
2126 : */
2127 : std::unique_ptr<BoundaryInfo> boundary_info;
2128 :
2129 : /**
2130 : * Moves any superclass data (e.g. GhostingFunctors that might rely
2131 : * on element and nodal data (which is managed by subclasses!)
2132 : * being already moved first.
2133 : *
2134 : * Must be manually called in dofobject-managing subclass move
2135 : * operators.
2136 : */
2137 : void post_dofobject_moves(MeshBase && other_mesh);
2138 :
2139 : /**
2140 : * Helper class to copy cached data, to synchronize with a possibly
2141 : * unprepared \p other_mesh
2142 : */
2143 : void copy_cached_data (const MeshBase & other_mesh);
2144 :
2145 : /**
2146 : * Shim to allow operator == (&) to behave like a virtual function
2147 : * without having to be one.
2148 : */
2149 : virtual bool subclass_locally_equals (const MeshBase & other_mesh) const = 0;
2150 :
2151 : /**
2152 : * Tests for equality of all elements and nodes in the mesh. Helper
2153 : * function for subclass_equals() in unstructured mesh subclasses.
2154 : */
2155 : bool nodes_and_elements_equal(const MeshBase & other_mesh) const;
2156 :
2157 : /**
2158 : * \returns A writable reference to the number of partitions.
2159 : */
2160 14358 : unsigned int & set_n_partitions ()
2161 14358 : { return _n_parts; }
2162 :
2163 : /**
2164 : * The number of partitions the mesh has. This is set by
2165 : * the partitioners, and may not be changed directly by
2166 : * the user.
2167 : *
2168 : * \note The number of partitions \e need \e not equal
2169 : * this->n_processors(), consider for example the case where you
2170 : * simply want to partition a mesh on one processor and view the
2171 : * result in GMV.
2172 : */
2173 : unsigned int _n_parts;
2174 :
2175 : /**
2176 : * The default mapping type (typically Lagrange) between master and
2177 : * physical space to assign to newly added elements.
2178 : */
2179 : ElemMappingType _default_mapping_type;
2180 :
2181 : /**
2182 : * The default mapping data (unused with Lagrange, used for nodal
2183 : * weight lookup index with rational bases) to assign to newly added
2184 : * elements.
2185 : */
2186 : unsigned char _default_mapping_data;
2187 :
2188 : /**
2189 : * Flags indicating in what ways \p this mesh has been prepared.
2190 : */
2191 : Preparation _preparation;
2192 :
2193 : /**
2194 : * A cached \p ElemRange for threaded mutation of all semilocal
2195 : * elements of this mesh.
2196 : *
2197 : * This will not actually be built unless needed. Further, since we
2198 : * want our \p elem_stored_range() method to be \p const (yet do the
2199 : * dynamic allocating) this needs to be mutable.
2200 : */
2201 : mutable std::unique_ptr<ElemRange> _element_stored_range;
2202 :
2203 : /**
2204 : * A cached \p ConstElemRange for threaded calculation on all
2205 : * local elements of this mesh.
2206 : *
2207 : * This will not actually be built unless needed. Further, since we
2208 : * want our \p elem_stored_range() method to be \p const (yet do the
2209 : * dynamic allocating) this needs to be mutable.
2210 : */
2211 : mutable std::unique_ptr<ConstElemRange>
2212 : _const_active_local_element_stored_range;
2213 :
2214 : /**
2215 : * A \p PointLocator class for this mesh.
2216 : * This will not actually be built unless needed. Further, since we want
2217 : * our \p point_locator() method to be \p const (yet do the dynamic allocating)
2218 : * this needs to be mutable. Since the PointLocatorBase::build() member is used,
2219 : * and it operates on a constant reference to the mesh, this is OK.
2220 : */
2221 : mutable std::unique_ptr<PointLocatorBase> _point_locator;
2222 :
2223 : /**
2224 : * Do we count lower dimensional elements in point locator refinement?
2225 : * This is relevant in tree-based point locators, for example.
2226 : */
2227 : bool _count_lower_dim_elems_in_point_locator;
2228 :
2229 : /**
2230 : * A partitioner to use at each prepare_for_use().
2231 : *
2232 : * This will be built in the constructor of each derived class, but
2233 : * can be replaced by the user through the partitioner() accessor.
2234 : */
2235 : std::unique_ptr<Partitioner> _partitioner;
2236 :
2237 : #ifdef LIBMESH_ENABLE_UNIQUE_ID
2238 : /**
2239 : * The next available unique id for assigning ids to DOF objects
2240 : */
2241 : unique_id_type _next_unique_id;
2242 : #endif
2243 :
2244 : /**
2245 : * Defaulting to \p this, a pointer to the mesh used to generate
2246 : * boundary elements on \p this.
2247 : */
2248 : MeshBase *_interior_mesh;
2249 :
2250 : /**
2251 : * If this is true then no partitioning should be done with the
2252 : * possible exception of orphaned nodes.
2253 : */
2254 : bool _skip_noncritical_partitioning;
2255 :
2256 : /**
2257 : * If this is true then no partitioning should be done.
2258 : */
2259 : bool _skip_all_partitioning;
2260 :
2261 : /**
2262 : * If this is true then renumbering will be kept to a minimum.
2263 : *
2264 : * This is set when prepare_for_use() is called.
2265 : */
2266 : bool _skip_renumber_nodes_and_elements;
2267 :
2268 : /**
2269 : * If this is \p true then we will skip \p find_neighbors in \p prepare_for_use
2270 : */
2271 : bool _skip_find_neighbors;
2272 :
2273 : /**
2274 : * If this is \p true then we will skip \p detect_interior_parents in \p prepare_for_use
2275 : */
2276 : bool _skip_detect_interior_parents;
2277 :
2278 : /**
2279 : * If this is false then even on DistributedMesh remote elements
2280 : * will not be deleted during mesh preparation.
2281 : *
2282 : * This is true by default.
2283 : */
2284 : bool _allow_remote_element_removal;
2285 :
2286 : /**
2287 : * The Exodus reader (and potentially other readers in the future?)
2288 : * now supports setting Node and Elem unique_ids based on values
2289 : * from within the Exodus file itself, rather than generating them
2290 : * automatically in LibMesh. In this case, the unique_ids will not
2291 : * necessarily be unique across the set of all _DofObjects_,
2292 : * although they should still be unique within the individual sets
2293 : * of Elems and Nodes. The reader can therefore set this Mesh flag
2294 : * (which defaults to false) to indicate we should be less strict
2295 : * when checking the "uniqueness" of unique_ids.
2296 : */
2297 : bool _allow_node_and_elem_unique_id_overlap;
2298 :
2299 : /**
2300 : * This structure maintains the mapping of named blocks
2301 : * for file formats that support named blocks. Currently
2302 : * this is only implemented for ExodusII
2303 : */
2304 : std::map<subdomain_id_type, std::string> _block_id_to_name;
2305 :
2306 : /**
2307 : * We cache the dimension of the elements present in the mesh.
2308 : * So, if we have a mesh with 1D and 2D elements, this structure
2309 : * will contain 1 and 2.
2310 : */
2311 : std::set<unsigned char> _elem_dims;
2312 :
2313 : /**
2314 : * We cache the (default) order of the geometric elements present in
2315 : * the mesh. E.g. if we have a mesh with TRI3 and TRI6 elements,
2316 : * this structure will contain FIRST and SECOND.
2317 : */
2318 : std::set<Order> _elem_default_orders;
2319 :
2320 : /**
2321 : * We cache the maximum nodal order supported by all the mesh's
2322 : * elements (the minimum supported_nodal_order() of any element)
2323 : */
2324 : Order _supported_nodal_order;
2325 :
2326 : /**
2327 : * We cache the subdomain ids of the elements present in the mesh.
2328 : */
2329 : std::set<subdomain_id_type> _mesh_subdomains;
2330 :
2331 : /**
2332 : * Map from "element set code" to list of set ids to which that element
2333 : * belongs (and vice-versa). Remarks:
2334 : * 1.) The elemset code is a dof_id_type because (if used) it is
2335 : * stored as an extra_integer (named "elemset_code") on all elements,
2336 : * and extra_integers are of type dof_id_type. Elements which do not
2337 : * belong to any set should be assigned an elemset code of DofObject::invalid_id.
2338 : * 2.) Element sets can be thought of as a generalization of the concept
2339 : * of a subdomain. Subdomains have the following restrictions:
2340 : * a.) A given element can only belong to a single subdomain
2341 : * b.) When using Exodus file input/output, subdomains are (unfortunately)
2342 : * tied to the concept of exodus element blocks, which consist of a single
2343 : * geometric element type, somewhat limiting their generality.
2344 : * 3.) The user is responsible for filling in the values of this map
2345 : * in a consistent manner, unless the elemsets are read in from an
2346 : * Exodus file, in which case the elemset codes will be set up
2347 : * automatically. The codes can basically be chosen arbitrarily,
2348 : * with the one requirement that elements which belong to no sets
2349 : * should have a set code of DofObject::invalid_id.
2350 : * 4.) We also keep a list of all the elemset ids which have been added in
2351 : * order to support O(1) performance behavior in n_elemsets() calls.
2352 : */
2353 : std::map<dof_id_type, const MeshBase::elemset_type *> _elemset_codes;
2354 : std::map<MeshBase::elemset_type, dof_id_type> _elemset_codes_inverse_map;
2355 : MeshBase::elemset_type _all_elemset_ids;
2356 :
2357 : /**
2358 : * The "spatial dimension" of the Mesh. See the documentation for
2359 : * Mesh::spatial_dimension() for more information.
2360 : */
2361 : unsigned char _spatial_dimension;
2362 :
2363 : /**
2364 : * The array of names for integer data associated with each element
2365 : * in the mesh
2366 : */
2367 : std::vector<std::string> _elem_integer_names;
2368 :
2369 : /**
2370 : * The array of default initialization values for integer data
2371 : * associated with each element in the mesh
2372 : */
2373 : std::vector<dof_id_type> _elem_integer_default_values;
2374 :
2375 : /**
2376 : * The array of names for integer data associated with each node
2377 : * in the mesh
2378 : */
2379 : std::vector<std::string> _node_integer_names;
2380 :
2381 : /**
2382 : * The array of default initialization values for integer data
2383 : * associated with each node in the mesh
2384 : */
2385 : std::vector<dof_id_type> _node_integer_default_values;
2386 :
2387 : /**
2388 : * Size extra-integer arrays of all elements in the mesh
2389 : */
2390 : void size_elem_extra_integers();
2391 :
2392 : /**
2393 : * Size extra-integer arrays of all nodes in the mesh
2394 : */
2395 : void size_node_extra_integers();
2396 :
2397 : /**
2398 : * Merge extra-integer arrays from an \p other mesh. Returns two
2399 : * mappings from index values in \p other to (possibly newly created)
2400 : * index values with the same string name in \p this mesh, the first
2401 : * for element integers and the second for node integers.
2402 : */
2403 : std::pair<std::vector<unsigned int>, std::vector<unsigned int>>
2404 : merge_extra_integer_names(const MeshBase & other);
2405 :
2406 : /**
2407 : * The default geometric GhostingFunctor, used to implement standard
2408 : * libMesh element ghosting behavior. We use a base class pointer
2409 : * here to avoid dragging in more header dependencies.
2410 : */
2411 : std::unique_ptr<GhostingFunctor> _default_ghosting;
2412 :
2413 : /**
2414 : * The list of all GhostingFunctor objects to be used when
2415 : * distributing a DistributedMesh.
2416 : *
2417 : * Basically unused by ReplicatedMesh for now, but belongs to
2418 : * MeshBase because the cost is trivial.
2419 : */
2420 : std::vector<GhostingFunctor *> _ghosting_functors;
2421 :
2422 : /**
2423 : * Hang on to references to any GhostingFunctor objects we were
2424 : * passed in shared_ptr form
2425 : */
2426 : std::map<GhostingFunctor *, std::shared_ptr<GhostingFunctor> > _shared_functors;
2427 :
2428 : // Keep track of any constraint equations that are inherent to the
2429 : // mesh, such as FE nodes whose Rational Bernstein values need to be
2430 : // constrained in terms of values on spline control nodes.
2431 : //
2432 : // _constraint_rows[constrained_node][i].first.first is an
2433 : // element (e.g. a NodeElem for a spline control node),
2434 : // _constraint_rows[constrained_node][i].first.second is the
2435 : // local node id of that element which is a constraining node,
2436 : // _constraint_rows[constrained_node][i].second is that node's
2437 : // constraint coefficient.
2438 : constraint_rows_type _constraint_rows;
2439 :
2440 : /**
2441 : * If nonzero, we will call PointLocatorBase::set_close_to_point_tol()
2442 : * on any PointLocators that we create.
2443 : */
2444 : Real _point_locator_close_to_point_tol;
2445 :
2446 : /**
2447 : * The partitioner class is a friend so that it can set
2448 : * the number of partitions.
2449 : */
2450 : friend class Partitioner;
2451 :
2452 : /**
2453 : * The MeshInput classes are friends so that they can set the number
2454 : * of partitions.
2455 : */
2456 : friend class MeshInput<MeshBase>;
2457 :
2458 : /**
2459 : * Make the \p BoundaryInfo class a friend so that
2460 : * it can create and interact with \p BoundaryMesh.
2461 : */
2462 : friend class BoundaryInfo;
2463 :
2464 : /**
2465 : * Make the \p MeshCommunication class a friend so that
2466 : * it can directly broadcast *_integer_names
2467 : */
2468 : friend class MeshCommunication;
2469 :
2470 :
2471 : /**
2472 : * The original iterator classes weren't properly const-safe;
2473 : * relying on their const-incorrectness is now deprecated.
2474 : */
2475 : #ifdef LIBMESH_ENABLE_DEPRECATED
2476 : typedef variant_filter_iterator<MeshBase::Predicate, Elem *> elem_filter_iter;
2477 :
2478 : typedef variant_filter_iterator<MeshBase::Predicate,
2479 : Elem * const,
2480 : Elem * const &,
2481 : Elem * const *> const_elem_filter_iter;
2482 :
2483 : typedef variant_filter_iterator<MeshBase::Predicate, Node *> node_filter_iter;
2484 :
2485 : typedef variant_filter_iterator<MeshBase::Predicate,
2486 : Node * const,
2487 : Node * const &,
2488 : Node * const *> const_node_filter_iter;
2489 : #else
2490 : typedef variant_filter_iterator<MeshBase::Predicate,
2491 : Elem * const,
2492 : Elem * const &,
2493 : Elem * const *,
2494 : const Elem * const,
2495 : const Elem * const &,
2496 : const Elem * const *> elem_filter_iter;
2497 :
2498 : typedef variant_filter_iterator<MeshBase::Predicate,
2499 : const Elem * const,
2500 : const Elem * const &,
2501 : const Elem * const *> const_elem_filter_iter;
2502 :
2503 : typedef variant_filter_iterator<MeshBase::Predicate,
2504 : Node * const,
2505 : Node * const &,
2506 : Node * const *,
2507 : const Node * const,
2508 : const Node * const &,
2509 : const Node * const *> node_filter_iter;
2510 :
2511 : typedef variant_filter_iterator<MeshBase::Predicate,
2512 : const Node * const,
2513 : const Node * const &,
2514 : const Node * const *> const_node_filter_iter;
2515 : #endif // LIBMESH_ENABLE_DEPRECATED
2516 :
2517 : };
2518 :
2519 :
2520 :
2521 :
2522 :
2523 :
2524 :
2525 :
2526 :
2527 :
2528 :
2529 : /**
2530 : * The definition of the element_iterator struct.
2531 : */
2532 : struct
2533 39751575 : MeshBase::element_iterator : MeshBase::elem_filter_iter
2534 : {
2535 : // Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor
2536 : template <typename PredType, typename IterType>
2537 668480 : element_iterator (const IterType & d,
2538 : const IterType & e,
2539 : const PredType & p ) :
2540 30640964 : elem_filter_iter(d,e,p) {}
2541 : };
2542 :
2543 :
2544 :
2545 :
2546 : /**
2547 : * The definition of the const_element_iterator struct. It is similar to the regular
2548 : * iterator above, but also provides an additional conversion-to-const ctor.
2549 : */
2550 : struct
2551 77475248 : MeshBase::const_element_iterator : MeshBase::const_elem_filter_iter
2552 : {
2553 : /**
2554 : * Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor.
2555 : */
2556 : template <typename PredType, typename IterType>
2557 8698090 : const_element_iterator (const IterType & d,
2558 : const IterType & e,
2559 : const PredType & p ) :
2560 45740618 : const_elem_filter_iter(d,e,p) {}
2561 :
2562 : /**
2563 : * The conversion-to-const ctor. Takes a regular iterator and calls the appropriate
2564 : * variant_filter_iterator copy constructor.
2565 : *
2566 : * \note This one is \e not templated!
2567 : */
2568 6637282 : const_element_iterator (const MeshBase::element_iterator & rhs) :
2569 3687206 : const_elem_filter_iter(rhs) {}
2570 : };
2571 :
2572 :
2573 :
2574 :
2575 :
2576 :
2577 :
2578 : /**
2579 : * The definition of the node_iterator struct.
2580 : */
2581 : struct
2582 13740310 : MeshBase::node_iterator : MeshBase::node_filter_iter
2583 : {
2584 : /**
2585 : * Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor.
2586 : */
2587 : template <typename PredType, typename IterType>
2588 348558 : node_iterator (const IterType & d,
2589 : const IterType & e,
2590 : const PredType & p ) :
2591 12324972 : node_filter_iter(d,e,p) {}
2592 : };
2593 :
2594 :
2595 :
2596 :
2597 : /**
2598 : * The definition of the const_node_iterator struct. It is similar to the regular
2599 : * iterator above, but also provides an additional conversion-to-const ctor.
2600 : */
2601 : struct
2602 9300021 : MeshBase::const_node_iterator : MeshBase::const_node_filter_iter
2603 : {
2604 : /**
2605 : * Templated forwarding ctor -- forwards to appropriate variant_filter_iterator ctor.
2606 : */
2607 : template <typename PredType, typename IterType>
2608 301512 : const_node_iterator (const IterType & d,
2609 : const IterType & e,
2610 : const PredType & p ) :
2611 9344189 : const_node_filter_iter(d,e,p) {}
2612 :
2613 : /**
2614 : * The conversion-to-const ctor. Takes a regular iterator and calls the appropriate
2615 : * variant_filter_iterator copy constructor.
2616 : *
2617 : * \note This one is *not* templated!
2618 : */
2619 39260 : const_node_iterator (const MeshBase::node_iterator & rhs) :
2620 20196 : const_node_filter_iter(rhs) {}
2621 : };
2622 :
2623 :
2624 : // ------------------------------------------------------------
2625 : // Elem class member functions
2626 : inline
2627 91404 : const std::set<unsigned char> & MeshBase::elem_dimensions() const
2628 : {
2629 91404 : libmesh_assert(_preparation.has_cached_elem_data);
2630 91404 : return _elem_dims;
2631 : }
2632 :
2633 :
2634 : inline
2635 0 : const std::set<Order> & MeshBase::elem_default_orders() const
2636 : {
2637 0 : libmesh_assert(_preparation.has_cached_elem_data);
2638 0 : return _elem_default_orders;
2639 : }
2640 :
2641 :
2642 : inline
2643 12 : Order MeshBase::supported_nodal_order() const
2644 : {
2645 12 : libmesh_assert(_preparation.has_cached_elem_data);
2646 414 : return _supported_nodal_order;
2647 : }
2648 :
2649 :
2650 : inline
2651 : const std::set<subdomain_id_type> & MeshBase::get_mesh_subdomains() const
2652 : {
2653 : libmesh_assert(_preparation.has_cached_elem_data);
2654 : return _mesh_subdomains;
2655 : }
2656 :
2657 :
2658 : inline
2659 7824 : unsigned int MeshBase::spatial_dimension () const
2660 : {
2661 7824 : libmesh_assert(_preparation.has_cached_elem_data);
2662 :
2663 238931 : return cast_int<unsigned int>(_spatial_dimension);
2664 : }
2665 :
2666 : template <typename T>
2667 : inline
2668 : unsigned int MeshBase::add_elem_datum(const std::string & name,
2669 : bool allocate_data,
2670 : const T * default_value)
2671 : {
2672 : const std::size_t old_size = _elem_integer_names.size();
2673 :
2674 : unsigned int n_more_integers = (sizeof(T)-1)/sizeof(dof_id_type);
2675 : std::vector<dof_id_type> int_data(n_more_integers+1, DofObject::invalid_id);
2676 : if (default_value)
2677 : std::memcpy(int_data.data(), default_value, sizeof(T));
2678 :
2679 : unsigned int start_idx = this->add_elem_integer(name, false, int_data[0]);
2680 : for (unsigned int i=0; i != n_more_integers; ++i)
2681 : this->add_elem_integer(name+"__"+std::to_string(i), false, int_data[i+1]);
2682 :
2683 : if (allocate_data && old_size != _elem_integer_names.size())
2684 : this->size_elem_extra_integers();
2685 :
2686 : return start_idx;
2687 : }
2688 :
2689 :
2690 : template <typename T>
2691 : inline
2692 : std::vector<unsigned int> MeshBase::add_elem_data(const std::vector<std::string> & names,
2693 : bool allocate_data,
2694 : const std::vector<T> * default_values)
2695 : {
2696 : libmesh_assert(!default_values || default_values->size() == names.size());
2697 :
2698 : std::vector<unsigned int> returnval(names.size());
2699 :
2700 : const std::size_t old_size = _elem_integer_names.size();
2701 :
2702 : for (auto i : index_range(names))
2703 : returnval[i] =
2704 : this->add_elem_datum<T>(names[i], false,
2705 : default_values ?
2706 : (*default_values)[i] : nullptr);
2707 :
2708 : if (allocate_data && old_size != _elem_integer_names.size())
2709 : this->size_elem_extra_integers();
2710 :
2711 : return returnval;
2712 : }
2713 :
2714 :
2715 : template <typename T>
2716 : inline
2717 72 : unsigned int MeshBase::add_node_datum(const std::string & name,
2718 : bool allocate_data,
2719 : const T * default_value)
2720 : {
2721 12 : const std::size_t old_size = _node_integer_names.size();
2722 :
2723 6 : unsigned int n_more_integers = (sizeof(T)-1)/sizeof(dof_id_type);
2724 72 : std::vector<dof_id_type> int_data(n_more_integers+1, DofObject::invalid_id);
2725 72 : if (default_value)
2726 72 : std::memcpy(int_data.data(), default_value, sizeof(T));
2727 :
2728 78 : unsigned int start_idx = this->add_node_integer(name, false, int_data[0]);
2729 36 : for (unsigned int i=0; i != n_more_integers; ++i)
2730 36 : this->add_node_integer(name+"__"+std::to_string(i), false, int_data[i+1]);
2731 :
2732 72 : if (allocate_data && old_size != _node_integer_names.size())
2733 72 : this->size_node_extra_integers();
2734 :
2735 78 : return start_idx;
2736 : }
2737 :
2738 :
2739 : template <typename T>
2740 : inline
2741 : std::vector<unsigned int> MeshBase::add_node_data(const std::vector<std::string> & names,
2742 : bool allocate_data,
2743 : const std::vector<T> * default_values)
2744 : {
2745 : libmesh_assert(!default_values || default_values->size() == names.size());
2746 :
2747 : std::vector<unsigned int> returnval(names.size());
2748 :
2749 : const std::size_t old_size = _node_integer_names.size();
2750 :
2751 : for (auto i : index_range(names))
2752 : returnval[i] =
2753 : this->add_node_datum<T>(names[i], false,
2754 : default_values ?
2755 : (*default_values)[i] : nullptr);
2756 :
2757 : if (allocate_data && old_size != _node_integer_names.size())
2758 : this->size_node_extra_integers();
2759 :
2760 : return returnval;
2761 : }
2762 :
2763 :
2764 :
2765 : } // namespace libMesh
2766 :
2767 : #endif // LIBMESH_MESH_BASE_H
|