libMesh
Loading...
Searching...
No Matches
point_locator_base.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19
20// Local Includes
21#include "libmesh/point_locator_base.h"
22#include "libmesh/point_locator_tree.h"
23#include "libmesh/elem.h"
24#include "libmesh/enum_point_locator_type.h"
25#include "libmesh/mesh_base.h"
26#include "libmesh/point_locator_nanoflann.h"
27
28namespace libMesh
29{
30
31
32
33
34//------------------------------------------------------------------
35// PointLocatorBase methods
37 const PointLocatorBase * master) :
38 _verbose (false),
39 _master (master),
40 _mesh (mesh),
41 _initialized (false),
42 _use_close_to_point_tol (false),
43 _close_to_point_tol (TOLERANCE),
44 _use_contains_point_tol (false),
45 _contains_point_tol (TOLERANCE)
46{
47 // If we have a non-nullptr master, inherit its close-to-point tolerances.
48 if (_master)
49 {
52 }
53}
54
55
56
58
59
60
62{
63 return this->_initialized;
64}
65
66
67
68std::unique_ptr<PointLocatorBase> PointLocatorBase::build (PointLocatorType t,
69 const MeshBase & mesh,
70 const PointLocatorBase * master)
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}
92
97
98
100{
102 _close_to_point_tol = close_to_point_tol;
103}
104
110
112{
114 _contains_point_tol = contains_point_tol;
115}
116
122
127
129{
130 return _mesh;
131}
132
133
134const Node *
136locate_node(const Point & p,
137 const std::set<subdomain_id_type> * allowed_subdomains,
138 Real tol) const
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}
156
157
158#ifndef NDEBUG
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}
180#endif
181
182} // namespace libMesh
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the MeshBase class.
Definition mesh_base.h:81
A Node is like a Point, but with more information.
Definition node.h:55
This is the base class for point locators.
const MeshBase & get_mesh() const
Get a const reference to this PointLocator's mesh.
void libmesh_assert_valid_point_locator()
Verifies that, for every node of every element, the point locator finds that element when searching a...
virtual ~PointLocatorBase()
Destructor.
Real _close_to_point_tol
The tolerance to use.
Real _contains_point_tol
The tolerance to use when locating an element in the tree.
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 el...
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.
virtual const Node * locate_node(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr, Real tol=TOLERANCE) const
bool _initialized
true when properly initialized, false otherwise.
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.
static std::unique_ptr< PointLocatorBase > build(PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=nullptr)
Builds an PointLocator for the mesh mesh.
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.
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
Constructor.
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.
virtual Real get_contains_point_tol() const
Get the tolerance for determining element containment in the point locator.
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
Real get_close_to_point_tol() const
Get the close-to-point tolerance.
const PointLocatorBase * _master
Const pointer to our master, initialized to nullptr if none given.
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 wi...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)
static constexpr Real TOLERANCE
PointLocatorType
defines an enum for the types of point locators (given a point with global coordinates,...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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