libMesh
point_locator_base.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 // C++ includes
21 
22 
23 // Local Includes
24 #include "libmesh/point_locator_base.h"
25 #include "libmesh/point_locator_tree.h"
26 
27 #include "libmesh/elem.h"
28 
29 namespace libMesh
30 {
31 
32 
33 
34 
35 //------------------------------------------------------------------
36 // PointLocatorBase methods
38  const PointLocatorBase * master) :
39  _verbose (false),
40  _master (master),
41  _mesh (mesh),
42  _initialized (false),
43  _use_close_to_point_tol (false),
44  _close_to_point_tol (TOLERANCE)
45 {
46 }
47 
48 
49 
50 
51 
53 {
54 }
55 
56 
57 
59 {
60  return this->_initialized;
61 }
62 
63 
64 
66  const MeshBase & mesh,
67  const PointLocatorBase * master)
68 {
69  switch (t)
70  {
71  case TREE:
72  return UniquePtr<PointLocatorBase>(new PointLocatorTree(mesh, /*Trees::NODES,*/ master));
73 
74  case TREE_ELEMENTS:
76 
79 
80  default:
81  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
82  }
83 
84  libmesh_error_msg("We'll never get here!");
86 }
87 
89 {
91  _close_to_point_tol = close_to_point_tol;
92 }
93 
94 
96 {
99 }
100 
101 
102 const Node *
104 locate_node(const Point & p,
105  const std::set<subdomain_id_type> * allowed_subdomains,
106  Real tol) const
107 {
108  std::set<const Elem *> candidate_elements;
109  this->operator()(p, candidate_elements, allowed_subdomains);
110 
111  for (std::set<const Elem *>::const_iterator
112  it = candidate_elements.begin();
113  it != candidate_elements.end(); ++it)
114  {
115  const Elem * elem = *it;
116  const int elem_n_nodes = elem->n_nodes();
117  const Real hmax = elem->hmax();
118  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
119 
120  for (int n=0; n != elem_n_nodes; ++n)
121  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
122  return elem->node_ptr(n);
123  }
124 
125  return libmesh_nullptr;
126 }
127 
128 } // namespace libMesh
virtual ~PointLocatorBase()
Destructor.
A Node is like a Point, but with more information.
Definition: node.h:52
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.
This is a point locator.
bool _use_close_to_point_tol
true if we will use a user-specified tolerance for locating the element.
Real _close_to_point_tol
The tolerance to use.
virtual const Elem * operator()(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr) const =0
Locates the element in which the point with global coordinates p is located.
PointLocatorType
defines an enum for the types of point locators (given a point with global coordinates, locate the corresponding element in space) available in libMesh.
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
bool _initialized
true when properly initialized, false otherwise.
MeshBase & mesh
const class libmesh_nullptr_t libmesh_nullptr
static const Real TOLERANCE
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:68
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual unsigned int n_nodes() const =0
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1874
virtual const Node * locate_node(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr, Real tol=TOLERANCE) const
This is the base class for point locators.
static UniquePtr< PointLocatorBase > build(PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=libmesh_nullptr)
Builds an PointLocator for the mesh mesh.
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
Constructor.
virtual Real hmax() const
Definition: elem.C:475
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & point(const unsigned int i) const
Definition: elem.h:1809
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:38