File indexing completed on 2026-11-09 10:21:11
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <VecGeom/base/Version.h>
0010
0011 #include "corecel/Config.hh"
0012
0013 #include "corecel/Macros.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/data/Collection.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017 #include "geocel/Types.hh"
0018
0019 #include "VecgeomTypes.hh"
0020
0021 #if CELERITAS_VECGEOM_VERSION >= 0x020000 && defined(VECGEOM_ENABLE_CUDA)
0022
0023 # include <VecGeom/base/Cuda.h>
0024 # include <VecGeom/base/Global.h>
0025 # include <VecGeom/management/CudaManager.h>
0026 #endif
0027
0028 #if CELER_VGNAV == CELER_VGNAV_PATH
0029 # include "detail/VecgeomNavCollection.hh"
0030 #elif CELER_VGNAV == CELER_VGNAV_TUPLE
0031 # include <VecGeom/navigation/NavStateTuple.h>
0032 #else
0033 # include <VecGeom/navigation/NavStateIndex.h>
0034 #endif
0035
0036 namespace celeritas
0037 {
0038
0039
0040
0041 struct VecgeomScalars
0042 {
0043 using vol_level_uint = VolumeLevelId::size_type;
0044
0045 VgPlacedVolume<MemSpace::host> const* host_world{nullptr};
0046 VgPlacedVolume<MemSpace::device> const* device_world{nullptr};
0047 vol_level_uint num_volume_levels{0};
0048
0049 template<MemSpace M>
0050 CELER_FUNCTION VgPlacedVolume<M> const* world() const
0051 {
0052 if constexpr (M == MemSpace::host)
0053 {
0054 return host_world;
0055 }
0056 else if constexpr (M == MemSpace::device)
0057 {
0058 return device_world;
0059 }
0060 #if CELER_CUDACC_BUGGY_IF_CONSTEXPR
0061 CELER_ASSERT_UNREACHABLE();
0062 #endif
0063 }
0064
0065
0066 explicit CELER_FUNCTION operator bool() const
0067 {
0068 return host_world != nullptr && num_volume_levels > 0;
0069 }
0070 };
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 template<Ownership W, MemSpace M>
0082 struct VecgeomParamsData
0083 {
0084 using ImplVolInstanceId = VgVolumeInstanceId;
0085
0086
0087 VecgeomScalars scalars;
0088
0089
0090 Collection<VolumeId, W, M, ImplVolumeId> volumes;
0091
0092 Collection<VolumeInstanceId, W, M, ImplVolInstanceId> volume_instances;
0093
0094
0095 explicit CELER_FUNCTION operator bool() const
0096 {
0097
0098 return scalars && !volumes.empty() && !volume_instances.empty();
0099 }
0100
0101
0102 template<Ownership W2, MemSpace M2>
0103 VecgeomParamsData& operator=(VecgeomParamsData<W2, M2>& other)
0104 {
0105 CELER_EXPECT(other);
0106 scalars = other.scalars;
0107 volumes = other.volumes;
0108 volume_instances = other.volume_instances;
0109 return *this;
0110 }
0111 };
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 template<Ownership W, MemSpace M>
0124 struct VecgeomStateData
0125 {
0126
0127
0128 template<class T>
0129 using StateItems = StateCollection<T, W, M>;
0130 #if CELER_VGNAV == CELER_VGNAV_PATH
0131 using VgStateItems = detail::VecgeomNavCollection<W, M>;
0132 #else
0133 using VgStateItems = StateItems<VgNavState>;
0134 #endif
0135
0136
0137
0138
0139 StateItems<Real3> pos;
0140 StateItems<Real3> dir;
0141
0142
0143 VgStateItems state;
0144 VgStateItems next_state;
0145
0146
0147
0148
0149 explicit CELER_FUNCTION operator bool() const
0150 {
0151
0152 return pos.size() > 0
0153 && dir.size() == pos.size()
0154 && state.size() == pos.size()
0155 && next_state.size() == pos.size();
0156
0157 }
0158
0159
0160 CELER_FUNCTION TrackSlotId::size_type size() const { return pos.size(); }
0161
0162
0163 template<Ownership W2, MemSpace M2>
0164 VecgeomStateData& operator=(VecgeomStateData<W2, M2>& other)
0165 {
0166 CELER_EXPECT(other);
0167 pos = other.pos;
0168 dir = other.dir;
0169 state = other.state;
0170 next_state = other.next_state;
0171 return *this;
0172 }
0173 };
0174
0175
0176
0177 template<MemSpace M>
0178 void resize(VecgeomStateData<Ownership::value, M>* data,
0179 HostCRef<VecgeomParamsData> const& params,
0180 size_type size);
0181
0182 extern template void resize<MemSpace::host>(
0183 VecgeomStateData<Ownership::value, MemSpace::host>*,
0184 HostCRef<VecgeomParamsData> const&,
0185 size_type);
0186
0187 extern template void resize<MemSpace::device>(
0188 VecgeomStateData<Ownership::value, MemSpace::device>*,
0189 HostCRef<VecgeomParamsData> const&,
0190 size_type);
0191
0192
0193 }