forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlongStepFactory.cc
109 lines (100 loc) · 3.92 KB
/
AlongStepFactory.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
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-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 accel/AlongStepFactory.cc
//---------------------------------------------------------------------------//
#include "AlongStepFactory.hh"
#include <CLHEP/Units/SystemOfUnits.h>
#include "corecel/io/Logger.hh"
#include "corecel/math/ArrayUtils.hh"
#include "corecel/math/QuantityIO.hh"
#include "celeritas/em/UrbanMscParams.hh"
#include "celeritas/ext/Convert.geant.hh"
#include "celeritas/field/RZMapFieldInput.hh"
#include "celeritas/field/UniformFieldData.hh"
#include "celeritas/global/alongstep/AlongStepGeneralLinearAction.hh"
#include "celeritas/global/alongstep/AlongStepRZMapFieldMscAction.hh"
#include "celeritas/global/alongstep/AlongStepUniformMscAction.hh"
#include "celeritas/io/ImportData.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Construct with a function to return the field strength.
*
* The function is evaluated whenever Celeritas is set up (which is after
* Geant4 physics is initialized).
*/
UniformAlongStepFactory::UniformAlongStepFactory(FieldFunction f)
: get_field_(std::move(f))
{
CELER_EXPECT(get_field_);
}
//---------------------------------------------------------------------------//
/*!
* Emit an along-step action.
*
* The action will embed the linear propagator if the magnetic field strength
* is zero (or the accessor is unset).
*/
auto UniformAlongStepFactory::operator()(AlongStepFactoryInput const& input) const
-> result_type
{
// Get the field strength in tesla (or zero if accessor is undefined)
auto field_params = get_field_ ? get_field_() : UniformFieldParams{};
auto magnitude
= native_value_to<units::FieldTesla>(norm(field_params.field));
if (magnitude > zero_quantity())
{
// Create a uniform field
CELER_LOG(info) << "Creating along-step action with field strength "
<< magnitude;
return celeritas::AlongStepUniformMscAction::from_params(
input.action_id,
*input.material,
*input.particle,
field_params,
celeritas::UrbanMscParams::from_import(
*input.particle, *input.material, *input.imported),
input.imported->em_params.energy_loss_fluct);
}
else
{
CELER_LOG(info) << "Creating along-step action with no field";
return celeritas::AlongStepGeneralLinearAction::from_params(
input.action_id,
*input.material,
*input.particle,
celeritas::UrbanMscParams::from_import(
*input.particle, *input.material, *input.imported),
input.imported->em_params.energy_loss_fluct);
}
}
//---------------------------------------------------------------------------//
/*!
* Emit an along-step action with a non-uniform magnetic field.
*
* The action will embed the field propagator with a RZMapField.
*/
RZMapFieldAlongStepFactory::RZMapFieldAlongStepFactory(RZMapFieldFunction f)
: get_fieldmap_(std::move(f))
{
CELER_EXPECT(get_fieldmap_);
}
auto RZMapFieldAlongStepFactory::operator()(
AlongStepFactoryInput const& input) const -> result_type
{
CELER_LOG(info) << "Creating along-step action with a RZMapField";
return celeritas::AlongStepRZMapFieldMscAction::from_params(
input.action_id,
*input.material,
*input.particle,
get_fieldmap_(),
celeritas::UrbanMscParams::from_import(
*input.particle, *input.material, *input.imported),
input.imported->em_params.energy_loss_fluct);
}
//---------------------------------------------------------------------------//
} // namespace celeritas