LCOV - code coverage report
Current view: top level - src/utils - point_locator_base.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 43 62 69.4 %
Date: 2025-08-19 19:27:09 Functions: 9 13 69.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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/point_locator_nanoflann.h"
      26             : 
      27             : namespace libMesh
      28             : {
      29             : 
      30             : 
      31             : 
      32             : 
      33             : //------------------------------------------------------------------
      34             : // PointLocatorBase methods
      35      500079 : PointLocatorBase::PointLocatorBase (const MeshBase & mesh,
      36      500079 :                                     const PointLocatorBase * master) :
      37      387481 :   _verbose                 (false),
      38      387481 :   _master                  (master),
      39      387481 :   _mesh                    (mesh),
      40      387481 :   _initialized             (false),
      41      387481 :   _use_close_to_point_tol  (false),
      42      387481 :   _close_to_point_tol      (TOLERANCE),
      43      387481 :   _use_contains_point_tol  (false),
      44      500079 :   _contains_point_tol      (TOLERANCE)
      45             : {
      46             :   // If we have a non-nullptr master, inherit its close-to-point tolerances.
      47      500079 :   if (_master)
      48             :     {
      49      487532 :       _use_close_to_point_tol = _master->_use_close_to_point_tol;
      50      487532 :       _close_to_point_tol = _master->_close_to_point_tol;
      51             :     }
      52      500079 : }
      53             : 
      54             : 
      55             : 
      56      387481 : PointLocatorBase::~PointLocatorBase () = default;
      57             : 
      58             : 
      59             : 
      60      488059 : bool PointLocatorBase::initialized () const
      61             : {
      62      488059 :   return this->_initialized;
      63             : }
      64             : 
      65             : 
      66             : 
      67      500073 : std::unique_ptr<PointLocatorBase> PointLocatorBase::build (PointLocatorType t,
      68             :                                                            const MeshBase & mesh,
      69             :                                                            const PointLocatorBase * master)
      70             : {
      71      500073 :   switch (t)
      72             :     {
      73           0 :     case TREE:
      74           0 :       return std::make_unique<PointLocatorTree>(mesh, /*Trees::NODES,*/ master);
      75             : 
      76      500073 :     case TREE_ELEMENTS:
      77      500073 :       return std::make_unique<PointLocatorTree>(mesh, Trees::ELEMENTS, master);
      78             : 
      79           0 :     case TREE_LOCAL_ELEMENTS:
      80           0 :       return std::make_unique<PointLocatorTree>(mesh, Trees::LOCAL_ELEMENTS, master);
      81             : 
      82             : #ifdef LIBMESH_HAVE_NANOFLANN
      83           0 :     case NANOFLANN:
      84           0 :       return std::make_unique<PointLocatorNanoflann>(mesh, master);
      85             : #endif
      86             : 
      87           0 :     default:
      88           0 :       libmesh_error_msg("ERROR: Bad PointLocatorType = " << t);
      89             :     }
      90             : }
      91             : 
      92         527 : Real PointLocatorBase::get_close_to_point_tol () const
      93             : {
      94         527 :   return _close_to_point_tol;
      95             : }
      96             : 
      97             : 
      98         598 : void PointLocatorBase::set_close_to_point_tol (Real close_to_point_tol)
      99             : {
     100         598 :   _use_close_to_point_tol = true;
     101         598 :   _close_to_point_tol = close_to_point_tol;
     102         598 : }
     103             : 
     104           0 : void PointLocatorBase::unset_close_to_point_tol ()
     105             : {
     106           0 :   _use_close_to_point_tol = false;
     107           0 :   _close_to_point_tol = TOLERANCE;
     108           0 : }
     109             : 
     110         598 : void PointLocatorBase::set_contains_point_tol(Real contains_point_tol)
     111             : {
     112         598 :   _use_contains_point_tol = true;
     113         598 :   _contains_point_tol = contains_point_tol;
     114         598 : }
     115             : 
     116           0 : void PointLocatorBase::unset_contains_point_tol()
     117             : {
     118           0 :   _use_contains_point_tol = false;
     119           0 :   _contains_point_tol = TOLERANCE;
     120           0 : }
     121             : 
     122           0 : Real PointLocatorBase::get_contains_point_tol() const
     123             : {
     124           0 :   return _contains_point_tol;
     125             : }
     126             : 
     127       61148 : const MeshBase & PointLocatorBase::get_mesh () const
     128             : {
     129       61148 :   return _mesh;
     130             : }
     131             : 
     132             : 
     133             : const Node *
     134       20874 : PointLocatorBase::
     135             : locate_node(const Point & p,
     136             :             const std::set<subdomain_id_type> * allowed_subdomains,
     137             :             Real tol) const
     138             : {
     139        1176 :   std::set<const Elem *> candidate_elements;
     140       20874 :   this->operator()(p, candidate_elements, allowed_subdomains);
     141             : 
     142       20874 :   for (const auto & elem : candidate_elements)
     143             :     {
     144       10919 :       const int elem_n_nodes = elem->n_nodes();
     145       10919 :       const Real hmax = elem->hmax();
     146       10919 :       const Real dist_tol_sq = (tol * hmax) * (tol * hmax);
     147             : 
     148       44420 :       for (int n=0; n != elem_n_nodes; ++n)
     149       46786 :         if ((elem->point(n) - p).norm_sq() < dist_tol_sq)
     150         588 :           return elem->node_ptr(n);
     151             :     }
     152             : 
     153           0 :   return nullptr;
     154             : }
     155             : 
     156             : } // namespace libMesh

Generated by: LCOV version 1.14