File indexing completed on 2025-12-15 10:10:58
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <utility>
0012 #include <vector>
0013
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Types.hh"
0016 #include "corecel/cont/LabelIdMultiMap.hh"
0017 #include "corecel/cont/Span.hh"
0018 #include "corecel/data/Collection.hh"
0019 #include "corecel/data/CollectionMirror.hh"
0020 #include "corecel/data/ParamsDataInterface.hh"
0021 #include "corecel/io/Label.hh"
0022 #include "celeritas/Quantities.hh"
0023 #include "celeritas/Types.hh"
0024 #include "celeritas/phys/AtomicNumber.hh"
0025
0026 #include "ElementView.hh"
0027 #include "IsotopeView.hh"
0028 #include "MaterialData.hh"
0029 #include "MaterialView.hh"
0030
0031 namespace celeritas
0032 {
0033 struct ImportData;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class MaterialParams final : public ParamsDataInterface<MaterialParamsData>
0047 {
0048 public:
0049
0050
0051 using MatId = PhysMatId;
0052 using SpanConstMaterialId = Span<MatId const>;
0053 using SpanConstElementId = Span<ElementId const>;
0054 using SpanConstIsotopeId = Span<IsotopeId const>;
0055
0056
0057
0058 struct IsotopeInput
0059 {
0060
0061
0062 using AtomicMassNumber = AtomicNumber;
0063 using MevEnergy = units::MevEnergy;
0064
0065
0066 AtomicNumber atomic_number;
0067 AtomicMassNumber atomic_mass_number;
0068 MevEnergy binding_energy;
0069 MevEnergy proton_loss_energy;
0070 MevEnergy neutron_loss_energy;
0071 units::MevMass nuclear_mass;
0072 Label label;
0073 };
0074
0075
0076 struct ElementInput
0077 {
0078 AtomicNumber atomic_number;
0079 units::AmuMass atomic_mass;
0080 std::vector<std::pair<IsotopeId, real_type>>
0081 isotopes_fractions;
0082 Label label;
0083 };
0084
0085
0086 struct MaterialInput
0087 {
0088 real_type number_density;
0089 real_type temperature;
0090 MatterState matter_state;
0091 std::vector<std::pair<ElementId, real_type>>
0092 elements_fractions;
0093 Label label;
0094 };
0095
0096
0097 struct Input
0098 {
0099 std::vector<IsotopeInput> isotopes;
0100 std::vector<ElementInput> elements;
0101 std::vector<MaterialInput> materials;
0102 std::vector<OptMatId> mat_to_optical;
0103 };
0104
0105 public:
0106
0107 static std::shared_ptr<MaterialParams> from_import(ImportData const& data);
0108
0109
0110 explicit MaterialParams(Input const& inp);
0111
0112
0113 MatId::size_type size() const { return mat_labels_.size(); }
0114
0115
0116
0117
0118
0119 MatId::size_type num_materials() const { return mat_labels_.size(); }
0120
0121
0122 Label const& id_to_label(MatId id) const;
0123
0124
0125 MatId find_material(std::string const& name) const;
0126
0127
0128 SpanConstMaterialId find_materials(std::string const& name) const;
0129
0130
0131
0132
0133
0134
0135 ElementId::size_type num_elements() const { return el_labels_.size(); }
0136
0137
0138 Label const& id_to_label(ElementId id) const;
0139
0140
0141 ElementId find_element(std::string const& name) const;
0142
0143
0144 SpanConstElementId find_elements(std::string const& name) const;
0145
0146
0147
0148
0149
0150
0151 IsotopeId::size_type num_isotopes() const { return isot_labels_.size(); }
0152
0153
0154 Label const& id_to_label(IsotopeId id) const;
0155
0156
0157 IsotopeId find_isotope(std::string const& name) const;
0158
0159
0160 SpanConstIsotopeId find_isotopes(std::string const& name) const;
0161
0162
0163
0164 inline MaterialView get(MatId id) const;
0165
0166
0167 inline ElementView get(ElementId id) const;
0168
0169
0170 inline IsotopeView get(IsotopeId id) const;
0171
0172
0173 inline IsotopeComponentId::size_type max_isotope_components() const;
0174
0175
0176 inline ElementComponentId::size_type max_element_components() const;
0177
0178
0179 inline bool is_missing_isotopes() const { return this->num_isotopes(); }
0180
0181
0182 HostRef const& host_ref() const final { return data_.host_ref(); }
0183
0184
0185 DeviceRef const& device_ref() const final { return data_.device_ref(); }
0186
0187 private:
0188
0189 LabelIdMultiMap<MatId> mat_labels_;
0190 LabelIdMultiMap<ElementId> el_labels_;
0191 LabelIdMultiMap<IsotopeId> isot_labels_;
0192
0193
0194 CollectionMirror<MaterialParamsData> data_;
0195
0196
0197 using HostValue = HostVal<MaterialParamsData>;
0198 void append_element_def(ElementInput const& inp, HostValue*);
0199 void append_isotope_def(IsotopeInput const& inp, HostValue*);
0200 ItemRange<MatElementComponent>
0201 extend_elcomponents(MaterialInput const& inp, HostValue*) const;
0202 void append_material_def(MaterialInput const& inp, HostValue*);
0203 };
0204
0205
0206
0207
0208
0209
0210
0211 MaterialView MaterialParams::get(MatId id) const
0212 {
0213 CELER_EXPECT(id < this->host_ref().materials.size());
0214 return MaterialView(this->host_ref(), id);
0215 }
0216
0217
0218
0219
0220
0221 ElementView MaterialParams::get(ElementId id) const
0222 {
0223 CELER_EXPECT(id < this->host_ref().elements.size());
0224 return ElementView(this->host_ref(), id);
0225 }
0226
0227
0228
0229
0230
0231 IsotopeView MaterialParams::get(IsotopeId id) const
0232 {
0233 CELER_EXPECT(id < this->host_ref().isotopes.size());
0234 return IsotopeView(this->host_ref(), id);
0235 }
0236
0237
0238
0239
0240
0241 IsotopeComponentId::size_type MaterialParams::max_isotope_components() const
0242 {
0243 return this->host_ref().max_isotope_components;
0244 }
0245
0246
0247
0248
0249
0250 ElementComponentId::size_type MaterialParams::max_element_components() const
0251 {
0252 return this->host_ref().max_element_components;
0253 }
0254
0255
0256 }