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