File indexing completed on 2025-09-17 08:53:44
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Macros.hh"
0011 #include "celeritas/Quantities.hh"
0012 #include "celeritas/Types.hh"
0013 #include "celeritas/grid/NonuniformGridCalculator.hh"
0014
0015 #include "PhysicsData.hh"
0016 #include "Types.hh"
0017
0018 namespace celeritas
0019 {
0020 namespace optical
0021 {
0022
0023
0024
0025
0026
0027
0028
0029 class PhysicsTrackView
0030 {
0031 public:
0032
0033
0034 using PhysicsParamsRef = NativeCRef<PhysicsParamsData>;
0035 using PhysicsStateRef = NativeRef<PhysicsStateData>;
0036 using Energy = units::MevEnergy;
0037
0038
0039
0040 struct Initializer
0041 {
0042 };
0043
0044 public:
0045
0046 inline CELER_FUNCTION PhysicsTrackView(PhysicsParamsRef const&,
0047 PhysicsStateRef const&,
0048 OptMatId,
0049 TrackSlotId);
0050
0051
0052 inline CELER_FUNCTION PhysicsTrackView& operator=(Initializer const&);
0053
0054
0055
0056
0057 inline CELER_FUNCTION void reset_interaction_mfp();
0058
0059
0060 inline CELER_FUNCTION void interaction_mfp(real_type);
0061
0062
0063 inline CELER_FUNCTION real_type interaction_mfp() const;
0064
0065
0066 inline CELER_FUNCTION bool has_interaction_mfp() const;
0067
0068
0069
0070
0071 inline CELER_FUNCTION void macro_xs(real_type xs);
0072
0073
0074 inline CELER_FUNCTION real_type macro_xs() const;
0075
0076
0077
0078
0079 inline CELER_FUNCTION ModelId::size_type num_models() const;
0080
0081
0082 inline CELER_FUNCTION ActionId model_to_action(ModelId) const;
0083
0084
0085 inline CELER_FUNCTION ModelId action_to_model(ActionId) const;
0086
0087
0088 inline CELER_FUNCTION ActionId discrete_action() const;
0089
0090
0091
0092
0093 inline CELER_FUNCTION ValueGridId mfp_grid(ModelId) const;
0094
0095
0096 inline CELER_FUNCTION real_type calc_mfp(ModelId, Energy) const;
0097
0098 private:
0099 PhysicsParamsRef const& params_;
0100 PhysicsStateRef const& states_;
0101 OptMatId const opt_material_;
0102 TrackSlotId const track_id_;
0103 };
0104
0105
0106
0107
0108
0109
0110
0111 CELER_FUNCTION
0112 PhysicsTrackView::PhysicsTrackView(PhysicsParamsRef const& params,
0113 PhysicsStateRef const& states,
0114 OptMatId opt_mat,
0115 TrackSlotId track_id)
0116 : params_(params)
0117 , states_(states)
0118 , opt_material_(opt_mat)
0119 , track_id_(track_id)
0120 {
0121 CELER_EXPECT(track_id_ < states_.size());
0122 CELER_EXPECT(opt_mat < params_.scalars.num_materials);
0123 }
0124
0125
0126
0127
0128
0129 CELER_FUNCTION PhysicsTrackView& PhysicsTrackView::operator=(Initializer const&)
0130 {
0131 this->reset_interaction_mfp();
0132 return *this;
0133 }
0134
0135
0136
0137
0138
0139 CELER_FUNCTION void PhysicsTrackView::reset_interaction_mfp()
0140 {
0141 states_.interaction_mfp[track_id_] = 0;
0142 }
0143
0144
0145
0146
0147
0148 CELER_FUNCTION void PhysicsTrackView::interaction_mfp(real_type mfp)
0149 {
0150 states_.interaction_mfp[track_id_] = mfp;
0151 }
0152
0153
0154
0155
0156
0157 CELER_FUNCTION real_type PhysicsTrackView::interaction_mfp() const
0158 {
0159 return states_.interaction_mfp[track_id_];
0160 }
0161
0162
0163
0164
0165
0166 CELER_FUNCTION bool PhysicsTrackView::has_interaction_mfp() const
0167 {
0168 return states_.interaction_mfp[track_id_] > 0;
0169 }
0170
0171
0172
0173
0174
0175 CELER_FUNCTION ModelId::size_type PhysicsTrackView::num_models() const
0176 {
0177 return params_.scalars.num_models;
0178 }
0179
0180
0181
0182
0183
0184 CELER_FUNCTION ActionId PhysicsTrackView::model_to_action(ModelId mid) const
0185 {
0186 CELER_EXPECT(mid < this->num_models());
0187 return ActionId{mid.get() + params_.scalars.model_to_action};
0188 }
0189
0190
0191
0192
0193
0194 CELER_FUNCTION ModelId PhysicsTrackView::action_to_model(ActionId aid) const
0195 {
0196 if (!aid)
0197 return ModelId{};
0198
0199
0200 ModelId::size_type result = aid.unchecked_get()
0201 - params_.scalars.model_to_action;
0202
0203 if (result >= this->num_models())
0204 return ModelId{};
0205
0206 return ModelId{result};
0207 }
0208
0209
0210
0211
0212
0213 CELER_FUNCTION ActionId PhysicsTrackView::discrete_action() const
0214 {
0215 return params_.scalars.discrete_action();
0216 }
0217
0218
0219
0220
0221
0222
0223
0224
0225 CELER_FUNCTION ValueGridId PhysicsTrackView::mfp_grid(ModelId model) const
0226 {
0227 CELER_EXPECT(model < this->num_models());
0228
0229 ValueGridId grid_id{opt_material_.get()
0230 + model.get() * params_.scalars.num_materials};
0231
0232 CELER_ENSURE(grid_id < params_.grids.size());
0233 return grid_id;
0234 }
0235
0236
0237
0238
0239
0240
0241
0242
0243 CELER_FUNCTION real_type PhysicsTrackView::calc_mfp(ModelId model,
0244 Energy energy) const
0245 {
0246 NonuniformGridCalculator calc{params_.grids[this->mfp_grid(model)], params_.reals};
0247 real_type result = calc(value_as<Energy>(energy));
0248 CELER_ENSURE(result > 0);
0249 return result;
0250 }
0251
0252
0253
0254
0255
0256 CELER_FUNCTION real_type PhysicsTrackView::macro_xs() const
0257 {
0258 return states_.macro_xs[track_id_];
0259 }
0260
0261
0262
0263
0264
0265 CELER_FUNCTION void PhysicsTrackView::macro_xs(real_type xs)
0266 {
0267 states_.macro_xs[track_id_] = xs;
0268 }
0269
0270
0271 }
0272 }