libMesh::MeshRefinement Class Reference

Responsible for mesh refinement algorithms and data. More...

#include <mesh_refinement.h>

Inheritance diagram for libMesh::MeshRefinement:

Classes

class  ElementFlagging
 

Public Member Functions

 MeshRefinement (MeshBase &mesh)
 
void set_periodic_boundaries_ptr (PeriodicBoundaries *pb_ptr)
 
 ~MeshRefinement ()
 
void clear ()
 
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)
 
void flag_elements_by_error_tolerance (const ErrorVector &error_per_cell)
 
bool flag_elements_by_nelem_target (const ErrorVector &error_per_cell)
 
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)
 
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)
 
void flag_elements_by (ElementFlagging &element_flagging)
 
void switch_h_to_p_refinement ()
 
void add_p_to_h_refinement ()
 
bool refine_and_coarsen_elements ()
 
bool coarsen_elements ()
 
bool refine_elements ()
 
void uniformly_refine (unsigned int n=1)
 
void uniformly_coarsen (unsigned int n=1)
 
void uniformly_p_refine (unsigned int n=1)
 
void uniformly_p_coarsen (unsigned int n=1)
 
void clean_refinement_flags ()
 
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)
 
Elemadd_elem (Elem *elem)
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
bool & coarsen_by_parents ()
 
Realrefine_fraction ()
 
Realcoarsen_fraction ()
 
unsigned int & max_h_level ()
 
Realcoarsen_threshold ()
 
dof_id_typenelem_target ()
 
Realabsolute_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 make_flags_parallel_consistent ()
 
bool get_enforce_mismatch_limit_prior_to_refinement ()
 
void set_enforce_mismatch_limit_prior_to_refinement (bool enforce)
 
bool & enforce_mismatch_limit_prior_to_refinement ()
 
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 }
 

Private Member Functions

 MeshRefinement (const MeshRefinement &)
 
MeshRefinementoperator= (const MeshRefinement &)
 
bool _coarsen_elements ()
 
bool _refine_elements ()
 
void _smooth_flags (bool refining, bool coarsening)
 
bool limit_level_mismatch_at_node (const unsigned int max_mismatch)
 
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 ()
 
void create_parent_error_vector (const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
 
void update_nodes_map ()
 
bool make_coarsening_compatible ()
 
bool make_refinement_compatible ()
 
Elemtopological_neighbor (Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
 
bool has_topological_neighbor (const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
 
bool enforce_mismatch_limit_prior_to_refinement (Elem *elem, NeighborType nt, unsigned max_mismatch)
 

Private Attributes

TopologyMap _new_nodes_map
 
MeshBase_mesh
 
bool _use_member_parameters
 
bool _coarsen_by_parents
 
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
 
PeriodicBoundaries_periodic_boundaries
 

Detailed Description

Responsible for mesh refinement algorithms and data.

This is the MeshRefinement class. This class implements adaptive mesh refinement algorithms for a MeshBase.

Author
Benjamin S. Kirk
Date
2002-2007

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 849 of file mesh_refinement.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 93 of file mesh_refinement.C.

References _periodic_boundaries, and set_periodic_boundaries_ptr().

93  :
94  ParallelObject(m),
95  _mesh(m),
97  _coarsen_by_parents(false),
98  _refine_fraction(0.3),
99  _coarsen_fraction(0.0),
101  _coarsen_threshold(10),
102  _nelem_target(0),
110 #ifdef LIBMESH_ENABLE_PERIODIC
112 #endif
113 {
114 }
115 
116 
117 
118 #ifdef LIBMESH_ENABLE_PERIODIC
120 {
121  _periodic_boundaries = pb_ptr;
122 }
ParallelObject(const Parallel::Communicator &comm_in)
const unsigned int invalid_uint
Definition: libmesh.h:184
Maps between boundary ids and PeriodicBoundaryBase objects.
const class libmesh_nullptr_t libmesh_nullptr
PeriodicBoundaries * _periodic_boundaries
signed char _underrefined_boundary_limit
unsigned char _face_level_mismatch_limit
signed char _overrefined_boundary_limit
bool _enforce_mismatch_limit_prior_to_refinement
unsigned char _node_level_mismatch_limit
unsigned char _edge_level_mismatch_limit
void set_periodic_boundaries_ptr(PeriodicBoundaries *pb_ptr)
libMesh::MeshRefinement::MeshRefinement ( const MeshRefinement )
private
libMesh::MeshRefinement::~MeshRefinement ( )

Destructor. Deletes all the elements that are currently stored.

Definition at line 127 of file mesh_refinement.C.

References clear().

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

128 {
129  this->clear();
130 }

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 1415 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::elements_begin(), libMesh::MeshBase::elements_end(), end, 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().

1416 {
1417  // This function must be run on all processors at once
1418  parallel_object_only();
1419 
1420  LOG_SCOPE ("_coarsen_elements()", "MeshRefinement");
1421 
1422  // Flags indicating if this call actually changes the mesh
1423  bool mesh_changed = false;
1424  bool mesh_p_changed = false;
1425 
1426  // Clear the unused_elements data structure.
1427  // The elements have been packed since it was built,
1428  // so there are _no_ unused elements. We cannot trust
1429  // any iterators currently in this data structure.
1430  // _unused_elements.clear();
1431 
1432  // Loop over the elements first to determine if the mesh will
1433  // undergo h-coarsening. If it will, then we'll need to communicate
1434  // more ghosted elements. We need to communicate them *before* we
1435  // do the coarsening; otherwise it is possible to coarsen away a
1436  // one-element-thick layer partition and leave the partitions on
1437  // either side unable to figure out how to talk to each other.
1439  it = _mesh.elements_begin(),
1440  end = _mesh.elements_end();
1441  it != end; ++it)
1442  {
1443  Elem * elem = *it;
1444  if (elem->refinement_flag() == Elem::COARSEN)
1445  {
1446  mesh_changed = true;
1447  break;
1448  }
1449  }
1450 
1451  // If the mesh changed on any processor, it changed globally
1452  this->comm().max(mesh_changed);
1453 
1454  // And then we may need to widen the ghosting layers.
1455  if (mesh_changed)
1457 
1459  it = _mesh.elements_begin(),
1460  end = _mesh.elements_end();
1461  it != end; ++it)
1462  {
1463  Elem * elem = *it;
1464 
1465  // active elements flagged for coarsening will
1466  // no longer be deleted until MeshRefinement::contract()
1467  if (elem->refinement_flag() == Elem::COARSEN)
1468  {
1469  // Huh? no level-0 element should be active
1470  // and flagged for coarsening.
1471  libmesh_assert_not_equal_to (elem->level(), 0);
1472 
1473  // Remove this element from any neighbor
1474  // lists that point to it.
1475  elem->nullify_neighbors();
1476 
1477  // Remove any boundary information associated
1478  // with this element
1479  _mesh.get_boundary_info().remove (elem);
1480 
1481  // Add this iterator to the _unused_elements
1482  // data structure so we might fill it.
1483  // The _unused_elements optimization is currently off.
1484  // _unused_elements.push_back (it);
1485 
1486  // Don't delete the element until
1487  // MeshRefinement::contract()
1488  // _mesh.delete_elem(elem);
1489  }
1490 
1491  // inactive elements flagged for coarsening
1492  // will become active
1493  else if (elem->refinement_flag() == Elem::COARSEN_INACTIVE)
1494  {
1495  elem->coarsen();
1496  libmesh_assert (elem->active());
1497 
1498  // the mesh has certainly changed
1499  mesh_changed = true;
1500  }
1501  if (elem->p_refinement_flag() == Elem::COARSEN)
1502  {
1503  if (elem->p_level() > 0)
1504  {
1506  elem->set_p_level(elem->p_level() - 1);
1507  mesh_p_changed = true;
1508  }
1509  else
1510  {
1512  }
1513  }
1514  }
1515 
1516  this->comm().max(mesh_p_changed);
1517 
1518  // And we may need to update DistributedMesh values reflecting the changes
1519  if (mesh_changed)
1521 
1522  // Node processor ids may need to change if an element of that id
1523  // was coarsened away
1524  if (mesh_changed && !_mesh.is_serial())
1525  {
1526  // Update the _new_nodes_map so that processors can
1527  // find requested nodes
1528  this->update_nodes_map ();
1529 
1531 
1532  // Clear the _new_nodes_map
1533  this->clear();
1534 
1535 #ifdef DEBUG
1536  MeshTools::libmesh_assert_valid_procids<Node>(_mesh);
1537 #endif
1538  }
1539 
1540  // If p levels changed all we need to do is make sure that parent p
1541  // levels changed in sync
1542  if (mesh_p_changed && !_mesh.is_serial())
1543  {
1545  }
1546 
1547  return (mesh_changed || mesh_p_changed);
1548 }
void set_p_level(const unsigned int p)
Definition: elem.h:2358
const BoundaryInfo & get_boundary_info() const
Definition: mesh_base.h:114
virtual bool is_serial() const
Definition: mesh_base.h:137
bool active() const
Definition: elem.h:2059
unsigned int p_level() const
Definition: elem.h:2224
void remove(const Node *node)
The base class for all geometric element types.
Definition: elem.h:86
IterBase * end
void send_coarse_ghosts(MeshBase &) const
libmesh_assert(j)
virtual element_iterator elements_begin()=0
virtual void update_parallel_id_counts()=0
virtual element_iterator elements_end()=0
void make_p_levels_parallel_consistent(MeshBase &)
RefinementState p_refinement_flag() const
Definition: elem.h:2320
void make_nodes_parallel_consistent(MeshBase &)
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2190
RefinementState refinement_flag() const
Definition: elem.h:2304
void nullify_neighbors()
Definition: elem.C:2694
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
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 1552 of file mesh_refinement.C.

References _mesh, libMesh::Elem::active(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::MeshBase::active_not_local_elements_begin(), libMesh::MeshBase::active_not_local_elements_end(), clear(), libMesh::ParallelObject::comm(), libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), end, 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().

1553 {
1554  // This function must be run on all processors at once
1555  parallel_object_only();
1556 
1557  // Update the _new_nodes_map so that elements can
1558  // find nodes to connect to.
1559  this->update_nodes_map ();
1560 
1561  LOG_SCOPE ("_refine_elements()", "MeshRefinement");
1562 
1563  // Iterate over the elements, counting the elements
1564  // flagged for h refinement.
1565  dof_id_type n_elems_flagged = 0;
1566 
1569 
1570  for (; it != end; ++it)
1571  {
1572  Elem * elem = *it;
1573  if (elem->refinement_flag() == Elem::REFINE)
1574  n_elems_flagged++;
1575  }
1576 
1577  // Construct a local vector of Elem * which have been
1578  // previously marked for refinement. We reserve enough
1579  // space to allow for every element to be refined.
1580  std::vector<Elem *> local_copy_of_elements;
1581  local_copy_of_elements.reserve(n_elems_flagged);
1582 
1583  // If mesh p levels changed, we might need to synchronize parent p
1584  // levels on a distributed mesh.
1585  bool mesh_p_changed = false;
1586 
1587  // Iterate over the elements, looking for elements flagged for
1588  // refinement.
1589 
1590  // If we are on a ReplicatedMesh, then we just do the refinement in
1591  // the same order on every processor and everything stays in sync.
1592 
1593  // If we are on a DistributedMesh, that's impossible.
1594  //
1595  // If the mesh is distributed, we need to make sure that if we end
1596  // up as the owner of a new node, which might happen if that node is
1597  // attached to one of our own elements, then we have given it a
1598  // legitimate node id and our own processor id. We generate
1599  // legitimate node ids and use our own processor id when we are
1600  // refining our own elements but not when we refine others'
1601  // elements. Therefore we want to refine our own elements *first*,
1602  // thereby generating all nodes which might belong to us, and then
1603  // refine others' elements *after*, thereby generating nodes with
1604  // temporary ids which we know we will discard.
1605  //
1606  // Even if the DistributedMesh is serialized, we can't just treat it
1607  // like a ReplicatedMesh, because DistributedMesh doesn't *trust*
1608  // users to refine partitioned elements in a serialized way, so it
1609  // assigns temporary ids, so we need to synchronize ids afterward to
1610  // be safe anyway, so we might as well use the distributed mesh code
1611  // path.
1612  {
1614  elem_it = _mesh.active_local_elements_begin(),
1615  elem_end = _mesh.active_local_elements_end();
1616 
1617  if (_mesh.is_replicated())
1618  {
1619  elem_it = _mesh.active_elements_begin();
1620  elem_end = _mesh.active_elements_end();
1621  }
1622 
1623  for (; elem_it != elem_end; ++elem_it)
1624  {
1625  Elem * elem = *elem_it;
1626  if (elem->refinement_flag() == Elem::REFINE)
1627  local_copy_of_elements.push_back(elem);
1628  if (elem->p_refinement_flag() == Elem::REFINE &&
1629  elem->active())
1630  {
1631  elem->set_p_level(elem->p_level()+1);
1633  mesh_p_changed = true;
1634  }
1635  }
1636  }
1637 
1638  if (!_mesh.is_replicated())
1639  {
1642  elem_end = _mesh.active_not_local_elements_end();
1643  elem_it != elem_end; ++elem_it)
1644  {
1645  Elem * elem = *elem_it;
1646  if (elem->refinement_flag() == Elem::REFINE)
1647  local_copy_of_elements.push_back(elem);
1648  if (elem->p_refinement_flag() == Elem::REFINE &&
1649  elem->active())
1650  {
1651  elem->set_p_level(elem->p_level()+1);
1653  mesh_p_changed = true;
1654  }
1655  }
1656  }
1657 
1658  // Now iterate over the local copies and refine each one.
1659  // This may resize the mesh's internal container and invalidate
1660  // any existing iterators.
1661 
1662  for (std::size_t e = 0; e != local_copy_of_elements.size(); ++e)
1663  local_copy_of_elements[e]->refine(*this);
1664 
1665  // The mesh changed if there were elements h refined
1666  bool mesh_changed = !local_copy_of_elements.empty();
1667 
1668  // If the mesh changed on any processor, it changed globally
1669  this->comm().max(mesh_changed);
1670  this->comm().max(mesh_p_changed);
1671 
1672  // And we may need to update DistributedMesh values reflecting the changes
1673  if (mesh_changed)
1675 
1676  if (mesh_changed && !_mesh.is_replicated())
1677  {
1680 #ifdef DEBUG
1682 #endif
1683  }
1684 
1685  if (mesh_p_changed && !_mesh.is_replicated())
1686  {
1688  }
1689 
1690  // Clear the _new_nodes_map and _unused_elements data structures.
1691  this->clear();
1692 
1693  return (mesh_changed || mesh_p_changed);
1694 }
void set_p_level(const unsigned int p)
Definition: elem.h:2358
virtual void libmesh_assert_valid_parallel_ids() const
Definition: mesh_base.h:948
bool active() const
Definition: elem.h:2059
unsigned int p_level() const
Definition: elem.h:2224
virtual bool is_replicated() const
Definition: mesh_base.h:159
void make_elems_parallel_consistent(MeshBase &)
The base class for all geometric element types.
Definition: elem.h:86
IterBase * end
virtual element_iterator elements_begin()=0
virtual element_iterator active_local_elements_begin()=0
virtual void update_parallel_id_counts()=0
virtual element_iterator elements_end()=0
void make_p_levels_parallel_consistent(MeshBase &)
RefinementState p_refinement_flag() const
Definition: elem.h:2320
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
virtual element_iterator active_not_local_elements_end()=0
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2304
virtual element_iterator active_not_local_elements_begin()=0
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
void make_new_nodes_parallel_consistent(MeshBase &)
virtual element_iterator active_local_elements_end()=0
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 1697 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().

1698 {
1699  // Smoothing can break in weird ways on a mesh with broken topology
1700 #ifdef DEBUG
1702 #endif
1703 
1704  // Repeat until flag changes match on every processor
1705  do
1706  {
1707  // Repeat until coarsening & refinement flags jive
1708  bool satisfied = false;
1709  do
1710  {
1711  // If we're refining or coarsening, hit the corresponding
1712  // face level test code. Short-circuiting || is our friend
1713  const bool coarsening_satisfied =
1714  !coarsening ||
1716 
1717  const bool refinement_satisfied =
1718  !refining ||
1720 
1721  bool smoothing_satisfied =
1722  !this->eliminate_unrefined_patches();// &&
1723 
1725  smoothing_satisfied = smoothing_satisfied &&
1727 
1729  smoothing_satisfied = smoothing_satisfied &&
1731 
1733  smoothing_satisfied = smoothing_satisfied &&
1735 
1737  smoothing_satisfied = smoothing_satisfied &&
1739 
1740  satisfied = (coarsening_satisfied &&
1741  refinement_satisfied &&
1742  smoothing_satisfied);
1743 
1744  libmesh_assert(this->comm().verify(satisfied));
1745  }
1746  while (!satisfied);
1747  }
1748  while (!_mesh.is_serial() && !this->make_flags_parallel_consistent());
1749 }
bool limit_level_mismatch_at_edge(const unsigned int max_mismatch)
virtual bool is_serial() const
Definition: mesh_base.h:137
bool limit_level_mismatch_at_node(const unsigned int max_mismatch)
bool limit_underrefined_boundary(const signed char max_mismatch)
bool limit_overrefined_boundary(const signed char max_mismatch)
signed char _underrefined_boundary_limit
libmesh_assert(j)
signed char _overrefined_boundary_limit
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)
Definition: mesh_tools.C:1825
Real & libMesh::MeshRefinement::absolute_global_tolerance ( )
inline

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 900 of file mesh_refinement.h.

References _absolute_global_tolerance, and _use_member_parameters.

Referenced by get_mesh().

901 {
902  _use_member_parameters = true;
904 }
Elem * libMesh::MeshRefinement::add_elem ( Elem elem)

Adds the element elem to the mesh.

Definition at line 206 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().

207 {
208  libmesh_assert(elem);
209 
210 
211  // // If the unused_elements has any iterators from
212  // // old elements, take the first one
213  // if (!_unused_elements.empty())
214  // {
215  // std::vector<Elem *>::iterator it = _unused_elements.front();
216 
217  // *it = elem;
218 
219  // _unused_elements.pop_front();
220  // }
221 
222  // // Otherwise, use the conventional add method
223  // else
224  // {
225  // _mesh.add_elem (elem);
226  // }
227 
228  // The _unused_elements optimization has been turned off.
229  _mesh.add_elem (elem);
230 
231  return elem;
232 }
libmesh_assert(j)
virtual Elem * add_elem(Elem *e)=0
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 141 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::n_nodes(), 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().

145 {
146  LOG_SCOPE("add_node()", "MeshRefinement");
147 
148  unsigned int parent_n = parent.as_parent_node(child, node);
149 
150  if (parent_n != libMesh::invalid_uint)
151  return parent.node_ptr(parent_n);
152 
153  const std::vector<std::pair<dof_id_type, dof_id_type> >
154  bracketing_nodes = parent.bracketing_nodes(child, node);
155 
156  // If we're not a parent node, we *must* be bracketed by at least
157  // one pair of parent nodes
158  libmesh_assert(bracketing_nodes.size());
159 
160  const dof_id_type new_node_id =
161  _new_nodes_map.find(bracketing_nodes);
162 
163  // Return the node if it already exists, but first update the
164  // processor_id if the node is now going to be attached to the
165  // element of a processor which may take ownership of it.
166  if (new_node_id != DofObject::invalid_id)
167  {
168  Node * node = _mesh.node_ptr(new_node_id);
169  if (proc_id < node->processor_id())
170  node->processor_id() = proc_id;
171  return node;
172  }
173 
174  // Otherwise we need to add a new node, with a default id and the
175  // requested processor_id. Figure out where to add the point:
176 
177  Point p; // defaults to 0,0,0
178 
179  for (unsigned int n=0; n != parent.n_nodes(); ++n)
180  {
181  // The value from the embedding matrix
182  const float em_val = parent.embedding_matrix(child,node,n);
183 
184  if (em_val != 0.)
185  {
186  p.add_scaled (parent.point(n), em_val);
187 
188  // If we'd already found the node we shouldn't be here
189  libmesh_assert_not_equal_to (em_val, 1);
190  }
191  }
192 
193  Node * new_node = _mesh.add_point (p, DofObject::invalid_id, proc_id);
194 
195  libmesh_assert(new_node);
196 
197  // Add the node to the map.
198  _new_nodes_map.add_node(*new_node, bracketing_nodes);
199 
200  // Return the address of the new node
201  return new_node;
202 }
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
const unsigned int invalid_uint
Definition: libmesh.h:184
dof_id_type find(dof_id_type bracket_node1, dof_id_type bracket_node2) const
Definition: topology_map.C:117
void add_scaled(const TypeVector< T2 > &, const T)
Definition: type_vector.h:620
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
libmesh_assert(j)
virtual unsigned int n_nodes() const =0
void add_node(const Node &mid_node, const std::vector< std::pair< dof_id_type, dof_id_type > > &bracketing_nodes)
Definition: topology_map.C:51
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1730
static const dof_id_type invalid_id
Definition: dof_object.h:334
virtual const std::vector< std::pair< dof_id_type, dof_id_type > > bracketing_nodes(unsigned int c, unsigned int n) const
Definition: elem.C:2374
const Point & point(const unsigned int i) const
Definition: elem.h:1667
virtual unsigned int as_parent_node(unsigned int c, unsigned int n) const
Definition: elem.C:2102
A geometric point in (x,y,z) 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:686
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 684 of file mesh_refinement_flagging.C.

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

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

685 {
686  MeshBase::element_iterator elem_it = _mesh.elements_begin();
687  const MeshBase::element_iterator elem_end = _mesh.elements_end();
688 
689  for ( ; elem_it != elem_end; ++elem_it)
690  (*elem_it)->set_p_refinement_flag((*elem_it)->refinement_flag());
691 }
virtual element_iterator elements_begin()=0
virtual element_iterator elements_end()=0
void libMesh::MeshRefinement::clean_refinement_flags ( )

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

Definition at line 695 of file mesh_refinement_flagging.C.

References _mesh, libMesh::Elem::DO_NOTHING, libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), 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().

696 {
697  // Possibly clean up the refinement flags from
698  // a previous step
699  // elem_iterator elem_it (_mesh.elements_begin());
700  // const elem_iterator elem_end(_mesh.elements_end());
701 
702  MeshBase::element_iterator elem_it = _mesh.elements_begin();
703  const MeshBase::element_iterator elem_end = _mesh.elements_end();
704 
705  for ( ; elem_it != elem_end; ++elem_it)
706  {
707  if ((*elem_it)->active())
708  {
709  (*elem_it)->set_refinement_flag(Elem::DO_NOTHING);
710  (*elem_it)->set_p_refinement_flag(Elem::DO_NOTHING);
711  }
712  else
713  {
714  (*elem_it)->set_refinement_flag(Elem::INACTIVE);
715  (*elem_it)->set_p_refinement_flag(Elem::INACTIVE);
716  }
717  }
718 }
virtual element_iterator elements_begin()=0
virtual element_iterator elements_end()=0
void libMesh::MeshRefinement::clear ( )

Deletes all the data that are currently stored.

Definition at line 134 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().

135 {
137 }
bool & libMesh::MeshRefinement::coarsen_by_parents ( )
inline

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 864 of file mesh_refinement.h.

References _coarsen_by_parents, and _use_member_parameters.

Referenced by get_mesh().

865 {
866  _use_member_parameters = true;
867  return _coarsen_by_parents;
868 }
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 639 of file mesh_refinement.C.

References _coarsen_elements(), _face_level_mismatch_limit, _mesh, _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), 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().

640 {
641  // This function must be run on all processors at once
642  parallel_object_only();
643 
644  // We can't yet turn a non-level-one mesh into a level-one mesh
647 
648  // Possibly clean up the refinement flags from
649  // a previous step
651  const MeshBase::element_iterator elem_end = _mesh.elements_end();
652 
653  for ( ; elem_it != elem_end; ++elem_it)
654  {
655  // Pointer to the element
656  Elem * elem = *elem_it;
657 
658  // Set refinement flag to INACTIVE if the
659  // element isn't active
660  if ( !elem->active())
661  {
664  }
665 
666  // This might be left over from the last step
667  if (elem->refinement_flag() == Elem::JUST_REFINED)
669  }
670 
671  // Parallel consistency has to come first, or coarsening
672  // along processor boundaries might occasionally be falsely
673  // prevented
674  bool flags_were_consistent = this->make_flags_parallel_consistent();
675 
676  // In theory, we should be able to remove the above call, which can
677  // be expensive and should be unnecessary. In practice, doing
678  // consistent flagging in parallel is hard, it's impossible to
679  // verify at the library level if it's being done by user code, and
680  // we don't want to abort large parallel runs in opt mode... but we
681  // do want to warn that they should be fixed.
682  libmesh_assert(flags_were_consistent);
683  if (!flags_were_consistent)
684  {
685  libMesh::out << "Refinement flags were not consistent between processors!\n"
686  << "Correcting and continuing.";
687  }
688 
689  // Smooth coarsening flags
690  _smooth_flags(false, true);
691 
692  // Coarsen the flagged elements.
693  const bool mesh_changed =
694  this->_coarsen_elements ();
695 
699  // FIXME: This won't pass unless we add a redundant find_neighbors()
700  // call or replace find_neighbors() with on-the-fly neighbor updating
701  // libmesh_assert(!this->eliminate_unrefined_patches());
702 
703  // We can't contract the mesh ourselves anymore - a System might
704  // need to restrict old coefficient vectors first
705  // _mesh.contract();
706 
707  // Finally, the new mesh may need to be prepared for use
708  if (mesh_changed)
709  _mesh.prepare_for_use (/*skip_renumber =*/false);
710 
711  return mesh_changed;
712 }
bool active() const
Definition: elem.h:2059
The base class for all geometric element types.
Definition: elem.h:86
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
libmesh_assert(j)
virtual element_iterator elements_begin()=0
bool test_level_one(bool libmesh_assert_yes=false)
unsigned char _face_level_mismatch_limit
virtual element_iterator elements_end()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Definition: mesh_base.C:173
RefinementState refinement_flag() const
Definition: elem.h:2304
void _smooth_flags(bool refining, bool coarsening)
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
OStreamProxy out(std::cout)
Real & libMesh::MeshRefinement::coarsen_fraction ( )
inline

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 876 of file mesh_refinement.h.

References _coarsen_fraction, and _use_member_parameters.

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

877 {
878  _use_member_parameters = true;
879  return _coarsen_fraction;
880 }
Real & libMesh::MeshRefinement::coarsen_threshold ( )
inline

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 888 of file mesh_refinement.h.

References _coarsen_threshold, and _use_member_parameters.

Referenced by get_mesh().

