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 
99 dof_id_type total_weight (const MeshBase & mesh);
100 
109 dof_id_type weight (const MeshBase & mesh,
110  const processor_id_type pid);
111 
112 inline
114 { return MeshTools::weight (mesh, mesh.processor_id()); }
115 
122 void build_nodes_to_elem_map (const MeshBase & mesh,
123  std::vector<std::vector<dof_id_type>> & nodes_to_elem_map);
124 
128 void build_nodes_to_elem_map (const MeshBase & mesh,
129  std::vector<std::vector<const Elem *>> & nodes_to_elem_map);
130 
137 void build_nodes_to_elem_map (const MeshBase & mesh,
138  std::unordered_map<dof_id_type, std::vector<dof_id_type>> & nodes_to_elem_map);
139 
143 void build_nodes_to_elem_map (const MeshBase & mesh,
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 
194 create_bounding_box (const MeshBase & mesh);
195 
199 Sphere
200 bounding_sphere (const MeshBase & mesh);
201 
210 create_nodal_bounding_box (const MeshBase & mesh);
211 
221 create_local_bounding_box (const MeshBase & mesh);
222 
229 #ifdef LIBMESH_ENABLE_DEPRECATED
231 processor_bounding_box (const MeshBase & mesh,
232  const processor_id_type pid);
233 #endif
234 
242  const processor_id_type pid);
243 
247 Sphere
248 processor_bounding_sphere (const MeshBase & mesh,
249  const processor_id_type pid);
250 
257 #ifdef LIBMESH_ENABLE_DEPRECATED
259 subdomain_bounding_box (const MeshBase & mesh,
260  const subdomain_id_type sid);
261 #endif
262 
263 
271  const subdomain_id_type sid);
272 
276 Sphere
277 subdomain_bounding_sphere (const MeshBase & mesh,
278  const subdomain_id_type sid);
279 
280 
285 void elem_types (const MeshBase & mesh,
286  std::vector<ElemType> & et);
287 
293 dof_id_type n_elem_of_type (const MeshBase & mesh,
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 
374 void get_not_subactive_node_ids(const MeshBase & mesh,
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 
422 void find_hanging_nodes_and_parents(const MeshBase & mesh,
423  std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
424 
436 
437 
438 #ifdef DEBUG
439 
443 void libmesh_assert_no_links_to_elem(const MeshBase & mesh,
444  const Elem * bad_elem);
445 
450 void libmesh_assert_equal_n_systems (const MeshBase & mesh);
451 
457 void libmesh_assert_old_dof_objects (const MeshBase & mesh);
458 
463 void libmesh_assert_valid_node_pointers (const MeshBase & mesh);
464 
469 void libmesh_assert_valid_remote_elems (const MeshBase & mesh);
470 
475 void libmesh_assert_valid_elem_ids (const MeshBase & mesh);
476 
481 void libmesh_assert_valid_amr_elem_ids (const MeshBase & mesh);
482 
489 
500 void libmesh_assert_connected_nodes (const MeshBase & mesh);
501 
506 void libmesh_assert_valid_boundary_ids (const MeshBase & mesh);
507 
515 void libmesh_assert_valid_dof_ids (const MeshBase & mesh,
516  unsigned int sysnum = libMesh::invalid_uint);
517 
526  unsigned int sysnum);
527 
528 #ifdef LIBMESH_ENABLE_UNIQUE_ID
529 
534 void libmesh_assert_valid_unique_ids (const MeshBase & mesh);
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 
614 void libmesh_assert_valid_neighbors (const MeshBase & mesh,
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
unsigned int n_active_local_levels(const MeshBase &mesh)
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:581
void elem_types(const MeshBase &mesh, std::vector< ElemType > &et)
Fills in a vector of all element types in the mesh.
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).
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...
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:245
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.
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...
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...
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).
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
The same functionality as the deprecated MeshTools::bounding_box().
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1682
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
BoundingBox(const Point &new_min, const Point &new_max)
Definition: mesh_tools.h:73
void libmesh_assert_valid_refinement_tree(const MeshBase &mesh)
A function for verifying that elements on this processor have valid descendants and consistent active...
This is the base class from which all geometric element types are derived.
Definition: elem.h:101
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...
unsigned int n_local_levels(const MeshBase &mesh)
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 ...
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...
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
Backwards compatibility with forward declarations.
Definition: mesh_tools.h:70
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)
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:77
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 paranoid_n_levels(const MeshBase &mesh)
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.
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.
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...
BoundingBox subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
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_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.
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
unsigned int n_levels(const MeshBase &mesh)
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
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...
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
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_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)
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
The same functionality as the deprecated MeshTools::subdomain_bounding_box().
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)
BoundingBox processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
BoundingBox(const std::pair< Point, Point > &bbox)
Definition: mesh_tools.h:79
void libmesh_assert_connected_nodes(const MeshBase &mesh)
A function for verifying that all nodes are connected to at least one element.
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.
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.
The definition of the const_node_iterator struct.
Definition: mesh_base.h:1736
BoundingBox bounding_box(const MeshBase &mesh)
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
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...
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
processor_id_type processor_id() const
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
The same functionality as the deprecated MeshTools::processor_bounding_box().
unsigned int n_p_levels(const MeshBase &mesh)
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...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
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, as is required by libMesh numeric classes.
dof_id_type n_non_subactive_elem_of_type_at_level(const MeshBase &mesh, const ElemType type, const unsigned int level)
void find_boundary_nodes(const MeshBase &mesh, std::vector< bool > &on_boundary)
Calling this function on a 2D mesh will convert all the elements to triangles.
uint8_t dof_id_type
Definition: id_types.h:67
unsigned int n_active_levels(const MeshBase &mesh)
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_valid_refinement_flags(const MeshBase &mesh)
A function for verifying that refinement flags on elements are consistent between processors...