23#include "libmesh/elem.h"
24#include "libmesh/libmesh_logging.h"
25#include "libmesh/mesh_base.h"
26#include "libmesh/mesh_tools.h"
27#include "libmesh/point_locator_tree.h"
28#include "libmesh/tree.h"
42 _out_of_mesh_mode(false),
43 _target_bin_size (200),
44 _build_type(Trees::NODES)
57 _out_of_mesh_mode(false),
58 _target_bin_size (200),
59 _build_type(build_type)
95 libMesh::err <<
"Warning: PointLocatorTree already initialized! Will ignore this call..." << std::endl;
101 <<
"Your requested build_type, " << build_type <<
" will not be used!" << std::endl;
114 LOG_SCOPE(
"init(no master)",
"PointLocatorTree");
116 if (LIBMESH_DIM == 1)
118 else if (LIBMESH_DIM == 2)
129 bool is_planar_xy =
false;
136 Dx = bbox.second(0) - bbox.first(0),
137 Dz = bbox.second(2) - bbox.first(2);
142 if ( (std::abs(Dz/(Dx + 1.e-20)) < 1e-10) && (std::abs(bbox.second(2)) < 1.e-10) )
159 cast_ptr<const PointLocatorTree *>(this->
_master);
164 libmesh_error_msg(
"ERROR: Initialize master first, then servants!");
185 const std::set<subdomain_id_type> * allowed_subdomains)
const
189 LOG_SCOPE(
"operator()",
"PointLocatorTree");
192 if (allowed_subdomains && this->
_element && !allowed_subdomains->count(this->_element->subdomain_id()))
215 this->
_element = this->
_tree->find_element(p, allowed_subdomains);
225 libMesh::out <<
"Performing linear search using close-to-point tolerance "
254 libmesh_assert (!this->
_element || !allowed_subdomains || allowed_subdomains->count(this->_element->subdomain_id()));
262 std::set<const Elem *> & candidate_elements,
263 const std::set<subdomain_id_type> * allowed_subdomains)
const
267 LOG_SCOPE(
"operator() - Version 2",
"PointLocatorTree");
276 const std::set<subdomain_id_type> * allowed_subdomains,
277 bool use_close_to_point,
278 Real close_to_point_tolerance)
const
280 LOG_SCOPE(
"perform_linear_search",
"PointLocatorTree");
288 this->
_mesh.active_local_element_ptr_range() :
289 this->
_mesh.active_element_ptr_range();
291 for (
const auto & elem : r)
293 if (!allowed_subdomains ||
294 allowed_subdomains->count(elem->subdomain_id()))
296 if (!use_close_to_point)
303 if (elem->close_to_point(p, close_to_point_tolerance))
314 const std::set<subdomain_id_type> * allowed_subdomains,
315 Real close_to_point_tolerance)
const
317 LOG_SCOPE(
"perform_fuzzy_linear_search",
"PointLocatorTree");
319 std::set<const Elem *> candidate_elements;
327 this->
_mesh.active_local_element_ptr_range() :
328 this->
_mesh.active_element_ptr_range();
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);
334 return candidate_elements;
Defines a Cartesian bounding box by the two corner extremum.
This is the base class from which all geometric element types are derived.
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
virtual bool close_to_point(const Point &p, Real tol) const
This is the MeshBase class.
unsigned int mesh_dimension() const
This is the base class for point locators.
Real _close_to_point_tol
The tolerance to use.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.
bool _initialized
true when properly initialized, false otherwise.
bool _use_contains_point_tol
true if we will use a user-specified tolerance for locating the element.
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element in an exhaustive search.
bool _verbose
Boolean flag to indicate whether to print out extra info.
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
const PointLocatorBase * _master
Const pointer to our master, initialized to nullptr if none given.
unsigned int _target_bin_size
Target bin size, which gets passed to the constructor of _tree.
~PointLocatorTree()
Destructor.
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.
const Elem * _element
Pointer to the last element that was found by the tree.
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.
PointLocatorTree(const MeshBase &mesh, const PointLocatorBase *master=nullptr)
Constructor.
unsigned int get_target_bin_size() const
Get the target bin size.
void set_target_bin_size(unsigned int target)
Set the target bin size.
virtual const Elem * operator()(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...
std::shared_ptr< TreeBase > _tree
Pointer to our tree.
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's helpful to be able to do a linear search over the entire mesh.
virtual void clear() override final
Clears the locator.
virtual void enable_out_of_mesh_mode() override final
Enables out-of-mesh mode.
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
virtual void disable_out_of_mesh_mode() override final
Disables out-of-mesh mode (default).
A Point defines a location in LIBMESH_DIM dimensional Real space.
The SimpleRange templated class is intended to make it easy to construct ranges from pairs of iterato...
BuildType
enum defining how to build the tree.
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real