889 {
890  _use_member_parameters = true;
891  return _coarsen_threshold;
892 }
const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
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_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(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::EigenSparseLinearSolver< T >::adjoint_solve(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), 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::DistributedVector< T >::clone(), libMesh::EigenSparseVector< T >::clone(), libMesh::LaspackVector< T >::clone(), libMesh::EpetraVector< T >::clone(), libMesh::PetscVector< T >::clone(), libMesh::EpetraVector< T >::close(), libMesh::Parallel::Sort< KeyType, IdxType >::communicate_bins(), 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::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), 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::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), flag_elements_by_elem_fraction(), flag_elements_by_error_fraction(), flag_elements_by_nelem_target(), libMesh::MeshCommunication::gather(), libMesh::MeshCommunication::gather_neighboring_elements(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::EquationSystems::get_solution(), libMesh::LocationMap< T >::init(), libMesh::PetscDiffSolver::init(), libMesh::TimeSolver::init(), libMesh::TopologyMap::init(), libMesh::TaoOptimizationSolver< T >::init(), libMesh::PetscNonlinearSolver< T >::init(), libMesh::DistributedVector< T >::init(), libMesh::EpetraVector< T >::init(), libMesh::PetscVector< 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::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(), 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::DistributedVector< T >::max(), libMesh::FEMSystem::mesh_position_set(), libMesh::MeshSerializer::MeshSerializer(), libMesh::DistributedVector< T >::min(), 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(), 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(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), 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(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::MeshCommunication::send_coarse_ghosts(), 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(), test_unflagged(), libMesh::MeshTools::total_weight(), uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::DistributedVector< T >::zero_clone(), libMesh::EigenSparseVector< T >::zero_clone(), libMesh::LaspackVector< T >::zero_clone(), libMesh::EpetraVector< T >::zero_clone(), and libMesh::PetscVector< T >::zero_clone().

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 236 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), 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().

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

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 911 of file mesh_refinement.h.

References _edge_level_mismatch_limit.

Referenced by get_mesh().

912 {
914 }
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 418 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::Elem::active(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::ancestor(), libMesh::Elem::child_ptr(), libMesh::Elem::COARSEN, libMesh::Elem::COARSEN_INACTIVE, libMesh::ParallelObject::comm(), libMesh::Elem::DO_NOTHING, libMesh::Elem::INACTIVE, libMesh::Elem::level(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::max(), libMesh::Elem::min_new_p_level_by_neighbor(), libMesh::Elem::n_children(), libMesh::Elem::n_neighbors(), libMesh::Elem::neighbor_ptr(), 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(), and libMesh::Elem::set_refinement_flag().

Referenced by _smooth_flags(), and get_mesh().

419 {
420  // This function must be run on all processors at once
421  parallel_object_only();
422 
423  bool flags_changed = false;
424 
425  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
426  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
427 
428  for (; elem_it != elem_end; ++elem_it)
429  {
430  Elem * elem = *elem_it;
431  // First assume that we'll have to flag this element for both h
432  // and p refinement, then change our minds if we see any
433  // neighbors that are as coarse or coarser than us.
434  bool h_flag_me = true,
435  p_flag_me = true;
436 
437 
438  // Skip the element if it is already fully flagged for refinement
439  if (elem->p_refinement_flag() == Elem::REFINE)
440  p_flag_me = false;
441  if (elem->refinement_flag() == Elem::REFINE)
442  {
443  h_flag_me = false;
444  if (!p_flag_me)
445  continue;
446  }
447  // Test the parent if that is already flagged for coarsening
448  else if (elem->refinement_flag() == Elem::COARSEN)
449  {
450  libmesh_assert(elem->parent());
451  elem = elem->parent();
452  // FIXME - this doesn't seem right - RHS
453  if (elem->refinement_flag() != Elem::COARSEN_INACTIVE)
454  continue;
455  p_flag_me = false;
456  }
457 
458  const unsigned int my_level = elem->level();
459  int my_p_adjustment = 0;
460  if (elem->p_refinement_flag() == Elem::REFINE)
461  my_p_adjustment = 1;
462  else if (elem->p_refinement_flag() == Elem::COARSEN)
463  {
464  libmesh_assert_greater (elem->p_level(), 0);
465  my_p_adjustment = -1;
466  }
467  const unsigned int my_new_p_level = elem->p_level() +
468  my_p_adjustment;
469 
470  // Check all the element neighbors
471  for (unsigned int n=0; n<elem->n_neighbors(); n++)
472  {
473  const Elem * neighbor = elem->neighbor_ptr(n);
474  // Quit if the element is on a local boundary
475  if (neighbor == libmesh_nullptr || neighbor == remote_elem)
476  {
477  h_flag_me = false;
478  p_flag_me = false;
479  break;
480  }
481  // if the neighbor will be equally or less refined than
482  // we are, then we will not become an unrefined island.
483  // So if we are still considering h refinement:
484  if (h_flag_me &&
485  // If our neighbor is already at a lower level,
486  // it can't end up at a higher level even if it
487  // is flagged for refinement once
488  ((neighbor->level() < my_level) ||
489  // If our neighbor is at the same level but isn't
490  // flagged for refinement, it won't end up at a
491  // higher level
492  ((neighbor->active()) &&
493  (neighbor->refinement_flag() != Elem::REFINE)) ||
494  // If our neighbor is currently more refined but is
495  // a parent flagged for coarsening, it will end up
496  // at the same level.
497  (neighbor->refinement_flag() == Elem::COARSEN_INACTIVE)))
498  {
499  // We've proven we won't become an unrefined island,
500  // so don't h refine to avoid that.
501  h_flag_me = false;
502 
503  // If we've also proven we don't need to p refine,
504  // we don't need to check more neighbors
505  if (!p_flag_me)
506  break;
507  }
508  if (p_flag_me)
509  {
510  // if active neighbors will have a p level
511  // equal to or lower than ours, then we do not need to p
512  // refine ourselves.
513  if (neighbor->active())
514  {
515  int p_adjustment = 0;
516  if (neighbor->p_refinement_flag() == Elem::REFINE)
517  p_adjustment = 1;
518  else if (neighbor->p_refinement_flag() == Elem::COARSEN)
519  {
520  libmesh_assert_greater (neighbor->p_level(), 0);
521  p_adjustment = -1;
522  }
523  if (my_new_p_level >= neighbor->p_level() + p_adjustment)
524  {
525  p_flag_me = false;
526  if (!h_flag_me)
527  break;
528  }
529  }
530  // If we have inactive neighbors, we need to
531  // test all their active descendants which neighbor us
532  else if (neighbor->ancestor())
533  {
534  if (neighbor->min_new_p_level_by_neighbor(elem,
535  my_new_p_level + 2) <= my_new_p_level)
536  {
537  p_flag_me = false;
538  if (!h_flag_me)
539  break;
540  }
541  }
542  }
543  }
544 
545  if (h_flag_me)
546  {
547  // Parents that would create islands should no longer
548  // coarsen
549  if (elem->refinement_flag() == Elem::COARSEN_INACTIVE)
550  {
551  for (unsigned int c=0; c<elem->n_children(); c++)
552  {
553  libmesh_assert_equal_to (elem->child_ptr(c)->refinement_flag(),
554  Elem::COARSEN);
555  elem->child_ptr(c)->set_refinement_flag(Elem::DO_NOTHING);
556  }
557  elem->set_refinement_flag(Elem::INACTIVE);
558  }
559  else
560  elem->set_refinement_flag(Elem::REFINE);
561  flags_changed = true;
562  }
563  if (p_flag_me)
564  {
565  if (elem->p_refinement_flag() == Elem::COARSEN)
566  elem->set_p_refinement_flag(Elem::DO_NOTHING);
567  else
568  elem->set_p_refinement_flag(Elem::REFINE);
569  flags_changed = true;
570  }
571  }
572 
573  // If flags changed on any processor then they changed globally
574  this->comm().max(flags_changed);
575 
576  return flags_changed;
577 }
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
const Parallel::Communicator & comm() const
const RemoteElem * remote_elem
Definition: remote_elem.C:57
bool & libMesh::MeshRefinement::enforce_mismatch_limit_prior_to_refinement ( )
inline

Get/set the _enforce_mismatch_limit_prior_to_refinement flag. The default value for this flag is false.

Definition at line 943 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().

944 {
946 }
bool _enforce_mismatch_limit_prior_to_refinement
bool libMesh::MeshRefinement::enforce_mismatch_limit_prior_to_refinement ( Elem elem,
NeighborType  nt,
unsigned  max_mismatch 
)
private

Definition at line 581 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().

584 {
585  // Eventual return value
586  bool flags_changed = false;
587 
588  // If we are enforcing the limit prior to refinement then we
589  // need to remove flags from any elements marked for refinement that
590  // would cause a mismatch
592  && elem->refinement_flag() == Elem::REFINE)
593  {
594  // get all the relevant neighbors since we may have to refine
595  // elements off edges or corners as well
596  std::set<const Elem *> neighbor_set;
597 
598  if (nt == POINT)
599  elem->find_point_neighbors(neighbor_set);
600  else if (nt == EDGE)
601  elem->find_edge_neighbors(neighbor_set);
602  else
603  libmesh_error_msg("Unrecognized NeighborType: " << nt);
604 
605  // Loop over the neighbors of element e
606  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
607  for (; n_it != neighbor_set.end(); ++n_it)
608  {
609  const Elem * neighbor = *n_it;
610 
611  if ((elem->level() + 1 - max_mismatch) > neighbor->level())
612  {
613  elem->set_refinement_flag(Elem::DO_NOTHING);
614  flags_changed = true;
615  }
616  if ((elem->p_level() + 1 - max_mismatch) > neighbor->p_level())
617  {
618  elem->set_p_refinement_flag(Elem::DO_NOTHING);
619  flags_changed = true;
620  }
621  } // loop over edge/point neighbors
622  } // if _enforce_mismatch_limit_prior_to_refinement
623 
624  return flags_changed;
625 }
bool _enforce_mismatch_limit_prior_to_refinement
unsigned char & libMesh::MeshRefinement::face_level_mismatch_limit ( )
inline

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 906 of file mesh_refinement.h.

References _face_level_mismatch_limit.

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

907 {
909 }
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 655 of file mesh_refinement_flagging.C.

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

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

656 {
657  element_flagging.flag_elements();
658 }
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 452 of file mesh_refinement_flagging.C.

References _coarsen_by_parents, _coarsen_fraction, _max_h_level, _mesh, _refine_fraction, _use_member_parameters, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::Parallel::Communicator::allgather(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::invalid_uint, libMesh::Elem::level(), 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 libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

456 {
457  parallel_object_only();
458 
459  // The function arguments are currently just there for
460  // backwards_compatibility
462  {
463  // If the user used non-default parameters, lets warn
464  // that they're deprecated
465  if (refine_frac != 0.3 ||
466  coarsen_frac != 0.0 ||
467  max_l != libMesh::invalid_uint)
468  libmesh_deprecated();
469 
470  _refine_fraction = refine_frac;
471  _coarsen_fraction = coarsen_frac;
472  _max_h_level = max_l;
473  }
474 
475  // Check for valid fractions..
476  // The fraction values must be in [0,1]
477  libmesh_assert_greater_equal (_refine_fraction, 0);
478  libmesh_assert_less_equal (_refine_fraction, 1);
479  libmesh_assert_greater_equal (_coarsen_fraction, 0);
480  libmesh_assert_less_equal (_coarsen_fraction, 1);
481 
482  // The number of active elements in the mesh
483  const dof_id_type n_active_elem = _mesh.n_active_elem();
484 
485  // The number of elements to flag for coarsening
486  const dof_id_type n_elem_coarsen =
487  static_cast<dof_id_type>(_coarsen_fraction * n_active_elem);
488 
489  // The number of elements to flag for refinement
490  const dof_id_type n_elem_refine =
491  static_cast<dof_id_type>(_refine_fraction * n_active_elem);
492 
493 
494 
495  // Clean up the refinement flags. These could be left
496  // over from previous refinement steps.
497  this->clean_refinement_flags();
498 
499 
500  // This vector stores the error and element number for all the
501  // active elements. It will be sorted and the top & bottom
502  // elements will then be flagged for coarsening & refinement
503  std::vector<ErrorVectorReal> sorted_error;
504 
505  sorted_error.reserve (n_active_elem);
506 
507  // Loop over the active elements and create the entry
508  // in the sorted_error vector
509  MeshBase::element_iterator elem_it = _mesh.active_local_elements_begin();
510  const MeshBase::element_iterator elem_end = _mesh.active_local_elements_end();
511 
512  for (; elem_it != elem_end; ++elem_it)
513  sorted_error.push_back (error_per_cell[(*elem_it)->id()]);
514 
515  this->comm().allgather(sorted_error);
516 
517  // Now sort the sorted_error vector
518  std::sort (sorted_error.begin(), sorted_error.end());
519 
520  // If we're coarsening by parents:
521  // Create a sorted error vector with coarsenable parent elements
522  // only, sorted by lowest errors first
523  ErrorVector error_per_parent, sorted_parent_error;
525  {
526  Real parent_error_min, parent_error_max;
527 
528  create_parent_error_vector(error_per_cell,
529  error_per_parent,
530  parent_error_min,
531  parent_error_max);
532 
533  sorted_parent_error = error_per_parent;
534  std::sort (sorted_parent_error.begin(), sorted_parent_error.end());
535 
536  // All the other error values will be 0., so get rid of them.
537  sorted_parent_error.erase (std::remove(sorted_parent_error.begin(),
538  sorted_parent_error.end(), 0.),
539  sorted_parent_error.end());
540  }
541 
542 
543  ErrorVectorReal top_error= 0., bottom_error = 0.;
544 
545  // Get the maximum error value corresponding to the
546  // bottom n_elem_coarsen elements
547  if (_coarsen_by_parents && n_elem_coarsen)
548  {
549  const unsigned int dim = _mesh.mesh_dimension();
550  unsigned int twotodim = 1;
551  for (unsigned int i=0; i!=dim; ++i)
552  twotodim *= 2;
553 
554  dof_id_type n_parent_coarsen = n_elem_coarsen / (twotodim - 1);
555 
556  if (n_parent_coarsen)
557  bottom_error = sorted_parent_error[n_parent_coarsen - 1];
558  }
559  else if (n_elem_coarsen)
560  {
561  bottom_error = sorted_error[n_elem_coarsen - 1];
562  }
563 
564  if (n_elem_refine)
565  top_error = sorted_error[sorted_error.size() - n_elem_refine];
566 
567  // Finally, let's do the element flagging
568  elem_it = _mesh.active_elements_begin();
569  for (; elem_it != elem_end; ++elem_it)
570  {
571  Elem * elem = *elem_it;
572  Elem * parent = elem->parent();
573 
574  if (_coarsen_by_parents && parent && n_elem_coarsen &&
575  error_per_parent[parent->id()] <= bottom_error)
576  elem->set_refinement_flag(Elem::COARSEN);
577 
578  if (!_coarsen_by_parents && n_elem_coarsen &&
579  error_per_cell[elem->id()] <= bottom_error)
580  elem->set_refinement_flag(Elem::COARSEN);
581 
582  if (n_elem_refine &&
583  elem->level() < _max_h_level &&
584  error_per_cell[elem->id()] >= top_error)
585  elem->set_refinement_flag(Elem::REFINE);
586  }
587 }
virtual dof_id_type n_active_elem() const =0
const unsigned int invalid_uint
Definition: libmesh.h:184
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual element_iterator active_local_elements_begin()=0
virtual element_iterator active_elements_begin()=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:147
virtual element_iterator active_local_elements_end()=0
uint8_t dof_id_type
Definition: id_types.h:64
void allgather(const T &send, std::vector< T > &recv) const
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_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::invalid_uint, libMesh::Elem::level(), std::max(), libMesh::Parallel::Communicator::max(), std::min(), libMesh::Parallel::Communicator::min(), libMesh::Elem::parent(), libMesh::Real, libMesh::Elem::REFINE, and libMesh::Elem::set_refinement_flag().

Referenced by 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  MeshBase::element_iterator el_it =
100  const MeshBase::element_iterator el_end =
102 
103  for (; el_it != el_end; ++el_it)
104  {
105  const dof_id_type id = (*el_it)->id();
106  libmesh_assert_less (id, error_per_cell.size());
107 
108  error_max = std::max (error_max, error_per_cell[id]);
109  error_min = std::min (error_min, error_per_cell[id]);
110  }
111  this->comm().max(error_max);
112  this->comm().min(error_min);
113 
114  // Compute the cutoff values for coarsening and refinement
115  const Real error_delta = (error_max - error_min);
116  const Real parent_error_delta = parent_error_max - parent_error_min;
117 
118  const Real refine_cutoff = (1.- _refine_fraction)*error_max;
119  const Real coarsen_cutoff = _coarsen_fraction*error_delta + error_min;
120  const Real parent_cutoff = _coarsen_fraction*parent_error_delta + error_min;
121 
122  // // Print information about the error
123  // libMesh::out << " Error Information:" << std::endl
124  // << " ------------------" << std::endl
125  // << " min: " << error_min << std::endl
126  // << " max: " << error_max << std::endl
127  // << " delta: " << error_delta << std::endl
128  // << " refine_cutoff: " << refine_cutoff << std::endl
129  // << " coarsen_cutoff: " << coarsen_cutoff << std::endl;
130 
131 
132 
133  // Loop over the elements and flag them for coarsening or
134  // refinement based on the element error
135 
136  MeshBase::element_iterator e_it =
138  const MeshBase::element_iterator e_end =
140  for (; e_it != e_end; ++e_it)
141  {
142  Elem * elem = *e_it;
143  const dof_id_type id = elem->id();
144 
145  libmesh_assert_less (id, error_per_cell.size());
146 
147  const ErrorVectorReal elem_error = error_per_cell[id];
148 
150  {
151  Elem * parent = elem->parent();
152  if (parent)
153  {
154  const dof_id_type parentid = parent->id();
155  if (error_per_parent[parentid] >= 0. &&
156  error_per_parent[parentid] <= parent_cutoff)
157  elem->set_refinement_flag(Elem::COARSEN);
158  }
159  }
160  // Flag the element for coarsening if its error
161  // is <= coarsen_fraction*delta + error_min
162  else if (elem_error <= coarsen_cutoff)
163  {
164  elem->set_refinement_flag(Elem::COARSEN);
165  }
166 
167  // Flag the element for refinement if its error
168  // is >= refinement_cutoff.
169  if (elem_error >= refine_cutoff)
170  if (elem->level() < _max_h_level)
171  elem->set_refinement_flag(Elem::REFINE);
172  }
173 }
const unsigned int invalid_uint
Definition: libmesh.h:184
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual element_iterator active_local_elements_begin()=0
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
virtual element_iterator active_local_elements_end()=0
long double min(long double a, double b)
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 177 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_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::COARSEN, create_parent_error_vector(), libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::Elem::level(), libMesh::MeshBase::n_active_elem(), libMesh::Elem::n_children(), libMesh::Elem::parent(), libMesh::Real, libMesh::Elem::REFINE, and libMesh::Elem::set_refinement_flag().

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

178 {
179  parallel_object_only();
180 
181  libmesh_assert_greater (_coarsen_threshold, 0);
182 
183  // Check for valid fractions..
184  // The fraction values must be in [0,1]
185  libmesh_assert_greater_equal (_refine_fraction, 0);
186  libmesh_assert_less_equal (_refine_fraction, 1);
187  libmesh_assert_greater_equal (_coarsen_fraction, 0);
188  libmesh_assert_less_equal (_coarsen_fraction, 1);
189 
190  // How much error per cell will we tolerate?
191  const Real local_refinement_tolerance =
192  _absolute_global_tolerance / std::sqrt(static_cast<Real>(_mesh.n_active_elem()));
193  const Real local_coarsening_tolerance =
194  local_refinement_tolerance * _coarsen_threshold;
195 
196  // Prepare another error vector if we need to sum parent errors
197  ErrorVector error_per_parent;
199  {
200  Real parent_error_min, parent_error_max;
201 
202  create_parent_error_vector(error_per_cell_in,
203  error_per_parent,
204  parent_error_min,
205  parent_error_max);
206  }
207 
208  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
209  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
210 
211  for (; elem_it != elem_end; ++elem_it)
212  {
213  Elem * elem = *elem_it;
214  Elem * parent = elem->parent();
215  const dof_id_type elem_number = elem->id();
216  const ErrorVectorReal elem_error = error_per_cell_in[elem_number];
217 
218  if (elem_error > local_refinement_tolerance &&
219  elem->level() < _max_h_level)
220  elem->set_refinement_flag(Elem::REFINE);
221 
222  if (!_coarsen_by_parents && elem_error <
223  local_coarsening_tolerance)
224  elem->set_refinement_flag(Elem::COARSEN);
225 
226  if (_coarsen_by_parents && parent)
227  {
228  ErrorVectorReal parent_error = error_per_parent[parent->id()];
229  if (parent_error >= 0.)
230  {
231  const Real parent_coarsening_tolerance =
232  std::sqrt(parent->n_children() *
233  local_coarsening_tolerance *
234  local_coarsening_tolerance);
235  if (parent_error < parent_coarsening_tolerance)
236  elem->set_refinement_flag(Elem::COARSEN);
237  }
238  }
239  }
240 }
virtual dof_id_type n_active_elem() const =0
void create_parent_error_vector(const ErrorVector &error_per_cell, ErrorVector &error_per_parent, Real &parent_error_min, Real &parent_error_max)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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 591 of file mesh_refinement_flagging.C.

References _coarsen_fraction, _max_h_level, _mesh, _refine_fraction, _use_member_parameters, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::COARSEN, libMesh::ErrorVectorReal, libMesh::DofObject::id(), libMesh::invalid_uint, libMesh::Elem::level(), std::max(), libMesh::ErrorVector::mean(), libMesh::Real, libMesh::Elem::REFINE, libMesh::Elem::set_refinement_flag(), and libMesh::ErrorVector::variance().

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

595 {
596  // The function arguments are currently just there for
597  // backwards_compatibility
599  {
600  // If the user used non-default parameters, lets warn
601  // that they're deprecated
602  if (refine_frac != 0.3 ||
603  coarsen_frac != 0.0 ||
604  max_l != libMesh::invalid_uint)
605  libmesh_deprecated();
606 
607  _refine_fraction = refine_frac;
608  _coarsen_fraction = coarsen_frac;
609  _max_h_level = max_l;
610  }
611 
612  // Get the mean value from the error vector
613  const Real mean = error_per_cell.mean();
614 
615  // Get the standard deviation. This equals the
616  // square-root of the variance
617  const Real stddev = std::sqrt (error_per_cell.variance());
618 
619  // Check for valid fractions
620  libmesh_assert_greater_equal (_refine_fraction, 0);
621  libmesh_assert_less_equal (_refine_fraction, 1);
622  libmesh_assert_greater_equal (_coarsen_fraction, 0);
623  libmesh_assert_less_equal (_coarsen_fraction, 1);
624 
625  // The refine and coarsen cutoff
626  const Real refine_cutoff = mean + _refine_fraction * stddev;
627  const Real coarsen_cutoff = std::max(mean - _coarsen_fraction * stddev, 0.);
628 
629  // Loop over the elements and flag them for coarsening or
630  // refinement based on the element error
631  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
632  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
633 
634  for (; elem_it != elem_end; ++elem_it)
635  {
636  Elem * elem = *elem_it;
637  const dof_id_type id = elem->id();
638 
639  libmesh_assert_less (id, error_per_cell.size());
640 
641  const ErrorVectorReal elem_error = error_per_cell[id];
642 
643  // Possibly flag the element for coarsening ...
644  if (elem_error <= coarsen_cutoff)
645  elem->set_refinement_flag(Elem::COARSEN);
646 
647  // ... or refinement
648  if ((elem_error >= refine_cutoff) && (elem->level() < _max_h_level))
649  elem->set_refinement_flag(Elem::REFINE);
650  }
651 }
const unsigned int invalid_uint
Definition: libmesh.h:184
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
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 244 of file mesh_refinement_flagging.C.

References _coarsen_by_parents, _coarsen_fraction, _coarsen_threshold, _max_h_level, _mesh, _nelem_target, _refine_fraction, libMesh::Elem::active(), libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::Parallel::Communicator::allgather(), libMesh::Elem::child_ptr(), clean_refinement_flags(), libMesh::Elem::COARSEN, libMesh::ParallelObject::comm(), create_parent_error_vector(), 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::Elem::n_children(), 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().

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

References enforce_mismatch_limit_prior_to_refinement().

Referenced by get_mesh().

932 {
933  libmesh_deprecated();
935 }
bool & enforce_mismatch_limit_prior_to_refinement()
const MeshBase& libMesh::MeshRefinement::get_mesh ( ) const
inline
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; }
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 1936 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().

1939 {
1940 #ifdef LIBMESH_ENABLE_PERIODIC
1941  if (_periodic_boundaries && !_periodic_boundaries->empty())
1942  {
1943  libmesh_assert(point_locator);
1944  return elem->has_topological_neighbor(neighbor, _mesh, *point_locator, _periodic_boundaries);
1945  }
1946 #endif
1947  return elem->has_neighbor(neighbor);
1948 }
bool has_topological_neighbor(const Elem *elem, const MeshBase &mesh, const PointLocatorBase &point_locator, const PeriodicBoundaries *pb) const
Definition: elem.C:1094
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
bool has_neighbor(const Elem *elem) const
Definition: elem.h:1862
bool libMesh::MeshRefinement::limit_level_mismatch_at_edge ( const unsigned int  max_mismatch)
private

Definition at line 138 of file mesh_refinement_smoothing.C.

References _enforce_mismatch_limit_prior_to_refinement, _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::build_edge_ptr(), libMesh::ParallelObject::comm(), EDGE, enforce_mismatch_limit_prior_to_refinement(), libMesh::Elem::level(), libmesh_nullptr, std::max(), libMesh::Parallel::Communicator::max(), libMesh::Elem::n_edges(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), libMesh::Elem::REFINE, libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), and swap().

