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) 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 FIELD_H
19#define FIELD_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24
25#include "published.h"
26
27namespace GMAD
28{
35 class Field : public Published<Field>
36 {
37 public:
38 std::string name;
39 std::string type;
40 double eScaling;
41 double bScaling;
42 std::string integrator;
44 std::string magneticFile;
46 std::string electricFile;
48 std::string fieldModulator;
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
76
77 std::string magneticSubField;
78 std::string electricSubField;
79
80 std::string magneticReflection;
81 std::string electricReflection;
82
83 std::string fieldParameters;
84
86 Field();
88 void clear();
90 void print()const;
92 template <typename T>
93 void set_value(std::string property, T value, bool bExit = true);
94
95
96 private:
98 void PublishMembers();
99 };
100
101 template <typename T>
102 void Field::set_value(std::string property, T value, bool bExit)
103 {
104#ifdef BDSDEBUG
105 std::cout << "field> Setting value " << std::setw(25) << std::left << property << value << std::endl;
106#endif
107 // member method can throw runtime_error, catch and exit gracefully
108 try
109 {set(this,property,value);}
110 catch (const std::runtime_error&)
111 {
112 std::cerr << "Error: field> unknown option \"" << property
113 << "\" 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:36
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:98
double maximumStepLengthOverride
Definition field.h:75
double z
Offset in z.
Definition field.h:52
std::string type
Type.
Definition field.h:39
std::string integrator
Which integrator to use.
Definition field.h:42
Field()
Constructor.
Definition field.cc:22
std::string magneticInterpolator
Interpolator for the magnetic field.
Definition field.h:45
std::string electricFile
File for the electric field map.
Definition field.h:46
double axisX
Definition field.h:60
void PublishMembers()
publish members
Definition field.cc:63
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:41
std::string name
Name.
Definition field.h:38
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
void set_value(std::string property, T value, bool bExit=true)
Set methods by property name and value.
Definition field.h:102
std::string magneticFile
File for magnetic field map.
Definition field.h:44
std::string electricInterpolator
Interpolator for the electric field.
Definition field.h:47
double x
Offset in x.
Definition field.h:50
void clear()
Reset.
Definition field.cc:28
std::string fieldModulator
Name of field modulator object.
Definition field.h:48
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:43
double eScaling
E Field Scaling factor.
Definition field.h:40
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:48
void set(Field *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.