BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
field.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 FIELD_H
20#define FIELD_H
21
22#include <iomanip>
23#include <iostream>
24#include <string>
25
26#include "published.h"
27
28namespace GMAD
29{
36 class Field : public Published<Field>
37 {
38 public:
39 std::string name;
40 std::string type;
41 double eScaling;
42 double bScaling;
43 std::string integrator;
45 std::string magneticFile;
47 std::string electricFile;
49
50 double x;
51 double y;
52 double z;
53 double t;
55 double phi;
56 double theta;
57 double psi;
60 double axisX;
61 double axisY;
62 double axisZ;
63 double angle;
65 bool axisAngle;
66
67 bool autoScale;
68
71
72 std::string magneticSubField;
73 std::string electricSubField;
74
75 std::string magneticReflection;
76 std::string electricReflection;
77
78 std::string fieldParameters;
79
81 Field();
83 void clear();
85 void print()const;
87 template <typename T>
88 void set_value(std::string property, T value);
89
90
91 private:
93 void PublishMembers();
94 };
95
96 template <typename T>
97 void Field::set_value(std::string property, T value)
98 {
99#ifdef BDSDEBUG
100 std::cout << "field> Setting value " << std::setw(25) << std::left << property << value << std::endl;
101#endif
102 // member method can throw runtime_error, catch and exit gracefully
103 try {
104 set(this,property,value);
105 }
106 catch(const std::runtime_error&) {
107 std::cerr << "Error: field> unknown option \"" << property << "\" with value " << value << std::endl;
108 exit(1);
109 }
110 }
111}
112
113#endif
Field class for parser.
Definition: field.h:37
void set_value(std::string property, T value)
Set methods by property name and value.
Definition: field.h:97
double theta
Euler angle for rotation.
Definition: field.h:56
bool autoScale
Scale the field to the magnet it's attached to.
Definition: field.h:67
void print() const
Print some properties.
Definition: field.cc:95
double z
Offset in z.
Definition: field.h:52
std::string type
Type.
Definition: field.h:40
std::string integrator
Which integrator to use.
Definition: field.h:43
Field()
Constructor.
Definition: field.cc:23
std::string magneticInterpolator
Interpolator for the magnetic field.
Definition: field.h:46
std::string electricFile
File for the electric field map.
Definition: field.h:47
double axisX
Definition: field.h:60
void PublishMembers()
publish members
Definition: field.cc:62
double phi
Euler angle for rotation.
Definition: field.h:55
double t
Definition: field.h:53
double bScaling
B Field Scaling factor.
Definition: field.h:42
std::string name
Name.
Definition: field.h:39
double maximumStepLength
Maximum permitted step length in the volumes the field is attached to.
Definition: field.h:70
double y
Offset in y.
Definition: field.h:51
double angle
Definition: field.h:63
std::string magneticFile
File for magnetic field map.
Definition: field.h:45
std::string electricInterpolator
Interpolator for the electric field.
Definition: field.h:48
double x
Offset in x.
Definition: field.h:50
void clear()
Reset.
Definition: field.cc:29
bool axisAngle
Flag to use the axis angle construction of rotation.
Definition: field.h:65
double axisY
Definition: field.h:61
bool globalTransform
Provide global to curvilinear coordinate transform.
Definition: field.h:44
double eScaling
E Field Scaling factor.
Definition: field.h:41
double axisZ
Definition: field.h:62
double psi
Euler angle for rotation.
Definition: field.h:57
Class that provides introspection to its members.
Definition: published.h:47
void set(Field *instance, const std::string &name, double value)
Definition: published.h:99
Parser namespace for GMAD language. Combination of Geant4 and MAD.