libMesh
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
libMesh::PointLocatorBase Class Referenceabstract

This is the base class for point locators. More...

#include <point_locator_base.h>

Inheritance diagram for libMesh::PointLocatorBase:
[legend]

Public Member Functions

virtual ~PointLocatorBase ()
 Destructor. More...
 
virtual void clear ()=0
 Clears the PointLocator. More...
 
virtual void init ()=0
 Initializes the point locator, so that the operator() methods can be used. More...
 
virtual const Elemoperator() (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr) const =0
 Locates the element in which the point with global coordinates p is located. More...
 
virtual void operator() (const Point &p, std::set< const Elem * > &candidate_elements, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr) const =0
 Locates a set of elements in proximity to the point with global coordinates p Pure virtual. More...
 
virtual const Nodelocate_node (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr, Real tol=TOLERANCE) const
 
bool initialized () const
 
virtual void enable_out_of_mesh_mode ()=0
 Enables out-of-mesh mode. More...
 
virtual void disable_out_of_mesh_mode ()=0
 Disables out-of-mesh mode (default). More...
 
virtual void set_close_to_point_tol (Real close_to_point_tol)
 Set a tolerance to use when determining if a point is contained within the mesh. More...
 
virtual void unset_close_to_point_tol ()
 Specify that we do not want to use a user-specified tolerance to determine if a point is contained within the mesh. More...
 

Static Public Member Functions

static UniquePtr< PointLocatorBasebuild (PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=libmesh_nullptr)
 Builds an PointLocator for the mesh mesh. More...
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

bool _verbose
 Boolean flag to indicate whether to print out extra info. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

 PointLocatorBase (const MeshBase &mesh, const PointLocatorBase *master)
 Constructor. More...
 
void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Protected Attributes

const PointLocatorBase_master
 Const pointer to our master, initialized to NULL if none given. More...
 
const MeshBase_mesh
 constant reference to the mesh in which the point is looked for. More...
 
bool _initialized
 true when properly initialized, false otherwise. More...
 
bool _use_close_to_point_tol
 true if we will use a user-specified tolerance for locating the element. More...
 
Real _close_to_point_tol
 The tolerance to use. More...
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Detailed Description

This is the base class for point locators.

They locate points in space: given a mesh they return the element and local coordinates for a given point in global coordinates.

Author
Daniel Dreyer
Date
2003

Definition at line 56 of file point_locator_base.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 119 of file reference_counter.h.

Constructor & Destructor Documentation

libMesh::PointLocatorBase::PointLocatorBase ( const MeshBase mesh,
const PointLocatorBase master 
)
protected

Constructor.

Protected so that this base class cannot be explicitly instantiated. Takes a master PointLocator that helps in saving memory.

Definition at line 37 of file point_locator_base.C.

38  :
39  _verbose (false),
40  _master (master),
41  _mesh (mesh),
42  _initialized (false),
45 {
46 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _close_to_point_tol
The tolerance to use.
bool _initialized
true when properly initialized, false otherwise.
MeshBase & mesh
static const Real TOLERANCE
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
bool _verbose
Boolean flag to indicate whether to print out extra info.
const PointLocatorBase * _master
Const pointer to our master, initialized to NULL if none given.
libMesh::PointLocatorBase::~PointLocatorBase ( )
virtual

Destructor.

Definition at line 52 of file point_locator_base.C.

53 {
54 }

Member Function Documentation

UniquePtr< PointLocatorBase > libMesh::PointLocatorBase::build ( PointLocatorType  t,
const MeshBase mesh,
const PointLocatorBase master = libmesh_nullptr 
)
static

Builds an PointLocator for the mesh mesh.

Optionally takes a master PointLocator to save memory. An UniquePtr<PointLocatorBase> is returned to prevent memory leak. This way the user need not remember to delete the object.

Definition at line 65 of file point_locator_base.C.

References libMesh::Trees::ELEMENTS, libMesh::Trees::LOCAL_ELEMENTS, libMesh::TREE, libMesh::TREE_ELEMENTS, and libMesh::TREE_LOCAL_ELEMENTS.

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

68 {
69  switch (t)
70  {
71  case TREE:
72  return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, /*Trees::NODES,*/ master));
73 
74  case TREE_ELEMENTS:
75  return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, Trees::ELEMENTS, master));
76 
78  return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, Trees::LOCAL_ELEMENTS, master));
79 
80  default:
81  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
82  }
83 
84  libmesh_error_msg("We'll never get here!");
85  return UniquePtr<PointLocatorBase>();
86 }
MeshBase & mesh
virtual void libMesh::PointLocatorBase::clear ( )
pure virtual

Clears the PointLocator.

Implemented in libMesh::PointLocatorTree.

virtual void libMesh::PointLocatorBase::disable_out_of_mesh_mode ( )
pure 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.

Implemented in libMesh::PointLocatorTree.

Referenced by libMesh::MeshFunction::disable_out_of_mesh_mode().

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 107 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

