File indexing completed on 2026-12-05 10:55:01
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 MaterialView(MaterialParamsRef const& params,
0041 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(
0067 ElementComponentId id) const;
0068
0069
0070 inline CELER_FUNCTION ElementId element_id(ElementComponentId id) const;
0071
0072
0073 inline CELER_FUNCTION real_type get_element_density(
0074 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 MatId material_;
0103
0104
0105
0106 CELER_FORCEINLINE_FUNCTION MaterialRecord const& material_def() const;
0107 };
0108
0109
0110
0111
0112
0113
0114
0115 CELER_FUNCTION MaterialView::MaterialView(MaterialParamsRef const& params,
0116 MatId id)
0117 : params_(params), material_(id)
0118 {
0119 CELER_EXPECT(id < params.materials.size());
0120 }
0121
0122
0123
0124
0125
0126 CELER_FUNCTION auto MaterialView::material_id() const -> MatId
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 OptMatId 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
0189
0190 CELER_FUNCTION ElementView MaterialView::element_record(
0191 ElementComponentId id) const
0192 {
0193 CELER_EXPECT(id < this->material_def().elements.size());
0194 return ElementView(params_, this->element_id(id));
0195 }
0196
0197
0198
0199
0200
0201 CELER_FUNCTION ElementId MaterialView::element_id(ElementComponentId id) const
0202 {
0203 CELER_EXPECT(id < this->material_def().elements.size());
0204 return this->elements()[id.get()].element;
0205 }
0206
0207
0208
0209
0210
0211 CELER_FUNCTION real_type MaterialView::get_element_density(
0212 ElementComponentId id) const
0213 {
0214 CELER_EXPECT(id < this->material_def().elements.size());
0215 return this->number_density() * this->elements()[id.get()].fraction;
0216 }
0217
0218
0219
0220
0221
0222 CELER_FUNCTION Span<MatElementComponent const> MaterialView::elements() const
0223 {
0224 return params_.elcomponents[this->material_def().elements];
0225 }
0226
0227
0228
0229
0230
0231
0232
0233 CELER_FUNCTION real_type MaterialView::zeff() const
0234 {
0235 return this->material_def().zeff;
0236 }
0237
0238
0239
0240
0241
0242 CELER_FUNCTION real_type MaterialView::density() const
0243 {
0244 return this->material_def().density;
0245 }
0246
0247
0248
0249
0250
0251 CELER_FUNCTION real_type MaterialView::electron_density() const
0252 {
0253 return this->material_def().electron_density;
0254 }
0255
0256
0257
0258
0259
0260 CELER_FUNCTION real_type MaterialView::radiation_length() const
0261 {
0262 return this->material_def().rad_length;
0263 }
0264
0265
0266
0267
0268
0269 CELER_FUNCTION units::MevEnergy MaterialView::mean_excitation_energy() const
0270 {
0271 return this->material_def().mean_exc_energy;
0272 }
0273
0274
0275
0276
0277
0278 CELER_FUNCTION units::LogMevEnergy
0279 MaterialView::log_mean_excitation_energy() const
0280 {
0281 return this->material_def().log_mean_exc_energy;
0282 }
0283
0284
0285
0286
0287
0288
0289
0290 CELER_FUNCTION MaterialRecord const& MaterialView::material_def() const
0291 {
0292 return params_.materials[material_];
0293 }
0294
0295
0296 }