File indexing completed on 2025-02-22 10:31:27
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "celeritas/geo/GeoTrackView.hh"
0011 #include "celeritas/random/RngEngine.hh"
0012
0013 #include "CoreTrackData.hh"
0014 #include "MaterialView.hh"
0015 #include "ParticleTrackView.hh"
0016 #include "SimTrackView.hh"
0017 #include "TrackInitializer.hh"
0018
0019 #if !CELER_DEVICE_COMPILE
0020 # include "corecel/io/Logger.hh"
0021 #endif
0022
0023 namespace celeritas
0024 {
0025 namespace optical
0026 {
0027
0028
0029
0030
0031 class CoreTrackView
0032 {
0033 public:
0034
0035
0036 using ParamsRef = NativeCRef<CoreParamsData>;
0037 using StateRef = NativeRef<CoreStateData>;
0038
0039
0040 public:
0041
0042 inline CELER_FUNCTION CoreTrackView(ParamsRef const& params,
0043 StateRef const& states,
0044 TrackSlotId slot);
0045
0046
0047 inline CELER_FUNCTION CoreTrackView& operator=(TrackInitializer const&);
0048
0049
0050 inline CELER_FUNCTION GeoTrackView geometry() const;
0051
0052
0053 inline CELER_FUNCTION MaterialView material() const;
0054
0055
0056 inline CELER_FUNCTION MaterialView material(GeoTrackView const&) const;
0057
0058
0059 inline CELER_FUNCTION SimTrackView sim() const;
0060
0061
0062 inline CELER_FUNCTION ParticleTrackView particle() const;
0063
0064
0065 inline CELER_FUNCTION RngEngine rng() const;
0066
0067
0068 inline CELER_FUNCTION TrackSlotId track_slot_id() const;
0069
0070
0071 inline CELER_FUNCTION ActionId boundary_action() const;
0072
0073
0074 inline CELER_FUNCTION void apply_errored();
0075
0076 private:
0077 ParamsRef const& params_;
0078 StateRef const& states_;
0079 TrackSlotId const track_slot_id_;
0080 };
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 CELER_FUNCTION
0091 CoreTrackView::CoreTrackView(ParamsRef const& params,
0092 StateRef const& states,
0093 TrackSlotId track_slot)
0094 : params_(params), states_(states), track_slot_id_(track_slot)
0095 {
0096 CELER_EXPECT(track_slot_id_ < states_.size());
0097 }
0098
0099
0100
0101
0102
0103 CELER_FUNCTION CoreTrackView&
0104 CoreTrackView::operator=(TrackInitializer const& init)
0105 {
0106
0107 this->sim() = SimTrackView::Initializer{init.time};
0108
0109
0110 auto geo = this->geometry();
0111 geo = GeoTrackInitializer{init.position, init.direction};
0112 if (CELER_UNLIKELY(geo.failed() || geo.is_outside()))
0113 {
0114 #if !CELER_DEVICE_COMPILE
0115 if (geo.is_outside())
0116 {
0117
0118
0119 CELER_LOG_LOCAL(error) << "Track started outside the geometry";
0120 }
0121 #endif
0122 this->apply_errored();
0123 return *this;
0124 }
0125
0126
0127 this->particle()
0128 = ParticleTrackView::Initializer{init.energy, init.polarization};
0129
0130
0131
0132 return *this;
0133 }
0134
0135
0136
0137
0138
0139 CELER_FUNCTION auto CoreTrackView::geometry() const -> GeoTrackView
0140 {
0141 return GeoTrackView{
0142 params_.geometry, states_.geometry, this->track_slot_id()};
0143 }
0144
0145
0146
0147
0148
0149 CELER_FORCEINLINE_FUNCTION auto CoreTrackView::material() const -> MaterialView
0150 {
0151 return this->material(this->geometry());
0152 }
0153
0154
0155
0156
0157
0158 CELER_FUNCTION auto
0159 CoreTrackView::material(GeoTrackView const& geo) const -> MaterialView
0160 {
0161 CELER_EXPECT(!geo.is_outside());
0162 return MaterialView{params_.material, geo.volume_id()};
0163 }
0164
0165
0166
0167
0168
0169 CELER_FUNCTION auto CoreTrackView::particle() const -> ParticleTrackView
0170 {
0171 return ParticleTrackView{states_.particle, this->track_slot_id()};
0172 }
0173
0174
0175
0176
0177
0178 CELER_FUNCTION auto CoreTrackView::rng() const -> RngEngine
0179 {
0180 return RngEngine{params_.rng, states_.rng, this->track_slot_id()};
0181 }
0182
0183
0184
0185
0186
0187 CELER_FUNCTION SimTrackView CoreTrackView::sim() const
0188 {
0189 return SimTrackView{states_.sim, this->track_slot_id()};
0190 }
0191
0192
0193
0194
0195
0196 CELER_FORCEINLINE_FUNCTION TrackSlotId CoreTrackView::track_slot_id() const
0197 {
0198 return track_slot_id_;
0199 }
0200
0201
0202
0203
0204
0205 CELER_FUNCTION ActionId CoreTrackView::boundary_action() const
0206 {
0207 return params_.scalars.boundary_action;
0208 }
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 CELER_FUNCTION void CoreTrackView::apply_errored()
0221 {
0222 auto sim = this->sim();
0223 CELER_EXPECT(is_track_valid(sim.status()));
0224 sim.status(TrackStatus::killed);
0225 sim.post_step_action({});
0226 }
0227
0228
0229 }
0230 }