File indexing completed on 2025-12-25 09:50:26
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Array.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/data/CollectionBuilder.hh"
0014 #include "corecel/sys/ThreadId.hh"
0015 #include "geocel/Types.hh"
0016
0017 #include "detail/GeantGeoNavCollection.hh"
0018
0019 class G4VPhysicalVolume;
0020
0021 namespace celeritas
0022 {
0023
0024
0025
0026
0027
0028
0029 template<Ownership W, MemSpace M>
0030 struct GeantGeoParamsData
0031 {
0032
0033 G4VPhysicalVolume* world{nullptr};
0034
0035
0036 VolumeId::size_type lv_offset{0};
0037
0038 VolumeInstanceId::size_type pv_offset{0};
0039
0040 GeoMatId::size_type mat_offset{0};
0041
0042
0043 explicit CELER_FUNCTION operator bool() const { return world != nullptr; }
0044
0045
0046 template<Ownership W2, MemSpace M2>
0047 GeantGeoParamsData& operator=(GeantGeoParamsData<W2, M2>& other)
0048 {
0049 world = other.world;
0050 return *this;
0051 }
0052 };
0053
0054
0055
0056
0057
0058
0059
0060 template<Ownership W, MemSpace M>
0061 struct GeantGeoStateData
0062 {
0063
0064
0065 using real_type = double;
0066 using Real3 = Array<double, 3>;
0067 template<class T>
0068 using Items = celeritas::StateCollection<T, W, MemSpace::host>;
0069
0070
0071
0072
0073 Items<Real3> pos;
0074 Items<Real3> dir;
0075 Items<real_type> next_step;
0076 Items<real_type> safety_radius;
0077
0078
0079 detail::GeantGeoNavCollection<W, M> nav_state;
0080
0081
0082
0083
0084 explicit CELER_FUNCTION operator bool() const
0085 {
0086 return this->size() > 0 && dir.size() == this->size()
0087 && next_step.size() == this->size()
0088 && safety_radius.size() == this->size()
0089 && nav_state.size() == this->size();
0090 }
0091
0092
0093 CELER_FUNCTION TrackSlotId::size_type size() const { return pos.size(); }
0094
0095
0096 template<Ownership W2, MemSpace M2>
0097 GeantGeoStateData& operator=(GeantGeoStateData<W2, M2>& other)
0098 {
0099 static_assert(M2 == M && W == Ownership::reference,
0100 "Only supported assignment is from the same memspace to "
0101 "a reference");
0102 CELER_EXPECT(other);
0103 pos = other.pos;
0104 dir = other.dir;
0105 next_step = other.next_step;
0106 safety_radius = other.safety_radius;
0107 nav_state = other.nav_state;
0108 return *this;
0109 }
0110
0111 void reset() { nav_state.reset(); }
0112 };
0113
0114
0115
0116
0117
0118 inline void resize(GeantGeoStateData<Ownership::value, MemSpace::host>* data,
0119 HostCRef<GeantGeoParamsData> const& params,
0120 StreamId stream_id,
0121 size_type size)
0122 {
0123 CELER_EXPECT(data);
0124 CELER_EXPECT(size > 0);
0125
0126 resize(&data->pos, size);
0127 resize(&data->dir, size);
0128 resize(&data->next_step, size);
0129 resize(&data->safety_radius, size);
0130 data->nav_state.resize(size, params.world, stream_id);
0131
0132 CELER_ENSURE(data);
0133 }
0134
0135
0136 inline void resize(GeantGeoStateData<Ownership::value, MemSpace::host>* data,
0137 HostCRef<GeantGeoParamsData> const& params,
0138 size_type size)
0139 {
0140 return resize(data, params, StreamId{0}, size);
0141 }
0142
0143 inline void resize(GeantGeoStateData<Ownership::value, MemSpace::device>*,
0144 HostCRef<GeantGeoParamsData> const&,
0145 StreamId,
0146 size_type)
0147 {
0148 CELER_NOT_IMPLEMENTED("Geant4 GPU");
0149 }
0150
0151 inline void resize(GeantGeoStateData<Ownership::value, MemSpace::device>*,
0152 HostCRef<GeantGeoParamsData> const&,
0153 size_type)
0154 {
0155 CELER_NOT_IMPLEMENTED("Geant4 GPU");
0156 }
0157
0158
0159 }