libMesh::MeshTools Namespace Reference

Namespaces

 Generation
 
 Modification
 
 Private
 

Classes

class  BoundingBox
 

Functions

void libmesh_assert_valid_dof_ids (const MeshBase &mesh)
 
template<>
void libmesh_assert_valid_procids< Elem > (const MeshBase &mesh)
 
template<>
void libmesh_assert_valid_procids< Node > (const MeshBase &mesh)
 
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)
 
void build_nodes_to_elem_map (const MeshBase &mesh, std::vector< std::vector< const Elem * > > &nodes_to_elem_map)
 
void find_boundary_nodes (const MeshBase &mesh, std::vector< bool > &on_boundary)
 
BoundingBox bounding_box (const MeshBase &mesh)
 
Sphere bounding_sphere (const MeshBase &mesh)
 
BoundingBox processor_bounding_box (const MeshBase &mesh, const processor_id_type pid)
 
Sphere processor_bounding_sphere (const MeshBase &mesh, const processor_id_type pid)
 
BoundingBox 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)
 
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)
 
void get_not_subactive_node_ids (const MeshBase &mesh, std::set< dof_id_type > &not_subactive_node_ids)
 
dof_id_type n_elem (const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
 
dof_id_type n_nodes (const MeshBase::const_node_iterator &begin, const MeshBase::const_node_iterator &end)
 
unsigned int max_level (const MeshBase &mesh)
 
void find_nodal_neighbors (const MeshBase &mesh, const Node &n, std::vector< std::vector< const Elem * > > &nodes_to_elem_map, std::vector< const Node * > &neighbors)
 
void find_hanging_nodes_and_parents (const MeshBase &mesh, std::map< dof_id_type, std::vector< dof_id_type > > &hanging_nodes)
 
void correct_node_proc_ids (MeshBase &, LocationMap< Node > &)
 
void libmesh_assert_no_links_to_elem (const MeshBase &mesh, const Elem *bad_elem)
 
void libmesh_assert_equal_n_systems (const MeshBase &mesh)
 
void libmesh_assert_old_dof_objects (const MeshBase &mesh)
 
void libmesh_assert_valid_node_pointers (const MeshBase &mesh)
 
void libmesh_assert_valid_remote_elems (const MeshBase &mesh)
 
void libmesh_assert_valid_elem_ids (const MeshBase &mesh)
 
void libmesh_assert_valid_amr_elem_ids (const MeshBase &mesh)
 
void libmesh_assert_connected_nodes (const MeshBase &mesh)
 
template<typename DofObjectSubclass >
void libmesh_assert_valid_procids (const MeshBase &mesh)
 
void libmesh_assert_valid_refinement_flags (const MeshBase &mesh)
 
void libmesh_assert_valid_refinement_tree (const MeshBase &mesh)
 
void libmesh_assert_valid_neighbors (const MeshBase &mesh)
 

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

MeshTools::BoundingBox libMesh::MeshTools::bounding_box ( const MeshBase mesh)
Returns
two points defining a cartesian box that bounds the mesh. The first entry in the pair is the mininum, the second is the maximim.

Definition at line 417 of file mesh_tools.C.

References libMesh::ParallelObject::comm(), libMesh::DofObject::invalid_processor_id, libMesh::libmesh_parallel_only(), libMesh::MeshBase::local_nodes_begin(), libMesh::MeshBase::local_nodes_end(), libMesh::Parallel::Communicator::max(), libMesh::Parallel::Communicator::min(), libMesh::Threads::parallel_reduce(), libMesh::MeshBase::pid_nodes_begin(), and libMesh::MeshBase::pid_nodes_end().

Referenced by libMesh::MetisPartitioner::_do_partition(), libMesh::MeshCommunication::assign_global_indices(), bounding_sphere(), libMesh::TreeNode< N >::bounds_point(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::TreeNode< N >::create_bounding_box(), libMesh::PointLocatorTree::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::TreeNode< N >::insert(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::TreeNode< N >::set_bounding_box(), libMesh::Tree< N >::Tree(), and libMesh::PostscriptIO::write().

418 {
419  // This function must be run on all processors at once
420  libmesh_parallel_only(mesh.comm());
421 
422  FindBBox find_bbox;
423 
425  mesh.local_nodes_end()),
426  find_bbox);
427 
428  // and the unpartitioned nodes
429  Threads::parallel_reduce (ConstNodeRange (mesh.pid_nodes_begin(DofObject::invalid_processor_id),
430  mesh.pid_nodes_end(DofObject::invalid_processor_id)),
431  find_bbox);
432 
433  // Compare the bounding boxes across processors
434  mesh.comm().min(find_bbox.min());
435  mesh.comm().max(find_bbox.max());
436 
437  return find_bbox.bbox();
438 }
Sphere libMesh::MeshTools::bounding_sphere ( const MeshBase mesh)

Same, but returns a sphere instead of a box.

Definition at line 443 of file mesh_tools.C.

References bounding_box(), and libMesh::Real.

444 {
445  BoundingBox bbox = bounding_box(mesh);
446 
447  const Real diag = (bbox.second - bbox.first).size();
448  const Point cent = (bbox.second + bbox.first)/2;
449 
450  return Sphere (cent, .5*diag);
451 }
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 350 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), end, libMesh::MeshBase::n_elem(), and libMesh::MeshBase::n_nodes().

Referenced by libMesh::VariationalMeshSmoother::readgr(), and libMesh::Tree< N >::Tree().

352 {
353  nodes_to_elem_map.resize (mesh.n_nodes());
354 
357 
358  for (; el != end; ++el)
359  for (unsigned int n=0; n<(*el)->n_nodes(); n++)
360  {
361  libmesh_assert_less ((*el)->node(n), nodes_to_elem_map.size());
362  libmesh_assert_less ((*el)->id(), mesh.n_elem());
363 
364  nodes_to_elem_map[(*el)->node(n)].push_back((*el)->id());
365  }
366 }
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 370 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), end, and libMesh::MeshBase::n_nodes().

