libMesh::PointLocatorTree Class Reference

#include <point_locator_tree.h>

Inheritance diagram for libMesh::PointLocatorTree:

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

38  :
39  PointLocatorBase (mesh,master),
40  _tree (NULL),
41  _element (NULL),
42  _out_of_mesh_mode(false)
43 {
44  this->init(Trees::NODES);
45 }
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().

52  :
53  PointLocatorBase (mesh,master),
54  _tree (NULL),
55  _element (NULL),
56  _out_of_mesh_mode(false)
57 {
58  this->init(build_type);
59 }
libMesh::PointLocatorTree::~PointLocatorTree ( )

Destructor.

Definition at line 64 of file point_locator_tree.C.

References clear().

65 {
66  this->clear ();
67 }

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

73 {
74  // only delete the tree when we are the master
75  if (this->_tree != NULL)
76  {
77  if (this->_master == NULL)
78  // we own the tree
79  delete this->_tree;
80  else
81  // someone else owns and therefore deletes the tree
82  this->_tree = NULL;
83  }
84 }
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.

271 {
272  _out_of_mesh_mode = false;
273 }
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::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::err.

246 {
247  /* Out-of-mesh mode is currently only supported if all of the
248  elements have affine mappings. The reason is that for quadratic
249  mappings, it is not easy to construct a relyable bounding box of
250  the element, and thus, the fallback linear search in \p
251  operator() is required. Hence, out-of-mesh mode would be
252  extremely slow. */
253  if(!_out_of_mesh_mode)
254  {
255 #ifdef DEBUG
256  MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();
257  const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();
258  for ( ; pos != end_pos; ++pos)
259  if (!(*pos)->has_affine_map())
260  {
261  libMesh::err << "ERROR: Out-of-mesh mode is currently only supported if all elements have affine mappings." << std::endl;
262  libmesh_error();
263  }
264 #endif
265 
266  _out_of_mesh_mode = true;
267  }
268 }
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::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::libmesh_assert(), libMesh::MeshBase::mesh_dimension(), libMesh::Real, libMesh::START_LOG(), and libMesh::STOP_LOG().

91 {
92  libmesh_assert (!this->_tree);
93 
94  if (this->_initialized)
95  {
96  libMesh::err << "ERROR: Already initialized! Will ignore this call..."
97  << std::endl;
98  }
99 
100  else
101 
102  {
103 
104  if (this->_master == NULL)
105  {
106  START_LOG("init(no master)", "PointLocatorTree");
107 
108  if (this->_mesh.mesh_dimension() == 3)
109  _tree = new Trees::OctTree (this->_mesh, 200, build_type);
110  else
111  {
112  // A 1D/2D mesh in 3D space needs special consideration.
113  // If the mesh is planar XY, we want to build a QuadTree
114  // to search efficiently. If the mesh is truly a manifold,
115  // then we need an octree
116 #if LIBMESH_DIM > 2
117  bool is_planar_xy = false;
118 
119  // Build the bounding box for the mesh. If the delta-z bound is
120  // negligibly small then we can use a quadtree.
121  {
122  MeshTools::BoundingBox bbox = MeshTools::bounding_box(this->_mesh);
123 
124  const Real
125  Dx = bbox.second(0) - bbox.first(0),
126  Dz = bbox.second(2) - bbox.first(2);
127 
128  if (std::abs(Dz/(Dx + 1.e-20)) < 1e-10)
129  is_planar_xy = true;
130  }
131 
132  if (!is_planar_xy)
133  _tree = new Trees::OctTree (this->_mesh, 200, build_type);
134  else
135 #endif
136 #if LIBMESH_DIM > 1
137  _tree = new Trees::QuadTree (this->_mesh, 200, build_type);
138 #else
139  _tree = new Trees::BinaryTree (this->_mesh, 200, build_type);
140 #endif
141  }
142 
143  STOP_LOG("init(no master)", "PointLocatorTree");
144  }
145 
146  else
147 
148  {
149  // We are _not_ the master. Let our Tree point to
150  // the master's tree. But for this we first transform
151  // the master in a state for which we are friends.
152  // And make sure the master @e has a tree!
153  const PointLocatorTree* my_master =
154  libmesh_cast_ptr<const PointLocatorTree*>(this->_master);
155 
156  if (my_master->initialized())
157  this->_tree = my_master->_tree;
158  else
159  {
160  libMesh::err << "ERROR: Initialize master first, then servants!"
161  << std::endl;
162  libmesh_error();
163  }
164  }
165 
166 
167  // Not all PointLocators may own a tree, but all of them
168  // use their own element pointer. Let the element pointer
169  // be unique for every interpolator.
170  // Suppose the interpolators are used concurrently
171  // at different locations in the mesh, then it makes quite
172  // sense to have unique start elements.
173  this->_element = NULL;
174  }
175 
176 
177  // ready for take-off
178  this->_initialized = true;
179 }
virtual void libMesh::PointLocatorTree::init ( )
inlinevirtual

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

108 { this->init(Trees::NODES); }
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 init(), and libMesh::PointLocatorList::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::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 libMesh::libmesh_assert(), libMesh::START_LOG(), and libMesh::STOP_LOG().

186 {
188 
189  START_LOG("operator()", "PointLocatorTree");
190 
191  // First check the element from last time before asking the tree
192  if (this->_element==NULL || !(this->_element->contains_point(p)))
193  {
194  // ask the tree
195  this->_element = this->_tree->find_element (p);
196 
197  if (this->_element == NULL)
198  {
199  /* No element seems to contain this point. If out-of-mesh
200  mode is enabled, just return NULL. If not, however, we
201  have to perform a linear search before we call \p
202  libmesh_error() since in the case of curved elements, the
203  bounding box computed in \p TreeNode::insert(const
204  Elem*) might be slightly inaccurate. */
205  if(!_out_of_mesh_mode)
206  {
207  START_LOG("linear search", "PointLocatorTree");
208  MeshBase::const_element_iterator pos = this->_mesh.active_elements_begin();
209  const MeshBase::const_element_iterator end_pos = this->_mesh.active_elements_end();
210 
211  for ( ; pos != end_pos; ++pos)
212  if ((*pos)->contains_point(p))
213  {
214  STOP_LOG("linear search", "PointLocatorTree");
215  STOP_LOG("operator()", "PointLocatorTree");
216  return this->_element = (*pos);
217  }
218 
219 /*
220  if (this->_element == NULL)
221  {
222  libMesh::err << std::endl
223  << " ******** Serious Problem. Could not find an Element "
224  << "in the Mesh"
225  << std:: endl
226  << " ******** that contains the Point "
227  << p;
228  libmesh_error();
229  }
230 */
231  STOP_LOG("linear search", "PointLocatorTree");
232  }
233  }
234  }
235 
236  // If we found an element, it should be active
237  libmesh_assert (!this->_element || this->_element->active());
238 
239  STOP_LOG("operator()", "PointLocatorTree");
240 
241  // return the element
242  return this->_element;
243 }
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
const Elem* libMesh::PointLocatorTree::_element
mutableprotected

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

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

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

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

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


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