File indexing completed on 2026-12-04 10:44:46
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/sys/ThreadId.hh"
0012 #include "celeritas/optical/CoreTrackData.hh"
0013 #include "celeritas/optical/CoreTrackView.hh"
0014 #include "celeritas/optical/SimTrackView.hh"
0015 #include "celeritas/track/TrackFunctors.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace optical
0020 {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template<class T>
0034 class TrackSlotExecutor
0035 {
0036 public:
0037
0038
0039 using ParamsPtr = CoreParamsPtr<MemSpace::native>;
0040 using StatePtr = CoreStatePtr<MemSpace::native>;
0041 using Applier = T;
0042
0043
0044 public:
0045
0046 CELER_FUNCTION TrackSlotExecutor(
0047 ParamsPtr params, StatePtr state, T&& execute_track)
0048 : params_{params}
0049 , state_{state}
0050 , execute_track_{celeritas::forward<T>(execute_track)}
0051 {
0052 }
0053
0054
0055 CELER_FUNCTION void operator()(TrackSlotId ts)
0056 {
0057 CELER_EXPECT(ts < state_->size());
0058 CoreTrackView track(*params_, *state_, ts);
0059 return execute_track_(track);
0060 }
0061
0062
0063 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId thread)
0064 {
0065
0066 return (*this)(TrackSlotId{thread.unchecked_get()});
0067 }
0068
0069 private:
0070 ParamsPtr const params_;
0071 StatePtr const state_;
0072 T execute_track_;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 template<class C, class T>
0087 class ConditionalTrackSlotExecutor
0088 {
0089 public:
0090
0091
0092 using ParamsPtr = CoreParamsPtr<MemSpace::native>;
0093 using StatePtr = CoreStatePtr<MemSpace::native>;
0094 using Applier = T;
0095
0096
0097 public:
0098
0099 CELER_FUNCTION ConditionalTrackSlotExecutor(
0100 ParamsPtr params, StatePtr state, C&& applies, T&& execute_track)
0101 : params_{params}
0102 , state_{state}
0103 , applies_{celeritas::forward<C>(applies)}
0104 , execute_track_{celeritas::forward<T>(execute_track)}
0105 {
0106 }
0107
0108
0109 CELER_FUNCTION void operator()(TrackSlotId ts)
0110 {
0111 CELER_EXPECT(ts < state_->size());
0112 CoreTrackView track(*params_, *state_, ts);
0113 if (!applies_(track))
0114 {
0115 return;
0116 }
0117
0118 return execute_track_(track);
0119 }
0120
0121
0122 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId thread)
0123 {
0124
0125 return (*this)(TrackSlotId{thread.unchecked_get()});
0126 }
0127
0128 private:
0129 ParamsPtr const params_;
0130 StatePtr const state_;
0131 C applies_;
0132 T execute_track_;
0133 };
0134
0135
0136
0137
0138
0139
0140
0141
0142 struct AppliesValidVolumetric
0143 {
0144 CELER_FUNCTION bool operator()(CoreTrackView const& track) const
0145 {
0146 return AppliesValid{}(track)
0147 && !track.surface_physics().is_crossing_boundary();
0148 }
0149 };
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 struct IsSurfaceModelEqual
0165 {
0166 SurfacePhysicsOrder step;
0167 SurfaceModelId model;
0168
0169
0170 CELER_FUNCTION bool operator()(CoreTrackView const& track) const
0171 {
0172 auto s_phys = track.surface_physics();
0173 return IsStepActionEqual{s_phys.scalars().surface_stepping_action}(
0174 track)
0175 && s_phys.interface(step).surface_model_id() == model
0176 && (step != SurfacePhysicsOrder::interaction
0177 || s_phys.reflectivity_action()
0178 == ReflectivityAction::interact);
0179 }
0180 };
0181
0182
0183
0184
0185 template<class T>
0186 CELER_CTAD_FUNCTION TrackSlotExecutor(
0187 CoreParamsPtr<MemSpace::native>, CoreStatePtr<MemSpace::native>, T&&)
0188 -> TrackSlotExecutor<T>;
0189
0190 template<class C, class T>
0191 CELER_CTAD_FUNCTION ConditionalTrackSlotExecutor(
0192 CoreParamsPtr<MemSpace::native>, CoreStatePtr<MemSpace::native>, C&&, T&&)
0193 -> ConditionalTrackSlotExecutor<C, T>;
0194
0195
0196
0197
0198
0199
0200
0201 template<class T>
0202 inline CELER_FUNCTION decltype(auto) make_active_thread_executor(
0203 CoreParamsPtr<MemSpace::native> params,
0204 CoreStatePtr<MemSpace::native> const& state,
0205 T&& apply_track)
0206 {
0207 return ConditionalTrackSlotExecutor{
0208 params, state, AppliesValid{}, celeritas::forward<T>(apply_track)};
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219 template<class T>
0220 inline CELER_FUNCTION decltype(auto) make_action_thread_executor(
0221 CoreParamsPtr<MemSpace::native> params,
0222 CoreStatePtr<MemSpace::native> state,
0223 ActionId action,
0224 T&& apply_track)
0225 {
0226 CELER_EXPECT(action);
0227 return ConditionalTrackSlotExecutor{params,
0228 state,
0229 IsStepActionEqual{action},
0230 celeritas::forward<T>(apply_track)};
0231 }
0232
0233
0234
0235
0236
0237
0238 template<class T>
0239 inline CELER_FUNCTION decltype(auto) make_active_volumetric_thread_executor(
0240 CoreParamsPtr<MemSpace::native> params,
0241 CoreStatePtr<MemSpace::native> const& state,
0242 T&& apply_track)
0243 {
0244 return ConditionalTrackSlotExecutor{params,
0245 state,
0246 AppliesValidVolumetric{},
0247 celeritas::forward<T>(apply_track)};
0248 }
0249
0250
0251
0252
0253
0254
0255
0256
0257 template<class T>
0258 inline CELER_FUNCTION decltype(auto) make_surface_physics_executor(
0259 CoreParamsPtr<MemSpace::native> params,
0260 CoreStatePtr<MemSpace::native> const& state,
0261 SurfacePhysicsOrder step,
0262 SurfaceModelId model,
0263 T&& apply_track)
0264 {
0265 CELER_EXPECT(step != SurfacePhysicsOrder::size_);
0266 CELER_EXPECT(model);
0267 return ConditionalTrackSlotExecutor{params,
0268 state,
0269 IsSurfaceModelEqual{step, model},
0270 celeritas::forward<T>(apply_track)};
0271 }
0272
0273
0274 }
0275 }