372 {
373  nodes_to_elem_map.resize (mesh.n_nodes());
374 
377 
378  for (; el != end; ++el)
379  for (unsigned int n=0; n<(*el)->n_nodes(); n++)
380  {
381  libmesh_assert_less ((*el)->node(n), nodes_to_elem_map.size());
382 
383  nodes_to_elem_map[(*el)->node(n)].push_back(*el);
384  }
385 }
void libMesh::MeshTools::correct_node_proc_ids ( MeshBase mesh,
LocationMap< Node > &  loc_map 
)

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 890 of file mesh_tools.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::ParallelObject::comm(), libMesh::LocationMap< T >::empty(), libMesh::Elem::get_node(), libMesh::DofObject::invalid_processor_id, libMesh::DofObject::invalidate_processor_id(), libMesh::libmesh_assert(), libMesh::libmesh_parallel_only(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::Elem::n_nodes(), libMesh::MeshBase::nodes_begin(), libMesh::MeshBase::nodes_end(), and libMesh::DofObject::processor_id().

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

892 {
893  // This function must be run on all processors at once
894  libmesh_parallel_only(mesh.comm());
895 
896  // We'll need the new_nodes_map to answer other processors'
897  // requests. It should never be empty unless we don't have any
898  // nodes.
899  libmesh_assert(mesh.nodes_begin() == mesh.nodes_end() ||
900  !loc_map.empty());
901 
902  // Fix all nodes' processor ids. Coarsening may have left us with
903  // nodes which are no longer touched by any elements of the same
904  // processor id, and for DofMap to work we need to fix that.
905 
906  // In the first pass, invalidate processor ids for nodes on active
907  // elements. We avoid touching subactive-only nodes.
909  const MeshBase::element_iterator e_end = mesh.active_elements_end();
910  for (; e_it != e_end; ++e_it)
911  {
912  Elem *elem = *e_it;
913  for (unsigned int n=0; n != elem->n_nodes(); ++n)
914  {
915  Node *node = elem->get_node(n);
916  node->invalidate_processor_id();
917  }
918  }
919 
920  // In the second pass, find the lowest processor ids on active
921  // elements touching each node, and set the node processor id.
922  for (e_it = mesh.active_elements_begin(); e_it != e_end; ++e_it)
923  {
924  Elem *elem = *e_it;
925  processor_id_type proc_id = elem->processor_id();
926  for (unsigned int n=0; n != elem->n_nodes(); ++n)
927  {
928  Node *node = elem->get_node(n);
929  if (node->processor_id() == DofObject::invalid_processor_id ||
930  node->processor_id() > proc_id)
931  node->processor_id() = proc_id;
932  }
933  }
934 
935  // Those two passes will correct every node that touches a local
936  // element, but we can't be sure about nodes touching remote
937  // elements. Fix those now.
939  (mesh, loc_map);
940 }
void libMesh::MeshTools::elem_types ( const MeshBase mesh,
std::vector< ElemType > &  et 
)

Return a vector of all element types for the mesh. Implemented in terms of element_iterators.

Definition at line 523 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), and end.

Referenced by libMesh::LegacyXdrIO::write_mesh().

525 {
528 
529  // Automatically get the first type
530  et.push_back((*el)->type()); ++el;
531 
532  // Loop over the rest of the elements.
533  // If the current element type isn't in the
534  // vector, insert it.
535  for (; el != end; ++el)
536  if (!std::count(et.begin(), et.end(), (*el)->type()))
537  et.push_back((*el)->type());
538 }
void libMesh::MeshTools::find_boundary_nodes ( const MeshBase mesh,
std::vector< bool > &  on_boundary 
)

Calling this function on a 2D mesh will convert all the elements to triangles. QUAD4s will be converted to TRI3s, QUAD8s and QUAD9s will be converted to TRI6s. Fills the vector "on_boundary" with flags that tell whether each node is on the domain boundary (true)) or not (false).

Definition at line 389 of file mesh_tools.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, libMesh::MeshBase::n_nodes(), and side.

Referenced by libMesh::MeshTools::Modification::distort(), libMesh::VariationalMeshSmoother::readgr(), libMesh::LaplaceMeshSmoother::smooth(), and libMesh::MeshTools::Modification::smooth().

391 {
392  // Resize the vector which holds boundary nodes and fill with false.
393  on_boundary.resize(mesh.n_nodes());
394  std::fill(on_boundary.begin(),
395  on_boundary.end(),
396  false);
397 
398  // Loop over elements, find those on boundary, and
399  // mark them as true in on_boundary.
402 
403  for (; el != end; ++el)
404  for (unsigned int s=0; s<(*el)->n_neighbors(); s++)
405  if ((*el)->neighbor(s) == NULL) // on the boundary
406  {
407  const AutoPtr<Elem> side((*el)->build_side(s));
408 
409  for (unsigned int n=0; n<side->n_nodes(); n++)
410  on_boundary[side->node(n)] = true;
411  }
412 }
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 786 of file mesh_tools.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), end, libMesh::Elem::is_node_on_side(), libMesh::Elem::level(), libMesh::Elem::n_neighbors(), libMesh::Elem::n_sides(), libMesh::Elem::neighbor(), libMesh::Elem::node(), libMesh::Elem::parent(), libMeshEnums::QUAD4, libMesh::Elem::type(), and libMesh::Elem::which_neighbor_am_i().

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

