libMesh
point_locator_base.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
26 namespace libMesh
27 {
28 
29 
30 
31 
32 //------------------------------------------------------------------
33 // PointLocatorBase methods
35  const PointLocatorBase * master) :
36  _verbose (false),
37  _master (master),
38  _mesh (mesh),
39  _initialized (false),
40  _use_close_to_point_tol (false),
41  _close_to_point_tol (TOLERANCE)
42 {
43  // If we have a non-nullptr master, inherit its close-to-point tolerances.
44  if (_master)
45  {
48  }
49 }
50 
51 
52 
54 {
55 }
56 
57 
58 
60 {
61  return this->_initialized;
62 }
63 
64 
65 
66 std::unique_ptr<PointLocatorBase> PointLocatorBase::build (PointLocatorType t,
67  const MeshBase & mesh,
68  const PointLocatorBase * master)
69 {
70  switch (t)
71  {
72  case TREE:
73  return libmesh_make_unique<PointLocatorTree>(mesh, /*Trees::NODES,*/ master);
74 
75  case TREE_ELEMENTS:
76  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::ELEMENTS, master);
77 
79  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::LOCAL_ELEMENTS, master);
80 
81  default:
82  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
83  }
84 }
85 
87 {
88  return _close_to_point_tol;
89 }
90 
91 
93 {
95  _close_to_point_tol = close_to_point_tol;
96 }
97 
98 
100 {
101  _use_close_to_point_tol = false;
103 }
104 
105 
107 {
108  return _mesh;
109 }
110 
111 
112 const Node *
114 locate_node(const Point & p,
115  const std::set<subdomain_id_type> * allowed_subdomains,
116  Real tol) const
117 {
118  std::set<const Elem *> candidate_elements;
119  this->operator()(p, candidate_elements, allowed_subdomains);
120 
121  for (const auto & elem : candidate_elements)
122  {
123  const int elem_n_nodes = elem->n_nodes();
124  const Real hmax = elem->hmax();
125  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
126 
127  for (int n=0; n != elem_n_nodes; ++n)
128  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
129  return elem->node_ptr(n);
130  }
131 
132  return nullptr;
133 }
134 
135 } // namespace libMesh
libMesh::TREE_LOCAL_ELEMENTS
Definition: enum_point_locator_type.h:38
libMesh::TREE
Definition: enum_point_locator_type.h:36
libMesh::PointLocatorBase::_master
const PointLocatorBase * _master
Const pointer to our master, initialized to nullptr if none given.
Definition: point_locator_base.h:191
libMesh::Trees::LOCAL_ELEMENTS
Definition: tree_base.h:57
libMesh::PointLocatorBase::set_close_to_point_tol
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.
Definition: point_locator_base.C:92
libMesh::TREE_ELEMENTS
Definition: enum_point_locator_type.h:37
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::PointLocatorBase::_close_to_point_tol
Real _close_to_point_tol
The tolerance to use.
Definition: point_locator_base.h:212
libMesh::PointLocatorBase::get_close_to_point_tol
Real get_close_to_point_tol() const
Get the close-to-point tolerance.
Definition: point_locator_base.C:86
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::PointLocatorBase::_use_close_to_point_tol
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element.
Definition: point_locator_base.h:207
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::PointLocatorBase::build
static std::unique_ptr< PointLocatorBase > build(PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=nullptr)
Builds an PointLocator for the mesh mesh.
Definition: point_locator_base.C:66
libMesh::PointLocatorBase::operator()
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.
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::PointLocatorBase::initialized
bool initialized() const
Definition: point_locator_base.C:59
libMesh::PointLocatorBase::locate_node
virtual const Node * locate_node(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr, Real tol=TOLERANCE) const
Definition: point_locator_base.C:114
libMesh::PointLocatorBase::get_mesh
const MeshBase & get_mesh() const
Get a const reference to this PointLocator's mesh.
Definition: point_locator_base.C:106
libMesh::TensorTools::norm_sq
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:85
libMesh::PointLocatorBase::~PointLocatorBase
virtual ~PointLocatorBase()
Destructor.
Definition: point_locator_base.C:53
libMesh::PointLocatorBase::_mesh
const MeshBase & _mesh
constant reference to the mesh in which the point is looked for.
Definition: point_locator_base.h:196
libMesh::PointLocatorType
PointLocatorType
Definition: enum_point_locator_type.h:35
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::PointLocatorBase::unset_close_to_point_tol
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...
Definition: point_locator_base.C:99
libMesh::PointLocatorBase
This is the base class for point locators.
Definition: point_locator_base.h:62
libMesh::PointLocatorBase::_initialized
bool _initialized
true when properly initialized, false otherwise.
Definition: point_locator_base.h:201
libMesh::Trees::ELEMENTS
Definition: tree_base.h:56
libMesh::PointLocatorBase::PointLocatorBase
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
Constructor.
Definition: point_locator_base.C:34