File indexing completed on 2025-02-22 10:31:29
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <memory>
0011 #include <utility>
0012 #include <vector>
0013
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Types.hh"
0016 #include "corecel/cont/Range.hh"
0017 #include "corecel/cont/Span.hh"
0018 #include "corecel/data/CollectionMirror.hh"
0019 #include "corecel/data/ParamsDataInterface.hh"
0020 #include "celeritas/Quantities.hh"
0021 #include "celeritas/Types.hh"
0022 #include "celeritas/Units.hh"
0023 #include "celeritas/global/ActionInterface.hh"
0024
0025 #include "Model.hh"
0026 #include "PhysicsData.hh"
0027 #include "Process.hh"
0028
0029 namespace celeritas
0030 {
0031 class ActionRegistry;
0032 class AtomicRelaxationParams;
0033 class MaterialParams;
0034 class ParticleParams;
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 struct PhysicsParamsOptions
0078 {
0079 using Energy = units::MevEnergy;
0080
0081
0082
0083 real_type min_range = 1 * units::millimeter;
0084 real_type max_step_over_range = 0.2;
0085 real_type fixed_step_limiter = 0;
0086
0087
0088
0089
0090 real_type min_eprime_over_e = 0.8;
0091 real_type linear_loss_limit = 0.01;
0092 Energy lowest_electron_energy = Energy{0.001};
0093
0094
0095
0096
0097 real_type lambda_limit = 1 * units::millimeter;
0098 real_type range_factor = 0.04;
0099 real_type safety_factor = 0.6;
0100 MscStepLimitAlgorithm step_limit_algorithm{MscStepLimitAlgorithm::safety};
0101
0102
0103 real_type secondary_stack_factor = 3;
0104 bool disable_integral_xs = false;
0105 };
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 class PhysicsParams final : public ParamsDataInterface<PhysicsParamsData>
0129 {
0130 public:
0131
0132
0133 using SPConstParticles = std::shared_ptr<ParticleParams const>;
0134 using SPConstMaterials = std::shared_ptr<MaterialParams const>;
0135 using SPConstProcess = std::shared_ptr<Process const>;
0136 using SPConstModel = std::shared_ptr<Model const>;
0137 using SPConstRelaxation = std::shared_ptr<AtomicRelaxationParams const>;
0138
0139 using VecProcess = std::vector<SPConstProcess>;
0140 using SpanConstProcessId = Span<ProcessId const>;
0141 using ActionIdRange = Range<ActionId>;
0142 using Options = PhysicsParamsOptions;
0143
0144
0145
0146 struct Input
0147 {
0148 SPConstParticles particles;
0149 SPConstMaterials materials;
0150 VecProcess processes;
0151 SPConstRelaxation relaxation;
0152 ActionRegistry* action_registry = nullptr;
0153
0154 Options options;
0155 };
0156
0157 public:
0158
0159 explicit PhysicsParams(Input);
0160
0161
0162
0163
0164 ModelId::size_type num_models() const { return models_.size(); }
0165
0166
0167 ProcessId::size_type num_processes() const { return processes_.size(); }
0168
0169
0170 inline ParticleId::size_type num_particles() const;
0171
0172
0173 inline ProcessId::size_type max_particle_processes() const;
0174
0175
0176 inline SPConstModel const& model(ModelId) const;
0177
0178
0179 inline SPConstProcess const& process(ProcessId) const;
0180
0181
0182 inline ProcessId process_id(ModelId id) const;
0183
0184
0185 inline ActionIdRange model_actions() const;
0186
0187
0188 SpanConstProcessId processes(ParticleId) const;
0189
0190
0191 HostRef const& host_ref() const final { return data_.host_ref(); }
0192
0193
0194 DeviceRef const& device_ref() const final { return data_.device_ref(); }
0195
0196 private:
0197 using SPAction = std::shared_ptr<StaticConcreteAction>;
0198 using VecModel = std::vector<std::pair<SPConstModel, ProcessId>>;
0199 using HostValue = celeritas::HostVal<PhysicsParamsData>;
0200
0201
0202 SPAction pre_step_action_;
0203 SPAction msc_action_;
0204 SPAction range_action_;
0205 SPAction discrete_action_;
0206 SPAction integral_rejection_action_;
0207 SPAction failure_action_;
0208 SPAction fixed_step_action_;
0209
0210
0211 VecProcess processes_;
0212 VecModel models_;
0213 SPConstRelaxation relaxation_;
0214
0215
0216 CollectionMirror<PhysicsParamsData> data_;
0217
0218 private:
0219 VecModel build_models(ActionRegistry*) const;
0220 void build_options(Options const& opts, HostValue* data) const;
0221 void build_ids(ParticleParams const& particles, HostValue* data) const;
0222 void build_xs(Options const& opts,
0223 MaterialParams const& mats,
0224 HostValue* data) const;
0225 void build_model_xs(MaterialParams const& mats, HostValue* data) const;
0226 };
0227
0228
0229
0230
0231
0232
0233
0234 auto PhysicsParams::num_particles() const -> ParticleId::size_type
0235 {
0236 return this->host_ref().process_ids.size();
0237 }
0238
0239
0240
0241
0242
0243 auto PhysicsParams::max_particle_processes() const -> ProcessId::size_type
0244 {
0245 return this->host_ref().scalars.max_particle_processes;
0246 }
0247
0248
0249
0250
0251
0252 auto PhysicsParams::model(ModelId id) const -> SPConstModel const&
0253 {
0254 CELER_EXPECT(id < this->num_models());
0255 return models_[id.get()].first;
0256 }
0257
0258
0259
0260
0261
0262 auto PhysicsParams::process(ProcessId id) const -> SPConstProcess const&
0263 {
0264 CELER_EXPECT(id < this->num_processes());
0265 return processes_[id.get()];
0266 }
0267
0268
0269
0270
0271
0272 ProcessId PhysicsParams::process_id(ModelId id) const
0273 {
0274 CELER_EXPECT(id < this->num_models());
0275 return models_[id.get()].second;
0276 }
0277
0278
0279
0280
0281
0282 auto PhysicsParams::model_actions() const -> ActionIdRange
0283 {
0284 auto offset = host_ref().scalars.model_to_action;
0285 return {ActionId{offset}, ActionId{offset + this->num_models()}};
0286 }
0287
0288
0289 }