libMesh
mesh_tools.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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/enum_elem_type.h"
27 #include "libmesh/id_types.h"
28 #include "libmesh/mesh_base.h"
29 
30 // C++ Includes
31 #include <vector>
32 #include <set>
33 #include <limits>
34 
35 namespace libMesh
36 {
37 
38 // forward declarations
39 class Sphere;
40 class Elem;
41 
51 namespace MeshTools
52 {
53 
59 #ifdef LIBMESH_ENABLE_DEPRECATED
61 {
62 public:
63  BoundingBox (const Point & new_min,
64  const Point & new_max) :
65  libMesh::BoundingBox(new_min, new_max) {
66  libmesh_deprecated(); // Switch to libMesh::BoundingBox
67  }
68 
69  BoundingBox (const std::pair<Point, Point> & bbox) :
70  libMesh::BoundingBox(bbox) {
71  libmesh_deprecated(); // Switch to libMesh::BoundingBox
72  }
73 
75  libmesh_deprecated(); // Switch to libMesh::BoundingBox
76  }
77 };
78 #endif
79 
80 
90 
99 dof_id_type weight (const MeshBase & mesh,
100  const processor_id_type pid);
101 
102 inline
104 { return MeshTools::weight (mesh, mesh.processor_id()); }
105 
112 void build_nodes_to_elem_map (const MeshBase & mesh,
113  std::vector<std::vector<dof_id_type>> & nodes_to_elem_map);
114 
118 void build_nodes_to_elem_map (const MeshBase & mesh,
119  std::vector<std::vector<const Elem *>> & nodes_to_elem_map);
120 
121 
122 // /**
123 // * Calling this function on a 2D mesh will convert all the elements
124 // * to triangles. \p QUAD4s will be converted to \p TRI3s, \p QUAD8s
125 // * and \p QUAD9s will be converted to \p TRI6s.
126 // */
127 // void all_tri (MeshBase & mesh);
128 
133 void find_boundary_nodes (const MeshBase & mesh,
134  std::vector<bool> & on_boundary);
135 
143 #ifdef LIBMESH_ENABLE_DEPRECATED
145 bounding_box (const MeshBase & mesh);
146 #endif
147 
154 create_bounding_box (const MeshBase & mesh);
155 
159 Sphere
160 bounding_sphere (const MeshBase & mesh);
161 
170 create_nodal_bounding_box (const MeshBase & mesh);
171 
181 create_local_bounding_box (const MeshBase & mesh);
182 
189 #ifdef LIBMESH_ENABLE_DEPRECATED
191 processor_bounding_box (const MeshBase & mesh,
192  const processor_id_type pid);
193 #endif
194 
202  const processor_id_type pid);
203 
207 Sphere
208 processor_bounding_sphere (const MeshBase & mesh,
209  const processor_id_type pid);
210 
217 #ifdef LIBMESH_ENABLE_DEPRECATED
219 subdomain_bounding_box (const MeshBase & mesh,
220  const subdomain_id_type sid);
221 #endif
222 
223 
231  const subdomain_id_type sid);
232 
236 Sphere
237 subdomain_bounding_sphere (const MeshBase & mesh,
238  const subdomain_id_type sid);
239 
240 
245 void elem_types (const MeshBase & mesh,
246  std::vector<ElemType> & et);
247 
253 dof_id_type n_elem_of_type (const MeshBase & mesh,
254  const ElemType type);
255 
262  const ElemType type);
263 
273  const ElemType type,
274  const unsigned int level);
275 
283 unsigned int n_levels(const MeshBase & mesh);
284 
291 unsigned int n_local_levels(const MeshBase & mesh);
292 
299 unsigned int n_active_levels(const MeshBase & mesh);
300 
307 unsigned int n_active_local_levels(const MeshBase & mesh);
308 
315 unsigned int n_p_levels (const MeshBase & mesh);
316 
326 unsigned int paranoid_n_levels(const MeshBase & mesh);
327 
334 void get_not_subactive_node_ids(const MeshBase & mesh,
335  std::set<dof_id_type> & not_subactive_node_ids);
336 
343 
344 
350  const MeshBase::const_node_iterator & end);
351 
352 
356 unsigned int max_level (const MeshBase & mesh);
357 
358 
363 void find_nodal_neighbors(const MeshBase & mesh,
364  const Node & n,
365  const std::vector<std::vector<const Elem *>> & nodes_to_elem_map,
366  std::vector<const Node *> & neighbors);
367 
374 void find_hanging_nodes_and_parents(const MeshBase & mesh,
375  std::map<dof_id_type, std::vector<dof_id_type>> & hanging_nodes);
376 
388 
389 
390 #ifdef DEBUG
391 
395 void libmesh_assert_no_links_to_elem(const MeshBase & mesh,
396  const Elem * bad_elem);
397 
402 void libmesh_assert_equal_n_systems (const MeshBase & mesh);
403 
409 void libmesh_assert_old_dof_objects (const MeshBase & mesh);
410 
415 void libmesh_assert_valid_node_pointers (const MeshBase & mesh);
416 
421 void libmesh_assert_valid_remote_elems (const MeshBase & mesh);
422 
427 void libmesh_assert_valid_elem_ids (const MeshBase & mesh);
428 
433 void libmesh_assert_valid_amr_elem_ids (const MeshBase & mesh);
434 
441 
452 void libmesh_assert_connected_nodes (const MeshBase & mesh);
453 
458 void libmesh_assert_valid_boundary_ids (const MeshBase & mesh);
459 
467 void libmesh_assert_valid_dof_ids (const MeshBase & mesh,
468  unsigned int sysnum = libMesh::invalid_uint);
469 
470 #ifdef LIBMESH_ENABLE_UNIQUE_ID
471 
476 void libmesh_assert_valid_unique_ids (const MeshBase & mesh);
477 #endif
478 
484 template <typename DofObjectSubclass>
486 
493 template <typename DofObjectSubclass>
495 
500 template <typename DofObjectSubclass>
502  libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
503  libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
504 }
505 
511 
517 
528 void libmesh_assert_valid_neighbors (const MeshBase & mesh,
529  bool assert_valid_remote_elems=true);
530 #endif
531 
532 // There is no reason for users to call functions in the MeshTools::Private namespace.
533 namespace Private {
549 } // end namespace Private
550 
551 } // end namespace MeshTools
552 
553 } // namespace libMesh
554 
555 
556 #endif // LIBMESH_MESH_TOOLS_H
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:555
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:501
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:510
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:664
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:1133
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
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:1037
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:1832
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:656
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
The same functionality as the deprecated MeshTools::bounding_box().
Definition: mesh_tools.C:329
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
Sphere processor_bounding_sphere(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:445
ElemType
Defines an enum for geometric element types.
BoundingBox(const Point &new_min, const Point &new_max)
Definition: mesh_tools.h:63
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:1678
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
unsigned int n_local_levels(const MeshBase &mesh)
Definition: mesh_tools.C:588
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:257
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:60
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:522
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:394
This is the MeshBase class.
Definition: mesh_base.h:68
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:631
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:963
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:1369
BoundingBox bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:316
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:1013
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:699
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:1070
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:245
unsigned int n_levels(const MeshBase &mesh)
Definition: mesh_tools.C:603
void libmesh_assert_valid_boundary_ids(const MeshBase &mesh)
A function for verifying that boundary condition ids match across processors.
Definition: mesh_tools.C:1194
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:1113
Sphere subdomain_bounding_sphere(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:496
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:1968
BoundingBox processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:409
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:873
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:222
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:472
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:381
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:69
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:1169
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:645
The definition of the const_node_iterator struct.
Definition: mesh_base.h:1548
dof_id_type n_active_elem_of_type(const MeshBase &mesh, const ElemType type)
Definition: mesh_tools.C:531
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:1713
libMesh::BoundingBox create_nodal_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:354
void libmesh_assert_valid_unique_ids(const MeshBase &mesh)
A function for verifying that unique ids match across processors.
Definition: mesh_tools.C:1397
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:420
unsigned int n_p_levels(const MeshBase &mesh)
Definition: mesh_tools.C:672
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:989
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
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:538
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.
Definition: mesh_tools.C:290
BoundingBox subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition: mesh_tools.C:461
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:64
unsigned int n_active_levels(const MeshBase &mesh)
Definition: mesh_tools.C:567
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:1090
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:1630