BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
field.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 std::string fieldModulator;
50
51 double x;
52 double y;
53 double z;
54 double t;
56 double phi;
57 double theta;
58 double psi;
61 double axisX;
62 double axisY;
63 double axisZ;
64 double angle;
66 bool axisAngle;
67
68 bool autoScale;
69
72
77
78 std::string magneticSubField;
79 std::string electricSubField;
80
81 std::string magneticReflection;
82 std::string electricReflection;
83
84 std::string fieldParameters;
85
87 Field();
89 void clear();
91 void print()const;
93 template <typename T>
94 void set_value(std::string property, T value, bool bExit = true);
95
96
97 private:
99 void PublishMembers();
100 };
101
102 template <typename T>
103 void Field::set_value(std::string property, T value, bool bExit)
104 {
105#ifdef BDSDEBUG
106 std::cout << "field> Setting value " << std::setw(25) << std::left << property << value << std::endl;
107#endif
108 // member method can throw runtime_error, catch and exit gracefully
109 try
110 {set(this,property,value);}
111 catch (const std::runtime_error&)
112 {
113 std::cerr << "Error: field> unknown option \"" << property << "\" with value \"" << value << "\"" << std::endl;
114 if (bExit)
115 {exit(1);}
116 else
117 {std::rethrow_exception(std::current_exception());} // to be caught by python
118 }
119 }
120}
121
122#endif
Field class for parser.
Definition field.h:37
double theta
Euler angle for rotation.
Definition field.h:57
bool autoScale
Scale the field to the magnet it's attached to.
Definition field.h:68
void print() const
Print some properties.
Definition field.cc:99
double maximumStepLengthOverride
Definition field.h:76
double z
Offset in z.
Definition field.h:53
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:61
void PublishMembers()
publish members
Definition field.cc:64
double phi
Euler angle for rotation.
Definition field.h:56
double t
Definition field.h:54
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:71
double y
Offset in y.
Definition field.h:52
double angle
Definition field.h:64
void set_value(std::string property, T value, bool bExit=true)
Set methods by property name and value.
Definition field.h:103
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:51
void clear()
Reset.
Definition field.cc:29
std::string fieldModulator
Name of field modulator object.
Definition field.h:49
bool axisAngle
Flag to use the axis angle construction of rotation.
Definition field.h:66
double axisY
Definition field.h:62
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:63
double psi
Euler angle for rotation.
Definition field.h:58
Class that provides introspection to its members.
Definition published.h:49
void set(Field *instance, const std::string &name, double value)
Definition published.h:101
Parser namespace for GMAD language. Combination of Geant4 and MAD.