libMesh::PointLocatorTree Class Reference

#include <point_locator_tree.h>

Inheritance diagram for libMesh::PointLocatorTree:

List of all members.

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 Elemoperator() (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< PointLocatorBasebuild (const PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=NULL)
static std::string get_info ()
static void print_info (std::ostream &out=libMesh::out)
static unsigned int n_objects ()
static void enable_print_counter_info ()
static void disable_print_counter_info ()

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
static bool _enable_print_counter = true

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> > libMesh::ReferenceCounter::Counts [protected, inherited]

Data structure to log the information. The log is identified by the class name.

Definition at line 113 of file reference_counter.h.


Constructor & Destructor Documentation

libMesh::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 37 of file point_locator_tree.C.

References init(), and libMesh::Trees::NODES.

00038                                                                     :
00039   PointLocatorBase (mesh,master),
00040   _tree            (NULL),
00041   _element         (NULL),
00042   _out_of_mesh_mode(false)
00043 {
00044   this->init(Trees::NODES);
00045 }

libMesh::PointLocatorTree::PointLocatorTree ( const MeshBase mesh,
const Trees::BuildType  build_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 50 of file point_locator_tree.C.

References init().

00052                                                                     :
00053   PointLocatorBase (mesh,master),
00054   _tree            (NULL),
00055   _element         (NULL),
00056   _out_of_mesh_mode(false)
00057 {
00058   this->init(build_type);
00059 }

libMesh::PointLocatorTree::~PointLocatorTree (  ) 

Destructor.

Definition at line 64 of file point_locator_tree.C.

References clear().

00065 {
00066   this->clear ();
00067 }


Member Function Documentation

AutoPtr< PointLocatorBase > libMesh::PointLocatorBase::build ( const PointLocatorType  t,
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 56 of file point_locator_base.C.

References libMesh::err, libMeshEnums::LIST, and libMeshEnums::TREE.

Referenced by libMesh::MeshBase::point_locator(), and libMesh::MeshBase::sub_point_locator().

00059 {
00060   switch (t)
00061     {
00062     case TREE:
00063       {
00064         AutoPtr<PointLocatorBase> ap(new PointLocatorTree(mesh,
00065                                                           master));
00066         return ap;
00067       }
00068 
00069     case LIST:
00070       {
00071         AutoPtr<PointLocatorBase> ap(new PointLocatorList(mesh,
00072                                                           master));
00073         return ap;
00074       }
00075 
00076     default:
00077       {
00078         libMesh::err << "ERROR: Bad PointLocatorType = " << t << std::endl;
00079         libmesh_error();
00080       }
00081     }
00082 
00083   libmesh_error();
00084   AutoPtr<PointLocatorBase> ap(NULL);
00085   return ap;
00086 }

void libMesh::PointLocatorTree::clear (  )  [virtual]

Clears the locator. This function frees dynamic memory with "delete".

Implements libMesh::PointLocatorBase.

Definition at line 72 of file point_locator_tree.C.

References libMesh::PointLocatorBase::_master, and _tree.

Referenced by ~PointLocatorTree().

00073 {
00074   // only delete the tree when we are the master
00075   if (this->_tree != NULL)
00076     {
00077       if (this->_master == NULL)
00078           // we own the tree
00079           delete this->_tree;
00080       else
00081           // someone else owns and therefore deletes the tree
00082           this->_tree = NULL;
00083     }
00084 }

void libMesh::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 libMesh::PointLocatorBase.

Definition at line 270 of file point_locator_tree.C.

References _out_of_mesh_mode.

00271 {
00272   _out_of_mesh_mode = false;
00273 }

void libMesh::ReferenceCounter::disable_print_counter_info (  )  [static, inherited]

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

00107 {
00108   _enable_print_counter = false;
00109   return;
00110 }

void libMesh::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 libMesh::PointLocatorBase.

Definition at line 245 of file point_locator_tree.C.

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

00246 {
00247   /* Out-of-mesh mode is currently only supported if all of the
00248      elements have affine mappings.  The reason is that for quadratic
00249      mappings, it is not easy to construct a relyable bounding box of
00250      the element, and thus, the fallback linear search in \p
00251      operator() is required.  Hence, out-of-mesh mode would be
00252      extremely slow.  */
00253   if(!_out_of_mesh_mode)
00254     {
00255 #ifdef DEBUG
00256       MeshBase::const_element_iterator       pos     = this->_mesh.active_elements_begin();
00257       const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();
00258       for ( ; pos != end_pos; ++pos)
00259         if (!(*pos)->has_affine_map())
00260           {
00261             libMesh::err << "ERROR: Out-of-mesh mode is currently only supported if all elements have affine mappings." << std::endl;
00262             libmesh_error();
00263           }
00264 #endif
00265 
00266       _out_of_mesh_mode = true;
00267     }
00268 }

void libMesh::ReferenceCounter::enable_print_counter_info (  )  [static, inherited]

Methods to enable/disable the reference counter output from print_info()

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

00101 {
00102   _enable_print_counter = true;
00103   return;
00104 }

std::string libMesh::ReferenceCounter::get_info (  )  [static, inherited]

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

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

Referenced by libMesh::ReferenceCounter::print_info().

00048 {
00049 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
00050 
00051   std::ostringstream oss;
00052 
00053   oss << '\n'
00054       << " ---------------------------------------------------------------------------- \n"
00055       << "| Reference count information                                                |\n"
00056       << " ---------------------------------------------------------------------------- \n";
00057 
00058   for (Counts::iterator it = _counts.begin();
00059        it != _counts.end(); ++it)
00060     {
00061       const std::string name(it->first);
00062       const unsigned int creations    = it->second.first;
00063       const unsigned int destructions = it->second.second;
00064 
00065       oss << "| " << name << " reference count information:\n"
00066           << "|  Creations:    " << creations    << '\n'
00067           << "|  Destructions: " << destructions << '\n';
00068     }
00069 
00070   oss << " ---------------------------------------------------------------------------- \n";
00071 
00072   return oss.str();
00073 
00074 #else
00075 
00076   return "";
00077 
00078 #endif
00079 }

void libMesh::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 163 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

00164 {
00165   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00166   std::pair<unsigned int, unsigned int>& p = _counts[name];
00167 
00168   p.first++;
00169 }

void libMesh::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 176 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

00177 {
00178   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
00179   std::pair<unsigned int, unsigned int>& p = _counts[name];
00180 
00181   p.second++;
00182 }

virtual void libMesh::PointLocatorTree::init (  )  [inline, virtual]

Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with "new".

Implements libMesh::PointLocatorBase.

Definition at line 108 of file point_locator_tree.h.

References init(), and libMesh::Trees::NODES.

Referenced by init(), and PointLocatorTree().

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

void libMesh::PointLocatorTree::init ( const Trees::BuildType  build_type  ) 

Initializes the locator, so that the operator() methods can be used. This function allocates dynamic memory with "new".

Definition at line 90 of file point_locator_tree.C.

References _element, libMesh::PointLocatorBase::_initialized, libMesh::PointLocatorBase::_master, libMesh::PointLocatorBase::_mesh, _tree, std::abs(), libMesh::MeshTools::bounding_box(), libMesh::err, libMesh::PointLocatorBase::initialized(), libMesh::MeshBase::mesh_dimension(), and libMesh::Real.

00091 {
00092   libmesh_assert (!this->_tree);
00093 
00094   if (this->_initialized)
00095     {
00096       libMesh::err << "ERROR: Already initialized!  Will ignore this call..."
00097                     << std::endl;
00098     }
00099 
00100   else
00101 
00102     {
00103 
00104       if (this->_master == NULL)
00105         {
00106           START_LOG("init(no master)", "PointLocatorTree");
00107 
00108           if (this->_mesh.mesh_dimension() == 3)
00109             _tree = new Trees::OctTree (this->_mesh, 200, build_type);
00110           else
00111             {
00112               // A 1D/2D mesh in 3D space needs special consideration.
00113               // If the mesh is planar XY, we want to build a QuadTree
00114               // to search efficiently.  If the mesh is truly a manifold,
00115               // then we need an octree
00116 #if LIBMESH_DIM > 2
00117               bool is_planar_xy = false;
00118 
00119               // Build the bounding box for the mesh.  If the delta-z bound is
00120               // negligibly small then we can use a quadtree.
00121               {
00122                 MeshTools::BoundingBox bbox = MeshTools::bounding_box(this->_mesh);
00123 
00124                 const Real
00125                   Dx = bbox.second(0) - bbox.first(0),
00126                   Dz = bbox.second(2) - bbox.first(2);
00127 
00128                 if (std::abs(Dz/(Dx + 1.e-20)) < 1e-10)
00129                   is_planar_xy = true;
00130               }
00131 
00132               if (!is_planar_xy)
00133                 _tree = new Trees::OctTree (this->_mesh, 200, build_type);
00134               else
00135 #endif
00136 #if LIBMESH_DIM > 1
00137                 _tree = new Trees::QuadTree (this->_mesh, 200, build_type);
00138 #else
00139                 _tree = new Trees::BinaryTree (this->_mesh, 200, build_type);
00140 #endif
00141             }
00142 
00143           STOP_LOG("init(no master)", "PointLocatorTree");
00144         }
00145 
00146       else
00147 
00148         {
00149           // We are _not_ the master.  Let our Tree point to
00150           // the master's tree.  But for this we first transform
00151           // the master in a state for which we are friends.
00152           // And make sure the master @e has a tree!
00153           const PointLocatorTree* my_master =
00154             libmesh_cast_ptr<const PointLocatorTree*>(this->_master);
00155 
00156           if (my_master->initialized())
00157             this->_tree = my_master->_tree;
00158           else
00159             {
00160               libMesh::err << "ERROR: Initialize master first, then servants!"
00161                             << std::endl;
00162               libmesh_error();
00163             }
00164         }
00165 
00166 
00167       // Not all PointLocators may own a tree, but all of them
00168       // use their own element pointer.  Let the element pointer
00169       // be unique for every interpolator.
00170       // Suppose the interpolators are used concurrently
00171       // at different locations in the mesh, then it makes quite
00172       // sense to have unique start elements.
00173       this->_element = NULL;
00174     }
00175 
00176 
00177   // ready for take-off
00178   this->_initialized = true;
00179 }

bool libMesh::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 libMesh::PointLocatorBase::_initialized.

Referenced by init(), and libMesh::PointLocatorList::init().

00151 {
00152   return (this->_initialized);
00153 }

static unsigned int libMesh::ReferenceCounter::n_objects (  )  [inline, static, inherited]

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 79 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

00080   { return _n_objects; }

const Elem * libMesh::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 libMesh::PointLocatorBase.

Definition at line 185 of file point_locator_tree.C.

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

00186 {
00187   libmesh_assert (this->_initialized);
00188 
00189   START_LOG("operator()", "PointLocatorTree");
00190 
00191   // First check the element from last time before asking the tree
00192   if (this->_element==NULL || !(this->_element->contains_point(p)))
00193     {
00194         // ask the tree
00195         this->_element = this->_tree->find_element (p);
00196 
00197         if (this->_element == NULL)
00198           {
00199             /* No element seems to contain this point.  If out-of-mesh
00200                mode is enabled, just return NULL.  If not, however, we
00201                have to perform a linear search before we call \p
00202                libmesh_error() since in the case of curved elements, the
00203                bounding box computed in \p TreeNode::insert(const
00204                Elem*) might be slightly inaccurate.  */
00205             if(!_out_of_mesh_mode)
00206               {
00207                 START_LOG("linear search", "PointLocatorTree");
00208                 MeshBase::const_element_iterator       pos     = this->_mesh.active_elements_begin();
00209                 const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();
00210 
00211                 for ( ; pos != end_pos; ++pos)
00212                   if ((*pos)->contains_point(p))
00213                     {
00214                       STOP_LOG("linear search", "PointLocatorTree");
00215                       STOP_LOG("operator()", "PointLocatorTree");
00216                       return this->_element = (*pos);
00217                     }
00218 
00219 /*
00220                 if (this->_element == NULL)
00221                   {
00222                     libMesh::err << std::endl
00223                                   << " ******** Serious Problem.  Could not find an Element "
00224                                   << "in the Mesh"
00225                                   << std:: endl
00226                                   << " ******** that contains the Point "
00227                                   << p;
00228                     libmesh_error();
00229                   }
00230 */
00231                 STOP_LOG("linear search", "PointLocatorTree");
00232               }
00233           }
00234     }
00235 
00236   // If we found an element, it should be active
00237   libmesh_assert (!this->_element || this->_element->active());
00238 
00239   STOP_LOG("operator()", "PointLocatorTree");
00240 
00241   // return the element
00242   return this->_element;
00243 }

void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out  )  [static, inherited]

Prints the reference information, by default to libMesh::out.

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

00089 {
00090   if( _enable_print_counter ) out_stream << ReferenceCounter::get_info();
00091 }


Member Data Documentation

const Elem* libMesh::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 libMesh::ReferenceCounter::_enable_print_counter = true [static, protected, inherited]

Flag to control whether reference count information is printed when print_info is called.

Definition at line 137 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

bool libMesh::PointLocatorBase::_initialized [protected, inherited]

true when properly initialized, false otherwise.

Definition at line 142 of file point_locator_base.h.

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

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(), libMesh::PointLocatorList::clear(), init(), and libMesh::PointLocatorList::init().

const MeshBase& libMesh::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(), libMesh::PointLocatorList::init(), and operator()().

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 131 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects [static, protected, inherited]

The number of objects. Print the reference count information when the number returns to 0.

Definition at line 126 of file reference_counter.h.

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

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

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


The documentation for this class was generated from the following files:

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:34 UTC

Hosted By:
SourceForge.net Logo