libMesh
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
libMesh::MeshTools Namespace Reference

Utility functions for operations on a Mesh object. More...

Namespaces

namespace  Generation
 Tools for Mesh generation.
 
namespace  Modification
 Tools for Mesh modification.
 
namespace  Private
 
namespace  Subdivision
 Utility functions for subdivision surface operations on a Mesh.
 

Classes

class  SidesToElemMap
 This class implements a generalization of the MeshTools::build_nodes_to_elem_map() function, but rather than being a standalone function taking a std::unordered_map argument, we define a class with APIs for both building the underlying map data structure and querying its contents. More...
 

Functions

dof_id_type total_weight (const MeshBase &mesh)
 
dof_id_type weight (const MeshBase &mesh, const processor_id_type pid)
 
dof_id_type weight (const MeshBase &mesh)
 
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 connectivity.
 
void build_nodes_to_elem_map (const MeshBase &mesh, std::vector< std::vector< const Elem * > > &nodes_to_elem_map)
 The same, except element pointers are returned instead of indices.
 
void build_nodes_to_elem_map (const MeshBase &mesh, std::unordered_map< dof_id_type, std::vector< dof_id_type > > &nodes_to_elem_map)
 After calling this function the input map nodes_to_elem_map will contain the node to element connectivity.
 
void build_nodes_to_elem_map (const MeshBase &mesh, std::unordered_map< dof_id_type, std::vector< const Elem * > > &nodes_to_elem_map)
 The same, except element pointers are returned instead of indices.
 
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.
 
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.
 
libMesh::BoundingBox create_bounding_box (const MeshBase &mesh)
 
Sphere bounding_sphere (const MeshBase &mesh)
 
libMesh::BoundingBox create_nodal_bounding_box (const MeshBase &mesh)
 
libMesh::BoundingBox create_local_bounding_box (const MeshBase &mesh)
 
libMesh::BoundingBox create_processor_bounding_box (const MeshBase &mesh, const processor_id_type pid)
 
Sphere processor_bounding_sphere (const MeshBase &mesh, const processor_id_type pid)
 
libMesh::BoundingBox create_subdomain_bounding_box (const MeshBase &mesh, const subdomain_id_type sid)
 
Sphere subdomain_bounding_sphere (const MeshBase &mesh, const subdomain_id_type sid)
 
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_elem_of_type (const MeshBase &mesh, const ElemType type)
 
dof_id_type n_active_elem_of_type (const MeshBase &mesh, const ElemType type)
 
dof_id_type n_non_subactive_elem_of_type_at_level (const MeshBase &mesh, const ElemType type, const unsigned int level)
 
unsigned int n_levels (const MeshBase &mesh)
 
unsigned int n_local_levels (const MeshBase &mesh)
 
unsigned int n_active_levels (const MeshBase &mesh)
 
unsigned int n_active_local_levels (const MeshBase &mesh)
 
unsigned int n_p_levels (const MeshBase &mesh)
 
unsigned int paranoid_n_levels (const MeshBase &mesh)
 
dof_id_type n_connected_components (const MeshBase &mesh, Real constraint_tol=0)
 
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.
 
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_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).
 
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 = 1, or number of NodeElem in the mesh for dim = 0).
 
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 the given one.
 
void find_nodal_neighbors (const MeshBase &mesh, const Node &n, 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 the given one.
 
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 the given one.
 
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 the hanging nodes in the mesh.
 
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 node.
 
void clear_spline_nodes (MeshBase &)
 Remove spline node (for IsoGeometric Analysis meshes) elements and nodes and constraints from the mesh.
 
bool valid_is_prepared (const MeshBase &mesh)
 A function for testing whether a mesh's cached is_prepared() setting is not a false positive, and that its preparation() values are not false positives.
 
template<>
void libmesh_assert_topology_consistent_procids< Elem > (const MeshBase &mesh)
 
template<>
void libmesh_assert_topology_consistent_procids< Node > (const MeshBase &mesh)
 
template<>
void libmesh_assert_parallel_consistent_procids< Elem > (const MeshBase &mesh)
 
template<>
void libmesh_assert_parallel_consistent_procids< Node > (const MeshBase &mesh)
 
void libmesh_assert_valid_is_prepared (const MeshBase &mesh)
 The following functions, no-ops except in builds with NDEBUG undefined, are for asserting internal consistency that we hope should never be broken in opt.
 
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_old_dof_objects (const MeshBase &mesh)
 A function for testing that all non-recently-created DofObjects within a mesh have old_dof_object data.
 
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.
 
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_elem_ids (const MeshBase &mesh)
 A function for verifying that ids and processor assignment of elements are correctly sorted (monotone increasing)
 
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 than children)
 
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 (parents' interior_parents are interior_parents' parents)
 
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.
 
template<typename DofObjectSubclass >
void libmesh_assert_topology_consistent_procids (const MeshBase &mesh)
 A function for verifying that processor assignment is topologically consistent on nodes (each node part of an active element on its processor) or elements (each parent has the processor id of one of its children).
 
void libmesh_assert_canonical_node_procids (const MeshBase &mesh)
 A function for verifying that processor assignment of nodes matches the heuristic specified in Node::choose_processor_id()
 
void libmesh_assert_valid_refinement_tree (const MeshBase &mesh)
 A function for verifying that elements on this processor have valid descendants and consistent active flags.
 
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 slow asymptotic behavior, and so are unsuitable for use even with METHOD=devel.
 
void libmesh_assert_equal_points (const MeshBase &mesh)
 A function for testing that node locations match across processors.
 
void libmesh_assert_equal_connectivity (const MeshBase &mesh)
 A function for testing that element nodal connectivities match across processors.
 
void libmesh_assert_connected_nodes (const MeshBase &mesh)
 A function for verifying that all nodes are connected to at least one element.
 
void libmesh_assert_valid_constraint_rows (const MeshBase &mesh)
 A function for verifying that all mesh constraint rows express relations between nodes and elements that are semilocal (local or ghosted) to the current processor's portion of the 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_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_unique_ids (const MeshBase &mesh)
 A function for verifying that unique ids match across processors.
 
void libmesh_assert_consistent_distributed (const MeshBase &mesh)
 A function for verifying that distribution of dof objects is parallel consistent (every processor can see every node or element it owns)
 
void libmesh_assert_consistent_distributed_nodes (const MeshBase &mesh)
 A function for verifying that distribution of nodes is parallel consistent (every processor can see every node it owns) even before node ids have been made consistent.
 
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 the processor id of each node it can see) even on nodes which have not yet received consistent DofObject::id(), using element topology to identify matching nodes.
 
template<typename DofObjectSubclass >
void libmesh_assert_parallel_consistent_procids (const MeshBase &mesh)
 A function for verifying that processor assignment is parallel consistent (every processor agrees on the processor id of each dof object it can see)
 
template<typename DofObjectSubclass >
void libmesh_assert_valid_procids (const MeshBase &mesh)
 A function for verifying that processor assignment is both parallel and topologically consistent.
 
void libmesh_assert_valid_refinement_flags (const MeshBase &mesh)
 A function for verifying that refinement flags on elements are consistent between processors.
 
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 descendant of a neighbor of its neighbors) and consistent (each neighbor link goes to either the same neighbor or to a RemoteElem on each processor)
 

Detailed Description

Utility functions for operations on a Mesh object.

Here is where useful functions for interfacing with a Mesh should be defined. In general this namespace should be used to prevent the Mesh class from becoming too cluttered.

Author
Benjamin S. Kirk
Date
2004

Function Documentation

◆ bounding_sphere()

Sphere libMesh::MeshTools::bounding_sphere ( const MeshBase &  mesh)
Returns
A bounding sphere for mesh instead of a bounding box.

Definition at line 682 of file mesh_tools.C.

683{
685
686 const Real diag = (bbox.second - bbox.first).norm();
687 const Point cent = (bbox.second + bbox.first)/2;
688
689 return Sphere (cent, .5*diag);
690}
Defines a Cartesian bounding box by the two corner extremum.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
This class defines a sphere.
Definition sphere.h:73
MeshBase & mesh
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:630
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References create_bounding_box(), mesh, and libMesh::Real.

◆ build_nodes_to_elem_map() [1/4]

void libMesh::MeshTools::build_nodes_to_elem_map ( const MeshBase &  mesh,
std::unordered_map< dof_id_type, std::vector< const Elem * > > &  nodes_to_elem_map 
)

The same, except element pointers are returned instead of indices.

Definition at line 575 of file mesh_tools.C.

577{
578 nodes_to_elem_map.clear();
579
580 for (const auto & elem : mesh.element_ptr_range())
581 for (auto & node : elem->node_ref_range())
582 nodes_to_elem_map[node.id()].push_back(elem);
583}

References mesh.

◆ build_nodes_to_elem_map() [2/4]

void libMesh::MeshTools::build_nodes_to_elem_map ( const MeshBase &  mesh,
std::unordered_map< dof_id_type, std::vector< dof_id_type > > &  nodes_to_elem_map 
)

After calling this function the input map nodes_to_elem_map will contain the node to element connectivity.

That is to say nodes_to_elem_map[i][j] is the global number of \( j^{th} \) element connected to node i.

Definition at line 563 of file mesh_tools.C.

565{
566 nodes_to_elem_map.clear();
567
568 for (const auto & elem : mesh.element_ptr_range())
569 for (auto & node : elem->node_ref_range())
570 nodes_to_elem_map[node.id()].push_back(elem->id());
571}

References mesh.

◆ build_nodes_to_elem_map() [3/4]

void libMesh::MeshTools::build_nodes_to_elem_map ( const MeshBase &  mesh,
std::vector< std::vector< const Elem * > > &  nodes_to_elem_map 
)

The same, except element pointers are returned instead of indices.

Definition at line 542 of file mesh_tools.C.

544{
545 // A vector indexed over all nodes is too inefficient to use for a
546 // distributed mesh. Use the unordered_map API instead.
547 if (!mesh.is_serial())
548 libmesh_deprecated();
549
550 nodes_to_elem_map.resize (mesh.max_node_id());
551
552 for (const auto & elem : mesh.element_ptr_range())
553 for (auto & node : elem->node_ref_range())
554 {
555 libmesh_assert_less (node.id(), nodes_to_elem_map.size());
556
557 nodes_to_elem_map[node.id()].push_back(elem);
558 }
559}
virtual bool is_serial() const
Definition mesh_base.h:365
virtual dof_id_type max_node_id() const =0

References libMesh::MeshBase::is_serial(), libMesh::MeshBase::max_node_id(), and mesh.

◆ build_nodes_to_elem_map() [4/4]

void libMesh::MeshTools::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 connectivity.

That is to say nodes_to_elem_map[i][j] is the global number of \( j^{th} \) element connected to node i.

Definition at line 520 of file mesh_tools.C.

522{
523 // A vector indexed over all nodes is too inefficient to use for a
524 // distributed mesh. Use the unordered_map API instead.
525 if (!mesh.is_serial())
526 libmesh_deprecated();
527
528 nodes_to_elem_map.resize (mesh.max_node_id());
529
530 for (const auto & elem : mesh.element_ptr_range())
531 for (auto & node : elem->node_ref_range())
532 {
533 libmesh_assert_less (node.id(), nodes_to_elem_map.size());
534 libmesh_assert_less (elem->id(), mesh.n_elem());
535
536 nodes_to_elem_map[node.id()].push_back(elem->id());
537 }
538}
virtual dof_id_type n_elem() const =0

References libMesh::MeshBase::is_serial(), libMesh::MeshBase::max_node_id(), mesh, and libMesh::MeshBase::n_elem().