Referenced by _smooth_flags(), and get_mesh().

139 {
140  // This function must be run on all processors at once
141  parallel_object_only();
142 
143  bool flags_changed = false;
144 
145 
146  // Maps holding the maximum element level that touches an edge
147  std::map<std::pair<unsigned int, unsigned int>, unsigned char>
148  max_level_at_edge;
149  std::map<std::pair<unsigned int, unsigned int>, unsigned char>
150  max_p_level_at_edge;
151 
152  // Loop over all the active elements & fill the maps
153  {
154  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
155  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
156 
157  for (; elem_it != elem_end; ++elem_it)
158  {
159  const Elem * elem = *elem_it;
160  const unsigned char elem_level =
161  cast_int<unsigned char>(elem->level() +
162  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
163  const unsigned char elem_p_level =
164  cast_int<unsigned char>(elem->p_level() +
165  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
166 
167  // Set the max_level at each edge
168  for (unsigned int n=0; n<elem->n_edges(); n++)
169  {
170  UniquePtr<const Elem> edge = elem->build_edge_ptr(n);
171  dof_id_type childnode0 = edge->node_id(0);
172  dof_id_type childnode1 = edge->node_id(1);
173  if (childnode1 < childnode0)
174  std::swap(childnode0, childnode1);
175 
176  for (const Elem * p = elem; p != libmesh_nullptr; p = p->parent())
177  {
178  UniquePtr<const Elem> pedge = p->build_edge_ptr(n);
179  dof_id_type node0 = pedge->node_id(0);
180  dof_id_type node1 = pedge->node_id(1);
181 
182  if (node1 < node0)
183  std::swap(node0, node1);
184 
185  // If elem does not share this edge with its ancestor
186  // p, refinement levels of elements sharing p's edge
187  // are not restricted by refinement levels of elem.
188  // Furthermore, elem will not share this edge with any
189  // of p's ancestors, so we can safely break out of the
190  // for loop early.
191  if (node0 != childnode0 && node1 != childnode1)
192  break;
193 
194  childnode0 = node0;
195  childnode1 = node1;
196 
197  std::pair<unsigned int, unsigned int> edge_key =
198  std::make_pair(node0, node1);
199 
200  if (max_level_at_edge.find(edge_key) ==
201  max_level_at_edge.end())
202  {
203  max_level_at_edge[edge_key] = elem_level;
204  max_p_level_at_edge[edge_key] = elem_p_level;
205  }
206  else
207  {
208  max_level_at_edge[edge_key] =
209  std::max (max_level_at_edge[edge_key], elem_level);
210  max_p_level_at_edge[edge_key] =
211  std::max (max_p_level_at_edge[edge_key], elem_p_level);
212  }
213  }
214  }
215  }
216  }
217 
218 
219  // Now loop over the active elements and flag the elements
220  // who violate the requested level mismatch
221  {
222  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
223  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
224 
225  for (; elem_it != elem_end; ++elem_it)
226  {
227  Elem * elem = *elem_it;
228  const unsigned int elem_level = elem->level();
229  const unsigned int elem_p_level = elem->p_level();
230 
231  // Skip the element if it is already fully flagged
232  if (elem->refinement_flag() == Elem::REFINE &&
233  elem->p_refinement_flag() == Elem::REFINE
235  continue;
236 
237  // Loop over the nodes, check for possible mismatch
238  for (unsigned int n=0; n<elem->n_edges(); n++)
239  {
240  UniquePtr<Elem> edge = elem->build_edge_ptr(n);
241  dof_id_type node0 = edge->node_id(0);
242  dof_id_type node1 = edge->node_id(1);
243  if (node1 < node0)
244  std::swap(node0, node1);
245 
246  std::pair<dof_id_type, dof_id_type> edge_key =
247  std::make_pair(node0, node1);
248 
249  // Flag the element for refinement if it violates
250  // the requested level mismatch
251  if ((elem_level + max_mismatch) < max_level_at_edge[edge_key]
252  && elem->refinement_flag() != Elem::REFINE)
253  {
254  elem->set_refinement_flag (Elem::REFINE);
255  flags_changed = true;
256  }
257 
258  if ((elem_p_level + max_mismatch) < max_p_level_at_edge[edge_key]
259  && elem->p_refinement_flag() != Elem::REFINE)
260  {
261  elem->set_p_refinement_flag (Elem::REFINE);
262  flags_changed = true;
263  }
264 
265  // Possibly enforce limit mismatch prior to refinement
266  flags_changed |= this->enforce_mismatch_limit_prior_to_refinement(elem, EDGE, max_mismatch);
267  } // loop over edges
268  } // loop over active elements
269  }
270 
271  // If flags changed on any processor then they changed globally
272  this->comm().max(flags_changed);
273 
274  return flags_changed;
275 }
bool & enforce_mismatch_limit_prior_to_refinement()
const class libmesh_nullptr_t libmesh_nullptr
long double max(long double a, double b)
bool _enforce_mismatch_limit_prior_to_refinement
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
const Parallel::Communicator & comm() const
void swap(Iterator &lhs, Iterator &rhs)
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_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::ParallelObject::comm(), enforce_mismatch_limit_prior_to_refinement(), libMesh::Elem::level(), std::max(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_nodes(), libMesh::Elem::node_id(), libMesh::Elem::p_level(), libMesh::Elem::p_refinement_flag(), POINT, 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().

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  {
53  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
54  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
55 
56  for (; elem_it != elem_end; ++elem_it)
57  {
58  const Elem * elem = *elem_it;
59  const unsigned char elem_level =
60  cast_int<unsigned char>(elem->level() +
61  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
62  const unsigned char elem_p_level =
63  cast_int<unsigned char>(elem->p_level() +
64  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
65 
66  // Set the max_level at each node
67  for (unsigned int n=0; n<elem->n_nodes(); n++)
68  {
69  const dof_id_type node_number = elem->node_id(n);
70 
71  libmesh_assert_less (node_number, max_level_at_node.size());
72 
73  max_level_at_node[node_number] =
74  std::max (max_level_at_node[node_number], elem_level);
75  max_p_level_at_node[node_number] =
76  std::max (max_p_level_at_node[node_number], elem_p_level);
77  }
78  }
79  }
80 
81 
82  // Now loop over the active elements and flag the elements
83  // who violate the requested level mismatch. Alternatively, if
84  // _enforce_mismatch_limit_prior_to_refinement is true, swap refinement flags
85  // accordingly.
86  {
87  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
88  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
89 
90  for (; elem_it != elem_end; ++elem_it)
91  {
92  Elem * elem = *elem_it;
93  const unsigned int elem_level = elem->level();
94  const unsigned int elem_p_level = elem->p_level();
95 
96  // Skip the element if it is already fully flagged
97  // unless we are enforcing mismatch prior to refinement and may need to
98  // remove the refinement flag(s)
99  if (elem->refinement_flag() == Elem::REFINE &&
100  elem->p_refinement_flag() == Elem::REFINE
102  continue;
103 
104  // Loop over the nodes, check for possible mismatch
105  for (unsigned int n=0; n<elem->n_nodes(); n++)
106  {
107  const dof_id_type node_number = elem->node_id(n);
108 
109  // Flag the element for refinement if it violates
110  // the requested level mismatch
111  if ((elem_level + max_mismatch) < max_level_at_node[node_number]
112  && elem->refinement_flag() != Elem::REFINE)
113  {
114  elem->set_refinement_flag (Elem::REFINE);
115  flags_changed = true;
116  }
117  if ((elem_p_level + max_mismatch) < max_p_level_at_node[node_number]
118  && elem->p_refinement_flag() != Elem::REFINE)
119  {
120  elem->set_p_refinement_flag (Elem::REFINE);
121  flags_changed = true;
122  }
123 
124  // Possibly enforce limit mismatch prior to refinement
125  flags_changed |= this->enforce_mismatch_limit_prior_to_refinement(elem, POINT, max_mismatch);
126  }
127  }
128  }
129 
130  // If flags changed on any processor then they changed globally
131  this->comm().max(flags_changed);
132 
133  return flags_changed;
134 }
bool & enforce_mismatch_limit_prior_to_refinement()
long double max(long double a, double b)
bool _enforce_mismatch_limit_prior_to_refinement
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
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 279 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::ParallelObject::comm(), libMesh::Elem::dim(), libMesh::Elem::find_interior_neighbors(), libMesh::Elem::interior_parent(), 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().

280 {
281  // This function must be run on all processors at once
282  parallel_object_only();
283 
284  bool flags_changed = false;
285 
286  // Loop over all the active elements & look for mismatches to fix.
287  {
288  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
289  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
290 
291  for (; elem_it != elem_end; ++elem_it)
292  {
293  Elem * elem = *elem_it;
294 
295  // If we don't have an interior_parent then there's nothing to
296  // be mismatched with.
297  if ((elem->dim() >= LIBMESH_DIM) ||
298  !elem->interior_parent())
299  continue;
300 
301  const unsigned char elem_level =
302  cast_int<unsigned char>(elem->level() +
303  ((elem->refinement_flag() == Elem::REFINE) ? 1 : 0));
304  const unsigned char elem_p_level =
305  cast_int<unsigned char>(elem->p_level() +
306  ((elem->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
307 
308  // get all relevant interior elements
309  std::set<const Elem *> neighbor_set;
310  elem->find_interior_neighbors(neighbor_set);
311 
312  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
313  for (; n_it != neighbor_set.end(); ++n_it)
314  {
315  // FIXME - non-const versions of the Elem set methods
316  // would be nice
317  Elem * neighbor = const_cast<Elem *>(*n_it);
318 
319  if (max_mismatch >= 0)
320  {
321  if ((elem_level > neighbor->level() + max_mismatch) &&
322  (neighbor->refinement_flag() != Elem::REFINE))
323  {
324  neighbor->set_refinement_flag(Elem::REFINE);
325  flags_changed = true;
326  }
327 
328  if ((elem_p_level > neighbor->p_level() + max_mismatch) &&
329  (neighbor->p_refinement_flag() != Elem::REFINE))
330  {
331  neighbor->set_p_refinement_flag(Elem::REFINE);
332  flags_changed = true;
333  }
334  }
335  } // loop over interior neighbors
336  }
337  }
338 
339  // If flags changed on any processor then they changed globally
340  this->comm().max(flags_changed);
341 
342  return flags_changed;
343 }
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
const Parallel::Communicator & comm() const
bool libMesh::MeshRefinement::limit_underrefined_boundary ( const signed char  max_mismatch)
private

Definition at line 347 of file mesh_refinement_smoothing.C.

References _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::ParallelObject::comm(), libMesh::Elem::dim(), libMesh::Elem::find_interior_neighbors(), libMesh::Elem::interior_parent(), 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().

348 {
349  // This function must be run on all processors at once
350  parallel_object_only();
351 
352  bool flags_changed = false;
353 
354  // Loop over all the active elements & look for mismatches to fix.
355  {
356  MeshBase::element_iterator elem_it = _mesh.active_elements_begin();
357  const MeshBase::element_iterator elem_end = _mesh.active_elements_end();
358 
359  for (; elem_it != elem_end; ++elem_it)
360  {
361  Elem * elem = *elem_it;
362 
363  // If we don't have an interior_parent then there's nothing to
364  // be mismatched with.
365  if ((elem->dim() >= LIBMESH_DIM) ||
366  !elem->interior_parent())
367  continue;
368 
369  // get all relevant interior elements
370  std::set<const Elem *> neighbor_set;
371  elem->find_interior_neighbors(neighbor_set);
372 
373  std::set<const Elem *>::iterator n_it = neighbor_set.begin();
374  for (; n_it != neighbor_set.end(); ++n_it)
375  {
376  // FIXME - non-const versions of the Elem set methods
377  // would be nice
378  const Elem * neighbor = *n_it;
379 
380  const unsigned char neighbor_level =
381  cast_int<unsigned char>(neighbor->level() +
382  ((neighbor->refinement_flag() == Elem::REFINE) ? 1 : 0));
383 
384  const unsigned char neighbor_p_level =
385  cast_int<unsigned char>(neighbor->p_level() +
386  ((neighbor->p_refinement_flag() == Elem::REFINE) ? 1 : 0));
387 
388  if (max_mismatch >= 0)
389  {
390  if ((neighbor_level >
391  elem->level() + max_mismatch) &&
392  (elem->refinement_flag() != Elem::REFINE))
393  {
394  elem->set_refinement_flag(Elem::REFINE);
395  flags_changed = true;
396  }
397 
398  if ((neighbor_p_level >
399  elem->p_level() + max_mismatch) &&
400  (elem->p_refinement_flag() != Elem::REFINE))
401  {
402  elem->set_p_refinement_flag(Elem::REFINE);
403  flags_changed = true;
404  }
405  }
406  } // loop over interior neighbors
407  }
408  }
409 
410  // If flags changed on any processor then they changed globally
411  this->comm().max(flags_changed);
412 
413  return flags_changed;
414 }
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=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 823 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::ancestor(), libMesh::MeshBase::ancestor_elements_begin(), libMesh::MeshBase::ancestor_elements_end(), libMesh::Parallel::any_source, libMesh::Elem::child_ptr(), 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::Elem::n_children(), libMesh::Elem::n_neighbors(), 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::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().

824 {
825  // This function must be run on all processors at once
826  parallel_object_only();
827 
828  // We may need a PointLocator for topological_neighbor() tests
829  // later, which we need to make sure gets constructed on all
830  // processors at once.
831  UniquePtr<PointLocatorBase> point_locator;
832 
833 #ifdef LIBMESH_ENABLE_PERIODIC
834  bool has_periodic_boundaries =
836  libmesh_assert(this->comm().verify(has_periodic_boundaries));
837 
838  if (has_periodic_boundaries)
839  point_locator = _mesh.sub_point_locator();
840 #endif
841 
842  LOG_SCOPE ("make_coarsening_compatible()", "MeshRefinement");
843 
844  // Unless we encounter a specific situation level-one
845  // will be satisfied after executing this loop just once
846  bool level_one_satisfied = true;
847 
848 
849  // Unless we encounter a specific situation we will be compatible
850  // with any selected refinement flags
851  bool compatible_with_refinement = true;
852 
853 
854  // find the maximum h and p levels in the mesh
855  unsigned int max_level = 0;
856  unsigned int max_p_level = 0;
857 
858  {
859  // First we look at all the active level-0 elements. Since it doesn't make
860  // sense to coarsen them we must un-set their coarsen flags if
861  // they are set.
864 
865  for (; el != end_el; ++el)
866  {
867  Elem * elem = *el;
868  max_level = std::max(max_level, elem->level());
869  max_p_level =
870  std::max(max_p_level,
871  static_cast<unsigned int>(elem->p_level()));
872 
873  if ((elem->level() == 0) &&
874  (elem->refinement_flag() == Elem::COARSEN))
876 
877  if ((elem->p_level() == 0) &&
878  (elem->p_refinement_flag() == Elem::COARSEN))
880  }
881  }
882 
883  // Even if there are no refined elements on this processor then
884  // there may still be work for us to do on e.g. ancestor elements.
885  // At the very least we need to be in the loop if a distributed mesh
886  // needs to synchronize data.
887 #if 0
888  if (max_level == 0 && max_p_level == 0)
889  {
890  // But we still have to check with other processors
891  this->comm().min(compatible_with_refinement);
892 
893  return compatible_with_refinement;
894  }
895 #endif
896 
897  // Loop over all the active elements. If an element is marked
898  // for coarsening we better check its neighbors. If ANY of these neighbors
899  // are marked for refinement AND are at the same level then there is a
900  // conflict. By convention refinement wins, so we un-mark the element for
901  // coarsening. Level-one would be violated in this case so we need to re-run
902  // the loop.
904  {
905 
906  repeat:
907  level_one_satisfied = true;
908 
909  do
910  {
911  level_one_satisfied = true;
912 
915 
916  for (; el != end_el; ++el)
917  {
918  Elem * elem = *el;
919  bool my_flag_changed = false;
920 
921  if (elem->refinement_flag() == Elem::COARSEN) // If the element is active and
922  // the coarsen flag is set
923  {
924  const unsigned int my_level = elem->level();
925 
926  for (unsigned int n=0; n<elem->n_neighbors(); n++)
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->level() == my_level) &&
937  (neighbor->refinement_flag() == Elem::REFINE)) // the neighbor is at my level
938  // and wants to be refined
939  {
941  my_flag_changed = true;
942  break;
943  }
944  }
945  else // I have a neighbor and it is not active. That means it has children.
946  { // While it _may_ be possible to coarsen us if all the children of
947  // that element want to be coarsened, it is impossible to know at this
948  // stage. Forget about it for the moment... This can be handled in
949  // two steps.
951  my_flag_changed = true;
952  break;
953  }
954  }
955  }
956  }
957  if (elem->p_refinement_flag() == Elem::COARSEN) // If
958  // the element is active and the order reduction flag is set
959  {
960  const unsigned int my_p_level = elem->p_level();
961 
962  for (unsigned int n=0; n<elem->n_neighbors(); n++)
963  {
964  const Elem * neighbor =
965  topological_neighbor(elem, point_locator.get(), n);
966 
967  if (neighbor != libmesh_nullptr && // I have a
968  neighbor != remote_elem) // neighbor here
969  {
970  if (neighbor->active()) // and it is active
971  {
972  if ((neighbor->p_level() > my_p_level &&
973  neighbor->p_refinement_flag() != Elem::COARSEN)
974  || (neighbor->p_level() == my_p_level &&
975  neighbor->p_refinement_flag() == Elem::REFINE))
976  {
978  my_flag_changed = true;
979  break;
980  }
981  }
982  else // I have a neighbor and it is not active.
983  { // We need to find which of its children
984  // have me as a neighbor, and maintain
985  // level one p compatibility with them.
986  // Because we currently have level one h
987  // compatibility, we don't need to check
988  // grandchildren
989 
990  libmesh_assert(neighbor->has_children());
991  for (unsigned int c=0; c!=neighbor->n_children(); c++)
992  {
993  const Elem * subneighbor = neighbor->child_ptr(c);
994  if (subneighbor != remote_elem &&
995  subneighbor->active() &&
996  has_topological_neighbor(subneighbor, point_locator.get(), elem))
997  if ((subneighbor->p_level() > my_p_level &&
998  subneighbor->p_refinement_flag() != Elem::COARSEN)
999  || (subneighbor->p_level() == my_p_level &&
1000  subneighbor->p_refinement_flag() == Elem::REFINE))
1001  {
1003  my_flag_changed = true;
1004  break;
1005  }
1006  }
1007  if (my_flag_changed)
1008  break;
1009  }
1010  }
1011  }
1012  }
1013 
1014  // If the current element's flag changed, we hadn't
1015  // satisfied the level one rule.
1016  if (my_flag_changed)
1017  level_one_satisfied = false;
1018 
1019  // Additionally, if it has non-local neighbors, and
1020  // we're not in serial, then we'll eventually have to
1021  // return compatible_with_refinement = false, because
1022  // our change has to propagate to neighboring
1023  // processors.
1024  if (my_flag_changed && !_mesh.is_serial())
1025  for (unsigned int n=0; n != elem->n_neighbors(); ++n)
1026  {
1027  Elem * neigh =
1028  topological_neighbor(elem, point_locator.get(), n);
1029 
1030  if (!neigh)
1031  continue;
1032  if (neigh == remote_elem ||
1033  neigh->processor_id() !=
1034  this->processor_id())
1035  {
1036  compatible_with_refinement = false;
1037  break;
1038  }
1039  // FIXME - for non-level one meshes we should
1040  // test all descendants
1041  if (neigh->has_children())
1042  for (unsigned int c=0; c != neigh->n_children(); ++c)
1043  if (neigh->child_ptr(c) == remote_elem ||
1044  neigh->child_ptr(c)->processor_id() !=
1045  this->processor_id())
1046  {
1047  compatible_with_refinement = false;
1048  break;
1049  }
1050  }
1051  }
1052  }
1053  while (!level_one_satisfied);
1054 
1055  } // end if (_face_level_mismatch_limit)
1056 
1057 
1058  // Next we look at all of the ancestor cells.
1059  // If there is a parent cell with all of its children
1060  // wanting to be unrefined then the element is a candidate
1061  // for unrefinement. If all the children don't
1062  // all want to be unrefined then ALL of them need to have their
1063  // unrefinement flags cleared.
1064  for (int level=(max_level); level >= 0; level--)
1065  {
1067  const MeshBase::element_iterator end_el = _mesh.level_elements_end(level);
1068  for (; el != end_el; ++el)
1069  {
1070  Elem * elem = *el;
1071  if (elem->ancestor())
1072  {
1073 
1074  // right now the element hasn't been disqualified
1075  // as a candidate for unrefinement
1076  bool is_a_candidate = true;
1077  bool found_remote_child = false;
1078 
1079  for (unsigned int c=0; c<elem->n_children(); c++)
1080  {
1081  Elem * child = elem->child_ptr(c);
1082  if (child == remote_elem)
1083  found_remote_child = true;
1084  else if ((child->refinement_flag() != Elem::COARSEN) ||
1085  !child->active() )
1086  is_a_candidate = false;
1087  }
1088 
1089  if (!is_a_candidate && !found_remote_child)
1090  {
1092 
1093  for (unsigned int c=0; c<elem->n_children(); c++)
1094  {
1095  Elem * child = elem->child_ptr(c);
1096  if (child == remote_elem)
1097  continue;
1098  if (child->refinement_flag() == Elem::COARSEN)
1099  {
1100  level_one_satisfied = false;
1102  }
1103  }
1104  }
1105  }
1106  }
1107  }
1108 
1109  if (!level_one_satisfied && _face_level_mismatch_limit) goto repeat;
1110 
1111 
1112  // If all the children of a parent are set to be coarsened
1113  // then flag the parent so that they can kill their kids.
1114 
1115  // On a distributed mesh, we won't always be able to determine this
1116  // on parent elements with remote children, even if we own the
1117  // parent, without communication.
1118  //
1119  // We'll first communicate *to* parents' owners when we determine
1120  // they cannot be coarsened, then we'll sync the final refinement
1121  // flag *from* the parents.
1122 
1123  // uncoarsenable_parents[p] live on processor id p
1124  const processor_id_type n_proc = _mesh.n_processors();
1125  const processor_id_type my_proc_id = _mesh.processor_id();
1126  const bool distributed_mesh = !_mesh.is_replicated();
1127 
1128  std::vector<std::vector<dof_id_type> >
1129  uncoarsenable_parents(n_proc);
1130 
1131  MeshBase::element_iterator ancestor_el =
1133  const MeshBase::element_iterator ancestor_el_end =
1135  for (; ancestor_el != ancestor_el_end; ++ancestor_el)
1136  {
1137  Elem * elem = *ancestor_el;
1138 
1139  // Presume all the children are flagged for coarsening and
1140  // then look for a contradiction
1141  bool all_children_flagged_for_coarsening = true;
1142 
1143  for (unsigned int c=0; c<elem->n_children(); c++)
1144  {
1145  Elem * child = elem->child_ptr(c);
1146  if (child != remote_elem &&
1147  child->refinement_flag() != Elem::COARSEN)
1148  {
1149  all_children_flagged_for_coarsening = false;
1150  if (!distributed_mesh)
1151  break;
1152  if (child->processor_id() != elem->processor_id())
1153  {
1154  uncoarsenable_parents[elem->processor_id()].push_back(elem->id());
1155  break;
1156  }
1157  }
1158  }
1159 
1160  if (all_children_flagged_for_coarsening)
1162  else
1164  }
1165 
1166  // If we have a distributed mesh, we might need to sync up
1167  // INACTIVE vs. COARSEN_INACTIVE flags.
1168  if (distributed_mesh)
1169  {
1170  // We'd better still be in sync here
1171  parallel_object_only();
1172 
1174  uncoarsenable_tag = this->comm().get_unique_tag(2718);
1175  std::vector<Parallel::Request> uncoarsenable_push_requests(n_proc-1);
1176 
1177  for (processor_id_type p = 0; p != n_proc; ++p)
1178  {
1179  if (p == my_proc_id)
1180  continue;
1181 
1183  uncoarsenable_push_requests[p - (p > my_proc_id)];
1184 
1185  _mesh.comm().send
1186  (p, uncoarsenable_parents[p], request, uncoarsenable_tag);
1187  }
1188 
1189  for (processor_id_type p = 1; p != n_proc; ++p)
1190  {
1191  std::vector<dof_id_type> my_uncoarsenable_parents;
1192  _mesh.comm().receive
1193  (Parallel::any_source, my_uncoarsenable_parents,
1194  uncoarsenable_tag);
1195 
1196  for (std::vector<dof_id_type>::const_iterator
1197  it = my_uncoarsenable_parents.begin(),
1198  end = my_uncoarsenable_parents.end(); it != end; ++it)
1199  {
1200  Elem & elem = _mesh.elem_ref(*it);
1204  }
1205  }
1206 
1207  Parallel::wait(uncoarsenable_push_requests);
1208 
1212  (this->comm(), _mesh.not_local_elements_begin(),
1214  // We'd like a smaller sync, but this leads to bugs?
1215  // SyncCoarsenInactive(),
1216  hsync);
1217  }
1218 
1219  // If one processor finds an incompatibility, we're globally
1220  // incompatible
1221  this->comm().min(compatible_with_refinement);
1222 
1223  return compatible_with_refinement;
1224 }
bool ancestor() const
Definition: elem.C:1569
virtual element_iterator ancestor_elements_begin()=0
bool has_children() const
Definition: elem.h:2097
Status wait(Request &r)
Definition: parallel.h:561
virtual bool is_serial() const
Definition: mesh_base.h:137
bool active() const
Definition: elem.h:2059
virtual element_iterator not_local_elements_end()=0
virtual element_iterator level_elements_begin(unsigned int level)=0
const unsigned int any_source
Definition: parallel.h:200
unsigned int p_level() const
Definition: elem.h:2224
virtual unsigned int n_neighbors() const
Definition: elem.h:557
virtual bool is_replicated() const
Definition: mesh_base.h:159
processor_id_type n_processors() const
The base class for all geometric element types.
Definition: elem.h:86
virtual element_iterator ancestor_elements_end()=0
uint8_t processor_id_type
Definition: id_types.h:99
MPI_Request request
Definition: parallel.h:167
const class libmesh_nullptr_t libmesh_nullptr
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
IterBase * end
long double max(long double a, double b)
PeriodicBoundaries * _periodic_boundaries
unsigned int max_level(const MeshBase &mesh)
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
const Elem * child_ptr(unsigned int i) const
Definition: elem.h:2247
RefinementState p_refinement_flag() const
Definition: elem.h:2320
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
virtual unsigned int n_children() const =0
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:483
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2190
RefinementState refinement_flag() const
Definition: elem.h:2304
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
virtual element_iterator not_local_elements_begin()=0
dof_id_type id() const
Definition: dof_object.h:624
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:531
MessageTag get_unique_tag(int tagvalue) const
processor_id_type processor_id() const
processor_id_type processor_id() const
Definition: dof_object.h:686
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 795 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(), and refine_elements().

796 {
797  // This function must be run on all processors at once
798  parallel_object_only();
799 
800  LOG_SCOPE ("make_flags_parallel_consistent()", "MeshRefinement");
801 
805  (this->comm(), _mesh.elements_begin(), _mesh.elements_end(), hsync);
806 
810  (this->comm(), _mesh.elements_begin(), _mesh.elements_end(), psync);
811 
812  // If we weren't consistent in both h and p on every processor then
813  // we weren't globally consistent
814  bool parallel_consistent = hsync.parallel_consistent &&
815  psync.parallel_consistent;
816  this->comm().min(parallel_consistent);
817 
818  return parallel_consistent;
819 }
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
virtual element_iterator elements_begin()=0
virtual element_iterator elements_end()=0
RefinementState p_refinement_flag() const
Definition: elem.h:2320
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2304
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
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 1233 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::Elem::child_ptr(), 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_children(), 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().

1234 {
1235  // This function must be run on all processors at once
1236  parallel_object_only();
1237 
1238  // We may need a PointLocator for topological_neighbor() tests
1239  // later, which we need to make sure gets constructed on all
1240  // processors at once.
1241  UniquePtr<PointLocatorBase> point_locator;
1242 
1243 #ifdef LIBMESH_ENABLE_PERIODIC
1244  bool has_periodic_boundaries =
1246  libmesh_assert(this->comm().verify(has_periodic_boundaries));
1247 
1248  if (has_periodic_boundaries)
1249  point_locator = _mesh.sub_point_locator();
1250 #endif
1251 
1252  LOG_SCOPE ("make_refinement_compatible()", "MeshRefinement");
1253 
1254  // Unless we encounter a specific situation we will be compatible
1255  // with any selected coarsening flags
1256  bool compatible_with_coarsening = true;
1257 
1258  // This loop enforces the level-1 rule. We should only
1259  // execute it if the user indeed wants level-1 satisfied!
1261  {
1262  // Unless we encounter a specific situation level-one
1263  // will be satisfied after executing this loop just once
1264  bool level_one_satisfied = true;
1265 
1266  do
1267  {
1268  level_one_satisfied = true;
1269 
1272 
1273  for (; el != end_el; ++el)
1274  {
1275  Elem * elem = *el;
1276  if (elem->refinement_flag() == Elem::REFINE) // If the element is active and the
1277  // h refinement flag is set
1278  {
1279  const unsigned int my_level = elem->level();
1280 
1281  for (unsigned int side=0; side != elem->n_sides(); side++)
1282  {
1283  Elem * neighbor =
1284  topological_neighbor(elem, point_locator.get(), side);
1285 
1286  if (neighbor != libmesh_nullptr && // I have a
1287  neighbor != remote_elem && // neighbor here
1288  neighbor->active()) // and it is active
1289  {
1290  // Case 1: The neighbor is at the same level I am.
1291  // 1a: The neighbor will be refined -> NO PROBLEM
1292  // 1b: The neighbor won't be refined -> NO PROBLEM
1293  // 1c: The neighbor wants to be coarsened -> PROBLEM
1294  if (neighbor->level() == my_level)
1295  {
1296  if (neighbor->refinement_flag() == Elem::COARSEN)
1297  {
1299  if (neighbor->parent())
1301  compatible_with_coarsening = false;
1302  level_one_satisfied = false;
1303  }
1304  }
1305 
1306 
1307  // Case 2: The neighbor is one level lower than I am.
1308  // The neighbor thus MUST be refined to satisfy
1309  // the level-one rule, regardless of whether it
1310  // was originally flagged for refinement. If it
1311  // wasn't flagged already we need to repeat
1312  // this process.
1313  else if ((neighbor->level()+1) == my_level)
1314  {
1315  if (neighbor->refinement_flag() != Elem::REFINE)
1316  {
1317  neighbor->set_refinement_flag(Elem::REFINE);
1318  if (neighbor->parent())
1320  compatible_with_coarsening = false;
1321  level_one_satisfied = false;
1322  }
1323  }
1324 #ifdef DEBUG
1325  // Note that the only other possibility is that the
1326  // neighbor is already refined, in which case it isn't
1327  // active and we should never get here.
1328  else
1329  libmesh_error_msg("ERROR: Neighbor level must be equal or 1 higher than mine.");
1330 #endif
1331  }
1332  }
1333  }
1334  if (elem->p_refinement_flag() == Elem::REFINE) // If the element is active and the
1335  // p refinement flag is set
1336  {
1337  const unsigned int my_p_level = elem->p_level();
1338 
1339  for (unsigned int side=0; side != elem->n_sides(); side++)
1340  {
1341  Elem * neighbor =
1342  topological_neighbor(elem, point_locator.get(), side);
1343 
1344  if (neighbor != libmesh_nullptr && // I have a
1345  neighbor != remote_elem) // neighbor here
1346  {
1347  if (neighbor->active()) // and it is active
1348  {
1349  if (neighbor->p_level() < my_p_level &&
1350  neighbor->p_refinement_flag() != Elem::REFINE)
1351  {
1353  level_one_satisfied = false;
1354  compatible_with_coarsening = false;
1355  }
1356  if (neighbor->p_level() == my_p_level &&
1357  neighbor->p_refinement_flag() == Elem::COARSEN)
1358  {
1360  level_one_satisfied = false;
1361  compatible_with_coarsening = false;
1362  }
1363  }
1364  else // I have an inactive neighbor
1365  {
1366  libmesh_assert(neighbor->has_children());
1367  for (unsigned int c=0; c!=neighbor->n_children(); c++)
1368  {
1369  Elem * subneighbor = neighbor->child_ptr(c);
1370  if (subneighbor == remote_elem)
1371  continue;
1372  if (subneighbor->active() &&
1373  has_topological_neighbor(subneighbor, point_locator.get(), elem))
1374  {
1375  if (subneighbor->p_level() < my_p_level &&
1376  subneighbor->p_refinement_flag() != Elem::REFINE)
1377  {
1378  // We should already be level one
1379  // compatible
1380  libmesh_assert_greater (subneighbor->p_level() + 2u,
1381  my_p_level);
1382  subneighbor->set_p_refinement_flag(Elem::REFINE);
1383  level_one_satisfied = false;
1384  compatible_with_coarsening = false;
1385  }
1386  if (subneighbor->p_level() == my_p_level &&
1387  subneighbor->p_refinement_flag() == Elem::COARSEN)
1388  {
1390  level_one_satisfied = false;
1391  compatible_with_coarsening = false;
1392  }
1393  }
1394  }
1395  }
1396  }
1397  }
1398  }
1399  }
1400  }
1401 
1402  while (!level_one_satisfied);
1403  } // end if (_face_level_mismatch_limit)
1404 
1405  // If we're not compatible on one processor, we're globally not
1406  // compatible
1407  this->comm().min(compatible_with_coarsening);
1408 
1409  return compatible_with_coarsening;
1410 }
bool has_children() const
Definition: elem.h:2097
bool active() const
Definition: elem.h:2059
unsigned int p_level() const
Definition: elem.h:2224
const Elem * parent() const
Definition: elem.h:2148
unsigned short int side
Definition: xdr_io.C:49
The base class for all geometric element types.
Definition: elem.h:86
const class libmesh_nullptr_t libmesh_nullptr
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
unsigned char _face_level_mismatch_limit
const Elem * child_ptr(unsigned int i) const
Definition: elem.h:2247
RefinementState p_refinement_flag() const
Definition: elem.h:2320
virtual unsigned int n_sides() const =0
virtual unsigned int n_children() const =0
bool has_topological_neighbor(const Elem *elem, const PointLocatorBase *point_locator, const Elem *neighbor)
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2190
RefinementState refinement_flag() const
Definition: elem.h:2304
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:531
const RemoteElem * remote_elem
Definition: remote_elem.C:57
unsigned int & libMesh::MeshRefinement::max_h_level ( )
inline

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 882 of file mesh_refinement.h.

References _max_h_level, and _use_member_parameters.

Referenced by get_mesh().

883 {
884  _use_member_parameters = true;
885  return _max_h_level;
886 }
processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
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::DistributedVector< T >::init(), 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::XdrIO::read(), libMesh::CheckpointIO::read_connectivity(), 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(), 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:722
const Parallel::Communicator & _communicator
dof_id_type & libMesh::MeshRefinement::nelem_target ( )
inline

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 894 of file mesh_refinement.h.

References _nelem_target, and _use_member_parameters.

Referenced by get_mesh().

895 {
896  _use_member_parameters = true;
897  return _nelem_target;
898 }
unsigned char & libMesh::MeshRefinement::node_level_mismatch_limit ( )
inline

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 916 of file mesh_refinement.h.

References _node_level_mismatch_limit.

Referenced by get_mesh().

917 {
919 }
unsigned char _node_level_mismatch_limit
MeshRefinement& libMesh::MeshRefinement::operator= ( const MeshRefinement )
private
signed char & libMesh::MeshRefinement::overrefined_boundary_limit ( )
inline

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 921 of file mesh_refinement.h.

References _overrefined_boundary_limit.

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

922 {
924 }
signed char _overrefined_boundary_limit
processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
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::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::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::DistributedVector< T >::init(), libMesh::SystemSubsetBySubdomain::init(), 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::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(), make_coarsening_compatible(), 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::ExodusII_IO_Helper::read_node_num_map(), 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(), libMesh::MeshTools::total_weight(), uniformly_coarsen(), libMesh::Parallel::Packing< Node * >::unpack(), libMesh::Parallel::Packing< Elem * >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), 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::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:720
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 517 of file mesh_refinement.C.

References _coarsen_elements(), _face_level_mismatch_limit, _mesh, _refine_elements(), _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), 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::out, libMesh::MeshBase::prepare_for_use(), libMesh::Elem::refinement_flag(), libMesh::Elem::set_p_refinement_flag(), libMesh::Elem::set_refinement_flag(), test_level_one(), and test_unflagged().

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

518 {
519  // This function must be run on all processors at once
520  parallel_object_only();
521 
522  // We can't yet turn a non-level-one mesh into a level-one mesh
525 
526  // Possibly clean up the refinement flags from
527  // a previous step
529  const MeshBase::element_iterator elem_end = _mesh.elements_end();
530 
531  for ( ; elem_it != elem_end; ++elem_it)
532  {
533  // Pointer to the element
534  Elem * elem = *elem_it;
535 
536  // Set refinement flag to INACTIVE if the
537  // element isn't active
538  if ( !elem->active())
539  {
542  }
543 
544  // This might be left over from the last step
545  if (elem->refinement_flag() == Elem::JUST_REFINED)
547  }
548 
549  // Parallel consistency has to come first, or coarsening
550  // along processor boundaries might occasionally be falsely
551  // prevented
552  bool flags_were_consistent = this->make_flags_parallel_consistent();
553 
554  // In theory, we should be able to remove the above call, which can
555  // be expensive and should be unnecessary. In practice, doing
556  // consistent flagging in parallel is hard, it's impossible to
557  // verify at the library level if it's being done by user code, and
558  // we don't want to abort large parallel runs in opt mode... but we
559  // do want to warn that they should be fixed.
560  if (!flags_were_consistent)
561  {
562  libMesh::out << "Refinement flags were not consistent between processors!\n"
563  << "Correcting and continuing.";
564  }
565 
566  // Smooth refinement and coarsening flags
567  _smooth_flags(true, true);
568 
569  // First coarsen the flagged elements.
570  const bool coarsening_changed_mesh =
571  this->_coarsen_elements ();
572 
573  // First coarsen the flagged elements.
574  // FIXME: test_level_one now tests consistency across periodic
575  // boundaries, which requires a point_locator, which just got
576  // invalidated by _coarsen_elements() and hasn't yet been cleared by
577  // prepare_for_use().
578 
579  // libmesh_assert(this->make_coarsening_compatible());
580  // libmesh_assert(this->make_refinement_compatible());
581 
582  // FIXME: This won't pass unless we add a redundant find_neighbors()
583  // call or replace find_neighbors() with on-the-fly neighbor updating
584  // libmesh_assert(!this->eliminate_unrefined_patches());
585 
586  // We can't contract the mesh ourselves anymore - a System might
587  // need to restrict old coefficient vectors first
588  // _mesh.contract();
589 
590  // First coarsen the flagged elements.
591  // Now refine the flagged elements. This will
592  // take up some space, maybe more than what was freed.
593  const bool refining_changed_mesh =
594  this->_refine_elements();
595 
596  // First coarsen the flagged elements.
597  // Finally, the new mesh needs to be prepared for use
598  if (coarsening_changed_mesh || refining_changed_mesh)
599  {
600 #ifdef DEBUG
602 #endif
603 
604  _mesh.prepare_for_use (/*skip_renumber =*/false);
605 
611  // FIXME: This won't pass unless we add a redundant find_neighbors()
612  // call or replace find_neighbors() with on-the-fly neighbor updating
613  // libmesh_assert(!this->eliminate_unrefined_patches());
614 
615  return true;
616  }
617  else
618  {
624  }
625 
626  // Otherwise there was no change in the mesh,
627  // let the user know. Also, there is no need
628  // to prepare the mesh for use since it did not change.
629  return false;
630 
631 }
virtual void libmesh_assert_valid_parallel_ids() const
Definition: mesh_base.h:948
bool active() const
Definition: elem.h:2059
The base class for all geometric element types.
Definition: elem.h:86
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
libmesh_assert(j)
virtual element_iterator elements_begin()=0
bool test_level_one(bool libmesh_assert_yes=false)
unsigned char _face_level_mismatch_limit
virtual element_iterator elements_end()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Definition: mesh_base.C:173
bool test_unflagged(bool libmesh_assert_yes=false)
RefinementState refinement_flag() const
Definition: elem.h:2304
void _smooth_flags(bool refining, bool coarsening)
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
OStreamProxy out(std::cout)
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 720 of file mesh_refinement.C.

References _face_level_mismatch_limit, _mesh, _refine_elements(), _smooth_flags(), libMesh::Elem::active(), libMesh::Elem::DO_NOTHING, libMesh::MeshBase::elements_begin(), libMesh::MeshBase::elements_end(), 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 libMesh::EquationSystems::reinit(), and libMesh::MeshRefinement::ElementFlagging::~ElementFlagging().

721 {
722  // This function must be run on all processors at once
723  parallel_object_only();
724 
727 
728  // Possibly clean up the refinement flags from
729  // a previous step
731  const MeshBase::element_iterator elem_end = _mesh.elements_end();
732 
733  for ( ; elem_it != elem_end; ++elem_it)
734  {
735  // Pointer to the element
736  Elem * elem = *elem_it;
737 
738  // Set refinement flag to INACTIVE if the
739  // element isn't active
740  if ( !elem->active())
741  {
744  }
745 
746  // This might be left over from the last step
747  if (elem->refinement_flag() == Elem::JUST_REFINED)
749  }
750 
751 
752 
753  // Parallel consistency has to come first, or coarsening
754  // along processor boundaries might occasionally be falsely
755  // prevented
756  bool flags_were_consistent = this->make_flags_parallel_consistent();
757 
758  // In theory, we should be able to remove the above call, which can
759  // be expensive and should be unnecessary. In practice, doing
760  // consistent flagging in parallel is hard, it's impossible to
761  // verify at the library level if it's being done by user code, and
762  // we don't want to abort large parallel runs in opt mode... but we
763  // do want to warn that they should be fixed.
764  libmesh_assert(flags_were_consistent);
765  if (!flags_were_consistent)
766  {
767  libMesh::out << "Refinement flags were not consistent between processors!\n"
768  << "Correcting and continuing.";
769  }
770 
771  // Smooth refinement flags
772  _smooth_flags(true, false);
773 
774  // Now refine the flagged elements. This will
775  // take up some space, maybe more than what was freed.
776  const bool mesh_changed =
777  this->_refine_elements();
778 
782  // FIXME: This won't pass unless we add a redundant find_neighbors()
783  // call or replace find_neighbors() with on-the-fly neighbor updating
784  // libmesh_assert(!this->eliminate_unrefined_patches());
785 
786  // Finally, the new mesh needs to be prepared for use
787  if (mesh_changed)
788  _mesh.prepare_for_use (/*skip_renumber =*/false);
789 
790  return mesh_changed;
791 }
bool active() const
Definition: elem.h:2059
The base class for all geometric element types.
Definition: elem.h:86
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
libmesh_assert(j)
virtual element_iterator elements_begin()=0
bool test_level_one(bool libmesh_assert_yes=false)
unsigned char _face_level_mismatch_limit
virtual element_iterator elements_end()=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Definition: mesh_base.C:173
RefinementState refinement_flag() const
Definition: elem.h:2304
void _smooth_flags(bool refining, bool coarsening)
void set_p_refinement_flag(const RefinementState pflag)
Definition: elem.h:2328
OStreamProxy out(std::cout)
Real & libMesh::MeshRefinement::refine_fraction ( )
inline

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 870 of file mesh_refinement.h.

References _refine_fraction, and _use_member_parameters.

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

871 {
872  _use_member_parameters = true;
873  return _refine_fraction;
874 }
void libMesh::MeshRefinement::set_enforce_mismatch_limit_prior_to_refinement ( bool  enforce)
inline

Set _enforce_mismatch_limit_prior_to_refinement option. Defaults to false.

Deprecated:
Use enforce_mismatch_limit_prior_to_refinement() instead.

Definition at line 937 of file mesh_refinement.h.

References enforce_mismatch_limit_prior_to_refinement().

Referenced by get_mesh().

938 {
939  libmesh_deprecated();
941 }
bool & enforce_mismatch_limit_prior_to_refinement()
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 662 of file mesh_refinement_flagging.C.

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

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

663 {
664  MeshBase::element_iterator elem_it = _mesh.elements_begin();
665  const MeshBase::element_iterator elem_end = _mesh.elements_end();
666 
667  for ( ; elem_it != elem_end; ++elem_it)
668  {
669  if ((*elem_it)->active())
670  {
671  (*elem_it)->set_p_refinement_flag((*elem_it)->refinement_flag());
672  (*elem_it)->set_refinement_flag(Elem::DO_NOTHING);
673  }
674  else
675  {
676  (*elem_it)->set_p_refinement_flag((*elem_it)->refinement_flag());
677  (*elem_it)->set_refinement_flag(Elem::INACTIVE);
678  }
679  }
680 }
virtual element_iterator elements_begin()=0
virtual element_iterator elements_end()=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 378 of file mesh_refinement.C.

References _mesh, _periodic_boundaries, libMesh::Elem::active(), libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::ParallelObject::comm(), libMesh::Elem::level(), libMesh::libmesh_assert(), libmesh_nullptr, libMesh::Parallel::Communicator::max(), libMesh::Elem::n_neighbors(), libMesh::out, libMesh::Elem::p_level(), libMesh::remote_elem, 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().

379 {
380  // This function must be run on all processors at once
381  parallel_object_only();
382 
383  // We may need a PointLocator for topological_neighbor() tests
384  // later, which we need to make sure gets constructed on all
385  // processors at once.
386  UniquePtr<PointLocatorBase> point_locator;
387 
388 #ifdef LIBMESH_ENABLE_PERIODIC
389  bool has_periodic_boundaries =
391  libmesh_assert(this->comm().verify(has_periodic_boundaries));
392 
393  if (has_periodic_boundaries)
394  point_locator = _mesh.sub_point_locator();
395 #endif
396 
399 
400  bool failure = false;
401 
402 #ifndef NDEBUG
403  Elem * failed_elem = libmesh_nullptr;
404  Elem * failed_neighbor = libmesh_nullptr;
405 #endif // !NDEBUG
406 
407  for ( ; elem_it != elem_end && !failure; ++elem_it)
408  {
409  // Pointer to the element
410  Elem * elem = *elem_it;
411 
412  for (unsigned int n=0; n<elem->n_neighbors(); n++)
413  {
414  Elem * neighbor =
415  topological_neighbor(elem, point_locator.get(), n);
416 
417  if (!neighbor || !neighbor->active() ||
418  neighbor == remote_elem)
419  continue;
420 
421  if ((neighbor->level() + 1 < elem->level()) ||
422  (neighbor->p_level() + 1 < elem->p_level()) ||
423  (neighbor->p_level() > elem->p_level() + 1))
424  {
425  failure = true;
426 #ifndef NDEBUG
427  failed_elem = elem;
428  failed_neighbor = neighbor;
429 #endif // !NDEBUG
430  break;
431  }
432  }
433  }
434 
435  // If any processor failed, we failed globally
436  this->comm().max(failure);
437 
438  if (failure)
439  {
440  // We didn't pass the level one test, so libmesh_assert that
441  // we're allowed not to
442 #ifndef NDEBUG
443  if (libmesh_assert_pass)
444  {
445  libMesh::out << "MeshRefinement Level one failure, element: "
446  << *failed_elem
447  << std::endl;
448  libMesh::out << "MeshRefinement Level one failure, neighbor: "
449  << *failed_neighbor
450  << std::endl;
451  }
452 #endif // !NDEBUG
453  libmesh_assert(!libmesh_assert_pass);
454  return false;
455  }
456  return true;
457 }
bool active() const
Definition: elem.h:2059
unsigned int p_level() const
Definition: elem.h:2224
virtual unsigned int n_neighbors() const
Definition: elem.h:557
The base class for all geometric element types.
Definition: elem.h:86
const class libmesh_nullptr_t libmesh_nullptr
PeriodicBoundaries * _periodic_boundaries
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual element_iterator active_local_elements_begin()=0
bool verify(const T &r, const Communicator &comm=Communicator_World)
const Parallel::Communicator & comm() const
unsigned int level() const
Definition: elem.h:2190
OStreamProxy out(std::cout)
Elem * topological_neighbor(Elem *elem, const PointLocatorBase *point_locator, const unsigned int side)
virtual element_iterator active_local_elements_end()=0
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:531
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 461 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), 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().

462 {
463  // This function must be run on all processors at once
464  parallel_object_only();
465 
466  bool found_flag = false;
467 
468  // Search for local flags
471 
472 #ifndef NDEBUG
473  Elem * failed_elem = libmesh_nullptr;
474 #endif
475 
476  for ( ; elem_it != elem_end; ++elem_it)
477  {
478  // Pointer to the element
479  Elem * elem = *elem_it;
480 
481  if (elem->refinement_flag() == Elem::REFINE ||
482  elem->refinement_flag() == Elem::COARSEN ||
483  elem->p_refinement_flag() == Elem::REFINE ||
484  elem->p_refinement_flag() == Elem::COARSEN)
485  {
486  found_flag = true;
487 #ifndef NDEBUG
488  failed_elem = elem;
489 #endif
490  break;
491  }
492  }
493 
494  // If we found a flag on any processor, it counts
495  this->comm().max(found_flag);
496 
497  if (found_flag)
498  {
499 #ifndef NDEBUG
500  if (libmesh_assert_pass)
501  {
502  libMesh::out <<
503  "MeshRefinement test_unflagged failure, element: " <<
504  *failed_elem << std::endl;
505  }
506 #endif
507  // We didn't pass the "elements are unflagged" test,
508  // so libmesh_assert that we're allowed not to
509  libmesh_assert(!libmesh_assert_pass);
510  return false;
511  }
512  return true;
513 }
The base class for all geometric element types.
Definition: elem.h:86
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
virtual element_iterator active_local_elements_begin()=0
RefinementState p_refinement_flag() const
Definition: elem.h:2320
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2304
OStreamProxy out(std::cout)
virtual element_iterator active_local_elements_end()=0
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 1920 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().

1923 {
1924 #ifdef LIBMESH_ENABLE_PERIODIC
1925  if (_periodic_boundaries && !_periodic_boundaries->empty())
1926  {
1927  libmesh_assert(point_locator);
1928  return elem->topological_neighbor(side, _mesh, *point_locator, _periodic_boundaries);
1929  }
1930 #endif
1931  return elem->neighbor_ptr(side);
1932 }
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:1821
const Elem * topological_neighbor(const unsigned int i, const MeshBase &mesh, const PointLocatorBase &point_locator, const PeriodicBoundaries *pb) const
Definition: elem.C:1057
signed char & libMesh::MeshRefinement::underrefined_boundary_limit ( )
inline

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 926 of file mesh_refinement.h.

References _underrefined_boundary_limit.

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

927 {
929 }
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 1821 of file mesh_refinement.C.

References _coarsen_elements(), _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), 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::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().

