$extrastylesheet
#include <patch.h>
Public Types | |
| typedef void(Patch::* | PMF )() |
Public Member Functions | |
| Patch (const processor_id_type my_procid=static_cast< processor_id_type >(-1)) | |
| ~Patch () | |
| void | add_face_neighbors () |
| void | add_local_face_neighbors () |
| void | add_semilocal_face_neighbors () |
| void | add_point_neighbors () |
| void | add_local_point_neighbors () |
| void | add_semilocal_point_neighbors () |
| void | build_around_element (const Elem *elem, const unsigned int target_patch_size=10, PMF patchtype=&Patch::add_local_face_neighbors) |
Protected Member Functions | |
| void | find_face_neighbors (std::set< const Elem * > &neighbor_set) |
| void | find_point_neighbors (std::set< const Elem * > &neighbor_set) |
Protected Attributes | |
| const processor_id_type | _my_procid |
This class implements useful utility functions for a patch of elements
| typedef void(Patch::* libMesh::Patch::PMF)() |
| libMesh::Patch::Patch | ( | const processor_id_type | my_procid = static_cast<processor_id_type>(-1) | ) | [inline] |
Constructor. Requires the processor ID to be interpreted as "local".
Definition at line 54 of file patch.h.
:
_my_procid(my_procid)
{}
| libMesh::Patch::~Patch | ( | ) | [inline] |
| void libMesh::Patch::add_face_neighbors | ( | ) |
This function finds all elements which touch the current patch at a face, and adds them to the patch.
Definition at line 77 of file patch.C.
References find_face_neighbors().
{
std::set<const Elem *> new_neighbors;
this->find_face_neighbors(new_neighbors);
this->insert(new_neighbors.begin(), new_neighbors.end());
}
This function finds all elements on the current processor which touch the current patch at a face, and adds them to the patch.
Definition at line 88 of file patch.C.
References _my_procid, find_face_neighbors(), and libMesh::DofObject::processor_id().
Referenced by build_around_element().
{
std::set<const Elem *> new_neighbors;
this->find_face_neighbors(new_neighbors);
std::set<const Elem*>::const_iterator it = new_neighbors.begin();
const std::set<const Elem*>::const_iterator end_it = new_neighbors.end();
for (; it != end_it; ++it)
{
const Elem* neighbor = *it;
if (neighbor->processor_id() ==
_my_procid) // ... if the neighbor belongs to this processor
this->insert (neighbor); // ... then add it to the patch
}
}
This function finds all elements on the current processor which touch the current patch at any point, and adds them to the patch.
Definition at line 158 of file patch.C.
References _my_procid, find_point_neighbors(), and libMesh::DofObject::processor_id().
Referenced by build_around_element().
{
std::set<const Elem *> new_neighbors;
this->find_point_neighbors(new_neighbors);
std::set<const Elem*>::const_iterator it = new_neighbors.begin();
const std::set<const Elem*>::const_iterator end_it = new_neighbors.end();
for (; it != end_it; ++it)
{
const Elem* neighbor = *it;
if (neighbor->processor_id() ==
_my_procid) // ... if the neighbor belongs to this processor
this->insert (neighbor); // ... then add it to the patch
}
}
| void libMesh::Patch::add_point_neighbors | ( | ) |
This function finds all elements which touch the current patch at any point, and adds them to the patch.
Definition at line 147 of file patch.C.
References find_point_neighbors().
{
std::set<const Elem *> new_neighbors;
this->find_point_neighbors(new_neighbors);
this->insert(new_neighbors.begin(), new_neighbors.end());
}
This function finds all elements which touch the current patch at a face and which touch one of our processor's elements at any point, and it adds them to the patch.
Definition at line 108 of file patch.C.
References _my_procid, find_face_neighbors(), and libMesh::Elem::is_semilocal().
{
std::set<const Elem *> new_neighbors;
this->find_face_neighbors(new_neighbors);
std::set<const Elem*>::const_iterator it = new_neighbors.begin();
const std::set<const Elem*>::const_iterator end_it = new_neighbors.end();
for (; it != end_it; ++it)
{
const Elem* neighbor = *it;
if (neighbor->is_semilocal(_my_procid))
this->insert (neighbor);
}
}
This function finds all elements which touch the current patch at any point and which touch one of our processor's elements at any point, and it adds them to the patch.
Definition at line 178 of file patch.C.
References _my_procid, find_point_neighbors(), and libMesh::Elem::is_semilocal().
{
std::set<const Elem *> new_neighbors;
this->find_point_neighbors(new_neighbors);
std::set<const Elem*>::const_iterator it = new_neighbors.begin();
const std::set<const Elem*>::const_iterator end_it = new_neighbors.end();
for (; it != end_it; ++it)
{
const Elem* neighbor = *it;
if (neighbor->is_semilocal(_my_procid))
this->insert (neighbor);
}
}
| void libMesh::Patch::build_around_element | ( | const Elem * | elem, |
| const unsigned int | target_patch_size = 10, |
||
| PMF | patchtype = &Patch::add_local_face_neighbors |
||
| ) |
Erases any elements in the current patch, then builds a new patch containing element elem by repeated addition of neighbors on the current processor. This procedure is repeated until the number of elements meets or exceeds target_patch_size, or until the patch has no more local neighbors.
Definition at line 197 of file patch.C.
References _my_procid, libMesh::Elem::active(), add_local_face_neighbors(), add_local_point_neighbors(), end, libMesh::err, libMesh::libmesh_assert(), and libMesh::DofObject::processor_id().
Referenced by libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), and libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()().
{
// Make sure we are building a patch for an active element.
libmesh_assert(e0);
libmesh_assert (e0->active());
// Make sure we are either starting with a local element or
// requesting a nonlocal patch
libmesh_assert ((patchtype != &Patch::add_local_face_neighbors &&
patchtype != &Patch::add_local_point_neighbors) ||
e0->processor_id() == _my_procid);
// First clear the current set, then add the element of interest.
this->clear();
this->insert (e0);
// Repeatedly add the neighbors of the elements in the patch until
// the target patch size is met
while (this->size() < target_patch_size)
{
// It is possible that the target patch size is larger than the number
// of elements that can be added to the patch. Since we don't
// have access to the Mesh object here, the only way we can
// detect this case is by detecting a "stagnant patch," i.e. a
// patch whose size does not increase after adding face neighbors
const std::size_t old_patch_size = this->size();
// We profile the patch-extending functions separately
(this->*patchtype)();
// Check for a "stagnant" patch
if (this->size() == old_patch_size)
{
libmesh_do_once(libMesh::err <<
"WARNING: stagnant patch of " << this->size() << " elements."
<< std::endl <<
"Does the target patch size exceed the number of local elements?"
<< std::endl;
libmesh_here(););
break;
}
} // end while loop
// make sure all the elements in the patch are active and local
// if we are in debug mode
#ifdef DEBUG
{
std::set<const Elem*>::const_iterator it = this->begin();
const std::set<const Elem*>::const_iterator end_it = this->end();
for (; it != end_it; ++it)
{
// Convenience. Keep the syntax simple.
const Elem* elem = *it;
libmesh_assert (elem->active());
if ((patchtype == &Patch::add_local_face_neighbors ||
patchtype == &Patch::add_local_point_neighbors))
libmesh_assert_equal_to (elem->processor_id(), _my_procid);
}
}
#endif
}
| void libMesh::Patch::find_face_neighbors | ( | std::set< const Elem * > & | neighbor_set | ) | [protected] |
This function finds all elements which touch the current patch at a face
Definition at line 38 of file patch.C.
References libMesh::Elem::active(), libMesh::Elem::active_family_tree_by_neighbor(), end, libMesh::Elem::n_sides(), and libMesh::Elem::neighbor().
Referenced by add_face_neighbors(), add_local_face_neighbors(), and add_semilocal_face_neighbors().
{
// Loop over all the elements in the patch
std::set<const Elem*>::const_iterator it = this->begin();
const std::set<const Elem*>::const_iterator end_it = this->end();
for (; it != end_it; ++it)
{
const Elem* elem = *it;
for (unsigned int s=0; s<elem->n_sides(); s++)
if (elem->neighbor(s) != NULL) // we have a neighbor on this side
{
const Elem* neighbor = elem->neighbor(s);
#ifdef LIBMESH_ENABLE_AMR
if (!neighbor->active()) // the neighbor is *not* active,
{ // so add *all* neighboring
// active children to the patch
std::vector<const Elem*> active_neighbor_children;
neighbor->active_family_tree_by_neighbor
(active_neighbor_children, elem);
std::vector<const Elem*>::const_iterator
child_it = active_neighbor_children.begin();
const std::vector<const Elem*>::const_iterator
child_end = active_neighbor_children.end();
for (; child_it != child_end; ++child_it)
new_neighbors.insert(*child_it);
}
else
#endif // #ifdef LIBMESH_ENABLE_AMR
new_neighbors.insert (neighbor); // add active neighbors
}
}
}
| void libMesh::Patch::find_point_neighbors | ( | std::set< const Elem * > & | neighbor_set | ) | [protected] |
This function finds all elements which touch the current patch at any point
Definition at line 127 of file patch.C.
References end, and libMesh::Elem::find_point_neighbors().
Referenced by add_local_point_neighbors(), add_point_neighbors(), and add_semilocal_point_neighbors().
{
// Loop over all the elements in the patch
std::set<const Elem*>::const_iterator it = this->begin();
const std::set<const Elem*>::const_iterator end_it = this->end();
for (; it != end_it; ++it)
{
std::set<const Elem*> elem_point_neighbors;
const Elem* elem = *it;
elem->find_point_neighbors(elem_point_neighbors);
new_neighbors.insert(elem_point_neighbors.begin(),
elem_point_neighbors.end());
}
}
const processor_id_type libMesh::Patch::_my_procid [protected] |
Definition at line 131 of file patch.h.
Referenced by add_local_face_neighbors(), add_local_point_neighbors(), add_semilocal_face_neighbors(), add_semilocal_point_neighbors(), and build_around_element().