point_locator_base.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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
23 #include "libmesh/elem.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 }
44 
45 
46 
47 
48 
50 {
51 }
52 
53 
54 
56 {
57  return this->_initialized;
58 }
59 
60 
61 
62 std::unique_ptr<PointLocatorBase> PointLocatorBase::build (PointLocatorType t,
63  const MeshBase & mesh,
64  const PointLocatorBase * master)
65 {
66  switch (t)
67  {
68  case TREE:
69  return libmesh_make_unique<PointLocatorTree>(mesh, /*Trees::NODES,*/ master);
70 
71  case TREE_ELEMENTS:
72  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::ELEMENTS, master);
73 
75  return libmesh_make_unique<PointLocatorTree>(mesh, Trees::LOCAL_ELEMENTS, master);
76 
77  default:
78  libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
79  }
80 }
81 
83 {
85  _close_to_point_tol = close_to_point_tol;
86 }
87 
88 
90 {
93 }
94 
95 
97 {
98  return _mesh;
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 (const auto & elem : candidate_elements)
112  {
113  const int elem_n_nodes = elem->n_nodes();
114  const Real hmax = elem->hmax();
115  const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
116 
117  for (int n=0; n != elem_n_nodes; ++n)
118  if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
119  return elem->node_ptr(n);
120  }
121 
122  return nullptr;
123 }
124 
125 } // namespace libMesh
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
virtual void set_close_to_point_tol(Real close_to_point_tol)
MeshBase & mesh
static const Real TOLERANCE
Base class for Mesh.
Definition: mesh_base.h:77
virtual const Node * locate_node(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=nullptr, Real tol=TOLERANCE) const
PointLocatorBase(const MeshBase &mesh, const PointLocatorBase *master)
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
virtual void unset_close_to_point_tol()
static std::unique_ptr< PointLocatorBase > build(PointLocatorType t, const MeshBase &mesh, const PointLocatorBase *master=nullptr)
A geometric point in (x,y,z) space.
Definition: point.h:38
const MeshBase & get_mesh() const