1822 {
1823  // Coarsen n times
1824  for (unsigned int rstep=0; rstep<n; rstep++)
1825  {
1826  // Clean up the refinement flags
1827  this->clean_refinement_flags();
1828 
1829  // Flag all the active elements for coarsening.
1832 
1833  for ( ; elem_it != elem_end; ++elem_it)
1834  {
1835  (*elem_it)->set_refinement_flag(Elem::COARSEN);
1836  if ((*elem_it)->parent())
1837  (*elem_it)->parent()->set_refinement_flag(Elem::COARSEN_INACTIVE);
1838  }
1839 
1840  // On a distributed mesh, we may have parent elements with
1841  // remote active children. To keep flags consistent, we'll need
1842  // a communication step.
1843  if (!_mesh.is_replicated())
1844  {
1845  const processor_id_type n_proc = _mesh.n_processors();
1846  const processor_id_type my_proc_id = _mesh.processor_id();
1847 
1848  std::vector<std::vector<dof_id_type> >
1849  parents_to_coarsen(n_proc);
1850 
1853 
1854  for ( ; elem_it != elem_end; ++elem_it)
1855  {
1856  const Elem & elem = **elem_it;
1857  if (elem.processor_id() != my_proc_id &&
1859  parents_to_coarsen[elem.processor_id()].push_back(elem.id());
1860  }
1861 
1863  coarsen_tag = this->comm().get_unique_tag(271);
1864  std::vector<Parallel::Request> coarsen_push_requests(n_proc-1);
1865 
1866  for (processor_id_type p = 0; p != n_proc; ++p)
1867  {
1868  if (p == my_proc_id)
1869  continue;
1870 
1872  coarsen_push_requests[p - (p > my_proc_id)];
1873 
1874  _mesh.comm().send
1875  (p, parents_to_coarsen[p], request, coarsen_tag);
1876  }
1877 
1878  for (processor_id_type p = 1; p != n_proc; ++p)
1879  {
1880  std::vector<dof_id_type> my_parents_to_coarsen;
1881  _mesh.comm().receive
1882  (Parallel::any_source, my_parents_to_coarsen,
1883  coarsen_tag);
1884 
1885  for (std::vector<dof_id_type>::const_iterator
1886  it = my_parents_to_coarsen.begin(),
1887  end = my_parents_to_coarsen.end(); it != end; ++it)
1888  {
1889  Elem & elem = _mesh.elem_ref(*it);
1893  }
1894  }
1895 
1896  Parallel::wait(coarsen_push_requests);
1897 
1901  (this->comm(), _mesh.not_local_elements_begin(),
1903  // We'd like a smaller sync, but this leads to bugs?
1904  // SyncCoarsenInactive(),
1905  hsync);
1906  }
1907 
1908  // Coarsen all the elements we just flagged.
1909  this->_coarsen_elements();
1910  }
1911 
1912 
1913  // Finally, the new mesh probably needs to be prepared for use
1914  if (n > 0)
1915  _mesh.prepare_for_use (/*skip_renumber =*/false);
1916 }
virtual element_iterator ancestor_elements_begin()=0
Status wait(Request &r)
Definition: parallel.h:561
virtual element_iterator not_local_elements_end()=0
const unsigned int any_source
Definition: parallel.h:200
virtual bool is_replicated() const
Definition: mesh_base.h:159
processor_id_type n_processors() const
The base class for all geometric element types.
Definition: elem.h:86
virtual element_iterator ancestor_elements_end()=0
uint8_t processor_id_type
Definition: id_types.h:99
MPI_Request request
Definition: parallel.h:167
void set_refinement_flag(const RefinementState rflag)
Definition: elem.h:2312
IterBase * end
libmesh_assert(j)
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Definition: mesh_base.C:173
void send(const unsigned int dest_processor_id, const T &buf, const MessageTag &tag=no_tag) const
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:483
const Parallel::Communicator & comm() const
RefinementState refinement_flag() const
Definition: elem.h:2304
Status receive(const unsigned int dest_processor_id, T &buf, const MessageTag &tag=any_tag) const
virtual element_iterator not_local_elements_begin()=0
dof_id_type id() const
Definition: dof_object.h:624
MessageTag get_unique_tag(int tagvalue) const
processor_id_type processor_id() const
processor_id_type processor_id() const
Definition: dof_object.h:686
void libMesh::MeshRefinement::uniformly_p_coarsen ( unsigned int  n = 1)

Attempts to uniformly p coarsen the mesh n times.

Definition at line 1771 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), and libMesh::Elem::JUST_COARSENED.

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

