BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
element.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef ELEMENT_H
19#define ELEMENT_H
20
21#include <exception>
22#include <iomanip>
23#include <iostream>
24#include <list>
25#include <map>
26#include <sstream>
27#include <string>
28#if __cplusplus >= 201703L
29#include <variant>
30#endif
31
32#include "published.h"
33
34namespace GMAD
35{
36 enum class ElementType;
37
38 struct Parameters;
39
46 struct Element: public Published<Element>
47 {
49 std::string name;
50 std::string userTypeName;
51 std::string userParameters;
52
53 double l;
54 double scaling;
56 double ks;
57 // double k0; // for dipole field B or angle is used
58 double k1;
59 double k2;
60 double k3;
61 double k4;
62 double angle;
63 double B;
64 double e1;
65 double e2;
66 double fint;
67 double fintx;
68 double fintK2;
69 double fintxK2;
70 double hgap;
71 double h1;
72 double h2;
73 double kick;
74 double hkick;
75 double vkick;
76 std::list<double> knl;
77 std::list<double> ksl;
78 double gradient;
79 double E;
80 double frequency;
81 double phase;
82 double tOffset;
83 std::string fieldModulator;
84 double kg;
85
87 double kick1;
88 double kick2;
89 double kick3;
90 double kick4;
91 double rmat11;
92 double rmat12;
93 double rmat13;
94 double rmat14;
95 double rmat21;
96 double rmat22;
97 double rmat23;
98 double rmat24;
99 double rmat31;
100 double rmat32;
101 double rmat33;
102 double rmat34;
103 double rmat41;
104 double rmat42;
105 double rmat43;
106 double rmat44;
108
109
112 double aper1;
113 double aper2;
114 double aper3;
115 double aper4;
116 std::string apertureType;
117 std::string beampipeMaterial;
118 std::string vacuumMaterial;
120
121 // magnet geometry
122 std::string magnetGeometryType;
123 double horizontalWidth; // formerly outerDiameter
124 bool yokeOnInside;
125 int hStyle;
126 double vhRatio;
129 double tilt;
130 double xsize, ysize;
131 double xsizeOut, ysizeOut;
132 double xsizeLeft, xsizeRight;
133 double jawTiltLeft, jawTiltRight;
134 double offsetX;
135 double offsetY;
136
137 // PWFA
138 double xsize2, ysize2;
139 double offsetX2, offsetY2;
140 double tilt2;
141 std::string outerShape;
142
143 // screen parameters
144 double tscint;
145 double twindow;
146 double tmount;
148 double screenXSize, screenYSize;
150 std::list<double> layerThicknesses;
151 std::list<std::string> layerMaterials;
152 std::list<int> layerIsSampler;
154
156 double screenPSize;
161 std::string windowmaterial;
162 std::string scintmaterial;
163 std::string mountmaterial;
165
167 double xdir;
168 double ydir;
169 double zdir;
171 double wavelength;
172 double phi, theta, psi;
173 double axisX, axisY, axisZ;
174 bool axisAngle;
175
183
185 std::string laserBeam;
192
195 double wireLength;
196 double wireOffsetX;
197 double wireOffsetY;
198 double wireOffsetZ;
199 double wireAngle;
201
207
216
217
220 std::string tipMaterial;
222
224 std::string bias;
225 std::string biasMaterial;
226 std::string biasVacuum;
227 std::string biasMaterialLV;
230 std::list<std::string> biasMaterialList;
232 std::list<std::string> biasVacuumList;
234 std::list<std::string> biasMaterialLVList;
235
238
239 std::string samplerName;
240 std::string samplerType;
246
247 std::string region;
248 std::string fieldOuter;
249 std::string fieldVacuum;
250 std::string fieldAll;
251
252 std::string geometryFile;
255
257
258 std::string material;
259 std::string namedVacuumVolumes;
260 bool markAsCollimator;
261 std::string spec;
262 std::string cavityModel;
263 std::string cavityFieldType;
264
265 std::string dicomDataPath;
266 std::string dicomDataFile;
267
269 std::string colour;
270
271 std::string crystalLeft;
272 std::string crystalRight;
273 std::string crystalBoth;
274 double crystalAngleYAxisLeft;
275 double crystalAngleYAxisRight;
276
278 std::string coolingDefinition;
279
284
285 bool scalingFieldOuterSet;
286
288 std::list<Element>* lst;
289
291 void print(int ident=0) const;
292
294 void flush();
295
297 bool isSpecial() const;
300 double property_lookup(std::string property_name) const;
301
303 void setSamplerInfo(std::string samplerType,
304 std::string samplerName,
305 double samplerRadius,
306 int samplerParticleSetIDIn = -1);
307
309 void set(const Parameters& params);
310 void set(const Parameters& params,std::string nameIn, ElementType typeIn);
313 template <typename T>
314 void set_value(std::string property, T value, bool exceptionSafe = true);
316 void set_value_array(const std::string& property, Array* value, bool bExit = true); // TODO keep separate as template calling order
318#if __cplusplus >= 201703L
319 std::list<std::variant<bool, int, double, std::string>> get_value_array(const std::string &);
320#endif
322 Element();
323
324 private:
326 void PublishMembers();
328 std::map<std::string,std::string> alternativeNames;
329
330
331 protected:
333 std::string getPublishedName(const std::string& name) const;
334
335 std::map<std::string, std::list<int>*> attribute_map_list_int;
336 std::map<std::string, std::list<double>*> attribute_map_list_double;
337 std::map<std::string, std::list<std::string>*> attribute_map_list_string;
338 };
339
340 template <typename T>
341 void Element::set_value(std::string property, T value, bool exceptionSafe)
342 {
343#ifdef BDSDEBUG
344 std::cout << "element> Setting value " << std::setw(25) << std::left << property << value << std::endl;
345#endif
346 // member method can throw runtime_error, catch and exit gracefully
347 try
348 {Published<Element>::set(this, property, value);}
349 catch(const std::runtime_error&)
350 {
351 std::stringstream ss;
352 ss << "Error: element> unknown property \"" << property
353 << "\" with value \"" << value << "\" in definition \"" << this->name << "\"";
354 if (!exceptionSafe)
355 {throw std::invalid_argument(ss.str());}
356 else
357 {std::cerr << ss.str() << std::endl;}
358 }
359 }
360}
361
362#endif
Representation of arrays used in tokens.
Definition array.h:39
Class that provides introspection to its members.
Definition published.h:48
void set(C *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.
ElementType
types of elements
Definition elementtype.h:27
Element class.
Definition element.h:47
double property_lookup(std::string property_name) const
Definition element.cc:730
double hkick
fractional delta px for hkicker
Definition element.h:74
std::string dicomDataFile
for CT, file for DICOM construction data
Definition element.h:266
std::string spec
Arbitrary specification to pass to beamline builder.
Definition element.h:261
void print(int ident=0) const
print method
Definition element.cc:326
std::string biasMaterial
temporary string for bias setting
Definition element.h:225
double twindow
thickness of window
Definition element.h:145
double B
magnetic field
Definition element.h:63
double aper4
beampipe information, new aperture model
Definition element.h:115
double hgap
half distance of pole separation for purposes of fringe fields - 'half gap'
Definition element.h:70
void set(const Parameters &params)
set method from Parameters structure
Definition element.cc:758
void PublishMembers()
publish members so these can be looked up from parser
Definition element.cc:52
std::string beampipeMaterial
beampipe information, new aperture model
Definition element.h:117
std::string samplerType
element has a sampler of this type (default "none")
Definition element.h:240
double ysize2
size of the beam mask second aperture
Definition element.h:138
double laserOffsetTheta
for laserwire
Definition element.h:186
double rmat33
rmatrix elements, only 4x4
Definition element.h:101
double rmat11
rmatrix elements, only 4x4
Definition element.h:91
double rmat43
rmatrix elements, only 4x4
Definition element.h:105
double laserOffsetPhi
for laserwire
Definition element.h:187
std::list< std::string > layerMaterials
for screen
Definition element.h:151
std::string userParameters
String for passing user parameters through.
Definition element.h:51
double scaling
Overall scaling of field strength.
Definition element.h:54
std::string cavityFieldType
Name for type of field to use in a cavity.
Definition element.h:263
double windowScreenGap
air gap between window and screen
Definition element.h:147
std::string tipMaterial
tip material
Definition element.h:220
double gradient
for rf cavities in V / m
Definition element.h:78
double degraderOffset
for degrader
Definition element.h:181
bool isSpecial() const
check if element is of a special type
Definition element.cc:318
double aper2
beampipe information, new aperture model
Definition element.h:113
double anodeLength
for gabor lens
Definition element.h:209
double fintx
fringe field integral at the dipole exit
Definition element.h:67
double kick4
rmatrix elements, only 4x4
Definition element.h:90
std::list< Element > * lst
in case the element is a list itself (line)
Definition element.h:288
double k2
sextupole
Definition element.h:59
double rmat42
rmatrix elements, only 4x4
Definition element.h:104
double aper1
beampipe information, new aperture model
Definition element.h:112
double rmat41
rmatrix elements, only 4x4
Definition element.h:103
double h2
output pole face curvature for bends
Definition element.h:72
std::string outerShape
'rectangular' or 'circular'. used in gascap and bmcol
Definition element.h:141
double laserOffsetY
for laserwire
Definition element.h:189
double awakeMagnetOffsetX
for AWAKE spectrometer
Definition element.h:160
double zdir
for 3d transform and laser
Definition element.h:169
double h1
input pole face curvature for bends
Definition element.h:71
std::string namedVacuumVolumes
For imported geometry - identify vacuum volumes.
Definition element.h:259
std::string biasMaterialLV
temporary string for bias setting
Definition element.h:227
double anodeThickness
for gabor lens
Definition element.h:211
bool stripOuterVolume
For Element. Make it an assembly.
Definition element.h:253
double screenPSize
for AWAKE spectrometer
Definition element.h:156
double xdir
for 3d transform and laser
Definition element.h:167
double rmat34
rmatrix elements, only 4x4
Definition element.h:102
double psi
for 3d transforms
Definition element.h:172
double rmat31
rmatrix elements, only 4x4
Definition element.h:99
double wedgeLength
for degrader
Definition element.h:178
double vhRatio
ratio of vertial to horizontal for some magnets
Definition element.h:126
double rmat22
rmatrix elements, only 4x4
Definition element.h:96
double fintxK2
second fringe field integral at the dipole exit - for TRANSPORT matching
Definition element.h:69
std::string userTypeName
User component element type name.
Definition element.h:50
double offsetY2
offset of the beam mask second aperture
Definition element.h:139
double kick3
rmatrix elements, only 4x4
Definition element.h:89
double rmat24
rmatrix elements, only 4x4
Definition element.h:98
double tOffset
time offset used for phase calculation (ns)
Definition element.h:82
std::list< std::string > biasMaterialList
Definition element.h:230
double fint
fringe field integral at the dipole entrance
Definition element.h:66
double xsizeRight
individual collimator jaw half widths
Definition element.h:132
std::string bias
temporary string for bias setting
Definition element.h:224
double coilWidthFraction
Fraction of available h space the coil will take up.
Definition element.h:127
double rmat44
rmatrix elements, only 4x4
Definition element.h:106
double ks
solenoid
Definition element.h:56
std::string fieldAll
Field for everything.
Definition element.h:250
double electrodeRadius
for gabor lens
Definition element.h:213
double jawTiltRight
jaw collimator jaw tilts (angle in x-z plane)
Definition element.h:133
std::string region
region with range cuts
Definition element.h:247
double wireDiameter
@[ for wirescanner
Definition element.h:194
int samplerParticleSetID
Definition element.h:245
double tmount
thickness of the screen mount
Definition element.h:146
std::list< double > ksl
skew multipole expansion
Definition element.h:77
int numberWedges
for degrader
Definition element.h:177
double kick1
rmatrix elements, only 4x4
Definition element.h:87
std::list< std::string > biasMaterialLVList
physics biasing list for specific LVs
Definition element.h:234
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition element.cc:309
std::list< double > knl
multipole expansion coefficients
Definition element.h:76
std::string windowmaterial
for AWAKE spectrometer
Definition element.h:161
double e2
output pole face rotation for bends
Definition element.h:65
double phase
phase of rf cavity (rad)
Definition element.h:81
double ysizeOut
collimator aperture or laser spotsize for laser
Definition element.h:131
std::string fieldVacuum
Vacuum field.
Definition element.h:249
bool autoColour
Automagically colour the external geometry.
Definition element.h:254
double angle
bending angle
Definition element.h:62
double electrodeThickness
for gabor lens
Definition element.h:214
int hStyle
-1 = unset; 0 = false (ie c style); 1 = true, use hstyle
Definition element.h:125
std::string geometryFile
For Element. File for external geometry.
Definition element.h:252
std::string vacuumMaterial
beampipe information, new aperture model
Definition element.h:118
double vkick
fractional delta py for vkicker
Definition element.h:75
double laserOffsetZ
for laserwire
Definition element.h:190
double E
voltage for rf cavities in V that will be assumed over length l
Definition element.h:79
double coilHeightFraction
Fraction of availalbe v space the coil will take up.
Definition element.h:128
std::list< int > layerIsSampler
for screen
Definition element.h:152
double laserOffsetX
for laserwire
Definition element.h:188
bool elementLengthIsArcLength
For Element. Treat the length as arc length, if not chord.
Definition element.h:256
double screenYSize
Definition element.h:148
double offsetX
offset X
Definition element.h:134
double screenEndZ
for AWAKE spectrometer
Definition element.h:157
double ysize
collimator aperture or laser spotsize for laser
Definition element.h:130
std::string coolingDefinition
For muon cooler.
Definition element.h:278
double rmat23
rmatrix elements, only 4x4
Definition element.h:97
Element()
constructor
Definition element.cc:44
std::string colour
Override colour for certain items.
Definition element.h:269
double rmat13
rmatrix elements, only 4x4
Definition element.h:93
double anodeRadius
for gabor lens
Definition element.h:210
double tilt
tilt
Definition element.h:129
double materialThickness
for degrader
Definition element.h:180
void flush()
flush method
Definition element.cc:509
double l
length in metres
Definition element.h:53
double kick
fractional delta p for either h or v kicker
Definition element.h:73
double rmat14
rmatrix elements, only 4x4
Definition element.h:94
double beampipeThickness
beampipe information, new aperture model
Definition element.h:111
std::string dicomDataPath
for CT, file for DICOM construction data
Definition element.h:265
double wavelength
for laser wire and 3d transforms
Definition element.h:171
double minimumKineticEnergy
minimum kinetic energy for user limits - respected on element by element basis
Definition element.h:237
std::string scintmaterial
for AWAKE spectrometer
Definition element.h:162
void set_value(std::string property, T value, bool exceptionSafe=true)
Definition element.h:341
double ydir
for 3d transform and laser
Definition element.h:168
double undulatorMagnetHeight
for undulator
Definition element.h:205
void setSamplerInfo(std::string samplerType, std::string samplerName, double samplerRadius, int samplerParticleSetIDIn=-1)
set sampler info
Definition element.cc:810
double tipThickness
for jaw collimator with tip
Definition element.h:219
std::string cavityModel
Name of geometry model object for rfconstantinz cavities.
Definition element.h:262
void set_value_array(const std::string &property, Array *value, bool bExit=true)
Set method for lists.
Definition element.cc:824
double e1
input pole face rotation for bends
Definition element.h:64
std::list< std::variant< bool, int, double, std::string > > get_value_array(const std::string &)
Get method for lists.
Definition element.cc:854
double k1
quadrupole
Definition element.h:58
std::string fieldOuter
Outer field.
Definition element.h:248
std::string laserBeam
for laserwire
Definition element.h:185
double undulatorPeriod
for undulator
Definition element.h:203
std::string biasVacuum
temporary string for bias setting
Definition element.h:226
double electrodeLength
for gabor lens
Definition element.h:212
std::map< std::string, std::string > alternativeNames
map that translates between alternative parser names for members, could be made static
Definition element.h:328
double tilt2
tilt of the beam mask second aperture
Definition element.h:140
double undulatorGap
for undulator
Definition element.h:204
double poleStartZ
for AWAKE spectrometer
Definition element.h:158
double fintK2
second fringe field integral at the dipole entrance - for TRANSPORT matching
Definition element.h:68
bool angleSet
Definition element.h:283
std::string mountmaterial
for AWAKE spectrometer
Definition element.h:163
double k4
decapole
Definition element.h:61
double samplerRadius
Definition element.h:241
double aper3
beampipe information, new aperture model
Definition element.h:114
ElementType type
element enum
Definition element.h:48
std::list< std::string > biasVacuumList
physics biasing list for the vacuum
Definition element.h:232
double offsetY
offset Y
Definition element.h:135
std::list< double > layerThicknesses
for screen
Definition element.h:150
double scalingFieldOuter
Extra arbitrary scaling for outer field - compounded with 'scaling'.
Definition element.h:55
double kg
gabor lens
Definition element.h:84
std::string samplerName
name of sampler (default empty)
Definition element.h:239
double degraderHeight
for degrader
Definition element.h:179
double tscint
thickness of scintillating part of screen
Definition element.h:144
double k3
octupole
Definition element.h:60
double screenWidth
for AWAKE spectrometer
Definition element.h:159
double frequency
frequency for rf cavity in Hz
Definition element.h:80
double kick2
rmatrix elements, only 4x4
Definition element.h:88
double rmat12
rmatrix elements, only 4x4
Definition element.h:92
std::string apertureType
beampipe information, new aperture model
Definition element.h:116
double rmat21
rmatrix elements, only 4x4
Definition element.h:95
double rmat32
rmatrix elements, only 4x4
Definition element.h:100
Parameters - Element class with booleans.
Definition parameters.h:43