787 {
790 
791  //Loop through all the elements
792  for (; it != end; ++it)
793  {
794  //Save it off for easier access
795  const Elem* elem = (*it);
796 
797  //Right now this only works for quad4's
798  //libmesh_assert_equal_to (elem->type(), libMeshEnums::QUAD4);
799  if(elem->type() == libMeshEnums::QUAD4)
800  {
801  //Loop over the sides looking for sides that have hanging nodes
802  //This code is inspired by compute_proj_constraints()
803  for (unsigned int s=0; s<elem->n_sides(); s++)
804  {
805  //If not a boundary node
806  if (elem->neighbor(s) != NULL)
807  {
808  // Get pointers to the element's neighbor.
809  const Elem* neigh = elem->neighbor(s);
810 
811  //Is there a coarser element next to this one?
812  if (neigh->level() < elem->level())
813  {
814  const Elem *ancestor = elem;
815  while (neigh->level() < ancestor->level())
816  ancestor = ancestor->parent();
817  unsigned int s_neigh = neigh->which_neighbor_am_i(ancestor);
818  libmesh_assert_less (s_neigh, neigh->n_neighbors());
819 
820  //Couple of helper uints...
821  unsigned int local_node1=0;
822  unsigned int local_node2=0;
823 
824  bool found_in_neighbor = false;
825 
826  //Find the two vertices that make up this side
827  while(!elem->is_node_on_side(local_node1++,s)) { }
828  local_node1--;
829 
830  //Start looking for the second one with the next node
831  local_node2=local_node1+1;
832 
833  //Find the other one
834  while(!elem->is_node_on_side(local_node2++,s)) { }
835  local_node2--;
836 
837  //Pull out their global ids:
838  dof_id_type node1 = elem->node(local_node1);
839  dof_id_type node2 = elem->node(local_node2);
840 
841  //Now find which node is present in the neighbor
842  //FIXME This assumes a level one rule!
843  //The _other_ one is the hanging node
844 
845  //First look for the first one
846  //FIXME could be streamlined a bit
847  for(unsigned int n=0;n<neigh->n_sides();n++)
848  {
849  if(neigh->node(n) == node1)
850  found_in_neighbor=true;
851  }
852 
853  dof_id_type hanging_node=0;
854 
855  if(!found_in_neighbor)
856  hanging_node=node1;
857  else //If it wasn't node1 then it must be node2!
858  hanging_node=node2;
859 
860  //Reset these for reuse
861  local_node1=0;
862  local_node2=0;
863 
864  //Find the first node that makes up the side in the neighbor (these should be the parent nodes)
865  while(!neigh->is_node_on_side(local_node1++,s_neigh)) { }
866  local_node1--;
867 
868  local_node2=local_node1+1;
869 
870  //Find the second node...
871  while(!neigh->is_node_on_side(local_node2++,s_neigh)) { }
872  local_node2--;
873 
874  //Save them if we haven't already found the parents for this one
875  if(hanging_nodes[hanging_node].size()<2)
876  {
877  hanging_nodes[hanging_node].push_back(neigh->node(local_node1));
878  hanging_nodes[hanging_node].push_back(neigh->node(local_node2));
879  }
880  }
881  }
882  }
883  }
884  }
885 }
void libMesh::MeshTools::find_nodal_neighbors ( const MeshBase mesh,
const Node n,
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 705 of file mesh_tools.C.

References libMesh::DofObject::id().

Referenced by libMesh::VariationalMeshSmoother::readgr().

708 {
709  dof_id_type global_id = n.id();
710 
711  //Iterators to iterate through the elements that include this node
712  std::vector<const Elem*>::const_iterator el = nodes_to_elem_map[global_id].begin();
713  std::vector<const Elem*>::const_iterator end_el = nodes_to_elem_map[global_id].end();
714 
715  unsigned int n_ed=0; // Number of edges on the element
716  unsigned int ed=0; // Current edge
717  unsigned int l_n=0; // Local node number
718  unsigned int o_n=0; // Other node on this edge
719 
720  //Assume we find a edge... then prove ourselves wrong...
721  bool found_edge=true;
722 
723  Node * node_to_save = NULL;
724 
725  //Look through the elements that contain this node
726  //find the local node id... then find the side that
727  //node lives on in the element
728  //next, look for the _other_ node on that side
729  //That other node is a "nodal_neighbor"... save it
730  for(;el != end_el;el++)
731  {
732  //We only care about active elements...
733  if((*el)->active())
734  {
735  n_ed=(*el)->n_edges();
736 
737  //Find the local node id
738  while(global_id != (*el)->node(l_n++)) { }
739  l_n--; //Hmmm... take the last one back off
740 
741  while(ed<n_ed)
742  {
743 
744  //Find the edge the node is on
745  while(found_edge && !(*el)->is_node_on_edge(l_n,ed++))
746  {
747  //This only happens if all the edges have already been found
748  if(ed>=n_ed)
749  found_edge=false;
750  }
751 
752  //Did we find one?
753  if(found_edge)
754  {
755  ed--; //Take the last one back off again
756 
757  //Now find the other node on that edge
758  while(!(*el)->is_node_on_edge(o_n++,ed) || global_id==(*el)->node(o_n-1)) { }
759  o_n--;
760 
761  //We've found one! Save it..
762  node_to_save=(*el)->get_node(o_n);
763 
764  //Search to see if we've already found this one
765  std::vector<const Node*>::const_iterator result = std::find(neighbors.begin(),neighbors.end(),node_to_save);
766 
767  //If we didn't find it and add it to the vector
768  if(result == neighbors.end())
769  neighbors.push_back(node_to_save);
770  }
771 
772  //Reset to look for another
773  o_n=0;
774 
775  //Keep looking for edges, node may be on more than one edge
776  ed++;
777  }
778 
779  //Reset to get ready for the next element
780  l_n=ed=0;
781  found_edge=true;
782  }
783  }
784 }
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 646 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::n_nodes(), libMesh::Elem::node(), and libMesh::Elem::subactive().

648 {
650  const MeshBase::const_element_iterator end_el = mesh.elements_end();
651  for( ; el != end_el; ++el)
652  {
653  const Elem* elem = (*el);
654  if(!elem->subactive())
655  for (unsigned int n=0; n<elem->n_nodes(); ++n)
656  not_subactive_node_ids.insert(elem->node(n));
657  }
658 }
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 ParallelMesh 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 1128 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::get_node(), libMesh::libmesh_assert(), libMesh::Elem::n_nodes(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

1129 {
1130  std::set<const Node*> used_nodes;
1131 
1132  const MeshBase::const_element_iterator el_end =
1133  mesh.elements_end();
1135  mesh.elements_begin(); el != el_end; ++el)
1136  {
1137  const Elem* elem = *el;
1138  libmesh_assert (elem);
1139 
1140  for (unsigned int n=0; n<elem->n_nodes(); ++n)
1141  used_nodes.insert(elem->get_node(n));
1142  }
1143 
1144  const MeshBase::const_node_iterator node_end = mesh.nodes_end();
1145 
1146  for (MeshBase::const_node_iterator node_it = mesh.nodes_begin();
1147  node_it != node_end; ++node_it)
1148  {
1149  Node *node = *node_it;
1150  libmesh_assert(node);
1151  libmesh_assert(used_nodes.count(node));
1152  }
1153 }
void libMesh::MeshTools::libmesh_assert_equal_n_systems ( const MeshBase mesh)

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

Definition at line 945 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::DofObject::n_systems(), libMesh::MeshBase::nodes_begin(), and libMesh::MeshBase::nodes_end().

946 {
948  mesh.elements_begin();
949  const MeshBase::const_element_iterator el_end =
950  mesh.elements_end();
951  if (el == el_end)
952  return;
953 
954  const unsigned int n_sys = (*el)->n_systems();
955 
956  for (; el != el_end; ++el)
957  {
958  const Elem *elem = *el;
959  libmesh_assert_equal_to (elem->n_systems(), n_sys);
960  }
961 
963  mesh.nodes_begin();
964  const MeshBase::const_node_iterator node_end =
965  mesh.nodes_end();
966 
967  if (node_it == node_end)
968  return;
969 
970  for (; node_it != node_end; ++node_it)
971  {
972  const Node *node = *node_it;
973  libmesh_assert_equal_to (node->n_systems(), n_sys);
974  }
975 }
void libMesh::MeshTools::libmesh_assert_no_links_to_elem ( const MeshBase mesh,
const Elem bad_elem 
)

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

Definition at line 1058 of file mesh_tools.C.

References libMesh::Elem::child(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::has_children(), libMesh::libmesh_assert(), libMesh::Elem::n_children(), libMesh::Elem::n_neighbors(), libMesh::Elem::neighbor(), and libMesh::Elem::parent().

1060 {
1061  const MeshBase::const_element_iterator el_end =
1062  mesh.elements_end();
1064  mesh.elements_begin(); el != el_end; ++el)
1065  {
1066  const Elem* elem = *el;
1067  libmesh_assert (elem);
1068  libmesh_assert_not_equal_to (elem->parent(), bad_elem);
1069  for (unsigned int n=0; n != elem->n_neighbors(); ++n)
1070  libmesh_assert_not_equal_to (elem->neighbor(n), bad_elem);
1071 #ifdef LIBMESH_ENABLE_AMR
1072  if (elem->has_children())
1073  for (unsigned int c=0; c != elem->n_children(); ++c)
1074  libmesh_assert_not_equal_to (elem->child(c), bad_elem);
1075 #endif
1076  }
1077 }
void libMesh::MeshTools::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. This is not expected to be true at all points within a simulation code.

Definition at line 979 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::get_node(), libMesh::DofObject::has_dofs(), libMesh::Elem::INACTIVE, libMesh::Elem::JUST_REFINED, libMesh::libmesh_assert(), libMesh::Elem::n_nodes(), libMesh::DofObject::old_dof_object, and libMesh::Elem::refinement_flag().

980 {
981 #ifdef LIBMESH_ENABLE_AMR
983  mesh.elements_begin();
984  const MeshBase::const_element_iterator el_end =
985  mesh.elements_end();
986 
987  for (; el != el_end; ++el)
988  {
989  const Elem *elem = *el;
990 
991  if (elem->refinement_flag() == Elem::JUST_REFINED ||
992  elem->refinement_flag() == Elem::INACTIVE)
993  continue;
994 
995  if (elem->has_dofs())
997 
998  for (unsigned int n=0; n != elem->n_nodes(); ++n)
999  {
1000  const Node *node = elem->get_node(n);
1001  if (node->has_dofs())
1003  }
1004  }
1005 #endif // LIBMESH_ENABLE_AMR
1006 }
void libMesh::MeshTools::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)

Definition at line 1106 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::Elem::parent(), and libMesh::DofObject::processor_id().

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

1107 {
1108  const MeshBase::const_element_iterator el_end =
1109  mesh.elements_end();
1111  mesh.elements_begin(); el != el_end; ++el)
1112  {
1113  const Elem* elem = *el;
1114  libmesh_assert (elem);
1115 
1116  const Elem* parent = elem->parent();
1117 
1118  if (parent)
1119  {
1120  libmesh_assert_greater_equal (elem->id(), parent->id());
1121  libmesh_assert_greater_equal (elem->processor_id(), parent->processor_id());
1122  }
1123  }
1124 }
void libMesh::MeshTools::libmesh_assert_valid_dof_ids ( const MeshBase mesh)

A function for verifying that degree of freedom indexing matches across processors.

Definition at line 1159 of file mesh_tools.C.

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

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

1160 {
1161  if (mesh.n_processors() == 1)
1162  return;
1163 
1164  libmesh_parallel_only(mesh.comm());
1165 
1166  dof_id_type pmax_elem_id = mesh.max_elem_id();
1167  mesh.comm().max(pmax_elem_id);
1168 
1169  for (dof_id_type i=0; i != pmax_elem_id; ++i)
1170  assert_semiverify_dofobj(mesh.comm(),
1171  mesh.query_elem(i));
1172 
1173  dof_id_type pmax_node_id = mesh.max_node_id();
1174  mesh.comm().max(pmax_node_id);
1175 
1176  for (dof_id_type i=0; i != pmax_node_id; ++i)
1177  assert_semiverify_dofobj(mesh.comm(),
1178  mesh.query_node_ptr(i));
1179 }
void libMesh::MeshTools::libmesh_assert_valid_elem_ids ( const MeshBase mesh)

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

Definition at line 1081 of file mesh_tools.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::DofObject::id(), libMesh::libmesh_assert(), and libMesh::DofObject::processor_id().

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

