libMesh::PointLocatorBase Class Referenceabstract

#include <point_locator_base.h>

Inheritance diagram for libMesh::PointLocatorBase:

Public Member Functions

virtual ~PointLocatorBase ()
 
virtual void clear ()=0
 
virtual void init ()=0
 
virtual const Elemoperator() (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const =0
 
virtual void operator() (const Point &p, std::set< const Elem *> &candidate_elements, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const =0
 
virtual const Nodelocate_node (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr, Real tol=TOLERANCE) const
 
bool initialized () const
 
virtual void enable_out_of_mesh_mode ()=0
 
virtual void disable_out_of_mesh_mode ()=0
 
virtual void set_close_to_point_tol (Real close_to_point_tol)
 
virtual void unset_close_to_point_tol ()
 
const MeshBaseget_mesh () const
 

Static Public Member Functions

static std::unique_ptr< PointLocatorBasebuild (PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=nullptr)
 
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 ()
 

Public Attributes

bool _verbose
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions

 PointLocatorBase (const MeshBase &mesh, const PointLocatorBase *master)
 
void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

const PointLocatorBase_master
 
const MeshBase_mesh
 
bool _initialized
 
bool _use_close_to_point_tol
 
Real _close_to_point_tol
 

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

Member Typedef Documentation

◆ Counts

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 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ PointLocatorBase()

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 34 of file point_locator_base.C.

35  :
36  _verbose (false),
37  _master (master),
38  _mesh (mesh),
39  _initialized (false),
42 {
43 }
MeshBase & mesh
static const Real TOLERANCE
const PointLocatorBase * _master

◆ ~PointLocatorBase()

libMesh::PointLocatorBase::~PointLocatorBase ( )
virtual

Destructor.

Definition at line 49 of file point_locator_base.C.

50 {
51 }

Member Function Documentation

◆ build()

std::unique_ptr< PointLocatorBase > libMesh::PointLocatorBase::build ( PointLocatorType  t,
const MeshBase mesh,
const PointLocatorBase master = nullptr 
)
static

Builds an PointLocator for the mesh mesh. Optionally takes a master PointLocator to save memory. An std::unique_ptr<PointLocatorBase> is returned to prevent memory leak. This way the user need not remember to delete the object.

Definition at line 62 of file point_locator_base.C.

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

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

65 {
66  switch (t)
67  {
68  case TREE:
69  return libmesh_make_unique<PointLocatorTree>(mesh, /*Trees::NODES,*/ master);
70 
71  case TREE_ELEMENTS:
72  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::ELEMENTS, master);
73 
75  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::LOCAL_ELEMENTS, master);
76 
77  default:
78  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
79  }
80 }
MeshBase & mesh

◆ clear()

virtual void libMesh::PointLocatorBase::clear ( )
pure virtual

Clears the PointLocator.

Implemented in libMesh::PointLocatorTree.

◆ disable_out_of_mesh_mode()

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

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

107 {
108  _enable_print_counter = false;
109  return;
110 }

◆ enable_out_of_mesh_mode()

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

◆ enable_print_counter_info()

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 }

◆ get_info()

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 (const auto & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ get_mesh()

const MeshBase & libMesh::PointLocatorBase::get_mesh ( ) const

Get a const reference to this PointLocator's mesh.

Definition at line 96 of file point_locator_base.C.

References _mesh.

Referenced by libMesh::PeriodicBoundaries::neighbor().

97 {
98  return _mesh;
99 }

◆ increment_constructor_count()

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 181 of file reference_counter.h.

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

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

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
spin_mutex spin_mtx
Definition: threads.C:29

◆ increment_destructor_count()

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 194 of file reference_counter.h.

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

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

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
spin_mutex spin_mtx
Definition: threads.C:29

◆ init()

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.

◆ initialized()

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

Definition at line 55 of file point_locator_base.C.

References _initialized.

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

56 {
57  return this->_initialized;
58 }

◆ locate_node()

const Node * libMesh::PointLocatorBase::locate_node ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = nullptr,
Real  tol = TOLERANCE 
) const
virtual
Returns
A pointer to a Node with global coordinates p or nullptr 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::TensorTools::norm_sq(), operator()(), and libMesh::Real.

107 {
108  std::set<const Elem *> candidate_elements;
109  this->operator()(p, candidate_elements, allowed_subdomains);
110 
111  for (const auto & elem : candidate_elements)
112  {
113  const int elem_n_nodes = elem->n_nodes();
114  const Real hmax = elem->hmax();
115  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
116 
117  for (int n=0; n != elem_n_nodes; ++n)
118  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
119  return elem->node_ptr(n);
120  }
121 
122  return nullptr;
123 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * operator()(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const =0

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

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

Definition at line 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects

◆ operator()() [1/2]

virtual const Elem* libMesh::PointLocatorBase::operator() ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = 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().

◆ operator()() [2/2]

virtual void libMesh::PointLocatorBase::operator() ( const Point p,
std::set< const Elem *> &  candidate_elements,
const std::set< subdomain_id_type > *  allowed_subdomains = 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.

◆ print_info()

void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

Definition at line 87 of file reference_counter.C.

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

88 {
90  out_stream << ReferenceCounter::get_info();
91 }
static std::string get_info()

◆ set_close_to_point_tol()

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

83 {
85  _close_to_point_tol = close_to_point_tol;
86 }

◆ unset_close_to_point_tol()

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 89 of file point_locator_base.C.

References _close_to_point_tol, _use_close_to_point_tol, and libMesh::TOLERANCE.

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

Member Data Documentation

◆ _close_to_point_tol

Real libMesh::PointLocatorBase::_close_to_point_tol
protected

The tolerance to use.

Definition at line 207 of file point_locator_base.h.

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

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _enable_print_counter

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 141 of file reference_counter.h.

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

◆ _initialized

bool libMesh::PointLocatorBase::_initialized
protected

true when properly initialized, false otherwise.

Definition at line 196 of file point_locator_base.h.

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

◆ _master

const PointLocatorBase* libMesh::PointLocatorBase::_master
protected

Const pointer to our master, initialized to nullptr 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 186 of file point_locator_base.h.

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

◆ _mesh

const MeshBase& libMesh::PointLocatorBase::_mesh
protected

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

Definition at line 191 of file point_locator_base.h.

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

◆ _mutex

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

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 130 of file reference_counter.h.

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

◆ _use_close_to_point_tol

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

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

◆ _verbose

bool libMesh::PointLocatorBase::_verbose

Boolean flag to indicate whether to print out extra info.

Definition at line 178 of file point_locator_base.h.

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


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