LCOV - code coverage report
Current view: top level - src/other - PointLocatorRegularOrthogonal.C (source / functions) Hit Total Coverage
Test: idaholab/magpie: 5710af Lines: 34 37 91.9 %
Date: 2025-07-21 23:34:39 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**********************************************************************/
       2             : /*                     DO NOT MODIFY THIS HEADER                      */
       3             : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
       4             : /*                                                                    */
       5             : /*            Copyright 2017 Battelle Energy Alliance, LLC            */
       6             : /*                        ALL RIGHTS RESERVED                         */
       7             : /**********************************************************************/
       8             : 
       9             : #include "PointLocatorRegularOrthogonal.h"
      10             : #include "PointLocatorRegularOrthogonalData.h"
      11             : #include "MooseError.h"
      12             : 
      13             : #include "libmesh/elem.h"
      14             : #include "libmesh/mesh_base.h"
      15             : 
      16         583 : PointLocatorRegularOrthogonal::PointLocatorRegularOrthogonal(const MeshBase & mesh,
      17         583 :                                                              const PointLocatorBase * master)
      18         583 :   : PointLocatorBase(mesh, master), _out_of_mesh_mode(false), _data(nullptr)
      19             : {
      20         583 :   if (master != nullptr)
      21             :   {
      22             :     const PointLocatorRegularOrthogonal * my_master =
      23             :         cast_ptr<const PointLocatorRegularOrthogonal *>(master);
      24             : 
      25         482 :     if (!my_master->initialized())
      26           0 :       mooseError("Linking a slave point locator to an uninitialized master is not allowed.");
      27             : 
      28         482 :     _data = my_master->_data;
      29         482 :     _initialized = true;
      30             :   }
      31         583 : }
      32             : 
      33        1166 : PointLocatorRegularOrthogonal::~PointLocatorRegularOrthogonal() { this->clear(); }
      34             : 
      35             : void
      36         583 : PointLocatorRegularOrthogonal::clear()
      37             : {
      38             :   // only delete the root element table when we are the master
      39         583 :   if (this->_data != nullptr)
      40             :   {
      41         583 :     if (this->_master == nullptr)
      42             :       // we own the root element table
      43         101 :       delete this->_data;
      44             :     else
      45             :       // someone else owns and therefore deletes the root element table
      46         482 :       this->_data = nullptr;
      47             :   }
      48             : 
      49         583 :   _initialized = false;
      50         583 : }
      51             : 
      52             : void
      53           0 : PointLocatorRegularOrthogonal::init()
      54             : {
      55           0 :   mooseError(
      56             :       "PointLocatorRegularOrthogonal needs to be explicitly initialized with mesh meta data.");
      57             : }
      58             : 
      59             : void
      60         101 : PointLocatorRegularOrthogonal::init(const std::vector<unsigned int> & cell_count,
      61             :                                     const Point & min_corner,
      62             :                                     const Point & max_corner)
      63             : {
      64             :   // initialize root element table on the master point locator only
      65         101 :   if (this->_master == nullptr)
      66         101 :     _data = new PointLocatorRegularOrthogonalData(cell_count, min_corner, max_corner, _mesh);
      67             : 
      68         101 :   _initialized = true;
      69         101 : }
      70             : 
      71             : const Elem *
      72    73445431 : PointLocatorRegularOrthogonal::operator()(
      73             :     const Point & p, const std::set<subdomain_id_type> * /* allowed_subdomains */) const
      74             : {
      75             :   Point el_pos;
      76    73445431 :   const Elem * el = _data->rootElement(p, el_pos);
      77             : 
      78             :   while (true)
      79             :   {
      80             :     // element has no active children (or point is out of mesh)
      81    74900260 :     if (el == nullptr || el->active())
      82    73445431 :       return el;
      83             : 
      84             :     // bisect the children
      85             :     unsigned int child = 0;
      86     5684535 :     for (unsigned int i = 0; i < _data->_dim; ++i)
      87     4229706 :       if (el_pos(i) >= 0.5)
      88             :       {
      89             :         // fortunately the libMesh child ordering is this simple (bit 0/1 for left right of center
      90             :         // point, etc.)
      91     2165304 :         child += 1 << i;
      92     2165304 :         el_pos(i) = (el_pos(i) - 0.5) * 2.0;
      93             :       }
      94             :       else
      95     2064402 :         el_pos(i) *= 2.0;
      96             : 
      97             :     el = el->child_ptr(child);
      98     1454829 :   }
      99             : }
     100             : 
     101             : void
     102        6456 : PointLocatorRegularOrthogonal::operator()(
     103             :     const Point & p,
     104             :     std::set<const Elem *> & candidate_elements,
     105             :     const std::set<subdomain_id_type> * /* allowed_subdomains */) const
     106             : {
     107             :   // return just one match, the exact one TODO: return all neighbors if we are fuzzily on a
     108             :   // face/edge/node
     109        6456 :   candidate_elements.insert((*this)(p));
     110        6456 :   return;
     111             : }

Generated by: LCOV version 1.14