1082 {
1083  processor_id_type lastprocid = 0;
1084  dof_id_type lastelemid = 0;
1085 
1086  const MeshBase::const_element_iterator el_end =
1087  mesh.active_elements_end();
1089  mesh.active_elements_begin(); el != el_end; ++el)
1090  {
1091  const Elem* elem = *el;
1092  libmesh_assert (elem);
1093  processor_id_type elemprocid = elem->processor_id();
1094  dof_id_type elemid = elem->id();
1095 
1096  libmesh_assert_greater_equal (elemid, lastelemid);
1097  libmesh_assert_greater_equal (elemprocid, lastprocid);
1098 
1099  lastelemid = elemid;
1100  lastprocid = elemprocid;
1101  }
1102 }
void libMesh::MeshTools::libmesh_assert_valid_neighbors ( const MeshBase mesh)

A function for verifying that neighbor connectivity is correct (each element is a neighbor of or descendant of a neighbor of its neighbors)

Definition at line 1427 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::libmesh_assert(), and libMesh::Elem::libmesh_assert_valid_neighbors().

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

1428 {
1429  const MeshBase::const_element_iterator el_end = mesh.elements_end();
1431  el != el_end; ++el)
1432  {
1433  const Elem* elem = *el;
1434  libmesh_assert (elem);
1436  }
1437 }
void libMesh::MeshTools::libmesh_assert_valid_node_pointers ( const MeshBase mesh)

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

Definition at line 1010 of file mesh_tools.C.

References libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::libmesh_assert(), libMesh::Elem::libmesh_assert_valid_node_pointers(), libMesh::Elem::n_neighbors(), libMesh::Elem::neighbor(), libMesh::Elem::parent(), and libMesh::remote_elem.

1011 {
1012  const MeshBase::const_element_iterator el_end =
1013  mesh.elements_end();
1015  mesh.elements_begin(); el != el_end; ++el)
1016  {
1017  const Elem* elem = *el;
1018  libmesh_assert (elem);
1019  while (elem)
1020  {
1022  for (unsigned int n=0; n != elem->n_neighbors(); ++n)
1023  if (elem->neighbor(n) &&
1024  elem->neighbor(n) != remote_elem)
1026 
1027  libmesh_assert_not_equal_to (elem->parent(), remote_elem);
1028  elem = elem->parent();
1029  }
1030  }
1031 }
template<typename DofObjectSubclass >
void libMesh::MeshTools::libmesh_assert_valid_procids ( const MeshBase &  mesh)

A function for verifying that processor assignment is self-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), and verifying that assignment is consistent (every processor agrees on the processor id of each dof object it can see)

template<>
void libMesh::MeshTools::libmesh_assert_valid_procids< Elem > ( const MeshBase mesh)

Definition at line 1182 of file mesh_tools.C.

