forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessBuilder.cc
244 lines (214 loc) · 8.38 KB
/
ProcessBuilder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//----------------------------------*-C++-*----------------------------------//
// Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/phys/ProcessBuilder.cc
//---------------------------------------------------------------------------//
#include "ProcessBuilder.hh"
#include <set>
#include <unordered_map>
#include <utility>
#include "corecel/Assert.hh"
#include "corecel/io/Logger.hh"
#include "celeritas/em/process/BremsstrahlungProcess.hh"
#include "celeritas/em/process/ComptonProcess.hh"
#include "celeritas/em/process/CoulombScatteringProcess.hh"
#include "celeritas/em/process/EIonizationProcess.hh"
#include "celeritas/em/process/EPlusAnnihilationProcess.hh"
#include "celeritas/em/process/GammaConversionProcess.hh"
#include "celeritas/em/process/PhotoelectricProcess.hh"
#include "celeritas/em/process/RayleighProcess.hh"
#include "celeritas/io/ImportData.hh"
#include "celeritas/io/ImportedElementalMapLoader.hh"
#include "celeritas/io/LivermorePEReader.hh"
#include "celeritas/io/SeltzerBergerReader.hh"
#include "ImportedProcessAdapter.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Get an ordered set of all available processes.
*/
auto ProcessBuilder::get_all_process_classes(
std::vector<ImportProcess> const& processes) -> std::set<IPC>
{
std::set<ImportProcessClass> result;
for (auto const& p : processes)
{
result.insert(p.process_class);
}
return result;
}
//---------------------------------------------------------------------------//
/*!
* Construct imported process data.
*
* \pre The import data must have already been converted to the native unit
* system.
*
* \warning If Livermore and SB data is present in the import data, their
* lifetime must extend beyond the \c ProcessBuilder instance.
*/
ProcessBuilder::ProcessBuilder(ImportData const& data,
SPConstParticle particle,
SPConstMaterial material,
UserBuildMap user_build,
Options options)
: input_{std::move(material), std::move(particle), nullptr}
, user_build_map_(std::move(user_build))
, selection_(options.brems_selection)
, brem_combined_(options.brem_combined)
, enable_lpm_(data.em_params.lpm)
, use_integral_xs_(data.em_params.integral_approach)
, coulomb_screening_factor_(data.em_params.screening_factor)
{
CELER_EXPECT(input_.material);
CELER_EXPECT(input_.particle);
CELER_EXPECT(std::string(data.units) == units::NativeTraits::label());
input_.imported = std::make_shared<ImportedProcesses>(data.processes);
if (!data.sb_data.empty())
{
read_sb_ = make_imported_element_loader(data.sb_data);
}
if (!data.livermore_pe_data.empty())
{
read_livermore_ = make_imported_element_loader(data.livermore_pe_data);
}
}
//---------------------------------------------------------------------------//
/*!
* Construct without custom user builders.
*/
ProcessBuilder::ProcessBuilder(ImportData const& data,
SPConstParticle particle,
SPConstMaterial material,
Options options)
: ProcessBuilder(
data, std::move(particle), std::move(material), UserBuildMap{}, options)
{
}
//---------------------------------------------------------------------------//
//! Default destructor
ProcessBuilder::~ProcessBuilder() = default;
//---------------------------------------------------------------------------//
/*!
* Construct a \c Process from a given processs class.
*
* This may return a null process (with a warning) if the user specifically
* requests that the process be omitted.
*/
auto ProcessBuilder::operator()(IPC ipc) -> SPProcess
{
// First, look for user-supplied processes
{
auto user_iter = user_build_map_.find(ipc);
if (user_iter != user_build_map_.end())
{
return user_iter->second(input_);
}
}
using BuilderMemFn = SPProcess (ProcessBuilder::*)();
static std::unordered_map<IPC, BuilderMemFn> const builtin_build{
{IPC::annihilation, &ProcessBuilder::build_annihilation},
{IPC::compton, &ProcessBuilder::build_compton},
{IPC::conversion, &ProcessBuilder::build_conversion},
{IPC::coulomb_scat, &ProcessBuilder::build_coulomb},
{IPC::e_brems, &ProcessBuilder::build_ebrems},
{IPC::e_ioni, &ProcessBuilder::build_eioni},
{IPC::photoelectric, &ProcessBuilder::build_photoelectric},
{IPC::rayleigh, &ProcessBuilder::build_rayleigh},
};
// Next, try built-in processes
{
auto iter = builtin_build.find(ipc);
CELER_VALIDATE(iter != builtin_build.end(),
<< "cannot build unsupported EM process '"
<< to_cstring(ipc) << "'");
BuilderMemFn build_impl{iter->second};
auto result = (this->*build_impl)();
CELER_ENSURE(result);
return result;
}
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_eioni() -> SPProcess
{
EIonizationProcess::Options options;
options.use_integral_xs = use_integral_xs_;
return std::make_shared<EIonizationProcess>(
this->particle(), this->imported(), options);
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_ebrems() -> SPProcess
{
BremsstrahlungProcess::Options options;
options.selection = selection_;
options.combined_model = brem_combined_;
options.enable_lpm = enable_lpm_;
options.use_integral_xs = use_integral_xs_;
if (!read_sb_)
{
read_sb_ = SeltzerBergerReader{};
}
return std::make_shared<BremsstrahlungProcess>(
this->particle(), this->material(), this->imported(), read_sb_, options);
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_photoelectric() -> SPProcess
{
if (!read_livermore_)
{
read_livermore_ = LivermorePEReader{};
}
return std::make_shared<PhotoelectricProcess>(
this->particle(), this->material(), this->imported(), read_livermore_);
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_compton() -> SPProcess
{
return std::make_shared<ComptonProcess>(this->particle(), this->imported());
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_conversion() -> SPProcess
{
GammaConversionProcess::Options options;
options.enable_lpm = enable_lpm_;
return std::make_shared<GammaConversionProcess>(
this->particle(), this->imported(), options);
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_rayleigh() -> SPProcess
{
return std::make_shared<RayleighProcess>(
this->particle(), this->material(), this->imported());
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_annihilation() -> SPProcess
{
EPlusAnnihilationProcess::Options options;
options.use_integral_xs = use_integral_xs_;
return std::make_shared<EPlusAnnihilationProcess>(this->particle(),
options);
}
//---------------------------------------------------------------------------//
auto ProcessBuilder::build_coulomb() -> SPProcess
{
WentzelModel::Options options;
options.screening_factor = coulomb_screening_factor_;
options.use_integral_xs = use_integral_xs_;
return std::make_shared<CoulombScatteringProcess>(
this->particle(), this->material(), this->imported(), options);
}
//---------------------------------------------------------------------------//
/*!
* Warn and return a null process.
*/
auto WarnAndIgnoreProcess::operator()(argument_type) const -> result_type
{
CELER_LOG(warning) << "Omitting " << to_cstring(this->process)
<< " from physics process list";
return nullptr;
}
//---------------------------------------------------------------------------//
} // namespace celeritas