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