libMesh
mesh_tools.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 
294  Real constraint_tol = 0);
295 
303  std::set<dof_id_type> & not_subactive_node_ids);
304 
311 
312 
318  const MeshBase::const_node_iterator & end);
319 
320 
328 Real volume (const MeshBase & mesh,
329  unsigned int dim=libMesh::invalid_uint);
330 
331 
336 void find_nodal_neighbors(const MeshBase & mesh,
337  const Node & n,
338  const std::vector<std::vector<const Elem *>> & nodes_to_elem_map,
339  std::vector<const Node *> & neighbors);
340 
345 void find_nodal_neighbors(const MeshBase & mesh,
346  const Node & n,
347  const std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map,
348  std::vector<const Node *> & neighbors);
349 
357  std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
358 
370 
381 
390 bool valid_is_prepared (const MeshBase & mesh);
391 
393 
400 #ifndef NDEBUG
401 
407 
414 
420 
426 
432 
438 
445 
454  unsigned int sysnum);
455 
462 template <typename DofObjectSubclass>
464 
470 
476 
477 #endif // !NDEBUG
478 
480 
482 
489 #ifdef DEBUG
490 
496  const Elem * bad_elem);
497 
502 
508 
520 
527 
533 
542  unsigned int sysnum = libMesh::invalid_uint);
543 
544 #ifdef LIBMESH_ENABLE_UNIQUE_ID
545 
551 #endif
552 
559 
566 
574 
580 template <typename DofObjectSubclass>
582 
587 template <typename DofObjectSubclass>
589 {
590  libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
591  libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
592 }
593 
599 
611  bool assert_valid_remote_elems=true);
612 
613 #endif // DEBUG
614 
616 
617 // There is no reason for users to call functions in the MeshTools::Private namespace.
618 namespace Private {
634 } // end namespace Private
635 
636 } // end namespace MeshTools
637 
638 } // namespace libMesh
639 
640 
641 #endif // LIBMESH_MESH_TOOLS_H
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:760
void libmesh_assert_equal_points(const MeshBase &mesh)
A function for testing that node locations match across processors.
Definition: mesh_tools.C:1605
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:588
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:716
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:977
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:1361
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:310
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:1287
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:1984
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:2393
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:969
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:559
The definition of the const_element_iterator struct.
Definition: mesh_base.h:2216
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:1182
unsigned int dim
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:663
void clear_spline_nodes(MeshBase &)
Remove spline node (for IsoGeometric Analysis meshes) elements and nodes and constraints from the mes...
Definition: mesh_tools.C:1147
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:1547
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:537
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:1036
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:1665
unsigned int n_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:789
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:2065
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:449
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:728
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:624
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:75
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:1954
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:826
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:517
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:1212
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:1878
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:1262
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:1534
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:1586
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:437
unsigned int n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:802
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
Definition: mesh_tools.C:1708
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:1341
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:702
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:2542
Real volume(const MeshBase &mesh, unsigned int dim=libMesh::invalid_uint)
Find the total volume of a mesh (interpreting that as area for dim = 2, or total arc length for dim =...
Definition: mesh_tools.C:985
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:1059
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:414
dof_id_type n_connected_components(const MeshBase &mesh, Real constraint_tol=0)
Definition: mesh_tools.C:840
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:678
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:611
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:1621
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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:1642
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:958
The definition of the const_node_iterator struct.
Definition: mesh_base.h:2267
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:737
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:2205
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:584
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
Definition: mesh_tools.C:1906
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:638
unsigned int n_p_levels(const MeshBase &mesh)
Definition: mesh_tools.C:1014
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:1238
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:1397
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:744
uint8_t dof_id_type
Definition: id_types.h:67
unsigned int n_active_levels(const MeshBase &mesh)
Definition: mesh_tools.C:772
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:1318
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:2158