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