BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSFieldInfo.hh
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 BDSFIELDINFO_H
20#define BDSFIELDINFO_H
21
22#include "BDSArrayReflectionType.hh"
23#include "BDSFieldFormat.hh"
24#include "BDSFieldType.hh"
25#include "BDSIntegratorType.hh"
26#include "BDSInterpolatorType.hh"
27
28#include "globals.hh" // geant4 types / globals
29#include "G4Transform3D.hh"
30#include "G4ThreeVector.hh"
31
32#include <ostream>
33
35class G4UserLimits;
36
65{
66public:
69 BDSFieldInfo(BDSFieldType fieldTypeIn,
70 G4double brhoIn,
71 BDSIntegratorType integratorTypeIn,
72 BDSMagnetStrength* magnetStrengthIn = nullptr,
73 G4bool provideGlobalTransformIn = true,
74 const G4Transform3D& transformIn = G4Transform3D(),
75 const G4String& magneticFieldFilePathIn = "",
76 BDSFieldFormat magneticFieldFormatIn = BDSFieldFormat::bdsim1d,
77 BDSInterpolatorType magneticInterpolatorTypeIn = BDSInterpolatorType::nearest3d,
78 const G4String& electricFieldFilePathIn = "",
79 BDSFieldFormat electricFieldFormatIn = BDSFieldFormat::bdsim1d,
80 BDSInterpolatorType electricInterpolatorTypeIn = BDSInterpolatorType::nearest3d,
81 G4bool cacheTransformsIn = false,
82 G4double eScalingIn = 1.0,
83 G4double bScalingIn = 1.0,
84 G4double timeOffsetIn = 0,
85 G4bool autoScaleIn = false,
86 G4UserLimits* stepLimitIn = nullptr,
87 G4double poleTipRadiusIn = 1,
88 G4double beamPipeRadiusIn = 0,
89 G4bool left = true,
90 const G4String& magneticSubFieldNameIn = "",
91 const G4String& electricSubFieldNameIn = "");
93
95 BDSFieldInfo(const BDSFieldInfo& other);
98
100 inline BDSFieldType FieldType() const {return fieldType;}
101 inline G4double BRho() const {return brho;}
102 inline BDSIntegratorType IntegratorType() const {return integratorType;}
103 inline BDSMagnetStrength* MagnetStrength() const {return magnetStrength;}
104 inline G4bool ProvideGlobal() const {return provideGlobalTransform;}
105 inline G4String MagneticFile() const {return magneticFieldFilePath;}
106 inline BDSFieldFormat MagneticFormat() const {return magneticFieldFormat;}
107 inline BDSInterpolatorType MagneticInterpolatorType() const {return magneticInterpolatorType;}
108 inline G4String ElectricFile() const {return electricFieldFilePath;}
109 inline BDSFieldFormat ElectricFormat() const {return electricFieldFormat;}
110 inline BDSInterpolatorType ElectricInterpolatorType() const {return electricInterpolatorType;}
111 inline G4bool CacheTransforms() const {return cacheTransforms;}
112 inline G4double EScaling() const {return eScaling;}
113 inline G4double BScaling() const {return bScaling;}
114 inline G4double TimeOffset() const {return timeOffset;}
115 inline G4bool AutoScale() const {return autoScale;}
116 inline G4UserLimits* UserLimits() const {return stepLimit;}
117 inline G4double PoleTipRadius() const {return poleTipRadius;}
118 inline G4double BeamPipeRadius() const {return beamPipeRadius;}
119 inline G4double ChordStepMinimum() const {return chordStepMinimum;}
120 inline G4double Tilt() const {return tilt;}
121 inline G4bool SecondFieldOnLeft() const {return secondFieldOnLeft;}
122 inline G4String MagneticSubFieldName() const {return magneticSubFieldName;}
123 inline G4String ElectricSubFieldName() const {return electricSubFieldName;}
124 inline G4String NameOfParserDefinition() const {return nameOfParserDefinition;}
125 inline G4bool UsePlacementWorldTransform() const {return usePlacementWorldTransform;}
126 inline const BDSArrayReflectionTypeSet& MagneticArrayReflectionType() const {return magneticArrayReflectionTypeSet;}
127 inline const BDSArrayReflectionTypeSet& ElectricArrayReflectionType() const {return electricArrayReflectionTypeSet;}
129
130 G4Transform3D Transform() const;
131 G4Transform3D TransformBeamline() const;
132 G4Transform3D TransformComplete() const;
133
135 inline void SetFieldType(BDSFieldType fieldTypeIn) {fieldType = fieldTypeIn;}
136 inline void SetIntegratorType(BDSIntegratorType typeIn) {integratorType = typeIn;}
137 inline void SetProvideGlobalTransform(G4bool provideGlobalTransformIn) {provideGlobalTransform = provideGlobalTransformIn;}
138 inline void SetMagneticInterpolatorType(BDSInterpolatorType typeIn) {magneticInterpolatorType = typeIn;}
139 inline void SetMagneticArrayReflectionType(const BDSArrayReflectionTypeSet& typeIn) {magneticArrayReflectionTypeSet = typeIn;}
140 inline void SetElectricArrayReflectionType(const BDSArrayReflectionTypeSet& typeIn) {electricArrayReflectionTypeSet = typeIn;}
141 inline void SetBScaling(G4double bScalingIn) {bScaling = bScalingIn;}
142 inline void SetAutoScale(G4bool autoScaleIn) {autoScale = autoScaleIn;}
143 inline void SetScalingRadius(G4double poleTipRadiusIn) {poleTipRadius = poleTipRadiusIn;}
144 inline void SetBeamPipeRadius(G4double beamPipeRadiusIn) {beamPipeRadius = beamPipeRadiusIn;}
145 inline void SetChordStepMinimum(G4double chordStepMinimumIn) {chordStepMinimum = chordStepMinimumIn;}
146 inline void SetSecondFieldOnLeft(G4bool leftIn) {secondFieldOnLeft = leftIn;}
147 inline void SetMagneticSubField(const G4String& mfnIn) {magneticSubFieldName = mfnIn;}
148 inline void SetElectricSubField(const G4String& efnIn) {electricSubFieldName = efnIn;}
149 inline void SetUsePlacementWorldTransform(G4bool use) {usePlacementWorldTransform = use;}
150
152 inline void CompoundBScaling(G4double extraBScalingIn) {bScaling *= extraBScalingIn;}
154 inline void CompoundEScaling(G4double extraEScalingIn) {eScaling *= extraEScalingIn;}
155
156 void SetTransform(const G4Transform3D& transformIn);
157 void SetTransformBeamline(const G4Transform3D& transformIn);
158
160 void SetUserLimits(G4UserLimits* userLimitsIn);
161
162 void SetNameOfParserDefinition(const G4String& nameIn) {nameOfParserDefinition = nameIn;}
163
166 void UpdateUserLimitsLengthMaximumStepSize(G4double maximumStepSize,
167 G4bool warn = false) const;
168
171 void Translate(const G4ThreeVector& translationIn);
172
174 inline void CacheTransforms(G4bool cacheTransformsIn) {cacheTransforms = cacheTransformsIn;}
175
177 friend std::ostream& operator<< (std::ostream &out, BDSFieldInfo const &info);
178
179 static G4UserLimits* defaultUL;
180
181private:
182 BDSFieldType fieldType;
183 G4double brho;
184 BDSIntegratorType integratorType;
185 BDSMagnetStrength* magnetStrength;
186 G4bool provideGlobalTransform;
187 G4Transform3D* transform;
188 G4String magneticFieldFilePath;
189 BDSFieldFormat magneticFieldFormat;
190 BDSInterpolatorType magneticInterpolatorType;
191 BDSArrayReflectionTypeSet magneticArrayReflectionTypeSet;
192 G4String electricFieldFilePath;
193 BDSFieldFormat electricFieldFormat;
194 BDSInterpolatorType electricInterpolatorType;
195 BDSArrayReflectionTypeSet electricArrayReflectionTypeSet;
196 G4bool cacheTransforms;
197 G4double eScaling;
198 G4double bScaling;
199 G4double timeOffset;
200 G4bool autoScale;
201 mutable G4UserLimits* stepLimit;
202 G4double poleTipRadius;
203 G4double beamPipeRadius;
204 G4double chordStepMinimum;
205 G4double tilt;
207 G4String magneticSubFieldName;
208 G4String electricSubFieldName;
209 G4bool usePlacementWorldTransform;
211 G4Transform3D* transformBeamline;
212
213 G4String nameOfParserDefinition;
214
215 // We need a default to pass back if none is specified.
216 const static G4ThreeVector defaultUnitDirection;
217};
218
219#endif
All info required to build complete field of any type.
Definition: BDSFieldInfo.hh:65
void CacheTransforms(G4bool cacheTransformsIn)
Turn on or off transform caching.
BDSFieldInfo & operator=(const BDSFieldInfo &)=delete
Assignment operator not used.
G4double beamPipeRadius
Optional radius of beam pipe.
G4String MagneticSubFieldName() const
Accessor.
void CompoundEScaling(G4double extraEScalingIn)
*= for EScaling.
void UpdateUserLimitsLengthMaximumStepSize(G4double maximumStepSize, G4bool warn=false) const
static G4UserLimits * defaultUL
Cache of default user limits.
G4Transform3D * transformBeamline
Transform from curvilinear frame to this field - ie beam line bit only.
G4double BScaling() const
Accessor.
const BDSArrayReflectionTypeSet & ElectricArrayReflectionType() const
Accessor.
G4double TimeOffset() const
Accessor.
BDSFieldFormat MagneticFormat() const
Accessor.
G4double ChordStepMinimum() const
Accessor.
G4Transform3D TransformComplete() const
Compound transform of field + beam line transform.
G4String NameOfParserDefinition() const
Accessor.
G4String ElectricFile() const
Accessor.
void SetTransformBeamline(const G4Transform3D &transformIn)
Set the beam line transform.
BDSInterpolatorType ElectricInterpolatorType() const
Accessor.
void CompoundBScaling(G4double extraBScalingIn)
*= for BScaling.
G4bool SecondFieldOnLeft() const
Accessor.
BDSInterpolatorType MagneticInterpolatorType() const
Accessor.
G4double poleTipRadius
Radius at which point the field will be scaled to.
G4double EScaling() const
Accessor.
G4double PoleTipRadius() const
Accessor.
G4double tilt
Cache of tilt of field.
G4bool ProvideGlobal() const
Accessor.
void SetFieldType(BDSFieldType fieldTypeIn)
Set Transform - could be done afterwards once instance of this class is passed around.
G4String MagneticFile() const
Accessor.
G4bool CacheTransforms() const
Accessor.
friend std::ostream & operator<<(std::ostream &out, BDSFieldInfo const &info)
output stream
BDSIntegratorType IntegratorType() const
Accessor.
void SetTransform(const G4Transform3D &transformIn)
Set the field definition transform.
G4double BeamPipeRadius() const
Accessor.
G4String ElectricSubFieldName() const
Accessor.
G4Transform3D Transform() const
Transform for the field definition only.
G4bool UsePlacementWorldTransform() const
Accessor.
BDSFieldFormat ElectricFormat() const
Accessor.
const BDSArrayReflectionTypeSet & MagneticArrayReflectionType() const
Accessor.
G4UserLimits * UserLimits() const
Accessor.
G4bool secondFieldOnLeft
Flag for case of two-beam field - if not left, it's right.
void Translate(const G4ThreeVector &translationIn)
G4double Tilt() const
Accessor.
BDSFieldType FieldType() const
Accessor.
BDSMagnetStrength * MagnetStrength() const
Accessor.
G4double BRho() const
Accessor.
G4bool AutoScale() const
Accessor.
G4Transform3D TransformBeamline() const
Transform from the curvilinear coordinates to the beam line component.
void SetUserLimits(G4UserLimits *userLimitsIn)
Delete and replace the user limits which this class owns (only if not default ul).
G4Transform3D * transform
Transform w.r.t. solid field will be attached to.
BDSFieldInfo()
Default constructor for zero field effectively.
Definition: BDSFieldInfo.cc:39
Efficient storage of magnet strengths.