File indexing completed on 2025-09-16 08:52:25
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "CutoffData.hh"
0010 #include "Secondary.hh"
0011
0012 namespace celeritas
0013 {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 class CutoffView
0029 {
0030 public:
0031
0032
0033 using CutoffId = OpaqueId<ParticleCutoff>;
0034 using CutoffData = NativeCRef<CutoffParamsData>;
0035 using Energy = units::MevEnergy;
0036
0037
0038 public:
0039
0040 inline CELER_FUNCTION
0041 CutoffView(CutoffData const& params, PhysMatId material);
0042
0043
0044 inline CELER_FUNCTION Energy energy(ParticleId particle) const;
0045
0046
0047 inline CELER_FUNCTION real_type range(ParticleId particle) const;
0048
0049
0050 inline CELER_FUNCTION bool apply_post_interaction() const;
0051
0052
0053 inline CELER_FUNCTION bool apply(Secondary const&) const;
0054
0055 private:
0056 CutoffData const& params_;
0057 PhysMatId material_;
0058
0059
0060
0061
0062 CELER_FORCEINLINE_FUNCTION ParticleCutoff get(ParticleId particle) const;
0063 };
0064
0065
0066
0067
0068
0069
0070
0071 CELER_FUNCTION
0072 CutoffView::CutoffView(CutoffData const& params, PhysMatId material)
0073 : params_(params), material_(material)
0074 {
0075 CELER_EXPECT(params_);
0076 CELER_EXPECT(material_ < params_.num_materials);
0077 }
0078
0079
0080
0081
0082
0083 CELER_FUNCTION auto CutoffView::energy(ParticleId particle) const -> Energy
0084 {
0085 return this->get(particle).energy;
0086 }
0087
0088
0089
0090
0091
0092 CELER_FUNCTION real_type CutoffView::range(ParticleId particle) const
0093 {
0094 return this->get(particle).range;
0095 }
0096
0097
0098
0099
0100
0101 CELER_FUNCTION bool CutoffView::apply_post_interaction() const
0102 {
0103 return params_.apply_post_interaction;
0104 }
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 CELER_FUNCTION bool CutoffView::apply(Secondary const& secondary) const
0115 {
0116 return (secondary.particle_id == params_.ids.gamma
0117 || secondary.particle_id == params_.ids.electron
0118 || secondary.particle_id == params_.ids.positron)
0119 && secondary.energy < this->energy(secondary.particle_id);
0120 }
0121
0122
0123
0124
0125
0126 CELER_FUNCTION ParticleCutoff CutoffView::get(ParticleId particle) const
0127 {
0128 CELER_EXPECT(particle < params_.id_to_index.size());
0129 CELER_EXPECT(params_.id_to_index[particle] < params_.num_particles);
0130 CutoffId id{params_.num_materials * params_.id_to_index[particle]
0131 + material_.get()};
0132 CELER_ENSURE(id < params_.cutoffs.size());
0133 return params_.cutoffs[id];
0134 }
0135
0136
0137 }