Referenced by libMesh::VariationalSmootherConstraint::constrain(), NodalNeighborsTest::do_test(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::GenericProjector(), libMesh::MeshTools::Subdivision::prepare_subdivision_mesh(), libMesh::C0Polyhedron::retriangulate(), libMesh::Partitioner::set_interface_node_processor_ids_BFS(), libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner(), MeshSmootherTest::testVariationalSmoother(), and libMesh::Tree< N >::Tree().

◆ clear_spline_nodes()

void libMesh::MeshTools::clear_spline_nodes ( MeshBase &  mesh)

Remove spline node (for IsoGeometric Analysis meshes) elements and nodes and constraints from the mesh.

This should be done after the mesh is read but before the constraints are used by System initialization. The result is a mesh and solution space with lower required continuity and more unconstrained degrees of freedom, but with fewer total degrees of freedom and far fewer constraint equations.

Definition at line 1284 of file mesh_tools.C.

1285{
1286 std::vector<Elem *> nodeelem_to_delete;
1287
1288 for (auto & elem : mesh.element_ptr_range())
1289 if (elem->type() == NODEELEM &&
1290 elem->mapping_type() == RATIONAL_BERNSTEIN_MAP)
1291 nodeelem_to_delete.push_back(elem);
1292
1293 auto & constraint_rows = mesh.set_constraint_rows();
1294
1295 // All our constraint_rows ought to be for spline constraints we're
1296 // about to get rid of.
1297#ifndef NDEBUG
1298 for (auto & node_row : constraint_rows)
1299 for (auto pr : node_row.second)
1300 {
1301 const Elem * elem = pr.first.first;
1302 libmesh_assert(elem->type() == NODEELEM);
1304 }
1305#endif
1306
1307 constraint_rows.clear();
1308
1309 for (Elem * elem : nodeelem_to_delete)
1310 {
1311 Node * node = elem->node_ptr(0);
1312 mesh.delete_elem(elem);
1313 mesh.delete_node(node);
1314 }
1315}
This is the base class from which all geometric element types are derived.
Definition elem.h:96
ElemMappingType mapping_type() const
Definition elem.h:3258
virtual ElemType type() const =0
virtual void delete_node(Node *n)=0
Removes the Node n from the mesh.
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
constraint_rows_type & set_constraint_rows()
Definition mesh_base.h:2001
A Node is like a Point, but with more information.
Definition node.h:55
@ RATIONAL_BERNSTEIN_MAP
libmesh_assert(ctx)

References libMesh::MeshBase::delete_elem(), libMesh::MeshBase::delete_node(), libMesh::libmesh_assert(), libMesh::Elem::mapping_type(), mesh, libMesh::NODEELEM, libMesh::RATIONAL_BERNSTEIN_MAP, libMesh::MeshBase::set_constraint_rows(), and libMesh::Elem::type().

Referenced by libMesh::DynaIO::read_mesh().

◆ correct_node_proc_ids()

void libMesh::MeshTools::correct_node_proc_ids ( MeshBase &  mesh)

Changes the processor ids on each node so be the same as the id of the lowest element touching that node.

This corrects "orphaned" processor ids that may occur from element coarsening.

On a distributed mesh, this function must be called in parallel to sync everyone's corrected processor ids on ghost nodes.

Definition at line 2600 of file mesh_tools.C.

2601{
2602 LOG_SCOPE("correct_node_proc_ids()","MeshTools");
2603
2604 // This function must be run on all processors at once
2605 libmesh_parallel_only(mesh.comm());
2606
2607 // We require all processors to agree on nodal processor ids before
2608 // going into this algorithm.
2609#ifdef DEBUG
2610 libmesh_assert_parallel_consistent_procids<Node>(mesh);
2611#endif
2612
2613 // If we have any unpartitioned elements at this
2614 // stage there is a problem
2615 libmesh_assert (n_elem(mesh.unpartitioned_elements_begin(),
2616 mesh.unpartitioned_elements_end()) == 0);
2617
2618 // Fix nodes' processor ids. Coarsening may have left us with nodes
2619 // which are no longer touched by any elements of the same processor
2620 // id, and for DofMap to work we need to fix that.
2621
2622 // This is harder now that libMesh no longer requires a distributed
2623 // mesh to ghost all nodal neighbors: it is possible for two active
2624 // elements on two different processors to share the same node in
2625 // such a way that neither processor knows the others' element
2626 // exists!
2627
2628 // While we're at it, if this mesh is configured to allow
2629 // repartitioning, we'll repartition *all* the nodes' processor ids
2630 // using the canonical Node heuristic, to try and improve DoF load
2631 // balancing. But if the mesh is disallowing repartitioning, we
2632 // won't touch processor_id on any node where it's valid, regardless
2633 // of whether or not it's canonical.
2634 bool repartition_all_nodes = !mesh.skip_noncritical_partitioning();
2635 std::unordered_set<const Node *> valid_nodes;
2636
2637 // If we aren't allowed to repartition, then we're going to leave
2638 // every node we can at its current processor_id, and *only*
2639 // repartition the nodes whose current processor id is incompatible
2640 // with DoFMap (because it doesn't touch an active element, e.g. due
2641 // to coarsening)
2642 if (!repartition_all_nodes)
2643 {
2644 for (const auto & elem : mesh.active_element_ptr_range())
2645 for (const auto & node : elem->node_ref_range())
2646 if (elem->processor_id() == node.processor_id())
2647 valid_nodes.insert(&node);
2648
2649 SyncNodeSet syncv(valid_nodes, mesh);
2650
2652 (mesh.comm(), mesh.nodes_begin(), mesh.nodes_end(), syncv);
2653 }
2654
2655 // We build up a set of compatible processor ids for each node
2656 proc_id_map_type new_proc_ids;
2657
2658 for (auto & elem : mesh.active_element_ptr_range())
2659 {
2660 processor_id_type pid = elem->processor_id();
2661
2662 for (auto & node : elem->node_ref_range())
2663 {
2664 const dof_id_type id = node.id();
2665 if (auto it = new_proc_ids.find(id);
2666 it == new_proc_ids.end())
2667 new_proc_ids.emplace(id, pid);
2668 else
2669 it->second = node.choose_processor_id(it->second, pid);
2670 }
2671 }
2672
2673 // Sort the new pids to push to each processor
2674 std::map<processor_id_type, std::vector<std::pair<dof_id_type, processor_id_type>>>
2675 ids_to_push;
2676
2677 for (const auto & node : mesh.node_ptr_range())
2678 if (const auto it = std::as_const(new_proc_ids).find(node->id());
2679 it != new_proc_ids.end() && node->processor_id() != DofObject::invalid_processor_id)
2680 ids_to_push[node->processor_id()].emplace_back(node->id(), /*pid=*/it->second);
2681
2682 auto action_functor =
2683 [& mesh, & new_proc_ids]
2685 const std::vector<std::pair<dof_id_type, processor_id_type>> & data)
2686 {
2687 for (const auto & [id, pid] : data)
2688 {
2689 if (const auto it = new_proc_ids.find(id);
2690 it == new_proc_ids.end())
2691 new_proc_ids.emplace(id, pid);
2692 else
2693 {
2694 const Node & node = mesh.node_ref(id);
2695 it->second = node.choose_processor_id(it->second, pid);
2696 }
2697 }
2698 };
2699
2700 Parallel::push_parallel_vector_data
2701 (mesh.comm(), ids_to_push, action_functor);
2702
2703 // Now new_proc_ids is correct for every node we used to own. Let's
2704 // ask every other processor about the nodes they used to own. But
2705 // first we'll need to keep track of which nodes we used to own,
2706 // lest we get them confused with nodes we newly own.
2707 std::unordered_set<Node *> ex_local_nodes;
2708 for (auto & node : mesh.local_node_ptr_range())
2709 if (const auto it = new_proc_ids.find(node->id());
2710 it != new_proc_ids.end() && it->second != mesh.processor_id())
2711 ex_local_nodes.insert(node);
2712
2713 SyncProcIdsFromMap sync(new_proc_ids, mesh);
2714 if (repartition_all_nodes)
2716 (mesh.comm(), mesh.nodes_begin(), mesh.nodes_end(), sync);
2717 else
2718 {
2719 NodesNotInSet nnis(valid_nodes);
2720
2722 (mesh.comm(), mesh.nodes_begin(), mesh.nodes_end(), nnis, sync);
2723 }
2724
2725 // And finally let's update the nodes we used to own.
2726 for (const auto & node : ex_local_nodes)
2727 {
2728 if (valid_nodes.count(node))
2729 continue;
2730
2731 const dof_id_type id = node->id();
2732 const proc_id_map_type::iterator it = new_proc_ids.find(id);
2733 libmesh_assert(it != new_proc_ids.end());
2734 node->processor_id() = it->second;
2735 }
2736
2737 // We should still have consistent nodal processor ids coming out of
2738 // this algorithm, but if we're allowed to repartition the mesh then
2739 // they should be canonically correct too.
2740#ifdef DEBUG
2741 libmesh_assert_valid_procids<Node>(mesh);
2742 //if (repartition_all_nodes)
2743 // libmesh_assert_canonical_node_procids(mesh);
2744#endif
2745}
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition dof_object.h:484
virtual const Node & node_ref(const dof_id_type i) const
Definition mesh_base.h:750
void skip_noncritical_partitioning(bool skip)
If true is passed in then the elements on this mesh will no longer be (re)partitioned,...
Definition mesh_base.h:1430
processor_id_type choose_processor_id(processor_id_type pid1, processor_id_type pid2) const
Return which of pid1 and pid2 would be preferred by the current load-balancing heuristic applied to t...
Definition node.C:78
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
const proc_id_map_type & new_proc_ids
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).
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.
uint8_t dof_id_type
Definition id_types.h:67
uint8_t processor_id_type
Definition id_types.h:104

References libMesh::Node::choose_processor_id(), libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), libmesh_assert_parallel_consistent_procids< Node >(), mesh, n_elem(), new_proc_ids, libMesh::MeshBase::node_ref(), libMesh::ParallelObject::processor_id(), TIMPI::push_parallel_vector_data(), libMesh::MeshBase::skip_noncritical_partitioning(), and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), and libMesh::MeshBase::partition().

◆ create_bounding_box()

libMesh::BoundingBox libMesh::MeshTools::create_bounding_box ( const MeshBase &  mesh)
Returns
A BoundingBox that bounds the mesh.

Definition at line 630 of file mesh_tools.C.

631{
632 // This function must be run on all processors at once
633 libmesh_parallel_only(mesh.comm());
634
635 FindBBox find_bbox;
636
637 // Start with any unpartitioned elements we know about locally
639 mesh.pid_elements_end(DofObject::invalid_processor_id)),
640 find_bbox);
641
642 // And combine with our local elements
643 find_bbox.bbox().union_with(create_local_bounding_box(mesh));
644
645 // Compare the bounding boxes across processors
646 mesh.comm().min(find_bbox.min());
647 mesh.comm().max(find_bbox.max());
648
649 return find_bbox.bbox();
650}
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
The StoredRange class defines a contiguous, divisible set of objects.
libMesh::BoundingBox create_local_bounding_box(const MeshBase &mesh)
Definition mesh_tools.C:695
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.

References libMesh::ParallelObject::comm(), create_local_bounding_box(), libMesh::DofObject::invalid_processor_id, libMesh::Parallel::Communicator::max(), mesh, libMesh::Parallel::Communicator::min(), and libMesh::Threads::parallel_reduce().

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map(), bounding_sphere(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::MeshTetInterface::check_hull_integrity(), libMesh::MeshBase::get_info(), libMesh::PointLocatorTree::init(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), MeshGenerationTest::testBuildCube(), MeshGenerationTest::testBuildLine(), MeshGenerationTest::testBuildSquare(), libMesh::Tree< N >::Tree(), and libMesh::PostscriptIO::write().

◆ create_local_bounding_box()

libMesh::BoundingBox libMesh::MeshTools::create_local_bounding_box ( const MeshBase &  mesh)
Returns
Two points defining a cartesian box that bounds the elements belonging to the local processor.

Unlike the other bounding box creation functions, this does not need to be run in parallel, because this is the only function we can guarantee can be resolved with only local information.

Definition at line 695 of file mesh_tools.C.

696{
697 FindBBox find_bbox;
698
700 find_bbox);
701
702 return find_bbox.bbox();
703}
const ElemRange & active_local_element_stored_range()
Definition mesh_base.C:2098

References libMesh::MeshBase::active_local_element_stored_range(), mesh, and libMesh::Threads::parallel_reduce().

Referenced by create_bounding_box(), and libMesh::MeshBase::get_info().

◆ create_nodal_bounding_box()

libMesh::BoundingBox libMesh::MeshTools::create_nodal_bounding_box ( const MeshBase &  mesh)
Returns
Two points defining a cartesian box that bounds the nodes of the mesh.

In the case of curved elements, this box might not bound the elements of the mesh.

Definition at line 655 of file mesh_tools.C.

656{
657 // This function must be run on all processors at once
658 libmesh_parallel_only(mesh.comm());
659
660 FindBBox find_bbox;
661
662 // Start with any unpartitioned nodes we know about locally
665 find_bbox);
666
667 // Add our local nodes
668 Threads::parallel_reduce (ConstNodeRange (mesh.local_nodes_begin(),
669 mesh.local_nodes_end()),
670 find_bbox);
671
672 // Compare the bounding boxes across processors
673 mesh.comm().min(find_bbox.min());
674 mesh.comm().max(find_bbox.max());
675
676 return find_bbox.bbox();
677}

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::Parallel::Communicator::max(), mesh, libMesh::Parallel::Communicator::min(), and libMesh::Threads::parallel_reduce().

Referenced by libMesh::MeshCommunication::assign_global_indices(), libMesh::MeshCommunication::check_for_duplicate_global_indices(), libMesh::LocationMap< T >::init(), MeshGenerationTest::testBuildCube(), and MeshGenerationTest::testBuildSquare().

