Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-29 09:13:53

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file geocel/AllVolumesView.hh
0006 //! \sa test/geocel/Volume.test.cc
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "geocel/Types.hh"
0013 
0014 #include "VolumeData.hh"
0015 #include "VolumePathAccumulator.hh"
0016 #include "VolumeView.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * GPU-compatible view of the full volume hierarchy graph.
0023  *
0024  * This provides device-accessible accessors over the complete
0025  * \c VolumeParamsData: scalar graph properties (world ID, depth, unique
0026  * instance count) and instance-to-volume mapping, as well as per-volume
0027  * \c VolumeView objects.
0028  */
0029 class AllVolumesView
0030 {
0031   public:
0032     //!@{
0033     //! \name Type aliases
0034     using ParamsRef = NativeCRef<VolumeParamsData>;
0035     //!@}
0036 
0037   public:
0038     // Construct with shared params data
0039     explicit inline CELER_FUNCTION AllVolumesView(ParamsRef const& params);
0040 
0041     //! Root volume of the geometry graph
0042     inline CELER_FUNCTION VolumeId world() const;
0043 
0044     //! Enclosing instance of the world volume (null if world is a true root)
0045     inline CELER_FUNCTION VolumeInstanceId world_instance() const;
0046 
0047     //! Number of logical volumes (nodes)
0048     inline CELER_FUNCTION VolumeId::size_type num_volumes() const;
0049 
0050     //! Number of volume instances (edges)
0051     inline CELER_FUNCTION VolumeInstanceId::size_type
0052     num_volume_instances() const;
0053 
0054     //! Total number of unique root-to-node paths
0055     inline CELER_FUNCTION VolumeUniqueInstanceId::size_type
0056     num_unique_instances() const;
0057 
0058     //! Depth of the volume graph (1 for a world with no children)
0059     inline CELER_FUNCTION VolumeLevelId::size_type num_volume_levels() const;
0060 
0061     // Get the logical volume instantiated by a volume instance
0062     inline CELER_FUNCTION VolumeId volume_id(VolumeInstanceId vi_id) const;
0063 
0064     // Get the precomputed unique-instance offset for a volume instance
0065     inline CELER_FUNCTION VolumeUniqueInstanceId::size_type offset(
0066         VolumeInstanceId vi_id) const;
0067 
0068     // Construct a view for the given volume
0069     inline CELER_FUNCTION VolumeView volume(VolumeId vol_id) const;
0070 
0071     // Construct a volume path accumulator from this volume view
0072     inline CELER_FUNCTION VolumePathAccumulator path_accumulator() const;
0073 
0074   private:
0075     ParamsRef const& params_;
0076 };
0077 
0078 //---------------------------------------------------------------------------//
0079 // INLINE DEFINITIONS
0080 //---------------------------------------------------------------------------//
0081 /*!
0082  * Construct with shared params data.
0083  */
0084 CELER_FORCEINLINE_FUNCTION AllVolumesView::AllVolumesView(
0085     ParamsRef const& params)
0086     : params_(params)
0087 {
0088 }
0089 
0090 //---------------------------------------------------------------------------//
0091 /*!
0092  * Get the root volume of the geometry graph.
0093  */
0094 CELER_FORCEINLINE_FUNCTION VolumeId AllVolumesView::world() const
0095 {
0096     return params_.scalars.world;
0097 }
0098 
0099 //---------------------------------------------------------------------------//
0100 /*!
0101  * Get the enclosing instance of the world volume.
0102  */
0103 CELER_FORCEINLINE_FUNCTION VolumeInstanceId AllVolumesView::world_instance() const
0104 {
0105     return params_.scalars.world_instance;
0106 }
0107 
0108 //---------------------------------------------------------------------------//
0109 /*!
0110  * Get the number of logical volumes.
0111  */
0112 CELER_FORCEINLINE_FUNCTION VolumeId::size_type
0113 AllVolumesView::num_volumes() const
0114 {
0115     return params_.scalars.num_volumes;
0116 }
0117 
0118 //---------------------------------------------------------------------------//
0119 /*!
0120  * Get the number of volume instances.
0121  */
0122 CELER_FORCEINLINE_FUNCTION VolumeInstanceId::size_type
0123 AllVolumesView::num_volume_instances() const
0124 {
0125     return params_.scalars.num_volume_instances;
0126 }
0127 
0128 //---------------------------------------------------------------------------//
0129 /*!
0130  * Get the total number of unique root-to-node paths.
0131  */
0132 CELER_FORCEINLINE_FUNCTION VolumeUniqueInstanceId::size_type
0133 AllVolumesView::num_unique_instances() const
0134 {
0135     return params_.scalars.num_unique_instances;
0136 }
0137 
0138 //---------------------------------------------------------------------------//
0139 /*!
0140  * Get the depth of the volume graph.
0141  */
0142 CELER_FORCEINLINE_FUNCTION VolumeLevelId::size_type
0143 AllVolumesView::num_volume_levels() const
0144 {
0145     return params_.scalars.num_volume_levels;
0146 }
0147 
0148 //---------------------------------------------------------------------------//
0149 /*!
0150  * Get the logical volume instantiated by a volume instance.
0151  */
0152 CELER_FUNCTION VolumeId AllVolumesView::volume_id(VolumeInstanceId vi_id) const
0153 {
0154     CELER_EXPECT(vi_id < params_.volume_ids.size());
0155     return params_.volume_ids[vi_id];
0156 }
0157 
0158 //---------------------------------------------------------------------------//
0159 /*!
0160  * Get the precomputed unique-instance offset for a volume instance.
0161  */
0162 CELER_FUNCTION VolumeUniqueInstanceId::size_type AllVolumesView::offset(
0163     VolumeInstanceId vi_id) const
0164 {
0165     CELER_EXPECT(vi_id < params_.unique_instance_offsets.size());
0166     return params_.unique_instance_offsets[vi_id];
0167 }
0168 
0169 //---------------------------------------------------------------------------//
0170 /*!
0171  * Construct a \c VolumeView for the given volume.
0172  */
0173 CELER_FUNCTION VolumeView AllVolumesView::volume(VolumeId vol_id) const
0174 {
0175     return VolumeView{params_, vol_id};
0176 }
0177 
0178 //---------------------------------------------------------------------------//
0179 /*!
0180  * Construct a \c VolumePathAccumulator.
0181  */
0182 CELER_FUNCTION VolumePathAccumulator AllVolumesView::path_accumulator() const
0183 {
0184     return VolumePathAccumulator{params_};
0185 }
0186 
0187 //---------------------------------------------------------------------------//
0188 }  // namespace celeritas