File indexing completed on 2026-05-19 08:08:15
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 class SimTrackView
0024 {
0025 public:
0026
0027 struct Initializer
0028 {
0029 real_type time{};
0030 };
0031
0032 public:
0033
0034 inline CELER_FUNCTION
0035 SimTrackView(NativeRef<SimStateData> const&, TrackSlotId);
0036
0037
0038 inline CELER_FUNCTION SimTrackView& operator=(Initializer const&);
0039
0040
0041 inline CELER_FUNCTION void status(TrackStatus);
0042
0043
0044 inline CELER_FUNCTION void add_time(real_type delta);
0045
0046
0047 inline CELER_FUNCTION void increment_num_steps();
0048
0049
0050 inline CELER_FUNCTION void reset_step_limit();
0051
0052
0053 inline CELER_FUNCTION void reset_step_limit(StepLimit const& sl);
0054
0055
0056 inline CELER_FUNCTION bool step_limit(StepLimit const& sl);
0057
0058
0059 inline CELER_FUNCTION void step_length(real_type length);
0060
0061
0062 inline CELER_FUNCTION void post_step_action(ActionId action);
0063
0064
0065
0066
0067 inline CELER_FUNCTION size_type num_steps() const;
0068
0069
0070 inline CELER_FUNCTION real_type time() const;
0071
0072
0073 inline CELER_FUNCTION TrackStatus status() const;
0074
0075
0076 inline CELER_FUNCTION real_type step_length() const;
0077
0078
0079 inline CELER_FUNCTION ActionId post_step_action() const;
0080
0081 private:
0082 NativeRef<SimStateData> const& states_;
0083 TrackSlotId track_slot_;
0084 };
0085
0086
0087
0088
0089
0090
0091
0092 CELER_FUNCTION
0093 SimTrackView::SimTrackView(NativeRef<SimStateData> const& states,
0094 TrackSlotId tid)
0095 : states_(states), track_slot_(tid)
0096 {
0097 CELER_EXPECT(track_slot_ < states_.size());
0098 }
0099
0100
0101
0102
0103
0104 CELER_FUNCTION SimTrackView& SimTrackView::operator=(Initializer const& init)
0105 {
0106 states_.time[track_slot_] = init.time;
0107 states_.step_length[track_slot_] = {};
0108 states_.status[track_slot_] = TrackStatus::initializing;
0109 states_.post_step_action[track_slot_] = {};
0110 states_.num_steps[track_slot_] = 0;
0111 return *this;
0112 }
0113
0114
0115
0116
0117
0118 CELER_FUNCTION void SimTrackView::status(TrackStatus status)
0119 {
0120 CELER_EXPECT(status != TrackStatus::size_);
0121 states_.status[track_slot_] = status;
0122 }
0123
0124
0125
0126
0127
0128 CELER_FORCEINLINE_FUNCTION void SimTrackView::increment_num_steps()
0129 {
0130 ++states_.num_steps[track_slot_];
0131 }
0132
0133
0134
0135
0136
0137 CELER_FUNCTION void SimTrackView::add_time(real_type delta)
0138 {
0139 CELER_EXPECT(delta >= 0);
0140 states_.time[track_slot_] += delta;
0141 }
0142
0143
0144
0145
0146
0147
0148
0149 CELER_FUNCTION void SimTrackView::reset_step_limit(StepLimit const& sl)
0150 {
0151 CELER_EXPECT(sl.step >= 0);
0152 CELER_EXPECT(static_cast<bool>(sl.action)
0153 != (sl.step == numeric_limits<real_type>::infinity()));
0154 states_.step_length[track_slot_] = sl.step;
0155 states_.post_step_action[track_slot_] = sl.action;
0156 }
0157
0158
0159
0160
0161
0162 CELER_FUNCTION void SimTrackView::reset_step_limit()
0163 {
0164 StepLimit limit;
0165 limit.step = numeric_limits<real_type>::infinity();
0166 limit.action = {};
0167 this->reset_step_limit(limit);
0168 }
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 CELER_FUNCTION void SimTrackView::post_step_action(ActionId action)
0179 {
0180 CELER_ASSERT(action);
0181 states_.post_step_action[track_slot_] = action;
0182 }
0183
0184
0185
0186
0187
0188 CELER_FUNCTION void SimTrackView::step_length(real_type length)
0189 {
0190 CELER_EXPECT(length > 0);
0191 states_.step_length[track_slot_] = length;
0192 }
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202 CELER_FUNCTION bool SimTrackView::step_limit(StepLimit const& sl)
0203 {
0204 CELER_ASSERT(sl.step >= 0);
0205
0206 bool is_limiting = (sl.step < states_.step_length[track_slot_]);
0207 if (is_limiting)
0208 {
0209 states_.step_length[track_slot_] = sl.step;
0210 states_.post_step_action[track_slot_] = sl.action;
0211 }
0212 return is_limiting;
0213 }
0214
0215
0216
0217
0218
0219
0220
0221 CELER_FORCEINLINE_FUNCTION size_type SimTrackView::num_steps() const
0222 {
0223 return states_.num_steps[track_slot_];
0224 }
0225
0226
0227
0228
0229
0230 CELER_FORCEINLINE_FUNCTION real_type SimTrackView::time() const
0231 {
0232 return states_.time[track_slot_];
0233 }
0234
0235
0236
0237
0238
0239 CELER_FORCEINLINE_FUNCTION TrackStatus SimTrackView::status() const
0240 {
0241 return states_.status[track_slot_];
0242 }
0243
0244
0245
0246
0247
0248 CELER_FORCEINLINE_FUNCTION real_type SimTrackView::step_length() const
0249 {
0250 return states_.step_length[track_slot_];
0251 }
0252
0253
0254
0255
0256
0257 CELER_FORCEINLINE_FUNCTION ActionId SimTrackView::post_step_action() const
0258 {
0259 return states_.post_step_action[track_slot_];
0260 }
0261
0262
0263 }
0264 }