LCOV - code coverage report
Current view: top level - include/raytracing - ClaimRays.h (source / functions) Hit Total Coverage
Test: idaholab/moose ray_tracing: #31405 (292dce) with base fef103 Lines: 5 5 100.0 %
Date: 2025-09-04 07:56:07 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : // Local includes
      13             : #include "ParallelStudy.h"
      14             : #include "Ray.h"
      15             : 
      16             : // MOOSE includes
      17             : #include "MeshChangedInterface.h"
      18             : 
      19             : // System includes
      20             : #include <unordered_map>
      21             : 
      22             : // libMesh includes
      23             : #include "libmesh/bounding_box.h"
      24             : #include "libmesh/parallel_object.h"
      25             : #include "libmesh/point_locator_base.h"
      26             : 
      27             : // Forward declarations
      28             : class RayTracingStudy;
      29             : class MooseMesh;
      30             : 
      31             : /**
      32             :  * Helper object for claiming Rays
      33             :  */
      34             : class ClaimRays : public libMesh::ParallelObject, public MeshChangedInterface
      35             : {
      36             : public:
      37             :   /**
      38             :    * Constructor.
      39             :    * @param study The RayTracingStudy
      40             :    * @param parallel_study The base parallel study
      41             :    * @param mesh The MooseMesh
      42             :    * @param rays The vector of Rays that need to be claimed
      43             :    * @param local_rays Insertion point for Rays that have been claimed
      44             :    * @param do_exchange Whether or not an exchange is needed, i.e., if "rays" still needs to be
      45             :    * filled by objects on other processors
      46             :    */
      47             :   ClaimRays(RayTracingStudy & study,
      48             :             const std::vector<std::shared_ptr<Ray>> & rays,
      49             :             std::vector<std::shared_ptr<Ray>> & local_rays,
      50             :             const bool do_exchange);
      51             : 
      52             :   /**
      53             :    * Call on mesh changes to reinit the necessary data structures
      54             :    */
      55             :   virtual void meshChanged() override;
      56             : 
      57             :   /**
      58             :    * Claim the Rays
      59             :    *
      60             :    * \p do_exchange sets whether or not an exchange is needed, i.e., if _rays still needs
      61             :    * to be filled by objects on other processors
      62             :    */
      63             :   void claim();
      64             : 
      65             : protected:
      66             :   /**
      67             :    * Initialize the object
      68             :    */
      69             :   virtual void init();
      70             : 
      71             :   /**
      72             :    * Entry point before claim()
      73             :    */
      74         907 :   virtual void preClaim() {}
      75             :   /**
      76             :    * Entry point after claim()
      77             :    */
      78         907 :   virtual void postClaim() {}
      79             :   /**
      80             :    * Entry point before possibly claiming a Ray
      81             :    */
      82       64739 :   virtual void prePossiblyClaimRay(const std::shared_ptr<Ray> & /* ray */) {}
      83             :   /**
      84             :    * Entry point for acting on a Ray after it is claimed
      85             :    */
      86             :   virtual void postClaimRay(std::shared_ptr<Ray> & ray, const Elem * elem);
      87             : 
      88             :   /**
      89             :    * Gets an ID associated with the Ray for claiming purposes. Defaults
      90             :    * to the Ray's ID.
      91             :    *
      92             :    * To break ties in claiming (when multiple processors have elements that
      93             :    * contain a point, say on an element's side on a processor boundary),
      94             :    * we pick the smallest element ID when this ID is even and the
      95             :    * largest element ID is odd. It is possible that the same Rays can
      96             :    * be generated with different IDs, in which case the user may
      97             :    * want to use a different ID for this process.
      98             :    */
      99      163881 :   virtual RayID getID(const std::shared_ptr<Ray> & ray) const { return ray->id(); }
     100             : 
     101             :   /**
     102             :    * Get the inflated bounding box for rank \pid.
     103             :    */
     104             :   const libMesh::BoundingBox & inflatedBoundingBox(const processor_id_type pid) const
     105             :   {
     106         160 :     return _inflated_bboxes[pid];
     107             :   }
     108             : 
     109             :   /// The mesh
     110             :   MooseMesh & _mesh;
     111             :   /// This processor ID
     112             :   const processor_id_type _pid;
     113             : 
     114             :   /// Whether or not the Rays need to be initially exchanged
     115             :   const bool _do_exchange;
     116             : 
     117             :   /// The RayTracingStudy
     118             :   RayTracingStudy & _study;
     119             :   /// The ParallelStudy, used as the context for communicating rays
     120             :   ParallelStudy<std::shared_ptr<Ray>, Ray> & _parallel_study;
     121             : 
     122             : private:
     123             :   /**
     124             :    * Builds the bounding boxes (_inflated_bboxes).
     125             :    */
     126             :   void buildBoundingBoxes();
     127             : 
     128             :   /**
     129             :    * Build the map of elements to all of their point neighbors
     130             :    *
     131             :    * TODO: Move this eventually into MooseMesh, MeshBase, or FEProblemBase
     132             :    */
     133             :   void buildPointNeighbors();
     134             : 
     135             :   /**
     136             :    * Possibly claim a Ray.
     137             :    */
     138             :   void possiblyClaim(const std::shared_ptr<Ray> & obj);
     139             : 
     140             :   /**
     141             :    * Verifies that the claiming process succeeded. That is, all Rays were claimed
     142             :    * once and only once.
     143             :    */
     144             :   void verifyClaiming();
     145             : 
     146             :   /**
     147             :    * Try to claim a spatial point.
     148             :    *
     149             :    * @param point The point to claim
     150             :    * @param id An ID associated with the point
     151             :    * @param elem The local element to first consider for this processor's ownership
     152             :    * @return The element that contains the point if we claim the point, nullptr if we don't claim it
     153             :    */
     154             :   const Elem * claimPoint(const Point & point, const RayID id, const Elem * elem);
     155             : 
     156             :   /// The Rays that need to be searched to possibly claimed
     157             :   const std::vector<std::shared_ptr<Ray>> & _rays;
     158             :   /// The local Rays that are claimed
     159             :   std::vector<std::shared_ptr<Ray>> & _local_rays;
     160             : 
     161             :   /// The point locator
     162             :   std::unique_ptr<libMesh::PointLocatorBase> _point_locator = nullptr;
     163             : 
     164             :   /// The inflated bounding boxes for all processors
     165             :   std::vector<libMesh::BoundingBox> _inflated_bboxes;
     166             : 
     167             :   /// Map of point neighbors for each element
     168             :   std::unordered_map<dof_id_type, std::vector<const Elem *>> _elem_point_neighbors;
     169             : 
     170             :   /// Whether or not an init is needed (bounding boxes, neighbors)
     171             :   bool _needs_init;
     172             : };

Generated by: LCOV version 1.14