◆ create_processor_bounding_box()

libMesh::BoundingBox libMesh::MeshTools::create_processor_bounding_box ( const MeshBase &  mesh,
const processor_id_type  pid 
)
Returns
A BoundingBox that bounds the elements belonging to processor pid.

Definition at line 708 of file mesh_tools.C.

710{
711 // This can only be run in parallel, with consistent arguments.
712 libmesh_parallel_only(mesh.comm());
714
715 libmesh_assert_less (pid, mesh.n_processors());
716
717 FindBBox find_bbox;
718
719 Threads::parallel_reduce (ConstElemRange (mesh.pid_elements_begin(pid),
720 mesh.pid_elements_end(pid)),
721 find_bbox);
722
723 // Compare the bounding boxes across processors
724 mesh.comm().min(find_bbox.min());
725 mesh.comm().max(find_bbox.max());
726
727 return find_bbox.bbox();
728}
timpi_pure bool verify(const T &r) const
processor_id_type n_processors() const

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), mesh, libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::Threads::parallel_reduce(), and libMesh::Parallel::Communicator::verify().

Referenced by processor_bounding_sphere().

◆ create_subdomain_bounding_box()

libMesh::BoundingBox libMesh::MeshTools::create_subdomain_bounding_box ( const MeshBase &  mesh,
const subdomain_id_type  sid 
)
Returns
A BoundingBox that bounds the elements belonging to subdomain sid.

Definition at line 748 of file mesh_tools.C.

750{
751 // This can only be run in parallel, with consistent arguments.
752 libmesh_parallel_only(mesh.comm());
754
755 FindBBox find_bbox;
756
758 (ConstElemRange (mesh.active_local_subdomain_elements_begin(sid),
759 mesh.active_local_subdomain_elements_end(sid)),
760 find_bbox);
761
762 // Compare the bounding boxes across processors
763 mesh.comm().min(find_bbox.min());
764 mesh.comm().max(find_bbox.max());
765
766 return find_bbox.bbox();
767}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), mesh, libMesh::Parallel::Communicator::min(), libMesh::Threads::parallel_reduce(), and libMesh::Parallel::Communicator::verify().

Referenced by subdomain_bounding_sphere().

◆ elem_types()

void libMesh::MeshTools::elem_types ( const MeshBase &  mesh,
std::vector< ElemType > &  et 
)

Fills in a vector of all element types in the mesh.

Implemented in terms of element_iterators.

Definition at line 786 of file mesh_tools.C.

788{
789 // Loop over the the elements. If the current element type isn't in
790 // the vector, insert it.
791 for (const auto & elem : mesh.element_ptr_range())
792 if (!std::count(et.begin(), et.end(), elem->type()))
793 et.push_back(elem->type());
794}

References mesh.

◆ find_block_boundary_nodes()

std::unordered_set< dof_id_type > libMesh::MeshTools::find_block_boundary_nodes ( const MeshBase &  mesh)

Returns a std::set containing Node IDs for all of the block boundary nodes.

A "block boundary node" is a node that is connected to elements from 2 or more blocks

Definition at line 608 of file mesh_tools.C.

609{
610 std::unordered_set<dof_id_type> block_boundary_nodes;
611
612 // Loop over elements, find those on boundary, and
613 // mark them as true in on_boundary.
614 for (const auto & elem : mesh.active_element_ptr_range())
615 for (auto s : elem->side_index_range())
616 if (elem->neighbor_ptr(s) && (elem->neighbor_ptr(s)->subdomain_id() != elem->subdomain_id()))
617 {
618 auto nodes_on_side = elem->nodes_on_side(s);
619
620 for (auto & local_id : nodes_on_side)
621 block_boundary_nodes.insert(elem->node_ptr(local_id)->id());
622 }
623
624 return block_boundary_nodes;
625}

References mesh.

Referenced by libMesh::LaplaceMeshSmoother::smooth().

◆ find_boundary_nodes()

std::unordered_set< dof_id_type > libMesh::MeshTools::find_boundary_nodes ( const MeshBase &  mesh)

Returns a std::set containing Node IDs for all of the boundary nodes.

Definition at line 588 of file mesh_tools.C.

589{
590 std::unordered_set<dof_id_type> boundary_nodes;
591
592 // Loop over elements, find those on boundary, and
593 // mark them as true in on_boundary.
594 for (const auto & elem : mesh.active_element_ptr_range())
595 for (auto s : elem->side_index_range())
596 if (elem->neighbor_ptr(s) == nullptr) // on the boundary
597 {
598 auto nodes_on_side = elem->nodes_on_side(s);
599
600 for (auto & local_id : nodes_on_side)
601 boundary_nodes.insert(elem->node_ptr(local_id)->id());
602 }
603
604 return boundary_nodes;
605}

References mesh.

Referenced by libMesh::VariationalSmootherConstraint::constrain(), libMesh::MeshTools::Modification::distort(), DistortTest::perturb_and_check(), libMesh::LaplaceMeshSmoother::smooth(), and libMesh::MeshTools::Modification::smooth().

◆ find_hanging_nodes_and_parents()

void libMesh::MeshTools::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 the hanging nodes in the mesh.

