Poster of Linux kernelThe best gift for a Linux geek
PointLocatorList

PointLocatorList

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

NAME

PointLocatorList -  

SYNOPSIS


#include <point_locator_list.h>

Inherits PointLocatorBase.  

Public Member Functions


PointLocatorList (const MeshBase &mesh, const PointLocatorBase *master=NULL)

~PointLocatorList ()

virtual void clear ()

virtual void init ()

virtual const Elem * operator() (const Point &p) const

virtual void enable_out_of_mesh_mode (void)

virtual void disable_out_of_mesh_mode (void)

bool initialized () const
 

Static Public Member Functions


static AutoPtr< PointLocatorBase > build (const PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=NULL)

static std::string get_info ()

static void print_info ()

static unsigned int n_objects ()
 

Protected Types


typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions


void increment_constructor_count (const std::string &name)

void increment_destructor_count (const std::string &name)
 

Protected Attributes


std::vector< std::pair< Point, const Elem * > > * _list

const PointLocatorBase * _master

const MeshBase & _mesh

bool _initialized
 

Static Protected Attributes


static Counts _counts

static Threads::atomic< unsigned int > _n_objects

static Threads::spin_mutex _mutex
 

Detailed Description

This is a point locator. It locates points in space using a list of element centroids: given a mesh this locator returns the element that is closest to the given point in global coordinates. Note that this may yield severe difficulties in case of extremely distorted elements, e.g. infinite elements.

This list version is not efficient, but especially reliable for the case of finding the closest dim-1 element (nearest-surface-element, e.g. used for projecting boundary conditions from a surface mesh onto a volumetric mesh). It should be noted that this class only works when the element list in the associated mesh object is not modified (like refinement etc). Otherwise, the point locator has to be cleared and re-initialized. Use PointLocatorBase::build() to create objects of this type at run time.

Author:

Daniel Dreyer, 2003

Definition at line 67 of file point_locator_list.h.  

Member Typedef Documentation

 

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.

Definition at line 105 of file reference_counter.h.  

Constructor & Destructor Documentation

 

PointLocatorList::PointLocatorList (const MeshBase &mesh, const PointLocatorBase *master = NULL)Constructor. Needs the mesh which holds the elements that should be identified as being close. Optionally takes a master interpolator. This master helps in saving memory by simply only setting up one list for all point locators. Only the master locator holds a list, the others simply use the master's list.

Definition at line 36 of file point_locator_list.C.

References init().

                                                                    :
  PointLocatorBase (mesh,master),
  _list            (NULL)
{
  // This code will only work if your mesh is the Voroni mesh of it's
  // own elements' centroids.  If your mesh is that regular you might
  // as well hand-code an O(1) algorithm for locating points within
  // it. - RHS
  libmesh_experimental();

  this->init();
}
 

PointLocatorList::~PointLocatorList ()Destructor.

Definition at line 53 of file point_locator_list.C.

References clear().

{
  this->clear ();
}
 

Member Function Documentation

 

AutoPtr< PointLocatorBase > PointLocatorBase::build (const PointLocatorTypet, const MeshBase &mesh, const PointLocatorBase *master = NULL) [static, inherited]Builds an PointLocator for the mesh mesh. Optionally takes a master PointLocator to save memory. An AutoPtr<PointLocatorBase> is returned to prevent memory leak. This way the user need not remember to delete the object.

Definition at line 55 of file point_locator_base.C.

References MeshEnums::LIST, and MeshEnums::TREE.

Referenced by MeshBase::point_locator().

{
  switch (t)
    {
    case TREE:
      {
        AutoPtr<PointLocatorBase> ap(new PointLocatorTree(mesh,
                                                          master));
        return ap;
      }

    case LIST:
      {
        AutoPtr<PointLocatorBase> ap(new PointLocatorList(mesh,
                                                          master));
        return ap;
      }

    default:
      {
        std::cerr << 'ERROR: Bad PointLocatorType = ' << t << std::endl;
        libmesh_error();
      }
    }

  libmesh_error();
  AutoPtr<PointLocatorBase> ap(NULL);
  return ap;
}
 

void PointLocatorList::clear () [virtual]Clears the locator. Overloaded from base class. This method frees dynamic memory using 'delete'.

Implements PointLocatorBase.

Definition at line 61 of file point_locator_list.C.

References _list, and PointLocatorBase::_master.

Referenced by ~PointLocatorList().

{
  // only delete the list when we are the master
  if (this->_list != NULL)
    {
      if (this->_master == NULL)
        {
          // we own the list
          this->_list->clear();
          delete this->_list;
        }
      else
          // someone else owns and therefore deletes the list
          this->_list = NULL;
    }
}
 

void PointLocatorList::disable_out_of_mesh_mode (void) [virtual]Disables out-of-mesh mode (default). If asked to find a point that is contained in no mesh at all, the point locator will now crash.

Implements PointLocatorBase.

Definition at line 208 of file point_locator_list.C.

{
  /* This functionality is not yet implemented for PointLocatorList.  */
  libmesh_error();
}
 

void PointLocatorList::enable_out_of_mesh_mode (void) [virtual]Enables out-of-mesh mode. In this mode, if asked to find a point that is contained in no mesh at all, the point locator will return a NULL pointer instead of crashing. Per default, this mode is off.

Implements PointLocatorBase.

Definition at line 202 of file point_locator_list.C.

{
  /* This functionality is not yet implemented for PointLocatorList.  */
  libmesh_error();
}
 

std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.

Definition at line 45 of file reference_counter.C.

References ReferenceCounter::_counts, and Quality::name().

Referenced by ReferenceCounter::print_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)

  std::ostringstream out;
  
  out << '
      << ' ---------------------------------------------------------------------------- 
      << '| Reference count information                                                |
      << ' ---------------------------------------------------------------------------- ;
  
  for (Counts::iterator it = _counts.begin();
       it != _counts.end(); ++it)
    {
      const std::string name(it->first);
      const unsigned int creations    = it->second.first;
      const unsigned int destructions = it->second.second;

      out << '| ' << name << ' reference count information:
          << '|  Creations:    ' << creations    << '
          << '|  Destructions: ' << destructions << ';
    }
  
  out << ' ---------------------------------------------------------------------------- ;

  return out.str();

#else

  return '';
  
#endif
}
 

void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected, inherited]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.

Definition at line 149 of file reference_counter.h.

References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.first++;
}
 

void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected, inherited]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.

Definition at line 167 of file reference_counter.h.

References ReferenceCounter::_counts, Quality::name(), and Threads::spin_mtx.

Referenced by ReferenceCountedObject< Value >::~ReferenceCountedObject().

{
  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
  std::pair<unsigned int, unsigned int>& p = _counts[name];

  p.second++;
}
 

void PointLocatorList::init () [virtual]Initializes the locator, so that the operator() methods can be used. Overloaded from base class. This method allocates dynamic memory using 'new'.

Implements PointLocatorBase.

Definition at line 82 of file point_locator_list.C.

References PointLocatorBase::_initialized, _list, PointLocatorBase::_master, PointLocatorBase::_mesh, MeshBase::active_elements_begin(), MeshBase::active_elements_end(), PointLocatorBase::initialized(), and MeshBase::n_active_elem().

Referenced by PointLocatorList().

{
  libmesh_assert (this->_list == NULL); 

  if (this->_initialized)
    {
      std::cerr << 'ERROR: Already initialized!  Will ignore this call...'
                << std::endl;
    }

  else

    {

      if (this->_master == NULL)
        {
          // We are the master, so we have to build the list.
          // First create it, then get a handy reference, and
          // then try to speed up by reserving space...
          this->_list = new std::vector<std::pair<Point, const Elem *> >;
          std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);

          my_list.clear();
          my_list.reserve(this->_mesh.n_active_elem());

          // fill our list with the centroids and element
          // pointers of the mesh.  For this use the handy
          // element iterators.
//        const_active_elem_iterator       el (this->_mesh.elements_begin());
//        const const_active_elem_iterator end(this->_mesh.elements_end()); 

          MeshBase::const_element_iterator       el  = _mesh.active_elements_begin();
          const MeshBase::const_element_iterator end = _mesh.active_elements_end(); 

          for (; el!=end; ++el)
            my_list.push_back(std::make_pair((*el)->centroid(), *el));
        }

      else
          
        {
          // We are _not_ the master.  Let our _list point to
          // the master's list.  But for this we first transform
          // the master in a state for which we are friends
          // (this should also beware of a bad master pointer?).
          // And make sure the master @e has a list!
          const PointLocatorList* my_master =
            libmesh_cast_ptr<const PointLocatorList*>(this->_master);

          if (my_master->initialized())
            this->_list = my_master->_list;
          else
            {
              std::cerr << 'ERROR: Initialize master first, then servants!'
                        << std::endl;
              libmesh_error();
            }
        }

    }


  // ready for take-off
  this->_initialized = true;
}
 

bool PointLocatorBase::initialized () const [inline, inherited]Returns:

true when this object is properly initialized and ready for use, false otherwise.

Definition at line 150 of file point_locator_base.h.

References PointLocatorBase::_initialized.

Referenced by PointLocatorTree::init(), and init().

{
  return (this->_initialized);
}
 

static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 76 of file reference_counter.h.

References ReferenceCounter::_n_objects.

Referenced by System::read_serialized_blocked_dof_objects(), and System::write_serialized_blocked_dof_objects().

  { return _n_objects; }
 

const Elem * PointLocatorList::operator() (const Point &p) const [virtual]Locates the element in which the point with global coordinates p is located. Overloaded from base class.

Implements PointLocatorBase.

Definition at line 152 of file point_locator_list.C.

References PointLocatorBase::_initialized, _list, Elem::active(), and TypeVector< T >::size_sq().

{
  libmesh_assert (this->_initialized);

  // Ask the list.  This is quite expensive, since
  // we loop through the whole list to try to find
  // the @e nearest element.
  // However, there is not much else to do: when
  // we would use bounding boxes like in a tree,
  // it may happen that a surface element is just
  // in plane with a bounding box face, and quite
  // close to it.  But when a point comes, this
  // point may belong to the bounding box (where the
  // coplanar element does @e not belong to).  Then
  // we would search through the elements in this 
  // bounding box, while the other bounding box'es
  // element is closer, but we simply don't consider
  // it!
  //
  // We _can_, however, use size_sq() instead of size()
  // here to avoid repeated calls to std::sqrt(), which is
  // pretty expensive.
  {
    std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);

    Real               last_distance_sq = Point(my_list[0].first -p).size_sq();
    const Elem *       last_elem        = NULL;
    const unsigned int max_index        = my_list.size();


    for (unsigned int n=1; n<max_index; n++)
      {
        const Real current_distance_sq = Point(my_list[n].first -p).size_sq();

        if (current_distance_sq < last_distance_sq)
          {
            last_distance_sq = current_distance_sq;
            last_elem        = my_list[n].second;
          }
      }

    // the element should be active
    libmesh_assert (last_elem->active());

    // return the element
    return (last_elem);
  }

}
 

void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.

Definition at line 83 of file reference_counter.C.

References ReferenceCounter::get_info().

{
#if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
  
  std::cout << ReferenceCounter::get_info();
  
#endif
}
 

Member Data Documentation

 

ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.

Definition at line 110 of file reference_counter.h.

Referenced by ReferenceCounter::get_info(), ReferenceCounter::increment_constructor_count(), and ReferenceCounter::increment_destructor_count().  

bool PointLocatorBase::_initialized [protected, inherited]true when properly initialized, false otherwise.

Definition at line 142 of file point_locator_base.h.

Referenced by PointLocatorTree::init(), init(), PointLocatorBase::initialized(), PointLocatorTree::operator()(), and operator()().  

std::vector<std::pair<Point, const Elem *> >* PointLocatorList::_list [protected]Pointer to the list of element centroids. Only the master has such a list. For servants, this pointer points to the list of the master. Note that it's not a std::list as the name might suggest, but a std::vector.

Definition at line 133 of file point_locator_list.h.

Referenced by clear(), init(), and operator()().  

const PointLocatorBase* PointLocatorBase::_master [protected, inherited]Const pointer to our master, initialized to NULL if none given. When using multiple PointLocators, one can be assigned master and be in charge of something that all can have access to.

Definition at line 132 of file point_locator_base.h.

Referenced by PointLocatorTree::clear(), clear(), PointLocatorTree::init(), and init().  

const MeshBase& PointLocatorBase::_mesh [protected, inherited]constant reference to the mesh in which the point is looked for.

Definition at line 137 of file point_locator_base.h.

Referenced by PointLocatorTree::enable_out_of_mesh_mode(), PointLocatorTree::init(), init(), and PointLocatorTree::operator()().  

Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.

Definition at line 123 of file reference_counter.h.  

Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.

Definition at line 118 of file reference_counter.h.

Referenced by ReferenceCounter::n_objects(), ReferenceCounter::ReferenceCounter(), and ReferenceCounter::~ReferenceCounter().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Static Public Member Functions
Protected Types
Protected Member Functions
Protected Attributes
Static Protected Attributes
Detailed Description
Member Typedef Documentation
typedef std::map<std::string, std::pair<unsigned int, unsigned int> > ReferenceCounter::Counts [protected, inherited]Data structure to log the information. The log is identified by the class name.
Constructor & Destructor Documentation
PointLocatorList::PointLocatorList (const MeshBase &mesh, const PointLocatorBase *master = NULL)Constructor. Needs the mesh which holds the elements that should be identified as being close. Optionally takes a master interpolator. This master helps in saving memory by simply only setting up one list for all point locators. Only the master locator holds a list, the others simply use the master's list.
PointLocatorList::~PointLocatorList ()Destructor.
Member Function Documentation
AutoPtr< PointLocatorBase > PointLocatorBase::build (const PointLocatorTypet, const MeshBase &mesh, const PointLocatorBase *master = NULL) [static, inherited]Builds an PointLocator for the mesh mesh. Optionally takes a master PointLocator to save memory. An AutoPtr<PointLocatorBase> is returned to prevent memory leak. This way the user need not remember to delete the object.
void PointLocatorList::clear () [virtual]Clears the locator. Overloaded from base class. This method frees dynamic memory using 'delete'.
void PointLocatorList::disable_out_of_mesh_mode (void) [virtual]Disables out-of-mesh mode (default). If asked to find a point that is contained in no mesh at all, the point locator will now crash.
void PointLocatorList::enable_out_of_mesh_mode (void) [virtual]Enables out-of-mesh mode. In this mode, if asked to find a point that is contained in no mesh at all, the point locator will return a NULL pointer instead of crashing. Per default, this mode is off.
std::string ReferenceCounter::get_info () [static, inherited]Gets a string containing the reference information.
void ReferenceCounter::increment_constructor_count (const std::string &name) [inline, protected, inherited]Increments the construction counter. Should be called in the constructor of any derived class that will be reference counted.
void ReferenceCounter::increment_destructor_count (const std::string &name) [inline, protected, inherited]Increments the destruction counter. Should be called in the destructor of any derived class that will be reference counted.
void PointLocatorList::init () [virtual]Initializes the locator, so that the operator() methods can be used. Overloaded from base class. This method allocates dynamic memory using 'new'.
bool PointLocatorBase::initialized () const [inline, inherited]Returns:
static unsigned int ReferenceCounter::n_objects () [inline, static, inherited]Prints the number of outstanding (created, but not yet destroyed) objects.
const Elem * PointLocatorList::operator() (const Point &p) const [virtual]Locates the element in which the point with global coordinates p is located. Overloaded from base class.
void ReferenceCounter::print_info () [static, inherited]Prints the reference information to std::cout.
Member Data Documentation
ReferenceCounter::Counts ReferenceCounter::_counts [static, protected, inherited]Actually holds the data.
bool PointLocatorBase::_initialized [protected, inherited]true when properly initialized, false otherwise.
std::vector<std::pair<Point, const Elem *> >* PointLocatorList::_list [protected]Pointer to the list of element centroids. Only the master has such a list. For servants, this pointer points to the list of the master. Note that it's not a std::list as the name might suggest, but a std::vector.
const PointLocatorBase* PointLocatorBase::_master [protected, inherited]Const pointer to our master, initialized to NULL if none given. When using multiple PointLocators, one can be assigned master and be in charge of something that all can have access to.
const MeshBase& PointLocatorBase::_mesh [protected, inherited]constant reference to the mesh in which the point is looked for.
Threads::spin_mutex ReferenceCounter::_mutex [static, protected, inherited]Mutual exclusion object to enable thread-safe reference counting.
Threads::atomic< unsigned int > ReferenceCounter::_n_objects [static, protected, inherited]The number of objects. Print the reference count information when the number returns to 0.
Author

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