1772 {
1773  // Coarsen p times
1774  for (unsigned int rstep=0; rstep<n; rstep++)
1775  {
1776  // P coarsen all the active elements
1779 
1780  for ( ; elem_it != elem_end; ++elem_it)
1781  {
1782  if ((*elem_it)->p_level() > 0)
1783  {
1784  (*elem_it)->set_p_level((*elem_it)->p_level()-1);
1785  (*elem_it)->set_p_refinement_flag(Elem::JUST_COARSENED);
1786  }
1787  }
1788  }
1789 }
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
void libMesh::MeshRefinement::uniformly_p_refine ( unsigned int  n = 1)

Uniformly p refines the mesh n times.

Definition at line 1752 of file mesh_refinement.C.

References _mesh, libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), and libMesh::Elem::JUST_REFINED.

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

1753 {
1754  // Refine n times
1755  for (unsigned int rstep=0; rstep<n; rstep++)
1756  {
1757  // P refine all the active elements
1760 
1761  for ( ; elem_it != elem_end; ++elem_it)
1762  {
1763  (*elem_it)->set_p_level((*elem_it)->p_level()+1);
1764  (*elem_it)->set_p_refinement_flag(Elem::JUST_REFINED);
1765  }
1766  }
1767 }
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
void libMesh::MeshRefinement::uniformly_refine ( unsigned int  n = 1)

