File indexing completed on 2026-11-07 10:11:40
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/math/ArrayUtils.hh"
0010 #include "celeritas/optical/Types.hh"
0011
0012 #include "SurfacePhysicsData.hh"
0013 #include "SurfacePhysicsUtils.hh"
0014
0015 namespace celeritas
0016 {
0017 namespace optical
0018 {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 class SurfaceTraversalView
0030 {
0031 public:
0032
0033
0034 using SurfaceParamsRef = NativeCRef<SurfacePhysicsParamsData>;
0035 using SurfaceStateRef = NativeRef<SurfacePhysicsStateData>;
0036
0037
0038 struct Initializer
0039 {
0040 };
0041
0042 public:
0043
0044 inline CELER_FUNCTION SurfaceTraversalView(
0045 SurfaceParamsRef const&, SurfaceStateRef const&, TrackSlotId);
0046
0047
0048 inline CELER_FUNCTION SurfaceTraversalView& operator=(Initializer const&);
0049
0050
0051 inline CELER_FUNCTION bool in_pre_volume() const;
0052
0053
0054 inline CELER_FUNCTION bool in_post_volume() const;
0055
0056
0057 inline CELER_FUNCTION bool is_exiting() const;
0058
0059
0060 inline CELER_FUNCTION bool is_exiting(LocalDirection) const;
0061
0062
0063 inline CELER_FUNCTION LocalPositionId pos() const;
0064
0065
0066 inline CELER_FUNCTION LocalPositionId next_pos() const;
0067
0068
0069 inline CELER_FUNCTION void pos(LocalPositionId);
0070
0071
0072 inline CELER_FUNCTION LocalSurfaceId::size_type num_local_pos() const;
0073
0074
0075 inline CELER_FUNCTION LocalDirection dir() const;
0076
0077
0078 inline CELER_FUNCTION void dir(LocalDirection);
0079
0080
0081 inline CELER_FUNCTION void cross_interface(LocalDirection);
0082
0083 private:
0084 SurfaceParamsRef const& params_;
0085 SurfaceStateRef const& states_;
0086 TrackSlotId const track_id_;
0087 };
0088
0089
0090
0091
0092
0093
0094
0095 CELER_FUNCTION SurfaceTraversalView::SurfaceTraversalView(
0096 SurfaceParamsRef const& params,
0097 SurfaceStateRef const& states,
0098 TrackSlotId track)
0099 : params_(params), states_(states), track_id_(track)
0100 {
0101 CELER_EXPECT(track_id_ < states_.size());
0102 CELER_EXPECT(states_.surface[track_id_] < params_.surfaces.size());
0103 }
0104
0105
0106
0107
0108
0109 CELER_FUNCTION SurfaceTraversalView& SurfaceTraversalView::operator=(
0110 Initializer const&)
0111 {
0112 states_.local_position[track_id_] = LocalPositionId{0};
0113 states_.local_direction[track_id_] = LocalDirection::forward;
0114 return *this;
0115 }
0116
0117
0118
0119
0120
0121 CELER_FUNCTION bool SurfaceTraversalView::in_pre_volume() const
0122 {
0123 return this->pos().get() == 0;
0124 }
0125
0126
0127
0128
0129
0130 CELER_FUNCTION bool SurfaceTraversalView::in_post_volume() const
0131 {
0132 return this->pos().get() + 1 == this->num_local_pos();
0133 }
0134
0135
0136
0137
0138
0139 CELER_FUNCTION bool SurfaceTraversalView::is_exiting() const
0140 {
0141 return this->is_exiting(this->dir());
0142 }
0143
0144
0145
0146
0147
0148 CELER_FUNCTION bool SurfaceTraversalView::is_exiting(LocalDirection d) const
0149 {
0150
0151
0152 return next_local_pos_id(this->pos(), d).unchecked_get()
0153 >= this->num_local_pos();
0154 }
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 CELER_FUNCTION LocalPositionId SurfaceTraversalView::pos() const
0166 {
0167 return states_.local_position[track_id_];
0168 }
0169
0170
0171
0172
0173 CELER_FUNCTION LocalPositionId SurfaceTraversalView::next_pos() const
0174 {
0175 return next_local_pos_id(this->pos(), this->dir());
0176 }
0177
0178
0179
0180
0181
0182
0183 CELER_FUNCTION void SurfaceTraversalView::pos(LocalPositionId pos)
0184 {
0185 CELER_EXPECT(pos < this->num_local_pos());
0186 states_.local_position[track_id_] = pos;
0187 }
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 CELER_FUNCTION LocalSurfaceId::size_type
0199 SurfaceTraversalView::num_local_pos() const
0200 {
0201 auto const& surface = params_.surfaces[states_.surface[track_id_]];
0202 return surface.interstitial_mat_ids.size() + 2;
0203 }
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 CELER_FUNCTION LocalDirection SurfaceTraversalView::dir() const
0214 {
0215 return states_.local_direction[track_id_];
0216 }
0217
0218
0219
0220
0221
0222 CELER_FUNCTION void SurfaceTraversalView::dir(LocalDirection dir)
0223 {
0224 states_.local_direction[track_id_] = dir;
0225 }
0226
0227
0228
0229
0230
0231 CELER_FUNCTION void SurfaceTraversalView::cross_interface(LocalDirection d)
0232 {
0233 CELER_EXPECT(!this->is_exiting(d));
0234 this->pos(next_local_pos_id(this->pos(), d));
0235 }
0236
0237
0238 }
0239 }