libMesh
mesh_tools.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
30 namespace libMesh
31 {
32 enum ElemType : int;
33 }
34 #else
35 #include "libmesh/enum_elem_type.h"
36 #endif
37 
38 // C++ Includes
39 #include <limits>
40 #include <set>
41 #include <unordered_set>
42 #include <unordered_map>
43 #include <vector>
44 
45 namespace libMesh
46 {
47 
48 // forward declarations
49 class Sphere;
50 class Elem;
51 
61 namespace MeshTools
62 {
63 
69 #ifdef LIBMESH_ENABLE_DEPRECATED
71 {
72 public:
73  BoundingBox (const Point & new_min,
74  const Point & new_max) :
75  libMesh::BoundingBox(new_min, new_max) {
76  libmesh_deprecated(); // Switch to libMesh::BoundingBox
77  }
78 
79  BoundingBox (const std::pair<Point, Point> & bbox) :
80  libMesh::BoundingBox(bbox) {
81  libmesh_deprecated(); // Switch to libMesh::BoundingBox
82  }
83 
85  libmesh_deprecated(); // Switch to libMesh::BoundingBox
86  }
87 };
88 #endif
89 
90 
100 
110  const processor_id_type pid);
111 
112 inline
114 { return MeshTools::weight (mesh, mesh.processor_id()); }
115 
123  std::vector<std::vector<dof_id_type>> & nodes_to_elem_map);
124 
129  std::vector<std::vector<const Elem *>> & nodes_to_elem_map);
130 
138  std::unordered_map<dof_id_type, std::vector<dof_id_type>> & nodes_to_elem_map);
139 
144  std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map);
145 
146 
147 // /**
148 // * Calling this function on a 2D mesh will convert all the elements
149 // * to triangles. \p QUAD4s will be converted to \p TRI3s, \p QUAD8s
150 // * and \p QUAD9s will be converted to \p TRI6s.
151 // */
152 // void all_tri (MeshBase & mesh);
153 
154 #ifdef LIBMESH_ENABLE_DEPRECATED
155 
159 void find_boundary_nodes (const MeshBase & mesh,
160  std::vector<bool> & on_boundary);
161 #endif
162 
166 std::unordered_set<dof_id_type> find_boundary_nodes(const MeshBase & mesh);
167 
174 std::unordered_set<dof_id_type> find_block_boundary_nodes(const MeshBase & mesh);
175 
183 #ifdef LIBMESH_ENABLE_DEPRECATED
185 bounding_box (const MeshBase & mesh);
186 #endif
187 
195 
199 Sphere
200 bounding_sphere (const MeshBase & mesh);
201 
211 
222 
229 #ifdef LIBMESH_ENABLE_DEPRECATED
232  const processor_id_type pid);
233 #endif
234 
242  const processor_id_type pid);
243 
247 Sphere
249  const processor_id_type pid);
250 
257 #ifdef LIBMESH_ENABLE_DEPRECATED
260  const subdomain_id_type sid);
261 #endif
262 
263 
271  const subdomain_id_type sid);
272 
276 Sphere
278  const subdomain_id_type sid);
279 
280 
285 void elem_types (const MeshBase & mesh,
286  std::vector<ElemType> & et);
287 
294  const ElemType type);
295 
302  const ElemType type);
303 
313  const ElemType type,
314  const unsigned int level);
315 
323 unsigned int n_levels(const MeshBase & mesh);
324 
331 unsigned int n_local_levels(const MeshBase & mesh);
332 
339 unsigned int n_active_levels(const MeshBase & mesh);
340 
347 unsigned int n_active_local_levels(const MeshBase & mesh);
348 
355 unsigned int n_p_levels (const MeshBase & mesh);
356 
366 unsigned int paranoid_n_levels(const MeshBase & mesh);
367 
375  std::set<dof_id_type> & not_subactive_node_ids);
376 
383 
384 
391 
392 
396 unsigned int max_level (const MeshBase & mesh);
397 
402 void find_nodal_neighbors(const MeshBase & mesh,
403  const Node & n,
404  const std::vector<std::vector<const Elem *>> & nodes_to_elem_map,
405  std::vector<const Node *> & neighbors);
406 
411 void find_nodal_neighbors(const MeshBase & mesh,
412  const Node & n,
413  const std::unordered_map<dof_id_type, std::vector<const Elem *>> & nodes_to_elem_map,
414  std::vector<const Node *> & neighbors);
415 
423  std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
424 
436 
437 
438 #ifdef DEBUG
439 
444  const Elem * bad_elem);
445 
451 
458 
464 
470 
476 
482 
489 
501 
507 
516  unsigned int sysnum = libMesh::invalid_uint);
517 
526  unsigned int sysnum);
527 
528 #ifdef LIBMESH_ENABLE_UNIQUE_ID
529 
535 #endif
536 
543 
550 
558 
564 template <typename DofObjectSubclass>
566 
573 template <typename DofObjectSubclass>
575 
580 template <typename DofObjectSubclass>
582  libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
583  libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
584 }
585 
591 
597 
603 
615  bool assert_valid_remote_elems=true);
616 #endif
617 
618 // There is no reason for users to call functions in the MeshTools::Private namespace.
619 namespace Private {
635 } // end namespace Private
636 
637 } // end namespace MeshTools
638 
639 } // namespace libMesh
640 
641 
642 #endif // LIBMESH_MESH_TOOLS_H
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::MeshTools::n_local_levels
unsigned int n_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:643
libMesh::MeshTools::paranoid_n_levels
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:680
libMesh::MeshTools::n_elem
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:705
libMesh::MeshTools::libmesh_assert_valid_boundary_ids
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
Definition: mesh_tools.C:1396
libMesh::MeshTools::total_weight
dof_id_type total_weight(const MeshBase &mesh)
Definition: mesh_tools.C:213
libMesh::BoundingBox
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
libMesh::MeshTools::bounding_sphere
Sphere bounding_sphere(const MeshBase &mesh)
Definition: mesh_tools.C:441
libMesh::MeshTools::libmesh_assert_valid_amr_elem_ids
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:1315
libMesh::MeshTools::create_nodal_bounding_box
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:414
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::MeshTools::create_subdomain_bounding_box
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
The same functionality as the deprecated MeshTools::subdomain_bounding_box().
Definition: mesh_tools.C:532
libMesh::MeshTools::libmesh_assert_valid_procids
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:581
libMesh::MeshTools::libmesh_assert_valid_neighbors
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:2061
libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids
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:1870
libMesh::MeshTools::bounding_box
BoundingBox bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:376
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
libMesh::MeshTools::create_local_bounding_box
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:454
libMesh::MeshTools::max_level
unsigned int max_level(const MeshBase &mesh)
Find the maximum h-refinement level in a mesh.
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshTools::build_nodes_to_elem_map
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:248
libMesh::MeshTools::processor_bounding_sphere
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:505
libMesh::MeshTools::find_block_boundary_nodes
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:354
libMesh::MeshTools::libmesh_assert_valid_elem_ids
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:1292
libMesh::MeshTools::libmesh_assert_valid_node_pointers
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:1218
libMesh::MeshTools::n_levels
unsigned int n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:656
libMesh::MeshTools::libmesh_assert_connected_nodes
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:1371
libMesh::MeshTools::processor_bounding_box
BoundingBox processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:469
libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes
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:1694
libMesh::Sphere
This class defines a sphere.
Definition: sphere.h:72
libMesh::MeshTools::create_bounding_box
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
The same functionality as the deprecated MeshTools::bounding_box().
Definition: mesh_tools.C:389
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::MeshTools::get_not_subactive_node_ids
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:694
libMesh::MeshTools::libmesh_assert_topology_consistent_procids
void libmesh_assert_topology_consistent_procids(const MeshBase &mesh)
A function for verifying that processor assignment is topologically consistent on nodes (each node pa...
libMesh::MeshTools::libmesh_assert_parallel_consistent_procids
void libmesh_assert_parallel_consistent_procids(const MeshBase &mesh)
A function for verifying that processor assignment is parallel consistent (every processor agrees on ...
libMesh::MeshTools::libmesh_assert_valid_unique_ids
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
Definition: mesh_tools.C:1634
libMesh::MeshTools::elem_types
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:570
libMesh::MeshBase::const_node_iterator
The definition of the const_node_iterator struct.
Definition: mesh_base.h:1945
libMesh::MeshTools::n_nodes
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:713
libMesh::MeshTools::subdomain_bounding_sphere
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:556
libMesh::MeshTools::create_processor_bounding_box
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
The same functionality as the deprecated MeshTools::processor_bounding_box().
Definition: mesh_tools.C:480
libMesh::MeshTools::libmesh_assert_contiguous_dof_ids
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 processors,...
Definition: mesh_tools.C:1593
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::MeshTools::libmesh_assert_old_dof_objects
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:1194
libMesh::MeshTools::n_non_subactive_elem_of_type_at_level
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:598
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::MeshTools::n_active_levels
unsigned int n_active_levels(const MeshBase &mesh)
Definition: mesh_tools.C:626
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::MeshTools::libmesh_assert_equal_n_systems
void libmesh_assert_equal_n_systems(const MeshBase &mesh)
A function for testing that all DofObjects within a mesh have the same n_systems count.
Definition: mesh_tools.C:1168
libMesh::MeshTools::n_elem_of_type
dof_id_type n_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:582
libMesh::MeshTools::libmesh_assert_no_links_to_elem
void libmesh_assert_no_links_to_elem(const MeshBase &mesh, const Elem *bad_elem)
A function for verifying that an element has been cut off from the rest of the mesh.
Definition: mesh_tools.C:1272
libMesh::MeshTools::find_nodal_neighbors
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:743
libMesh::MeshBase::const_element_iterator
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1891
libMesh::MeshTools::n_active_local_levels
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:614
libMesh::MeshTools::libmesh_assert_valid_dof_ids
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:1566
libMesh::MeshTools::libmesh_assert_canonical_node_procids
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:1961
libMesh::MeshTools::n_active_elem_of_type
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:591
libMesh::MeshTools::Private::globally_renumber_nodes_and_elements
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:2411
libMesh::MeshTools::BoundingBox::BoundingBox
BoundingBox(const std::pair< Point, Point > &bbox)
Definition: mesh_tools.h:79
libMesh::MeshTools::subdomain_bounding_box
BoundingBox subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:521
libMesh::MeshTools::BoundingBox::BoundingBox
BoundingBox()
Definition: mesh_tools.h:84
libMesh::MeshTools::libmesh_assert_valid_remote_elems
void libmesh_assert_valid_remote_elems(const MeshBase &mesh)
A function for verifying that active local elements' neighbors are never remote elements.
Definition: mesh_tools.C:1242
libMesh::MeshTools::find_hanging_nodes_and_parents
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:1078
libMesh::MeshTools::libmesh_assert_valid_amr_interior_parents
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:1335
libMesh::MeshTools::n_p_levels
unsigned int n_p_levels(const MeshBase &mesh)
Definition: mesh_tools.C:721
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::MeshTools::libmesh_assert_consistent_distributed
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:1664
libMesh::MeshTools::libmesh_assert_valid_refinement_tree
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:2026
libMesh::MeshTools::find_boundary_nodes
void find_boundary_nodes(const MeshBase &mesh, std::vector< bool > &on_boundary)
Definition: mesh_tools.C:306
libMesh::MeshTools::BoundingBox::BoundingBox
BoundingBox(const Point &new_min, const Point &new_max)
Definition: mesh_tools.h:73
libMesh::MeshTools::libmesh_assert_valid_refinement_flags
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:1978
libMesh::TestClass
Definition: id_types.h:33
libMesh::MeshTools::BoundingBox
Backwards compatibility with forward declarations.
Definition: mesh_tools.h:70
libMesh::MeshTools::weight
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:236
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::MeshTools::correct_node_proc_ids
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:2252
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33