References libMesh::Elem::active(), libMesh::Elem::child(), libMesh::ParallelObject::comm(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::has_children(), libMesh::libmesh_assert(), libMesh::libmesh_parallel_only(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::Elem::n_children(), libMesh::ParallelObject::n_processors(), libMesh::Elem::parent(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::MeshBase::query_elem(), libMesh::remote_elem, and libMesh::Elem::subactive().

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

1183 {
1184  if (mesh.n_processors() == 1)
1185  return;
1186 
1187  libmesh_parallel_only(mesh.comm());
1188 
1189  // We want this test to be valid even when called even after nodes
1190  // have been added asynchonously but before they're renumbered
1191  dof_id_type parallel_max_elem_id = mesh.max_elem_id();
1192  mesh.comm().max(parallel_max_elem_id);
1193 
1194  // Check processor ids for consistency between processors
1195 
1196  for (dof_id_type i=0; i != parallel_max_elem_id; ++i)
1197  {
1198  const Elem *elem = mesh.query_elem(i);
1199 
1200  processor_id_type min_id =
1201  elem ? elem->processor_id() :
1203  mesh.comm().min(min_id);
1204 
1205  processor_id_type max_id =
1206  elem ? elem->processor_id() :
1208  mesh.comm().max(max_id);
1209 
1210  if (elem)
1211  {
1212  libmesh_assert_equal_to (min_id, elem->processor_id());
1213  libmesh_assert_equal_to (max_id, elem->processor_id());
1214  }
1215 
1216  if (min_id == mesh.processor_id())
1217  libmesh_assert(elem);
1218  }
1219 
1220  // If we're adaptively refining, check processor ids for consistency
1221  // between parents and children.
1222 #ifdef LIBMESH_ENABLE_AMR
1223 
1224  // Ancestor elements we won't worry about, but subactive and active
1225  // elements ought to have parents with consistent processor ids
1226 
1227  const MeshBase::const_element_iterator el_end =
1228  mesh.elements_end();
1230  mesh.elements_begin(); el != el_end; ++el)
1231  {
1232  const Elem *elem = *el;
1233  libmesh_assert(elem);
1234 
1235  if (!elem->active() && !elem->subactive())
1236  continue;
1237 
1238  const Elem *parent = elem->parent();
1239 
1240  if (parent)
1241  {
1242  libmesh_assert(parent->has_children());
1243  processor_id_type parent_procid = parent->processor_id();
1244  bool matching_child_id = false;
1245  for (unsigned int c = 0; c != parent->n_children(); ++c)
1246  {
1247  const Elem* child = parent->child(c);
1248  libmesh_assert(child);
1249 
1250  // If we've got a remote_elem then we don't know whether
1251  // it's responsible for the parent's processor id; all
1252  // we can do is assume it is and let its processor fail
1253  // an assert if there's something wrong.
1254  if (child == remote_elem ||
1255  child->processor_id() == parent_procid)
1256  matching_child_id = true;
1257  }
1258  libmesh_assert(matching_child_id);
1259  }
1260  }
1261 #endif
1262 }
template<>
void libMesh::MeshTools::libmesh_assert_valid_procids< Node > ( const MeshBase mesh)

Definition at line 1267 of file mesh_tools.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::ParallelObject::comm(), libMesh::Elem::get_node(), libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::libmesh_parallel_only(), libMesh::MeshBase::local_nodes_begin(), libMesh::MeshBase::local_nodes_end(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_node_id(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::Elem::n_nodes(), libMesh::ParallelObject::n_processors(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), and libMesh::MeshBase::query_node_ptr().

Referenced by libMesh::MeshRefinement::_coarsen_elements(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), and libMesh::Partitioner::set_node_processor_ids().

1268 {
1269  if (mesh.n_processors() == 1)
1270  return;
1271 
1272  libmesh_parallel_only(mesh.comm());
1273 
1274  // We want this test to be valid even when called even after nodes
1275  // have been added asynchonously but before they're renumbered
1276  dof_id_type parallel_max_node_id = mesh.max_node_id();
1277  mesh.comm().max(parallel_max_node_id);
1278 
1279  // Check processor ids for consistency between processors
1280 
1281  for (dof_id_type i=0; i != parallel_max_node_id; ++i)
1282  {
1283  const Node *node = mesh.query_node_ptr(i);
1284 
1285  processor_id_type min_id =
1286  node ? node->processor_id() :
1288  mesh.comm().min(min_id);
1289 
1290  processor_id_type max_id =
1291  node ? node->processor_id() :
1293  mesh.comm().max(max_id);
1294 
1295  if (node)
1296  {
1297  libmesh_assert_equal_to (min_id, node->processor_id());
1298  libmesh_assert_equal_to (max_id, node->processor_id());
1299  }
1300 
1301  if (min_id == mesh.processor_id())
1302  libmesh_assert(node);
1303  }
1304 
1305  std::vector<bool> node_touched_by_me(parallel_max_node_id, false);
1306 
1307  const MeshBase::const_element_iterator el_end =
1310  mesh.active_local_elements_begin(); el != el_end; ++el)
1311  {
1312  const Elem* elem = *el;
1313  libmesh_assert (elem);
1314 
1315  for (unsigned int i=0; i != elem->n_nodes(); ++i)
1316  {
1317  const Node *node = elem->get_node(i);
1318  dof_id_type nodeid = node->id();
1319  node_touched_by_me[nodeid] = true;
1320  }
1321  }
1322  std::vector<bool> node_touched_by_anyone(node_touched_by_me);
1323  mesh.comm().max(node_touched_by_anyone);
1324 
1325  const MeshBase::const_node_iterator nd_end = mesh.local_nodes_end();
1327  nd != nd_end; ++nd)
1328  {
1329  const Node *node = *nd;
1330  libmesh_assert(node);
1331 
1332  dof_id_type nodeid = node->id();
1333  libmesh_assert(!node_touched_by_anyone[nodeid] ||
1334  node_touched_by_me[nodeid]);
1335  }
1336 }
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 1343 of file mesh_tools.C.

References libMesh::ParallelObject::comm(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::libmesh_parallel_only(), libMesh::MeshBase::max_elem_id(), libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::Elem::p_refinement_flag(), and libMesh::Elem::refinement_flag().

1344 {
1345  libmesh_parallel_only(mesh.comm());
1346  if (mesh.n_processors() == 1)
1347  return;
1348 
1349  std::vector<unsigned char> my_elem_h_state(mesh.max_elem_id(), 255);
1350  std::vector<unsigned char> my_elem_p_state(mesh.max_elem_id(), 255);
1351 
1352  const MeshBase::const_element_iterator el_end =
1353  mesh.elements_end();
1355  mesh.elements_begin(); el != el_end; ++el)
1356  {
1357  const Elem* elem = *el;
1358  libmesh_assert (elem);
1359  dof_id_type elemid = elem->id();
1360 
1361  my_elem_h_state[elemid] =
1362  static_cast<unsigned char>(elem->refinement_flag());
1363 
1364  my_elem_p_state[elemid] =
1365  static_cast<unsigned char>(elem->p_refinement_flag());
1366  }
1367  std::vector<unsigned char> min_elem_h_state(my_elem_h_state);
1368  mesh.comm().min(min_elem_h_state);
1369 
1370  std::vector<unsigned char> min_elem_p_state(my_elem_p_state);
1371  mesh.comm().min(min_elem_p_state);
1372 
1373  for (dof_id_type i=0; i!= mesh.max_elem_id(); ++i)
1374  {
1375  libmesh_assert(my_elem_h_state[i] == 255 ||
1376  my_elem_h_state[i] == min_elem_h_state[i]);
1377  libmesh_assert(my_elem_p_state[i] == 255 ||
1378  my_elem_p_state[i] == min_elem_p_state[i]);
1379  }
1380 }
void libMesh::MeshTools::libmesh_assert_valid_refinement_tree ( const MeshBase mesh)

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

Definition at line 1390 of file mesh_tools.C.

References libMesh::Elem::active(), libMesh::Elem::ancestor(), libMesh::Elem::child(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Elem::has_children(), libMesh::libmesh_assert(), libMesh::Elem::n_children(), libMesh::Elem::parent(), libMesh::remote_elem, and libMesh::Elem::subactive().

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

1391 {
1392  const MeshBase::const_element_iterator el_end =
1393  mesh.elements_end();
1395  mesh.elements_begin(); el != el_end; ++el)
1396  {
1397  const Elem *elem = *el;
1398  libmesh_assert(elem);
1399  if (elem->has_children())
1400  for (unsigned int n=0; n != elem->n_children(); ++n)
1401  {
1402  libmesh_assert(elem->child(n));
1403  if (elem->child(n) != remote_elem)
1404  libmesh_assert_equal_to (elem->child(n)->parent(), elem);
1405  }
1406  if (elem->active())
1407  {
1408  libmesh_assert(!elem->ancestor());
1409  libmesh_assert(!elem->subactive());
1410  }
1411  else if (elem->ancestor())
1412  {
1413  libmesh_assert(!elem->subactive());
1414  }
1415  else
1416  libmesh_assert(elem->subactive());
1417  }
1418 }
void libMesh::MeshTools::libmesh_assert_valid_remote_elems ( const MeshBase mesh)

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

Definition at line 1034 of file mesh_tools.C.

References libMesh::Elem::child(), libMesh::libmesh_assert(), libMesh::MeshBase::local_elements_begin(), libMesh::MeshBase::local_elements_end(), libMesh::Elem::n_children(), libMesh::Elem::n_neighbors(), libMesh::Elem::neighbor(), libMesh::Elem::parent(), and libMesh::remote_elem.

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

1035 {
1036  const MeshBase::const_element_iterator el_end =
1037  mesh.local_elements_end();
1039  mesh.local_elements_begin(); el != el_end; ++el)
1040  {
1041  const Elem* elem = *el;
1042  libmesh_assert (elem);
1043  for (unsigned int n=0; n != elem->n_neighbors(); ++n)
1044  libmesh_assert_not_equal_to (elem->neighbor(n), remote_elem);
1045 #ifdef LIBMESH_ENABLE_AMR
1046  const Elem* parent = elem->parent();
1047  if (parent)
1048  {
1049  libmesh_assert_not_equal_to (parent, remote_elem);
1050  for (unsigned int c=0; c != elem->n_children(); ++c)
1051  libmesh_assert_not_equal_to (parent->child(c), remote_elem);
1052  }
1053 #endif
1054  }
1055 }
unsigned int libMesh::MeshTools::max_level ( const MeshBase &  mesh)
dof_id_type libMesh::MeshTools::n_active_elem_of_type ( const MeshBase mesh,
const ElemType  type 
)

Return the number of active elements of type type. Implemented in terms of active_type_element_iterators.

Definition at line 551 of file mesh_tools.C.

References libMesh::MeshBase::active_type_elements_begin(), and libMesh::MeshBase::active_type_elements_end().

Referenced by libMesh::DivaIO::write_stream().

553 {
554  return static_cast<dof_id_type>(std::distance(mesh.active_type_elements_begin(type),
555  mesh.active_type_elements_end (type)));
556 }
unsigned int libMesh::MeshTools::n_active_levels ( const MeshBase mesh)

Return 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 maxxing in parallel.

Definition at line 590 of file mesh_tools.C.

References libMesh::ParallelObject::comm(), libMesh::libmesh_parallel_only(), std::max(), libMesh::Parallel::Communicator::max(), n_active_local_levels(), libMesh::MeshBase::unpartitioned_elements_begin(), and libMesh::MeshBase::unpartitioned_elements_end().

Referenced by libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::write_connectivity(), and libMesh::XdrIO::write_serialized_connectivity().

591 {
592  libmesh_parallel_only(mesh.comm());
593 
594  unsigned int nl = MeshTools::n_active_local_levels(mesh);
595 
598  const MeshBase::const_element_iterator end_el =
600 
601  for( ; el != end_el; ++el)
602  if ((*el)->active())
603  nl = std::max((*el)->level() + 1, nl);
604 
605  mesh.comm().max(nl);
606  return nl;
607 }
unsigned int libMesh::MeshTools::n_active_local_levels ( const MeshBase mesh)

Return 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 575 of file mesh_tools.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), std::max(), and max_level().

