libMesh
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
libMesh::PointLocatorTree Class Reference

This is a point locator. More...

#include <point_locator_tree.h>

Inheritance diagram for libMesh::PointLocatorTree:
[legend]

Public Member Functions

 PointLocatorTree (const MeshBase &mesh, const PointLocatorBase *master=nullptr)
 Constructor. More...
 
 PointLocatorTree (const MeshBase &mesh, const Trees::BuildType build_type, const PointLocatorBase *master=nullptr)
 Constructor. More...
 
 ~PointLocatorTree ()
 Destructor. More...
 
virtual void clear () override final
 Clears the locator. More...
 
void init (Trees::BuildType build_type)
 Initializes the locator, so that the operator() methods can be used. More...
 
virtual void init () override final
 Initializes the locator, so that the operator() methods can be used. More...
 
virtual const Elemoperator() (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const override final
 Locates the element in which the point with global coordinates p is located, optionally restricted to a set of allowed subdomains. More...
 
virtual void operator() (const Point &p, std::set< const Elem *> &candidate_elements, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const override final
 Locates a set of elements in proximity to the point with global coordinates p Pure virtual. More...
 
const Elemperform_linear_search (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains, bool use_close_to_point, Real close_to_point_tolerance=TOLERANCE) const
 As a fallback option, it's helpful to be able to do a linear search over the entire mesh. More...
 
std::set< const Elem * > perform_fuzzy_linear_search (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains, Real close_to_point_tolerance=TOLERANCE) const
 A method to check if "fat" point p is in multiple elements. More...
 
virtual void enable_out_of_mesh_mode () override final
 Enables out-of-mesh mode. More...
 
virtual void disable_out_of_mesh_mode () override final
 Disables out-of-mesh mode (default). More...
 
void set_target_bin_size (unsigned int target)
 Set the target bin size. More...
 
unsigned int get_target_bin_size () const
 Get the target bin size. More...
 
virtual const Nodelocate_node (const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr, Real tol=TOLERANCE) const
 
bool initialized () const
 
Real get_close_to_point_tol () const
 Get the close-to-point tolerance. 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...
 
virtual void set_contains_point_tol (Real contains_point_tol)
 Set a tolerance to use when checking if a point is within an element in the mesh. More...
 
virtual void unset_contains_point_tol ()
 Specify that we do not want to use a user-specified tolerance to determine if a point is inside an element in the mesh. More...
 
virtual Real get_contains_point_tol () const
 Get the tolerance for determining element containment in the point locator. More...
 
bool get_use_contains_point_tol () const
 The contains_point_tol may be nonzero (in fact it defaults to non-zero) but unless the user calls set_contains_point_tol(), it won't actually be used. More...
 
const MeshBaseget_mesh () const
 Get a const reference to this PointLocator's mesh. More...
 
bool get_verbose () const
 Get the verbosity setting (whether to print extra info to screen, default false) for this PointLocator. More...
 
void set_verbose (bool verbosity)
 Set the verbosity setting for this PointLocator. More...
 
void libmesh_assert_valid_point_locator ()
 Verifies that, for every node of every element, the point locator finds that element when searching at that node. More...
 

Static Public Member Functions

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

Protected Types

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

Protected Member Functions

void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. More...
 

Protected Attributes

std::shared_ptr< TreeBase_tree
 Pointer to our tree. More...
 
const Elem_element
 Pointer to the last element that was found by the tree. More...
 
bool _out_of_mesh_mode
 true if out-of-mesh mode is enabled. More...
 
unsigned int _target_bin_size
 Target bin size, which gets passed to the constructor of _tree. More...
 
Trees::BuildType _build_type
 How the underlying tree is built. More...
 
bool _verbose
 Boolean flag to indicate whether to print out extra info. More...
 
const PointLocatorBase_master
 Const pointer to our master, initialized to nullptr 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 in an exhaustive search. More...
 
Real _close_to_point_tol
 The tolerance to use. More...
 
bool _use_contains_point_tol
 true if we will use a user-specified tolerance for locating the element. More...
 
Real _contains_point_tol
 The tolerance to use when locating an element in the tree. 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 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
Date
2003

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

Constructor & Destructor Documentation

◆ PointLocatorTree() [1/2]

libMesh::PointLocatorTree::PointLocatorTree ( const MeshBase mesh,
const PointLocatorBase master = nullptr 
)

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

38  :
39  PointLocatorBase (mesh,master),
40  _tree (nullptr),
41  _element (nullptr),
42  _out_of_mesh_mode(false),
43  _target_bin_size (200),
45 {
46  this->init(_build_type);
47 }
virtual void init() override final
Initializes the locator, so that the operator() methods can be used.
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
MeshBase & mesh
const Elem * _element
Pointer to the last element that was found by the tree.
Trees::BuildType _build_type
How the underlying tree is built.
unsigned int _target_bin_size
Target bin size, which gets passed to the constructor of _tree.
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
Constructor.

◆ PointLocatorTree() [2/2]

libMesh::PointLocatorTree::PointLocatorTree ( const MeshBase mesh,
const Trees::BuildType  build_type,
const PointLocatorBase master = nullptr 
)

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 51 of file point_locator_tree.C.

References _build_type, and init().

53  :
54  PointLocatorBase (mesh,master),
55  _tree (nullptr),
56  _element (nullptr),
57  _out_of_mesh_mode(false),
58  _target_bin_size (200),
59  _build_type(build_type)
60 {
61  this->init(_build_type);
62 }
virtual void init() override final
Initializes the locator, so that the operator() methods can be used.
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
MeshBase & mesh
const Elem * _element
Pointer to the last element that was found by the tree.
Trees::BuildType _build_type
How the underlying tree is built.
unsigned int _target_bin_size
Target bin size, which gets passed to the constructor of _tree.
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
Constructor.

◆ ~PointLocatorTree()

libMesh::PointLocatorTree::~PointLocatorTree ( )
default

Destructor.

Member Function Documentation

◆ build()

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

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

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

Referenced by libMesh::MeshBase::sub_point_locator().

71 {
72  switch (t)
73  {
74  case TREE:
75  return std::make_unique<PointLocatorTree>(mesh, /*Trees::NODES,*/ master);
76 
77  case TREE_ELEMENTS:
78  return std::make_unique<PointLocatorTree>(mesh, Trees::ELEMENTS, master);
79 
81  return std::make_unique<PointLocatorTree>(mesh, Trees::LOCAL_ELEMENTS, master);
82 
83 #ifdef LIBMESH_HAVE_NANOFLANN
84  case NANOFLANN:
85  return std::make_unique<PointLocatorNanoflann>(mesh, master);
86 #endif
87 
88  default:
89  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
90  }
91 }
MeshBase & mesh

◆ clear()

void libMesh::PointLocatorTree::clear ( )
finaloverridevirtual

Clears the locator.

This function frees dynamic memory with "delete".

Implements libMesh::PointLocatorBase.

Definition at line 70 of file point_locator_tree.C.

References libMesh::PointLocatorBase::_initialized, and _tree.

71 {
72  this->_initialized = false;
73 
74  // reset() actually frees the memory if we are master, otherwise it
75  // just reduces the ref. count.
76  _tree.reset();
77 }
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
bool _initialized
true when properly initialized, false otherwise.

◆ disable_out_of_mesh_mode()

void libMesh::PointLocatorTree::disable_out_of_mesh_mode ( )
finaloverridevirtual

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 347 of file point_locator_tree.C.

References _out_of_mesh_mode.

348 {
349  _out_of_mesh_mode = false;
350 }
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ enable_out_of_mesh_mode()

void libMesh::PointLocatorTree::enable_out_of_mesh_mode ( )
finaloverridevirtual

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 nullptr instead of crashing. Per default, this mode is off.

Implements libMesh::PointLocatorBase.

Definition at line 339 of file point_locator_tree.C.

References _out_of_mesh_mode.

Referenced by InfFERadialTest::testRefinement().

340 {
341  // Out-of-mesh mode should now work properly even on meshes with
342  // non-affine elements.
343  _out_of_mesh_mode = true;
344 }
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Enabled by default.

Definition at line 94 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ get_close_to_point_tol()

Real libMesh::PointLocatorBase::get_close_to_point_tol ( ) const
inherited

Get the close-to-point tolerance.

Definition at line 93 of file point_locator_base.C.

References libMesh::PointLocatorBase::_close_to_point_tol.

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

94 {
95  return _close_to_point_tol;
96 }
Real _close_to_point_tol
The tolerance to use.

◆ get_contains_point_tol()

Real libMesh::PointLocatorBase::get_contains_point_tol ( ) const
virtualinherited

Get the tolerance for determining element containment in the point locator.

Definition at line 123 of file point_locator_base.C.

References libMesh::PointLocatorBase::_contains_point_tol.

124 {
125  return _contains_point_tol;
126 }
Real _contains_point_tol
The tolerance to use when locating an element in the tree.

◆ 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 & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
static Counts _counts
Actually holds the data.

◆ get_mesh()

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

Get a const reference to this PointLocator's mesh.

Definition at line 128 of file point_locator_base.C.

References libMesh::PointLocatorBase::_mesh.

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

129 {
130  return _mesh;
131 }
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.

◆ get_target_bin_size()

unsigned int libMesh::PointLocatorTree::get_target_bin_size ( ) const

Get the target bin size.

Definition at line 359 of file point_locator_tree.C.

References _target_bin_size.

Referenced by init().

360 {
361  return _target_bin_size;
362 }
unsigned int _target_bin_size
Target bin size, which gets passed to the constructor of _tree.

◆ get_use_contains_point_tol()

bool libMesh::PointLocatorBase::get_use_contains_point_tol ( ) const
inlineinherited

The contains_point_tol may be nonzero (in fact it defaults to non-zero) but unless the user calls set_contains_point_tol(), it won't actually be used.

This const accessor can be used to determine the current status of this flag.

Definition at line 192 of file point_locator_base.h.

References libMesh::PointLocatorBase::_use_contains_point_tol.

192 { return _use_contains_point_tol; }
bool _use_contains_point_tol
true if we will use a user-specified tolerance for locating the element.

◆ get_verbose()

bool libMesh::PointLocatorBase::get_verbose ( ) const
inlineinherited

Get the verbosity setting (whether to print extra info to screen, default false) for this PointLocator.

Definition at line 203 of file point_locator_base.h.

References libMesh::PointLocatorBase::_verbose.

203 { return _verbose; }
bool _verbose
Boolean flag to indicate whether to print out extra info.

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

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

Definition at line 183 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

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

Definition at line 207 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ init() [1/2]

void libMesh::PointLocatorTree::init ( 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 88 of file point_locator_tree.C.

References _build_type, _element, libMesh::PointLocatorBase::_initialized, libMesh::PointLocatorBase::_master, libMesh::PointLocatorBase::_mesh, _tree, libMesh::MeshTools::create_bounding_box(), libMesh::err, get_target_bin_size(), libMesh::PointLocatorBase::initialized(), libMesh::libmesh_assert(), and libMesh::Real.

89 {
90  libmesh_assert (!this->_tree);
91 
92  if (this->_initialized)
93  {
94  // Warn that we are already initialized
95  libMesh::err << "Warning: PointLocatorTree already initialized! Will ignore this call..." << std::endl;
96 
97  // Further warn if we try to init() again with a different build_type
98  if (_build_type != build_type)
99  {
100  libMesh::err << "Warning: PointLocatorTree is using build_type = " << _build_type << ".\n"
101  << "Your requested build_type, " << build_type << " will not be used!" << std::endl;
102  }
103  }
104 
105  else
106  {
107  // Let the requested build_type override the _build_type we were
108  // constructed with. This is no big deal since we have not been
109  // initialized before.
110  _build_type = build_type;
111 
112  if (this->_master == nullptr)
113  {
114  LOG_SCOPE("init(no master)", "PointLocatorTree");
115 
116  if (LIBMESH_DIM == 1)
117  _tree = std::make_shared<Trees::BinaryTree>(this->_mesh, get_target_bin_size(), _build_type);
118  else if (LIBMESH_DIM == 2)
119  _tree = std::make_shared<Trees::QuadTree>(this->_mesh, get_target_bin_size(), _build_type);
120  else if (this->_mesh.mesh_dimension() == 3) // && LIBMESH_DIM==3
121  _tree = std::make_shared<Trees::OctTree>(this->_mesh, get_target_bin_size(), _build_type);
122  else
123  {
124  // LIBMESH_DIM==3 but we have a mesh with only 1D/2D
125  // elements, which needs special consideration. If the
126  // mesh is planar XY, we want to build a QuadTree to
127  // search efficiently. If the mesh is truly a manifold,
128  // then we need an octree
129  bool is_planar_xy = false;
130 
131  // Build the bounding box for the mesh. If the delta-z bound is
132  // negligibly small then we can use a quadtree.
133  BoundingBox bbox = MeshTools::create_bounding_box(this->_mesh);
134 
135  const Real
136  Dx = bbox.second(0) - bbox.first(0),
137  Dz = bbox.second(2) - bbox.first(2);
138 
139  // In order to satisfy is_planar_xy the mesh should be planar and should
140  // also be in the z=0 plane, since otherwise it is incorrect to use a
141  // QuadTree since QuadTrees assume z=0.
142  if ( (std::abs(Dz/(Dx + 1.e-20)) < 1e-10) && (std::abs(bbox.second(2)) < 1.e-10) )
143  is_planar_xy = true;
144 
145  if (is_planar_xy)
146  _tree = std::make_shared<Trees::QuadTree>(this->_mesh, get_target_bin_size(), _build_type);
147  else
148  _tree = std::make_shared<Trees::OctTree>(this->_mesh, get_target_bin_size(), _build_type);
149  }
150  }
151 
152  else
153  {
154  // We are _not_ the master. Let our Tree point to
155  // the master's tree. But for this we first transform
156  // the master in a state for which we are friends.
157  // And make sure the master has a tree!
158  const PointLocatorTree * my_master =
159  cast_ptr<const PointLocatorTree *>(this->_master);
160 
161  if (my_master->initialized())
162  this->_tree = my_master->_tree;
163  else
164  libmesh_error_msg("ERROR: Initialize master first, then servants!");
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 = nullptr;
174  }
175 
176  // ready for take-off
177  this->_initialized = true;
178 
179  // This may be too expensive to use even in debug mode, but it's
180  // helpful to uncomment for debugging.
181  // this->libmesh_assert_valid_point_locator();
182 }
OStreamProxy err
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
Definition: mesh_tools.C:566
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
unsigned int get_target_bin_size() const
Get the target bin size.
bool _initialized
true when properly initialized, false otherwise.
const Elem * _element
Pointer to the last element that was found by the tree.
PointLocatorTree(const MeshBase &mesh, const PointLocatorBase *master=nullptr)
Constructor.
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
libmesh_assert(ctx)
Trees::BuildType _build_type
How the underlying tree is built.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const PointLocatorBase * _master
Const pointer to our master, initialized to nullptr if none given.

◆ init() [2/2]

void libMesh::PointLocatorTree::init ( )
finaloverridevirtual

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

This function allocates dynamic memory with "new".

Implements libMesh::PointLocatorBase.

Definition at line 81 of file point_locator_tree.C.

References _build_type.

Referenced by PointLocatorTree().

82 {
83  this->init(_build_type);
84 }
virtual void init() override final
Initializes the locator, so that the operator() methods can be used.
Trees::BuildType _build_type
How the underlying tree is built.

◆ initialized()

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

Definition at line 61 of file point_locator_base.C.

References libMesh::PointLocatorBase::_initialized.

Referenced by init(), and libMesh::MeshFunction::MeshFunction().

62 {
63  return this->_initialized;
64 }
bool _initialized
true when properly initialized, false otherwise.

◆ libmesh_assert_valid_point_locator()

void libMesh::PointLocatorBase::libmesh_assert_valid_point_locator ( )
inherited

Verifies that, for every node of every element, the point locator finds that element when searching at that node.

This is an O(N log N) operation, and so only available in builds with NDEBUG undefined, for asserting internal consistency (the PointLocator works) and external consistency (user code didn't change the mesh without updating the PointLocator afterward) that we hope should never be broken in opt.

Definition at line 159 of file point_locator_base.C.

References libMesh::PointLocatorBase::_mesh, libMesh::LAGRANGE_MAP, libMesh::libmesh_assert(), libMesh::make_range(), and libMesh::PointLocatorBase::operator()().

160 {
161  // We might only have been built with TREE_LOCAL_ELEMENTS as an
162  // option; let's just check local elements to be safe.
163  for (const Elem * elem : this->_mesh.active_local_element_ptr_range())
164  {
165  // For non-Lagrange mappings, we might have nodes that are
166  // really control points, not contained in the element they
167  // define; we can only safely check containment of vertices.
168  auto range = make_range(0u, (elem->mapping_type() == LAGRANGE_MAP) ?
169  elem->n_nodes() : elem->n_vertices());
170 
171  for (auto n : range)
172  {
173  const Node & node = elem->node_ref(n);
174  std::set<const Elem *> candidate_elements;
175  this->operator()(node, candidate_elements);
176  libmesh_assert(candidate_elements.count(elem));
177  }
178  }
179 }
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:176
virtual const Elem * operator()(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr) const =0
Locates the element in which the point with global coordinates p is located.

◆ locate_node()

const Node * libMesh::PointLocatorBase::locate_node ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = nullptr,
Real  tol = TOLERANCE 
) const
virtualinherited
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 136 of file point_locator_base.C.

References libMesh::TensorTools::norm_sq(), libMesh::PointLocatorBase::operator()(), and libMesh::Real.

139 {
140  std::set<const Elem *> candidate_elements;
141  this->operator()(p, candidate_elements, allowed_subdomains);
142 
143  for (const auto & elem : candidate_elements)
144  {
145  const int elem_n_nodes = elem->n_nodes();
146  const Real hmax = elem->hmax();
147  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
148 
149  for (int n=0; n != elem_n_nodes; ++n)
150  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
151  return elem->node_ptr(n);
152  }
153 
154  return nullptr;
155 }
auto norm_sq(const T &a)
Definition: tensor_tools.h:104
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
Locates the element in which the point with global coordinates p is located.

◆ n_objects()

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

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

Definition at line 85 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

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

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ operator()() [1/2]

const Elem * libMesh::PointLocatorTree::operator() ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains = nullptr 
) const
finaloverridevirtual

Locates the element in which the point with global coordinates p is located, optionally restricted to a set of allowed subdomains.

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 184 of file point_locator_tree.C.

References libMesh::PointLocatorBase::_close_to_point_tol, libMesh::PointLocatorBase::_contains_point_tol, _element, libMesh::PointLocatorBase::_initialized, _out_of_mesh_mode, _tree, libMesh::PointLocatorBase::_use_close_to_point_tol, libMesh::PointLocatorBase::_use_contains_point_tol, libMesh::PointLocatorBase::_verbose, libMesh::Elem::active(), libMesh::Elem::close_to_point(), libMesh::Elem::contains_point(), libMesh::libmesh_assert(), libMesh::out, and perform_linear_search().

186 {
188 
189  LOG_SCOPE("operator()", "PointLocatorTree");
190 
191  // If we're provided with an allowed_subdomains list and have a cached element, make sure it complies
192  if (allowed_subdomains && this->_element && !allowed_subdomains->count(this->_element->subdomain_id()))
193  this->_element = nullptr;
194 
195  if (this->_element != nullptr)
196  {
197  // If the user specified a custom tolerance, we actually call
198  // Elem::close_to_point() instead, since Elem::contains_point()
199  // warns about using non-default BoundingBox tolerances.
201  this->_element = nullptr;
202 
203  // Otherwise, just call contains_point(p) with default tolerances.
204  else if (!(this->_element->contains_point(p)))
205  this->_element = nullptr;
206  }
207 
208  // First check the element from last time before asking the tree
209  if (this->_element==nullptr)
210  {
211  // ask the tree
213  this->_element = this->_tree->find_element(p, allowed_subdomains, _contains_point_tol);
214  else
215  this->_element = this->_tree->find_element(p, allowed_subdomains);
216 
217  if (this->_element == nullptr)
218  {
219  // If we haven't found the element, we may want to do a linear
220  // search using a tolerance.
222  {
223  if (_verbose)
224  {
225  libMesh::out << "Performing linear search using close-to-point tolerance "
227  << std::endl;
228  }
229 
230  this->_element =
231  this->perform_linear_search(p,
232  allowed_subdomains,
233  /*use_close_to_point*/ true,
235 
236  return this->_element;
237  }
238 
239  // No element seems to contain this point. In theory, our
240  // tree now correctly handles curved elements. In
241  // out-of-mesh mode this is sometimes expected, and we can
242  // just return nullptr without searching further. Out of
243  // out-of-mesh mode, something must have gone wrong.
244  libmesh_assert_equal_to (_out_of_mesh_mode, true);
245 
246  return this->_element;
247  }
248  }
249 
250  // If we found an element, it should be active
251  libmesh_assert (!this->_element || this->_element->active());
252 
253  // If we found an element and have a restriction list, they better match
254  libmesh_assert (!this->_element || !allowed_subdomains || allowed_subdomains->count(this->_element->subdomain_id()));
255 
256  // return the element
257  return this->_element;
258 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element in an exhaustive search...
Real _close_to_point_tol
The tolerance to use.
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
bool _initialized
true when properly initialized, false otherwise.
const Elem * _element
Pointer to the last element that was found by the tree.
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2784
libmesh_assert(ctx)
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
virtual bool close_to_point(const Point &p, Real tol) const
Definition: elem.C:2809
bool _verbose
Boolean flag to indicate whether to print out extra info.
OStreamProxy out
const Elem * perform_linear_search(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains, bool use_close_to_point, Real close_to_point_tolerance=TOLERANCE) const
As a fallback option, it&#39;s helpful to be able to do a linear search over the entire mesh...
bool active() const
Definition: elem.h:2955
bool _use_contains_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.

◆ operator()() [2/2]

void libMesh::PointLocatorTree::operator() ( const Point p,
std::set< const Elem *> &  candidate_elements,
const std::set< subdomain_id_type > *  allowed_subdomains = nullptr 
) const
finaloverridevirtual

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.

Implements libMesh::PointLocatorBase.

Definition at line 261 of file point_locator_tree.C.

References libMesh::PointLocatorBase::_close_to_point_tol, libMesh::PointLocatorBase::_initialized, _tree, and libMesh::libmesh_assert().

264 {
266 
267  LOG_SCOPE("operator() - Version 2", "PointLocatorTree");
268 
269  // ask the tree
270  this->_tree->find_elements (p, candidate_elements, allowed_subdomains, _close_to_point_tol);
271 }
Real _close_to_point_tol
The tolerance to use.
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
bool _initialized
true when properly initialized, false otherwise.
libmesh_assert(ctx)

◆ perform_fuzzy_linear_search()

std::set< const Elem * > libMesh::PointLocatorTree::perform_fuzzy_linear_search ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains,
Real  close_to_point_tolerance = TOLERANCE 
) const

A method to check if "fat" point p is in multiple elements.

This would happen if p is close to a face or node. This is important for evaluating MeshFunction on faces when discontinuous shape functions are used.

Definition at line 313 of file point_locator_tree.C.

References _build_type, libMesh::PointLocatorBase::_mesh, and libMesh::Trees::LOCAL_ELEMENTS.

316 {
317  LOG_SCOPE("perform_fuzzy_linear_search", "PointLocatorTree");
318 
319  std::set<const Elem *> candidate_elements;
320 
321  // The type of iterator depends on the Trees::BuildType
322  // used for this PointLocator. If it's
323  // TREE_LOCAL_ELEMENTS, we only want to double check
324  // local elements during this linear search.
325  SimpleRange<MeshBase::const_element_iterator> r =
327  this->_mesh.active_local_element_ptr_range() :
328  this->_mesh.active_element_ptr_range();
329 
330  for (const auto & elem : r)
331  if ((!allowed_subdomains || allowed_subdomains->count(elem->subdomain_id())) && elem->close_to_point(p, close_to_point_tolerance))
332  candidate_elements.insert(elem);
333 
334  return candidate_elements;
335 }
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
Trees::BuildType _build_type
How the underlying tree is built.

◆ perform_linear_search()

const Elem * libMesh::PointLocatorTree::perform_linear_search ( const Point p,
const std::set< subdomain_id_type > *  allowed_subdomains,
bool  use_close_to_point,
Real  close_to_point_tolerance = TOLERANCE 
) const

As a fallback option, it's helpful to be able to do a linear search over the entire mesh.

This can be used if operator() fails to find an element that contains p, for example. Optionally specify a "close to point" tolerance to use in the linear search. Return nullptr if no element is found.

Definition at line 275 of file point_locator_tree.C.

References _build_type, libMesh::PointLocatorBase::_contains_point_tol, libMesh::PointLocatorBase::_mesh, and libMesh::Trees::LOCAL_ELEMENTS.

Referenced by operator()().

279 {
280  LOG_SCOPE("perform_linear_search", "PointLocatorTree");
281 
282  // The type of iterator depends on the Trees::BuildType
283  // used for this PointLocator. If it's
284  // TREE_LOCAL_ELEMENTS, we only want to double check
285  // local elements during this linear search.
286  SimpleRange<MeshBase::const_element_iterator> r =
288  this->_mesh.active_local_element_ptr_range() :
289  this->_mesh.active_element_ptr_range();
290 
291  for (const auto & elem : r)
292  {
293  if (!allowed_subdomains ||
294  allowed_subdomains->count(elem->subdomain_id()))
295  {
296  if (!use_close_to_point)
297  {
298  if (elem->contains_point(p, _contains_point_tol))
299  return elem;
300  }
301  else
302  {
303  if (elem->close_to_point(p, close_to_point_tolerance))
304  return elem;
305  }
306  }
307  }
308 
309  return nullptr;
310 }
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
Trees::BuildType _build_type
How the underlying tree is built.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.

◆ print_info()

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

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

Definition at line 81 of file reference_counter.C.

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

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

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
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...

◆ set_close_to_point_tol()

void libMesh::PointLocatorBase::set_close_to_point_tol ( Real  close_to_point_tol)
virtualinherited

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

Definition at line 99 of file point_locator_base.C.

References libMesh::PointLocatorBase::_close_to_point_tol, and libMesh::PointLocatorBase::_use_close_to_point_tol.

100 {
102  _close_to_point_tol = close_to_point_tol;
103 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element in an exhaustive search...
Real _close_to_point_tol
The tolerance to use.

◆ set_contains_point_tol()

void libMesh::PointLocatorBase::set_contains_point_tol ( Real  contains_point_tol)
virtualinherited

Set a tolerance to use when checking if a point is within an element in the mesh.

Definition at line 111 of file point_locator_base.C.

References libMesh::PointLocatorBase::_contains_point_tol, and libMesh::PointLocatorBase::_use_contains_point_tol.

112 {
114  _contains_point_tol = contains_point_tol;
115 }
bool _use_contains_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.

◆ set_target_bin_size()

void libMesh::PointLocatorTree::set_target_bin_size ( unsigned int  target)

Set the target bin size.

Definition at line 353 of file point_locator_tree.C.

References _target_bin_size.

354 {
355  _target_bin_size = target_bin_size;
356 }
unsigned int _target_bin_size
Target bin size, which gets passed to the constructor of _tree.

◆ set_verbose()

void libMesh::PointLocatorBase::set_verbose ( bool  verbosity)
inlineinherited

Set the verbosity setting for this PointLocator.

Definition at line 208 of file point_locator_base.h.

References libMesh::PointLocatorBase::_verbose.

208 { _verbose = verbosity; }
bool _verbose
Boolean flag to indicate whether to print out extra info.

◆ unset_close_to_point_tol()

void libMesh::PointLocatorBase::unset_close_to_point_tol ( )
virtualinherited

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

References libMesh::PointLocatorBase::_close_to_point_tol, libMesh::PointLocatorBase::_use_close_to_point_tol, and libMesh::TOLERANCE.

106 {
107  _use_close_to_point_tol = false;
109 }
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element in an exhaustive search...
static constexpr Real TOLERANCE
Real _close_to_point_tol
The tolerance to use.

◆ unset_contains_point_tol()

void libMesh::PointLocatorBase::unset_contains_point_tol ( )
virtualinherited

Specify that we do not want to use a user-specified tolerance to determine if a point is inside an element in the mesh.

Definition at line 117 of file point_locator_base.C.

References libMesh::PointLocatorBase::_contains_point_tol, libMesh::PointLocatorBase::_use_contains_point_tol, and libMesh::TOLERANCE.

118 {
119  _use_contains_point_tol = false;
121 }
static constexpr Real TOLERANCE
bool _use_contains_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.

Member Data Documentation

◆ _build_type

Trees::BuildType libMesh::PointLocatorTree::_build_type
protected

How the underlying tree is built.

Definition at line 195 of file point_locator_tree.h.

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

◆ _close_to_point_tol

Real libMesh::PointLocatorBase::_close_to_point_tol
protectedinherited

◆ _contains_point_tol

Real libMesh::PointLocatorBase::_contains_point_tol
protectedinherited

◆ _counts

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

Actually holds the data.

Definition at line 124 of file reference_counter.h.

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

◆ _element

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 179 of file point_locator_tree.h.

Referenced by init(), and operator()().

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

◆ _initialized

bool libMesh::PointLocatorBase::_initialized
protectedinherited

◆ _master

const PointLocatorBase* libMesh::PointLocatorBase::_master
protectedinherited

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

Referenced by init(), libMesh::PointLocatorNanoflann::init(), and libMesh::PointLocatorBase::PointLocatorBase().

◆ _mesh

const MeshBase& libMesh::PointLocatorBase::_mesh
protectedinherited

◆ _mutex

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.

◆ _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 132 of file reference_counter.h.

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

◆ _out_of_mesh_mode

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 185 of file point_locator_tree.h.

Referenced by disable_out_of_mesh_mode(), enable_out_of_mesh_mode(), and operator()().

◆ _target_bin_size

unsigned int libMesh::PointLocatorTree::_target_bin_size
protected

Target bin size, which gets passed to the constructor of _tree.

Definition at line 190 of file point_locator_tree.h.

Referenced by get_target_bin_size(), and set_target_bin_size().

◆ _tree

std::shared_ptr<TreeBase> libMesh::PointLocatorTree::_tree
protected

Pointer to our tree.

The tree is built at run-time through init(). For non-master PointLocators, this simply points to the tree of the master.

Definition at line 172 of file point_locator_tree.h.

Referenced by clear(), init(), and operator()().

◆ _use_close_to_point_tol

bool libMesh::PointLocatorBase::_use_close_to_point_tol
protectedinherited

true if we will use a user-specified tolerance for locating the element in an exhaustive search.

Definition at line 255 of file point_locator_base.h.

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

◆ _use_contains_point_tol

bool libMesh::PointLocatorBase::_use_contains_point_tol
protectedinherited

◆ _verbose

bool libMesh::PointLocatorBase::_verbose
protectedinherited

Boolean flag to indicate whether to print out extra info.

Definition at line 231 of file point_locator_base.h.

Referenced by libMesh::PointLocatorBase::get_verbose(), operator()(), and libMesh::PointLocatorBase::set_verbose().


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