libMesh::PointLocatorList Class Reference

#include <point_locator_list.h>

Inheritance diagram for libMesh::PointLocatorList:

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
protectedinherited

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

39  :
40  PointLocatorBase (mesh,master),
41  _list (NULL)
42 {
43  // This code will only work if your mesh is the Voroni mesh of it's
44  // own elements' centroids. If your mesh is that regular you might
45  // as well hand-code an O(1) algorithm for locating points within
46  // it. - RHS
47  libmesh_experimental();
48 
49  this->init();
50 }
libMesh::PointLocatorList::~PointLocatorList ( )

Destructor.

Definition at line 55 of file point_locator_list.C.

References clear().

56 {
57  this->clear ();
58 }

Member Function Documentation

AutoPtr< PointLocatorBase > libMesh::PointLocatorBase::build ( const PointLocatorType  t,
const MeshBase mesh,
const PointLocatorBase master = NULL 
)
staticinherited

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

59 {
60  switch (t)
61  {
62  case TREE:
63  {
64  AutoPtr<PointLocatorBase> ap(new PointLocatorTree(mesh,
65  master));
66  return ap;
67  }
68 
69  case LIST:
70  {
71  AutoPtr<PointLocatorBase> ap(new PointLocatorList(mesh,
72  master));
73  return ap;
74  }
75 
76  default:
77  {
78  libMesh::err << "ERROR: Bad PointLocatorType = " << t << std::endl;
79  libmesh_error();
80  }
81  }
82 
83  libmesh_error();
84  AutoPtr<PointLocatorBase> ap(NULL);
85  return ap;
86 }
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().

64 {
65  // only delete the list when we are the master
66  if (this->_list != NULL)
67  {
68  if (this->_master == NULL)
69  {
70  // we own the list
71  this->_list->clear();
72  delete this->_list;
73  }
74  else
75  // someone else owns and therefore deletes the list
76  this->_list = NULL;
77  }
78 }
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.

219 {
220  /* This functionality is not yet implemented for PointLocatorList. */
221  libmesh_not_implemented();
222 }
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

107 {
108  _enable_print_counter = false;
109  return;
110 }
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.

213 {
214  /* This functionality is not yet implemented for PointLocatorList. */
215  libmesh_not_implemented();
216 }
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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.

101 {
102  _enable_print_counter = true;
103  return;
104 }
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

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

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

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, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

164 {
165  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
166  std::pair<unsigned int, unsigned int>& p = _counts[name];
167 
168  p.first++;
169 }
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

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, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

177 {
178  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
179  std::pair<unsigned int, unsigned int>& p = _counts[name];
180 
181  p.second++;
182 }
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(), libMesh::libmesh_assert(), libMesh::MeshBase::n_active_elem(), libMesh::START_LOG(), and libMesh::STOP_LOG().

Referenced by PointLocatorList().

85 {
86  libmesh_assert (!this->_list);
87 
88  if (this->_initialized)
89  {
90  libMesh::err << "ERROR: Already initialized! Will ignore this call..."
91  << std::endl;
92  }
93 
94  else
95 
96  {
97 
98  if (this->_master == NULL)
99  {
100  START_LOG("init(no master)", "PointLocatorList");
101 
102  // We are the master, so we have to build the list.
103  // First create it, then get a handy reference, and
104  // then try to speed up by reserving space...
105  this->_list = new std::vector<std::pair<Point, const Elem *> >;
106  std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);
107 
108  my_list.clear();
109  my_list.reserve(this->_mesh.n_active_elem());
110 
111  // fill our list with the centroids and element
112  // pointers of the mesh. For this use the handy
113  // element iterators.
114 // const_active_elem_iterator el (this->_mesh.elements_begin());
115 // const const_active_elem_iterator end(this->_mesh.elements_end());
116 
117  MeshBase::const_element_iterator el = _mesh.active_elements_begin();
118  const MeshBase::const_element_iterator end = _mesh.active_elements_end();
119 
120  for (; el!=end; ++el)
121  my_list.push_back(std::make_pair((*el)->centroid(), *el));
122 
123  STOP_LOG("init(no master)", "PointLocatorList");
124  }
125 
126  else
127 
128  {
129  // We are _not_ the master. Let our _list point to
130  // the master's list. But for this we first transform
131  // the master in a state for which we are friends
132  // (this should also beware of a bad master pointer?).
133  // And make sure the master @e has a list!
134  const PointLocatorList* my_master =
135  libmesh_cast_ptr<const PointLocatorList*>(this->_master);
136 
137  if (my_master->initialized())
138  this->_list = my_master->_list;
139  else
140  {
141  libMesh::err << "ERROR: Initialize master first, then servants!"
142  << std::endl;
143  libmesh_error();
144  }
145  }
146 
147  }
148 
149 
150  // ready for take-off
151  this->_initialized = true;
152 }
bool libMesh::PointLocatorBase::initialized ( ) const
inlineinherited
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().

151 {
152  return (this->_initialized);
153 }
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

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.

80  { 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::Elem::active(), libMesh::libmesh_assert(), libMesh::Real, libMesh::TypeVector< T >::size_sq(), libMesh::START_LOG(), and libMesh::STOP_LOG().

159 {
161 
162  START_LOG("operator()", "PointLocatorList");
163 
164  // Ask the list. This is quite expensive, since
165  // we loop through the whole list to try to find
166  // the @e nearest element.
167  // However, there is not much else to do: when
168  // we would use bounding boxes like in a tree,
169  // it may happen that a surface element is just
170  // in plane with a bounding box face, and quite
171  // close to it. But when a point comes, this
172  // point may belong to the bounding box (where the
173  // coplanar element does @e not belong to). Then
174  // we would search through the elements in this
175  // bounding box, while the other bounding box'es
176  // element is closer, but we simply don't consider
177  // it!
178  //
179  // We _can_, however, use size_sq() instead of size()
180  // here to avoid repeated calls to std::sqrt(), which is
181  // pretty expensive.
182  {
183  std::vector<std::pair<Point, const Elem *> >& my_list = *(this->_list);
184 
185  Real last_distance_sq = Point(my_list[0].first -p).size_sq();
186  const Elem * last_elem = NULL;
187  const std::size_t max_index = my_list.size();
188 
189 
190  for (std::size_t n=1; n<max_index; n++)
191  {
192  const Real current_distance_sq = Point(my_list[n].first -p).size_sq();
193 
194  if (current_distance_sq < last_distance_sq)
195  {
196  last_distance_sq = current_distance_sq;
197  last_elem = my_list[n].second;
198  }
199  }
200 
201  // If we found an element, it should be active
202  libmesh_assert (!last_elem || last_elem->active());
203 
204  STOP_LOG("operator()", "PointLocatorList");
205 
206  // return the element
207  return (last_elem);
208  }
209 
210 }
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

89 {
91 }

Member Data Documentation

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

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
protectedinherited

true when properly initialized, false otherwise.

Definition at line 142 of file point_locator_base.h.

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

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(), and init().

const PointLocatorBase* libMesh::PointLocatorBase::_master
protectedinherited

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

const MeshBase& libMesh::PointLocatorBase::_mesh
protectedinherited

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

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

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
staticprotectedinherited

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 07 2014 16:58:01 UTC

Hosted By:
SourceForge.net Logo