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