108 {
109  _enable_print_counter = false;
110  return;
111 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
virtual void libMesh::PointLocatorBase::enable_out_of_mesh_mode ( )
pure 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.

Implemented in libMesh::PointLocatorTree.

Referenced by libMesh::MeshFunction::enable_out_of_mesh_mode(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), and libMesh::System::point_value().

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

102 {
103  _enable_print_counter = true;
104  return;
105 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
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 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 185 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 198 of file reference_counter.h.

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

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
virtual void libMesh::PointLocatorBase::init ( )
pure virtual

Initializes the point locator, so that the operator() methods can be used.

Pure virtual.

Implemented in libMesh::PointLocatorTree.

bool libMesh::PointLocatorBase::initialized ( ) const
Returns
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 58 of file point_locator_base.C.

References _initialized.

Referenced by libMesh::PointLocatorTree::init().

59 {
60  return this->_initialized;
61 }
bool _initialized
true when properly initialized, false otherwise.
const Node * libMesh::PointLocatorBase::locate_node ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = libmesh_nullptr,
Real  tol = TOLERANCE 
) const
virtual
Returns
A pointer to a Node with global coordinates p or NULL if no such Node can be found.

Virtual subclasses can override for efficiency, but the base class has a default implementation that works based on element lookup.

Optionally allows the user to restrict the subdomains searched; with such a restriction, only a Node belonging to an element on one or more of those subdomains will be returned.

Will only return a Node whose distance from p is less than tol multiplied by the size of a semilocal element which contains p.

Definition at line 104 of file point_locator_base.C.

References libMesh::Elem::hmax(), libmesh_nullptr, libMesh::Elem::n_nodes(), libMesh::Elem::node_ptr(), libMesh::TensorTools::norm_sq(), operator()(), libMesh::Elem::point(), and libMesh::Real.

Referenced by unset_close_to_point_tol().

107 {
108  std::set<const Elem *> candidate_elements;
109  this->operator()(p, candidate_elements, allowed_subdomains);
110 
111  for (std::set<const Elem *>::const_iterator
112  it = candidate_elements.begin();
113  it != candidate_elements.end(); ++it)
114  {
115  const Elem * elem = *it;
116  const int elem_n_nodes = elem->n_nodes();
117  const Real hmax = elem->hmax();
118  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
119 
120  for (int n=0; n != elem_n_nodes; ++n)
121  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
122  return elem->node_ptr(n);
123  }
124 
125  return libmesh_nullptr;
126 }
virtual const Elem * operator()(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr) const =0
Locates the element in which the point with global coordinates p is located.
const class libmesh_nullptr_t libmesh_nullptr
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited
virtual const Elem* libMesh::PointLocatorBase::operator() ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = libmesh_nullptr 
) const
pure virtual

Locates the element in which the point with global coordinates p is located.

Pure virtual. Optionally allows the user to restrict the subdomains searched.

Implemented in libMesh::PointLocatorTree.

Referenced by locate_node().

virtual void libMesh::PointLocatorBase::operator() ( const Point p,
std::set< const Elem * > &  candidate_elements,
const std::set< subdomain_id_type > *  allowed_subdomains = libmesh_nullptr 
) const
pure virtual

Locates a set of elements in proximity to the point with global coordinates p Pure virtual.

Optionally allows the user to restrict the subdomains searched.

Implemented in libMesh::PointLocatorTree.

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

Referenced by libMesh::LibMeshInit::LibMeshInit().

89 {
91  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
void libMesh::PointLocatorBase::set_close_to_point_tol ( Real  close_to_point_tol)
virtual

Set a tolerance to use when determining if a point is contained within the mesh.

Definition at line 88 of file point_locator_base.C.

References _close_to_point_tol, and _use_close_to_point_tol.

Referenced by libMesh::MeshFunction::set_point_locator_tolerance().

89 {
91  _close_to_point_tol = close_to_point_tol;
92 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _close_to_point_tol
The tolerance to use.
void libMesh::PointLocatorBase::unset_close_to_point_tol ( )
virtual

Specify that we do not want to use a user-specified tolerance to determine if a point is contained within the mesh.

Definition at line 95 of file point_locator_base.C.

References _close_to_point_tol, _use_close_to_point_tol, locate_node(), and libMesh::TOLERANCE.

Referenced by libMesh::MeshFunction::unset_point_locator_tolerance().

96 {
99 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _close_to_point_tol
The tolerance to use.
static const Real TOLERANCE

Member Data Documentation

Real libMesh::PointLocatorBase::_close_to_point_tol
protected

The tolerance to use.

Definition at line 196 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::operator()(), set_close_to_point_tol(), and unset_close_to_point_tol().

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 143 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

true when properly initialized, false otherwise.

Definition at line 185 of file point_locator_base.h.

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

const PointLocatorBase* libMesh::PointLocatorBase::_master
protected

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 175 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::clear(), and libMesh::PointLocatorTree::init().

const MeshBase& libMesh::PointLocatorBase::_mesh
protected

constant reference to the mesh in which the point is looked for.

Definition at line 180 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::init(), libMesh::PointLocatorTree::perform_fuzzy_linear_search(), and libMesh::PointLocatorTree::perform_linear_search().

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 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 132 of file reference_counter.h.

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

bool libMesh::PointLocatorBase::_use_close_to_point_tol
protected

true if we will use a user-specified tolerance for locating the element.

Definition at line 191 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::operator()(), set_close_to_point_tol(), and unset_close_to_point_tol().

bool libMesh::PointLocatorBase::_verbose

Boolean flag to indicate whether to print out extra info.

Definition at line 167 of file point_locator_base.h.

Referenced by libMesh::PointLocatorTree::operator()().


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