Uniformly refines the mesh n times.

Definition at line 1793 of file mesh_refinement.C.

References _mesh, _refine_elements(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), clean_refinement_flags(), libMesh::MeshBase::prepare_for_use(), and libMesh::Elem::REFINE.

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

1794 {
1795  // Refine n times
1796  // FIXME - this won't work if n>1 and the mesh
1797  // has already been attached to an equation system
1798  for (unsigned int rstep=0; rstep<n; rstep++)
1799  {
1800  // Clean up the refinement flags
1801  this->clean_refinement_flags();
1802 
1803  // Flag all the active elements for refinement.
1806 
1807  for ( ; elem_it != elem_end; ++elem_it)
1808  (*elem_it)->set_refinement_flag(Elem::REFINE);
1809 
1810  // Refine all the elements we just flagged.
1811  this->_refine_elements();
1812  }
1813 
1814  // Finally, the new mesh probably needs to be prepared for use
1815  if (n > 0)
1816  _mesh.prepare_for_use (/*skip_renumber =*/false);
1817 }
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Definition: mesh_base.C:173
virtual element_iterator active_elements_begin()=0
virtual element_iterator active_elements_end()=0
void libMesh::MeshRefinement::update_nodes_map ( )
private

Updates the _new_nodes_map

Definition at line 371 of file mesh_refinement.C.

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

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

372 {
373  this->_new_nodes_map.init(_mesh);
374 }
void init(MeshBase &)
Definition: topology_map.C:34

Member Data Documentation

Real libMesh::MeshRefinement::_absolute_global_tolerance
private
bool libMesh::MeshRefinement::_coarsen_by_parents
private
Real libMesh::MeshRefinement::_coarsen_threshold
private
unsigned char libMesh::MeshRefinement::_edge_level_mismatch_limit
private

Definition at line 764 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 838 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
dof_id_type libMesh::MeshRefinement::_nelem_target
private

Definition at line 759 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 731 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 765 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 767 of file mesh_refinement.h.

Referenced by _smooth_flags(), and overrefined_boundary_limit().

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

Definition at line 768 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 743 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: