Poster of Linux kernelThe best gift for a Linux geek
Patch

Patch

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

Patch -  

SYNOPSIS


#include <patch.h>  

Public Types


typedef void(Patch::* PMF )()
 

Public Member Functions


Patch ()

~Patch ()

void add_face_neighbors ()

void add_local_face_neighbors ()

void add_point_neighbors ()

void add_local_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)
 

Detailed Description

This class implements useful utility functions for a patch of elements

Author:

Roy H. Stogner, 2007. based on code by Varis Carey, Benjamin S. Kirk, 2004.

Definition at line 43 of file patch.h.  

Member Typedef Documentation

 

typedef void(Patch::* Patch::PMF)()Pointer to Member Function typedef

Definition at line 84 of file patch.h.  

Constructor & Destructor Documentation

 

Patch::Patch () [inline]Constructor.

Definition at line 50 of file patch.h.

{}
 

Patch::~Patch () [inline]Destructor.

Definition at line 55 of file patch.h.

{}
 

Member Function Documentation

 

void 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 75 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());
}
 

void Patch::add_local_face_neighbors ()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 86 of file patch.C.

References find_face_neighbors(), libMesh::processor_id(), and 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 = new_neighbors.end();

  for (; it != end; ++it)
    {
      const Elem* neighbor = *it;
      if (neighbor->processor_id() ==
          libMesh::processor_id()) // ... if the neighbor belongs to this processor
        this->insert (neighbor);   // ... then add it to the patch
    }
}
 

void Patch::add_local_point_neighbors ()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 137 of file patch.C.

References find_point_neighbors(), libMesh::processor_id(), and 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 = new_neighbors.end();

  for (; it != end; ++it)
    {
      const Elem* neighbor = *it;
      if (neighbor->processor_id() ==
          libMesh::processor_id()) // ... if the neighbor belongs to this processor
        this->insert (neighbor);   // ... then add it to the patch
    }
}
 

void 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 126 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());
}
 

void Patch::build_around_element (const Elem *elem, const unsigned inttarget_patch_size = 10, PMFpatchtype = &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 157 of file patch.C.

References Elem::active(), add_local_face_neighbors(), add_local_point_neighbors(), libMesh::processor_id(), and DofObject::processor_id().

Referenced by PatchRecoveryErrorEstimator::EstimateError::operator()().

{
  
  // Make sure we are building a patch for an active element.
  libmesh_assert (e0 != NULL);
  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() == libMesh::processor_id());
  
  // 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 unsigned int 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)
        {
//        std::cerr << 'WARNING: stagnant patch of '
//                  << this->size() << ' elements.'
//                  << std::endl
//                  << 'Does your target patch size exceed the number of elements in the mesh?'
//                  << 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 = this->end();
    
    for (; it != end; ++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 (elem->processor_id() == libMesh::processor_id());
      }
  }
#endif

}
 

void 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 36 of file patch.C.

References Elem::active(), Elem::active_family_tree_by_neighbor(), Elem::n_sides(), and Elem::neighbor().

Referenced by add_face_neighbors(), and add_local_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 = this->end();

  for (; it != end; ++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 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 106 of file patch.C.

References Elem::find_point_neighbors().

Referenced by add_local_point_neighbors(), and add_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 = this->end();

  for (; it != end; ++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());
    }
}

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Types
Public Member Functions
Protected Member Functions
Detailed Description
Member Typedef Documentation
typedef void(Patch::* Patch::PMF)()Pointer to Member Function typedef
Constructor & Destructor Documentation
Patch::Patch () [inline]Constructor.
Patch::~Patch () [inline]Destructor.
Member Function Documentation
void Patch::add_face_neighbors ()This function finds all elements which touch the current patch at a face, and adds them to the patch.
void Patch::add_local_face_neighbors ()This function finds all elements on the current processor which touch the current patch at a face, and adds them to the patch.
void Patch::add_local_point_neighbors ()This function finds all elements on the current processor which touch the current patch at any point, and adds them to the patch.
void Patch::add_point_neighbors ()This function finds all elements which touch the current patch at any point, and adds them to the patch.
void Patch::build_around_element (const Elem *elem, const unsigned inttarget_patch_size = 10, PMFpatchtype = &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.
void Patch::find_face_neighbors (std::set< const Elem * > &neighbor_set) [protected]This function finds all elements which touch the current patch at a face
void Patch::find_point_neighbors (std::set< const Elem * > &neighbor_set) [protected]This function finds all elements which touch the current patch at any point
Author

This document was created by man2html, using the manual pages.
Time: 21:52:04 GMT, April 16, 2011