File indexing completed on 2025-11-30 10:07:56
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/random/engine/RngEngine.hh"
0010 #include "celeritas/geo/GeoTrackView.hh"
0011
0012 #include "CoreTrackData.hh"
0013 #include "MaterialView.hh"
0014 #include "ParticleTrackView.hh"
0015 #include "PhysicsTrackView.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_record() const;
0054
0055
0056 inline CELER_FUNCTION MaterialView material_record(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 PhysicsTrackView physics() const;
0066
0067
0068 inline CELER_FUNCTION RngEngine rng() const;
0069
0070
0071 inline CELER_FUNCTION TrackSlotId track_slot_id() const;
0072
0073
0074 inline CELER_FUNCTION ActionId boundary_action() const;
0075
0076
0077 inline CELER_FUNCTION void apply_errored();
0078
0079 private:
0080 ParamsRef const& params_;
0081 StateRef const& states_;
0082 TrackSlotId const track_slot_id_;
0083 };
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 CELER_FUNCTION
0094 CoreTrackView::CoreTrackView(ParamsRef const& params,
0095 StateRef const& states,
0096 TrackSlotId track_slot)
0097 : params_(params), states_(states), track_slot_id_(track_slot)
0098 {
0099 CELER_EXPECT(track_slot_id_ < states_.size());
0100 }
0101
0102
0103
0104
0105
0106 CELER_FUNCTION CoreTrackView&
0107 CoreTrackView::operator=(TrackInitializer const& init)
0108 {
0109
0110 this->sim() = SimTrackView::Initializer{init.time};
0111
0112
0113 auto geo = this->geometry();
0114 geo = GeoTrackInitializer{init.position, init.direction};
0115 if (CELER_UNLIKELY(geo.failed() || geo.is_outside()))
0116 {
0117 #if !CELER_DEVICE_COMPILE
0118 if (geo.is_outside())
0119 {
0120
0121
0122 CELER_LOG_LOCAL(error) << "Track started outside the geometry";
0123 }
0124 #endif
0125 this->apply_errored();
0126 return *this;
0127 }
0128
0129
0130 this->particle()
0131 = ParticleTrackView::Initializer{init.energy, init.polarization};
0132
0133
0134 this->physics() = PhysicsTrackView::Initializer{};
0135
0136 return *this;
0137 }
0138
0139
0140
0141
0142
0143 CELER_FUNCTION auto CoreTrackView::geometry() const -> GeoTrackView
0144 {
0145 return GeoTrackView{
0146 params_.geometry, states_.geometry, this->track_slot_id()};
0147 }
0148
0149
0150
0151
0152
0153 CELER_FORCEINLINE_FUNCTION auto
0154 CoreTrackView::material_record() const -> MaterialView
0155 {
0156 return this->material_record(this->geometry());
0157 }
0158
0159
0160
0161
0162
0163 CELER_FUNCTION auto
0164 CoreTrackView::material_record(GeoTrackView const& geo) const -> MaterialView
0165 {
0166 CELER_EXPECT(!geo.is_outside());
0167 return MaterialView{params_.material, geo.volume_id()};
0168 }
0169
0170
0171
0172
0173
0174 CELER_FUNCTION auto CoreTrackView::particle() const -> ParticleTrackView
0175 {
0176 return ParticleTrackView{states_.particle, this->track_slot_id()};
0177 }
0178
0179
0180
0181
0182
0183 CELER_FUNCTION auto CoreTrackView::physics() const -> PhysicsTrackView
0184 {
0185 OptMatId mat_id = this->material_record().material_id();
0186 CELER_ASSERT(mat_id);
0187 return PhysicsTrackView{
0188 params_.physics, states_.physics, mat_id, this->track_slot_id()};
0189 }
0190
0191
0192
0193
0194
0195 CELER_FUNCTION auto CoreTrackView::rng() const -> RngEngine
0196 {
0197 return RngEngine{params_.rng, states_.rng, this->track_slot_id()};
0198 }
0199
0200
0201
0202
0203
0204 CELER_FUNCTION SimTrackView CoreTrackView::sim() const
0205 {
0206 return SimTrackView{states_.sim, this->track_slot_id()};
0207 }
0208
0209
0210
0211
0212
0213 CELER_FORCEINLINE_FUNCTION TrackSlotId CoreTrackView::track_slot_id() const
0214 {
0215 return track_slot_id_;
0216 }
0217
0218
0219
0220
0221
0222 CELER_FUNCTION ActionId CoreTrackView::boundary_action() const
0223 {
0224 return params_.scalars.boundary_action;
0225 }
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 CELER_FUNCTION void CoreTrackView::apply_errored()
0238 {
0239 auto sim = this->sim();
0240 CELER_EXPECT(is_track_valid(sim.status()));
0241 sim.status(TrackStatus::errored);
0242 sim.post_step_action(params_.scalars.tracking_cut_action);
0243 }
0244
0245
0246 }
0247 }