It will hold an array of the parents of the node (meaning the two nodes to either side of it that make up the side the hanging node is on.

Definition at line 1196 of file mesh_tools.C.

1198{
1199 // Loop through all the elements
1200 for (auto & elem : mesh.active_local_element_ptr_range())
1201 if (elem->type() == QUAD4)
1202 for (auto s : elem->side_index_range())
1203 {
1204 // Loop over the sides looking for sides that have hanging nodes
1205 // This code is inspired by compute_proj_constraints()
1206 const Elem * neigh = elem->neighbor_ptr(s);
1207
1208 // If not a boundary side
1209 if (neigh != nullptr)
1210 {
1211 // Is there a coarser element next to this one?
1212 if (neigh->level() < elem->level())
1213 {
1214 const Elem * ancestor = elem;
1215 while (neigh->level() < ancestor->level())
1216 ancestor = ancestor->parent();
1217 unsigned int s_neigh = neigh->which_neighbor_am_i(ancestor);
1218 libmesh_assert_less (s_neigh, neigh->n_neighbors());
1219
1220 // Couple of helper uints...
1221 unsigned int local_node1=0;
1222 unsigned int local_node2=0;
1223
1224 bool found_in_neighbor = false;
1225
1226 // Find the two vertices that make up this side
1227 while (!elem->is_node_on_side(local_node1++,s)) { }
1228 local_node1--;
1229
1230 // Start looking for the second one with the next node
1231 local_node2=local_node1+1;
1232
1233 // Find the other one
1234 while (!elem->is_node_on_side(local_node2++,s)) { }
1235 local_node2--;
1236
1237 //Pull out their global ids:
1238 dof_id_type node1 = elem->node_id(local_node1);
1239 dof_id_type node2 = elem->node_id(local_node2);
1240
1241 // Now find which node is present in the neighbor
1242 // FIXME This assumes a level one rule!
1243 // The _other_ one is the hanging node
1244
1245 // First look for the first one
1246 // FIXME could be streamlined a bit
1247 for (unsigned int n=0;n<neigh->n_sides();n++)
1248 if (neigh->node_id(n) == node1)
1249 found_in_neighbor=true;
1250
1251 dof_id_type hanging_node=0;
1252
1253 if (!found_in_neighbor)
1254 hanging_node=node1;
1255 else // If it wasn't node1 then it must be node2!
1256 hanging_node=node2;
1257
1258 // Reset for reuse
1259 local_node1=0;
1260
1261 // Find the first node that makes up the side in the neighbor (these should be the parent nodes)
1262 while (!neigh->is_node_on_side(local_node1++,s_neigh)) { }
1263 local_node1--;
1264
1265 local_node2=local_node1+1;
1266
1267 // Find the second node...
1268 while (!neigh->is_node_on_side(local_node2++,s_neigh)) { }
1269 local_node2--;
1270
1271 // Save them if we haven't already found the parents for this one
1272 if (hanging_nodes[hanging_node].size()<2)
1273 {
1274 hanging_nodes[hanging_node].push_back(neigh->node_id(local_node1));
1275 hanging_nodes[hanging_node].push_back(neigh->node_id(local_node2));
1276 }
1277 }
1278 }
1279 }
1280}
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const =0
const Elem * parent() const
Definition elem.h:3168
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition elem.h:3057
unsigned int n_neighbors() const
Definition elem.h:812
unsigned int level() const
Definition elem.h:3212
virtual unsigned int n_sides() const =0
dof_id_type node_id(const unsigned int i) const
Definition elem.h:2605
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736

References libMesh::Elem::is_node_on_side(), libMesh::Elem::level(), mesh, libMesh::Elem::n_neighbors(), libMesh::Elem::n_sides(), libMesh::Elem::neighbor_ptr(), libMesh::Elem::node_id(), libMesh::Elem::parent(), libMesh::QUAD4, and libMesh::Elem::which_neighbor_am_i().

◆ find_nodal_neighbors() [1/2]

void libMesh::MeshTools::find_nodal_neighbors ( const MeshBase &  mesh,
const Node &  n,
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 the given one.

Definition at line 1145 of file mesh_tools.C.

1149{
1150 const std::vector<const Elem *> node_to_elem_vec =
1151 libmesh_map_find(nodes_to_elem_map, node.id());
1152 find_nodal_neighbors_helper(node.id(), node_to_elem_vec, neighbors);
1153}

References libMesh::DofObject::id().

◆ find_nodal_neighbors() [2/2]

void libMesh::MeshTools::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 the given one.

Definition at line 1134 of file mesh_tools.C.

1138{
1139 find_nodal_neighbors_helper(node.id(), nodes_to_elem_map[node.id()],
1140 neighbors);
1141}

References libMesh::DofObject::id().

Referenced by NodalNeighborsTest::do_test(), find_nodal_or_face_neighbors(), libMesh::MeshTools::Subdivision::prepare_subdivision_mesh(), libMesh::Partitioner::set_interface_node_processor_ids_BFS(), and libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner().

◆ find_nodal_or_face_neighbors()

void libMesh::MeshTools::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 the given one.

IF NO nodal neighbors are found, all nodes on the containing side are treated as neighbors. This is useful when the node does not lie on an edge, such as the central face node in HEX27, TET14, etc. elements.

Definition at line 1155 of file mesh_tools.C.

1160{
1161 // Find all the nodal neighbors... that is the nodes directly connected
1162 // to this node through one edge.
1163 find_nodal_neighbors(mesh, node, nodes_to_elem_map, neighbors);
1164
1165 // If no neighbors are found, use all nodes on the containing side as
1166 // neighbors.
1167 if (!neighbors.size())
1168 {
1169 // Grab the element containing node
1170 const auto * elem = libmesh_map_find(nodes_to_elem_map, node.id()).front();
1171 // Find the element side containing node
1172 for (const auto &side : elem->side_index_range())
1173 {
1174 const auto &nodes_on_side = elem->nodes_on_side(side);
1175 const auto it =
1176 std::find_if(nodes_on_side.begin(), nodes_on_side.end(), [&](auto local_node_id) {
1177 return elem->node_id(local_node_id) == node.id();
1178 });
1179
1180 if (it != nodes_on_side.end())
1181 {
1182 for (const auto &local_node_id : nodes_on_side)
1183 // No need to add node itself as a neighbor
1184 if (const auto *node_ptr = elem->node_ptr(local_node_id);
1185 *node_ptr != node)
1186 neighbors.push_back(node_ptr);
1187 break;
1188 }
1189 }
1190 }
1191 libmesh_assert(neighbors.size());
1192}
dof_id_type id() const
Definition dof_object.h:833
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...

References find_nodal_neighbors(), libMesh::DofObject::id(), libMesh::libmesh_assert(), and mesh.

Referenced by libMesh::VariationalSmootherConstraint::get_neighbors_for_boundary_constraint(), libMesh::VariationalSmootherConstraint::get_neighbors_for_subdomain_constraint(), and MeshSmootherTest::testVariationalSmoother().

◆ get_not_subactive_node_ids()

void libMesh::MeshTools::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.

Non-subactive elements are those which are either active or inactive. This is useful for determining which nodes should be written to a data file, and is used by the XDA mesh writing methods.

Definition at line 1056 of file mesh_tools.C.

1058{
1059 for (const auto & elem : mesh.element_ptr_range())
1060 if (!elem->subactive())
1061 for (auto & n : elem->node_ref_range())
1062 not_subactive_node_ids.insert(n.id());
1063}

References mesh.

◆ libmesh_assert_canonical_node_procids()

void libMesh::MeshTools::libmesh_assert_canonical_node_procids ( const MeshBase &  mesh)
inline

A function for verifying that processor assignment of nodes matches the heuristic specified in Node::choose_processor_id()

Definition at line 683 of file mesh_tools.h.

683{}

◆ libmesh_assert_connected_nodes()

void libMesh::MeshTools::libmesh_assert_connected_nodes ( const MeshBase &  mesh)

A function for verifying that all nodes are connected to at least one element.

This will fail in the most general case. When DistributedMesh and NodeConstraints are enabled, we expect the possibility that a processor will be given remote nodes to satisfy node constraints without also being given the remote elements connected to those nodes.

Definition at line 1814 of file mesh_tools.C.

1815{
1816 LOG_SCOPE("libmesh_assert_connected_nodes()", "MeshTools");
1817
1818 std::set<const Node *> used_nodes;
1819
1820 for (const auto & elem : mesh.element_ptr_range())
1821 {
1822 libmesh_assert (elem);
1823
1824 for (auto & n : elem->node_ref_range())
1825 used_nodes.insert(&n);
1826 }
1827
1828 for (const auto & node : mesh.node_ptr_range())
1829 {
1830 libmesh_assert(node);
1831 libmesh_assert(used_nodes.count(node));
1832 }
1833}

References libMesh::libmesh_assert(), and mesh.

◆ libmesh_assert_consistent_distributed()

void libMesh::MeshTools::libmesh_assert_consistent_distributed ( const MeshBase &  mesh)

A function for verifying that distribution of dof objects is parallel consistent (every processor can see every node or element it owns)

Definition at line 2161 of file mesh_tools.C.

2162{
2163 libmesh_parallel_only(mesh.comm());
2164
2165 dof_id_type parallel_max_elem_id = mesh.max_elem_id();
2166 mesh.comm().max(parallel_max_elem_id);
2167
2168 for (dof_id_type i=0; i != parallel_max_elem_id; ++i)
2169 {
2170 const Elem * elem = mesh.query_elem_ptr(i);
2171 processor_id_type pid =
2173 mesh.comm().min(pid);
2174 libmesh_assert(elem || pid != mesh.processor_id());
2175 }
2176
2177 dof_id_type parallel_max_node_id = mesh.max_node_id();
2178 mesh.comm().max(parallel_max_node_id);
2179
2180 for (dof_id_type i=0; i != parallel_max_node_id; ++i)
2181 {
2182 const Node * node = mesh.query_node_ptr(i);
2183 processor_id_type pid =
2185 mesh.comm().min(pid);
2186 libmesh_assert(node || pid != mesh.processor_id());
2187 }
2188}
processor_id_type processor_id() const
Definition dof_object.h:895
virtual const Node * query_node_ptr(const dof_id_type i) const =0
virtual dof_id_type max_elem_id() const =0
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMesh::Parallel::Communicator::min(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), and libMesh::MeshBase::query_node_ptr().

◆ libmesh_assert_consistent_distributed_nodes()

void libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes ( const MeshBase &  mesh)

A function for verifying that distribution of nodes is parallel consistent (every processor can see every node it owns) even before node ids have been made consistent.

Definition at line 2191 of file mesh_tools.C.

2192{
2193 libmesh_parallel_only(mesh.comm());
2194 auto locator = mesh.sub_point_locator();
2195
2196 dof_id_type parallel_max_elem_id = mesh.max_elem_id();
2197 mesh.comm().max(parallel_max_elem_id);
2198
2199 for (dof_id_type i=0; i != parallel_max_elem_id; ++i)
2200 {
2201 const Elem * elem = mesh.query_elem_ptr(i);
2202
2203 const unsigned int my_n_nodes = elem ? elem->n_nodes() : 0;
2204 unsigned int n_nodes = my_n_nodes;
2205 mesh.comm().max(n_nodes);
2206
2207 if (n_nodes)
2208 libmesh_assert(mesh.comm().semiverify(elem ? &my_n_nodes : nullptr));
2209
2210 for (unsigned int n=0; n != n_nodes; ++n)
2211 {
2212 const Node * node = elem ? elem->node_ptr(n) : nullptr;
2213 processor_id_type pid =
2215 mesh.comm().min(pid);
2216 libmesh_assert(node || pid != mesh.processor_id());
2217 }
2218 }
2219}
timpi_pure bool semiverify(const T *r) const
virtual unsigned int n_nodes() const =0
const Node * node_ptr(const unsigned int i) const
Definition elem.h:2637
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition mesh_base.C:1952
const dof_id_type n_nodes
Definition tecplot_io.C:67

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Parallel::Communicator::min(), libMesh::Elem::n_nodes(), n_nodes, libMesh::Elem::node_ptr(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), libMesh::Parallel::Communicator::semiverify(), and libMesh::MeshBase::sub_point_locator().

◆ libmesh_assert_contiguous_dof_ids()

void libMesh::MeshTools::libmesh_assert_contiguous_dof_ids ( const MeshBase &  mesh,
unsigned int  sysnum 
)
inline

A function for verifying that degree of freedom indexes are contiguous on each processor, as is required by libMesh numeric classes.

Verify a particular system by specifying that system's number.

Definition at line 678 of file mesh_tools.h.

678{}

◆ libmesh_assert_equal_connectivity()

void libMesh::MeshTools::libmesh_assert_equal_connectivity ( const MeshBase &  mesh)

A function for testing that element nodal connectivities match across processors.

Definition at line 1793 of file mesh_tools.C.

1794{
1795 LOG_SCOPE("libmesh_assert_equal_connectivity()", "MeshTools");
1796
1797 dof_id_type pmax_elem_id = mesh.max_elem_id();
1798 mesh.comm().max(pmax_elem_id);
1799
1800 for (dof_id_type i=0; i != pmax_elem_id; ++i)
1801 {
1802 const Elem * e = mesh.query_elem_ptr(i);
1803
1804 std::vector<dof_id_type> nodes;
1805 if (e)
1806 for (auto n : e->node_index_range())
1807 nodes.push_back(e->node_id(n));
1808
1809 libmesh_assert(mesh.comm().semiverify(e ? &nodes : nullptr));
1810 }
1811}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Elem::node_id(), libMesh::Elem::node_index_range(), libMesh::MeshBase::query_elem_ptr(), and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::MeshCommunication::assign_global_indices(), and libMesh::SimplexRefiner::refine_via_edges().

◆ libmesh_assert_equal_n_systems()

void libMesh::MeshTools::libmesh_assert_equal_n_systems ( const MeshBase &  mesh)
inline

A function for testing that all DofObjects within a mesh have the same n_systems count.

Definition at line 664 of file mesh_tools.h.

664{}

◆ libmesh_assert_equal_points()

void libMesh::MeshTools::libmesh_assert_equal_points ( const MeshBase &  mesh)

A function for testing that node locations match across processors.

Definition at line 1777 of file mesh_tools.C.

1778{
1779 LOG_SCOPE("libmesh_assert_equal_points()", "MeshTools");
1780
1781 dof_id_type pmax_node_id = mesh.max_node_id();
1782 mesh.comm().max(pmax_node_id);
1783
1784 for (dof_id_type i=0; i != pmax_node_id; ++i)
1785 {
1786 const Point * p = mesh.query_node_ptr(i);
1787
1789 }
1790}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshBase::query_node_ptr(), and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::MeshCommunication::assign_global_indices(), and libMesh::SimplexRefiner::refine_via_edges().

◆ libmesh_assert_no_links_to_elem()

void libMesh::MeshTools::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 slow asymptotic behavior, and so are unsuitable for use even with METHOD=devel.

A function for verifying that an element has been cut off from the rest of the mesh

Definition at line 1758 of file mesh_tools.C.

1760{
1761 for (const auto & elem : mesh.element_ptr_range())
1762 {
1763 libmesh_assert (elem);
1764 libmesh_assert_not_equal_to (elem->parent(), bad_elem);
1765 for (auto n : elem->neighbor_ptr_range())
1766 libmesh_assert_not_equal_to (n, bad_elem);
1767
1768#ifdef LIBMESH_ENABLE_AMR
1769 if (elem->has_children())
1770 for (auto & child : elem->child_ref_range())
1771 libmesh_assert_not_equal_to (&child, bad_elem);
1772#endif
1773 }
1774}

References libMesh::libmesh_assert(), and mesh.

◆ libmesh_assert_old_dof_objects()

void libMesh::MeshTools::libmesh_assert_old_dof_objects ( const MeshBase &  mesh)
inline

A function for testing that all non-recently-created DofObjects within a mesh have old_dof_object data.

This is not expected to be true at all points within a simulation code.

Definition at line 666 of file mesh_tools.h.

666{}

◆ libmesh_assert_parallel_consistent_new_node_procids()

void libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids ( const MeshBase &  mesh)

A function for verifying that processor assignment is parallel consistent (every processor agrees on the processor id of each node it can see) even on nodes which have not yet received consistent DofObject::id(), using element topology to identify matching nodes.

Definition at line 2272 of file mesh_tools.C.

2273{
2274 LOG_SCOPE("libmesh_assert_parallel_consistent_new_node_procids()", "MeshTools");
2275
2276 if (mesh.n_processors() == 1)
2277 return;
2278
2279 libmesh_parallel_only(mesh.comm());
2280
2281 // We want this test to hit every node when called even after nodes
2282 // have been added asynchronously but before everything has been
2283 // renumbered.
2284 dof_id_type parallel_max_elem_id = mesh.max_elem_id();
2285 mesh.comm().max(parallel_max_elem_id);
2286
2287 std::vector<bool> elem_touched_by_anyone(parallel_max_elem_id, false);
2288
2289 for (dof_id_type i=0; i != parallel_max_elem_id; ++i)
2290 {
2291 const Elem * elem = mesh.query_elem_ptr(i);
2292
2293 const unsigned int my_n_nodes = elem ? elem->n_nodes() : 0;
2294 unsigned int n_nodes = my_n_nodes;
2295 mesh.comm().max(n_nodes);
2296
2297 if (n_nodes)
2298 libmesh_assert(mesh.comm().semiverify(elem ? &my_n_nodes : nullptr));
2299
2300 for (unsigned int n=0; n != n_nodes; ++n)
2301 {
2302 const Node * node = elem ? elem->node_ptr(n) : nullptr;
2303 const processor_id_type pid = node ? node->processor_id() : 0;
2304 libmesh_assert(mesh.comm().semiverify (node ? &pid : nullptr));
2305 }
2306 }
2307}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Elem::n_nodes(), n_nodes, libMesh::ParallelObject::n_processors(), libMesh::Elem::node_ptr(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent().

◆ libmesh_assert_parallel_consistent_procids()

template<typename DofObjectSubclass >
void libMesh::MeshTools::libmesh_assert_parallel_consistent_procids ( const MeshBase &  mesh)

A function for verifying that processor assignment is parallel consistent (every processor agrees on the processor id of each dof object it can see)

◆ libmesh_assert_parallel_consistent_procids< Elem >()

Definition at line 2224 of file mesh_tools.C.

2225{
2226 LOG_SCOPE("libmesh_assert_parallel_consistent_procids()", "MeshTools");
2227
2228 if (mesh.n_processors() == 1)
2229 return;
2230
2231 libmesh_parallel_only(mesh.comm());
2232
2233 // Some code (looking at you, stitch_meshes) modifies DofObject ids
2234 // without keeping max_elem_id()/max_node_id() consistent, but
2235 // that's done in a safe way for performance reasons, so we'll play
2236 // along and just figure out new max ids ourselves.
2237 dof_id_type parallel_max_elem_id = 0;
2238 for (const auto & elem : mesh.element_ptr_range())
2239 parallel_max_elem_id = std::max<dof_id_type>(parallel_max_elem_id,
2240 elem->id()+1);
2241 mesh.comm().max(parallel_max_elem_id);
2242
2243 // Check processor ids for consistency between processors
2244
2245 for (dof_id_type i=0; i != parallel_max_elem_id; ++i)
2246 {
2247 const Elem * elem = mesh.query_elem_ptr(i);
2248
2249 processor_id_type min_id =
2250 elem ? elem->processor_id() :
2251 std::numeric_limits<processor_id_type>::max();
2252 mesh.comm().min(min_id);
2253
2254 processor_id_type max_id =
2255 elem ? elem->processor_id() :
2256 std::numeric_limits<processor_id_type>::min();
2257 mesh.comm().max(max_id);
2258
2259 if (elem)
2260 {
2261 libmesh_assert_equal_to (min_id, elem->processor_id());
2262 libmesh_assert_equal_to (max_id, elem->processor_id());
2263 }
2264
2265 if (min_id == mesh.processor_id())
2266 libmesh_assert(elem);
2267 }
2268}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), mesh, libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), and libMesh::MeshBase::query_elem_ptr().

◆ libmesh_assert_parallel_consistent_procids< Node >()

Definition at line 2310 of file mesh_tools.C.

2311{
2312 LOG_SCOPE("libmesh_assert_parallel_consistent_procids()", "MeshTools");
2313
2314 if (mesh.n_processors() == 1)
2315 return;
2316
2317 libmesh_parallel_only(mesh.comm());
2318
2319 // We want this test to be valid even when called even after nodes
2320 // have been added asynchronously but before they're renumbered
2321 //
2322 // Plus, some code (looking at you, stitch_meshes) modifies
2323 // DofObject ids without keeping max_elem_id()/max_node_id()
2324 // consistent, but that's done in a safe way for performance
2325 // reasons, so we'll play along and just figure out new max ids
2326 // ourselves.
2327 dof_id_type parallel_max_node_id = 0;
2328 for (const auto & node : mesh.node_ptr_range())
2329 parallel_max_node_id = std::max<dof_id_type>(parallel_max_node_id,
2330 node->id()+1);
2331 mesh.comm().max(parallel_max_node_id);
2332
2333 std::vector<bool> node_touched_by_anyone(parallel_max_node_id, false);
2334
2335 for (const auto & elem : as_range(mesh.local_elements_begin(),
2336 mesh.local_elements_end()))
2337 {
2338 libmesh_assert (elem);
2339
2340 for (auto & node : elem->node_ref_range())
2341 {
2342 dof_id_type nodeid = node.id();
2343 node_touched_by_anyone[nodeid] = true;
2344 }
2345 }
2346 mesh.comm().max(node_touched_by_anyone);
2347
2348 // Check processor ids for consistency between processors
2349 // on any node an element touches
2350 for (dof_id_type i=0; i != parallel_max_node_id; ++i)
2351 {
2352 if (!node_touched_by_anyone[i])
2353 continue;
2354
2355 const Node * node = mesh.query_node_ptr(i);
2356 const processor_id_type pid = node ? node->processor_id() : 0;
2357
2358 libmesh_assert(mesh.comm().semiverify (node ? &pid : nullptr));
2359 }
2360}
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), mesh, libMesh::ParallelObject::n_processors(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_node_ptr(), and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::UnstructuredMesh::copy_nodes_and_elements(), correct_node_proc_ids(), and libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent().

◆ libmesh_assert_topology_consistent_procids()

template<typename DofObjectSubclass >
void libMesh::MeshTools::libmesh_assert_topology_consistent_procids ( const MeshBase &  mesh)
inline

A function for verifying that processor assignment is topologically consistent on nodes (each node part of an active element on its processor) or elements (each parent has the processor id of one of its children).

Definition at line 681 of file mesh_tools.h.

681{}

◆ libmesh_assert_topology_consistent_procids< Elem >()

Definition at line 1611 of file mesh_tools.C.

1612{
1613 LOG_SCOPE("libmesh_assert_topology_consistent_procids()", "MeshTools");
1614
1615 // This parameter is not used when !LIBMESH_ENABLE_AMR
1617
1618 // If we're adaptively refining, check processor ids for consistency
1619 // between parents and children.
1620#ifdef LIBMESH_ENABLE_AMR
1621
1622 // Ancestor elements we won't worry about, but subactive and active
1623 // elements ought to have parents with consistent processor ids
1624 for (const auto & elem : mesh.element_ptr_range())
1625 {
1626 libmesh_assert(elem);
1627
1628 if (!elem->active() && !elem->subactive())
1629 continue;
1630
1631 const Elem * parent = elem->parent();
1632
1633 if (parent)
1634 {
1635 libmesh_assert(parent->has_children());
1636 processor_id_type parent_procid = parent->processor_id();
1637 bool matching_child_id = false;
1638 // If we've got a remote_elem then we don't know whether
1639 // it's responsible for the parent's processor id; all
1640 // we can do is assume it is and let its processor fail
1641 // an assert if there's something wrong.
1642 for (auto & child : parent->child_ref_range())
1643 if (&child == remote_elem ||
1644 child.processor_id() == parent_procid)
1645 matching_child_id = true;
1646 libmesh_assert(matching_child_id);
1647 }
1648 }
1649#endif
1650}
bool has_children() const
Definition elem.h:3117
void libmesh_ignore(const Args &...)
const RemoteElem * remote_elem
Definition remote_elem.C:57

References libMesh::Elem::child_ref_range(), libMesh::Elem::has_children(), libMesh::libmesh_assert(), libMesh::libmesh_ignore(), mesh, libMesh::Elem::parent(), libMesh::DofObject::processor_id(), and libMesh::remote_elem.

◆ libmesh_assert_topology_consistent_procids< Node >()

Definition at line 1655 of file mesh_tools.C.

1656{
1657 LOG_SCOPE("libmesh_assert_topology_consistent_procids()", "MeshTools");
1658
1659 if (mesh.n_processors() == 1)
1660 return;
1661
1662 libmesh_parallel_only(mesh.comm());
1663
1664 // We want this test to be valid even when called after nodes have
1665 // been added asynchronously but before they're renumbered.
1666 //
1667 // Plus, some code (looking at you, stitch_meshes) modifies
1668 // DofObject ids without keeping max_elem_id()/max_node_id()
1669 // consistent, but that's done in a safe way for performance
1670 // reasons, so we'll play along and just figure out new max ids
1671 // ourselves.
1672 dof_id_type parallel_max_node_id = 0;
1673 for (const auto & node : mesh.node_ptr_range())
1674 parallel_max_node_id = std::max<dof_id_type>(parallel_max_node_id,
1675 node->id()+1);
1676 mesh.comm().max(parallel_max_node_id);
1677
1678
1679 std::vector<bool> node_touched_by_me(parallel_max_node_id, false);
1680
1681 for (const auto & elem : as_range(mesh.local_elements_begin(),
1682 mesh.local_elements_end()))
1683 {
1684 libmesh_assert (elem);
1685
1686 for (auto & node : elem->node_ref_range())
1687 {
1688 dof_id_type nodeid = node.id();
1689 node_touched_by_me[nodeid] = true;
1690 }
1691 }
1692 std::vector<bool> node_touched_by_anyone(node_touched_by_me);
1693 mesh.comm().max(node_touched_by_anyone);
1694
1695 for (const auto & node : mesh.local_node_ptr_range())
1696 {
1697 libmesh_assert(node);
1698 dof_id_type nodeid = node->id();
1699 libmesh_assert(!node_touched_by_anyone[nodeid] ||
1700 node_touched_by_me[nodeid]);
1701 }
1702}

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), mesh, and libMesh::ParallelObject::n_processors().

