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