File indexing completed on 2026-11-15 10:10:39
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "celeritas/Types.hh"
0012
0013 #include "SimData.hh"
0014
0015 namespace celeritas
0016 {
0017 namespace optical
0018 {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 class SimTrackView
0029 {
0030 public:
0031
0032 struct Initializer
0033 {
0034 PrimaryId primary;
0035 real_type time{};
0036 };
0037
0038 public:
0039
0040 inline CELER_FUNCTION SimTrackView(NativeCRef<SimParamsData> const& params,
0041 NativeRef<SimStateData> const&,
0042 TrackSlotId);
0043
0044
0045 inline CELER_FUNCTION SimTrackView& operator=(Initializer const&);
0046
0047
0048 inline CELER_FUNCTION void status(TrackStatus);
0049
0050
0051 inline CELER_FUNCTION void add_time(real_type delta);
0052
0053
0054 inline CELER_FUNCTION void increment_num_steps();
0055
0056
0057 inline CELER_FUNCTION void reset_step_limit();
0058
0059
0060 inline CELER_FUNCTION void reset_step_limit(StepLimit const& sl);
0061
0062
0063 inline CELER_FUNCTION bool step_limit(StepLimit const& sl);
0064
0065
0066 inline CELER_FUNCTION void step_length(real_type length);
0067
0068
0069 inline CELER_FUNCTION void post_step_action(ActionId action);
0070
0071
0072
0073
0074 inline CELER_FUNCTION size_type num_steps() const;
0075
0076
0077 inline CELER_FUNCTION PrimaryId primary_id() const;
0078
0079
0080 inline CELER_FUNCTION real_type time() const;
0081
0082
0083 inline CELER_FUNCTION TrackStatus status() const;
0084
0085
0086 inline CELER_FUNCTION real_type step_length() const;
0087
0088
0089 inline CELER_FUNCTION ActionId post_step_action() const;
0090
0091
0092
0093
0094 inline CELER_FUNCTION size_type max_steps() const;
0095
0096 private:
0097 NativeCRef<SimParamsData> const& params_;
0098 NativeRef<SimStateData> const& states_;
0099 TrackSlotId track_slot_;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108 CELER_FUNCTION SimTrackView::SimTrackView(
0109 NativeCRef<SimParamsData> const& params,
0110 NativeRef<SimStateData> const& states,
0111 TrackSlotId tid)
0112 : params_(params), states_(states), track_slot_(tid)
0113 {
0114 CELER_EXPECT(params_);
0115 CELER_EXPECT(track_slot_ < states_.size());
0116 }
0117
0118
0119
0120
0121
0122 CELER_FUNCTION SimTrackView& SimTrackView::operator=(Initializer const& init)
0123 {
0124 states_.primary_ids[track_slot_] = init.primary;
0125 states_.time[track_slot_] = init.time;
0126 states_.step_length[track_slot_] = {};
0127 states_.status[track_slot_] = TrackStatus::initializing;
0128 states_.post_step_action[track_slot_] = {};
0129 states_.num_steps[track_slot_] = 0;
0130 return *this;
0131 }
0132
0133
0134
0135
0136
0137 CELER_FUNCTION void SimTrackView::status(TrackStatus status)
0138 {
0139 CELER_EXPECT(status != TrackStatus::size_);
0140 states_.status[track_slot_] = status;
0141 }
0142
0143
0144
0145
0146
0147 CELER_FORCEINLINE_FUNCTION void SimTrackView::increment_num_steps()
0148 {
0149 ++states_.num_steps[track_slot_];
0150 }
0151
0152
0153
0154
0155
0156 CELER_FUNCTION void SimTrackView::add_time(real_type delta)
0157 {
0158 CELER_EXPECT(delta >= 0);
0159 states_.time[track_slot_] += delta;
0160 }
0161
0162
0163
0164
0165
0166
0167
0168 CELER_FUNCTION void SimTrackView::reset_step_limit(StepLimit const& sl)
0169 {
0170 CELER_EXPECT(sl.step >= 0);
0171 CELER_EXPECT(static_cast<bool>(sl.action)
0172 != (sl.step == numeric_limits<real_type>::infinity()));
0173 states_.step_length[track_slot_] = sl.step;
0174 states_.post_step_action[track_slot_] = sl.action;
0175 }
0176
0177
0178
0179
0180
0181 CELER_FUNCTION void SimTrackView::reset_step_limit()
0182 {
0183 StepLimit limit;
0184 limit.step = numeric_limits<real_type>::infinity();
0185 limit.action = {};
0186 this->reset_step_limit(limit);
0187 }
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 CELER_FUNCTION void SimTrackView::post_step_action(ActionId action)
0198 {
0199 CELER_ASSERT(action);
0200 states_.post_step_action[track_slot_] = action;
0201 }
0202
0203
0204
0205
0206
0207 CELER_FUNCTION void SimTrackView::step_length(real_type length)
0208 {
0209 CELER_EXPECT(length > 0);
0210 states_.step_length[track_slot_] = length;
0211 }
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221 CELER_FUNCTION bool SimTrackView::step_limit(StepLimit const& sl)
0222 {
0223 CELER_ASSERT(sl.step >= 0);
0224
0225 bool is_limiting = (sl.step < states_.step_length[track_slot_]);
0226 if (is_limiting)
0227 {
0228 states_.step_length[track_slot_] = sl.step;
0229 states_.post_step_action[track_slot_] = sl.action;
0230 }
0231 return is_limiting;
0232 }
0233
0234
0235
0236
0237
0238
0239
0240 CELER_FORCEINLINE_FUNCTION size_type SimTrackView::num_steps() const
0241 {
0242 return states_.num_steps[track_slot_];
0243 }
0244
0245
0246
0247
0248
0249 CELER_FORCEINLINE_FUNCTION PrimaryId SimTrackView::primary_id() const
0250 {
0251 return states_.primary_ids[track_slot_];
0252 }
0253
0254
0255
0256
0257
0258 CELER_FORCEINLINE_FUNCTION real_type SimTrackView::time() const
0259 {
0260 return states_.time[track_slot_];
0261 }
0262
0263
0264
0265
0266
0267 CELER_FORCEINLINE_FUNCTION TrackStatus SimTrackView::status() const
0268 {
0269 return states_.status[track_slot_];
0270 }
0271
0272
0273
0274
0275
0276 CELER_FORCEINLINE_FUNCTION real_type SimTrackView::step_length() const
0277 {
0278 return states_.step_length[track_slot_];
0279 }
0280
0281
0282
0283
0284
0285 CELER_FORCEINLINE_FUNCTION ActionId SimTrackView::post_step_action() const
0286 {
0287 return states_.post_step_action[track_slot_];
0288 }
0289
0290
0291
0292
0293
0294 CELER_FORCEINLINE_FUNCTION size_type SimTrackView::max_steps() const
0295 {
0296 return params_.max_steps;
0297 }
0298
0299
0300 }
0301 }