BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSIntegratorType.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSIntegratorType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh" // geant4 types / globals
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30// dictionary for BDSIntegratorType for reflexivity
31template<>
32std::map<BDSIntegratorType, std::string>* BDSIntegratorType::dictionary =
33 new std::map<BDSIntegratorType, std::string> ({
34 {BDSIntegratorType::none, "none"},
35 {BDSIntegratorType::teleporter, "teleporter"},
36 {BDSIntegratorType::solenoid, "solenoid"},
37 {BDSIntegratorType::dipolerodrigues, "dipolerodrigues"},
38 {BDSIntegratorType::dipolerodrigues2, "dipolerodrigues2"},
39 {BDSIntegratorType::dipolematrix, "dipolematrix"},
40 {BDSIntegratorType::quadrupole, "quadrupole"},
41 {BDSIntegratorType::sextupole, "sextupole"},
42 {BDSIntegratorType::multipolethin, "multipolethin"},
43 {BDSIntegratorType::octupole, "octupole"},
44 {BDSIntegratorType::decapole, "decapole"},
45 {BDSIntegratorType::dipolefringe, "dipolefringe"},
46 {BDSIntegratorType::dipolefringescaling, "dipolefringescaling"},
47 {BDSIntegratorType::euler, "euler"},
48 {BDSIntegratorType::kickerthin, "kickerthin"},
49 {BDSIntegratorType::rmatrixthin, "rmatrixthin"},
50 {BDSIntegratorType::g4rk4minimumstep, "g4rk4minimumstep"},
51 {BDSIntegratorType::g4cashkarprkf45, "g4cashkarprkf45"},
52 {BDSIntegratorType::g4classicalrk4, "g4classicalrk4"},
53 {BDSIntegratorType::g4constrk4, "g4constrk4"},
54 {BDSIntegratorType::g4expliciteuler, "g4expliciteuler"},
55 {BDSIntegratorType::g4impliciteuler, "g4impliciteuler"},
56 {BDSIntegratorType::g4simpleheum, "g4simpleheum"},
57 {BDSIntegratorType::g4simplerunge, "g4simplerunge"},
58 {BDSIntegratorType::g4exacthelixstepper, "g4exacthelixstepper"},
59 {BDSIntegratorType::g4helixexpliciteuler, "g4helixexpliciteuler"},
60 {BDSIntegratorType::g4helixheum, "g4helixheum"},
61 {BDSIntegratorType::g4heliximpliciteuler, "g4heliximpliciteuler"},
62 {BDSIntegratorType::g4helixmixedstepper, "g4helixmixedstepper"},
63 {BDSIntegratorType::g4helixsimplerunge, "g4helixsimplerunge"},
64 {BDSIntegratorType::g4nystromrk4, "g4nystromrk4"},
65 {BDSIntegratorType::g4rkg3stepper, "g4rkg3stepper"},
66 {BDSIntegratorType::rmatrixthin, "rmatrixthin"},
67 {BDSIntegratorType::paralleltransport, "paralleltransport"},
68 {BDSIntegratorType::cavityfringe, "cavityfringe"}
69#if G4VERSION_NUMBER > 1029
70 // introduced in version 10.3
71 ,
72 {BDSIntegratorType::g4bogackishampine23, "g4bogackishampine23"},
73 {BDSIntegratorType::g4bogackishampine45, "g4bogackishampine45"},
74 {BDSIntegratorType::g4dolomcprirk34, "g4dolomcprirk34"},
75 {BDSIntegratorType::g4dormandprince745, "g4dormandprince745"},
76 {BDSIntegratorType::g4dormandprincerk56, "g4dormandprincerk56"},
77 {BDSIntegratorType::g4tsitourasrk45, "g4tsitourasrk45"}
78#endif
79#if G4VERSION_NUMBER > 1039
80 // introduced in version 10.4
81 // g4dormandprincerk78 is broken in 10.3 but fixed in 10.4 - safe to use now
82 ,
83 {BDSIntegratorType::g4dormandprincerk78, "g4dormandprincerk78"},
84 {BDSIntegratorType::g4rk547feq1, "g4rk547feq1"},
85 {BDSIntegratorType::g4rk547feq2, "g4rk547feq2"},
86 {BDSIntegratorType::g4rk547feq3, "g4rk547feq3"}
87#endif
88 });
89
91{
92 std::map<G4String, BDSIntegratorType> types;
93 types["none"] = BDSIntegratorType::none;
94 types["teleporter"] = BDSIntegratorType::teleporter;
95 types["solenoid"] = BDSIntegratorType::solenoid;
96 types["dipolerodrigues"] = BDSIntegratorType::dipolerodrigues;
97 types["dipolerodrigues2"] = BDSIntegratorType::dipolerodrigues2;
98 types["dipolematrix"] = BDSIntegratorType::dipolematrix;
99 types["quadrupole"] = BDSIntegratorType::quadrupole;
100 types["sextupole"] = BDSIntegratorType::sextupole;
101 types["multipolethin"] = BDSIntegratorType::multipolethin;
102 types["octupole"] = BDSIntegratorType::octupole;
103 types["decapole"] = BDSIntegratorType::decapole;
104 types["dipolefringe"] = BDSIntegratorType::dipolefringe;
105 types["dipolefringescaling"] = BDSIntegratorType::dipolefringescaling;
106 types["euler"] = BDSIntegratorType::euler;
107 types["kickerthin"] = BDSIntegratorType::kickerthin;
108 types["g4rk4minimumstep"] = BDSIntegratorType::g4rk4minimumstep;
109 types["g4cashkarprkf45"] = BDSIntegratorType::g4cashkarprkf45;
110 types["g4classicalrk4"] = BDSIntegratorType::g4classicalrk4;
111 types["g4constrk4"] = BDSIntegratorType::g4constrk4;
112 types["g4expliciteuler"] = BDSIntegratorType::g4expliciteuler;
113 types["g4impliciteuler"] = BDSIntegratorType::g4impliciteuler;
114 types["g4simpleheum"] = BDSIntegratorType::g4simpleheum;
115 types["g4simplerunge"] = BDSIntegratorType::g4simplerunge;
116 types["g4exacthelixstepper"] = BDSIntegratorType::g4exacthelixstepper;
117 types["g4helixexpliciteuler"] = BDSIntegratorType::g4helixexpliciteuler;
118 types["g4helixheum"] = BDSIntegratorType::g4helixheum;
119 types["g4heliximpliciteuler"] = BDSIntegratorType::g4heliximpliciteuler;
120 types["g4helixmixedstepper"] = BDSIntegratorType::g4helixmixedstepper;
121 types["g4helixsimplerunge"] = BDSIntegratorType::g4helixsimplerunge;
122 types["g4nystromrk4"] = BDSIntegratorType::g4nystromrk4;
123 types["g4rkg3stepper"] = BDSIntegratorType::g4rkg3stepper;
124 types["rmatrixthin"] = BDSIntegratorType::rmatrixthin;
125 types["paralleltransport"] = BDSIntegratorType::paralleltransport;
126 types["cavityfringe"] = BDSIntegratorType::cavityfringe;
127#if G4VERSION_NUMBER > 1029
128 // introduced in version 10.3
129 types["g4bogackishampine23"] = BDSIntegratorType::g4bogackishampine23;
130 types["g4bogackishampine45"] = BDSIntegratorType::g4bogackishampine45;
131 types["g4dolomcprirk34"] = BDSIntegratorType::g4dolomcprirk34;
132 types["g4dormandprince745"] = BDSIntegratorType::g4dormandprince745;
133 types["g4dormandprincerk56"] = BDSIntegratorType::g4dormandprincerk56;
134 types["g4tsitourasrk45"] = BDSIntegratorType::g4tsitourasrk45;
135#endif
136#if G4VERSION_NUMBER > 1039
137 // introduced in version 10.4
138 types["g4dormandprincerk78"] = BDSIntegratorType::g4dormandprincerk78;
139 types["g4rk547feq1"] = BDSIntegratorType::g4rk547feq1;
140 types["g4rk547feq2"] = BDSIntegratorType::g4rk547feq2;
141 types["g4rk547feq3"] = BDSIntegratorType::g4rk547feq3;
142#endif
143
144 integratorType = BDS::LowerCase(integratorType);
145
146 auto result = types.find(integratorType);
147 if (result == types.end())
148 {// it's not a valid key
149 G4String msg = "\"" + integratorType + "\" is not a valid integrator type\n";
150 msg += "Available integrator types are:\n";
151 for (const auto& it : types)
152 {msg += "\"" + it.first + "\"\n";}
153 throw BDSException(__METHOD_NAME__, msg);
154 }
155
156#ifdef BDSDEBUG
157 G4cout << __METHOD_NAME__ << "determined integrator type to be " << result->second << G4endl;
158#endif
159 return result->second;
160}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< integratortypes_def, int >, std::string > * dictionary
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
BDSIntegratorType DetermineIntegratorType(G4String integratorType)
Function that determines enum from string (case-insensitive).