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