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