File indexing completed on 2025-09-15 08:54:43
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/random/engine/RngEngine.hh"
0010 #include "corecel/sys/ThreadId.hh"
0011 #include "celeritas/geo/GeoMaterialView.hh"
0012 #include "celeritas/geo/GeoTrackView.hh"
0013 #include "celeritas/mat/MaterialTrackView.hh"
0014 #include "celeritas/phys/CutoffView.hh"
0015 #include "celeritas/phys/ParticleTrackView.hh"
0016 #include "celeritas/phys/PhysicsStepView.hh"
0017 #include "celeritas/phys/PhysicsTrackView.hh"
0018 #include "celeritas/track/SimTrackView.hh"
0019
0020 #include "CoreTrackData.hh"
0021
0022 namespace celeritas
0023 {
0024
0025
0026
0027
0028
0029
0030 class CoreTrackView
0031 {
0032 public:
0033
0034
0035 using ParamsRef = NativeCRef<CoreParamsData>;
0036 using StateRef = NativeRef<CoreStateData>;
0037
0038
0039 public:
0040
0041 inline CELER_FUNCTION CoreTrackView(ParamsRef const& params,
0042 StateRef const& states,
0043 ThreadId thread);
0044
0045
0046 inline CELER_FUNCTION CoreTrackView(ParamsRef const& params,
0047 StateRef const& states,
0048 TrackSlotId slot);
0049
0050
0051 inline CELER_FUNCTION SimTrackView sim() const;
0052
0053
0054 inline CELER_FUNCTION GeoTrackView geometry() const;
0055
0056
0057 inline CELER_FUNCTION GeoMaterialView geo_material() const;
0058
0059
0060 inline CELER_FUNCTION MaterialTrackView material() const;
0061
0062
0063 inline CELER_FUNCTION ParticleTrackView particle() const;
0064
0065
0066 inline CELER_FUNCTION ParticleView particle_record(ParticleId) const;
0067
0068
0069 inline CELER_FUNCTION CutoffView cutoff() const;
0070
0071
0072 inline CELER_FUNCTION PhysicsTrackView physics() const;
0073
0074
0075 inline CELER_FUNCTION PhysicsStepView physics_step() const;
0076
0077
0078 inline CELER_FUNCTION RngEngine rng() const;
0079
0080
0081 inline CELER_FUNCTION ThreadId thread_id() const;
0082
0083
0084 inline CELER_FUNCTION TrackSlotId track_slot_id() const;
0085
0086
0087 inline CELER_FUNCTION ActionId boundary_action() const;
0088
0089
0090 inline CELER_FUNCTION ActionId propagation_limit_action() const;
0091
0092
0093 inline CELER_FUNCTION ActionId tracking_cut_action() const;
0094
0095
0096 inline CELER_FUNCTION CoreScalars const& core_scalars() const;
0097
0098
0099
0100 [[deprecated]] CELER_FUNCTION SimTrackView make_sim_view() const { return this->sim(); }
0101 [[deprecated]] CELER_FUNCTION GeoTrackView make_geo_view() const { return this->geometry(); }
0102 [[deprecated]] CELER_FUNCTION GeoMaterialView make_geo_material_view() const { return this->geo_material(); }
0103 [[deprecated]] CELER_FUNCTION MaterialTrackView make_material_view() const { return this->material(); }
0104 [[deprecated]] CELER_FUNCTION ParticleTrackView make_particle_view() const { return this->particle(); }
0105 [[deprecated]] CELER_FUNCTION ParticleView make_particle_view(ParticleId pid) const { return this->particle_record(pid); }
0106 [[deprecated]] CELER_FUNCTION CutoffView make_cutoff_view() const { return this->cutoff(); }
0107 [[deprecated]] CELER_FUNCTION PhysicsTrackView make_physics_view() const { return this->physics(); }
0108 [[deprecated]] CELER_FUNCTION PhysicsStepView make_physics_step_view() const { return this->physics_step(); }
0109 [[deprecated]] CELER_FUNCTION RngEngine make_rng_engine() const { return this->rng(); }
0110
0111
0112
0113
0114
0115 inline CELER_FUNCTION void apply_errored();
0116
0117 private:
0118 StateRef const& states_;
0119 ParamsRef const& params_;
0120 ThreadId const thread_id_;
0121 TrackSlotId track_slot_id_;
0122 };
0123
0124
0125
0126
0127
0128
0129
0130 CELER_FUNCTION
0131 CoreTrackView::CoreTrackView(ParamsRef const& params,
0132 StateRef const& states,
0133 ThreadId thread)
0134 : states_(states), params_(params), thread_id_(thread)
0135 {
0136 CELER_EXPECT(states_.track_slots.empty()
0137 || thread_id_ < states_.track_slots.size());
0138 track_slot_id_ = TrackSlotId{states_.track_slots.empty()
0139 ? thread_id_.get()
0140 : states_.track_slots[thread_id_]};
0141 CELER_ENSURE(track_slot_id_ < states_.size());
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151 CELER_FUNCTION
0152 CoreTrackView::CoreTrackView(ParamsRef const& params,
0153 StateRef const& states,
0154 TrackSlotId track_slot)
0155 : states_(states), params_(params), track_slot_id_(track_slot)
0156 {
0157 CELER_EXPECT(track_slot_id_ < states_.size());
0158 }
0159
0160
0161
0162
0163
0164 CELER_FUNCTION SimTrackView CoreTrackView::sim() const
0165 {
0166 return SimTrackView{params_.sim, states_.sim, this->track_slot_id()};
0167 }
0168
0169
0170
0171
0172
0173 CELER_FUNCTION auto CoreTrackView::geometry() const -> GeoTrackView
0174 {
0175 return GeoTrackView{
0176 params_.geometry, states_.geometry, this->track_slot_id()};
0177 }
0178
0179
0180
0181
0182
0183 CELER_FUNCTION auto CoreTrackView::geo_material() const -> GeoMaterialView
0184 {
0185 return GeoMaterialView{params_.geo_mats};
0186 }
0187
0188
0189
0190
0191
0192 CELER_FUNCTION auto CoreTrackView::material() const -> MaterialTrackView
0193 {
0194 return MaterialTrackView{
0195 params_.materials, states_.materials, this->track_slot_id()};
0196 }
0197
0198
0199
0200
0201
0202 CELER_FUNCTION auto CoreTrackView::particle() const -> ParticleTrackView
0203 {
0204 return ParticleTrackView{
0205 params_.particles, states_.particles, this->track_slot_id()};
0206 }
0207
0208
0209
0210
0211
0212 CELER_FUNCTION auto
0213 CoreTrackView::particle_record(ParticleId pid) const -> ParticleView
0214 {
0215 return ParticleView{params_.particles, pid};
0216 }
0217
0218
0219
0220
0221
0222 CELER_FUNCTION auto CoreTrackView::cutoff() const -> CutoffView
0223 {
0224 PhysMatId mat_id = this->material().material_id();
0225 CELER_ASSERT(mat_id);
0226 return CutoffView{params_.cutoffs, mat_id};
0227 }
0228
0229
0230
0231
0232
0233 CELER_FUNCTION auto CoreTrackView::physics() const -> PhysicsTrackView
0234 {
0235 PhysMatId mat_id = this->material().material_id();
0236 CELER_ASSERT(mat_id);
0237 auto par = this->particle();
0238 return PhysicsTrackView{
0239 params_.physics, states_.physics, par, mat_id, this->track_slot_id()};
0240 }
0241
0242
0243
0244
0245
0246 CELER_FUNCTION auto CoreTrackView::physics_step() const -> PhysicsStepView
0247 {
0248 return PhysicsStepView{
0249 params_.physics, states_.physics, this->track_slot_id()};
0250 }
0251
0252
0253
0254
0255
0256 CELER_FUNCTION auto CoreTrackView::rng() const -> RngEngine
0257 {
0258 return RngEngine{params_.rng, states_.rng, this->track_slot_id()};
0259 }
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273 CELER_FORCEINLINE_FUNCTION ThreadId CoreTrackView::thread_id() const
0274 {
0275 CELER_EXPECT(thread_id_);
0276 return thread_id_;
0277 }
0278
0279
0280
0281
0282
0283 CELER_FORCEINLINE_FUNCTION TrackSlotId CoreTrackView::track_slot_id() const
0284 {
0285 return track_slot_id_;
0286 }
0287
0288
0289
0290
0291
0292 CELER_FUNCTION ActionId CoreTrackView::boundary_action() const
0293 {
0294 return params_.scalars.boundary_action;
0295 }
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306 CELER_FUNCTION ActionId CoreTrackView::propagation_limit_action() const
0307 {
0308 return params_.scalars.propagation_limit_action;
0309 }
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321 CELER_FUNCTION ActionId CoreTrackView::tracking_cut_action() const
0322 {
0323 return params_.scalars.tracking_cut_action;
0324 }
0325
0326
0327
0328
0329
0330
0331
0332
0333 CELER_FUNCTION CoreScalars const& CoreTrackView::core_scalars() const
0334 {
0335 return params_.scalars;
0336 }
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346 CELER_FUNCTION void CoreTrackView::apply_errored()
0347 {
0348 auto sim = this->sim();
0349 CELER_EXPECT(is_track_valid(sim.status()));
0350 sim.status(TrackStatus::errored);
0351 sim.along_step_action({});
0352 sim.post_step_action(this->tracking_cut_action());
0353 }
0354
0355
0356 }