BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldInfo.hh
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 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
37class G4UserLimits;
38
67{
68public:
71 BDSFieldInfo(BDSFieldType fieldTypeIn,
72 G4double brhoIn,
73 BDSIntegratorType integratorTypeIn,
74 BDSMagnetStrength* magnetStrengthIn = nullptr,
75 G4bool provideGlobalTransformIn = true,
76 const G4Transform3D& transformIn = G4Transform3D(),
77 const G4String& magneticFieldFilePathIn = "",
78 BDSFieldFormat magneticFieldFormatIn = BDSFieldFormat::bdsim1d,
79 BDSInterpolatorType magneticInterpolatorTypeIn = BDSInterpolatorType::nearest3d,
80 const G4String& electricFieldFilePathIn = "",
81 BDSFieldFormat electricFieldFormatIn = BDSFieldFormat::bdsim1d,
82 BDSInterpolatorType electricInterpolatorTypeIn = BDSInterpolatorType::nearest3d,
83 G4bool cacheTransformsIn = false,
84 G4double eScalingIn = 1.0,
85 G4double bScalingIn = 1.0,
86 G4double timeOffsetIn = 0,
87 G4bool autoScaleIn = false,
88 G4UserLimits* stepLimitIn = nullptr,
89 G4double poleTipRadiusIn = 1,
90 G4double beamPipeRadiusIn = 0,
91 G4bool left = true,
92 const G4String& magneticSubFieldNameIn = "",
93 const G4String& electricSubFieldNameIn = "");
95
97 BDSFieldInfo(const BDSFieldInfo& other);
100
102 inline BDSFieldType FieldType() const {return fieldType;}
103 inline G4double BRho() const {return brho;}
104 inline BDSIntegratorType IntegratorType() const {return integratorType;}
105 inline BDSMagnetStrength* MagnetStrength() const {return magnetStrength;}
106 inline G4bool ProvideGlobal() const {return provideGlobalTransform;}
107 inline G4String MagneticFile() const {return magneticFieldFilePath;}
108 inline BDSFieldFormat MagneticFormat() const {return magneticFieldFormat;}
109 inline BDSInterpolatorType MagneticInterpolatorType() const {return magneticInterpolatorType;}
110 inline G4String ElectricFile() const {return electricFieldFilePath;}
111 inline BDSFieldFormat ElectricFormat() const {return electricFieldFormat;}
112 inline BDSInterpolatorType ElectricInterpolatorType() const {return electricInterpolatorType;}
113 inline G4bool CacheTransforms() const {return cacheTransforms;}
114 inline G4double EScaling() const {return eScaling;}
115 inline G4double BScaling() const {return bScaling;}
116 inline G4double TimeOffset() const {return timeOffset;}
117 inline G4bool AutoScale() const {return autoScale;}
118 inline G4UserLimits* UserLimits() const {return stepLimit;}
119 inline G4double PoleTipRadius() const {return poleTipRadius;}
120 inline G4double BeamPipeRadius() const {return beamPipeRadius;}
121 inline G4double ChordStepMinimum() const {return chordStepMinimum;}
122 inline G4double Tilt() const {return tilt;}
123 inline G4bool SecondFieldOnLeft() const {return secondFieldOnLeft;}
124 inline G4String MagneticSubFieldName() const {return magneticSubFieldName;}
125 inline G4String ElectricSubFieldName() const {return electricSubFieldName;}
126 inline G4String NameOfParserDefinition() const {return nameOfParserDefinition;}
127 inline G4bool UsePlacementWorldTransform() const {return usePlacementWorldTransform;}
128 inline const BDSArrayReflectionTypeSet& MagneticArrayReflectionType() const {return magneticArrayReflectionTypeSet;}
129 inline const BDSArrayReflectionTypeSet& ElectricArrayReflectionType() const {return electricArrayReflectionTypeSet;}
130 inline BDSModulatorInfo* ModulatorInfo() const {return modulatorInfo;}
132 inline G4bool IsThin() const {return isThin;}
133 inline BDSFieldInfoExtra* ExtraInfo() const {return extraInfo;}
135
136 G4double SynchronousT() const;
137
138 G4Transform3D Transform() const;
139 G4Transform3D TransformBeamline() const;
140 G4Transform3D TransformComplete() const;
141
143 inline void SetFieldType(BDSFieldType fieldTypeIn) {fieldType = fieldTypeIn;}
144 inline void SetIntegratorType(BDSIntegratorType typeIn) {integratorType = typeIn;}
145 inline void SetProvideGlobalTransform(G4bool provideGlobalTransformIn) {provideGlobalTransform = provideGlobalTransformIn;}
146 inline void SetMagneticInterpolatorType(BDSInterpolatorType typeIn) {magneticInterpolatorType = typeIn;}
147 inline void SetMagneticArrayReflectionType(const BDSArrayReflectionTypeSet& typeIn) {magneticArrayReflectionTypeSet = typeIn;}
148 inline void SetElectricArrayReflectionType(const BDSArrayReflectionTypeSet& typeIn) {electricArrayReflectionTypeSet = typeIn;}
149 inline void SetBScaling(G4double bScalingIn) {bScaling = bScalingIn;}
150 inline void SetAutoScale(G4bool autoScaleIn) {autoScale = autoScaleIn;}
151 inline void SetScalingRadius(G4double poleTipRadiusIn) {poleTipRadius = poleTipRadiusIn;}
152 inline void SetBeamPipeRadius(G4double beamPipeRadiusIn) {beamPipeRadius = beamPipeRadiusIn;}
153 inline void SetChordStepMinimum(G4double chordStepMinimumIn) {chordStepMinimum = chordStepMinimumIn;}
154 inline void SetSecondFieldOnLeft(G4bool leftIn) {secondFieldOnLeft = leftIn;}
155 inline void SetMagneticSubField(const G4String& mfnIn) {magneticSubFieldName = mfnIn;}
156 inline void SetElectricSubField(const G4String& efnIn) {electricSubFieldName = efnIn;}
157 inline void SetUsePlacementWorldTransform(G4bool use) {usePlacementWorldTransform = use;}
158 inline void SetModulatorInfo(BDSModulatorInfo* modulatorInfoIn) {modulatorInfo = modulatorInfoIn;}
159 inline void SetIgnoreUpdateOfMaximumStepSize(G4bool ignoreUpdateOfMaximumStepSizeIn) {ignoreUpdateOfMaximumStepSize = ignoreUpdateOfMaximumStepSizeIn;}
160
162 inline void CompoundBScaling(G4double extraBScalingIn) {bScaling *= extraBScalingIn;}
164 inline void CompoundEScaling(G4double extraEScalingIn) {eScaling *= extraEScalingIn;}
165
166 void SetTransform(const G4Transform3D& transformIn);
167 void SetTransformBeamline(const G4Transform3D& transformIn);
168
170 void SetUserLimits(G4UserLimits* userLimitsIn);
171
172 void SetNameOfParserDefinition(const G4String& nameIn) {nameOfParserDefinition = nameIn;}
173
175 void SetExtraInfo(BDSFieldInfoExtra* extraInfoIn) {extraInfo = extraInfoIn;}
176
179 void UpdateUserLimitsLengthMaximumStepSize(G4double maximumStepSize,
180 G4bool warn = false) const;
181
184 void Translate(const G4ThreeVector& translationIn);
185
187 inline void CacheTransforms(G4bool cacheTransformsIn) {cacheTransforms = cacheTransformsIn;}
188
190 friend std::ostream& operator<< (std::ostream &out, BDSFieldInfo const &info);
191
192 static G4UserLimits* defaultUL;
193
195 void SetFieldAsThin();
196
197private:
198 BDSFieldType fieldType;
199 G4double brho;
200 BDSIntegratorType integratorType;
201 BDSMagnetStrength* magnetStrength;
202 G4bool provideGlobalTransform;
203 G4Transform3D* transform;
204 G4String magneticFieldFilePath;
205 BDSFieldFormat magneticFieldFormat;
206 BDSInterpolatorType magneticInterpolatorType;
207 BDSArrayReflectionTypeSet magneticArrayReflectionTypeSet;
208 G4String electricFieldFilePath;
209 BDSFieldFormat electricFieldFormat;
210 BDSInterpolatorType electricInterpolatorType;
211 BDSArrayReflectionTypeSet electricArrayReflectionTypeSet;
212 G4bool cacheTransforms;
213 G4double eScaling;
214 G4double bScaling;
215 G4double timeOffset;
216 G4bool autoScale;
217 mutable G4UserLimits* stepLimit;
218 G4double poleTipRadius;
219 G4double beamPipeRadius;
220 G4double chordStepMinimum;
221 G4double tilt;
223 G4String magneticSubFieldName;
224 G4String electricSubFieldName;
225 G4bool usePlacementWorldTransform;
226 BDSModulatorInfo* modulatorInfo;
228 G4bool isThin;
229
231 G4Transform3D* transformBeamline;
232 BDSFieldInfoExtra* extraInfo;
233
234 G4String nameOfParserDefinition;
235
236 // We need a default to pass back if none is specified.
237 const static G4ThreeVector defaultUnitDirection;
238};
239
240#endif
Base class for any extra (complex) information for a particular field.
All info required to build complete field of any type.
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.
G4bool ignoreUpdateOfMaximumStepSize
To be used when enforcing a larger maximum step size value.
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.
G4bool IsThin() const
Accessor.
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.
void SetExtraInfo(BDSFieldInfoExtra *extraInfoIn)
Set the additional 'extra' info member.
G4bool IgnoreUpdateOfMaximumStepSize() 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 SetFieldAsThin()
Set thin to allow geant tracking error controls to be set seperately for thin elements.
void Translate(const G4ThreeVector &translationIn)
BDSModulatorInfo * ModulatorInfo() const
Accessor.
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.
BDSFieldInfoExtra * ExtraInfo() const
Accessor.
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.
Efficient storage of magnet strengths.
Holder class for all information required to describe a modulator.