Referenced by libMesh::MeshCommunication::make_node_ids_parallel_consistent().

◆ libmesh_assert_valid_amr_elem_ids()

void libMesh::MeshTools::libmesh_assert_valid_amr_elem_ids ( const MeshBase &  mesh)
inline

A function for verifying that ids of elements are correctly sorted for AMR (parents have lower ids than children)

Definition at line 674 of file mesh_tools.h.

674{}

Referenced by libMesh::UnstructuredMesh::copy_nodes_and_elements().

◆ libmesh_assert_valid_amr_interior_parents()

void libMesh::MeshTools::libmesh_assert_valid_amr_interior_parents ( const MeshBase &  mesh)
inline

A function for verifying that any interior_parent pointers on elements are consistent with AMR (parents' interior_parents are interior_parents' parents)

Definition at line 676 of file mesh_tools.h.

676{}

Referenced by libMesh::UnstructuredMesh::find_neighbors().

◆ libmesh_assert_valid_boundary_ids()

void libMesh::MeshTools::libmesh_assert_valid_boundary_ids ( const MeshBase &  mesh)

A function for verifying that boundary condition ids match across processors.

Definition at line 1880 of file mesh_tools.C.

1881{
1882 LOG_SCOPE("libmesh_assert_valid_boundary_ids()", "MeshTools");
1883
1884 if (mesh.n_processors() == 1)
1885 return;
1886
1887 libmesh_parallel_only(mesh.comm());
1888
1889 const BoundaryInfo & boundary_info = mesh.get_boundary_info();
1890
1891 dof_id_type pmax_elem_id = mesh.max_elem_id();
1892 mesh.comm().max(pmax_elem_id);
1893
1894 for (dof_id_type i=0; i != pmax_elem_id; ++i)
1895 {
1896 const Elem * elem = mesh.query_elem_ptr(i);
1897 const unsigned int my_n_nodes = elem ? elem->n_nodes() : 0;
1898 const unsigned int my_n_edges = elem ? elem->n_edges() : 0;
1899 const unsigned int my_n_sides = elem ? elem->n_sides() : 0;
1900 unsigned int
1901 n_nodes = my_n_nodes,
1902 n_edges = my_n_edges,
1903 n_sides = my_n_sides;
1904
1905 mesh.comm().max(n_nodes);
1906 mesh.comm().max(n_edges);
1907 mesh.comm().max(n_sides);
1908
1909 if (elem)
1910 {
1911 libmesh_assert_equal_to(my_n_nodes, n_nodes);
1912 libmesh_assert_equal_to(my_n_edges, n_edges);
1913 libmesh_assert_equal_to(my_n_sides, n_sides);
1914 }
1915
1916 // Let's test all IDs on the element with one communication
1917 // rather than n_nodes + n_edges + n_sides communications, to
1918 // cut down on latency in dbg modes.
1919 std::vector<boundary_id_type> all_bcids;
1920
1921 for (unsigned int n=0; n != n_nodes; ++n)
1922 {
1923 std::vector<boundary_id_type> bcids;
1924 if (elem)
1925 {
1926 boundary_info.boundary_ids(elem->node_ptr(n), bcids);
1927
1928 // Ordering of boundary ids shouldn't matter
1929 std::sort(bcids.begin(), bcids.end());
1930 }
1931 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
1932
1933 all_bcids.insert(all_bcids.end(), bcids.begin(),
1934 bcids.end());
1935 // Separator
1936 all_bcids.push_back(BoundaryInfo::invalid_id);
1937 }
1938
1939 for (unsigned short e=0; e != n_edges; ++e)
1940 {
1941 std::vector<boundary_id_type> bcids;
1942
1943 if (elem)
1944 {
1945 boundary_info.edge_boundary_ids(elem, e, bcids);
1946
1947 // Ordering of boundary ids shouldn't matter
1948 std::sort(bcids.begin(), bcids.end());
1949 }
1950
1951 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
1952
1953 all_bcids.insert(all_bcids.end(), bcids.begin(),
1954 bcids.end());
1955 // Separator
1956 all_bcids.push_back(BoundaryInfo::invalid_id);
1957
1958 if (elem)
1959 {
1960 boundary_info.raw_edge_boundary_ids(elem, e, bcids);
1961
1962 // Ordering of boundary ids shouldn't matter
1963 std::sort(bcids.begin(), bcids.end());
1964
1965 all_bcids.insert(all_bcids.end(), bcids.begin(),
1966 bcids.end());
1967 // Separator
1968 all_bcids.push_back(BoundaryInfo::invalid_id);
1969 }
1970
1971 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
1972 }
1973
1974 for (unsigned short s=0; s != n_sides; ++s)
1975 {
1976 std::vector<boundary_id_type> bcids;
1977
1978 if (elem)
1979 {
1980 boundary_info.boundary_ids(elem, s, bcids);
1981
1982 // Ordering of boundary ids shouldn't matter
1983 std::sort(bcids.begin(), bcids.end());
1984
1985 all_bcids.insert(all_bcids.end(), bcids.begin(),
1986 bcids.end());
1987 // Separator
1988 all_bcids.push_back(BoundaryInfo::invalid_id);
1989 }
1990
1991 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
1992
1993 if (elem)
1994 {
1995 boundary_info.raw_boundary_ids(elem, s, bcids);
1996
1997 // Ordering of boundary ids shouldn't matter
1998 std::sort(bcids.begin(), bcids.end());
1999
2000 all_bcids.insert(all_bcids.end(), bcids.begin(),
2001 bcids.end());
2002 // Separator
2003 all_bcids.push_back(BoundaryInfo::invalid_id);
2004 }
2005
2006 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
2007 }
2008
2009 for (unsigned short sf=0; sf != 2; ++sf)
2010 {
2011 std::vector<boundary_id_type> bcids;
2012
2013 if (elem)
2014 {
2015 boundary_info.shellface_boundary_ids(elem, sf, bcids);
2016
2017 // Ordering of boundary ids shouldn't matter
2018 std::sort(bcids.begin(), bcids.end());
2019
2020 all_bcids.insert(all_bcids.end(), bcids.begin(),
2021 bcids.end());
2022 // Separator
2023 all_bcids.push_back(BoundaryInfo::invalid_id);
2024 }
2025
2026 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
2027
2028 if (elem)
2029 {
2030 boundary_info.raw_shellface_boundary_ids(elem, sf, bcids);
2031
2032 // Ordering of boundary ids shouldn't matter
2033 std::sort(bcids.begin(), bcids.end());
2034
2035 all_bcids.insert(all_bcids.end(), bcids.begin(),
2036 bcids.end());
2037 // Separator
2038 all_bcids.push_back(BoundaryInfo::invalid_id);
2039 }
2040
2041 // libmesh_assert(mesh.comm().semiverify (elem ? &bcids : nullptr));
2042 }
2043
2045 (elem ? &all_bcids : nullptr));
2046 }
2047}
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void shellface_boundary_ids(const Elem *const elem, const unsigned short int shellface, std::vector< boundary_id_type > &vec_to_fill) const
void raw_shellface_boundary_ids(const Elem *const elem, const unsigned short int shellface, std::vector< boundary_id_type > &vec_to_fill) const
void edge_boundary_ids(const Elem *const elem, const unsigned short int edge, std::vector< boundary_id_type > &vec_to_fill) const
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
Fills a user-provided std::vector with the boundary ids associated with Node node.
void raw_boundary_ids(const Elem *const elem, const unsigned short int side, std::vector< boundary_id_type > &vec_to_fill) const
void raw_edge_boundary_ids(const Elem *const elem, const unsigned short int edge, std::vector< boundary_id_type > &vec_to_fill) const
static const boundary_id_type invalid_id
Number used for internal use.
virtual unsigned int n_edges() const =0
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:178

