libMesh
Classes | Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
libMesh::MeshRefinement Class Reference

This is the MeshRefinement class. More...

#include <mesh_refinement.h>

Inheritance diagram for libMesh::MeshRefinement:
[legend]

Classes

class  ElementFlagging
 Abstract base class to be used for user-specified element flagging. More...
 

Public Member Functions

 MeshRefinement (MeshBase &mesh)
 Constructor. More...
 
void set_periodic_boundaries_ptr (PeriodicBoundaries *pb_ptr)
 Sets the PeriodicBoundaries pointer. More...
 
 ~MeshRefinement ()
 Destructor. More...
 
void clear ()
 Deletes all the data that are currently stored. More...
 
void flag_elements_by_error_fraction (const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
 Flags elements for coarsening and refinement based on the computed error passed in error_per_cell. More...
 
void flag_elements_by_error_tolerance (const ErrorVector &error_per_cell)
 Flags elements for coarsening and refinement based on the computed error passed in error_per_cell. More...
 
bool flag_elements_by_nelem_target (const ErrorVector &error_per_cell)
 Flags elements for coarsening and refinement based on the computed error passed in error_per_cell. More...
 
void flag_elements_by_elem_fraction (const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
 Flags elements for coarsening and refinement based on the computed error passed in error_per_cell. More...
 
void flag_elements_by_mean_stddev (const ErrorVector &error_per_cell, const Real refine_fraction=1.0, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
 Flags elements for coarsening and refinement based on the computed error passed in error_per_cell. More...
 
void flag_elements_by (ElementFlagging &element_flagging)
 Flag elements based on a function object. More...
 
void switch_h_to_p_refinement ()
 Takes a mesh whose elements are flagged for h refinement and coarsening, and switches those flags to request p refinement and coarsening instead. More...
 
void add_p_to_h_refinement ()
 Takes a mesh whose elements are flagged for h refinement and coarsening, and adds flags to request p refinement and coarsening of the same elements. More...
 
bool refine_and_coarsen_elements ()
 Refines and coarsens user-requested elements. More...
 
bool coarsen_elements ()
 Only coarsens the user-requested elements. More...
 
bool refine_elements ()
 Only refines the user-requested elements. More...
 
void uniformly_refine (unsigned int n=1)
 Uniformly refines the mesh n times. More...
 
void uniformly_coarsen (unsigned int n=1)
 Attempts to uniformly coarsen the mesh n times. More...
 
void uniformly_p_refine (unsigned int n=1)
 Uniformly p refines the mesh n times. More...
 
void uniformly_p_coarsen (unsigned int n=1)
 Attempts to uniformly p coarsen the mesh n times. More...
 
void clean_refinement_flags ()
 Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh. More...
 
bool test_level_one (bool libmesh_assert_yes=false)
 
bool test_unflagged (bool libmesh_assert_yes=false)
 
Nodeadd_node (Elem &parent, unsigned int child, unsigned int node, processor_id_type proc_id)
 Add a node to the mesh. More...
 
Elemadd_elem (Elem *elem)
 Adds the element elem to the mesh. More...
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
bool & coarsen_by_parents ()
 If coarsen_by_parents is true, complete groups of sibling elements (elements with the same parent) will be flagged for coarsening. More...
 
Realrefine_fraction ()
 The refine_fraction sets either a desired target or a desired maximum number of elements to flag for refinement, depending on which flag_elements_by method is called. More...
 
Realcoarsen_fraction ()
 The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for coarsening, depending on which flag_elements_by method is called. More...
 
unsigned intmax_h_level ()
 The max_h_level is the greatest refinement level an element should reach. More...
 
Realcoarsen_threshold ()
 The coarsen_threshold provides hysteresis in AMR/C strategies. More...
 
dof_id_typenelem_target ()
 If nelem_target is set to a nonzero value, methods like flag_elements_by_nelem_target() will attempt to keep the number of active elements in the mesh close to nelem_target. More...
 
Realabsolute_global_tolerance ()
 If absolute_global_tolerance is set to a nonzero value, methods like flag_elements_by_global_tolerance() will attempt to reduce the global error of the mesh (defined as the square root of the sum of the squares of the errors on active elements) to below this tolerance. More...
 
unsigned char & face_level_mismatch_limit ()
 If face_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two face neighbors will not differ by more than that limit. More...
 
unsigned char & edge_level_mismatch_limit ()
 If edge_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two edge neighbors will not differ by more than that limit. More...
 
unsigned char & node_level_mismatch_limit ()
 If node_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two nodal neighbors will not differ by more than that limit. More...
 
signed char & overrefined_boundary_limit ()
 If overrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will produce meshes in which the refinement level of a boundary element is no more than that many levels greater than the level of any of its interior neighbors. More...
 
signed char & underrefined_boundary_limit ()
 If underrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will produce meshes in which the refinement level of an element is no more than that many levels greater than the level of any boundary elements on its sides. More...
 
bool make_flags_parallel_consistent ()
 Copy refinement flags on ghost elements from their local processors. More...
 
bool get_enforce_mismatch_limit_prior_to_refinement ()
 
void set_enforce_mismatch_limit_prior_to_refinement (bool enforce)
 Set _enforce_mismatch_limit_prior_to_refinement option. More...
 
bool & enforce_mismatch_limit_prior_to_refinement ()
 Get/set the _enforce_mismatch_limit_prior_to_refinement flag. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Protected Attributes

const Parallel::Communicator_communicator
 

Private Types

enum  NeighborType { POINT, EDGE }
 This helper function enforces the desired mismatch limits prior to refinement. More...
 

Private Member Functions

 MeshRefinement (const MeshRefinement &)
 
MeshRefinementoperator= (const MeshRefinement &)
 
bool _coarsen_elements ()
 Coarsens user-requested elements. More...
 
bool _refine_elements ()
 Refines user-requested elements. More...
 
void _smooth_flags (bool refining, bool coarsening)
 Smooths refinement flags according to current settings. More...
 
bool limit_level_mismatch_at_node (const unsigned int max_mismatch)
 This algorithm restricts the maximum level mismatch at any node in the mesh. More...
 
bool limit_level_mismatch_at_edge (const unsigned int max_mismatch)
 
bool limit_overrefined_boundary (const signed char max_mismatch)
 
bool limit_underrefined_boundary (const signed char max_mismatch)
 
bool eliminate_unrefined_patches ()
 This algorithm selects an element for refinement if all of its neighbors are (or will be) refined. More...
 
void create_parent_error_vector (const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
 Calculates the error on all coarsenable parents. More...
 
void update_nodes_map ()
 Updates the _new_nodes_map. More...
 
bool make_coarsening_compatible ()
 Take user-specified coarsening flags and augment them so that level-one dependency is satisfied. More...
 
bool make_refinement_compatible ()
 Take user-specified refinement flags and augment them so that level-one dependency is satisfied. More...
 
Elemtopological_neighbor (Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
 Local dispatch function for getting the correct topological neighbor from the Elem class. More...
 
bool has_topological_neighbor (const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
 Local dispatch function for checking the correct has_neighbor function from the Elem class. More...
 
bool enforce_mismatch_limit_prior_to_refinement (Elem *elem, NeighborType nt, unsigned max_mismatch)
 

Private Attributes

TopologyMap _new_nodes_map
 Data structure that holds the new nodes information. More...
 
MeshBase_mesh
 Reference to the mesh. More...
 
bool _use_member_parameters
 For backwards compatibility, we initialize this as false and then set it to true if the user uses any of the refinement parameter accessor functions. More...
 
bool _coarsen_by_parents
 Refinement parameter values. More...
 
Real _refine_fraction
 
Real _coarsen_fraction
 
unsigned int _max_h_level
 
Real _coarsen_threshold
 
dof_id_type _nelem_target
 
Real _absolute_global_tolerance
 
unsigned char _face_level_mismatch_limit
 
unsigned char _edge_level_mismatch_limit
 
unsigned char _node_level_mismatch_limit
 
signed char _overrefined_boundary_limit
 
signed char _underrefined_boundary_limit
 
bool _enforce_mismatch_limit_prior_to_refinement
 This option enforces the mismatch level prior to refinement by checking if refining any element marked for refinement would cause a mismatch greater than the limit. More...
 
PeriodicBoundaries_periodic_boundaries
 

Detailed Description

This is the MeshRefinement class.

This class implements adaptive mesh refinement algorithms for a MeshBase.

Author
Benjamin S. Kirk
Date
2002-2007 Responsible for mesh refinement algorithms and data.

Definition at line 58 of file mesh_refinement.h.

Member Enumeration Documentation

This helper function enforces the desired mismatch limits prior to refinement.

It is called from the MeshRefinement::limit_level_mismatch_at_edge() and MeshRefinement::limit_level_mismatch_at_node() functions.

Returns
true if this enforcement caused the refinement flags for elem to change, false otherwise.
Enumerator
POINT 
EDGE 

Definition at line 853 of file mesh_refinement.h.

Constructor & Destructor Documentation

libMesh::MeshRefinement::MeshRefinement ( MeshBase mesh)
explicit

Constructor.

Definition at line 92 of file mesh_refinement.C.

References _periodic_boundaries, and set_periodic_boundaries_ptr().

92  :
93  ParallelObject(m),
94  _mesh(m),
96  _coarsen_by_parents(false),
97  _refine_fraction(0.3),
98  _coarsen_fraction(0.0),
100  _coarsen_threshold(10),
101  _nelem_target(0),
109 #ifdef LIBMESH_ENABLE_PERIODIC
111 #endif
112 {
113 }
114 
115 
116 
117 #ifdef LIBMESH_ENABLE_PERIODIC
119 {
120  _periodic_boundaries = pb_ptr;
121 }
ParallelObject(const Parallel::Communicator &comm_in)
Constructor.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
MeshBase & _mesh
Reference to the mesh.
We&#39;re using a class instead of a typedef to allow forward declarations and future flexibility...
const class libmesh_nullptr_t libmesh_nullptr
PeriodicBoundaries * _periodic_boundaries
signed char _underrefined_boundary_limit
unsigned char _face_level_mismatch_limit
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
signed char _overrefined_boundary_limit
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
unsigned char _node_level_mismatch_limit
unsigned char _edge_level_mismatch_limit
void set_periodic_boundaries_ptr(PeriodicBoundaries *pb_ptr)
Sets the PeriodicBoundaries pointer.
bool _coarsen_by_parents
Refinement parameter values.
libMesh::MeshRefinement::MeshRefinement ( const MeshRefinement )
private
libMesh::MeshRefinement::~MeshRefinement ( )

Destructor.

Deletes all the elements that are currently stored.

Definition at line 126 of file mesh_refinement.C.

References clear().

Referenced by libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

127 {
128  this->clear();
129 }
void clear()
Deletes all the data that are currently stored.

Member Function Documentation

bool libMesh::MeshRefinement::_coarsen_elements ( )
private

Coarsens user-requested elements.

Both coarsen_elements and refine_elements used to be in the public interface for the MeshRefinement object. Unfortunately, without proper preparation (make_refinement_compatible, make_coarsening_compatible) at least coarsen_elements() did not work alone. By making them private, we signal to the user that they are not part of the interface. It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the mesh actually changed (hence data needs to be projected) and false otherwise.

Definition at line 1367 of file mesh_refinement.C.

References _mesh, libMesh::Elem::active(), clear(), libMesh::Elem::COARSEN, libMesh::Elem::coarsen(), libMesh::Elem::COARSEN_INACTIVE, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), libMesh::MeshBase::get_boundary_info(), libMesh::MeshBase::is_serial(), libMesh::Elem::JUST_COARSENED, libMesh::Elem::level(), libMesh::libmesh_assert(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::Parallel::Communicator::max(), libMesh::Elem::nullify_neighbors(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::refinement_flag(), libMesh::BoundaryInfo::remove(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Elem::set_p_level(), libMesh::Elem::set_p_refinement_flag(), update_nodes_map(), and libMesh::MeshBase::update_parallel_id_counts().

Referenced by coarsen_elements(), get_mesh(), refine_and_coarsen_elements(), and uniformly_coarsen().

1368 {
1369  // This function must be run on all processors at once
1370  parallel_object_only();
1371 
1372  LOG_SCOPE ("_coarsen_elements()", "MeshRefinement");
1373 
1374  // Flags indicating if this call actually changes the mesh
1375  bool mesh_changed = false;
1376  bool mesh_p_changed = false;
1377 
1378  // Clear the unused_elements data structure.
1379  // The elements have been packed since it was built,
1380  // so there are _no_ unused elements. We cannot trust
1381  // any iterators currently in this data structure.
1382  // _unused_elements.clear();
1383 
1384  // Loop over the elements first to determine if the mesh will
1385  // undergo h-coarsening. If it will, then we'll need to communicate
1386  // more ghosted elements. We need to communicate them *before* we
1387  // do the coarsening; otherwise it is possible to coarsen away a
1388  // one-element-thick layer partition and leave the partitions on
1389  // either side unable to figure out how to talk to each other.
1390  for (auto & elem : _mesh.element_ptr_range())
1391  if (elem->refinement_flag() == Elem::COARSEN)
1392  {
1393  mesh_changed = true;
1394  break;
1395  }
1396 
1397  // If the mesh changed on any processor, it changed globally
1398  this->comm().max(mesh_changed);
1399 
1400  // And then we may need to widen the ghosting layers.
1401  if (mesh_changed)
1403 
1404  for (auto & elem : _mesh.element_ptr_range())
1405  {
1406  // active elements flagged for coarsening will
1407  // no longer be deleted until MeshRefinement::contract()
1408  if (elem->refinement_flag() == Elem::COARSEN)
1409  {
1410  // Huh? no level-0 element should be active
1411  // and flagged for coarsening.
1412  libmesh_assert_not_equal_to (elem->level(), 0);
1413 
1414  // Remove this element from any neighbor
1415  // lists that point to it.
1416  elem->nullify_neighbors();
1417 
1418  // Remove any boundary information associated
1419  // with this element
1420  _mesh.get_boundary_info().remove (elem);
1421 
1422  // Add this iterator to the _unused_elements
1423  // data structure so we might fill it.
1424  // The _unused_elements optimization is currently off.
1425  // _unused_elements.push_back (it);
1426 
1427  // Don't delete the element until
1428  // MeshRefinement::contract()
1429  // _mesh.delete_elem(elem);
1430  }
1431 
1432  // inactive elements flagged for coarsening
1433  // will become active
1434  else if (elem->refinement_flag() == Elem::COARSEN_INACTIVE)
1435  {
1436  elem->coarsen();
1437  libmesh_assert (elem->active());
1438 
1439  // the mesh has certainly changed
1440  mesh_changed = true;
1441  }
1442  if (elem->p_refinement_flag() == Elem::COARSEN)
1443  {
1444  if (elem->p_level() > 0)
1445  {
1446  elem->set_p_refinement_flag(Elem::JUST_COARSENED);
1447  elem->set_p_level(elem->p_level() - 1);
1448  mesh_p_changed = true;
1449  }
1450  else
1451  {
1452  elem->set_p_refinement_flag(Elem::DO_NOTHING);
1453  }
1454  }
1455  }
1456 
1457  this->comm().max(mesh_p_changed);
1458 
1459  // And we may need to update DistributedMesh values reflecting the changes
1460  if (mesh_changed)
1462 
1463  // Node processor ids may need to change if an element of that id
1464  // was coarsened away
1465  if (mesh_changed && !_mesh.is_serial())
1466  {
1467  // Update the _new_nodes_map so that processors can
1468  // find requested nodes
1469  this->update_nodes_map ();
1470 
1472 
1473  // Clear the _new_nodes_map
1474  this->clear();
1475 
1476 #ifdef DEBUG
1477  MeshTools::libmesh_assert_valid_procids<Node>(_mesh);
1478 #endif
1479  }
1480 
1481  // If p levels changed all we need to do is make sure that parent p
1482  // levels changed in sync
1483  if (mesh_p_changed && !_mesh.is_serial())
1484  {
1486  }
1487 
1488  return (mesh_changed || mesh_p_changed);
1489 }
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:117
virtual bool is_serial() const
Definition: mesh_base.h:140
void update_nodes_map()
Updates the _new_nodes_map.
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
void remove(const Node *node)
Removes the boundary conditions associated with node node, if any exist.
void send_coarse_ghosts(MeshBase &) const
Examine a just-coarsened mesh, and for any newly-coarsened elements, send the associated ghosted elem...
libmesh_assert(j)
This is the MeshCommunication class.
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual void update_parallel_id_counts()=0
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors...
void make_p_levels_parallel_consistent(MeshBase &)
Copy p levels of ghost elements from their local processors.
void make_nodes_parallel_consistent(MeshBase &)
Copy processor_ids and ids on ghost nodes from their local processors.
const Parallel::Communicator & comm() const
void clear()
Deletes all the data that are currently stored.
bool libMesh::MeshRefinement::_refine_elements ( )
private

Refines user-requested elements.

It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the mesh actually changed (hence data needs to be projected) and false otherwise.

Definition at line 1493 of file mesh_refinement.C.

References _mesh, libMesh::Elem::active(), libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshBase::active_local_element_ptr_range(), libMesh::MeshBase::active_not_local_elements_begin(), libMesh::MeshBase::active_not_local_elements_end(), clear(), libMesh::ParallelObject::comm(), libMesh::MeshBase::element_ptr_range(), libMesh::MeshBase::is_replicated(), libMesh::Elem::JUST_REFINED, libMesh::MeshBase::libmesh_assert_valid_parallel_ids(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::Parallel::Communicator::max(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_level(), libMesh::Elem::set_p_refinement_flag(), update_nodes_map(), and libMesh::MeshBase::update_parallel_id_counts().

Referenced by get_mesh(), refine_and_coarsen_elements(), refine_elements(), and uniformly_refine().

1494 {
1495  // This function must be run on all processors at once
1496  parallel_object_only();
1497 
1498  // Update the _new_nodes_map so that elements can
1499  // find nodes to connect to.
1500  this->update_nodes_map ();
1501 
1502  LOG_SCOPE ("_refine_elements()", "MeshRefinement");
1503 
1504  // Iterate over the elements, counting the elements
1505  // flagged for h refinement.
1506  dof_id_type n_elems_flagged = 0;
1507 
1508  for (auto & elem : _mesh.element_ptr_range())
1509  if (elem->refinement_flag() == Elem::REFINE)
1510  n_elems_flagged++;
1511 
1512  // Construct a local vector of Elem * which have been
1513  // previously marked for refinement. We reserve enough
1514  // space to allow for every element to be refined.
1515  std::vector<Elem *> local_copy_of_elements;
1516  local_copy_of_elements.reserve(n_elems_flagged);
1517 
1518  // If mesh p levels changed, we might need to synchronize parent p
1519  // levels on a distributed mesh.
1520  bool mesh_p_changed = false;
1521 
1522  // Iterate over the elements, looking for elements flagged for
1523  // refinement.
1524 
1525  // If we are on a ReplicatedMesh, then we just do the refinement in
1526  // the same order on every processor and everything stays in sync.
1527 
1528  // If we are on a DistributedMesh, that's impossible.
1529  //
1530  // If the mesh is distributed, we need to make sure that if we end
1531  // up as the owner of a new node, which might happen if that node is
1532  // attached to one of our own elements, then we have given it a
1533  // legitimate node id and our own processor id. We generate
1534  // legitimate node ids and use our own processor id when we are
1535  // refining our own elements but not when we refine others'
1536  // elements. Therefore we want to refine our own elements *first*,
1537  // thereby generating all nodes which might belong to us, and then
1538  // refine others' elements *after*, thereby generating nodes with
1539  // temporary ids which we know we will discard.
1540  //
1541  // Even if the DistributedMesh is serialized, we can't just treat it
1542  // like a ReplicatedMesh, because DistributedMesh doesn't *trust*
1543  // users to refine partitioned elements in a serialized way, so it
1544  // assigns temporary ids, so we need to synchronize ids afterward to
1545  // be safe anyway, so we might as well use the distributed mesh code
1546  // path.
1548  {
1549  if (elem->refinement_flag() == Elem::REFINE)
1550  local_copy_of_elements.push_back(elem);
1551  if (elem->p_refinement_flag() == Elem::REFINE &&
1552  elem->active())
1553  {
1554  elem->set_p_level(elem->p_level()+1);
1555  elem->set_p_refinement_flag(Elem::JUST_REFINED);
1556  mesh_p_changed = true;
1557  }
1558  }
1559 
1560  if (!_mesh.is_replicated())
1561  {
1564  elem_end = _mesh.active_not_local_elements_end();
1565  elem_it != elem_end; ++elem_it)
1566  {
1567  Elem * elem = *elem_it;
1568  if (elem->refinement_flag() == Elem::REFINE)
1569  local_copy_of_elements.push_back(elem);
1570  if (elem->p_refinement_flag() == Elem::REFINE &&
1571  elem->active())
1572  {
1573  elem->set_p_level(elem->p_level()+1);
1575  mesh_p_changed = true;
1576  }
1577  }
1578  }
1579 
1580  // Now iterate over the local copies and refine each one.
1581  // This may resize the mesh's internal container and invalidate
1582  // any existing iterators.
1583 
1584  for (std::size_t e = 0; e != local_copy_of_elements.size(); ++e)
1585  local_copy_of_elements[e]->refine(*this);
1586 
1587  // The mesh changed if there were elements h refined
1588  bool mesh_changed = !local_copy_of_elements.empty();
1589 
1590  // If the mesh changed on any processor, it changed globally
1591  this->comm().max(mesh_changed);
1592  this->comm().max(mesh_p_changed);
1593 
1594  // And we may need to update DistributedMesh values reflecting the changes
1595  if (mesh_changed)
1597 
1598  if (mesh_changed && !_mesh.is_replicated())
1599  {
1602 #ifdef DEBUG
1604 #endif
1605  }
1606 
1607  if (mesh_p_changed && !_mesh.is_replicated())
1608  {
1610  }
1611 
1612  // Clear the _new_nodes_map and _unused_elements data structures.
1613  this->clear();
1614 
1615  return (mesh_changed || mesh_p_changed);
1616 }
The definition of the element_iterator struct.
Definition: mesh_base.h:1476
void set_p_level(const unsigned int p)
Sets the value of the p-refinement level for the element.
Definition: elem.h:2559
virtual void libmesh_assert_valid_parallel_ids() const
Verify id and processor_id consistency of our elements and nodes containers.
Definition: mesh_base.h:965
bool active() const
Definition: elem.h:2257
void update_nodes_map()
Updates the _new_nodes_map.
unsigned int p_level() const
Definition: elem.h:2422
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
virtual bool is_replicated() const
Definition: mesh_base.h:162
void make_elems_parallel_consistent(MeshBase &)
Copy ids of ghost elements from their local processors.
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
This is the MeshCommunication class.
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual void update_parallel_id_counts()=0
Updates parallel caches so that methods like n_elem() accurately reflect changes on other processors...
void make_p_levels_parallel_consistent(MeshBase &)
Copy p levels of ghost elements from their local processors.
RefinementState p_refinement_flag() const
Definition: elem.h:2521
virtual element_iterator active_not_local_elements_end()=0
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2505
void clear()
Deletes all the data that are currently stored.
virtual element_iterator active_not_local_elements_begin()=0
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
Definition: elem.h:2529
void make_new_nodes_parallel_consistent(MeshBase &)
Copy processor_ids and ids on new nodes from their local processors.
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::MeshRefinement::_smooth_flags ( bool  refining,
bool  coarsening 
)
private

Smooths refinement flags according to current settings.

It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the flags actually changed (hence data needs to be projected) and false otherwise.

Definition at line 1619 of file mesh_refinement.C.

References _edge_level_mismatch_limit, _mesh, _node_level_mismatch_limit, _overrefined_boundary_limit, _underrefined_boundary_limit, libMesh::ParallelObject::comm(), eliminate_unrefined_patches(), libMesh::MeshBase::is_serial(), libMesh::libmesh_assert(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), limit_level_mismatch_at_edge(), limit_level_mismatch_at_node(), limit_overrefined_boundary(), limit_underrefined_boundary(), make_coarsening_compatible(), make_flags_parallel_consistent(), make_refinement_compatible(), and libMesh::Parallel::verify().

Referenced by coarsen_elements(), get_mesh(), refine_and_coarsen_elements(), and refine_elements().

1620 {
1621  // Smoothing can break in weird ways on a mesh with broken topology
1622 #ifdef DEBUG
1624 #endif
1625 
1626  // Repeat until flag changes match on every processor
1627  do
1628  {
1629  // Repeat until coarsening & refinement flags jive
1630  bool satisfied = false;
1631  do
1632  {
1633  // If we're refining or coarsening, hit the corresponding
1634  // face level test code. Short-circuiting || is our friend
1635  const bool coarsening_satisfied =
1636  !coarsening ||
1638 
1639  const bool refinement_satisfied =
1640  !refining ||
1642 
1643  bool smoothing_satisfied =
1644  !this->eliminate_unrefined_patches();// &&
1645 
1647  smoothing_satisfied = smoothing_satisfied &&
1649 
1651  smoothing_satisfied = smoothing_satisfied &&
1653 
1655  smoothing_satisfied = smoothing_satisfied &&
1657 
1659  smoothing_satisfied = smoothing_satisfied &&
1661 
1662  satisfied = (coarsening_satisfied &&
1663  refinement_satisfied &&
1664  smoothing_satisfied);
1665 
1666  libmesh_assert(this->comm().verify(satisfied));
1667  }
1668  while (!satisfied);
1669  }
1670  while (!_mesh.is_serial() && !this->make_flags_parallel_consistent());
1671 }
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
virtual bool is_serial() const
Definition: mesh_base.h:140
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
This algorithm restricts the maximum level mismatch at any node in the mesh.
bool limit_underrefined_boundary(const signed char max_mismatch)
MeshBase & _mesh
Reference to the mesh.
bool limit_overrefined_boundary(const signed char max_mismatch)
signed char _underrefined_boundary_limit
bool make_refinement_compatible()
Take user-specified refinement flags and augment them so that level-one dependency is satisfied...
libmesh_assert(j)
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
signed char _overrefined_boundary_limit
bool make_coarsening_compatible()
Take user-specified coarsening flags and augment them so that level-one dependency is satisfied...
unsigned char _node_level_mismatch_limit
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
unsigned char _edge_level_mismatch_limit
void libmesh_assert_valid_neighbors(const MeshBase &mesh, bool assert_valid_remote_elems=true)
A function for verifying that neighbor connectivity is correct (each element is a neighbor of or desc...
Definition: mesh_tools.C:1713
bool eliminate_unrefined_patches()
This algorithm selects an element for refinement if all of its neighbors are (or will be) refined...
Real & libMesh::MeshRefinement::absolute_global_tolerance ( )

If absolute_global_tolerance is set to a nonzero value, methods like flag_elements_by_global_tolerance() will attempt to reduce the global error of the mesh (defined as the square root of the sum of the squares of the errors on active elements) to below this tolerance.

absolute_global_tolerance is 0 by default.

Definition at line 904 of file mesh_refinement.h.

References _absolute_global_tolerance, and _use_member_parameters.

Referenced by build_mesh_refinement(), and get_mesh().

905 {
906  _use_member_parameters = true;
908 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
Elem * libMesh::MeshRefinement::add_elem ( Elem elem)

Adds the element elem to the mesh.

Definition at line 205 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::add_elem(), and libMesh::libmesh_assert().

Referenced by libMesh::Elem::refine(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

206 {
207  libmesh_assert(elem);
208 
209 
210  // // If the unused_elements has any iterators from
211  // // old elements, take the first one
212  // if (!_unused_elements.empty())
213  // {
214  // std::vector<Elem *>::iterator it = _unused_elements.front();
215 
216  // *it = elem;
217 
218  // _unused_elements.pop_front();
219  // }
220 
221  // // Otherwise, use the conventional add method
222  // else
223  // {
224  // _mesh.add_elem (elem);
225  // }
226 
227  // The _unused_elements optimization has been turned off.
228  _mesh.add_elem (elem);
229 
230  return elem;
231 }
MeshBase & _mesh
Reference to the mesh.
libmesh_assert(j)
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
Node * libMesh::MeshRefinement::add_node ( Elem parent,
unsigned int  child,
unsigned int  node,
processor_id_type  proc_id 
)

Add a node to the mesh.

The node should be node n of child c of parent Elem parent. The processor_id is assigned to all newly created nodes.

Returns
A pointer to a suitable existing or newly-created node.

Definition at line 140 of file mesh_refinement.C.

References _mesh, _new_nodes_map, libMesh::TopologyMap::add_node(), libMesh::MeshBase::add_point(), libMesh::TypeVector< T >::add_scaled(), libMesh::Elem::as_parent_node(), libMesh::Elem::bracketing_nodes(), libMesh::Elem::embedding_matrix(), libMesh::TopologyMap::find(), libMesh::DofObject::invalid_id, libMesh::invalid_uint, libMesh::libmesh_assert(), libMesh::Elem::node_index_range(), libMesh::Elem::node_ptr(), libMesh::MeshBase::node_ptr(), libMesh::Elem::point(), libMesh::ParallelObject::processor_id(), and libMesh::DofObject::processor_id().

Referenced by libMesh::Elem::refine(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

144 {
145  LOG_SCOPE("add_node()", "MeshRefinement");
146 
147  unsigned int parent_n = parent.as_parent_node(child, node);
148 
149  if (parent_n != libMesh::invalid_uint)
150  return parent.node_ptr(parent_n);
151 
152  const std::vector<std::pair<dof_id_type, dof_id_type>>
153  bracketing_nodes = parent.bracketing_nodes(child, node);
154 
155  // If we're not a parent node, we *must* be bracketed by at least
156  // one pair of parent nodes
157  libmesh_assert(bracketing_nodes.size());
158 
159  const dof_id_type new_node_id =
160  _new_nodes_map.find(bracketing_nodes);
161 
162  // Return the node if it already exists, but first update the
163  // processor_id if the node is now going to be attached to the
164  // element of a processor which may take ownership of it.
165  if (new_node_id != DofObject::invalid_id)
166  {
167  Node * node = _mesh.node_ptr(new_node_id);
168  if (proc_id < node->processor_id())
169  node->processor_id() = proc_id;
170  return node;
171  }
172 
173  // Otherwise we need to add a new node, with a default id and the
174  // requested processor_id. Figure out where to add the point:
175 
176  Point p; // defaults to 0,0,0
177 
178  for (auto n : parent.node_index_range())
179  {
180  // The value from the embedding matrix
181  const float em_val = parent.embedding_matrix(child,node,n);
182 
183  if (em_val != 0.)
184  {
185  p.add_scaled (parent.point(n), em_val);
186 
187  // If we'd already found the node we shouldn't be here
188  libmesh_assert_not_equal_to (em_val, 1);
189  }
190  }
191 
192  Node * new_node = _mesh.add_point (p, DofObject::invalid_id, proc_id);
193 
194  libmesh_assert(new_node);
195 
196  // Add the node to the map.
197  _new_nodes_map.add_node(*new_node, bracketing_nodes);
198 
199  // Return the address of the new node
200  return new_node;
201 }
A Node is like a Point, but with more information.
Definition: node.h:52
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
dof_id_type find(dof_id_type bracket_node1, dof_id_type bracket_node2) const
Definition: topology_map.C:118
TopologyMap _new_nodes_map
Data structure that holds the new nodes information.
MeshBase & _mesh
Reference to the mesh.
void add_scaled(const TypeVector< T2 > &, const T)
Add a scaled value to this vector without creating a temporary.
Definition: type_vector.h:624
IntRange< unsigned short > node_index_range() const
Definition: elem.h:2065
void add_node(const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type >> &bracketing_nodes)
Add a node to the map, between each pair of specified bracketing nodes.
Definition: topology_map.C:52
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
libmesh_assert(j)
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1874
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:324
virtual const std::vector< std::pair< dof_id_type, dof_id_type > > bracketing_nodes(unsigned int c, unsigned int n) const
Definition: elem.C:2353
const Point & point(const unsigned int i) const
Definition: elem.h:1809
virtual unsigned int as_parent_node(unsigned int c, unsigned int n) const
Definition: elem.C:2080
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:64
processor_id_type processor_id() const
Definition: dof_object.h:694
virtual float embedding_matrix(const unsigned int child_num, const unsigned int child_node_num, const unsigned int parent_node_num) const =0
void libMesh::MeshRefinement::add_p_to_h_refinement ( )

Takes a mesh whose elements are flagged for h refinement and coarsening, and adds flags to request p refinement and coarsening of the same elements.

Definition at line 654 of file mesh_refinement_flagging.C.

References _mesh, and libMesh::MeshBase::element_ptr_range().

Referenced by main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

655 {
656  for (auto & elem : _mesh.element_ptr_range())
657  elem->set_p_refinement_flag(elem->refinement_flag());
658 }
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > element_ptr_range()=0
void libMesh::MeshRefinement::clean_refinement_flags ( )

Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.

Definition at line 662 of file mesh_refinement_flagging.C.

References _mesh, libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), and libMesh::Elem::INACTIVE.

Referenced by flag_elements_by_elem_fraction(), flag_elements_by_error_fraction(), flag_elements_by_nelem_target(), libMesh::EquationSystems::init(), libMesh::EquationSystems::read(), uniformly_coarsen(), uniformly_refine(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

663 {
664  // Possibly clean up the refinement flags from
665  // a previous step
666  for (auto & elem : _mesh.element_ptr_range())
667  {
668  if (elem->active())
669  {
670  elem->set_refinement_flag(Elem::DO_NOTHING);
671  elem->set_p_refinement_flag(Elem::DO_NOTHING);
672  }
673  else
674  {
675  elem->set_refinement_flag(Elem::INACTIVE);
676  elem->set_p_refinement_flag(Elem::INACTIVE);
677  }
678  }
679 }
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > element_ptr_range()=0
void libMesh::MeshRefinement::clear ( )

Deletes all the data that are currently stored.

Definition at line 133 of file mesh_refinement.C.

References _new_nodes_map, and libMesh::TopologyMap::clear().

Referenced by _coarsen_elements(), _refine_elements(), libMesh::MeshRefinement::ElementFlagging::~ElementFlagging(), and ~MeshRefinement().

134 {
136 }
TopologyMap _new_nodes_map
Data structure that holds the new nodes information.
bool & libMesh::MeshRefinement::coarsen_by_parents ( )

If coarsen_by_parents is true, complete groups of sibling elements (elements with the same parent) will be flagged for coarsening.

This should make the coarsening more likely to occur as requested.

coarsen_by_parents is true by default.

Definition at line 868 of file mesh_refinement.h.

References _coarsen_by_parents, and _use_member_parameters.

Referenced by build_mesh_refinement(), and get_mesh().

869 {
870  _use_member_parameters = true;
871  return _coarsen_by_parents;
872 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
bool _coarsen_by_parents
Refinement parameter values.
bool libMesh::MeshRefinement::coarsen_elements ( )

Only coarsens the user-requested elements.

Some elements will not be coarsened to satisfy the level one rule. It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the mesh actually changed (hence data needs to be projected) and false otherwise.
Note
This function used to take an argument, maintain_level_one, new code should use face_level_mismatch_limit() instead.

Definition at line 623 of file mesh_refinement.C.

References _coarsen_elements(), _face_level_mismatch_limit, _mesh, _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), libMesh::Elem::INACTIVE, libMesh::Elem::JUST_REFINED, libMesh::libmesh_assert(), make_coarsening_compatible(), make_flags_parallel_consistent(), libMesh::out, libMesh::MeshBase::prepare_for_use(), libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), and test_level_one().

Referenced by libMesh::EquationSystems::reinit(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

624 {
625  // This function must be run on all processors at once
626  parallel_object_only();
627 
628  // We can't yet turn a non-level-one mesh into a level-one mesh
631 
632  // Possibly clean up the refinement flags from
633  // a previous step
634  for (auto & elem : _mesh.element_ptr_range())
635  {
636  // Set refinement flag to INACTIVE if the
637  // element isn't active
638  if (!elem->active())
639  {
640  elem->set_refinement_flag(Elem::INACTIVE);
641  elem->set_p_refinement_flag(Elem::INACTIVE);
642  }
643 
644  // This might be left over from the last step
645  if (elem->refinement_flag() == Elem::JUST_REFINED)
646  elem->set_refinement_flag(Elem::DO_NOTHING);
647  }
648 
649  // Parallel consistency has to come first, or coarsening
650  // along processor boundaries might occasionally be falsely
651  // prevented
652  bool flags_were_consistent = this->make_flags_parallel_consistent();
653 
654  // In theory, we should be able to remove the above call, which can
655  // be expensive and should be unnecessary. In practice, doing
656  // consistent flagging in parallel is hard, it's impossible to
657  // verify at the library level if it's being done by user code, and
658  // we don't want to abort large parallel runs in opt mode... but we
659  // do want to warn that they should be fixed.
660  libmesh_assert(flags_were_consistent);
661  if (!flags_were_consistent)
662  {
663  libMesh::out << "Refinement flags were not consistent between processors!\n"
664  << "Correcting and continuing.";
665  }
666 
667  // Smooth coarsening flags
668  _smooth_flags(false, true);
669 
670  // Coarsen the flagged elements.
671  const bool mesh_changed =
672  this->_coarsen_elements ();
673 
677  // FIXME: This won't pass unless we add a redundant find_neighbors()
678  // call or replace find_neighbors() with on-the-fly neighbor updating
679  // libmesh_assert(!this->eliminate_unrefined_patches());
680 
681  // We can't contract the mesh ourselves anymore - a System might
682  // need to restrict old coefficient vectors first
683  // _mesh.contract();
684 
685  // Finally, the new mesh may need to be prepared for use
686  if (mesh_changed)
687  _mesh.prepare_for_use (/*skip_renumber =*/false);
688 
689  return mesh_changed;
690 }
MeshBase & _mesh
Reference to the mesh.
libmesh_assert(j)
bool test_level_one(bool libmesh_assert_yes=false)
virtual SimpleRange< element_iterator > element_ptr_range()=0
unsigned char _face_level_mismatch_limit
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
bool make_coarsening_compatible()
Take user-specified coarsening flags and augment them so that level-one dependency is satisfied...
OStreamProxy out
void _smooth_flags(bool refining, bool coarsening)
Smooths refinement flags according to current settings.
bool _coarsen_elements()
Coarsens user-requested elements.
Real & libMesh::MeshRefinement::coarsen_fraction ( )

The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for coarsening, depending on which flag_elements_by method is called.

coarsen_fraction must be in $ [0,1] $, and is 0 by default.

Definition at line 880 of file mesh_refinement.h.

References _coarsen_fraction, and _use_member_parameters.

Referenced by assemble_and_solve(), build_mesh_refinement(), get_mesh(), main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

881 {
882  _use_member_parameters = true;
883  return _coarsen_fraction;
884 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
Real & libMesh::MeshRefinement::coarsen_threshold ( )

The coarsen_threshold provides hysteresis in AMR/C strategies.

Refinement of elements with error estimate E will be done even at the expense of coarsening elements whose children's accumulated error does not exceed coarsen_threshold * E.

coarsen_threshold must be in $ [0,1] $, and is 0.1 by default.

Definition at line 892 of file mesh_refinement.h.

References _coarsen_threshold, and _use_member_parameters.

Referenced by build_mesh_refinement(), and get_mesh().

893 {
894  _use_member_parameters = true;
895  return _coarsen_threshold;
896 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 87 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_petsc_preconditioner_apply(), libMesh::__libmesh_petsc_snes_jacobian(), libMesh::__libmesh_petsc_snes_postcheck(), libMesh::__libmesh_petsc_snes_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), _coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::ParmetisPartitioner::_do_repartition(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), libMesh::EquationSystems::_read_impl(), _refine_elements(), _smooth_flags(), add_cube_convex_hull_to_mesh(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::ImplicitSystem::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::DofMap::attach_matrix(), libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), libMesh::Parallel::Sort< KeyType, IdxType >::binsort(), libMesh::MeshCommunication::broadcast(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::PetscNonlinearSolver< T >::build_mat_null_space(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshBase::cache_elem_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::MeshTools::create_nodal_bounding_box(), create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::RBConstruction::enrich_RB_space(), AssembleOptimization::equality_constraints(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::RBEIMConstruction::evaluate_mesh_function(), flag_elements_by_elem_fraction(), flag_elements_by_error_fraction(), flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TopologyMap::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::ParmetisPartitioner::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_rb_construction(), integrate_function(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), limit_level_mismatch_at_edge(), limit_level_mismatch_at_node(), limit_overrefined_boundary(), limit_underrefined_boundary(), main(), make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), new_function_base(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::MetisPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::print(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshCommunication::redistribute(), refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), LinearElasticityWithContact::residual_and_jacobian(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::RBEIMConstruction::set_explicit_sys_subvector(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::Parallel::sync_element_data_by_parent_id(), libMesh::Parallel::sync_node_data_by_element_id(), test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), test_unflagged(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), SystemsTest::testProjectCubeWithMeshFunction(), libMesh::MeshTools::total_weight(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::RBEIMConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

88  { return _communicator; }
const Parallel::Communicator & _communicator
void libMesh::MeshRefinement::create_parent_error_vector ( const ErrorVector error_per_cell,
ErrorVector error_per_parent,
Real parent_error_min,
Real parent_error_max 
)
private

Calculates the error on all coarsenable parents.

error_per_parent[parent_id] stores this error if parent_id corresponds to a coarsenable parent, and stores -1 otherwise.

Definition at line 235 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::ParallelObject::comm(), libMesh::DofObject::id(), libMesh::libmesh_assert(), std::max(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::Elem::parent(), libMesh::Parallel::Communicator::sum(), and libMesh::Parallel::verify().

Referenced by flag_elements_by_elem_fraction(), flag_elements_by_error_fraction(), flag_elements_by_error_tolerance(), flag_elements_by_nelem_target(), and get_mesh().

239 {
240  // This function must be run on all processors at once
241  parallel_object_only();
242 
243  // Make sure the input error vector is valid
244 #ifdef DEBUG
245  for (std::size_t i=0; i != error_per_cell.size(); ++i)
246  {
247  libmesh_assert_greater_equal (error_per_cell[i], 0);
248  // isnan() isn't standard C++ yet
249 #ifdef isnan
250  libmesh_assert(!isnan(error_per_cell[i]));
251 #endif
252  }
253 
254  // Use a reference to std::vector to avoid confusing
255  // this->comm().verify
256  std::vector<ErrorVectorReal> & epc = error_per_parent;
257  libmesh_assert(this->comm().verify(epc));
258 #endif // #ifdef DEBUG
259 
260  // error values on uncoarsenable elements will be left at -1
261  error_per_parent.clear();
262  error_per_parent.resize(error_per_cell.size(), 0.0);
263 
264  {
265  // Find which elements are uncoarsenable
266  for (auto & elem : _mesh.active_local_element_ptr_range())
267  {
268  Elem * parent = elem->parent();
269 
270  // Active elements are uncoarsenable
271  error_per_parent[elem->id()] = -1.0;
272 
273  // Grandparents and up are uncoarsenable
274  while (parent)
275  {
276  parent = parent->parent();
277  if (parent)
278  {
279  const dof_id_type parentid = parent->id();
280  libmesh_assert_less (parentid, error_per_parent.size());
281  error_per_parent[parentid] = -1.0;
282  }
283  }
284  }
285 
286  // Sync between processors.
287  // Use a reference to std::vector to avoid confusing
288  // this->comm().min
289  std::vector<ErrorVectorReal> & epp = error_per_parent;
290  this->comm().min(epp);
291  }
292 
293  // The parent's error is defined as the square root of the
294  // sum of the children's errors squared, so errors that are
295  // Hilbert norms remain Hilbert norms.
296  //
297  // Because the children may be on different processors, we
298  // calculate local contributions to the parents' errors squared
299  // first, then sum across processors and take the square roots
300  // second.
301  for (auto & elem : _mesh.active_local_element_ptr_range())
302  {
303  Elem * parent = elem->parent();
304 
305  // Calculate each contribution to parent cells
306  if (parent)
307  {
308  const dof_id_type parentid = parent->id();
309  libmesh_assert_less (parentid, error_per_parent.size());
310 
311  // If the parent has grandchildren we won't be able to
312  // coarsen it, so forget it. Otherwise, add this child's
313  // contribution to the sum of the squared child errors
314  if (error_per_parent[parentid] != -1.0)
315  error_per_parent[parentid] += (error_per_cell[elem->id()] *
316  error_per_cell[elem->id()]);
317  }
318  }
319 
320  // Sum the vector across all processors
321  this->comm().sum(static_cast<std::vector<ErrorVectorReal> &>(error_per_parent));
322 
323  // Calculate the min and max as we loop
324  parent_error_min = std::numeric_limits<double>::max();
325  parent_error_max = 0.;
326 
327  for (std::size_t i = 0; i != error_per_parent.size(); ++i)
328  {
329  // If this element isn't a coarsenable parent with error, we
330  // have nothing to do. Just flag it as -1 and move on
331  // Note that this->comm().sum might have left uncoarsenable
332  // elements with error_per_parent=-n_proc, so reset it to
333  // error_per_parent=-1
334  if (error_per_parent[i] < 0.)
335  {
336  error_per_parent[i] = -1.;
337  continue;
338  }
339 
340  // The error estimator might have already given us an
341  // estimate on the coarsenable parent elements; if so then
342  // we want to retain that estimate
343  if (error_per_cell[i])
344  {
345  error_per_parent[i] = error_per_cell[i];
346  continue;
347  }
348  // if not, then e_parent = sqrt(sum(e_child^2))
349  else
350  error_per_parent[i] = std::sqrt(error_per_parent[i]);
351 
352  parent_error_min = std::min (parent_error_min,
353  error_per_parent[i]);
354  parent_error_max = std::max (parent_error_max,
355  error_per_parent[i]);
356  }
357 }
MeshBase & _mesh
Reference to the mesh.
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
const Elem * parent() const
Definition: elem.h:2346
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
long double max(long double a, double b)
libmesh_assert(j)
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
dof_id_type id() const
Definition: dof_object.h:632
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64
unsigned char & libMesh::MeshRefinement::edge_level_mismatch_limit ( )

If edge_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two edge neighbors will not differ by more than that limit.

If edge_level_mismatch_limit is 0, then level differences will be unlimited.

edge_level_mismatch_limit is 0 by default.

Definition at line 915 of file mesh_refinement.h.

References _edge_level_mismatch_limit.

Referenced by get_mesh().

916 {
918 }
unsigned char _edge_level_mismatch_limit
bool libMesh::MeshRefinement::eliminate_unrefined_patches ( )
private

This algorithm selects an element for refinement if all of its neighbors are (or will be) refined.

This algorithm will transform this mesh:

* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |       |   |   |
* |   |   |       |   |   |
* o---o---o       o---o---o
* |   |   |       |   |   |
* |   |   |       |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* 

into this:

* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |   :   |   |   |
* |   |   |   :   |   |   |
* o---o---o...o...o---o---o
* |   |   |   :   |   |   |
* |   |   |   :   |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* |   |   |   |   |   |   |
* |   |   |   |   |   |   |
* o---o---o---o---o---o---o
* 

by refining the indicated element

Definition at line 380 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::COARSEN, libMesh::Elem::COARSEN_INACTIVE, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::Elem::INACTIVE, libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::max(), libMesh::Elem::REFINE, and libMesh::remote_elem.

Referenced by _smooth_flags(), and get_mesh().

381 {
382  // This function must be run on all processors at once
383  parallel_object_only();
384 
385  bool flags_changed = false;
386 
387  // Note: we *cannot* use a reference to the real pointer here, since
388  // the pointer may be reseated below and we don't want to reseat
389  // pointers held by the Mesh.
390  for (Elem * elem : _mesh.active_element_ptr_range())
391  {
392  // First assume that we'll have to flag this element for both h
393  // and p refinement, then change our minds if we see any
394  // neighbors that are as coarse or coarser than us.
395  bool h_flag_me = true,
396  p_flag_me = true;
397 
398 
399  // Skip the element if it is already fully flagged for refinement
400  if (elem->p_refinement_flag() == Elem::REFINE)
401  p_flag_me = false;
402  if (elem->refinement_flag() == Elem::REFINE)
403  {
404  h_flag_me = false;
405  if (!p_flag_me)
406  continue;
407  }
408  // Test the parent if that is already flagged for coarsening
409  else if (elem->refinement_flag() == Elem::COARSEN)
410  {
411  libmesh_assert(elem->parent());
412  elem = elem->parent();
413  // FIXME - this doesn't seem right - RHS
414  if (elem->refinement_flag() != Elem::COARSEN_INACTIVE)
415  continue;
416  p_flag_me = false;
417  }
418 
419  const unsigned int my_level = elem->level();
420  int my_p_adjustment = 0;
421  if (elem->p_refinement_flag() == Elem::REFINE)
422  my_p_adjustment = 1;
423  else if (elem->p_refinement_flag() == Elem::COARSEN)
424  {
425  libmesh_assert_greater (elem->p_level(), 0);
426  my_p_adjustment = -1;
427  }
428  const unsigned int my_new_p_level = elem->p_level() +
429  my_p_adjustment;
430 
431  // Check all the element neighbors
432  for (auto neighbor : elem->neighbor_ptr_range())
433  {
434  // Quit if the element is on a local boundary
435  if (neighbor == libmesh_nullptr || neighbor == remote_elem)
436  {
437  h_flag_me = false;
438  p_flag_me = false;
439  break;
440  }
441  // if the neighbor will be equally or less refined than
442  // we are, then we will not become an unrefined island.
443  // So if we are still considering h refinement:
444  if (h_flag_me &&
445  // If our neighbor is already at a lower level,
446  // it can't end up at a higher level even if it
447  // is flagged for refinement once
448  ((neighbor->level() < my_level) ||
449  // If our neighbor is at the same level but isn't
450  // flagged for refinement, it won't end up at a
451  // higher level
452  ((neighbor->active()) &&
453  (neighbor->refinement_flag() != Elem::REFINE)) ||
454  // If our neighbor is currently more refined but is
455  // a parent flagged for coarsening, it will end up
456  // at the same level.
457  (neighbor->refinement_flag() == Elem::COARSEN_INACTIVE)))
458  {
459  // We've proven we won't become an unrefined island,
460  // so don't h refine to avoid that.
461  h_flag_me = false;
462 
463  // If we've also proven we don't need to p refine,
464  // we don't need to check more neighbors
465  if (!p_flag_me)
466  break;
467  }
468  if (p_flag_me)
469  {
470  // if active neighbors will have a p level
471  // equal to or lower than ours, then we do not need to p
472  // refine ourselves.
473  if (neighbor->active())
474  {
475  int p_adjustment = 0;
476  if (neighbor->p_refinement_flag() == Elem::REFINE)
477  p_adjustment = 1;
478  else if (neighbor->p_refinement_flag() == Elem::COARSEN)
479  {
480  libmesh_assert_greater (neighbor->p_level(), 0);
481  p_adjustment = -1;
482  }
483  if (my_new_p_level >= neighbor->p_level() + p_adjustment)
484  {
485  p_flag_me = false;
486  if (!h_flag_me)
487  break;
488  }
489  }
490  // If we have inactive neighbors, we need to
491  // test all their active descendants which neighbor us
492  else if (neighbor->ancestor())
493  {
494  if (neighbor->min_new_p_level_by_neighbor(elem,
495  my_new_p_level + 2) <= my_new_p_level)
496  {
497  p_flag_me = false;
498  if (!h_flag_me)
499  break;
500  }
501  }
502  }
503  }
504 
505  if (h_flag_me)
506  {
507  // Parents that would create islands should no longer
508  // coarsen
509  if (elem->refinement_flag() == Elem::COARSEN_INACTIVE)
510  {
511  for (auto & child : elem->child_ref_range())
512  {
513  libmesh_assert_equal_to (child.refinement_flag(),
514  Elem::COARSEN);
515  child.set_refinement_flag(Elem::DO_NOTHING);
516  }
517  elem->set_refinement_flag(Elem::INACTIVE);
518  }
519  else
520  elem->set_refinement_flag(Elem::REFINE);
521  flags_changed = true;
522  }
523  if (p_flag_me)
524  {
525  if (elem->p_refinement_flag() == Elem::COARSEN)
526  elem->set_p_refinement_flag(Elem::DO_NOTHING);
527  else
528  elem->set_p_refinement_flag(Elem::REFINE);
529  flags_changed = true;
530  }
531  }
532 
533  // If flags changed on any processor then they changed globally
534  this->comm().max(flags_changed);
535 
536  return flags_changed;
537 }
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
const class libmesh_nullptr_t libmesh_nullptr
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
libmesh_assert(j)
const Parallel::Communicator & comm() const
const RemoteElem * remote_elem
Definition: remote_elem.C:57
bool & libMesh::MeshRefinement::enforce_mismatch_limit_prior_to_refinement ( )

Get/set the _enforce_mismatch_limit_prior_to_refinement flag.

The default value for this flag is false.

Definition at line 949 of file mesh_refinement.h.

References _enforce_mismatch_limit_prior_to_refinement.

Referenced by get_enforce_mismatch_limit_prior_to_refinement(), get_mesh(), limit_level_mismatch_at_edge(), limit_level_mismatch_at_node(), and set_enforce_mismatch_limit_prior_to_refinement().

950 {
952 }
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
bool libMesh::MeshRefinement::enforce_mismatch_limit_prior_to_refinement ( Elem elem,
NeighborType  nt,
unsigned  max_mismatch 
)
private

Definition at line 541 of file mesh_refinement_smoothing.C.

References _enforce_mismatch_limit_prior_to_refinement, libMesh::Elem::DO_NOTHING, EDGE, libMesh::Elem::find_edge_neighbors(), libMesh::Elem::find_point_neighbors(), libMesh::Elem::level(), libMesh::Elem::p_level(), POINT, libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), and libMesh::Elem::set_refinement_flag().

544 {
545  // Eventual return value
546  bool flags_changed = false;
547 
548  // If we are enforcing the limit prior to refinement then we
549  // need to remove flags from any elements marked for refinement that
550  // would cause a mismatch
552  && elem->refinement_flag() == Elem::REFINE)
553  {
554  // get all the relevant neighbors since we may have to refine
555  // elements off edges or corners as well
556  std::set<const Elem *> neighbor_set;
557 
558  if (nt == POINT)
559  elem->find_point_neighbors(neighbor_set);
560  else if (nt == EDGE)
561  elem->find_edge_neighbors(neighbor_set);
562  else
563  libmesh_error_msg("Unrecognized NeighborType: " << nt);
564 
565  // Loop over the neighbors of element e
566  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
567  for (; n_it != neighbor_set.end(); ++n_it)
568  {
569  const Elem * neighbor = *n_it;
570 
571  if ((elem->level() + 1 - max_mismatch) > neighbor->level())
572  {
573  elem->set_refinement_flag(Elem::DO_NOTHING);
574  flags_changed = true;
575  }
576  if ((elem->p_level() + 1 - max_mismatch) > neighbor->p_level())
577  {
578  elem->set_p_refinement_flag(Elem::DO_NOTHING);
579  flags_changed = true;
580  }
581  } // loop over edge/point neighbors
582  } // if _enforce_mismatch_limit_prior_to_refinement
583 
584  return flags_changed;
585 }
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
unsigned char & libMesh::MeshRefinement::face_level_mismatch_limit ( )

If face_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two face neighbors will not differ by more than that limit.

If face_level_mismatch_limit is 0, then level differences will be unlimited.

face_level_mismatch_limit is 1 by default. Currently the only supported options are 0 and 1.

Definition at line 910 of file mesh_refinement.h.

References _face_level_mismatch_limit.

Referenced by get_mesh(), and libMesh::EquationSystems::reinit().

911 {
913 }
unsigned char _face_level_mismatch_limit
void libMesh::MeshRefinement::flag_elements_by ( ElementFlagging element_flagging)

Flag elements based on a function object.

The class ElementFlagging defines a mechanism for implementing refinement strategies.

Definition at line 628 of file mesh_refinement_flagging.C.

References libMesh::MeshRefinement::ElementFlagging::flag_elements().

Referenced by libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

629 {
630  element_flagging.flag_elements();
631 }
void libMesh::MeshRefinement::flag_elements_by_elem_fraction ( const ErrorVector error_per_cell,
const Real  refine_fraction = 0.3,
const Real  coarsen_fraction = 0.0,
const unsigned int  max_level = libMesh::invalid_uint 
)

Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.

This method picks the top refine_fraction * n_elem elements for refinement and the bottom coarsen_fraction * n_elem elements for coarsening. The two fractions refine_fraction and coarsen_fraction must be in $ [0,1] $.

All the function arguments except error_per_cell have been deprecated, and will be removed in future libMesh releases - to control these parameters, set the corresponding member variables.

Definition at line 434 of file mesh_refinement_flagging.C.

References _coarsen_by_parents, _coarsen_fraction, _max_h_level, _mesh, _refine_fraction, _use_member_parameters, libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshBase::active_local_element_ptr_range(), libMesh::Parallel::Communicator::allgather(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), dim, libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::invalid_uint, libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_active_elem(), libMesh::Elem::parent(), libMesh::Real, libMesh::Elem::REFINE, and libMesh::Elem::set_refinement_flag().

Referenced by main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

438 {
439  parallel_object_only();
440 
441  // The function arguments are currently just there for
442  // backwards_compatibility
444  {
445  // If the user used non-default parameters, lets warn
446  // that they're deprecated
447  if (refine_frac != 0.3 ||
448  coarsen_frac != 0.0 ||
449  max_l != libMesh::invalid_uint)
450  libmesh_deprecated();
451 
452  _refine_fraction = refine_frac;
453  _coarsen_fraction = coarsen_frac;
454  _max_h_level = max_l;
455  }
456 
457  // Check for valid fractions..
458  // The fraction values must be in [0,1]
459  libmesh_assert_greater_equal (_refine_fraction, 0);
460  libmesh_assert_less_equal (_refine_fraction, 1);
461  libmesh_assert_greater_equal (_coarsen_fraction, 0);
462  libmesh_assert_less_equal (_coarsen_fraction, 1);
463 
464  // The number of active elements in the mesh
465  const dof_id_type n_active_elem = _mesh.n_active_elem();
466 
467  // The number of elements to flag for coarsening
468  const dof_id_type n_elem_coarsen =
469  static_cast<dof_id_type>(_coarsen_fraction * n_active_elem);
470 
471  // The number of elements to flag for refinement
472  const dof_id_type n_elem_refine =
473  static_cast<dof_id_type>(_refine_fraction * n_active_elem);
474 
475 
476 
477  // Clean up the refinement flags. These could be left
478  // over from previous refinement steps.
479  this->clean_refinement_flags();
480 
481 
482  // This vector stores the error and element number for all the
483  // active elements. It will be sorted and the top & bottom
484  // elements will then be flagged for coarsening & refinement
485  std::vector<ErrorVectorReal> sorted_error;
486 
487  sorted_error.reserve (n_active_elem);
488 
489  // Loop over the active elements and create the entry
490  // in the sorted_error vector
491  for (auto & elem : _mesh.active_local_element_ptr_range())
492  sorted_error.push_back (error_per_cell[elem->id()]);
493 
494  this->comm().allgather(sorted_error);
495 
496  // Now sort the sorted_error vector
497  std::sort (sorted_error.begin(), sorted_error.end());
498 
499  // If we're coarsening by parents:
500  // Create a sorted error vector with coarsenable parent elements
501  // only, sorted by lowest errors first
502  ErrorVector error_per_parent, sorted_parent_error;
504  {
505  Real parent_error_min, parent_error_max;
506 
507  create_parent_error_vector(error_per_cell,
508  error_per_parent,
509  parent_error_min,
510  parent_error_max);
511 
512  sorted_parent_error = error_per_parent;
513  std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
514 
515  // All the other error values will be 0., so get rid of them.
516  sorted_parent_error.erase (std::remove(sorted_parent_error.begin(),
517  sorted_parent_error.end(), 0.),
518  sorted_parent_error.end());
519  }
520 
521 
522  ErrorVectorReal top_error= 0., bottom_error = 0.;
523 
524  // Get the maximum error value corresponding to the
525  // bottom n_elem_coarsen elements
526  if (_coarsen_by_parents && n_elem_coarsen)
527  {
528  const unsigned int dim = _mesh.mesh_dimension();
529  unsigned int twotodim = 1;
530  for (unsigned int i=0; i!=dim; ++i)
531  twotodim *= 2;
532 
533  dof_id_type n_parent_coarsen = n_elem_coarsen / (twotodim - 1);
534 
535  if (n_parent_coarsen)
536  bottom_error = sorted_parent_error[n_parent_coarsen - 1];
537  }
538  else if (n_elem_coarsen)
539  {
540  bottom_error = sorted_error[n_elem_coarsen - 1];
541  }
542 
543  if (n_elem_refine)
544  top_error = sorted_error[sorted_error.size() - n_elem_refine];
545 
546  // Finally, let's do the element flagging
547  for (auto & elem : _mesh.active_element_ptr_range())
548  {
549  Elem * parent = elem->parent();
550 
551  if (_coarsen_by_parents && parent && n_elem_coarsen &&
552  error_per_parent[parent->id()] <= bottom_error)
553  elem->set_refinement_flag(Elem::COARSEN);
554 
555  if (!_coarsen_by_parents && n_elem_coarsen &&
556  error_per_cell[elem->id()] <= bottom_error)
557  elem->set_refinement_flag(Elem::COARSEN);
558 
559  if (n_elem_refine &&
560  elem->level() < _max_h_level &&
561  error_per_cell[elem->id()] >= top_error)
562  elem->set_refinement_flag(Elem::REFINE);
563  }
564 }
virtual dof_id_type n_active_elem() const =0
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
MeshBase & _mesh
Reference to the mesh.
unsigned int dim
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
Calculates the error on all coarsenable parents.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
unsigned int mesh_dimension() const
Definition: mesh_base.C:148
bool _coarsen_by_parents
Refinement parameter values.
uint8_t dof_id_type
Definition: id_types.h:64
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
void libMesh::MeshRefinement::flag_elements_by_error_fraction ( const ErrorVector error_per_cell,
const Real  refine_fraction = 0.3,
const Real  coarsen_fraction = 0.0,
const unsigned int  max_level = libMesh::invalid_uint 
)

Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.

The two fractions refine_fraction and coarsen_fraction must be in $ [0,1] $.

All the function arguments except error_per_cell have been deprecated, and will be removed in future libMesh releases - to control these parameters, set the corresponding member variables.

Definition at line 44 of file mesh_refinement_flagging.C.

References _coarsen_by_parents, _coarsen_fraction, _max_h_level, _mesh, _refine_fraction, _use_member_parameters, libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshBase::active_local_element_ptr_range(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::invalid_uint, std::max(), libMesh::Parallel::Communicator::max(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::Elem::parent(), libMesh::Real, and libMesh::Elem::REFINE.

Referenced by assemble_and_solve(), main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

48 {
49  parallel_object_only();
50 
51  // The function arguments are currently just there for
52  // backwards_compatibility
54  {
55  // If the user used non-default parameters, lets warn
56  // that they're deprecated
57  if (refine_frac != 0.3 ||
58  coarsen_frac != 0.0 ||
59  max_l != libMesh::invalid_uint)
60  libmesh_deprecated();
61 
62  _refine_fraction = refine_frac;
63  _coarsen_fraction = coarsen_frac;
64  _max_h_level = max_l;
65  }
66 
67  // Check for valid fractions..
68  // The fraction values must be in [0,1]
69  libmesh_assert_greater_equal (_refine_fraction, 0);
70  libmesh_assert_less_equal (_refine_fraction, 1);
71  libmesh_assert_greater_equal (_coarsen_fraction, 0);
72  libmesh_assert_less_equal (_coarsen_fraction, 1);
73 
74  // Clean up the refinement flags. These could be left
75  // over from previous refinement steps.
76  this->clean_refinement_flags();
77 
78  // We're getting the minimum and maximum error values
79  // for the ACTIVE elements
80  Real error_min = 1.e30;
81  Real error_max = 0.;
82 
83  // And, if necessary, for their parents
84  Real parent_error_min = 1.e30;
85  Real parent_error_max = 0.;
86 
87  // Prepare another error vector if we need to sum parent errors
88  ErrorVector error_per_parent;
90  {
91  create_parent_error_vector(error_per_cell,
92  error_per_parent,
93  parent_error_min,
94  parent_error_max);
95  }
96 
97  // We need to loop over all active elements to find the minimum
98  for (auto & elem : _mesh.active_local_element_ptr_range())
99  {
100  const dof_id_type id = elem->id();
101  libmesh_assert_less (id, error_per_cell.size());
102 
103  error_max = std::max (error_max, error_per_cell[id]);
104  error_min = std::min (error_min, error_per_cell[id]);
105  }
106  this->comm().max(error_max);
107  this->comm().min(error_min);
108 
109  // Compute the cutoff values for coarsening and refinement
110  const Real error_delta = (error_max - error_min);
111  const Real parent_error_delta = parent_error_max - parent_error_min;
112 
113  const Real refine_cutoff = (1.- _refine_fraction)*error_max;
114  const Real coarsen_cutoff = _coarsen_fraction*error_delta + error_min;
115  const Real parent_cutoff = _coarsen_fraction*parent_error_delta + error_min;
116 
117  // // Print information about the error
118  // libMesh::out << " Error Information:" << std::endl
119  // << " ------------------" << std::endl
120  // << " min: " << error_min << std::endl
121  // << " max: " << error_max << std::endl
122  // << " delta: " << error_delta << std::endl
123  // << " refine_cutoff: " << refine_cutoff << std::endl
124  // << " coarsen_cutoff: " << coarsen_cutoff << std::endl;
125 
126 
127 
128  // Loop over the elements and flag them for coarsening or
129  // refinement based on the element error
130  for (auto & elem : _mesh.active_element_ptr_range())
131  {
132  const dof_id_type id = elem->id();
133 
134  libmesh_assert_less (id, error_per_cell.size());
135 
136  const ErrorVectorReal elem_error = error_per_cell[id];
137 
139  {
140  Elem * parent = elem->parent();
141  if (parent)
142  {
143  const dof_id_type parentid = parent->id();
144  if (error_per_parent[parentid] >= 0. &&
145  error_per_parent[parentid] <= parent_cutoff)
146  elem->set_refinement_flag(Elem::COARSEN);
147  }
148  }
149  // Flag the element for coarsening if its error
150  // is <= coarsen_fraction*delta + error_min
151  else if (elem_error <= coarsen_cutoff)
152  {
153  elem->set_refinement_flag(Elem::COARSEN);
154  }
155 
156  // Flag the element for refinement if its error
157  // is >= refinement_cutoff.
158  if (elem_error >= refine_cutoff)
159  if (elem->level() < _max_h_level)
160  elem->set_refinement_flag(Elem::REFINE);
161  }
162 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
Calculates the error on all coarsenable parents.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
long double min(long double a, double b)
bool _coarsen_by_parents
Refinement parameter values.
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::MeshRefinement::flag_elements_by_error_tolerance ( const ErrorVector error_per_cell)

Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.

This method refines the worst elements with errors greater than absolute_global_tolerance / n_active_elem, flagging at most refine_fraction * n_active_elem It coarsens elements with errors less than coarsen_threshold * global_tolerance / n_active_elem, flagging at most coarsen_fraction * n_active_elem

The three fractions refine_fraction coarsen_fraction and coarsen_threshold should be in $ [0,1] $.

Definition at line 166 of file mesh_refinement_flagging.C.

References _absolute_global_tolerance, _coarsen_by_parents, _coarsen_fraction, _coarsen_threshold, _max_h_level, _mesh, _refine_fraction, libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::COARSEN, create_parent_error_vector(), libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::MeshBase::n_active_elem(), libMesh::Elem::n_children(), libMesh::Elem::parent(), libMesh::Real, and libMesh::Elem::REFINE.

Referenced by libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

167 {
168  parallel_object_only();
169 
170  libmesh_assert_greater (_coarsen_threshold, 0);
171 
172  // Check for valid fractions..
173  // The fraction values must be in [0,1]
174  libmesh_assert_greater_equal (_refine_fraction, 0);
175  libmesh_assert_less_equal (_refine_fraction, 1);
176  libmesh_assert_greater_equal (_coarsen_fraction, 0);
177  libmesh_assert_less_equal (_coarsen_fraction, 1);
178 
179  // How much error per cell will we tolerate?
180  const Real local_refinement_tolerance =
181  _absolute_global_tolerance / std::sqrt(static_cast<Real>(_mesh.n_active_elem()));
182  const Real local_coarsening_tolerance =
183  local_refinement_tolerance * _coarsen_threshold;
184 
185  // Prepare another error vector if we need to sum parent errors
186  ErrorVector error_per_parent;
188  {
189  Real parent_error_min, parent_error_max;
190 
191  create_parent_error_vector(error_per_cell_in,
192  error_per_parent,
193  parent_error_min,
194  parent_error_max);
195  }
196 
197  for (auto & elem : _mesh.active_element_ptr_range())
198  {
199  Elem * parent = elem->parent();
200  const dof_id_type elem_number = elem->id();
201  const ErrorVectorReal elem_error = error_per_cell_in[elem_number];
202 
203  if (elem_error > local_refinement_tolerance &&
204  elem->level() < _max_h_level)
205  elem->set_refinement_flag(Elem::REFINE);
206 
207  if (!_coarsen_by_parents && elem_error <
208  local_coarsening_tolerance)
209  elem->set_refinement_flag(Elem::COARSEN);
210 
211  if (_coarsen_by_parents && parent)
212  {
213  ErrorVectorReal parent_error = error_per_parent[parent->id()];
214  if (parent_error >= 0.)
215  {
216  const Real parent_coarsening_tolerance =
217  std::sqrt(parent->n_children() *
218  local_coarsening_tolerance *
219  local_coarsening_tolerance);
220  if (parent_error < parent_coarsening_tolerance)
221  elem->set_refinement_flag(Elem::COARSEN);
222  }
223  }
224  }
225 }
virtual dof_id_type n_active_elem() const =0
MeshBase & _mesh
Reference to the mesh.
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
Calculates the error on all coarsenable parents.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool _coarsen_by_parents
Refinement parameter values.
uint8_t dof_id_type
Definition: id_types.h:64
void libMesh::MeshRefinement::flag_elements_by_mean_stddev ( const ErrorVector error_per_cell,
const Real  refine_fraction = 1.0,
const Real  coarsen_fraction = 0.0,
const unsigned int  max_level = libMesh::invalid_uint 
)

Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.

This method picks the top refine_fraction * stddev + mean elements for refinement and the bottom mean - coarsen_fraction * stddev elements for coarsening. The two fractions refine_fraction and coarsen_fraction must be in $ [0,1] $.

All the function arguments except error_per_cell have been deprecated, and will be removed in future libMesh releases - to control these parameters, set the corresponding member variables.

Definition at line 568 of file mesh_refinement_flagging.C.

References _coarsen_fraction, _max_h_level, _mesh, _refine_fraction, _use_member_parameters, libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::COARSEN, libMesh::ErrorVectorReal, libMesh::invalid_uint, std::max(), libMesh::ErrorVector::mean(), libMesh::Real, libMesh::Elem::REFINE, and libMesh::ErrorVector::variance().

Referenced by libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

572 {
573  // The function arguments are currently just there for
574  // backwards_compatibility
576  {
577  // If the user used non-default parameters, lets warn
578  // that they're deprecated
579  if (refine_frac != 0.3 ||
580  coarsen_frac != 0.0 ||
581  max_l != libMesh::invalid_uint)
582  libmesh_deprecated();
583 
584  _refine_fraction = refine_frac;
585  _coarsen_fraction = coarsen_frac;
586  _max_h_level = max_l;
587  }
588 
589  // Get the mean value from the error vector
590  const Real mean = error_per_cell.mean();
591 
592  // Get the standard deviation. This equals the
593  // square-root of the variance
594  const Real stddev = std::sqrt (error_per_cell.variance());
595 
596  // Check for valid fractions
597  libmesh_assert_greater_equal (_refine_fraction, 0);
598  libmesh_assert_less_equal (_refine_fraction, 1);
599  libmesh_assert_greater_equal (_coarsen_fraction, 0);
600  libmesh_assert_less_equal (_coarsen_fraction, 1);
601 
602  // The refine and coarsen cutoff
603  const Real refine_cutoff = mean + _refine_fraction * stddev;
604  const Real coarsen_cutoff = std::max(mean - _coarsen_fraction * stddev, 0.);
605 
606  // Loop over the elements and flag them for coarsening or
607  // refinement based on the element error
608  for (auto & elem : _mesh.active_element_ptr_range())
609  {
610  const dof_id_type id = elem->id();
611 
612  libmesh_assert_less (id, error_per_cell.size());
613 
614  const ErrorVectorReal elem_error = error_per_cell[id];
615 
616  // Possibly flag the element for coarsening ...
617  if (elem_error <= coarsen_cutoff)
618  elem->set_refinement_flag(Elem::COARSEN);
619 
620  // ... or refinement
621  if ((elem_error >= refine_cutoff) && (elem->level() < _max_h_level))
622  elem->set_refinement_flag(Elem::REFINE);
623  }
624 }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t dof_id_type
Definition: id_types.h:64
bool libMesh::MeshRefinement::flag_elements_by_nelem_target ( const ErrorVector error_per_cell)

Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.

This method attempts to produce a mesh with slightly more than nelem_target active elements, trading element refinement for element coarsening when their error ratios exceed coarsen_threshold. It flags no more than refine_fraction * n_elem elements for refinement and flags no more than coarsen_fraction * n_elem elements for coarsening.

Returns
true if it has done all the AMR/C it can do in a single step, or false if further adaptive steps may be required to produce a mesh with a narrow error distribution and the right number of elements.

Definition at line 229 of file mesh_refinement_flagging.C.

References _coarsen_by_parents, _coarsen_fraction, _coarsen_threshold, _max_h_level, _mesh, _nelem_target, _refine_fraction, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::Parallel::Communicator::allgather(), libMesh::Elem::child_ref_range(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), dim, libMesh::Elem::has_children(), libMesh::Elem::level(), libMesh::libmesh_assert(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::mesh_dimension(), std::min(), libMesh::MeshBase::n_active_elem(), libMesh::MeshBase::query_elem_ptr(), libMesh::Real, libMesh::Elem::REFINE, libMesh::remote_elem, and libMesh::Elem::set_refinement_flag().

Referenced by libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

230 {
231  parallel_object_only();
232 
233  // Check for valid fractions..
234  // The fraction values must be in [0,1]
235  libmesh_assert_greater_equal (_refine_fraction, 0);
236  libmesh_assert_less_equal (_refine_fraction, 1);
237  libmesh_assert_greater_equal (_coarsen_fraction, 0);
238  libmesh_assert_less_equal (_coarsen_fraction, 1);
239 
240  // This function is currently only coded to work when coarsening by
241  // parents - it's too hard to guess how many coarsenings will be
242  // performed otherwise.
244 
245  // The number of active elements in the mesh - hopefully less than
246  // 2 billion on 32 bit machines
247  const dof_id_type n_active_elem = _mesh.n_active_elem();
248 
249  // The maximum number of active elements to flag for coarsening
250  const dof_id_type max_elem_coarsen =
251  static_cast<dof_id_type>(_coarsen_fraction * n_active_elem) + 1;
252 
253  // The maximum number of elements to flag for refinement
254  const dof_id_type max_elem_refine =
255  static_cast<dof_id_type>(_refine_fraction * n_active_elem) + 1;
256 
257  // Clean up the refinement flags. These could be left
258  // over from previous refinement steps.
259  this->clean_refinement_flags();
260 
261  // The target number of elements to add or remove
262  const std::ptrdiff_t n_elem_new =
263  std::ptrdiff_t(_nelem_target) - std::ptrdiff_t(n_active_elem);
264 
265  // Create an vector with active element errors and ids,
266  // sorted by highest errors first
267  const dof_id_type max_elem_id = _mesh.max_elem_id();
268  std::vector<std::pair<ErrorVectorReal, dof_id_type>> sorted_error;
269 
270  sorted_error.reserve (n_active_elem);
271 
272  // On a DistributedMesh, we need to communicate to know which remote ids
273  // correspond to active elements.
274  {
275  std::vector<bool> is_active(max_elem_id, false);
276 
277  for (auto & elem : _mesh.active_local_element_ptr_range())
278  {
279  const dof_id_type eid = elem->id();
280  is_active[eid] = true;
281  libmesh_assert_less (eid, error_per_cell.size());
282  sorted_error.push_back
283  (std::make_pair(error_per_cell[eid], eid));
284  }
285 
286  this->comm().max(is_active);
287 
288  this->comm().allgather(sorted_error);
289  }
290 
291  // Default sort works since pairs are sorted lexicographically
292  std::sort (sorted_error.begin(), sorted_error.end());
293  std::reverse (sorted_error.begin(), sorted_error.end());
294 
295  // Create a sorted error vector with coarsenable parent elements
296  // only, sorted by lowest errors first
297  ErrorVector error_per_parent;
298  std::vector<std::pair<ErrorVectorReal, dof_id_type>> sorted_parent_error;
299  Real parent_error_min, parent_error_max;
300 
301  create_parent_error_vector(error_per_cell,
302  error_per_parent,
303  parent_error_min,
304  parent_error_max);
305 
306  // create_parent_error_vector sets values for non-parents and
307  // non-coarsenable parents to -1. Get rid of them.
308  for (std::size_t i=0; i != error_per_parent.size(); ++i)
309  if (error_per_parent[i] != -1)
310  sorted_parent_error.push_back(std::make_pair(error_per_parent[i], i));
311 
312  std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
313 
314  // Keep track of how many elements we plan to coarsen & refine
315  dof_id_type coarsen_count = 0;
316  dof_id_type refine_count = 0;
317 
318  const unsigned int dim = _mesh.mesh_dimension();
319  unsigned int twotodim = 1;
320  for (unsigned int i=0; i!=dim; ++i)
321  twotodim *= 2;
322 
323  // First, let's try to get our element count to target_nelem
324  if (n_elem_new >= 0)
325  {
326  // Every element refinement creates at least
327  // 2^dim-1 new elements
328  refine_count =
329  std::min(cast_int<dof_id_type>(n_elem_new / (twotodim-1)),
330  max_elem_refine);
331  }
332  else
333  {
334  // Every successful element coarsening is likely to destroy
335  // 2^dim-1 net elements.
336  coarsen_count =
337  std::min(cast_int<dof_id_type>(-n_elem_new / (twotodim-1)),
338  max_elem_coarsen);
339  }
340 
341  // Next, let's see if we can trade any refinement for coarsening
342  while (coarsen_count < max_elem_coarsen &&
343  refine_count < max_elem_refine &&
344  coarsen_count < sorted_parent_error.size() &&
345  refine_count < sorted_error.size() &&
346  sorted_error[refine_count].first >
347  sorted_parent_error[coarsen_count].first * _coarsen_threshold)
348  {
349  coarsen_count++;
350  refine_count++;
351  }
352 
353  // On a DistributedMesh, we need to communicate to know which remote ids
354  // correspond to refinable elements
355  dof_id_type successful_refine_count = 0;
356  {
357  std::vector<bool> is_refinable(max_elem_id, false);
358 
359  for (std::size_t i=0; i != sorted_error.size(); ++i)
360  {
361  dof_id_type eid = sorted_error[i].second;
362  Elem * elem = _mesh.query_elem_ptr(eid);
363  if (elem && elem->level() < _max_h_level)
364  is_refinable[eid] = true;
365  }
366  this->comm().max(is_refinable);
367 
368  if (refine_count > max_elem_refine)
369  refine_count = max_elem_refine;
370  for (std::size_t i=0; i != sorted_error.size(); ++i)
371  {
372  if (successful_refine_count >= refine_count)
373  break;
374 
375  dof_id_type eid = sorted_error[i].second;
376  Elem * elem = _mesh.query_elem_ptr(eid);
377  if (is_refinable[eid])
378  {
379  if (elem)
381  successful_refine_count++;
382  }
383  }
384  }
385 
386  // If we couldn't refine enough elements, don't coarsen too many
387  // either
388  if (coarsen_count < (refine_count - successful_refine_count))
389  coarsen_count = 0;
390  else
391  coarsen_count -= (refine_count - successful_refine_count);
392 
393  if (coarsen_count > max_elem_coarsen)
394  coarsen_count = max_elem_coarsen;
395 
396  dof_id_type successful_coarsen_count = 0;
397  if (coarsen_count)
398  {
399  for (std::size_t i=0; i != sorted_parent_error.size(); ++i)
400  {
401  if (successful_coarsen_count >= coarsen_count * twotodim)
402  break;
403 
404  dof_id_type parent_id = sorted_parent_error[i].second;
405  Elem * parent = _mesh.query_elem_ptr(parent_id);
406 
407  // On a DistributedMesh we skip remote elements
408  if (!parent)
409  continue;
410 
411  libmesh_assert(parent->has_children());
412  for (auto & elem : parent->child_ref_range())
413  {
414  if (&elem != remote_elem)
415  {
416  libmesh_assert(elem.active());
417  elem.set_refinement_flag(Elem::COARSEN);
418  successful_coarsen_count++;
419  }
420  }
421  }
422  }
423 
424  // Return true if we've done all the AMR/C we can
425  if (!successful_coarsen_count &&
426  !successful_refine_count)
427  return true;
428  // And false if there may still be more to do.
429  return false;
430 }
virtual dof_id_type n_active_elem() const =0
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
unsigned int dim
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
Calculates the error on all coarsenable parents.
libmesh_assert(j)
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
virtual dof_id_type max_elem_id() const =0
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
unsigned int mesh_dimension() const
Definition: mesh_base.C:148
long double min(long double a, double b)
bool _coarsen_by_parents
Refinement parameter values.
uint8_t dof_id_type
Definition: id_types.h:64
void allgather(const T &send, std::vector< T > &recv) const
Take a vector of length this->size(), and fill in recv[processor_id] = the value of send on that proc...
const RemoteElem * remote_elem
Definition: remote_elem.C:57
bool libMesh::MeshRefinement::get_enforce_mismatch_limit_prior_to_refinement ( )
Returns
The value of the _enforce_mismatch_limit_prior_to_refinement flag, false by default.
Deprecated:
Use enforce_mismatch_limit_prior_to_refinement() instead.

Definition at line 936 of file mesh_refinement.h.

References enforce_mismatch_limit_prior_to_refinement().

Referenced by get_mesh().

937 {
938  libmesh_deprecated();
940 }
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
const MeshBase& libMesh::MeshRefinement::get_mesh ( ) const
Returns
A constant reference to the MeshBase object associated with this object.

Definition at line 322 of file mesh_refinement.h.

References _mesh.

322 { return _mesh; }
MeshBase & _mesh
Reference to the mesh.
MeshBase& libMesh::MeshRefinement::get_mesh ( )
bool libMesh::MeshRefinement::has_topological_neighbor ( const Elem elem,
const PointLocatorBase point_locator,
const Elem neighbor 
)
private

Local dispatch function for checking the correct has_neighbor function from the Elem class.

Definition at line 1840 of file mesh_refinement.C.

References _mesh, _periodic_boundaries, libMesh::Elem::has_neighbor(), libMesh::Elem::has_topological_neighbor(), and libMesh::libmesh_assert().

Referenced by get_mesh(), make_coarsening_compatible(), and make_refinement_compatible().

1843 {
1844 #ifdef LIBMESH_ENABLE_PERIODIC
1845  if (_periodic_boundaries && !_periodic_boundaries->empty())
1846  {
1847  libmesh_assert(point_locator);
1848  return elem->has_topological_neighbor(neighbor, _mesh, *point_locator, _periodic_boundaries);
1849  }
1850 #endif
1851  return elem->has_neighbor(neighbor);
1852 }
bool has_topological_neighbor(const Elem *elem, const MeshBase &mesh, const PointLocatorBase &point_locator, const PeriodicBoundaries *pb) const
Definition: elem.C:1104
MeshBase & _mesh
Reference to the mesh.
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
bool has_neighbor(const Elem *elem) const
Definition: elem.h:2010
bool libMesh::MeshRefinement::limit_level_mismatch_at_edge ( const unsigned int  max_mismatch)
private

Definition at line 126 of file mesh_refinement_smoothing.C.

References _enforce_mismatch_limit_prior_to_refinement, _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::ParallelObject::comm(), EDGE, enforce_mismatch_limit_prior_to_refinement(), libmesh_nullptr, std::max(), libMesh::Parallel::Communicator::max(), libMesh::Elem::REFINE, and swap().

Referenced by _smooth_flags(), and get_mesh().

127 {
128  // This function must be run on all processors at once
129  parallel_object_only();
130 
131  bool flags_changed = false;
132 
133 
134  // Maps holding the maximum element level that touches an edge
135  std::map<std::pair<unsigned int, unsigned int>, unsigned char>
136  max_level_at_edge;
137  std::map<std::pair<unsigned int, unsigned int>, unsigned char>
138  max_p_level_at_edge;
139 
140  // Loop over all the active elements & fill the maps
141  for (auto & elem : _mesh.active_element_ptr_range())
142  {
143  const unsigned char elem_level =
144  cast_int<unsigned char>(elem->level() +
145  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
146  const unsigned char elem_p_level =
147  cast_int<unsigned char>(elem->p_level() +
148  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
149 
150  // Set the max_level at each edge
151  for (unsigned int n=0; n<elem->n_edges(); n++)
152  {
153  UniquePtr<const Elem> edge = elem->build_edge_ptr(n);
154  dof_id_type childnode0 = edge->node_id(0);
155  dof_id_type childnode1 = edge->node_id(1);
156  if (childnode1 < childnode0)
157  std::swap(childnode0, childnode1);
158 
159  for (const Elem * p = elem; p != libmesh_nullptr; p = p->parent())
160  {
161  UniquePtr<const Elem> pedge = p->build_edge_ptr(n);
162  dof_id_type node0 = pedge->node_id(0);
163  dof_id_type node1 = pedge->node_id(1);
164 
165  if (node1 < node0)
166  std::swap(node0, node1);
167 
168  // If elem does not share this edge with its ancestor
169  // p, refinement levels of elements sharing p's edge
170  // are not restricted by refinement levels of elem.
171  // Furthermore, elem will not share this edge with any
172  // of p's ancestors, so we can safely break out of the
173  // for loop early.
174  if (node0 != childnode0 && node1 != childnode1)
175  break;
176 
177  childnode0 = node0;
178  childnode1 = node1;
179 
180  std::pair<unsigned int, unsigned int> edge_key =
181  std::make_pair(node0, node1);
182 
183  if (max_level_at_edge.find(edge_key) ==
184  max_level_at_edge.end())
185  {
186  max_level_at_edge[edge_key] = elem_level;
187  max_p_level_at_edge[edge_key] = elem_p_level;
188  }
189  else
190  {
191  max_level_at_edge[edge_key] =
192  std::max (max_level_at_edge[edge_key], elem_level);
193  max_p_level_at_edge[edge_key] =
194  std::max (max_p_level_at_edge[edge_key], elem_p_level);
195  }
196  }
197  }
198  }
199 
200 
201  // Now loop over the active elements and flag the elements
202  // who violate the requested level mismatch
203  for (auto & elem : _mesh.active_element_ptr_range())
204  {
205  const unsigned int elem_level = elem->level();
206  const unsigned int elem_p_level = elem->p_level();
207 
208  // Skip the element if it is already fully flagged
209  if (elem->refinement_flag() == Elem::REFINE &&
210  elem->p_refinement_flag() == Elem::REFINE
212  continue;
213 
214  // Loop over the nodes, check for possible mismatch
215  for (unsigned int n=0; n<elem->n_edges(); n++)
216  {
217  UniquePtr<Elem> edge = elem->build_edge_ptr(n);
218  dof_id_type node0 = edge->node_id(0);
219  dof_id_type node1 = edge->node_id(1);
220  if (node1 < node0)
221  std::swap(node0, node1);
222 
223  std::pair<dof_id_type, dof_id_type> edge_key =
224  std::make_pair(node0, node1);
225 
226  // Flag the element for refinement if it violates
227  // the requested level mismatch
228  if ((elem_level + max_mismatch) < max_level_at_edge[edge_key]
229  && elem->refinement_flag() != Elem::REFINE)
230  {
231  elem->set_refinement_flag (Elem::REFINE);
232  flags_changed = true;
233  }
234 
235  if ((elem_p_level + max_mismatch) < max_p_level_at_edge[edge_key]
236  && elem->p_refinement_flag() != Elem::REFINE)
237  {
238  elem->set_p_refinement_flag (Elem::REFINE);
239  flags_changed = true;
240  }
241 
242  // Possibly enforce limit mismatch prior to refinement
243  flags_changed |= this->enforce_mismatch_limit_prior_to_refinement(elem, EDGE, max_mismatch);
244  } // loop over edges
245  } // loop over active elements
246 
247  // If flags changed on any processor then they changed globally
248  this->comm().max(flags_changed);
249 
250  return flags_changed;
251 }
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
const class libmesh_nullptr_t libmesh_nullptr
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
const Parallel::Communicator & comm() const
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
uint8_t dof_id_type
Definition: id_types.h:64
bool libMesh::MeshRefinement::limit_level_mismatch_at_node ( const unsigned int  max_mismatch)
private

This algorithm restricts the maximum level mismatch at any node in the mesh.

Calling this with max_mismatch equal to 1 would transform this mesh:

* o---o---o---o---o-------o-------o
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o       |       |
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o-------o-------o
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o       |       |
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o-------o-------o
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* o-------o-------o               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* o-------o-------o---------------o
* 

into this:

* o---o---o---o---o-------o-------o
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o       |       |
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o-------o-------o
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o       |       |
* |   |   |   |   |       |       |
* |   |   |   |   |       |       |
* o---o---o---o---o-------o-------o
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* o-------o-------o.......o.......o
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* o-------o-------o-------o-------o
* 

by refining the indicated element

Definition at line 39 of file mesh_refinement_smoothing.C.

References _enforce_mismatch_limit_prior_to_refinement, _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::ParallelObject::comm(), enforce_mismatch_limit_prior_to_refinement(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::n_nodes(), POINT, and libMesh::Elem::REFINE.

Referenced by _smooth_flags(), and get_mesh().

40 {
41  // This function must be run on all processors at once
42  parallel_object_only();
43 
44  bool flags_changed = false;
45 
46 
47  // Vector holding the maximum element level that touches a node.
48  std::vector<unsigned char> max_level_at_node (_mesh.n_nodes(), 0);
49  std::vector<unsigned char> max_p_level_at_node (_mesh.n_nodes(), 0);
50 
51  // Loop over all the active elements & fill the vector
52  for (auto & elem : _mesh.active_element_ptr_range())
53  {
54  const unsigned char elem_level =
55  cast_int<unsigned char>(elem->level() +
56  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
57  const unsigned char elem_p_level =
58  cast_int<unsigned char>(elem->p_level() +
59  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
60 
61  // Set the max_level at each node
62  for (unsigned int n=0; n<elem->n_nodes(); n++)
63  {
64  const dof_id_type node_number = elem->node_id(n);
65 
66  libmesh_assert_less (node_number, max_level_at_node.size());
67 
68  max_level_at_node[node_number] =
69  std::max (max_level_at_node[node_number], elem_level);
70  max_p_level_at_node[node_number] =
71  std::max (max_p_level_at_node[node_number], elem_p_level);
72  }
73  }
74 
75 
76  // Now loop over the active elements and flag the elements
77  // who violate the requested level mismatch. Alternatively, if
78  // _enforce_mismatch_limit_prior_to_refinement is true, swap refinement flags
79  // accordingly.
80  for (auto & elem : _mesh.active_element_ptr_range())
81  {
82  const unsigned int elem_level = elem->level();
83  const unsigned int elem_p_level = elem->p_level();
84 
85  // Skip the element if it is already fully flagged
86  // unless we are enforcing mismatch prior to refinement and may need to
87  // remove the refinement flag(s)
88  if (elem->refinement_flag() == Elem::REFINE &&
89  elem->p_refinement_flag() == Elem::REFINE
91  continue;
92 
93  // Loop over the nodes, check for possible mismatch
94  for (unsigned int n=0; n<elem->n_nodes(); n++)
95  {
96  const dof_id_type node_number = elem->node_id(n);
97 
98  // Flag the element for refinement if it violates
99  // the requested level mismatch
100  if ((elem_level + max_mismatch) < max_level_at_node[node_number]
101  && elem->refinement_flag() != Elem::REFINE)
102  {
103  elem->set_refinement_flag (Elem::REFINE);
104  flags_changed = true;
105  }
106  if ((elem_p_level + max_mismatch) < max_p_level_at_node[node_number]
107  && elem->p_refinement_flag() != Elem::REFINE)
108  {
109  elem->set_p_refinement_flag (Elem::REFINE);
110  flags_changed = true;
111  }
112 
113  // Possibly enforce limit mismatch prior to refinement
114  flags_changed |= this->enforce_mismatch_limit_prior_to_refinement(elem, POINT, max_mismatch);
115  }
116  }
117 
118  // If flags changed on any processor then they changed globally
119  this->comm().max(flags_changed);
120 
121  return flags_changed;
122 }
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
bool _enforce_mismatch_limit_prior_to_refinement
This option enforces the mismatch level prior to refinement by checking if refining any element marke...
const Parallel::Communicator & comm() const
virtual dof_id_type n_nodes() const =0
uint8_t dof_id_type
Definition: id_types.h:64
bool libMesh::MeshRefinement::limit_overrefined_boundary ( const signed char  max_mismatch)
private

Definition at line 255 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::ParallelObject::comm(), libMesh::Elem::level(), libMesh::Parallel::Communicator::max(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), and libMesh::Elem::set_refinement_flag().

Referenced by _smooth_flags(), and get_mesh().

256 {
257  // This function must be run on all processors at once
258  parallel_object_only();
259 
260  bool flags_changed = false;
261 
262  // Loop over all the active elements & look for mismatches to fix.
263  for (auto & elem : _mesh.active_element_ptr_range())
264  {
265  // If we don't have an interior_parent then there's nothing to
266  // be mismatched with.
267  if ((elem->dim() >= LIBMESH_DIM) ||
268  !elem->interior_parent())
269  continue;
270 
271  const unsigned char elem_level =
272  cast_int<unsigned char>(elem->level() +
273  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
274  const unsigned char elem_p_level =
275  cast_int<unsigned char>(elem->p_level() +
276  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
277 
278  // get all relevant interior elements
279  std::set<const Elem *> neighbor_set;
280  elem->find_interior_neighbors(neighbor_set);
281 
282  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
283  for (; n_it != neighbor_set.end(); ++n_it)
284  {
285  // FIXME - non-const versions of the Elem set methods
286  // would be nice
287  Elem * neighbor = const_cast<Elem *>(*n_it);
288 
289  if (max_mismatch >= 0)
290  {
291  if ((elem_level > neighbor->level() + max_mismatch) &&
292  (neighbor->refinement_flag() != Elem::REFINE))
293  {
294  neighbor->set_refinement_flag(Elem::REFINE);
295  flags_changed = true;
296  }
297 
298  if ((elem_p_level > neighbor->p_level() + max_mismatch) &&
299  (neighbor->p_refinement_flag() != Elem::REFINE))
300  {
301  neighbor->set_p_refinement_flag(Elem::REFINE);
302  flags_changed = true;
303  }
304  }
305  } // loop over interior neighbors
306  }
307 
308  // If flags changed on any processor then they changed globally
309  this->comm().max(flags_changed);
310 
311  return flags_changed;
312 }
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
const Parallel::Communicator & comm() const
bool libMesh::MeshRefinement::limit_underrefined_boundary ( const signed char  max_mismatch)
private

Definition at line 316 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::ParallelObject::comm(), libMesh::Elem::level(), libMesh::Parallel::Communicator::max(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), and libMesh::Elem::set_refinement_flag().

Referenced by _smooth_flags(), and get_mesh().

317 {
318  // This function must be run on all processors at once
319  parallel_object_only();
320 
321  bool flags_changed = false;
322 
323  // Loop over all the active elements & look for mismatches to fix.
324  for (auto & elem : _mesh.active_element_ptr_range())
325  {
326  // If we don't have an interior_parent then there's nothing to
327  // be mismatched with.
328  if ((elem->dim() >= LIBMESH_DIM) ||
329  !elem->interior_parent())
330  continue;
331 
332  // get all relevant interior elements
333  std::set<const Elem *> neighbor_set;
334  elem->find_interior_neighbors(neighbor_set);
335 
336  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
337  for (; n_it != neighbor_set.end(); ++n_it)
338  {
339  // FIXME - non-const versions of the Elem set methods
340  // would be nice
341  const Elem * neighbor = *n_it;
342 
343  const unsigned char neighbor_level =
344  cast_int<unsigned char>(neighbor->level() +
345  ((neighbor->refinement_flag() == Elem::REFINE) ? 1 : 0));
346 
347  const unsigned char neighbor_p_level =
348  cast_int<unsigned char>(neighbor->p_level() +
349  ((neighbor->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
350 
351  if (max_mismatch >= 0)
352  {
353  if ((neighbor_level >
354  elem->level() + max_mismatch) &&
355  (elem->refinement_flag() != Elem::REFINE))
356  {
357  elem->set_refinement_flag(Elem::REFINE);
358  flags_changed = true;
359  }
360 
361  if ((neighbor_p_level >
362  elem->p_level() + max_mismatch) &&
363  (elem->p_refinement_flag() != Elem::REFINE))
364  {
365  elem->set_p_refinement_flag(Elem::REFINE);
366  flags_changed = true;
367  }
368  }
369  } // loop over interior neighbors
370  }
371 
372  // If flags changed on any processor then they changed globally
373  this->comm().max(flags_changed);
374 
375  return flags_changed;
376 }
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
const Parallel::Communicator & comm() const
bool libMesh::MeshRefinement::make_coarsening_compatible ( )
private

Take user-specified coarsening flags and augment them so that level-one dependency is satisfied.

This function used to take an argument, maintain_level_one - new code should use face_level_mismatch_limit() instead.

Definition at line 795 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::ancestor(), libMesh::MeshBase::ancestor_elements_begin(), libMesh::MeshBase::ancestor_elements_end(), libMesh::Parallel::any_source, libMesh::Elem::child_ref_range(), libMesh::Elem::COARSEN, libMesh::Elem::COARSEN_INACTIVE, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::elem_ref(), end, libMesh::Parallel::Communicator::get_unique_tag(), libMesh::Elem::has_children(), has_topological_neighbor(), libMesh::DofObject::id(), libMesh::Elem::INACTIVE, libMesh::MeshBase::is_replicated(), libMesh::MeshBase::is_serial(), libMesh::Elem::level(), libMesh::MeshBase::level_elements_begin(), libMesh::MeshBase::level_elements_end(), libMesh::libmesh_assert(), libmesh_nullptr, std::max(), libMesh::MeshTools::max_level(), libMesh::Parallel::Communicator::min(), libMesh::ParallelObject::n_processors(), libMesh::MeshBase::not_local_elements_begin(), libMesh::MeshBase::not_local_elements_end(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::Parallel::Communicator::receive(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::remote_elem, libMesh::Parallel::Communicator::send(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), libMesh::Elem::side_index_range(), libMesh::MeshBase::sub_point_locator(), libMesh::Parallel::sync_dofobject_data_by_id(), topological_neighbor(), libMesh::Parallel::verify(), and libMesh::Parallel::wait().

Referenced by _smooth_flags(), coarsen_elements(), get_mesh(), and refine_and_coarsen_elements().

796 {
797  // This function must be run on all processors at once
798  parallel_object_only();
799 
800  // We may need a PointLocator for topological_neighbor() tests
801  // later, which we need to make sure gets constructed on all
802  // processors at once.
803  UniquePtr<PointLocatorBase> point_locator;
804 
805 #ifdef LIBMESH_ENABLE_PERIODIC
806  bool has_periodic_boundaries =
808  libmesh_assert(this->comm().verify(has_periodic_boundaries));
809 
810  if (has_periodic_boundaries)
811  point_locator = _mesh.sub_point_locator();
812 #endif
813 
814  LOG_SCOPE ("make_coarsening_compatible()", "MeshRefinement");
815 
816  // Unless we encounter a specific situation level-one
817  // will be satisfied after executing this loop just once
818  bool level_one_satisfied = true;
819 
820 
821  // Unless we encounter a specific situation we will be compatible
822  // with any selected refinement flags
823  bool compatible_with_refinement = true;
824 
825 
826  // find the maximum h and p levels in the mesh
827  unsigned int max_level = 0;
828  unsigned int max_p_level = 0;
829 
830  {
831  // First we look at all the active level-0 elements. Since it doesn't make
832  // sense to coarsen them we must un-set their coarsen flags if
833  // they are set.
834  for (auto & elem : _mesh.active_element_ptr_range())
835  {
836  max_level = std::max(max_level, elem->level());
837  max_p_level =
838  std::max(max_p_level,
839  static_cast<unsigned int>(elem->p_level()));
840 
841  if ((elem->level() == 0) &&
842  (elem->refinement_flag() == Elem::COARSEN))
843  elem->set_refinement_flag(Elem::DO_NOTHING);
844 
845  if ((elem->p_level() == 0) &&
846  (elem->p_refinement_flag() == Elem::COARSEN))
847  elem->set_p_refinement_flag(Elem::DO_NOTHING);
848  }
849  }
850 
851  // Even if there are no refined elements on this processor then
852  // there may still be work for us to do on e.g. ancestor elements.
853  // At the very least we need to be in the loop if a distributed mesh
854  // needs to synchronize data.
855 #if 0
856  if (max_level == 0 && max_p_level == 0)
857  {
858  // But we still have to check with other processors
859  this->comm().min(compatible_with_refinement);
860 
861  return compatible_with_refinement;
862  }
863 #endif
864 
865  // Loop over all the active elements. If an element is marked
866  // for coarsening we better check its neighbors. If ANY of these neighbors
867  // are marked for refinement AND are at the same level then there is a
868  // conflict. By convention refinement wins, so we un-mark the element for
869  // coarsening. Level-one would be violated in this case so we need to re-run
870  // the loop.
872  {
873 
874  repeat:
875  level_one_satisfied = true;
876 
877  do
878  {
879  level_one_satisfied = true;
880 
881  for (auto & elem : _mesh.active_element_ptr_range())
882  {
883  bool my_flag_changed = false;
884 
885  if (elem->refinement_flag() == Elem::COARSEN) // If the element is active and
886  // the coarsen flag is set
887  {
888  const unsigned int my_level = elem->level();
889 
890  for (auto n : elem->side_index_range())
891  {
892  const Elem * neighbor =
893  topological_neighbor(elem, point_locator.get(), n);
894 
895  if (neighbor != libmesh_nullptr && // I have a
896  neighbor != remote_elem) // neighbor here
897  {
898  if (neighbor->active()) // and it is active
899  {
900  if ((neighbor->level() == my_level) &&
901  (neighbor->refinement_flag() == Elem::REFINE)) // the neighbor is at my level
902  // and wants to be refined
903  {
905  my_flag_changed = true;
906  break;
907  }
908  }
909  else // I have a neighbor and it is not active. That means it has children.
910  { // While it _may_ be possible to coarsen us if all the children of
911  // that element want to be coarsened, it is impossible to know at this
912  // stage. Forget about it for the moment... This can be handled in
913  // two steps.
914  elem->set_refinement_flag(Elem::DO_NOTHING);
915  my_flag_changed = true;
916  break;
917  }
918  }
919  }
920  }
921  if (elem->p_refinement_flag() == Elem::COARSEN) // If
922  // the element is active and the order reduction flag is set
923  {
924  const unsigned int my_p_level = elem->p_level();
925 
926  for (auto n : elem->side_index_range())
927  {
928  const Elem * neighbor =
929  topological_neighbor(elem, point_locator.get(), n);
930 
931  if (neighbor != libmesh_nullptr && // I have a
932  neighbor != remote_elem) // neighbor here
933  {
934  if (neighbor->active()) // and it is active
935  {
936  if ((neighbor->p_level() > my_p_level &&
937  neighbor->p_refinement_flag() != Elem::COARSEN)
938  || (neighbor->p_level() == my_p_level &&
939  neighbor->p_refinement_flag() == Elem::REFINE))
940  {
942  my_flag_changed = true;
943  break;
944  }
945  }
946  else // I have a neighbor and it is not active.
947  { // We need to find which of its children
948  // have me as a neighbor, and maintain
949  // level one p compatibility with them.
950  // Because we currently have level one h
951  // compatibility, we don't need to check
952  // grandchildren
953 
954  libmesh_assert(neighbor->has_children());
955  for (auto & subneighbor : neighbor->child_ref_range())
956  if (&subneighbor != remote_elem &&
957  subneighbor.active() &&
958  has_topological_neighbor(&subneighbor, point_locator.get(), elem))
959  if ((subneighbor.p_level() > my_p_level &&
960  subneighbor.p_refinement_flag() != Elem::COARSEN)
961  || (subneighbor.p_level() == my_p_level &&
962  subneighbor.p_refinement_flag() == Elem::REFINE))
963  {
964  elem->set_p_refinement_flag(Elem::DO_NOTHING);
965  my_flag_changed = true;
966  break;
967  }
968  if (my_flag_changed)
969  break;
970  }
971  }
972  }
973  }
974 
975  // If the current element's flag changed, we hadn't
976  // satisfied the level one rule.
977  if (my_flag_changed)
978  level_one_satisfied = false;
979 
980  // Additionally, if it has non-local neighbors, and
981  // we're not in serial, then we'll eventually have to
982  // return compatible_with_refinement = false, because
983  // our change has to propagate to neighboring
984  // processors.
985  if (my_flag_changed && !_mesh.is_serial())
986  for (auto n : elem->side_index_range())
987  {
988  Elem * neigh =
989  topological_neighbor(elem, point_locator.get(), n);
990 
991  if (!neigh)
992  continue;
993  if (neigh == remote_elem ||
994  neigh->processor_id() !=
995  this->processor_id())
996  {
997  compatible_with_refinement = false;
998  break;
999  }
1000  // FIXME - for non-level one meshes we should
1001  // test all descendants
1002  if (neigh->has_children())
1003  for (auto & child : neigh->child_ref_range())
1004  if (&child == remote_elem ||
1005  child.processor_id() !=
1006  this->processor_id())
1007  {
1008  compatible_with_refinement = false;
1009  break;
1010  }
1011  }
1012  }
1013  }
1014  while (!level_one_satisfied);
1015 
1016  } // end if (_face_level_mismatch_limit)
1017 
1018 
1019  // Next we look at all of the ancestor cells.
1020  // If there is a parent cell with all of its children
1021  // wanting to be unrefined then the element is a candidate
1022  // for unrefinement. If all the children don't
1023  // all want to be unrefined then ALL of them need to have their
1024  // unrefinement flags cleared.
1025  for (int level=(max_level); level >= 0; level--)
1026  {
1028  const MeshBase::element_iterator end_el = _mesh.level_elements_end(level);
1029  for (; el != end_el; ++el)
1030  {
1031  Elem * elem = *el;
1032  if (elem->ancestor())
1033  {
1034 
1035  // right now the element hasn't been disqualified
1036  // as a candidate for unrefinement
1037  bool is_a_candidate = true;
1038  bool found_remote_child = false;
1039 
1040  for (auto & child : elem->child_ref_range())
1041  {
1042  if (&child == remote_elem)
1043  found_remote_child = true;
1044  else if ((child.refinement_flag() != Elem::COARSEN) ||
1045  !child.active() )
1046  is_a_candidate = false;
1047  }
1048 
1049  if (!is_a_candidate && !found_remote_child)
1050  {
1052 
1053  for (auto & child : elem->child_ref_range())
1054  {
1055  if (&child == remote_elem)
1056  continue;
1057  if (child.refinement_flag() == Elem::COARSEN)
1058  {
1059  level_one_satisfied = false;
1060  child.set_refinement_flag(Elem::DO_NOTHING);
1061  }
1062  }
1063  }
1064  }
1065  }
1066  }
1067 
1068  if (!level_one_satisfied && _face_level_mismatch_limit) goto repeat;
1069 
1070 
1071  // If all the children of a parent are set to be coarsened
1072  // then flag the parent so that they can kill their kids.
1073 
1074  // On a distributed mesh, we won't always be able to determine this
1075  // on parent elements with remote children, even if we own the
1076  // parent, without communication.
1077  //
1078  // We'll first communicate *to* parents' owners when we determine
1079  // they cannot be coarsened, then we'll sync the final refinement
1080  // flag *from* the parents.
1081 
1082  // uncoarsenable_parents[p] live on processor id p
1083  const processor_id_type n_proc = _mesh.n_processors();
1084  const processor_id_type my_proc_id = _mesh.processor_id();
1085  const bool distributed_mesh = !_mesh.is_replicated();
1086 
1087  std::vector<std::vector<dof_id_type>>
1088  uncoarsenable_parents(n_proc);
1089 
1090  MeshBase::element_iterator ancestor_el =
1092  const MeshBase::element_iterator ancestor_el_end =
1094  for (; ancestor_el != ancestor_el_end; ++ancestor_el)
1095  {
1096  Elem * elem = *ancestor_el;
1097 
1098  // Presume all the children are flagged for coarsening and
1099  // then look for a contradiction
1100  bool all_children_flagged_for_coarsening = true;
1101 
1102  for (auto & child : elem->child_ref_range())
1103  {
1104  if (&child != remote_elem &&
1105  child.refinement_flag() != Elem::COARSEN)
1106  {
1107  all_children_flagged_for_coarsening = false;
1108  if (!distributed_mesh)
1109  break;
1110  if (child.processor_id() != elem->processor_id())
1111  {
1112  uncoarsenable_parents[elem->processor_id()].push_back(elem->id());
1113  break;
1114  }
1115  }
1116  }
1117 
1118  if (all_children_flagged_for_coarsening)
1120  else
1122  }
1123 
1124  // If we have a distributed mesh, we might need to sync up
1125  // INACTIVE vs. COARSEN_INACTIVE flags.
1126  if (distributed_mesh)
1127  {
1128  // We'd better still be in sync here
1129  parallel_object_only();
1130 
1132  uncoarsenable_tag = this->comm().get_unique_tag(2718);
1133  std::vector<Parallel::Request> uncoarsenable_push_requests(n_proc-1);
1134 
1135  for (processor_id_type p = 0; p != n_proc; ++p)
1136  {
1137  if (p == my_proc_id)
1138  continue;
1139 
1141  uncoarsenable_push_requests[p - (p > my_proc_id)];
1142 
1143  _mesh.comm().send
1144  (p, uncoarsenable_parents[p], request, uncoarsenable_tag);
1145  }
1146 
1147  for (processor_id_type p = 1; p != n_proc; ++p)
1148  {
1149  std::vector<dof_id_type> my_uncoarsenable_parents;
1150  _mesh.comm().receive
1151  (Parallel::any_source, my_uncoarsenable_parents,
1152  uncoarsenable_tag);
1153 
1154  for (std::vector<dof_id_type>::const_iterator
1155  it = my_uncoarsenable_parents.begin(),
1156  end = my_uncoarsenable_parents.end(); it != end; ++it)
1157  {
1158  Elem & elem = _mesh.elem_ref(*it);
1162  }
1163  }
1164 
1165  Parallel::wait(uncoarsenable_push_requests);
1166 
1170  (this->comm(), _mesh.not_local_elements_begin(),
1172  // We'd like a smaller sync, but this leads to bugs?
1173  // SyncCoarsenInactive(),
1174  hsync);
1175  }
1176 
1177  // If one processor finds an incompatibility, we're globally
1178  // incompatible
1179  this->comm().min(compatible_with_refinement);
1180 
1181  return compatible_with_refinement;
1182 }
The definition of the element_iterator struct.
Definition: mesh_base.h:1476
bool ancestor() const
Definition: elem.C:1574
virtual element_iterator ancestor_elements_begin()=0
Iterate over elements for which elem->ancestor() is true.
bool has_children() const
Definition: elem.h:2295
Status wait(Request &r)
Wait for a non-blocking send or receive to finish.
Definition: parallel.h:565
virtual bool is_serial() const
Definition: mesh_base.h:140
bool active() const
Definition: elem.h:2257
virtual element_iterator not_local_elements_end()=0
virtual element_iterator level_elements_begin(unsigned int level)=0
Iterate over elements of a given level.
const unsigned int any_source
Accept from any source.
Definition: parallel.h:204
unsigned int p_level() const
Definition: elem.h:2422
MeshBase & _mesh
Reference to the mesh.
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
virtual bool is_replicated() const
Definition: mesh_base.h:162
processor_id_type n_processors() const
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
virtual element_iterator ancestor_elements_end()=0
uint8_t processor_id_type
Definition: id_types.h:99
MPI_Request request
Request object for non-blocking I/O.
Definition: parallel.h:171
const class libmesh_nullptr_t libmesh_nullptr
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
long double max(long double a, double b)
PeriodicBoundaries * _periodic_boundaries
unsigned int max_level(const MeshBase &mesh)
Find the maximum h-refinement level in a mesh.
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Definition: elem.h:1699
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual element_iterator level_elements_end(unsigned int level)=0
unsigned char _face_level_mismatch_limit
Encapsulates the MPI tag integers.
Definition: parallel.h:227
RefinementState p_refinement_flag() const
Definition: elem.h:2521
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
Blocking-send to one processor with data-defined type.
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.
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
Local dispatch function for checking the correct has_neighbor function from the Elem class...
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:490
bool verify(const T &r, const Communicator &comm=Communicator_World)
Encapsulates the MPI_Request.
Definition: parallel.h:517
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2388
RefinementState refinement_flag() const
Definition: elem.h:2505
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
Blocking-receive from one processor with data-defined type.
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
Definition: elem.h:2529
virtual element_iterator not_local_elements_begin()=0
dof_id_type id() const
Definition: dof_object.h:632
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
Local dispatch function for getting the correct topological neighbor from the Elem class...
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
MessageTag get_unique_tag(int tagvalue) const
Get a tag that is unique to this Communicator.
processor_id_type processor_id() const
processor_id_type processor_id() const
Definition: dof_object.h:694
const RemoteElem * remote_elem
Definition: remote_elem.C:57
bool libMesh::MeshRefinement::make_flags_parallel_consistent ( )

Copy refinement flags on ghost elements from their local processors.

Returns
true if any flags changed.

Definition at line 767 of file mesh_refinement.C.

References _mesh, libMesh::ParallelObject::comm(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), libMesh::Parallel::Communicator::min(), libMesh::Elem::p_refinement_flag(), libMesh::SyncRefinementFlags::parallel_consistent, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), and libMesh::Parallel::sync_dofobject_data_by_id().

Referenced by _smooth_flags(), coarsen_elements(), get_mesh(), refine_and_coarsen_elements(), refine_elements(), and libMesh::HPCoarsenTest::select_refinement().

768 {
769  // This function must be run on all processors at once
770  parallel_object_only();
771 
772  LOG_SCOPE ("make_flags_parallel_consistent()", "MeshRefinement");
773 
777  (this->comm(), _mesh.elements_begin(), _mesh.elements_end(), hsync);
778 
782  (this->comm(), _mesh.elements_begin(), _mesh.elements_end(), psync);
783 
784  // If we weren't consistent in both h and p on every processor then
785  // we weren't globally consistent
786  bool parallel_consistent = hsync.parallel_consistent &&
787  psync.parallel_consistent;
788  this->comm().min(parallel_consistent);
789 
790  return parallel_consistent;
791 }
MeshBase & _mesh
Reference to the mesh.
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
virtual element_iterator elements_begin()=0
Iterate over all the elements in the Mesh.
virtual element_iterator elements_end()=0
RefinementState p_refinement_flag() const
Definition: elem.h:2521
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.
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2505
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
Definition: elem.h:2529
bool libMesh::MeshRefinement::make_refinement_compatible ( )
private

Take user-specified refinement flags and augment them so that level-one dependency is satisfied.

This function used to take an argument, maintain_level_one - new code should use face_level_mismatch_limit() instead.

Definition at line 1191 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::child_ref_range(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::Elem::has_children(), has_topological_neighbor(), libMesh::Elem::INACTIVE, libMesh::Elem::level(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::min(), libMesh::Elem::n_sides(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::parent(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::remote_elem, libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), side, libMesh::MeshBase::sub_point_locator(), topological_neighbor(), and libMesh::Parallel::verify().

Referenced by _smooth_flags(), get_mesh(), refine_and_coarsen_elements(), and refine_elements().

1192 {
1193  // This function must be run on all processors at once
1194  parallel_object_only();
1195 
1196  // We may need a PointLocator for topological_neighbor() tests
1197  // later, which we need to make sure gets constructed on all
1198  // processors at once.
1199  UniquePtr<PointLocatorBase> point_locator;
1200 
1201 #ifdef LIBMESH_ENABLE_PERIODIC
1202  bool has_periodic_boundaries =
1204  libmesh_assert(this->comm().verify(has_periodic_boundaries));
1205 
1206  if (has_periodic_boundaries)
1207  point_locator = _mesh.sub_point_locator();
1208 #endif
1209 
1210  LOG_SCOPE ("make_refinement_compatible()", "MeshRefinement");
1211 
1212  // Unless we encounter a specific situation we will be compatible
1213  // with any selected coarsening flags
1214  bool compatible_with_coarsening = true;
1215 
1216  // This loop enforces the level-1 rule. We should only
1217  // execute it if the user indeed wants level-1 satisfied!
1219  {
1220  // Unless we encounter a specific situation level-one
1221  // will be satisfied after executing this loop just once
1222  bool level_one_satisfied = true;
1223 
1224  do
1225  {
1226  level_one_satisfied = true;
1227 
1228  for (auto & elem : _mesh.active_element_ptr_range())
1229  {
1230  const unsigned short n_sides = elem->n_sides();
1231 
1232  if (elem->refinement_flag() == Elem::REFINE) // If the element is active and the
1233  // h refinement flag is set
1234  {
1235  const unsigned int my_level = elem->level();
1236 
1237  for (unsigned short side = 0; side != n_sides;
1238  ++side)
1239  {
1240  Elem * neighbor =
1241  topological_neighbor(elem, point_locator.get(), side);
1242 
1243  if (neighbor != libmesh_nullptr && // I have a
1244  neighbor != remote_elem && // neighbor here
1245  neighbor->active()) // and it is active
1246  {
1247  // Case 1: The neighbor is at the same level I am.
1248  // 1a: The neighbor will be refined -> NO PROBLEM
1249  // 1b: The neighbor won't be refined -> NO PROBLEM
1250  // 1c: The neighbor wants to be coarsened -> PROBLEM
1251  if (neighbor->level() == my_level)
1252  {
1253  if (neighbor->refinement_flag() == Elem::COARSEN)
1254  {
1256  if (neighbor->parent())
1258  compatible_with_coarsening = false;
1259  level_one_satisfied = false;
1260  }
1261  }
1262 
1263 
1264  // Case 2: The neighbor is one level lower than I am.
1265  // The neighbor thus MUST be refined to satisfy
1266  // the level-one rule, regardless of whether it
1267  // was originally flagged for refinement. If it
1268  // wasn't flagged already we need to repeat
1269  // this process.
1270  else if ((neighbor->level()+1) == my_level)
1271  {
1272  if (neighbor->refinement_flag() != Elem::REFINE)
1273  {
1274  neighbor->set_refinement_flag(Elem::REFINE);
1275  if (neighbor->parent())
1277  compatible_with_coarsening = false;
1278  level_one_satisfied = false;
1279  }
1280  }
1281 #ifdef DEBUG
1282  // Note that the only other possibility is that the
1283  // neighbor is already refined, in which case it isn't
1284  // active and we should never get here.
1285  else
1286  libmesh_error_msg("ERROR: Neighbor level must be equal or 1 higher than mine.");
1287 #endif
1288  }
1289  }
1290  }
1291  if (elem->p_refinement_flag() == Elem::REFINE) // If the element is active and the
1292  // p refinement flag is set
1293  {
1294  const unsigned int my_p_level = elem->p_level();
1295 
1296  for (unsigned int side=0; side != n_sides; side++)
1297  {
1298  Elem * neighbor =
1299  topological_neighbor(elem, point_locator.get(), side);
1300 
1301  if (neighbor != libmesh_nullptr && // I have a
1302  neighbor != remote_elem) // neighbor here
1303  {
1304  if (neighbor->active()) // and it is active
1305  {
1306  if (neighbor->p_level() < my_p_level &&
1307  neighbor->p_refinement_flag() != Elem::REFINE)
1308  {
1310  level_one_satisfied = false;
1311  compatible_with_coarsening = false;
1312  }
1313  if (neighbor->p_level() == my_p_level &&
1314  neighbor->p_refinement_flag() == Elem::COARSEN)
1315  {
1317  level_one_satisfied = false;
1318  compatible_with_coarsening = false;
1319  }
1320  }
1321  else // I have an inactive neighbor
1322  {
1323  libmesh_assert(neighbor->has_children());
1324  for (auto & subneighbor : neighbor->child_ref_range())
1325  if (&subneighbor != remote_elem && subneighbor.active() &&
1326  has_topological_neighbor(&subneighbor, point_locator.get(), elem))
1327  {
1328  if (subneighbor.p_level() < my_p_level &&
1329  subneighbor.p_refinement_flag() != Elem::REFINE)
1330  {
1331  // We should already be level one
1332  // compatible
1333  libmesh_assert_greater (subneighbor.p_level() + 2u,
1334  my_p_level);
1335  subneighbor.set_p_refinement_flag(Elem::REFINE);
1336  level_one_satisfied = false;
1337  compatible_with_coarsening = false;
1338  }
1339  if (subneighbor.p_level() == my_p_level &&
1340  subneighbor.p_refinement_flag() == Elem::COARSEN)
1341  {
1342  subneighbor.set_p_refinement_flag(Elem::DO_NOTHING);
1343  level_one_satisfied = false;
1344  compatible_with_coarsening = false;
1345  }
1346  }
1347  }
1348  }
1349  }
1350  }
1351  }
1352  }
1353 
1354  while (!level_one_satisfied);
1355  } // end if (_face_level_mismatch_limit)
1356 
1357  // If we're not compatible on one processor, we're globally not
1358  // compatible
1359  this->comm().min(compatible_with_coarsening);
1360 
1361  return compatible_with_coarsening;
1362 }
bool has_children() const
Definition: elem.h:2295
bool active() const
Definition: elem.h:2257
unsigned int p_level() const
Definition: elem.h:2422
MeshBase & _mesh
Reference to the mesh.
void min(T &r) const
Take a local variable and replace it with the minimum of it&#39;s values on all processors.
const Elem * parent() const
Definition: elem.h:2346
unsigned short int side
Definition: xdr_io.C:49
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
PeriodicBoundaries * _periodic_boundaries
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
Definition: elem.h:1699
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
unsigned char _face_level_mismatch_limit
RefinementState p_refinement_flag() const
Definition: elem.h:2521
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
Local dispatch function for checking the correct has_neighbor function from the Elem class...
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2388
RefinementState refinement_flag() const
Definition: elem.h:2505
void set_p_refinement_flag(const RefinementState pflag)
Sets the value of the p-refinement flag for the element.
Definition: elem.h:2529
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
Local dispatch function for getting the correct topological neighbor from the Elem class...
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
const RemoteElem * remote_elem
Definition: remote_elem.C:57
unsigned int & libMesh::MeshRefinement::max_h_level ( )

The max_h_level is the greatest refinement level an element should reach.

max_h_level is unlimited (libMesh::invalid_uint) by default

Definition at line 886 of file mesh_refinement.h.

References _max_h_level, and _use_member_parameters.

Referenced by assemble_and_solve(), get_mesh(), and main().

887 {
888  _use_member_parameters = true;
889  return _max_h_level;
890 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inherited
Returns
The number of processors in the group.

Definition at line 93 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::size().

Referenced by libMesh::ParmetisPartitioner::_do_repartition(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::MeshCommunication::broadcast(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::MeshBase::get_info(), libMesh::EquationSystems::get_solution(), libMesh::SystemSubsetBySubdomain::init(), libMesh::ParmetisPartitioner::initialize(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Parallel::Sort< KeyType, IdxType >::sort(), WriteVecAndScalar::testWrite(), uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

94  { return cast_int<processor_id_type>(_communicator.size()); }
unsigned int size() const
Definition: parallel.h:726
const Parallel::Communicator & _communicator
dof_id_type & libMesh::MeshRefinement::nelem_target ( )

If nelem_target is set to a nonzero value, methods like flag_elements_by_nelem_target() will attempt to keep the number of active elements in the mesh close to nelem_target.

nelem_target is 0 by default.

Definition at line 898 of file mesh_refinement.h.

References _nelem_target, and _use_member_parameters.

Referenced by build_mesh_refinement(), and get_mesh().

899 {
900  _use_member_parameters = true;
901  return _nelem_target;
902 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
unsigned char & libMesh::MeshRefinement::node_level_mismatch_limit ( )

If node_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce meshes in which the refinement level of two nodal neighbors will not differ by more than that limit.

If node_level_mismatch_limit is 0, then level differences will be unlimited.

node_level_mismatch_limit is 0 by default.

Definition at line 920 of file mesh_refinement.h.

References _node_level_mismatch_limit.

Referenced by get_mesh().

921 {
923 }
unsigned char _node_level_mismatch_limit
MeshRefinement& libMesh::MeshRefinement::operator= ( const MeshRefinement )
private
signed char & libMesh::MeshRefinement::overrefined_boundary_limit ( )

If overrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will produce meshes in which the refinement level of a boundary element is no more than that many levels greater than the level of any of its interior neighbors.

This may be counter-intuitive in the 1D-embedded-in-3D case: an edge has more interior neighbors than a face containing that edge.

If overrefined_boundary_limit is negative, then level differences will be unlimited.

overrefined_boundary_limit is 0 by default. This implies that adaptive coarsening can only be done on an interior element if any boundary elements on its sides are simultaneously coarsened.

Definition at line 925 of file mesh_refinement.h.

References _overrefined_boundary_limit.

Referenced by get_mesh(), and libMesh::EquationSystems::reinit().

926 {
928 }
signed char _overrefined_boundary_limit
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inherited
Returns
The rank of this processor in the group.

Definition at line 99 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and libMesh::Parallel::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::EquationSystems::_read_impl(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), libMesh::ParmetisPartitioner::assign_partitioning(), libMesh::MeshCommunication::broadcast(), libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::ParmetisPartitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), libMesh::DofMap::build_sparsity(), libMesh::DistributedMesh::clear(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMConstruction::evaluate_mesh_function(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::EquationSystems::get_solution(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::SystemSubsetBySubdomain::init(), HeatSystem::init_data(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEIMEvaluation::legacy_write_out_interpolation_points_elem(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::MetisPartitioner::partition_range(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::SparseMatrix< T >::print(), libMesh::NumericVector< T >::print_global(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::MeshCommunication::redistribute(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::LaplaceMeshSmoother::smooth(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), BoundaryInfoTest::testShellFaceConstraints(), WriteVecAndScalar::testWrite(), libMesh::MeshTools::total_weight(), uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::MeshTools::weight(), libMesh::NameBasedIO::write(), libMesh::CheckpointIO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEvaluation::write_out_vectors(), write_output_solvedata(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), and libMesh::ExodusII_IO_Helper::write_timestep().

100  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
unsigned int rank() const
Definition: parallel.h:724
bool libMesh::MeshRefinement::refine_and_coarsen_elements ( )

Refines and coarsens user-requested elements.

Will also refine/coarsen additional elements to satisfy level-one rule. It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the mesh actually changed (hence data needs to be projected) and false otherwise.
Note
This function used to take an argument, maintain_level_one. New code should use face_level_mismatch_limit() instead.

Definition at line 491 of file mesh_refinement.C.

References _coarsen_elements(), _face_level_mismatch_limit, _mesh, _refine_elements(), _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), libMesh::Elem::INACTIVE, libMesh::Elem::JUST_REFINED, libMesh::libmesh_assert(), libMesh::MeshBase::libmesh_assert_valid_parallel_ids(), make_coarsening_compatible(), make_flags_parallel_consistent(), make_refinement_compatible(), libMesh::Parallel::Communicator::max(), libMesh::Elem::p_refinement_flag(), libMesh::MeshBase::prepare_for_use(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), test_level_one(), and test_unflagged().

Referenced by assemble_and_solve(), MixedDimensionNonUniformRefinement::build_mesh(), MixedDimensionNonUniformRefinementTriangle::build_mesh(), MixedDimensionNonUniformRefinement3D::build_mesh(), main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

492 {
493  // This function must be run on all processors at once
494  parallel_object_only();
495 
496  // We can't yet turn a non-level-one mesh into a level-one mesh
499 
500  // Possibly clean up the refinement flags from
501  // a previous step. While we're at it, see if this method should be
502  // a no-op.
503  bool elements_flagged = false;
504 
505  for (auto & elem : _mesh.element_ptr_range())
506  {
507  // This might be left over from the last step
508  const Elem::RefinementState flag = elem->refinement_flag();
509 
510  // Set refinement flag to INACTIVE if the
511  // element isn't active
512  if ( !elem->active())
513  {
514  elem->set_refinement_flag(Elem::INACTIVE);
515  elem->set_p_refinement_flag(Elem::INACTIVE);
516  }
517  else if (flag == Elem::JUST_REFINED)
518  elem->set_refinement_flag(Elem::DO_NOTHING);
519  else if (!elements_flagged)
520  {
521  if (flag == Elem::REFINE || flag == Elem::COARSEN)
522  elements_flagged = true;
523  else
524  {
525  const Elem::RefinementState pflag =
526  elem->p_refinement_flag();
527  if (pflag == Elem::REFINE || pflag == Elem::COARSEN)
528  elements_flagged = true;
529  }
530  }
531  }
532 
533  // Did *any* processor find elements flagged for AMR/C?
534  _mesh.comm().max(elements_flagged);
535 
536  // If we have nothing to do, let's not bother verifying that nothing
537  // is compatible with nothing.
538  if (!elements_flagged)
539  return false;
540 
541  // Parallel consistency has to come first, or coarsening
542  // along processor boundaries might occasionally be falsely
543  // prevented
544 #ifdef DEBUG
545  bool flags_were_consistent = this->make_flags_parallel_consistent();
546 
547  libmesh_assert (flags_were_consistent);
548 #endif
549 
550  // Smooth refinement and coarsening flags
551  _smooth_flags(true, true);
552 
553  // First coarsen the flagged elements.
554  const bool coarsening_changed_mesh =
555  this->_coarsen_elements ();
556 
557  // First coarsen the flagged elements.
558  // FIXME: test_level_one now tests consistency across periodic
559  // boundaries, which requires a point_locator, which just got
560  // invalidated by _coarsen_elements() and hasn't yet been cleared by
561  // prepare_for_use().
562 
563  // libmesh_assert(this->make_coarsening_compatible());
564  // libmesh_assert(this->make_refinement_compatible());
565 
566  // FIXME: This won't pass unless we add a redundant find_neighbors()
567  // call or replace find_neighbors() with on-the-fly neighbor updating
568  // libmesh_assert(!this->eliminate_unrefined_patches());
569 
570  // We can't contract the mesh ourselves anymore - a System might
571  // need to restrict old coefficient vectors first
572  // _mesh.contract();
573 
574  // First coarsen the flagged elements.
575  // Now refine the flagged elements. This will
576  // take up some space, maybe more than what was freed.
577  const bool refining_changed_mesh =
578  this->_refine_elements();
579 
580  // First coarsen the flagged elements.
581  // Finally, the new mesh needs to be prepared for use
582  if (coarsening_changed_mesh || refining_changed_mesh)
583  {
584 #ifdef DEBUG
586 #endif
587 
588  _mesh.prepare_for_use (/*skip_renumber =*/false);
589 
595  // FIXME: This won't pass unless we add a redundant find_neighbors()
596  // call or replace find_neighbors() with on-the-fly neighbor updating
597  // libmesh_assert(!this->eliminate_unrefined_patches());
598 
599  return true;
600  }
601  else
602  {
608  }
609 
610  // Otherwise there was no change in the mesh,
611  // let the user know. Also, there is no need
612  // to prepare the mesh for use since it did not change.
613  return false;
614 
615 }
bool _refine_elements()
Refines user-requested elements.
virtual void libmesh_assert_valid_parallel_ids() const
Verify id and processor_id consistency of our elements and nodes containers.
Definition: mesh_base.h:965
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
RefinementState
Enumeration of possible element refinement states.
Definition: elem.h:1125
bool make_refinement_compatible()
Take user-specified refinement flags and augment them so that level-one dependency is satisfied...
libmesh_assert(j)
bool test_level_one(bool libmesh_assert_yes=false)
virtual SimpleRange< element_iterator > element_ptr_range()=0
unsigned char _face_level_mismatch_limit
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
bool make_coarsening_compatible()
Take user-specified coarsening flags and augment them so that level-one dependency is satisfied...
bool test_unflagged(bool libmesh_assert_yes=false)
const Parallel::Communicator & comm() const
void _smooth_flags(bool refining, bool coarsening)
Smooths refinement flags according to current settings.
bool _coarsen_elements()
Coarsens user-requested elements.
bool libMesh::MeshRefinement::refine_elements ( )

Only refines the user-requested elements.

It is possible that for a given set of refinement flags there is actually no change upon calling this member function.

Returns
true if the mesh actually changed (hence data needs to be projected) and false otherwise.
Note
This function used to take an argument, maintain_level_one, new code should use face_level_mismatch_limit() instead.

Definition at line 698 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _refine_elements(), _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), libMesh::Elem::INACTIVE, libMesh::Elem::JUST_REFINED, libMesh::libmesh_assert(), make_flags_parallel_consistent(), make_refinement_compatible(), libMesh::out, libMesh::MeshBase::prepare_for_use(), libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), and test_level_one().

Referenced by main(), libMesh::EquationSystems::reinit(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

699 {
700  // This function must be run on all processors at once
701  parallel_object_only();
702 
705 
706  // Possibly clean up the refinement flags from
707  // a previous step
708  for (auto & elem : _mesh.element_ptr_range())
709  {
710  // Set refinement flag to INACTIVE if the
711  // element isn't active
712  if (!elem->active())
713  {
714  elem->set_refinement_flag(Elem::INACTIVE);
715  elem->set_p_refinement_flag(Elem::INACTIVE);
716  }
717 
718  // This might be left over from the last step
719  if (elem->refinement_flag() == Elem::JUST_REFINED)
720  elem->set_refinement_flag(Elem::DO_NOTHING);
721  }
722 
723 
724 
725  // Parallel consistency has to come first, or coarsening
726  // along processor boundaries might occasionally be falsely
727  // prevented
728  bool flags_were_consistent = this->make_flags_parallel_consistent();
729 
730  // In theory, we should be able to remove the above call, which can
731  // be expensive and should be unnecessary. In practice, doing
732  // consistent flagging in parallel is hard, it's impossible to
733  // verify at the library level if it's being done by user code, and
734  // we don't want to abort large parallel runs in opt mode... but we
735  // do want to warn that they should be fixed.
736  libmesh_assert(flags_were_consistent);
737  if (!flags_were_consistent)
738  {
739  libMesh::out << "Refinement flags were not consistent between processors!\n"
740  << "Correcting and continuing.";
741  }
742 
743  // Smooth refinement flags
744  _smooth_flags(true, false);
745 
746  // Now refine the flagged elements. This will
747  // take up some space, maybe more than what was freed.
748  const bool mesh_changed =
749  this->_refine_elements();
750 
754  // FIXME: This won't pass unless we add a redundant find_neighbors()
755  // call or replace find_neighbors() with on-the-fly neighbor updating
756  // libmesh_assert(!this->eliminate_unrefined_patches());
757 
758  // Finally, the new mesh needs to be prepared for use
759  if (mesh_changed)
760  _mesh.prepare_for_use (/*skip_renumber =*/false);
761 
762  return mesh_changed;
763 }
bool _refine_elements()
Refines user-requested elements.
MeshBase & _mesh
Reference to the mesh.
bool make_refinement_compatible()
Take user-specified refinement flags and augment them so that level-one dependency is satisfied...
libmesh_assert(j)
bool test_level_one(bool libmesh_assert_yes=false)
virtual SimpleRange< element_iterator > element_ptr_range()=0
unsigned char _face_level_mismatch_limit
bool make_flags_parallel_consistent()
Copy refinement flags on ghost elements from their local processors.
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
OStreamProxy out
void _smooth_flags(bool refining, bool coarsening)
Smooths refinement flags according to current settings.
Real & libMesh::MeshRefinement::refine_fraction ( )

The refine_fraction sets either a desired target or a desired maximum number of elements to flag for refinement, depending on which flag_elements_by method is called.

refine_fraction must be in $ [0,1] $, and is 0.3 by default.

Definition at line 874 of file mesh_refinement.h.

References _refine_fraction, and _use_member_parameters.

Referenced by assemble_and_solve(), build_mesh_refinement(), get_mesh(), main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

875 {
876  _use_member_parameters = true;
877  return _refine_fraction;
878 }
bool _use_member_parameters
For backwards compatibility, we initialize this as false and then set it to true if the user uses any...
void libMesh::MeshRefinement::set_enforce_mismatch_limit_prior_to_refinement ( bool  enforce)

Set _enforce_mismatch_limit_prior_to_refinement option.

Defaults to false.

Deprecated:
Use enforce_mismatch_limit_prior_to_refinement() instead.

Definition at line 942 of file mesh_refinement.h.

References enforce_mismatch_limit_prior_to_refinement().

Referenced by get_mesh().

943 {
944  libmesh_deprecated();
946 }
bool & enforce_mismatch_limit_prior_to_refinement()
Get/set the _enforce_mismatch_limit_prior_to_refinement flag.
void libMesh::MeshRefinement::set_periodic_boundaries_ptr ( PeriodicBoundaries pb_ptr)
void libMesh::MeshRefinement::switch_h_to_p_refinement ( )

Takes a mesh whose elements are flagged for h refinement and coarsening, and switches those flags to request p refinement and coarsening instead.

Definition at line 635 of file mesh_refinement_flagging.C.

References _mesh, libMesh::Elem::DO_NOTHING, libMesh::MeshBase::element_ptr_range(), and libMesh::Elem::INACTIVE.

Referenced by main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

636 {
637  for (auto & elem : _mesh.element_ptr_range())
638  {
639  if (elem->active())
640  {
641  elem->set_p_refinement_flag(elem->refinement_flag());
642  elem->set_refinement_flag(Elem::DO_NOTHING);
643  }
644  else
645  {
646  elem->set_p_refinement_flag(elem->refinement_flag());
647  elem->set_refinement_flag(Elem::INACTIVE);
648  }
649  }
650 }
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > element_ptr_range()=0
bool libMesh::MeshRefinement::test_level_one ( bool  libmesh_assert_yes = false)
Returns
true if the mesh satisfies the level one restriction, and false otherwise.

Aborts the program if libmesh_assert_yes is true and the mesh does not satisfy the level one restriction.

Definition at line 368 of file mesh_refinement.C.

References _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_local_element_ptr_range(), libMesh::ParallelObject::comm(), libMesh::Elem::level(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::max(), libMesh::out, libMesh::Elem::p_level(), libMesh::remote_elem, libMesh::Elem::side_index_range(), libMesh::MeshBase::sub_point_locator(), topological_neighbor(), and libMesh::Parallel::verify().

Referenced by coarsen_elements(), refine_and_coarsen_elements(), refine_elements(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

369 {
370  // This function must be run on all processors at once
371  parallel_object_only();
372 
373  // We may need a PointLocator for topological_neighbor() tests
374  // later, which we need to make sure gets constructed on all
375  // processors at once.
376  UniquePtr<PointLocatorBase> point_locator;
377 
378 #ifdef LIBMESH_ENABLE_PERIODIC
379  bool has_periodic_boundaries =
381  libmesh_assert(this->comm().verify(has_periodic_boundaries));
382 
383  if (has_periodic_boundaries)
384  point_locator = _mesh.sub_point_locator();
385 #endif
386 
387  bool failure = false;
388 
389 #ifndef NDEBUG
390  Elem * failed_elem = libmesh_nullptr;
391  Elem * failed_neighbor = libmesh_nullptr;
392 #endif // !NDEBUG
393 
394  for (auto & elem : _mesh.active_local_element_ptr_range())
395  for (auto n : elem->side_index_range())
396  {
397  Elem * neighbor =
398  topological_neighbor(elem, point_locator.get(), n);
399 
400  if (!neighbor || !neighbor->active() ||
401  neighbor == remote_elem)
402  continue;
403 
404  if ((neighbor->level() + 1 < elem->level()) ||
405  (neighbor->p_level() + 1 < elem->p_level()) ||
406  (neighbor->p_level() > elem->p_level() + 1))
407  {
408  failure = true;
409 #ifndef NDEBUG
410  failed_elem = elem;
411  failed_neighbor = neighbor;
412 #endif // !NDEBUG
413  break;
414  }
415  }
416 
417  // If any processor failed, we failed globally
418  this->comm().max(failure);
419 
420  if (failure)
421  {
422  // We didn't pass the level one test, so libmesh_assert that
423  // we're allowed not to
424 #ifndef NDEBUG
425  if (libmesh_assert_pass)
426  {
427  libMesh::out << "MeshRefinement Level one failure, element: "
428  << *failed_elem
429  << std::endl;
430  libMesh::out << "MeshRefinement Level one failure, neighbor: "
431  << *failed_neighbor
432  << std::endl;
433  }
434 #endif // !NDEBUG
435  libmesh_assert(!libmesh_assert_pass);
436  return false;
437  }
438  return true;
439 }
bool active() const
Definition: elem.h:2257
unsigned int p_level() const
Definition: elem.h:2422
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
OStreamProxy out
unsigned int level() const
Definition: elem.h:2388
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
Local dispatch function for getting the correct topological neighbor from the Elem class...
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
const RemoteElem * remote_elem
Definition: remote_elem.C:57
bool libMesh::MeshRefinement::test_unflagged ( bool  libmesh_assert_yes = false)
Returns
true if the mesh has no elements flagged to be coarsened or refined, and false otherwise.

Aborts the program if libmesh_assert_yes is true and the mesh has flagged elements.

Definition at line 443 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::max(), libMesh::out, libMesh::Elem::p_refinement_flag(), libMesh::Elem::REFINE, and libMesh::Elem::refinement_flag().

Referenced by refine_and_coarsen_elements(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

444 {
445  // This function must be run on all processors at once
446  parallel_object_only();
447 
448  bool found_flag = false;
449 
450 #ifndef NDEBUG
451  Elem * failed_elem = libmesh_nullptr;
452 #endif
453 
454  // Search for local flags
455  for (auto & elem : _mesh.active_local_element_ptr_range())
456  if (elem->refinement_flag() == Elem::REFINE ||
457  elem->refinement_flag() == Elem::COARSEN ||
458  elem->p_refinement_flag() == Elem::REFINE ||
459  elem->p_refinement_flag() == Elem::COARSEN)
460  {
461  found_flag = true;
462 #ifndef NDEBUG
463  failed_elem = elem;
464 #endif
465  break;
466  }
467 
468  // If we found a flag on any processor, it counts
469  this->comm().max(found_flag);
470 
471  if (found_flag)
472  {
473 #ifndef NDEBUG
474  if (libmesh_assert_pass)
475  {
476  libMesh::out <<
477  "MeshRefinement test_unflagged failure, element: " <<
478  *failed_elem << std::endl;
479  }
480 #endif
481  // We didn't pass the "elements are unflagged" test,
482  // so libmesh_assert that we're allowed not to
483  libmesh_assert(!libmesh_assert_pass);
484  return false;
485  }
486  return true;
487 }
void max(T &r) const
Take a local variable and replace it with the maximum of it&#39;s values on all processors.
MeshBase & _mesh
Reference to the mesh.
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
const Parallel::Communicator & comm() const
OStreamProxy out
Elem * libMesh::MeshRefinement::topological_neighbor ( Elem elem,
const PointLocatorBase point_locator,
const unsigned int  side 
)
private

Local dispatch function for getting the correct topological neighbor from the Elem class.

Definition at line 1824 of file mesh_refinement.C.

References _mesh, _periodic_boundaries, libMesh::libmesh_assert(), libMesh::Elem::neighbor_ptr(), and libMesh::Elem::topological_neighbor().

Referenced by get_mesh(), make_coarsening_compatible(), make_refinement_compatible(), and test_level_one().

1827 {
1828 #ifdef LIBMESH_ENABLE_PERIODIC
1829  if (_periodic_boundaries && !_periodic_boundaries->empty())
1830  {
1831  libmesh_assert(point_locator);
1832  return elem->topological_neighbor(side, _mesh, *point_locator, _periodic_boundaries);
1833  }
1834 #endif
1835  return elem->neighbor_ptr(side);
1836 }
MeshBase & _mesh
Reference to the mesh.
unsigned short int side
Definition: xdr_io.C:49
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:1967
const Elem * topological_neighbor(const unsigned int i, const MeshBase &mesh, const PointLocatorBase &point_locator, const PeriodicBoundaries *pb) const
Definition: elem.C:1067
signed char & libMesh::MeshRefinement::underrefined_boundary_limit ( )

If underrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will produce meshes in which the refinement level of an element is no more than that many levels greater than the level of any boundary elements on its sides.

If underrefined_boundary_limit is negative, then level differences will be unlimited.

underrefined_boundary_limit is 0 by default. This implies that adaptive coarsening can only be done on a boundary element if any interior elements it is on the side of are simultaneously coarsened.

Definition at line 930 of file mesh_refinement.h.

References _underrefined_boundary_limit.

Referenced by get_mesh(), and libMesh::EquationSystems::reinit().

931 {
933 }
signed char _underrefined_boundary_limit
void libMesh::MeshRefinement::uniformly_coarsen ( unsigned int  n = 1)

Attempts to uniformly coarsen the mesh n times.

Definition at line 1728 of file mesh_refinement.C.

References _coarsen_elements(), _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshBase::ancestor_elements_begin(), libMesh::MeshBase::ancestor_elements_end(), libMesh::Parallel::any_source, clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::Elem::COARSEN_INACTIVE, libMesh::ParallelObject::comm(), libMesh::MeshBase::elem_ref(), end, libMesh::Parallel::Communicator::get_unique_tag(), libMesh::DofObject::id(), libMesh::Elem::INACTIVE, libMesh::MeshBase::is_replicated(), libMesh::libmesh_assert(), libMesh::ParallelObject::n_processors(), libMesh::MeshBase::not_local_elements_begin(), libMesh::MeshBase::not_local_elements_end(), libMesh::Elem::parent(), libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::DofObject::processor_id(), libMesh::Parallel::Communicator::receive(), libMesh::Elem::refinement_flag(), libMesh::Parallel::Communicator::send(), libMesh::Elem::set_refinement_flag(), libMesh::Parallel::sync_dofobject_data_by_id(), and libMesh::Parallel::wait().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

1729 {
1730  // Coarsen n times
1731  for (unsigned int rstep=0; rstep<n; rstep++)
1732  {
1733  // Clean up the refinement flags
1734  this->clean_refinement_flags();
1735 
1736  // Flag all the active elements for coarsening.
1737  for (auto & elem : _mesh.active_element_ptr_range())
1738  {
1739  elem->set_refinement_flag(Elem::COARSEN);
1740  if (elem->parent())
1741  elem->parent()->set_refinement_flag(Elem::COARSEN_INACTIVE);
1742  }
1743 
1744  // On a distributed mesh, we may have parent elements with
1745  // remote active children. To keep flags consistent, we'll need
1746  // a communication step.
1747  if (!_mesh.is_replicated())
1748  {
1749  const processor_id_type n_proc = _mesh.n_processors();
1750  const processor_id_type my_proc_id = _mesh.processor_id();
1751 
1752  std::vector<std::vector<dof_id_type>>
1753  parents_to_coarsen(n_proc);
1754 
1757 
1758  for ( ; elem_it != elem_end; ++elem_it)
1759  {
1760  const Elem & elem = **elem_it;
1761  if (elem.processor_id() != my_proc_id &&
1763  parents_to_coarsen[elem.processor_id()].push_back(elem.id());
1764  }
1765 
1767  coarsen_tag = this->comm().get_unique_tag(271);
1768  std::vector<Parallel::Request> coarsen_push_requests(n_proc-1);
1769 
1770  for (processor_id_type p = 0; p != n_proc; ++p)
1771  {
1772  if (p == my_proc_id)
1773  continue;
1774 
1776  coarsen_push_requests[p - (p > my_proc_id)];
1777 
1778  _mesh.comm().send
1779  (p, parents_to_coarsen[p], request, coarsen_tag);
1780  }
1781 
1782  for (processor_id_type p = 1; p != n_proc; ++p)
1783  {
1784  std::vector<dof_id_type> my_parents_to_coarsen;
1785  _mesh.comm().receive
1786  (Parallel::any_source, my_parents_to_coarsen,
1787  coarsen_tag);
1788 
1789  for (std::vector<dof_id_type>::const_iterator
1790  it = my_parents_to_coarsen.begin(),
1791  end = my_parents_to_coarsen.end(); it != end; ++it)
1792  {
1793  Elem & elem = _mesh.elem_ref(*it);
1797  }
1798  }
1799 
1800  Parallel::wait(coarsen_push_requests);
1801 
1805  (this->comm(), _mesh.not_local_elements_begin(),
1807  // We'd like a smaller sync, but this leads to bugs?
1808  // SyncCoarsenInactive(),
1809  hsync);
1810  }
1811 
1812  // Coarsen all the elements we just flagged.
1813  this->_coarsen_elements();
1814  }
1815 
1816 
1817  // Finally, the new mesh probably needs to be prepared for use
1818  if (n > 0)
1819  _mesh.prepare_for_use (/*skip_renumber =*/false);
1820 }
virtual element_iterator ancestor_elements_begin()=0
Iterate over elements for which elem->ancestor() is true.
Status wait(Request &r)
Wait for a non-blocking send or receive to finish.
Definition: parallel.h:565
virtual element_iterator not_local_elements_end()=0
const unsigned int any_source
Accept from any source.
Definition: parallel.h:204
MeshBase & _mesh
Reference to the mesh.
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
virtual bool is_replicated() const
Definition: mesh_base.h:162
processor_id_type n_processors() const
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
virtual element_iterator ancestor_elements_end()=0
uint8_t processor_id_type
Definition: id_types.h:99
MPI_Request request
Request object for non-blocking I/O.
Definition: parallel.h:171
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
libmesh_assert(j)
Encapsulates the MPI tag integers.
Definition: parallel.h:227
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
Blocking-send to one processor with data-defined type.
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.
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:490
Encapsulates the MPI_Request.
Definition: parallel.h:517
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2505
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
Blocking-receive from one processor with data-defined type.
virtual element_iterator not_local_elements_begin()=0
bool _coarsen_elements()
Coarsens user-requested elements.
dof_id_type id() const
Definition: dof_object.h:632
MessageTag get_unique_tag(int tagvalue) const
Get a tag that is unique to this Communicator.
processor_id_type processor_id() const
processor_id_type processor_id() const
Definition: dof_object.h:694
void libMesh::MeshRefinement::uniformly_p_coarsen ( unsigned int  n = 1)

Attempts to uniformly p coarsen the mesh n times.

Definition at line 1688 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::JUST_COARSENED, libMesh::Elem::p_level(), libMesh::Elem::set_p_level(), and libMesh::Elem::set_p_refinement_flag().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

1689 {
1690  // Coarsen p times
1691  for (unsigned int rstep=0; rstep<n; rstep++)
1692  for (auto & elem : _mesh.active_element_ptr_range())
1693  if (elem->p_level() > 0)
1694  {
1695  // P coarsen all the active elements
1696  elem->set_p_level(elem->p_level()-1);
1697  elem->set_p_refinement_flag(Elem::JUST_COARSENED);
1698  }
1699 }
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
void libMesh::MeshRefinement::uniformly_p_refine ( unsigned int  n = 1)

Uniformly p refines the mesh n times.

Definition at line 1674 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_element_ptr_range(), libMesh::Elem::JUST_REFINED, libMesh::Elem::p_level(), libMesh::Elem::set_p_level(), and libMesh::Elem::set_p_refinement_flag().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), main(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

1675 {
1676  // Refine n times
1677  for (unsigned int rstep=0; rstep<n; rstep++)
1678  for (auto & elem : _mesh.active_element_ptr_range())
1679  {
1680  // P refine all the active elements
1681  elem->set_p_level(elem->p_level()+1);
1682  elem->set_p_refinement_flag(Elem::JUST_REFINED);
1683  }
1684 }
MeshBase & _mesh
Reference to the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
void libMesh::MeshRefinement::uniformly_refine ( unsigned int  n = 1)

Uniformly refines the mesh n times.

Definition at line 1703 of file mesh_refinement.C.

References _mesh, _refine_elements(), libMesh::MeshBase::active_element_ptr_range(), clean_refinement_flags(), libMesh::MeshBase::prepare_for_use(), libMesh::Elem::REFINE, and libMesh::Elem::set_refinement_flag().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), main(), SlitMeshRefinedMeshTest::setUp(), MixedDimensionRefinedMeshTest::setUp(), SlitMeshRefinedSystemTest::setUp(), BoundaryRefinedMeshTest::setUp(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

1704 {
1705  // Refine n times
1706  // FIXME - this won't work if n>1 and the mesh
1707  // has already been attached to an equation system
1708  for (unsigned int rstep=0; rstep<n; rstep++)
1709  {
1710  // Clean up the refinement flags
1711  this->clean_refinement_flags();
1712 
1713  // Flag all the active elements for refinement.
1714  for (auto & elem : _mesh.active_element_ptr_range())
1715  elem->set_refinement_flag(Elem::REFINE);
1716 
1717  // Refine all the elements we just flagged.
1718  this->_refine_elements();
1719  }
1720 
1721  // Finally, the new mesh probably needs to be prepared for use
1722  if (n > 0)
1723  _mesh.prepare_for_use (/*skip_renumber =*/false);
1724 }
bool _refine_elements()
Refines user-requested elements.
MeshBase & _mesh
Reference to the mesh.
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
void libMesh::MeshRefinement::update_nodes_map ( )
private

Updates the _new_nodes_map.

Definition at line 361 of file mesh_refinement.C.

References _mesh, _new_nodes_map, and libMesh::TopologyMap::init().

Referenced by _coarsen_elements(), _refine_elements(), and get_mesh().

362 {
363  this->_new_nodes_map.init(_mesh);
364 }
TopologyMap _new_nodes_map
Data structure that holds the new nodes information.
MeshBase & _mesh
Reference to the mesh.
void init(MeshBase &)
Definition: topology_map.C:35

Member Data Documentation

Real libMesh::MeshRefinement::_absolute_global_tolerance
private
bool libMesh::MeshRefinement::_coarsen_by_parents
private
Real libMesh::MeshRefinement::_coarsen_fraction
private
Real libMesh::MeshRefinement::_coarsen_threshold
private
const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited
unsigned char libMesh::MeshRefinement::_edge_level_mismatch_limit
private

Definition at line 768 of file mesh_refinement.h.

Referenced by _smooth_flags(), and edge_level_mismatch_limit().

bool libMesh::MeshRefinement::_enforce_mismatch_limit_prior_to_refinement
private

This option enforces the mismatch level prior to refinement by checking if refining any element marked for refinement would cause a mismatch greater than the limit.

Applies to all mismatch methods.

Calling this with node_level_mismatch_limit() = 1 would transform this mesh:

* o-------o-------o-------o-------o
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* o-------o---o---o-------o-------o
* |       |   :   |       |       |
* |       |   :   |       |       |
* |       o...o...o       |       |
* |       |   :   |       |       |
* |       |   :   |       |       |
* o-------o---o---o-------o-------o
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* o-------o-------o               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* |       |       |               |
* o-------o-------o---------------o
* 

into this:

* o-------o-------o-------o-------o
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* o-------o-------o-------o-------o
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* |       |       |       |       |
* o-------o-------o-------o-------o
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* o-------o-------o.......o.......o
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* |       |       |       :       |
* o-------o-------o-------o-------o
* 

by moving the refinement flag to the indicated element.

Default value is false.

Definition at line 842 of file mesh_refinement.h.

Referenced by enforce_mismatch_limit_prior_to_refinement(), limit_level_mismatch_at_edge(), and limit_level_mismatch_at_node().

unsigned char libMesh::MeshRefinement::_face_level_mismatch_limit
private
unsigned int libMesh::MeshRefinement::_max_h_level
private
MeshBase& libMesh::MeshRefinement::_mesh
private
dof_id_type libMesh::MeshRefinement::_nelem_target
private

Definition at line 763 of file mesh_refinement.h.

Referenced by flag_elements_by_nelem_target(), and nelem_target().

TopologyMap libMesh::MeshRefinement::_new_nodes_map
private

Data structure that holds the new nodes information.

Definition at line 735 of file mesh_refinement.h.

Referenced by add_node(), clear(), and update_nodes_map().

unsigned char libMesh::MeshRefinement::_node_level_mismatch_limit
private

Definition at line 769 of file mesh_refinement.h.

Referenced by _smooth_flags(), and node_level_mismatch_limit().

signed char libMesh::MeshRefinement::_overrefined_boundary_limit
private

Definition at line 771 of file mesh_refinement.h.

Referenced by _smooth_flags(), and overrefined_boundary_limit().

PeriodicBoundaries* libMesh::MeshRefinement::_periodic_boundaries
private
Real libMesh::MeshRefinement::_refine_fraction
private
signed char libMesh::MeshRefinement::_underrefined_boundary_limit
private

Definition at line 772 of file mesh_refinement.h.

Referenced by _smooth_flags(), and underrefined_boundary_limit().

bool libMesh::MeshRefinement::_use_member_parameters
private

For backwards compatibility, we initialize this as false and then set it to true if the user uses any of the refinement parameter accessor functions.

Definition at line 747 of file mesh_refinement.h.

Referenced by absolute_global_tolerance(), coarsen_by_parents(), coarsen_fraction(), coarsen_threshold(), flag_elements_by_elem_fraction(), flag_elements_by_error_fraction(), flag_elements_by_mean_stddev(), max_h_level(), nelem_target(), and refine_fraction().


The documentation for this class was generated from the following files: