Poster of Linux kernelThe best gift for a Linux geek
PointLocatorTree

PointLocatorTree

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

NAME

PointLocatorTree -  

SYNOPSIS


#include <point_locator_tree.h>

Inherits PointLocatorBase.  

Public Member Functions


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

PointLocatorTree (const MeshBase &mesh, const Trees::BuildType build_type, const PointLocatorBase *master=NULL)

~PointLocatorTree ()

virtual void clear ()

void init (const Trees::BuildType build_type)

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


TreeBase * _tree

const Elem * _element

bool _out_of_mesh_mode

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 tree: given a mesh they return the element and local coordinates for a given point in global coordinates. Use PointLocatorBase::build() to create objects of this type at run time.

Author:

Daniel Dreyer, 2003

Definition at line 52 of file point_locator_tree.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

 

PointLocatorTree::PointLocatorTree (const MeshBase &mesh, const PointLocatorBase *master = NULL)Constructor. Needs the mesh in which the points should be located. Optionally takes a master interpolator. This master helps in saving memory by reducing the number of trees in use. Only the master locator holds a tree, the others simply use the master's tree.

Definition at line 35 of file point_locator_tree.C.

References init(), and Trees::NODES.

                                                                    :
  PointLocatorBase (mesh,master),
  _tree            (NULL),
  _element         (NULL),
  _out_of_mesh_mode(false)
{
  this->init(Trees::NODES);
}
 

PointLocatorTree::PointLocatorTree (const MeshBase &mesh, const Trees::BuildTypebuild_type, const PointLocatorBase *master = NULL)Constructor. Needs the mesh in which the points should be located. Allows the user to specify the method to use when building the tree. Optionally takes a master interpolator. This master helps in saving memory by reducing the number of trees in use. Only the master locator holds a tree, the others simply use the master's tree. Allows the user to specify the build type.

Definition at line 48 of file point_locator_tree.C.

References init().

                                                                    :
  PointLocatorBase (mesh,master),
  _tree            (NULL),
  _element         (NULL),
  _out_of_mesh_mode(false)
{
  this->init(build_type);
}
 

PointLocatorTree::~PointLocatorTree ()Destructor.

Definition at line 62 of file point_locator_tree.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 PointLocatorTree::clear () [virtual]Clears the locator. This function frees dynamic memory with 'delete'.

Implements PointLocatorBase.

Definition at line 70 of file point_locator_tree.C.

References PointLocatorBase::_master, and _tree.

Referenced by ~PointLocatorTree().

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

void PointLocatorTree::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 246 of file point_locator_tree.C.

References _out_of_mesh_mode.

{
  _out_of_mesh_mode = false;
}
 

void PointLocatorTree::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 221 of file point_locator_tree.C.

References PointLocatorBase::_mesh, _out_of_mesh_mode, MeshBase::active_elements_begin(), and MeshBase::active_elements_end().