References libMesh::BoundaryInfo::boundary_ids(), libMesh::ParallelObject::comm(), libMesh::BoundaryInfo::edge_boundary_ids(), libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::invalid_id, libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Elem::n_edges(), libMesh::Elem::n_nodes(), n_nodes, libMesh::ParallelObject::n_processors(), libMesh::Elem::n_sides(), libMesh::Elem::node_ptr(), libMesh::MeshBase::query_elem_ptr(), libMesh::BoundaryInfo::raw_boundary_ids(), libMesh::BoundaryInfo::raw_edge_boundary_ids(), libMesh::BoundaryInfo::raw_shellface_boundary_ids(), libMesh::Parallel::Communicator::semiverify(), and libMesh::BoundaryInfo::shellface_boundary_ids().

Referenced by libMesh::MeshBase::complete_preparation(), and libMesh::DofMap::create_dof_constraints().

◆ libmesh_assert_valid_constraint_rows()

void libMesh::MeshTools::libmesh_assert_valid_constraint_rows ( const MeshBase &  mesh)

A function for verifying that all mesh constraint rows express relations between nodes and elements that are semilocal (local or ghosted) to the current processor's portion of the mesh.

Definition at line 1837 of file mesh_tools.C.

1838{
1839 libmesh_parallel_only(mesh.comm());
1840
1841 const auto & constraint_rows = mesh.get_constraint_rows();
1842
1843 bool have_constraint_rows = !constraint_rows.empty();
1844 mesh.comm().max(have_constraint_rows);
1845 if (!have_constraint_rows)
1846 return;
1847
1848 for (auto & row : constraint_rows)
1849 {
1850 const Node * node = row.first;
1851 libmesh_assert(node == mesh.node_ptr(node->id()));
1852
1853 for (auto & pr : row.second)
1854 {
1855 const Elem * spline_elem = pr.first.first;
1856 libmesh_assert(spline_elem == mesh.elem_ptr(spline_elem->id()));
1857 }
1858 }
1859
1860 dof_id_type pmax_node_id = mesh.max_node_id();
1861 mesh.comm().max(pmax_node_id);
1862
1863 for (dof_id_type i=0; i != pmax_node_id; ++i)
1864 {
1865 const Node * node = mesh.query_node_ptr(i);
1866
1867 bool have_constraint = constraint_rows.count(node);
1868
1869 const std::size_t my_n_constraints = have_constraint ?
1870 libmesh_map_find(constraint_rows, node).size() : std::size_t(-1);
1871 const std::size_t * n_constraints = node ?
1872 &my_n_constraints : nullptr;
1873
1874 libmesh_assert(mesh.comm().semiverify(n_constraints));
1875 }
1876}
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual const Elem * elem_ptr(const dof_id_type i) const =0
constraint_rows_type & get_constraint_rows()
Constraint rows accessors.
Definition mesh_base.h:1994

References libMesh::ParallelObject::comm(), libMesh::MeshBase::elem_ptr(), libMesh::MeshBase::get_constraint_rows(), libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshBase::node_ptr(), libMesh::MeshBase::query_node_ptr(), and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::MeshBase::complete_preparation(), and libMesh::MeshCommunication::delete_remote_elements().

◆ libmesh_assert_valid_dof_ids()

void libMesh::MeshTools::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.

Verify a particular system by specifying that system's number, or verify all systems at once by leaving sysnum unspecified.

Definition at line 2050 of file mesh_tools.C.

2051{
2052 LOG_SCOPE("libmesh_assert_valid_dof_ids()", "MeshTools");
2053
2054 if (mesh.n_processors() == 1)
2055 return;
2056
2057 libmesh_parallel_only(mesh.comm());
2058
2059 dof_id_type pmax_elem_id = mesh.max_elem_id();
2060 mesh.comm().max(pmax_elem_id);
2061
2062 for (dof_id_type i=0; i != pmax_elem_id; ++i)
2063 assert_semiverify_dofobj(mesh.comm(),
2065 sysnum);
2066
2067 dof_id_type pmax_node_id = mesh.max_node_id();
2068 mesh.comm().max(pmax_node_id);
2069
2070 for (dof_id_type i=0; i != pmax_node_id; ++i)
2071 assert_semiverify_dofobj(mesh.comm(),
2073 sysnum);
2074}

References libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMesh::ParallelObject::n_processors(), libMesh::MeshBase::query_elem_ptr(), and libMesh::MeshBase::query_node_ptr().

Referenced by libMesh::DofMap::distribute_dofs().

◆ libmesh_assert_valid_elem_ids()

void libMesh::MeshTools::libmesh_assert_valid_elem_ids ( const MeshBase &  mesh)
inline

A function for verifying that ids and processor assignment of elements are correctly sorted (monotone increasing)

Definition at line 672 of file mesh_tools.h.

672{}

Referenced by libMesh::DistributedMesh::renumber_nodes_and_elements().

◆ libmesh_assert_valid_is_prepared()

void libMesh::MeshTools::libmesh_assert_valid_is_prepared ( const MeshBase &  mesh)
inline

The following functions, no-ops except in builds with NDEBUG undefined, are for asserting internal consistency that we hope should never be broken in opt.

Like libmesh_assert(MeshTools::valid_is_prepared(mesh)), but provides more information on preparation incompleteness in case of an error.

Definition at line 662 of file mesh_tools.h.

662{}

Referenced by libMesh::System::assemble(), libMesh::FEMSystem::assemble_qoi(), libMesh::System::assemble_qoi(), libMesh::System::assemble_qoi_derivative(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), libMesh::NonlinearImplicitSystem::assembly(), libMesh::MeshBase::complete_preparation(), and libMesh::MeshTetInterface::volume_to_surface_mesh().

◆ libmesh_assert_valid_neighbors()

void libMesh::MeshTools::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 descendant of a neighbor of its neighbors) and consistent (each neighbor link goes to either the same neighbor or to a RemoteElem on each processor)

If assert_valid_remote_elems is set to false, then no error will be thrown for neighbor links where a remote_elem should exist but a nullptr exists instead.

Definition at line 2412 of file mesh_tools.C.

2414{
2415 LOG_SCOPE("libmesh_assert_valid_neighbors()", "MeshTools");
2416
2417 for (const auto & elem : mesh.element_ptr_range())
2418 {
2419 libmesh_assert (elem);
2420 elem->libmesh_assert_valid_neighbors();
2421 }
2422
2423 if (mesh.n_processors() == 1)
2424 return;
2425
2426 libmesh_parallel_only(mesh.comm());
2427
2428 dof_id_type pmax_elem_id = mesh.max_elem_id();
2429 mesh.comm().max(pmax_elem_id);
2430
2431 for (dof_id_type i=0; i != pmax_elem_id; ++i)
2432 {
2433 const Elem * elem = mesh.query_elem_ptr(i);
2434
2435 const unsigned int my_n_neigh = elem ? elem->n_neighbors() : 0;
2436 unsigned int n_neigh = my_n_neigh;
2437 mesh.comm().max(n_neigh);
2438 if (elem)
2439 libmesh_assert_equal_to (my_n_neigh, n_neigh);
2440
2441 for (unsigned int n = 0; n != n_neigh; ++n)
2442 {
2443 dof_id_type my_neighbor = DofObject::invalid_id;
2444 dof_id_type * p_my_neighbor = nullptr;
2445
2446 // If we have a non-remote_elem neighbor link, then we can
2447 // verify it.
2448 if (elem && elem->neighbor_ptr(n) != remote_elem)
2449 {
2450 p_my_neighbor = &my_neighbor;
2451 if (elem->neighbor_ptr(n))
2452 my_neighbor = elem->neighbor_ptr(n)->id();
2453
2454 // But wait - if we haven't set remote_elem links yet then
2455 // some nullptr links on ghost elements might be
2456 // future-remote_elem links, so we can't verify those.
2457 if (!assert_valid_remote_elems &&
2458 !elem->neighbor_ptr(n) &&
2459 elem->processor_id() != mesh.processor_id())
2460 p_my_neighbor = nullptr;
2461 }
2462 libmesh_assert(mesh.comm().semiverify(p_my_neighbor));
2463 }
2464 }
2465}
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473

References libMesh::ParallelObject::comm(), libMesh::DofObject::id(), libMesh::DofObject::invalid_id, libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Elem::n_neighbors(), libMesh::ParallelObject::n_processors(), libMesh::Elem::neighbor_ptr(), libMesh::DofObject::processor_id(), libMesh::ParallelObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), libMesh::remote_elem, and libMesh::Parallel::Communicator::semiverify().

Referenced by libMesh::DistributedMesh::allgather(), libMesh::DistributedMesh::delete_remote_elements(), libMesh::UnstructuredMesh::find_neighbors(), and libMesh::UnstructuredMesh::stitching_helper().

◆ libmesh_assert_valid_node_pointers()

void libMesh::MeshTools::libmesh_assert_valid_node_pointers ( const MeshBase &  mesh)
inline

A function for walking across the mesh to try and ferret out invalidated or misassigned pointers.

Definition at line 668 of file mesh_tools.h.

668{}

◆ libmesh_assert_valid_procids()

template<typename DofObjectSubclass >
void libMesh::MeshTools::libmesh_assert_valid_procids ( const MeshBase &  mesh)

A function for verifying that processor assignment is both parallel and topologically consistent.

Definition at line 610 of file mesh_tools.h.

611{
612 libmesh_assert_parallel_consistent_procids<DofObjectSubclass>(mesh);
613 libmesh_assert_topology_consistent_procids<DofObjectSubclass>(mesh);
614}
MeshBase & mesh

References mesh.

◆ libmesh_assert_valid_refinement_flags()

void libMesh::MeshTools::libmesh_assert_valid_refinement_flags ( const MeshBase &  mesh)

A function for verifying that refinement flags on elements are consistent between processors.

Definition at line 2365 of file mesh_tools.C.

2366{
2367 LOG_SCOPE("libmesh_assert_valid_refinement_flags()", "MeshTools");
2368
2369 libmesh_parallel_only(mesh.comm());
2370 if (mesh.n_processors() == 1)
2371 return;
2372
2373 dof_id_type pmax_elem_id = mesh.max_elem_id();
2374 mesh.comm().max(pmax_elem_id);
2375
2376 std::vector<unsigned char> my_elem_h_state(pmax_elem_id, 255);
2377 std::vector<unsigned char> my_elem_p_state(pmax_elem_id, 255);
2378
2379 for (const auto & elem : mesh.element_ptr_range())
2380 {
2381 libmesh_assert (elem);
2382 dof_id_type elemid = elem->id();
2383
2384 my_elem_h_state[elemid] =
2385 static_cast<unsigned char>(elem->refinement_flag());
2386
2387 my_elem_p_state[elemid] =
2388 static_cast<unsigned char>(elem->p_refinement_flag());
2389 }
2390 std::vector<unsigned char> min_elem_h_state(my_elem_h_state);
2391 mesh.comm().min(min_elem_h_state);
2392
2393 std::vector<unsigned char> min_elem_p_state(my_elem_p_state);
2394 mesh.comm().min(min_elem_p_state);
2395
2396 for (dof_id_type i=0; i!= pmax_elem_id; ++i)
2397 {
2398 libmesh_assert(my_elem_h_state[i] == 255 ||
2399 my_elem_h_state[i] == min_elem_h_state[i]);
2400 libmesh_assert(my_elem_p_state[i] == 255 ||
2401 my_elem_p_state[i] == min_elem_p_state[i]);
2402 }
2403}

References libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), mesh, libMesh::Parallel::Communicator::min(), and libMesh::ParallelObject::n_processors().

◆ libmesh_assert_valid_refinement_tree()

void libMesh::MeshTools::libmesh_assert_valid_refinement_tree ( const MeshBase &  mesh)
inline

A function for verifying that elements on this processor have valid descendants and consistent active flags.

Definition at line 685 of file mesh_tools.h.

685{}

Referenced by libMesh::DistributedMesh::delete_remote_elements(), and libMesh::MeshCommunication::delete_remote_elements().

◆ libmesh_assert_valid_remote_elems()

void libMesh::MeshTools::libmesh_assert_valid_remote_elems ( const MeshBase &  mesh)
inline

A function for verifying that active local elements' neighbors are never remote elements.

Definition at line 670 of file mesh_tools.h.

670{}

Referenced by libMesh::Partitioner::partition().

◆ libmesh_assert_valid_unique_ids()

void libMesh::MeshTools::libmesh_assert_valid_unique_ids ( const MeshBase &  mesh)

A function for verifying that unique ids match across processors.

Definition at line 2078 of file mesh_tools.C.

2079{
2080 LOG_SCOPE("libmesh_assert_valid_unique_ids()", "MeshTools");
2081
2082 libmesh_parallel_only(mesh.comm());
2083
2084 // Storage for semi-local DofObject ids.
2085 std::unordered_set<unique_id_type> semilocal_unique_ids;
2086
2087 auto gather_elem_ids = [&]()
2088 {
2089 for (auto const & elem : mesh.active_element_ptr_range())
2090 {
2091 auto [it, inserted] = semilocal_unique_ids.insert(elem->unique_id());
2092 libmesh_assert(inserted);
2093 libmesh_ignore(it);
2094 }
2095 };
2096
2097 auto gather_node_ids = [&]()
2098 {
2099 for (auto const & node : mesh.node_ptr_range())
2100 {
2101 auto [it, inserted] = semilocal_unique_ids.insert(node->unique_id());
2102 libmesh_assert(inserted);
2103 libmesh_ignore(it);
2104 }
2105 };
2106
2107 auto verify_elems = [&]()
2108 {
2109 dof_id_type pmax_elem_id = mesh.max_elem_id();
2110 mesh.comm().max(pmax_elem_id);
2111
2112 for (auto i : make_range(pmax_elem_id))
2113 {
2114 const Elem * elem = mesh.query_elem_ptr(i);
2115 assert_dofobj_unique_id(mesh.comm(), elem, semilocal_unique_ids);
2116 }
2117 };
2118
2119 auto verify_nodes = [&]()
2120 {
2121 dof_id_type pmax_node_id = mesh.max_node_id();
2122 mesh.comm().max(pmax_node_id);
2123
2124 for (auto i : make_range(pmax_node_id))
2125 {
2126 const Node * node = mesh.query_node_ptr(i);
2127 assert_dofobj_unique_id(mesh.comm(), node, semilocal_unique_ids);
2128 }
2129 };
2130
2132 {
2133 // First collect all the unique_ids we can see and make sure there's
2134 // no duplicates
2135 gather_elem_ids();
2136 gather_node_ids();
2137
2138 // Then make sure elements/nodes are all in sync and remote
2139 // elements don't duplicate semilocal
2140 verify_elems();
2141 verify_nodes();
2142 }
2143 else
2144 {
2145 // If the mesh allows Node and Elem unique_ids to overlap, then we only
2146 // check for validity and uniqueness of an Elem (resp. Node) unique id
2147 // within the set of Elem (resp. Node) unique_ids.
2148 gather_elem_ids();
2149 verify_elems();
2150
2151 // Clear id list before checking Nodes
2152 semilocal_unique_ids.clear();
2153
2154 // Finally, check Nodes
2155 gather_node_ids();
2156 verify_nodes();
2157 }
2158}
void allow_node_and_elem_unique_id_overlap(bool allow)
If true is passed, then this mesh will no longer require unique_ids to be unique across the set of al...
Definition mesh_base.h:1399
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::MeshBase::allow_node_and_elem_unique_id_overlap(), libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libMesh::libmesh_ignore(), libMesh::make_range(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshBase::query_elem_ptr(), and libMesh::MeshBase::query_node_ptr().

Referenced by libMesh::MeshBase::complete_preparation(), and libMesh::SimplexRefiner::refine_via_edges().

◆ n_active_elem_of_type()

dof_id_type libMesh::MeshTools::n_active_elem_of_type ( const MeshBase &  mesh,
const ElemType  type 
)
Returns
The number of active elements of type type.

Implemented in terms of active_type_element_iterators.

Definition at line 807 of file mesh_tools.C.

809{
810 return static_cast<dof_id_type>(std::distance(mesh.active_type_elements_begin(type),
811 mesh.active_type_elements_end (type)));
812}

References mesh.

◆ n_active_levels()

unsigned int libMesh::MeshTools::n_active_levels ( const MeshBase &  mesh)
Returns
The number of levels of refinement in the active mesh.

Implemented by looping over all the active local elements and finding the maximum level, then taking the max in parallel.

Definition at line 859 of file mesh_tools.C.

860{
861 libmesh_parallel_only(mesh.comm());
862
863 unsigned int nl = n_active_local_levels(mesh);
864
865 for (const auto & elem : as_range(mesh.unpartitioned_elements_begin(),
866 mesh.unpartitioned_elements_end()))
867 if (elem->active())
868 nl = std::max(elem->level() + 1, nl);
869
870 mesh.comm().max(nl);
871 return nl;
872}
unsigned int n_active_local_levels(const MeshBase &mesh)
Definition mesh_tools.C:830

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), mesh, and n_active_local_levels().

Referenced by libMesh::XdrIO::write_serialized_connectivity().

◆ n_active_local_levels()

unsigned int libMesh::MeshTools::n_active_local_levels ( const MeshBase &  mesh)
Returns
The number of levels of refinement in the active local mesh.

Implemented by looping over all the active local elements and finding the maximum level.

Definition at line 830 of file mesh_tools.C.

831{
832 struct LevelCounter {
833 unsigned int nl;
834
835 LevelCounter () : nl(0) {}
836
837 LevelCounter (LevelCounter &, Threads::split) :
838 nl(0) {}
839
840 void operator()(const ConstElemRange & range) {
841 for (const Elem * elem : range)
842 nl = std::max(elem->level() + 1, nl);
843 }
844
845 void join(const LevelCounter & other) {
846 nl = std::max(nl, other.nl);
847 }
848 };
849
850 LevelCounter counter;
851
853
854 return counter.nl;
855}
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.

References libMesh::MeshBase::active_local_element_stored_range(), mesh, and libMesh::Threads::parallel_reduce().

Referenced by n_active_levels().

◆ n_connected_components()

dof_id_type libMesh::MeshTools::n_connected_components ( const MeshBase &  mesh,
Real  constraint_tol = 0 
)
Returns
The number of topologically connected components in the mesh, where a local connection is defined as two nodes connected to the same element, two elements connected to the same node, and/or two nodes connected by a constraint row; thus a connection can be made at a single vertex, not just at an element side.

To count sufficiently weak constraint row coefficients as a lack-of-connection, set a constraint_tol greater than 0.

Definition at line 927 of file mesh_tools.C.

929{
930 LOG_SCOPE("n_connected_components()", "MeshTools");
931
932 // Yes, I'm being lazy. This is for mesh analysis before a
933 // simulation, not anything going in any loops.
934 if (!mesh.is_serial_on_zero())
935 libmesh_not_implemented();
936
937 dof_id_type n_components = 0;
938
939 if (mesh.processor_id())
940 {
941 mesh.comm().broadcast(n_components);
942 return n_components;
943 }
944
945 // All nodes in a set here are connected (at least indirectly) to
946 // all other nodes in the same set, but have not yet been discovered
947 // to be connected to nodes in other sets.
948 //
949 // Using an unordered_set of ids rather than a set of pointers seems
950 // to be roughly 150% faster?
951 // typedef const Node * node_entry_type
952 typedef dof_id_type node_entry_type;
953 std::vector<std::unordered_set<node_entry_type>> components;
954
955 // With a typical mesh with few components and somewhat-contiguous
956 // ordering, vector performance should be fine. With a mesh with
957 // many components or completely scrambled ordering, performance
958 // can be a disaster.
959 auto find_component = [&components](node_entry_type n) {
960 for (auto & c: components)
961 if (c.find(n) != c.end())
962 return &c;
963
964 return (std::unordered_set<node_entry_type> *)(nullptr);
965 };
966
967 auto add_to_component =
968 [&find_component]
969 (std::unordered_set<node_entry_type> & component, node_entry_type n) {
970 // We may already be in the desired component
971 if (component.find(n) != component.end())
972 return;
973
974 auto current_component = find_component(n);
975
976 // Didn't we *just* check this?
977 libmesh_assert (&component != current_component);
978
979 // If we're unknown, we should be in the desired component
980 if (!current_component)
981 component.insert(n);
982
983 // If we think we're in another component, it should actually be
984 // part of the desired component
985 else
986 {
987 // Merge the component likely to be smaller into the one
988 // likely to be larger - this is orders of magnitude faster
989 // than the other way around!
990 current_component->merge(component);
991 current_component->swap(component);
992 libmesh_assert(current_component->empty());
993 }
994 };
995
996 const auto & constraint_rows = mesh.get_constraint_rows();
997
998 for (const auto & elem : mesh.element_ptr_range())
999 {
1000 // const node_entry_type first_node = elem->node_ptr(0);
1001 const node_entry_type first_node = elem->node_id(0);
1002
1003 auto component = find_component(first_node);
1004
1005 // If we didn't find one, make a new one, reusing an existing
1006 // slot if possible or growing our vector if necessary
1007 if (!component)
1008 for (auto & c: components)
1009 if (c.empty())
1010 component = &c;
1011
1012 if (!component)
1013 component = &components.emplace_back();
1014
1015 for (const Node & node : elem->node_ref_range())
1016 {
1017 // const node_entry_type n = &node;
1018 const node_entry_type n = node.id();
1019 add_to_component(*component, n);
1020
1021 auto it = constraint_rows.find(&node);
1022 if (it == constraint_rows.end())
1023 continue;
1024
1025 for (const auto & [pr, val] : it->second)
1026 {
1027 // Ignore too-trivial constraint coefficients if
1028 // we get a non-default-0 constraint_tol
1029 if (std::abs(val) < constraint_tol)
1030 continue;
1031
1032 const Elem * spline_elem = pr.first;
1033 libmesh_assert(spline_elem == mesh.elem_ptr(spline_elem->id()));
1034
1035 const Node * spline_node =
1036 spline_elem->node_ptr(pr.second);
1037
1038 // add_to_component(*component, spline_node);
1039 add_to_component(*component, spline_node->id());
1040 }
1041 }
1042 }
1043
1044 for (auto & component : components)
1045 if (!component.empty())
1046 ++n_components;
1047
1048 // We calculated this on proc 0; now let everyone else know too
1049 mesh.comm().broadcast(n_components);
1050
1051 return n_components;
1052}
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
virtual bool is_serial_on_zero() const
Definition mesh_base.h:372

References libMesh::Parallel::Communicator::broadcast(), libMesh::ParallelObject::comm(), libMesh::MeshBase::elem_ptr(), libMesh::MeshBase::get_constraint_rows(), libMesh::DofObject::id(), libMesh::MeshBase::is_serial_on_zero(), libMesh::libmesh_assert(), mesh, libMesh::Elem::node_ptr(), and libMesh::ParallelObject::processor_id().

Referenced by main(), and ConnectedComponentsTest::testEdge().

◆ n_elem()

dof_id_type libMesh::MeshTools::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 at line 1067 of file mesh_tools.C.

1069{
1070 return cast_int<dof_id_type>(std::distance(begin, end));
1071}