Referenced by n_active_levels().

576 {
577  unsigned int max_level = 0;
578 
581 
582  for( ; el != end_el; ++el)
583  max_level = std::max((*el)->level(), max_level);
584 
585  return max_level + 1;
586 }
dof_id_type libMesh::MeshTools::n_elem_of_type ( const MeshBase mesh,
const ElemType  type 
)

Return the number of elements of type type. Implemented in terms of type_element_iterators.

Definition at line 542 of file mesh_tools.C.

References libMesh::MeshBase::type_elements_begin(), and libMesh::MeshBase::type_elements_end().

544 {
545  return static_cast<dof_id_type>(std::distance(mesh.type_elements_begin(type),
546  mesh.type_elements_end (type)));
547 }
unsigned int libMesh::MeshTools::n_levels ( const MeshBase mesh)

Return the number of levels of refinement in the mesh. Implemented by looping over all the local elements and finding the maximum level, then summing in parallel.

Definition at line 626 of file mesh_tools.C.

References libMesh::ParallelObject::comm(), libMesh::libmesh_parallel_only(), std::max(), libMesh::Parallel::Communicator::max(), n_local_levels(), libMesh::MeshBase::unpartitioned_elements_begin(), and libMesh::MeshBase::unpartitioned_elements_end().

Referenced by libMesh::MeshCommunication::delete_remote_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::LegacyXdrIO::read_mesh(), libMesh::MeshTools::Modification::smooth(), and libMesh::LegacyXdrIO::write_mesh().

627 {
628  libmesh_parallel_only(mesh.comm());
629 
630  unsigned int nl = MeshTools::n_local_levels(mesh);
631 
634  const MeshBase::const_element_iterator end_el =
636 
637  for( ; el != end_el; ++el)
638  nl = std::max((*el)->level() + 1, nl);
639 
640  mesh.comm().max(nl);
641  return nl;
642 }
unsigned int libMesh::MeshTools::n_local_levels ( const MeshBase mesh)

Return 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 611 of file mesh_tools.C.

References libMesh::MeshBase::local_elements_begin(), libMesh::MeshBase::local_elements_end(), std::max(), and max_level().

Referenced by n_levels().

612 {
613  unsigned int max_level = 0;
614 
617 
618  for( ; el != end_el; ++el)
619  max_level = std::max((*el)->level(), max_level);
620 
621  return max_level + 1;
622 }
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 670 of file mesh_tools.C.

Referenced by libMesh::CheckpointIO::write_nodes().

672 {
673  return std::distance(begin, end);
674 }
dof_id_type libMesh::MeshTools::n_non_subactive_elem_of_type_at_level ( const MeshBase mesh,
const ElemType  type,
const unsigned int  level 
)

Return 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 returns the std::distance between them.

Definition at line 558 of file mesh_tools.C.

References end, libMesh::MeshBase::type_elements_begin(), and libMesh::MeshBase::type_elements_end().

Referenced by libMesh::LegacyXdrIO::write_mesh().

561 {
562  dof_id_type cnt = 0;
563  // iterate over the elements of the specified type
566 
567  for(; el!=end; ++el)
568  if( ((*el)->level() == level) && !(*el)->subactive())
569  cnt++;
570 
571  return cnt;
572 }
unsigned int libMesh::MeshTools::n_p_levels ( const MeshBase mesh)

Return 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 678 of file mesh_tools.C.

