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