File indexing completed on 2026-05-13 08:33:35
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 #include "surface/VolumeSurfaceSelector.hh"
0019
0020 #if !CELER_DEVICE_COMPILE
0021 # include "corecel/io/Logger.hh"
0022 #endif
0023
0024 namespace celeritas
0025 {
0026 namespace optical
0027 {
0028
0029
0030
0031
0032 class CoreTrackView
0033 {
0034 public:
0035
0036
0037 using ParamsRef = NativeCRef<CoreParamsData>;
0038 using StateRef = NativeRef<CoreStateData>;
0039
0040
0041 public:
0042
0043 inline CELER_FUNCTION CoreTrackView(ParamsRef const& params,
0044 StateRef const& states,
0045 TrackSlotId slot);
0046
0047
0048 inline CELER_FUNCTION CoreTrackView& operator=(TrackInitializer const&);
0049
0050
0051 inline CELER_FUNCTION GeoTrackView geometry() const;
0052
0053
0054 inline CELER_FUNCTION MaterialView material_record() const;
0055
0056
0057 inline CELER_FUNCTION MaterialView material_record(GeoTrackView const&) const;
0058
0059
0060 inline CELER_FUNCTION SimTrackView sim() const;
0061
0062
0063 inline CELER_FUNCTION ParticleTrackView particle() const;
0064
0065
0066 inline CELER_FUNCTION PhysicsTrackView physics() const;
0067
0068
0069 inline CELER_FUNCTION VolumeSurfaceSelector surface_selector() const;
0070
0071
0072 inline CELER_FUNCTION RngEngine rng() const;
0073
0074
0075 inline CELER_FUNCTION TrackSlotId track_slot_id() const;
0076
0077
0078 inline CELER_FUNCTION ActionId boundary_action() const;
0079
0080
0081 inline CELER_FUNCTION void apply_errored();
0082
0083 private:
0084 ParamsRef const& params_;
0085 StateRef const& states_;
0086 TrackSlotId const track_slot_id_;
0087 };
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 CELER_FUNCTION
0098 CoreTrackView::CoreTrackView(ParamsRef const& params,
0099 StateRef const& states,
0100 TrackSlotId track_slot)
0101 : params_(params), states_(states), track_slot_id_(track_slot)
0102 {
0103 CELER_EXPECT(track_slot_id_ < states_.size());
0104 }
0105
0106
0107
0108
0109
0110 CELER_FUNCTION CoreTrackView&
0111 CoreTrackView::operator=(TrackInitializer const& init)
0112 {
0113
0114 this->sim() = SimTrackView::Initializer{init.time};
0115
0116
0117 auto geo = this->geometry();
0118 geo = GeoTrackInitializer{init.position, init.direction, {}};
0119 if (CELER_UNLIKELY(geo.failed() || geo.is_outside()))
0120 {
0121 #if !CELER_DEVICE_COMPILE
0122 if (geo.is_outside())
0123 {
0124
0125
0126 CELER_LOG_LOCAL(error) << "Track started outside the geometry";
0127 }
0128 #endif
0129 this->apply_errored();
0130 return *this;
0131 }
0132
0133
0134 this->particle()
0135 = ParticleTrackView::Initializer{init.energy, init.polarization};
0136
0137
0138 this->physics() = PhysicsTrackView::Initializer{};
0139
0140 return *this;
0141 }
0142
0143
0144
0145
0146
0147 CELER_FUNCTION auto CoreTrackView::geometry() const -> GeoTrackView
0148 {
0149 return GeoTrackView{
0150 params_.geometry, states_.geometry, this->track_slot_id()};
0151 }
0152
0153
0154
0155
0156
0157 CELER_FORCEINLINE_FUNCTION auto CoreTrackView::material_record() const
0158 -> MaterialView
0159 {
0160 return this->material_record(this->geometry());
0161 }
0162
0163
0164
0165
0166
0167 CELER_FUNCTION auto
0168 CoreTrackView::material_record(GeoTrackView const& geo) const -> MaterialView
0169 {
0170 CELER_EXPECT(!geo.is_outside());
0171 return MaterialView{params_.material, geo.volume_id()};
0172 }
0173
0174
0175
0176
0177
0178 CELER_FUNCTION auto CoreTrackView::particle() const -> ParticleTrackView
0179 {
0180 return ParticleTrackView{states_.particle, this->track_slot_id()};
0181 }
0182
0183
0184
0185
0186
0187 CELER_FUNCTION auto CoreTrackView::physics() const -> PhysicsTrackView
0188 {
0189 OptMatId mat_id = this->material_record().material_id();
0190 CELER_ASSERT(mat_id);
0191 return PhysicsTrackView{
0192 params_.physics, states_.physics, mat_id, this->track_slot_id()};
0193 }
0194
0195
0196
0197
0198
0199 CELER_FUNCTION auto CoreTrackView::surface_selector() const
0200 -> VolumeSurfaceSelector
0201 {
0202 return VolumeSurfaceSelector{params_.surface, this->geometry()};
0203 }
0204
0205
0206
0207
0208
0209 CELER_FUNCTION auto CoreTrackView::rng() const -> RngEngine
0210 {
0211 return RngEngine{params_.rng, states_.rng, this->track_slot_id()};
0212 }
0213
0214
0215
0216
0217
0218 CELER_FUNCTION SimTrackView CoreTrackView::sim() const
0219 {
0220 return SimTrackView{states_.sim, this->track_slot_id()};
0221 }
0222
0223
0224
0225
0226
0227 CELER_FORCEINLINE_FUNCTION TrackSlotId CoreTrackView::track_slot_id() const
0228 {
0229 return track_slot_id_;
0230 }
0231
0232
0233
0234
0235
0236 CELER_FUNCTION ActionId CoreTrackView::boundary_action() const
0237 {
0238 return params_.scalars.boundary_action;
0239 }
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 CELER_FUNCTION void CoreTrackView::apply_errored()
0252 {
0253 auto sim = this->sim();
0254 CELER_EXPECT(is_track_valid(sim.status()));
0255 sim.status(TrackStatus::errored);
0256 sim.post_step_action(params_.scalars.tracking_cut_action);
0257 }
0258
0259
0260 }
0261 }