References libMesh::ParallelObject::comm(), libMesh::libmesh_parallel_only(), libMesh::MeshBase::local_elements_begin(), libMesh::MeshBase::local_elements_end(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::unpartitioned_elements_begin(), and libMesh::MeshBase::unpartitioned_elements_end().

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

679 {
680  libmesh_parallel_only(mesh.comm());
681 
682  unsigned int max_p_level = 0;
683 
684  // first my local elements
686  el = mesh.local_elements_begin(),
687  end_el = mesh.local_elements_end();
688 
689  for( ; el != end_el; ++el)
690  max_p_level = std::max((*el)->p_level(), max_p_level);
691 
692  // then any unpartitioned objects
693  el = mesh.unpartitioned_elements_begin();
694  end_el = mesh.unpartitioned_elements_end();
695 
696  for( ; el != end_el; ++el)
697  max_p_level = std::max((*el)->p_level(), max_p_level);
698 
699  mesh.comm().max(max_p_level);
700  return max_p_level + 1;
701 }
MeshTools::BoundingBox libMesh::MeshTools::processor_bounding_box ( const MeshBase mesh,
const processor_id_type  pid 
)
Returns
two points defining a cartesian box that bounds the elements belonging to processor pid.

Definition at line 456 of file mesh_tools.C.

References libMesh::ParallelObject::n_processors(), libMesh::Threads::parallel_reduce(), libMesh::MeshBase::pid_elements_begin(), and libMesh::MeshBase::pid_elements_end().

Referenced by processor_bounding_sphere().

458 {
459  libmesh_assert_less (pid, mesh.n_processors());
460 
461  FindBBox find_bbox;
462 
464  mesh.pid_elements_end(pid)),
465  find_bbox);
466 
467  return find_bbox.bbox();
468 }
Sphere libMesh::MeshTools::processor_bounding_sphere ( const MeshBase mesh,
const processor_id_type  pid 
)

Same, but returns a sphere instead of a box.

Definition at line 473 of file mesh_tools.C.

References processor_bounding_box(), and libMesh::Real.

475 {
476  BoundingBox bbox = processor_bounding_box(mesh,pid);
477 
478  const Real diag = (bbox.second - bbox.first).size();
479  const Point cent = (bbox.second + bbox.first)/2;
480 
481  return Sphere (cent, .5*diag);
482 }
MeshTools::BoundingBox libMesh::MeshTools::subdomain_bounding_box ( const MeshBase mesh,
const subdomain_id_type  sid 
)
Returns
two points defining a Cartesian box that bounds the elements belonging to subdomain sid.

Definition at line 487 of file mesh_tools.C.

References libMesh::MeshBase::elem(), std::max(), std::min(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_nodes(), libMesh::Elem::node(), libMesh::MeshBase::point(), libMesh::MeshBase::spatial_dimension(), and libMesh::Elem::subdomain_id().

Referenced by subdomain_bounding_sphere().

489 {
490  libmesh_assert_not_equal_to (mesh.n_nodes(), 0);
491 
492  Point min( 1.e30, 1.e30, 1.e30);
493  Point max(-1.e30, -1.e30, -1.e30);
494 
495  for (unsigned int e=0; e<mesh.n_elem(); e++)
496  if (mesh.elem(e)->subdomain_id() == sid)
497  for (unsigned int n=0; n<mesh.elem(e)->n_nodes(); n++)
498  for (unsigned int i=0; i<mesh.spatial_dimension(); i++)
499  {
500  min(i) = std::min(min(i), mesh.point(mesh.elem(e)->node(n))(i));
501  max(i) = std::max(max(i), mesh.point(mesh.elem(e)->node(n))(i));
502  }
503 
504  return BoundingBox (min, max);
505 }
Sphere libMesh::MeshTools::subdomain_bounding_sphere ( const MeshBase mesh,
const subdomain_id_type  sid 
)

Same, but returns a sphere instead of a box.

Definition at line 510 of file mesh_tools.C.

References libMesh::Real, and subdomain_bounding_box().

512 {
513  BoundingBox bbox = subdomain_bounding_box(mesh,sid);
514 
515  const Real diag = (bbox.second - bbox.first).size();
516  const Point cent = (bbox.second + bbox.first)/2;
517 
518  return Sphere (cent, .5*diag);
519 }
dof_id_type libMesh::MeshTools::total_weight ( const MeshBase mesh)

This function returns the sum over all the elemenents 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 315 of file mesh_tools.C.

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

Referenced by libMesh::LegacyXdrIO::write_mesh().

316 {
317  if (!mesh.is_serial())
318  {
319  libmesh_parallel_only(mesh.comm());
321  mesh.comm().sum(weight);
322  dof_id_type unpartitioned_weight =
323  MeshTools::weight (mesh, DofObject::invalid_processor_id);
324  return weight + unpartitioned_weight;
325  }
326 
327  SumElemWeight sew;
328 
330  mesh.elements_end()),
331  sew);
332  return sew.weight();
333 
334 }
dof_id_type libMesh::MeshTools::weight ( const MeshBase mesh,
const processor_id_type  pid 
)

This function returns the sum over all the elemenents 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 338 of file mesh_tools.C.

References libMesh::Threads::parallel_reduce(), libMesh::MeshBase::pid_elements_begin(), and libMesh::MeshBase::pid_elements_end().

Referenced by libMesh::QGrundmann_Moller::gm_rule(), libMesh::FE< Dim, T >::init_shape_functions(), libMesh::InfFE< friend_Dim, friend_T_radial, friend_T_map >::init_shape_functions(), libMesh::FEXYZ< Dim >::init_shape_functions(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::MeshTools::Modification::smooth(), total_weight(), and weight().

339 {
340  SumElemWeight sew;
341 
343  mesh.pid_elements_end(pid)),
344  sew);
345  return sew.weight();
346 }
dof_id_type libMesh::MeshTools::weight ( const MeshBase &  mesh)
inline

Definition at line 135 of file mesh_tools.h.

References libMesh::ParallelObject::processor_id(), and weight().

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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:33 UTC

Hosted By:
SourceForge.net Logo