libMesh
mesh_tools.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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_TOOLS_H
21 #define LIBMESH_MESH_TOOLS_H
22 
23 // Local Includes
24 #include "libmesh/libmesh.h"
25 #include "libmesh/bounding_box.h"
26 #include "libmesh/id_types.h"
27 #include "libmesh/mesh_base.h"
28 
29 // C++ Includes
30 #include <limits>
31 #include <set>
32 #include <unordered_set>
33 #include <unordered_map>
34 #include <vector>
35 
36 namespace libMesh
37 {
38 
39 // forward declarations
40 class Sphere;
41 class Elem;
42 enum ElemType : int;
43 
53 namespace MeshTools
54 {
55 
64 dof_id_type total_weight (const MeshBase & mesh);
65 
74 dof_id_type weight (const MeshBase & mesh,
75  const processor_id_type pid);
76 
77 inline
79 { return MeshTools::weight (mesh, mesh.processor_id()); }
80 
88  std::vector<std::vector<dof_id_type>> & nodes_to_elem_map);
89 
94  std::vector<std::vector<const Elem *>> & nodes_to_elem_map);
95 
103  std::unordered_map<dof_id_type, std::vector<dof_id_type>> & nodes_to_elem_map);
104 
109  std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map);
110 
111 
112 // /**
113 // * Calling this function on a 2D mesh will convert all the elements
114 // * to triangles. \p QUAD4s will be converted to \p TRI3s, \p QUAD8s
115 // * and \p QUAD9s will be converted to \p TRI6s.
116 // */
117 // void all_tri (MeshBase & mesh);
118 
122 std::unordered_set<dof_id_type> find_boundary_nodes(const MeshBase & mesh);
123 
130 std::unordered_set<dof_id_type> find_block_boundary_nodes(const MeshBase & mesh);
131 
137 
141 Sphere
142 bounding_sphere (const MeshBase & mesh);
143 
153 
164 
171  const processor_id_type pid);
172 
176 Sphere
178  const processor_id_type pid);
179 
186  const subdomain_id_type sid);
187 
191 Sphere
193  const subdomain_id_type sid);
194 
195 
200 void elem_types (const MeshBase & mesh,
201  std::vector<ElemType> & et);
202 
209  const ElemType type);
210 
217  const ElemType type);
218 
228  const ElemType type,
229  const unsigned int level);
230 
238 unsigned int n_levels(const MeshBase & mesh);
239 
246 unsigned int n_local_levels(const MeshBase & mesh);
247 
254 unsigned int n_active_levels(const MeshBase & mesh);
255 
262 unsigned int n_active_local_levels(const MeshBase & mesh);
263 
270 unsigned int n_p_levels (const MeshBase & mesh);
271 
281 unsigned int paranoid_n_levels(const MeshBase & mesh);
282 
290  std::set<dof_id_type> & not_subactive_node_ids);
291 
298 
299 
305  const MeshBase::const_node_iterator & end);
306 
307 
311 unsigned int max_level (const MeshBase & mesh);
312 
317 void find_nodal_neighbors(const MeshBase & mesh,
318  const Node & n,
319  const std::vector<std::vector<const Elem *>> & nodes_to_elem_map,
320  std::vector<const Node *> & neighbors);
321 
326 void find_nodal_neighbors(const MeshBase & mesh,
327  const Node & n,
328  const std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map,
329  std::vector<const Node *> & neighbors);
330 
338  std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
339 
351 
362 
371 bool valid_is_prepared (const MeshBase & mesh);
372 
374 
381 #ifndef NDEBUG
382 
388 
395 
401 
407 
413 
419 
426 
433 
442  unsigned int sysnum);
443 
450 template <typename DofObjectSubclass>
452 
458 
464 
465 #endif // !NDEBUG
466 
468 
470 
477 #ifdef DEBUG
478 
484  const Elem * bad_elem);
485 
490 
496 
508 
514 
523  unsigned int sysnum = libMesh::invalid_uint);
524 
525 #ifdef LIBMESH_ENABLE_UNIQUE_ID
526 
532 #endif
533 
540 
547 
555 
561 template <typename DofObjectSubclass>
563 
568 template <typename DofObjectSubclass>
570 {
571  libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
572  libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
573 }
574 
580 
592  bool assert_valid_remote_elems=true);
593 
594 #endif // DEBUG
595 
597 
598 // There is no reason for users to call functions in the MeshTools::Private namespace.
599 namespace Private {
615 } // end namespace Private
616 
617 } // end namespace MeshTools
618 
619 } // namespace libMesh
620 
621 
622 #endif // LIBMESH_MESH_TOOLS_H
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:759
void libmesh_assert_equal_points(const MeshBase &mesh)
A function for testing that node locations match across processors.
Definition: mesh_tools.C:1474
ElemType
Defines an enum for geometric element types.
void libmesh_assert_valid_procids(const MeshBase &mesh)
A function for verifying that processor assignment is both parallel and topologically consistent...
Definition: mesh_tools.h:569
void elem_types(const MeshBase &mesh, std::vector< ElemType > &et)
Fills in a vector of all element types in the mesh.
Definition: mesh_tools.C:715
dof_id_type n_nodes(const MeshBase::const_node_iterator &begin, const MeshBase::const_node_iterator &end)
Count up the number of nodes of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:858
A Node is like a Point, but with more information.
Definition: node.h:52
void libmesh_assert_valid_amr_interior_parents(const MeshBase &mesh)
A function for verifying that any interior_parent pointers on elements are consistent with AMR (paren...
Definition: mesh_tools.C:1213
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:286
This class defines a sphere.
Definition: sphere.h:72
void libmesh_assert_valid_remote_elems(const MeshBase &mesh)
A function for verifying that active local elements&#39; neighbors are never remote elements.
Definition: mesh_tools.C:1139
void libmesh_assert_consistent_distributed_nodes(const MeshBase &mesh)
A function for verifying that distribution of nodes is parallel consistent (every processor can see e...
Definition: mesh_tools.C:1810
void correct_node_proc_ids(MeshBase &)
Changes the processor ids on each node so be the same as the id of the lowest element touching that n...
Definition: mesh_tools.C:2219
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:850
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:558
The definition of the const_element_iterator struct.
Definition: mesh_base.h:2121
bool valid_is_prepared(const MeshBase &mesh)
A function for testing whether a mesh&#39;s cached is_prepared() setting is not a false positive...
Definition: mesh_tools.C:1034
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:662
void clear_spline_nodes(MeshBase &)
Remove spline node (for IsoGeometric Analysis meshes) elements and nodes and constraints from the mes...
Definition: mesh_tools.C:999
void libmesh_assert_valid_refinement_tree(const MeshBase &mesh)
A function for verifying that elements on this processor have valid descendants and consistent active...
Definition: mesh_tools.C:1416
std::unordered_set< dof_id_type > find_block_boundary_nodes(const MeshBase &mesh)
Returns a std::set containing Node IDs for all of the block boundary nodes.
Definition: mesh_tools.C:536
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
void find_nodal_neighbors(const MeshBase &mesh, const Node &n, const std::vector< std::vector< const Elem *>> &nodes_to_elem_map, std::vector< const Node *> &neighbors)
Given a mesh and a node in the mesh, the vector will be filled with every node directly attached to t...
Definition: mesh_tools.C:888
void libmesh_assert_valid_constraint_rows(const MeshBase &mesh)
A function for verifying that all mesh constraint rows express relations between nodes and elements t...
Definition: mesh_tools.C:1249
unsigned int n_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:788
void libmesh_assert_parallel_consistent_new_node_procids(const MeshBase &mesh)
A function for verifying that processor assignment is parallel consistent (every processor agrees on ...
Definition: mesh_tools.C:1891
void build_nodes_to_elem_map(const MeshBase &mesh, std::vector< std::vector< dof_id_type >> &nodes_to_elem_map)
After calling this function the input vector nodes_to_elem_map will contain the node to element conne...
Definition: mesh_tools.C:448
The libMesh namespace provides an interface to certain functionality in the library.
unsigned int max_level(const MeshBase &mesh)
Find the maximum h-refinement level in a mesh.
dof_id_type n_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:727
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:623
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:74
void libmesh_assert_consistent_distributed(const MeshBase &mesh)
A function for verifying that distribution of dof objects is parallel consistent (every processor can...
Definition: mesh_tools.C:1780
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:825
std::unordered_set< dof_id_type > find_boundary_nodes(const MeshBase &mesh)
Calling this function on a 2D mesh will convert all the elements to triangles.
Definition: mesh_tools.C:516
void libmesh_assert_equal_n_systems(const MeshBase &mesh)
The following functions, only available in builds with NDEBUG undefined, are for asserting internal c...
Definition: mesh_tools.C:1064
void libmesh_assert_valid_dof_ids(const MeshBase &mesh, unsigned int sysnum=libMesh::invalid_uint)
A function for verifying that degree of freedom indexing matches across processors.
Definition: mesh_tools.C:1704
uint8_t processor_id_type
void libmesh_assert_valid_node_pointers(const MeshBase &mesh)
A function for walking across the mesh to try and ferret out invalidated or misassigned pointers...
Definition: mesh_tools.C:1114
void libmesh_assert_canonical_node_procids(const MeshBase &mesh)
A function for verifying that processor assignment of nodes matches the heuristic specified in Node::...
Definition: mesh_tools.C:1403
void libmesh_assert_no_links_to_elem(const MeshBase &mesh, const Elem *bad_elem)
The following functions, only available in builds with DEBUG defined, typically have surprisingly slo...
Definition: mesh_tools.C:1455
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:436
unsigned int n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:801
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
Definition: mesh_tools.C:1534
void libmesh_assert_valid_amr_elem_ids(const MeshBase &mesh)
A function for verifying that ids of elements are correctly sorted for AMR (parents have lower ids th...
Definition: mesh_tools.C:1193
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:701
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:2376
void find_hanging_nodes_and_parents(const MeshBase &mesh, std::map< dof_id_type, std::vector< dof_id_type >> &hanging_nodes)
Given a mesh hanging_nodes will be filled with an associative array keyed off the global id of all th...
Definition: mesh_tools.C:911
void libmesh_assert_topology_consistent_procids(const MeshBase &mesh)
A function for verifying that processor assignment is topologically consistent on nodes (each node pa...
dof_id_type total_weight(const MeshBase &mesh)
Definition: mesh_tools.C:413
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:677
void libmesh_assert_parallel_consistent_procids(const MeshBase &mesh)
A function for verifying that processor assignment is parallel consistent (every processor agrees on ...
Sphere bounding_sphere(const MeshBase &mesh)
Definition: mesh_tools.C:610
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
void libmesh_assert_equal_connectivity(const MeshBase &mesh)
A function for testing that element nodal connectivities match across processors. ...
Definition: mesh_tools.C:1490
void libmesh_assert_connected_nodes(const MeshBase &mesh)
A function for verifying that all nodes are connected to at least one element.
Definition: mesh_tools.C:1511
void get_not_subactive_node_ids(const MeshBase &mesh, std::set< dof_id_type > &not_subactive_node_ids)
Builds a set of node IDs for nodes which belong to non-subactive elements.
Definition: mesh_tools.C:839
The definition of the const_node_iterator struct.
Definition: mesh_base.h:2172
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:736
void libmesh_assert_valid_neighbors(const MeshBase &mesh, bool assert_valid_remote_elems=true)
A function for verifying that neighbor connectivity is correct (each element is a neighbor of or desc...
Definition: mesh_tools.C:2031
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:583
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
Definition: mesh_tools.C:1732
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:637
unsigned int n_p_levels(const MeshBase &mesh)
Definition: mesh_tools.C:866
void libmesh_assert_old_dof_objects(const MeshBase &mesh)
A function for testing that all non-recently-created DofObjects within a mesh have old_dof_object dat...
Definition: mesh_tools.C:1090
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
void libmesh_assert_contiguous_dof_ids(const MeshBase &mesh, unsigned int sysnum)
A function for verifying that degree of freedom indexes are contiguous on each processor, as is required by libMesh numeric classes.
Definition: mesh_tools.C:1266
dof_id_type n_non_subactive_elem_of_type_at_level(const MeshBase &mesh, const ElemType type, const unsigned int level)
Definition: mesh_tools.C:743
uint8_t dof_id_type
Definition: id_types.h:67
unsigned int n_active_levels(const MeshBase &mesh)
Definition: mesh_tools.C:771
void libmesh_assert_valid_elem_ids(const MeshBase &mesh)
A function for verifying that ids and processor assignment of elements are correctly sorted (monotone...
Definition: mesh_tools.C:1170
void libmesh_assert_valid_refinement_flags(const MeshBase &mesh)
A function for verifying that refinement flags on elements are consistent between processors...
Definition: mesh_tools.C:1984