libMesh::PointLocatorList Class Reference

#include <point_locator_list.h>

Inheritance diagram for libMesh::PointLocatorList:

List of all members.

Public Member Functions

 PointLocatorList (const MeshBase &mesh, const PointLocatorBase *master=NULL)
 ~PointLocatorList ()
virtual void clear ()
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

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

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 68 of file point_locator_list.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::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 38 of file point_locator_list.C.

References init().

00039                                                                     :
00040   PointLocatorBase (mesh,master),
00041   _list            (NULL)
00042 {
00043   // This code will only work if your mesh is the Voroni mesh of it's
00044   // own elements' centroids.  If your mesh is that regular you might
00045   // as well hand-code an O(1) algorithm for locating points within
00046   // it. - RHS
00047   libmesh_experimental();
00048 
00049   this->init();
00050 }

libMesh::PointLocatorList::~PointLocatorList (  ) 

Destructor.

Definition at line 55 of file point_locator_list.C.

References clear().

00056 {
00057   this->clear ();
00058 }


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::PointLocatorList::clear (  )  [virtual]

Clears the locator. Overloaded from base class. This method frees dynamic memory using "delete".

Implements libMesh::PointLocatorBase.

Definition at line 63 of file point_locator_list.C.

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

Referenced by ~PointLocatorList().

00064 {
00065   // only delete the list when we are the master
00066   if (this->_list != NULL)
00067     {
00068       if (this->_master == NULL)
00069         {
00070           // we own the list
00071           this->_list->clear();
00072           delete this->_list;
00073         }
00074       else
00075           // someone else owns and therefore deletes the list
00076           this->_list = NULL;
00077     }
00078 }

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

Definition at line 218 of file point_locator_list.C.

00219 {
00220   /* This functionality is not yet implemented for PointLocatorList.  */
00221   libmesh_not_implemented();
00222 }

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

Definition at line 212 of file point_locator_list.C.

00213 {
00214   /* This functionality is not yet implemented for PointLocatorList.  */
00215   libmesh_not_implemented();
00216 }

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 }

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

Definition at line 84 of file point_locator_list.C.

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

Referenced by PointLocatorList().

00085 {
00086   libmesh_assert (!this->_list);
00087 
00088   if (this->_initialized)
00089     {
00090       libMesh::err << "ERROR: Already initialized!  Will ignore this call..."
00091                     << std::endl;
00092     }
00093 
00094   else
00095 
00096     {
00097 
00098       if (this->_master == NULL)
00099         {
00100           START_LOG("init(no master)", "PointLocatorList");
00101 
00102           // We are the master, so we have to build the list.
00103           // First create it, then get a handy reference, and
00104           // then try to speed up by reserving space...
00105           this->_list = new std::vector<std::pair<Point, const Elem *> >;
00106           std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);
00107 
00108           my_list.clear();
00109           my_list.reserve(this->_mesh.n_active_elem());
00110 
00111           // fill our list with the centroids and element
00112           // pointers of the mesh.  For this use the handy
00113           // element iterators.
00114 //        const_active_elem_iterator       el (this->_mesh.elements_begin());
00115 //        const const_active_elem_iterator end(this->_mesh.elements_end());
00116 
00117           MeshBase::const_element_iterator       el  = _mesh.active_elements_begin();
00118           const MeshBase::const_element_iterator end = _mesh.active_elements_end();
00119 
00120           for (; el!=end; ++el)
00121             my_list.push_back(std::make_pair((*el)->centroid(), *el));
00122 
00123           STOP_LOG("init(no master)", "PointLocatorList");
00124         }
00125 
00126       else
00127 
00128         {
00129           // We are _not_ the master.  Let our _list point to
00130           // the master's list.  But for this we first transform
00131           // the master in a state for which we are friends
00132           // (this should also beware of a bad master pointer?).
00133           // And make sure the master @e has a list!
00134           const PointLocatorList* my_master =
00135             libmesh_cast_ptr<const PointLocatorList*>(this->_master);
00136 
00137           if (my_master->initialized())
00138             this->_list = my_master->_list;
00139           else
00140             {
00141               libMesh::err << "ERROR: Initialize master first, then servants!"
00142                             << std::endl;
00143               libmesh_error();
00144             }
00145         }
00146 
00147     }
00148 
00149 
00150   // ready for take-off
00151   this->_initialized = true;
00152 }

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

Definition at line 158 of file point_locator_list.C.

References libMesh::PointLocatorBase::_initialized, _list, libMesh::Elem::active(), and libMesh::Real.

00159 {
00160   libmesh_assert (this->_initialized);
00161 
00162   START_LOG("operator()", "PointLocatorList");
00163 
00164   // Ask the list.  This is quite expensive, since
00165   // we loop through the whole list to try to find
00166   // the @e nearest element.
00167   // However, there is not much else to do: when
00168   // we would use bounding boxes like in a tree,
00169   // it may happen that a surface element is just
00170   // in plane with a bounding box face, and quite
00171   // close to it.  But when a point comes, this
00172   // point may belong to the bounding box (where the
00173   // coplanar element does @e not belong to).  Then
00174   // we would search through the elements in this
00175   // bounding box, while the other bounding box'es
00176   // element is closer, but we simply don't consider
00177   // it!
00178   //
00179   // We _can_, however, use size_sq() instead of size()
00180   // here to avoid repeated calls to std::sqrt(), which is
00181   // pretty expensive.
00182   {
00183     std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);
00184 
00185     Real              last_distance_sq = Point(my_list[0].first -p).size_sq();
00186     const Elem *      last_elem        = NULL;
00187     const std::size_t max_index        = my_list.size();
00188 
00189 
00190     for (std::size_t n=1; n<max_index; n++)
00191       {
00192         const Real current_distance_sq = Point(my_list[n].first -p).size_sq();
00193 
00194         if (current_distance_sq < last_distance_sq)
00195           {
00196             last_distance_sq = current_distance_sq;
00197             last_elem        = my_list[n].second;
00198           }
00199       }
00200 
00201     // If we found an element, it should be active
00202     libmesh_assert (!last_elem || last_elem->active());
00203 
00204     STOP_LOG("operator()", "PointLocatorList");
00205 
00206     // return the element
00207     return (last_elem);
00208   }
00209 
00210 }

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

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 libMesh::PointLocatorTree::init(), init(), libMesh::PointLocatorBase::initialized(), libMesh::PointLocatorTree::operator()(), and operator()().

std::vector<std::pair<Point, const Elem *> >* libMesh::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 134 of file point_locator_list.h.

Referenced by clear(), init(), and 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 libMesh::PointLocatorTree::clear(), clear(), libMesh::PointLocatorTree::init(), and 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 libMesh::PointLocatorTree::enable_out_of_mesh_mode(), libMesh::PointLocatorTree::init(), init(), and libMesh::PointLocatorTree::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().


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