BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
element.h
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#ifndef ELEMENT_H
20#define ELEMENT_H
21
22#include <iomanip>
23#include <iostream>
24#include <list>
25#include <map>
26#include <string>
27
28#include "published.h"
29
30namespace GMAD
31{
32 enum class ElementType;
33
34 struct Parameters;
35
42 struct Element: public Published<Element>
43 {
45 std::string name;
46 std::string userTypeName;
47 std::string userParameters;
48
49 double l;
50 double scaling;
52 double ks;
53 // double k0; // for dipole field B or angle is used
54 double k1;
55 double k2;
56 double k3;
57 double k4;
58 double angle;
59 double B;
60 double e1;
61 double e2;
62 double fint;
63 double fintx;
64 double fintK2;
65 double fintxK2;
66 double hgap;
67 double h1;
68 double h2;
69 double kick;
70 double hkick;
71 double vkick;
72 std::list<double> knl;
73 std::list<double> ksl;
74 double gradient;
75 double E;
76 double frequency;
77 double phase;
78 double tOffset;
79
81 double kick1;
82 double kick2;
83 double kick3;
84 double kick4;
85 double rmat11;
86 double rmat12;
87 double rmat13;
88 double rmat14;
89 double rmat21;
90 double rmat22;
91 double rmat23;
92 double rmat24;
93 double rmat31;
94 double rmat32;
95 double rmat33;
96 double rmat34;
97 double rmat41;
98 double rmat42;
99 double rmat43;
100 double rmat44;
102
103
106 double aper1;
107 double aper2;
108 double aper3;
109 double aper4;
110 std::string apertureType;
111 std::string beampipeMaterial;
112 std::string vacuumMaterial;
114
115 // magnet geometry
116 std::string magnetGeometryType;
117 double horizontalWidth; // formerly outerDiameter
118 bool yokeOnInside;
119 int hStyle;
120 double vhRatio;
123 double tilt;
124 double xsize, ysize;
125 double xsizeOut, ysizeOut;
126 double xsizeLeft, xsizeRight;
127 double offsetX;
128 double offsetY;
129
130 // screen parameters
131 double tscint;
132 double twindow;
133 double tmount;
135 double screenXSize, screenYSize;
137 std::list<double> layerThicknesses;
138 std::list<std::string> layerMaterials;
139 std::list<int> layerIsSampler;
141
143 double screenPSize;
148 std::string windowmaterial;
149 std::string scintmaterial;
150 std::string mountmaterial;
152
154 double xdir;
155 double ydir;
156 double zdir;
158 double waveLength;
159 double phi, theta, psi;
160 double axisX, axisY, axisZ;
161 bool axisAngle;
162
170
177 double wireAngle;
179
185
187 std::string bias;
188 std::string biasMaterial;
189 std::string biasVacuum;
192 std::list<std::string> biasMaterialList;
194 std::list<std::string> biasVacuumList;
195
198
199 std::string samplerName;
200 std::string samplerType;
206
207 std::string region;
208 std::string fieldOuter;
209 std::string fieldVacuum;
210 std::string fieldAll;
211
212 std::string geometryFile;
215 std::string material;
216 std::string namedVacuumVolumes;
217 bool markAsCollimator;
218 std::string spec;
219 std::string cavityModel;
220
221 std::string dicomDataPath;
222 std::string dicomDataFile;
223
225 std::string colour;
226
227 std::string crystalLeft;
228 std::string crystalRight;
229 std::string crystalBoth;
230 double crystalAngleYAxisLeft;
231 double crystalAngleYAxisRight;
232
237
238 bool scalingFieldOuterSet;
239
241 std::list<Element>* lst;
242
244 void print(int ident=0) const;
245
247 void flush();
248
250 bool isSpecial() const;
253 double property_lookup(std::string property_name) const;
254
256 void setSamplerInfo(std::string samplerType,
257 std::string samplerName,
258 double samplerRadius,
259 int samplerParticleSetIDIn = -1);
260
262 void set(const Parameters& params);
263 void set(const Parameters& params,std::string nameIn, ElementType typeIn);
266 template <typename T>
267 void set_value(std::string property, T value);
268
270 Element();
271
272 private:
274 void PublishMembers();
276 std::map<std::string,std::string> alternativeNames;
277
278 protected:
280 std::string getPublishedName(const std::string& name) const;
281 };
282
283 template <typename T>
284 void Element::set_value(std::string property, T value)
285 {
286#ifdef BDSDEBUG
287 std::cout << "element> Setting value " << std::setw(25) << std::left << property << value << std::endl;
288#endif
289 // member method can throw runtime_error, catch and exit gracefully
290 try {
291 Published<Element>::set(this,property,value);
292 }
293 catch(const std::runtime_error&) {
294 std::cerr << "Error: element> unknown property \"" << property << "\" with value " << value << std::endl;
295 exit(1);
296 }
297 }
298}
299
300#endif
Class that provides introspection to its members.
Definition: published.h:47
void set(C *instance, const std::string &name, double value)
Definition: published.h:99
Parser namespace for GMAD language. Combination of Geant4 and MAD.
ElementType
types of elements
Definition: elementtype.h:28
Element class.
Definition: element.h:43
double property_lookup(std::string property_name) const
Definition: element.cc:617
double hkick
fractional delta px for hkicker
Definition: element.h:70
std::string dicomDataFile
for CT, file for DICOM construction data
Definition: element.h:222
std::string spec
arbitrary specification to pass to beamline builder
Definition: element.h:218
void print(int ident=0) const
print method
Definition: element.cc:276
std::string biasMaterial
temporary string for bias setting
Definition: element.h:188
double twindow
thickness of window
Definition: element.h:132
double B
magnetic field
Definition: element.h:59
double aper4
beampipe information, new aperture model
Definition: element.h:109
double hgap
half distance of pole separation for purposes of fringe fields - 'half gap'
Definition: element.h:66
void set(const Parameters &params)
set method from Parameters structure
Definition: element.cc:645
void PublishMembers()
publish members so these can be looked up from parser
Definition: element.cc:53
std::string beampipeMaterial
beampipe information, new aperture model
Definition: element.h:111
std::string samplerType
element has a sampler of this type (default "none")
Definition: element.h:200
double rmat33
rmatrix elements, only 4x4
Definition: element.h:95
double rmat11
rmatrix elements, only 4x4
Definition: element.h:85
double rmat43
rmatrix elements, only 4x4
Definition: element.h:99
std::list< std::string > layerMaterials
for screen
Definition: element.h:138
std::string userParameters
String for passing user parameters through.
Definition: element.h:47
double scaling
Overall scaling of field strength.
Definition: element.h:50
double windowScreenGap
air gap between window and screen
Definition: element.h:134
double gradient
for rf cavities in V / m
Definition: element.h:74
double degraderOffset
for degrader
Definition: element.h:168
bool isSpecial() const
check if element is of a special type
Definition: element.cc:268
double wireAngle
for wirescanner
Definition: element.h:177
double aper2
beampipe information, new aperture model
Definition: element.h:107
double fintx
fringe field integral at the dipole exit
Definition: element.h:63
double kick4
rmatrix elements, only 4x4
Definition: element.h:84
std::list< Element > * lst
in case the element is a list itself (line)
Definition: element.h:241
double k2
sextupole
Definition: element.h:55
double rmat42
rmatrix elements, only 4x4
Definition: element.h:98
double aper1
beampipe information, new aperture model
Definition: element.h:106
double rmat41
rmatrix elements, only 4x4
Definition: element.h:97
double h2
output pole face curvature for bends
Definition: element.h:68
double awakeMagnetOffsetX
for AWAKE spectrometer
Definition: element.h:147
double zdir
for 3d transform and laser
Definition: element.h:156
double h1
input pole face curvature for bends
Definition: element.h:67
std::string namedVacuumVolumes
For imported geometry - identify vacuum volumes.
Definition: element.h:216
bool stripOuterVolume
For Element. Make it an assembly.
Definition: element.h:213
double screenPSize
for AWAKE spectrometer
Definition: element.h:143
double xdir
for 3d transform and laser
Definition: element.h:154
double rmat34
rmatrix elements, only 4x4
Definition: element.h:96
double psi
for 3d transforms
Definition: element.h:159
double wireOffsetX
for wirescanner
Definition: element.h:174
double rmat31
rmatrix elements, only 4x4
Definition: element.h:93
double wedgeLength
for degrader
Definition: element.h:165
double vhRatio
ratio of vertial to horizontal for some magnets
Definition: element.h:120
double waveLength
for laser wire and 3d transforms
Definition: element.h:158
double rmat22
rmatrix elements, only 4x4
Definition: element.h:90
double fintxK2
second fringe field integral at the dipole exit - for TRANSPORT matching
Definition: element.h:65
std::string userTypeName
User component element type name.
Definition: element.h:46
double wireOffsetY
for wirescanner
Definition: element.h:175
double kick3
rmatrix elements, only 4x4
Definition: element.h:83
double rmat24
rmatrix elements, only 4x4
Definition: element.h:92
double tOffset
time offset used for phase calculation (ns)
Definition: element.h:78
std::list< std::string > biasMaterialList
Definition: element.h:192
double fint
fringe field integral at the dipole entrance
Definition: element.h:62
double xsizeRight
individual collimator jaw half widths
Definition: element.h:126
std::string bias
temporary string for bias setting
Definition: element.h:187
double coilWidthFraction
Fraction of available h space the coil will take up.
Definition: element.h:121
double rmat44
rmatrix elements, only 4x4
Definition: element.h:100
double ks
solenoid
Definition: element.h:52
std::string fieldAll
Field for everything.
Definition: element.h:210
std::string region
region with range cuts
Definition: element.h:207
double wireDiameter
for wirescanner
Definition: element.h:172
int samplerParticleSetID
Definition: element.h:205
double tmount
thickness of the screen mount
Definition: element.h:133
double wireOffsetZ
for wirescanner
Definition: element.h:176
std::list< double > ksl
skew multipole expansion
Definition: element.h:73
int numberWedges
for degrader
Definition: element.h:164
double kick1
rmatrix elements, only 4x4
Definition: element.h:81
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition: element.cc:259
std::list< double > knl
multipole expansion coefficients
Definition: element.h:72
std::string windowmaterial
for AWAKE spectrometer
Definition: element.h:148
double e2
output pole face rotation for bends
Definition: element.h:61
double phase
phase of rf cavity (rad)
Definition: element.h:77
double ysizeOut
collimator aperture or laser spotsize for laser
Definition: element.h:125
std::string fieldVacuum
Vacuum field.
Definition: element.h:209
bool autoColour
Automagically colour the external geometry.
Definition: element.h:214
double angle
bending angle
Definition: element.h:58
void set_value(std::string property, T value)
Definition: element.h:284
int hStyle
-1 = unset; 0 = false (ie c style); 1 = true, use hstyle
Definition: element.h:119
std::string geometryFile
For Element. File for external geometry.
Definition: element.h:212
std::string vacuumMaterial
beampipe information, new aperture model
Definition: element.h:112
double vkick
fractional delta py for vkicker
Definition: element.h:71
double E
electric field amplitude for rf cavities in V
Definition: element.h:75
double coilHeightFraction
Fraction of availalbe v space the coil will take up.
Definition: element.h:122
std::list< int > layerIsSampler
for screen
Definition: element.h:139
double screenYSize
Definition: element.h:135
double offsetX
offset X
Definition: element.h:127
double screenEndZ
for AWAKE spectrometer
Definition: element.h:144
double ysize
collimator aperture or laser spotsize for laser
Definition: element.h:124
double rmat23
rmatrix elements, only 4x4
Definition: element.h:91
Element()
constructor
Definition: element.cc:45
std::string colour
Override colour for certain items.
Definition: element.h:225
double rmat13
rmatrix elements, only 4x4
Definition: element.h:87
double tilt
tilt
Definition: element.h:123
double materialThickness
for degrader
Definition: element.h:167
void flush()
flush method
Definition: element.cc:431
double l
length in metres
Definition: element.h:49
double kick
fractional delta p for either h or v kicker
Definition: element.h:69
double rmat14
rmatrix elements, only 4x4
Definition: element.h:88
double beampipeThickness
beampipe information, new aperture model
Definition: element.h:105
std::string dicomDataPath
for CT, file for DICOM construction data
Definition: element.h:221
double minimumKineticEnergy
minimum kinetic energy for user limits - respected on element by element basis
Definition: element.h:197
std::string scintmaterial
for AWAKE spectrometer
Definition: element.h:149
double ydir
for 3d transform and laser
Definition: element.h:155
double undulatorMagnetHeight
for undulator
Definition: element.h:183
void setSamplerInfo(std::string samplerType, std::string samplerName, double samplerRadius, int samplerParticleSetIDIn=-1)
set sampler info
Definition: element.cc:690
std::string cavityModel
model for rf cavities
Definition: element.h:219
double e1
input pole face rotation for bends
Definition: element.h:60
double k1
quadrupole
Definition: element.h:54
std::string fieldOuter
Outer field.
Definition: element.h:208
double undulatorPeriod
for undulator
Definition: element.h:181
std::string biasVacuum
temporary string for bias setting
Definition: element.h:189
double wireLength
for wirescanner
Definition: element.h:173
std::map< std::string, std::string > alternativeNames
map that translates between alternative parser names for members, could be made static
Definition: element.h:276
double undulatorGap
for undulator
Definition: element.h:182
double poleStartZ
for AWAKE spectrometer
Definition: element.h:145
double fintK2
second fringe field integral at the dipole entrance - for TRANSPORT matching
Definition: element.h:64
bool angleSet
Definition: element.h:236
std::string mountmaterial
for AWAKE spectrometer
Definition: element.h:150
double k4
decapole
Definition: element.h:57
double samplerRadius
Definition: element.h:201
double aper3
beampipe information, new aperture model
Definition: element.h:108
ElementType type
element enum
Definition: element.h:44
std::list< std::string > biasVacuumList
physics biasing list for the vacuum
Definition: element.h:194
double offsetY
offset Y
Definition: element.h:128
std::list< double > layerThicknesses
for screen
Definition: element.h:137
double scalingFieldOuter
Extra arbitrary scaling for outer field - compounded with 'scaling'.
Definition: element.h:51
std::string samplerName
name of sampler (default empty)
Definition: element.h:199
double degraderHeight
for degrader
Definition: element.h:166
double tscint
thickness of scintillating part of screen
Definition: element.h:131
double k3
octupole
Definition: element.h:56
double screenWidth
for AWAKE spectrometer
Definition: element.h:146
double frequency
frequency for rf cavity in Hz
Definition: element.h:76
double kick2
rmatrix elements, only 4x4
Definition: element.h:82
double rmat12
rmatrix elements, only 4x4
Definition: element.h:86
std::string apertureType
beampipe information, new aperture model
Definition: element.h:110
double rmat21
rmatrix elements, only 4x4
Definition: element.h:89
double rmat32
rmatrix elements, only 4x4
Definition: element.h:94
Parameters - Element class with booleans.
Definition: parameters.h:44