{
  /* Out-of-mesh mode is currently only supported if all of the
     elements have affine mappings.  The reason is that for quadratic
     mappings, it is not easy to construct a relyable bounding box of
     the element, and thus, the fallback linear search in 
operator() is required. Hence, out-of-mesh mode would be extremely slow. */ if(!_out_of_mesh_mode) { #ifdef DEBUG MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin(); const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end(); for ( ; pos != end_pos; ++pos) if (!(*pos)->has_affine_map()) { std::cerr << 'ERROR: Out-of-mesh mode is currently only supported if all elements have affine mappings.' << std::endl; libmesh_error(); } #endif _out_of_mesh_mode = true; } }
 

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 PointLocatorTree::init (const Trees::BuildTypebuild_type)Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with 'new'.

Definition at line 88 of file point_locator_tree.C.

References _element, PointLocatorBase::_initialized, PointLocatorBase::_master, PointLocatorBase::_mesh, _tree, MeshTools::bounding_box(), PointLocatorBase::initialized(), and MeshBase::mesh_dimension().

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

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

  else

    {

      if (this->_master == NULL)
        {
          if (this->_mesh.mesh_dimension() == 3)
            _tree = new Trees::OctTree (this->_mesh, 200, build_type);          
          else
            {
              // A 1D/2D mesh in 3D space needs special consideration.
              // If the mesh is planar XY, we want to build a QuadTree
              // to search efficiently.  If the mesh is truly a manifold,
              // then we need an octree
              bool is_planar_xy = false;
              
              // Build the bounding box for the mesh.  If the delta-z bound is
              // negligibly small then we can use a quadtree.
              {
                MeshTools::BoundingBox bbox = MeshTools::bounding_box(this->_mesh);
                
                const Real
                  Dx = bbox.second(0) - bbox.first(0),
                  Dz = bbox.second(2) - bbox.first(2);
                
                if (std::abs(Dz/(Dx + 1.e-20)) < 1e-10)
                  is_planar_xy = true;
              }
                            
              if (is_planar_xy)
                _tree = new Trees::QuadTree (this->_mesh, 200, build_type);
              else
                _tree = new Trees::OctTree (this->_mesh, 200, build_type);
            }
        }

      else
          
        {
          // We are _not_ the master.  Let our Tree point to
          // the master's tree.  But for this we first transform
          // the master in a state for which we are friends.
          // And make sure the master @e has a tree!
          const PointLocatorTree* my_master =
            libmesh_cast_ptr<const PointLocatorTree*>(this->_master);

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


      // Not all PointLocators may own a tree, but all of them
      // use their own element pointer.  Let the element pointer
      // be unique for every interpolator.
      // Suppose the interpolators are used concurrently
      // at different locations in the mesh, then it makes quite
      // sense to have unique start elements.
      this->_element = NULL;
    }


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

virtual void PointLocatorTree::init () [inline, virtual]Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with 'new'.

Implements PointLocatorBase.

Definition at line 108 of file point_locator_tree.h.

References init(), and Trees::NODES.

Referenced by init(), and PointLocatorTree().

{ this->init(Trees::NODES); };
 

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 init(), and PointLocatorList::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 * PointLocatorTree::operator() (const Point &p) const [virtual]Locates the element in which the point with global coordinates p is located. The mutable _element member is used to cache the result and allow it to be used during the next call to operator().

Implements PointLocatorBase.

Definition at line 173 of file point_locator_tree.C.

References _element, PointLocatorBase::_initialized, PointLocatorBase::_mesh, _out_of_mesh_mode, _tree, Elem::active(), MeshBase::active_elements_begin(), MeshBase::active_elements_end(), Elem::contains_point(), and TreeBase::find_element().

{
  libmesh_assert (this->_initialized);
  
  // First check the element from last time before asking the tree
  if (this->_element==NULL || !(this->_element->contains_point(p)))
    {
        // ask the tree
        this->_element = this->_tree->find_element (p);

        if (this->_element == NULL)
          {
            /* No element seems to contain this point.  If out-of-mesh
               mode is enabled, just return NULL.  If not, however, we
               have to perform a linear search before we call 
libmesh_error() since in the case of curved elements, the bounding box computed in
TreeNode::insert(const Elem*) might be slightly inaccurate. */ if(!_out_of_mesh_mode) { MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin(); const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end(); for ( ; pos != end_pos; ++pos) if ((*pos)->contains_point(p)) return this->_element = (*pos); if (this->_element == NULL) { std::cerr << std::endl << ' ******** Serious Problem. Could not find an Element ' << 'in the Mesh' << std:: endl << ' ******** that contains the Point ' << p; libmesh_error(); } } } } // the element should be active libmesh_assert (this->_element->active()); // return the element return this->_element; }
 

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().  

const Elem* PointLocatorTree::_element [mutable, protected]Pointer to the last element that was found by the tree. Chances are that this may be close to the next call to operator()...

Definition at line 147 of file point_locator_tree.h.

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

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

Definition at line 142 of file point_locator_base.h.

Referenced by init(), PointLocatorList::init(), PointLocatorBase::initialized(), operator()(), and PointLocatorList::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 clear(), PointLocatorList::clear(), init(), and PointLocatorList::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 enable_out_of_mesh_mode(), init(), PointLocatorList::init(), and 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().  

bool PointLocatorTree::_out_of_mesh_mode [protected]true if out-of-mesh mode is enabled. See enable_out_of_mesh_mode() for details.

Definition at line 153 of file point_locator_tree.h.

Referenced by disable_out_of_mesh_mode(), enable_out_of_mesh_mode(), and operator()().  

TreeBase* PointLocatorTree::_tree [protected]Pointer to our tree. The tree is built at run-time through init(). For servant PointLocators (not master), this simply points to the tree of the master.

Definition at line 140 of file point_locator_tree.h.

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

 

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
PointLocatorTree::PointLocatorTree (const MeshBase &mesh, const PointLocatorBase *master = NULL)Constructor. Needs the mesh in which the points should be located. Optionally takes a master interpolator. This master helps in saving memory by reducing the number of trees in use. Only the master locator holds a tree, the others simply use the master's tree.
PointLocatorTree::PointLocatorTree (const MeshBase &mesh, const Trees::BuildTypebuild_type, const PointLocatorBase *master = NULL)Constructor. Needs the mesh in which the points should be located. Allows the user to specify the method to use when building the tree. Optionally takes a master interpolator. This master helps in saving memory by reducing the number of trees in use. Only the master locator holds a tree, the others simply use the master's tree. Allows the user to specify the build type.
PointLocatorTree::~PointLocatorTree ()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 PointLocatorTree::clear () [virtual]Clears the locator. This function frees dynamic memory with 'delete'.
void PointLocatorTree::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 PointLocatorTree::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 PointLocatorTree::init (const Trees::BuildTypebuild_type)Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with 'new'.
virtual void PointLocatorTree::init () [inline, virtual]Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with '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 * PointLocatorTree::operator() (const Point &p) const [virtual]Locates the element in which the point with global coordinates p is located. The mutable _element member is used to cache the result and allow it to be used during the next call to operator().
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.
const Elem* PointLocatorTree::_element [mutable, protected]Pointer to the last element that was found by the tree. Chances are that this may be close to the next call to operator()...
bool PointLocatorBase::_initialized [protected, inherited]true when properly initialized, false otherwise.
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.
bool PointLocatorTree::_out_of_mesh_mode [protected]true if out-of-mesh mode is enabled. See enable_out_of_mesh_mode() for details.
TreeBase* PointLocatorTree::_tree [protected]Pointer to our tree. The tree is built at run-time through init(). For servant PointLocators (not master), this simply points to the tree of the master.
Author

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