Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:59:58

0001 // SPDX-FileCopyrightText: 2023 CERN
0002 // SPDX-License-Identifier: Apache-2.0
0003 //---------------------------------------------------------------------------//
0004 /*!
0005  * \file geocel/vg/detail/SurfNavigator.hh
0006  * \brief Navigation methods using the surface model.
0007  *
0008  * Original source:
0009  * https://github.com/apt-sim/AdePT/blob/e03b856523164fb13f9f030d52297db96c8a2c8d/base/inc/AdePT/SurfNavigator.h
0010  */
0011 //---------------------------------------------------------------------------//
0012 #pragma once
0013 
0014 #include <VecGeom/base/Config.h>
0015 #include <VecGeom/base/Global.h>
0016 #include <VecGeom/base/Vector3D.h>
0017 #include <VecGeom/navigation/NavigationState.h>
0018 #include <VecGeom/surfaces/BVHSurfNavigator.h>
0019 
0020 #ifdef VECGEOM_ENABLE_CUDA
0021 #    include <VecGeom/backend/cuda/Interface.h>
0022 #endif
0023 #include "corecel/Macros.hh"
0024 
0025 namespace celeritas
0026 {
0027 namespace detail
0028 {
0029 //---------------------------------------------------------------------------//
0030 class SurfNavigator
0031 {
0032   public:
0033     using Precision = vecgeom::Precision;
0034     using Vector3D = vecgeom::Vector3D<vecgeom::Precision>;
0035     using SurfData = vgbrep::SurfData<Precision>;
0036     using Real_b = typename SurfData::Real_b;
0037     using VPlacedVolumePtr_t = vecgeom::VPlacedVolume const*;
0038 
0039     static constexpr Precision kBoundaryPush = 10 * vecgeom::kTolerance;
0040 
0041     /// @brief Locates the point in the geometry volume tree
0042     /// @param pvol_id Placed volume id to be checked first
0043     /// @param point Point to be checked, in the local frame of pvol
0044     /// @param path Path to a parent of pvol that must contain the point
0045     /// @param top Check first if pvol contains the point
0046     /// @param exclude Placed volume id to exclude from the search
0047     /// @return Index of the placed volume that contains the point
0048     CELER_FUNCTION static int LocatePointIn(int pvol_id,
0049                                             Vector3D const& point,
0050                                             vecgeom::NavigationState& path,
0051                                             bool top,
0052                                             int* exclude = nullptr)
0053     {
0054         return vgbrep::protonav::BVHSurfNavigator<Precision>::LocatePointIn(
0055             pvol_id, point, path, top, exclude);
0056     }
0057 
0058     /// @brief Computes the isotropic safety from the globalpoint.
0059     /// @param globalpoint Point in global coordinates
0060     /// @param state Path where to compute safety
0061     /// @return Isotropic safe distance
0062     CELER_FUNCTION static Precision
0063     ComputeSafety(Vector3D const& globalpoint,
0064                   vecgeom::NavigationState const& state)
0065     {
0066         auto safety
0067             = vgbrep::protonav::BVHSurfNavigator<Precision>::ComputeSafety(
0068                 globalpoint, state);
0069         return safety;
0070     }
0071 
0072     // Computes a step from the globalpoint (which must be in the current
0073     // volume) into globaldir, taking step_limit into account. If a volume is
0074     // hit, the function calls out_state.SetBoundaryState(true) and relocates
0075     // the state to the next volume.
0076     //
0077     // The surface model does automatic relocation, so this function does it as
0078     // well.
0079     CELER_FUNCTION static Precision
0080     ComputeStepAndNextVolume(Vector3D const& globalpoint,
0081                              Vector3D const& globaldir,
0082                              Precision step_limit,
0083                              vecgeom::NavigationState const& in_state,
0084                              vecgeom::NavigationState& out_state,
0085                              long& hitsurf)
0086     {
0087         if (step_limit <= 0)
0088         {
0089             in_state.CopyTo(&out_state);
0090             out_state.SetBoundaryState(false);
0091             return step_limit;
0092         }
0093 
0094         auto step = vgbrep::protonav::BVHSurfNavigator<
0095             Precision>::ComputeStepAndNextSurface(globalpoint,
0096                                                   globaldir,
0097                                                   in_state,
0098                                                   out_state,
0099                                                   hitsurf,
0100                                                   step_limit);
0101         return step;
0102     }
0103 
0104     // Computes a step from the globalpoint (which must be in the current
0105     // volume) into globaldir, taking step_limit into account. If a volume is
0106     // hit, the function calls out_state.SetBoundaryState(true) and relocates
0107     // the state to the next volume.
0108     CELER_FUNCTION static Precision
0109     ComputeStepAndPropagatedState(Vector3D const& globalpoint,
0110                                   Vector3D const& globaldir,
0111                                   Precision step_limit,
0112                                   long& hit_surf,
0113                                   vecgeom::NavigationState const& in,
0114                                   vecgeom::NavigationState& out)
0115     {
0116         return ComputeStepAndNextVolume(
0117             globalpoint, globaldir, step_limit, in, out, hit_surf);
0118     }
0119 
0120     // Relocate a state that was returned from ComputeStepAndNextVolume: the
0121     // surface model does this computation within ComputeStepAndNextVolume, so
0122     // the relocation does nothing
0123     CELER_FUNCTION static void
0124     RelocateToNextVolume(Vector3D const& globalpoint,
0125                          Vector3D const& globaldir,
0126                          long hitsurf_index,
0127                          vecgeom::NavigationState& out_state)
0128     {
0129         CELER_EXPECT(!out_state.IsOutside());
0130         vgbrep::CrossedSurface crossed_surf;
0131         vgbrep::protonav::BVHSurfNavigator<Precision>::RelocateToNextVolume(
0132             globalpoint,
0133             globaldir,
0134             Precision(0),
0135             hitsurf_index,
0136             out_state,
0137             crossed_surf);
0138     }
0139 };
0140 //---------------------------------------------------------------------------//
0141 }  // namespace detail
0142 }  // End namespace celeritas