libMesh
Loading...
Searching...
No Matches
mesh_tools.h
Go to the documentation of this file.
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_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
36namespace libMesh
37{
38
39// forward declarations
40class Sphere;
41class Elem;
42enum ElemType : int;
43
53namespace MeshTools
54{
55
64dof_id_type total_weight (const MeshBase & mesh);
65
74dof_id_type weight (const MeshBase & mesh,
75 const processor_id_type pid);
76
77inline
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
122std::unordered_set<dof_id_type> find_boundary_nodes(const MeshBase & mesh);
123
130std::unordered_set<dof_id_type> find_block_boundary_nodes(const MeshBase & mesh);
131
137
141Sphere
143
153
164
171 const processor_id_type pid);
172
176Sphere
178 const processor_id_type pid);
179
186 const subdomain_id_type sid);
187
191Sphere
193 const subdomain_id_type sid);
194
195
200void 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
238unsigned int n_levels(const MeshBase & mesh);
239
246unsigned int n_local_levels(const MeshBase & mesh);
247
254unsigned int n_active_levels(const MeshBase & mesh);
255
262unsigned int n_active_local_levels(const MeshBase & mesh);
263
270unsigned int n_p_levels (const MeshBase & mesh);
271
281unsigned 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
319
320
328Real volume (const MeshBase & mesh,
329 unsigned int dim=libMesh::invalid_uint);
330
331
337 const Node & n,
338 const std::vector<std::vector<const Elem *>> & nodes_to_elem_map,
339 std::vector<const Node *> & neighbors);
340
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
358 const MeshBase & mesh,
359 const Node & node,
360 const std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map,
361 std::vector<const Node *> & neighbors);
362
370 std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
371
383
394
403bool valid_is_prepared (const MeshBase & mesh);
404
406
413#ifndef NDEBUG
414
420
427
433
439
445
451
458
467 unsigned int sysnum);
468
475template <typename DofObjectSubclass>
477
483
489
490#endif // !NDEBUG
491
493
495
502#ifdef DEBUG
503
509 const Elem * bad_elem);
510
515
521
533
540
546
555 unsigned int sysnum = libMesh::invalid_uint);
556
557#ifdef LIBMESH_ENABLE_UNIQUE_ID
562#endif
563
570
577
585
591template <typename DofObjectSubclass>
593
598template <typename DofObjectSubclass>
600{
601 libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
602 libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
603}
604
610
622 bool assert_valid_remote_elems=true);
623
624#endif // DEBUG
625
627
628// There is no reason for users to call functions in the MeshTools::Private namespace.
629namespace Private {
645} // end namespace Private
646
647} // end namespace MeshTools
648
649} // namespace libMesh
650
651
652#endif // LIBMESH_MESH_TOOLS_H
unsigned int dim
void ErrorVector unsigned int
Defines a Cartesian bounding box by the two corner extremum.
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the MeshBase class.
Definition mesh_base.h:81
A Node is like a Point, but with more information.
Definition node.h:55
This class defines a sphere.
Definition sphere.h:73
MeshBase & mesh
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
void libmesh_assert_equal_connectivity(const MeshBase &mesh)
A function for testing that element nodal connectivities match across processors.
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.
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition mesh_tools.C:444
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:456
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...
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:723
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 =...
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
Sphere bounding_sphere(const MeshBase &mesh)
Definition mesh_tools.C:618
void libmesh_assert_valid_elem_ids(const MeshBase &mesh)
A function for verifying that ids and processor assignment of elements are correctly sorted (monotone...
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 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).
dof_id_type n_connected_components(const MeshBase &mesh, Real constraint_tol=0)
Definition mesh_tools.C:864
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:751
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 ...
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:566
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...
unsigned int n_p_levels(const MeshBase &mesh)
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:631
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...
void libmesh_assert_valid_refinement_flags(const MeshBase &mesh)
A function for verifying that refinement flags on elements are consistent between processors.
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition mesh_tools.C:685
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition mesh_tools.C:767
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...
bool valid_is_prepared(const MeshBase &mesh)
A function for testing whether a mesh's cached is_prepared() setting is not a false positive.
void libmesh_assert_valid_remote_elems(const MeshBase &mesh)
A function for verifying that active local elements' neighbors are never remote elements.
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.
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
Definition mesh_tools.C:670
void libmesh_assert_parallel_consistent_procids(const MeshBase &mesh)
A function for verifying that processor assignment is parallel consistent (every processor agrees on ...
void clear_spline_nodes(MeshBase &)
Remove spline node (for IsoGeometric Analysis meshes) elements and nodes and constraints from the mes...
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,...
unsigned int n_active_levels(const MeshBase &mesh)
Definition mesh_tools.C:796
unsigned int n_local_levels(const MeshBase &mesh)
Definition mesh_tools.C:813
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
Definition mesh_tools.C:709
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...
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:993
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:591
void libmesh_assert_connected_nodes(const MeshBase &mesh)
A function for verifying that all nodes are connected to at least one element.
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...
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:599
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...
void find_nodal_or_face_neighbors(const MeshBase &mesh, const Node &node, const std::unordered_map< dof_id_type, 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...
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...
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:544
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...
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition mesh_tools.C:645
void libmesh_assert_canonical_node_procids(const MeshBase &mesh)
A function for verifying that processor assignment of nodes matches the heuristic specified in Node::...
void libmesh_assert_equal_n_systems(const MeshBase &mesh)
The following functions, only available in builds with NDEBUG undefined, are for asserting internal c...
dof_id_type n_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition mesh_tools.C:735
void libmesh_assert_valid_refinement_tree(const MeshBase &mesh)
A function for verifying that elements on this processor have valid descendants and consistent active...
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...
dof_id_type total_weight(const MeshBase &mesh)
Definition mesh_tools.C:421
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition mesh_tools.C:744
std::unordered_set< dof_id_type > find_boundary_nodes(const MeshBase &mesh)
Returns a std::set containing Node IDs for all of the boundary nodes.
Definition mesh_tools.C:524
void libmesh_assert_consistent_distributed(const MeshBase &mesh)
A function for verifying that distribution of dof objects is parallel consistent (every processor can...
unsigned int n_levels(const MeshBase &mesh)
Definition mesh_tools.C:826
void libmesh_assert_equal_points(const MeshBase &mesh)
A function for testing that node locations match across processors.
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition mesh_tools.C:850
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.
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:303
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
The definition of the const_element_iterator struct.
Definition mesh_base.h:2556
The definition of the const_node_iterator struct.
Definition mesh_base.h:2607
const dof_id_type n_nodes
Definition tecplot_io.C:67