File indexing completed on 2025-02-22 10:31:25
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 "ElementView.hh"
0015 #include "MaterialData.hh"
0016
0017 namespace celeritas
0018 {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 class MaterialView
0031 {
0032 public:
0033
0034
0035 using MaterialParamsRef = NativeCRef<MaterialParamsData>;
0036
0037
0038 public:
0039
0040 inline CELER_FUNCTION
0041 MaterialView(MaterialParamsRef const& params, MaterialId id);
0042
0043
0044
0045
0046 CELER_FORCEINLINE_FUNCTION MaterialId material_id() const;
0047
0048
0049 CELER_FORCEINLINE_FUNCTION real_type number_density() const;
0050
0051
0052 CELER_FORCEINLINE_FUNCTION real_type temperature() const;
0053
0054
0055 CELER_FORCEINLINE_FUNCTION MatterState matter_state() const;
0056
0057
0058 CELER_FORCEINLINE_FUNCTION OpticalMaterialId optical_material_id() const;
0059
0060
0061
0062
0063 inline CELER_FUNCTION ElementComponentId::size_type num_elements() const;
0064
0065
0066 inline CELER_FUNCTION ElementView
0067 make_element_view(ElementComponentId id) const;
0068
0069
0070 inline CELER_FUNCTION ElementId element_id(ElementComponentId id) const;
0071
0072
0073 inline CELER_FUNCTION real_type
0074 get_element_density(ElementComponentId id) const;
0075
0076
0077 inline CELER_FUNCTION Span<MatElementComponent const> elements() const;
0078
0079
0080
0081
0082 inline CELER_FUNCTION real_type zeff() const;
0083
0084
0085 inline CELER_FUNCTION real_type density() const;
0086
0087
0088 inline CELER_FUNCTION real_type electron_density() const;
0089
0090
0091 inline CELER_FUNCTION real_type radiation_length() const;
0092
0093
0094 inline CELER_FUNCTION units::MevEnergy mean_excitation_energy() const;
0095
0096
0097 inline CELER_FUNCTION units::LogMevEnergy
0098 log_mean_excitation_energy() const;
0099
0100 private:
0101 MaterialParamsRef const& params_;
0102 MaterialId material_;
0103
0104
0105
0106 CELER_FORCEINLINE_FUNCTION MaterialRecord const& material_def() const;
0107 };
0108
0109
0110
0111
0112
0113
0114
0115 CELER_FUNCTION
0116 MaterialView::MaterialView(MaterialParamsRef const& params, MaterialId id)
0117 : params_(params), material_(id)
0118 {
0119 CELER_EXPECT(id < params.materials.size());
0120 }
0121
0122
0123
0124
0125
0126 CELER_FUNCTION MaterialId MaterialView::material_id() const
0127 {
0128 return material_;
0129 }
0130
0131
0132
0133
0134
0135 CELER_FUNCTION real_type MaterialView::number_density() const
0136 {
0137 return this->material_def().number_density;
0138 }
0139
0140
0141
0142
0143
0144 CELER_FUNCTION real_type MaterialView::temperature() const
0145 {
0146 return this->material_def().temperature;
0147 }
0148
0149
0150
0151
0152
0153 CELER_FUNCTION MatterState MaterialView::matter_state() const
0154 {
0155 return this->material_def().matter_state;
0156 }
0157
0158
0159
0160
0161
0162
0163
0164
0165 CELER_FUNCTION OpticalMaterialId MaterialView::optical_material_id() const
0166 {
0167 if (params_.optical_id.empty())
0168 {
0169 return {};
0170 }
0171 CELER_ASSERT(material_ < params_.optical_id.size());
0172 return params_.optical_id[material_];
0173 }
0174
0175
0176
0177
0178
0179 CELER_FUNCTION ElementComponentId::size_type MaterialView::num_elements() const
0180 {
0181 return this->material_def().elements.size();
0182 }
0183
0184
0185
0186
0187
0188 CELER_FUNCTION ElementView
0189 MaterialView::make_element_view(ElementComponentId id) const
0190 {
0191 CELER_EXPECT(id < this->material_def().elements.size());
0192 return ElementView(params_, this->element_id(id));
0193 }
0194
0195
0196
0197
0198
0199 CELER_FUNCTION ElementId MaterialView::element_id(ElementComponentId id) const
0200 {
0201 CELER_EXPECT(id < this->material_def().elements.size());
0202 return this->elements()[id.get()].element;
0203 }
0204
0205
0206
0207
0208
0209 CELER_FUNCTION real_type
0210 MaterialView::get_element_density(ElementComponentId id) const
0211 {
0212 CELER_EXPECT(id < this->material_def().elements.size());
0213 return this->number_density() * this->elements()[id.get()].fraction;
0214 }
0215
0216
0217
0218
0219
0220 CELER_FUNCTION Span<MatElementComponent const> MaterialView::elements() const
0221 {
0222 return params_.elcomponents[this->material_def().elements];
0223 }
0224
0225
0226
0227
0228
0229
0230
0231 CELER_FUNCTION real_type MaterialView::zeff() const
0232 {
0233 return this->material_def().zeff;
0234 }
0235
0236
0237
0238
0239
0240 CELER_FUNCTION real_type MaterialView::density() const
0241 {
0242 return this->material_def().density;
0243 }
0244
0245
0246
0247
0248
0249 CELER_FUNCTION real_type MaterialView::electron_density() const
0250 {
0251 return this->material_def().electron_density;
0252 }
0253
0254
0255
0256
0257
0258 CELER_FUNCTION real_type MaterialView::radiation_length() const
0259 {
0260 return this->material_def().rad_length;
0261 }
0262
0263
0264
0265
0266
0267 CELER_FUNCTION units::MevEnergy MaterialView::mean_excitation_energy() const
0268 {
0269 return this->material_def().mean_exc_energy;
0270 }
0271
0272
0273
0274
0275
0276 CELER_FUNCTION units::LogMevEnergy
0277 MaterialView::log_mean_excitation_energy() const
0278 {
0279 return this->material_def().log_mean_exc_energy;
0280 }
0281
0282
0283
0284
0285
0286
0287
0288 CELER_FUNCTION MaterialRecord const& MaterialView::material_def() const
0289 {
0290 return params_.materials[material_];
0291 }
0292
0293
0294 }