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