Referenced by libMesh::MeshTools::Subdivision::add_boundary_ghosts(), correct_node_proc_ids(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::Partitioner::set_node_processor_ids(), libMesh::Partitioner::set_parent_processor_ids(), and libMesh::XdrIO::write_serialized_connectivity().

◆ n_elem_of_type()

dof_id_type libMesh::MeshTools::n_elem_of_type ( const MeshBase &  mesh,
const ElemType  type 
)
Returns
The number of elements of type type.

Implemented in terms of type_element_iterators.

Definition at line 798 of file mesh_tools.C.

800{
801 return static_cast<dof_id_type>(std::distance(mesh.type_elements_begin(type),
802 mesh.type_elements_end (type)));
803}

References mesh.

◆ n_levels()

unsigned int libMesh::MeshTools::n_levels ( const MeshBase &  mesh)
Returns
The number of levels of refinement in the mesh.

Implemented by looping over all the local elements and unpartitioned elements and finding the maximum level, then summing in parallel.

Definition at line 889 of file mesh_tools.C.

890{
891 libmesh_parallel_only(mesh.comm());
892
893 unsigned int nl = n_local_levels(mesh);
894
895 for (const auto & elem : as_range(mesh.unpartitioned_elements_begin(),
896 mesh.unpartitioned_elements_end()))
897 nl = std::max(elem->level() + 1, nl);
898
899 mesh.comm().max(nl);
900
901 // n_levels() is only valid and should only be called in cases where
902 // the mesh is validly distributed (or serialized). Let's run an
903 // expensive test in debug mode to make sure this is such a case.
904#ifdef DEBUG
905 const unsigned int paranoid_nl = paranoid_n_levels(mesh);
906 libmesh_assert_equal_to(nl, paranoid_nl);
907#endif
908 return nl;
909}
unsigned int n_local_levels(const MeshBase &mesh)
Definition mesh_tools.C:876
unsigned int paranoid_n_levels(const MeshBase &mesh)
Definition mesh_tools.C:913

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), mesh, n_local_levels(), and paranoid_n_levels().

Referenced by libMesh::MeshCommunication::delete_remote_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::PetscDMWrapper::init_petscdm(), libMesh::MeshTools::Modification::orient_elements(), libMesh::MeshTools::Modification::permute_elements(), libMesh::Partitioner::set_node_processor_ids(), and libMesh::MeshTools::Modification::smooth().

◆ n_local_levels()

unsigned int libMesh::MeshTools::n_local_levels ( const MeshBase &  mesh)
Returns
The number of levels of refinement in the local mesh.

Implemented by looping over all the local elements and finding the maximum level.

Definition at line 876 of file mesh_tools.C.

877{
878 unsigned int nl = 0;
879
880 for (const auto & elem : as_range(mesh.local_elements_begin(),
881 mesh.local_elements_end()))
882 nl = std::max(elem->level() + 1, nl);
883
884 return nl;
885}

References libMesh::as_range(), and mesh.

Referenced by n_levels().

◆ n_nodes()

dof_id_type libMesh::MeshTools::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 at line 1075 of file mesh_tools.C.

1077{
1078 return cast_int<dof_id_type>(std::distance(begin, end));
1079}

◆ n_non_subactive_elem_of_type_at_level()

dof_id_type libMesh::MeshTools::n_non_subactive_elem_of_type_at_level ( const MeshBase &  mesh,
const ElemType  type,
const unsigned int  level 
)
Returns
The number of elements of type type at the specified refinement level.
Todo:
Replace all of the n_xxx_elem() functions like this with a single function which takes a range of iterators and computes the std::distance between them.

Definition at line 814 of file mesh_tools.C.

817{
818 dof_id_type cnt = 0;
819
820 // iterate over the elements of the specified type
821 for (const auto & elem : as_range(mesh.type_elements_begin(type),
822 mesh.type_elements_end(type)))
823 if ((elem->level() == level) && !elem->subactive())
824 cnt++;
825
826 return cnt;
827}

References libMesh::as_range(), and mesh.

◆ n_p_levels()

unsigned int libMesh::MeshTools::n_p_levels ( const MeshBase &  mesh)
Returns
The number of p-levels of refinement in the mesh.

Implemented by looping over all the local elements and finding the maximum p-level, then summing in parallel.

Definition at line 1112 of file mesh_tools.C.

1113{
1114 libmesh_parallel_only(mesh.comm());
1115
1116 unsigned int max_p_level = 0;
1117
1118 // first my local elements
1119 for (const auto & elem : as_range(mesh.local_elements_begin(),
1120 mesh.local_elements_end()))
1121 max_p_level = std::max(elem->p_level(), max_p_level);
1122
1123 // then any unpartitioned objects
1124 for (const auto & elem : as_range(mesh.unpartitioned_elements_begin(),
1125 mesh.unpartitioned_elements_end()))
1126 max_p_level = std::max(elem->p_level(), max_p_level);
1127
1128 mesh.comm().max(max_p_level);
1129 return max_p_level + 1;
1130}

References libMesh::as_range(), libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), and mesh.

Referenced by libMesh::XdrIO::write().

◆ paranoid_n_levels()

unsigned int libMesh::MeshTools::paranoid_n_levels ( const MeshBase &  mesh)
Returns
The number of levels of refinement in the mesh, even if that mesh is not currently properly distributed or properly serialized.

Implemented by looping over all elements and finding the maximum level, then summing in parallel. This is much slower than n_levels() but will return correct values even when the mesh is in an inconsistent parallel state.

Definition at line 913 of file mesh_tools.C.

914{
915 libmesh_parallel_only(mesh.comm());
916
917 unsigned int nl = 0;
918 for (const auto & elem : mesh.element_ptr_range())
919 nl = std::max(elem->level() + 1, nl);
920
921 mesh.comm().max(nl);
922 return nl;
923}

References libMesh::ParallelObject::comm(), libMesh::Parallel::Communicator::max(), and mesh.

Referenced by n_levels().

◆ processor_bounding_sphere()

Sphere libMesh::MeshTools::processor_bounding_sphere ( const MeshBase &  mesh,
const processor_id_type  pid 
)
Returns
A processor bounding sphere instead of a processor bounding box.

Definition at line 733 of file mesh_tools.C.

735{
738
739 const Real diag = (bbox.second - bbox.first).norm();
740 const Point cent = (bbox.second + bbox.first)/2;
741
742 return Sphere (cent, .5*diag);
743}
libMesh::BoundingBox create_processor_bounding_box(const MeshBase &mesh, const processor_id_type pid)
Definition mesh_tools.C:708

References create_processor_bounding_box(), mesh, and libMesh::Real.

◆ subdomain_bounding_sphere()

Sphere libMesh::MeshTools::subdomain_bounding_sphere ( const MeshBase &  mesh,
const subdomain_id_type  sid 
)
Returns
A subdomain bounding sphere instead of a subdomain bounding box.

Definition at line 772 of file mesh_tools.C.

774{
777
778 const Real diag = (bbox.second - bbox.first).norm();
779 const Point cent = (bbox.second + bbox.first)/2;
780
781 return Sphere (cent, .5*diag);
782}
libMesh::BoundingBox create_subdomain_bounding_box(const MeshBase &mesh, const subdomain_id_type sid)
Definition mesh_tools.C:748

References create_subdomain_bounding_box(), mesh, and libMesh::Real.

◆ total_weight()

dof_id_type libMesh::MeshTools::total_weight ( const MeshBase &  mesh)
Returns
The sum over all the elements of the number of nodes per element.

This can be useful for partitioning hybrid meshes. A feasible load balancing scheme is to keep the weight per processor as uniform as possible.

Definition at line 485 of file mesh_tools.C.

486{
487 if (!mesh.is_serial())
488 {
489 libmesh_parallel_only(mesh.comm());
491 mesh.comm().sum(weight);
492 dof_id_type unpartitioned_weight =
494 return weight + unpartitioned_weight;
495 }
496
497 SumElemWeight sew;
498
500 mesh.elements_end()),
501 sew);
502 return sew.weight();
503
504}
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition mesh_tools.C:508

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::MeshBase::is_serial(), mesh, libMesh::Threads::parallel_reduce(), libMesh::ParallelObject::processor_id(), libMesh::Parallel::Communicator::sum(), and weight().

◆ valid_is_prepared()

bool libMesh::MeshTools::valid_is_prepared ( const MeshBase &  mesh)

A function for testing whether a mesh's cached is_prepared() setting is not a false positive, and that its preparation() values are not false positives.

If the mesh is marked as completely not prepared, or if preparing an already-prepared mesh (without any repartitioning or renumbering) or preparing after a complete_preparation() (likewise) does not change the mesh, then we return true. If the mesh believes it is prepared but prepare_for_use() would change it, or if the mesh believes it is partially prepared in a certain way but complete_preparation() does not completely prepare it, we return false.

Definition at line 1319 of file mesh_tools.C.

1320{
1321 LOG_SCOPE("valid_is_prepared()", "MeshTools");
1322
1323 const MeshBase::Preparation prep = mesh.preparation();
1324
1325 // If the mesh doesn't think *anything* has been prepared, we have
1326 // nothing to check.
1327 if (prep == MeshBase::Preparation())
1328 return true;
1329
1330 // If the mesh thinks it's partitioned, check. These are counts,
1331 // not caches, so it's a real check.
1332 if (prep.is_partitioned)
1333 if (mesh.n_unpartitioned_elem() ||
1335 return false;
1336
1337 // If the mesh thinks it's prepared in some way, *re*-preparing in
1338 // that way shouldn't change a clone of it, as long as we disallow
1339 // repartitioning or renumbering or remote element removal.
1340 std::unique_ptr<MeshBase> mesh_clone = reprepared_mesh_clone(mesh);
1341
1342 // Check whether the original and clone compare equal
1343 return (mesh == *mesh_clone);
1344}
Preparation preparation() const
Definition mesh_base.h:221
dof_id_type n_unpartitioned_elem() const
Definition mesh_base.h:708
dof_id_type n_unpartitioned_nodes() const
Definition mesh_base.h:602
Flags indicating in what ways a mesh has been prepared for use.
Definition mesh_base.h:2146

References libMesh::MeshBase::Preparation::is_partitioned, mesh, libMesh::MeshBase::n_unpartitioned_elem(), libMesh::MeshBase::n_unpartitioned_nodes(), and libMesh::MeshBase::preparation().

Referenced by ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), ConstraintOperatorTest::testCoreform(), MeshBaseTest::testMeshBaseVerifyHasCachedElemData(), MeshBaseTest::testMeshBaseVerifyHasNeighborPtrs(), MeshBaseTest::testMeshBaseVerifyIsPrepared(), and MeshBaseTest::testMeshBaseVerifyRemovalPreparation().

◆ volume()

Real libMesh::MeshTools::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 = 1, or number of NodeElem in the mesh for dim = 0).

By default the dimension chosen will be the mesh_dimension(), which if not manually overridden will be the largest dimension of elements in the mesh.

Definition at line 1083 of file mesh_tools.C.

1085{
1086 libmesh_parallel_only(mesh.comm());
1087
1090
1091 Real vol = 0;
1092
1093 // first my local elements
1094 for (const auto & elem : as_range(mesh.local_elements_begin(),
1095 mesh.local_elements_end()))
1096 if (elem->dim() == dim)
1097 vol += elem->volume();
1098
1099 // then count any unpartitioned objects, once
1100 if (mesh.processor_id() == 0)
1101 for (const auto & elem : as_range(mesh.unpartitioned_elements_begin(),
1102 mesh.unpartitioned_elements_end()))
1103 if (elem->dim() == dim)
1104 vol += elem->volume();
1105
1106 mesh.comm().sum(vol);
1107 return vol;
1108}
unsigned int dim
unsigned int mesh_dimension() const
Definition mesh_base.C:515
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 =...
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

References libMesh::as_range(), libMesh::ParallelObject::comm(), dim, libMesh::invalid_uint, mesh, libMesh::MeshBase::mesh_dimension(), libMesh::ParallelObject::processor_id(), libMesh::Real, and libMesh::Parallel::Communicator::sum().

Referenced by AllRBBTest::test_box(), AllRBBTest::test_circle(), AllRBBTest::test_cylinder(), AllRBBTest::test_disk(), AllTriTest::test_helper(), AllTriTest::test_helper_c0polyhedron(), AllRBBTest::test_sphere(), AllTriTest::testAllTriC0PolygonOctagon(), MeshGenerationTest::testBuildCube(), MeshTetTest::testHole(), MeshTetTest::testNetGenQuadratic(), MeshTetTest::testNetGenTet14(), MeshTetTest::testTetInterfaceBase(), and MeshTetTest::testTetsToTets().

◆ weight() [1/2]

dof_id_type libMesh::MeshTools::weight ( const MeshBase &  mesh)
inline

Definition at line 78 of file mesh_tools.h.

79{ return MeshTools::weight (mesh, mesh.processor_id()); }

References mesh, and weight().

◆ weight() [2/2]

dof_id_type libMesh::MeshTools::weight ( const MeshBase &  mesh,
const processor_id_type  pid 
)
Returns
The sum over all the elements on processor pid of nodes per element.

This can be useful for partitioning hybrid meshes. A feasible load balancing scheme is to keep the weight per processor as uniform as possible.

Definition at line 508 of file mesh_tools.C.

509{
510 SumElemWeight sew;
511
512 Threads::parallel_reduce (ConstElemRange (mesh.pid_elements_begin(pid),
513 mesh.pid_elements_end(pid)),
514 sew);
515 return sew.weight();
516}

References mesh, and libMesh::Threads::parallel_reduce().

Referenced by libMesh::MeshTools::Modification::smooth(), total_weight(), and weight().