BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldLoader.hh
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 BDSFIELDLOADER_H
19#define BDSFIELDLOADER_H
20
21#include "BDSArrayReflectionType.hh"
22#include "BDSInterpolatorType.hh"
23#include "G4String.hh"
24#include "G4Transform3D.hh"
25
26#include <array>
27#include <set>
28
33class BDSArrayInfo;
36class BDSFieldInfo;
37class BDSFieldMag;
46
62{
63public:
65 static BDSFieldLoader* Instance();
66
68
69 void DeleteArrays();
70
73 const BDSMagnetStrength* scalingStrength = nullptr,
74 const G4String& scalingKey = "none");
75
78
81
82private:
85
88
90 static void BFilePathOK(const BDSFieldInfo& info);
91 static void EFilePathOK(const BDSFieldInfo& info);
93
95 BDSArray1DCoords* Get1DCached(const G4String& filePath);
96 BDSArray2DCoords* Get2DCached(const G4String& filePath);
97 BDSArray3DCoords* Get3DCached(const G4String& filePath);
98 BDSArray4DCoords* Get4DCached(const G4String& filePath);
100
102 BDSArray2DCoords* LoadPoissonMag2D(const G4String& filePath);
103 BDSArray1DCoords* LoadBDSIM1D(const G4String& filePath);
104 BDSArray2DCoords* LoadBDSIM2D(const G4String& filePath);
105 BDSArray3DCoords* LoadBDSIM3D(const G4String& filePath);
106 BDSArray4DCoords* LoadBDSIM4D(const G4String& filePath);
108
111 void CreateOperators(const BDSArrayReflectionTypeSet* reflectionTypes,
112 const BDSArray4DCoords* existingArray,
113 BDSArrayOperatorIndex*& indexOperator,
114 BDSArrayOperatorValue*& valueOperator) const;
115
120 const std::array<G4bool, 4>& operatesOnXYZT,
121 G4double tolerance=0.05) const;
122
125 G4bool NeedToProvideTransform(const BDSArrayReflectionTypeSet* reflectionTypes) const;
126
127 BDSArray1DCoords* CreateArrayReflected(BDSArray1DCoords* existingArray,
128 const BDSArrayReflectionTypeSet* reflectionType) const;
129 BDSArray2DCoords* CreateArrayReflected(BDSArray2DCoords* existingArray,
130 const BDSArrayReflectionTypeSet* reflectionType) const;
131 BDSArray3DCoords* CreateArrayReflected(BDSArray3DCoords* existingArray,
132 const BDSArrayReflectionTypeSet* reflectionType) const;
133 BDSArray4DCoords* CreateArrayReflected(BDSArray4DCoords* existingArray,
134 const BDSArrayReflectionTypeSet* reflectionType) const;
135
138 BDSInterpolatorType interpolatorType) const;
139
142 BDSInterpolatorType interpolatorType) const;
143
146 BDSInterpolatorType interpolatorType) const;
147
150 BDSInterpolatorType interpolatorType) const;
151
153 BDSFieldMagInterpolated* LoadBDSIM1DB(const G4String& filePath,
154 BDSInterpolatorType interpolatorType,
155 const G4Transform3D& transform,
156 G4double bScaling,
157 const BDSArrayReflectionTypeSet* reflection = nullptr);
158
160 BDSFieldMagInterpolated* LoadBDSIM2DB(const G4String& filePath,
161 BDSInterpolatorType interpolatorType,
162 const G4Transform3D& transform,
163 G4double bScaling,
164 const BDSArrayReflectionTypeSet* reflection = nullptr);
165
167 BDSFieldMagInterpolated* LoadBDSIM3DB(const G4String& filePath,
168 BDSInterpolatorType interpolatorType,
169 const G4Transform3D& transform,
170 G4double bScaling,
171 const BDSArrayReflectionTypeSet* reflection = nullptr);
172
174 BDSFieldMagInterpolated* LoadBDSIM4DB(const G4String& filePath,
175 BDSInterpolatorType interpolatorType,
176 const G4Transform3D& transform,
177 G4double bScaling,
178 const BDSArrayReflectionTypeSet* reflection = nullptr);
179
181 BDSFieldMagInterpolated* LoadPoissonSuperFishB(const G4String& filePath,
182 BDSInterpolatorType interpolatorType,
183 const G4Transform3D& transform,
184 G4double bScaling,
185 const BDSArrayReflectionTypeSet* reflection = nullptr);
186
189 BDSFieldMagInterpolated* LoadPoissonSuperFishBQuad(const G4String& filePath,
190 BDSInterpolatorType interpolatorType,
191 const G4Transform3D& transform,
192 G4double bScaling,
193 const BDSArrayReflectionTypeSet* reflection = nullptr);
194
198 BDSInterpolatorType interpolatorType,
199 const G4Transform3D& transform,
200 G4double bScaling,
201 const BDSArrayReflectionTypeSet* reflection = nullptr);
202
204 BDSFieldEInterpolated* LoadBDSIM1DE(const G4String& filePath,
205 BDSInterpolatorType interpolatorType,
206 const G4Transform3D& transform,
207 G4double eScaling,
208 const BDSArrayReflectionTypeSet* reflection = nullptr);
209
211 BDSFieldEInterpolated* LoadBDSIM2DE(const G4String& filePath,
212 BDSInterpolatorType interpolatorType,
213 const G4Transform3D& transform,
214 G4double eScaling,
215 const BDSArrayReflectionTypeSet* reflection = nullptr);
216
218 BDSFieldEInterpolated* LoadBDSIM3DE(const G4String& filePath,
219 BDSInterpolatorType interpolatorType,
220 const G4Transform3D& transform,
221 G4double eScaling,
222 const BDSArrayReflectionTypeSet* reflection = nullptr);
223
225 BDSFieldEInterpolated* LoadBDSIM4DE(const G4String& filePath,
226 BDSInterpolatorType interpolatorType,
227 const G4Transform3D& transform,
228 G4double eScaling,
229 const BDSArrayReflectionTypeSet* reflection = nullptr);
230
232 BDSFieldEMInterpolated* LoadBDSIM1DEM(const G4String& eFilePath,
233 const G4String& bFilePath,
234 BDSInterpolatorType eInterpolatorType,
235 BDSInterpolatorType bInterpolatorType,
236 const G4Transform3D& transform,
237 G4double eScaling,
238 G4double bScaling,
239 const BDSArrayReflectionTypeSet* eReflection = nullptr,
240 const BDSArrayReflectionTypeSet* bReflection = nullptr);
241
243 BDSFieldEMInterpolated* LoadBDSIM2DEM(const G4String& eFilePath,
244 const G4String& bFilePath,
245 BDSInterpolatorType eInterpolatorType,
246 BDSInterpolatorType bInterpolatorType,
247 const G4Transform3D& transform,
248 G4double eScaling,
249 G4double bScaling,
250 const BDSArrayReflectionTypeSet* eReflection = nullptr,
251 const BDSArrayReflectionTypeSet* bReflection = nullptr);
252
254 BDSFieldEMInterpolated* LoadBDSIM3DEM(const G4String& eFilePath,
255 const G4String& bFilePath,
256 BDSInterpolatorType eInterpolatorType,
257 BDSInterpolatorType bInterpolatorType,
258 const G4Transform3D& transform,
259 G4double eScaling,
260 G4double bScaling,
261 const BDSArrayReflectionTypeSet* eReflection = nullptr,
262 const BDSArrayReflectionTypeSet* bReflection = nullptr);
263
265 BDSFieldEMInterpolated* LoadBDSIM4DEM(const G4String& eFilePath,
266 const G4String& bFilePath,
267 BDSInterpolatorType eInterpolatorType,
268 BDSInterpolatorType bInterpolatorType,
269 const G4Transform3D& transform,
270 G4double eScaling,
271 G4double bScaling,
272 const BDSArrayReflectionTypeSet* eReflection = nullptr,
273 const BDSArrayReflectionTypeSet* bReflection = nullptr);
274
276 std::map<G4String, BDSArray1DCoords*> arrays1d;
277 std::map<G4String, BDSArray2DCoords*> arrays2d;
278 std::map<G4String, BDSArray3DCoords*> arrays3d;
279 std::map<G4String, BDSArray4DCoords*> arrays4d;
281};
282
283#endif
1D array with spatial mapping derived from BDSArray4DCoords.
2D array with spatial mapping derived from BDSArray4DCoords.
3D array with spatial mapping derived from BDSArray4DCoords.
Overlay of 4D array that provides uniform only spatial coordinate mapping.
Simple holder of information about an array.
Interface for modifying by reference array indices.
Interface for modifying field values.
Class to provide scaling and a base class pointer for interpolator fields.
Class to provide scaling and a base class pointer for interpolator fields.
All info required to build complete field of any type.
A loader for various field map formats.
BDSFieldEInterpolated * LoadBDSIM3DE(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double eScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 3D BDSIM format electric field.
static void EFilePathOK(const BDSFieldInfo &info)
Check file path isn't empty and throw exception if it is.
BDSFieldEMInterpolated * LoadBDSIM3DEM(const G4String &eFilePath, const G4String &bFilePath, BDSInterpolatorType eInterpolatorType, BDSInterpolatorType bInterpolatorType, const G4Transform3D &transform, G4double eScaling, G4double bScaling, const BDSArrayReflectionTypeSet *eReflection=nullptr, const BDSArrayReflectionTypeSet *bReflection=nullptr)
Load a 3D BDSIM format electro-magnetic field.
BDSInterpolator3D * CreateInterpolator3D(BDSArray3DCoords *array, BDSInterpolatorType interpolatorType) const
Create the appropriate 3D interpolator for an array.
std::map< G4String, BDSArray1DCoords * > arrays1d
Map of cached field map array.
BDSFieldEMInterpolated * LoadBDSIM4DEM(const G4String &eFilePath, const G4String &bFilePath, BDSInterpolatorType eInterpolatorType, BDSInterpolatorType bInterpolatorType, const G4Transform3D &transform, G4double eScaling, G4double bScaling, const BDSArrayReflectionTypeSet *eReflection=nullptr, const BDSArrayReflectionTypeSet *bReflection=nullptr)
Load a 4D BDSIM format electro-magnetic field.
std::map< G4String, BDSArray2DCoords * > arrays2d
Map of cached field map array.
BDSArray2DCoords * LoadPoissonMag2D(const G4String &filePath)
Utility function to use the right templated loader class (gz or normal).
BDSArray3DCoords * Get3DCached(const G4String &filePath)
Return the cached array if there is one - may return nullptr.
BDSArray2DCoords * LoadBDSIM2D(const G4String &filePath)
Utility function to use the right templated loader class (gz or normal).
BDSFieldEMInterpolated * LoadEMField(const BDSFieldInfo &info)
Main interface to load an electro-magnetic field.
BDSInterpolator1D * CreateInterpolator1D(BDSArray1DCoords *array, BDSInterpolatorType interpolatorType) const
Create the appropriate 1D interpolator for an array.
BDSFieldEInterpolated * LoadBDSIM2DE(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double eScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 2D BDSIM format electric field.
std::map< G4String, BDSArray3DCoords * > arrays3d
Map of cached field map array.
void ReportIfProblemWithReflection(const BDSArrayInfo &info, const std::array< G4bool, 4 > &operatesOnXYZT, G4double tolerance=0.05) const
BDSInterpolator2D * CreateInterpolator2D(BDSArray2DCoords *array, BDSInterpolatorType interpolatorType) const
Create the appropriate 2D interpolator for an array.
BDSFieldEInterpolated * LoadBDSIM4DE(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double eScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 4D BDSIM format electric field.
BDSFieldMagInterpolated * LoadPoissonSuperFishB(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 2D poisson superfish B field map.
BDSFieldLoader()
Private default constructor as singleton.
BDSFieldMagInterpolated * LoadPoissonSuperFishBQuad(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
BDSArray1DCoords * Get1DCached(const G4String &filePath)
Return the cached array if there is one - may return nullptr.
BDSFieldMagInterpolated * LoadBDSIM1DB(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 1D BDSIM format magnetic field.
BDSFieldEMInterpolated * LoadBDSIM1DEM(const G4String &eFilePath, const G4String &bFilePath, BDSInterpolatorType eInterpolatorType, BDSInterpolatorType bInterpolatorType, const G4Transform3D &transform, G4double eScaling, G4double bScaling, const BDSArrayReflectionTypeSet *eReflection=nullptr, const BDSArrayReflectionTypeSet *bReflection=nullptr)
Load a 1D BDSIM format electro-magnetic field.
BDSArray3DCoords * LoadBDSIM3D(const G4String &filePath)
Utility function to use the right templated loader class (gz or normal).
BDSFieldMagInterpolated * LoadBDSIM4DB(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 4D BDSIM format magnetic field.
BDSFieldMagInterpolated * LoadBDSIM2DB(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 2D BDSIM format magnetic field.
BDSFieldMagInterpolated * LoadMagField(const BDSFieldInfo &info, const BDSMagnetStrength *scalingStrength=nullptr, const G4String &scalingKey="none")
Main interface to load a magnetic field.
static BDSFieldLoader * instance
Singleton instance.
static BDSFieldLoader * Instance()
Singleton accessor.
BDSFieldEMInterpolated * LoadBDSIM2DEM(const G4String &eFilePath, const G4String &bFilePath, BDSInterpolatorType eInterpolatorType, BDSInterpolatorType bInterpolatorType, const G4Transform3D &transform, G4double eScaling, G4double bScaling, const BDSArrayReflectionTypeSet *eReflection=nullptr, const BDSArrayReflectionTypeSet *bReflection=nullptr)
Load a 2D BDSIM format electro-magnetic field.
BDSArray4DCoords * Get4DCached(const G4String &filePath)
Return the cached array if there is one - may return nullptr.
BDSFieldMagInterpolated * LoadPoissonSuperFishBDipole(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
BDSInterpolator4D * CreateInterpolator4D(BDSArray4DCoords *array, BDSInterpolatorType interpolatorType) const
Create the appropriate 4D interpolator for an array.
BDSFieldMagInterpolated * LoadBDSIM3DB(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double bScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 3D BDSIM format magnetic field.
BDSFieldEInterpolated * LoadEField(const BDSFieldInfo &info)
Main interface to load an electric field.
G4bool NeedToProvideTransform(const BDSArrayReflectionTypeSet *reflectionTypes) const
BDSFieldEInterpolated * LoadBDSIM1DE(const G4String &filePath, BDSInterpolatorType interpolatorType, const G4Transform3D &transform, G4double eScaling, const BDSArrayReflectionTypeSet *reflection=nullptr)
Load a 1D BDSIM format electric field.
void CreateOperators(const BDSArrayReflectionTypeSet *reflectionTypes, const BDSArray4DCoords *existingArray, BDSArrayOperatorIndex *&indexOperator, BDSArrayOperatorValue *&valueOperator) const
static void BFilePathOK(const BDSFieldInfo &info)
Check file path isn't empty and throw exception if it is.
BDSArray1DCoords * LoadBDSIM1D(const G4String &filePath)
Utility function to use the right templated loader class (gz or normal).
BDSArray4DCoords * LoadBDSIM4D(const G4String &filePath)
Utility function to use the right templated loader class (gz or normal).
std::map< G4String, BDSArray4DCoords * > arrays4d
Map of cached field map array.
BDSArray2DCoords * Get2DCached(const G4String &filePath)
Return the cached array if there is one - may return nullptr.
Class to provide scaling and a base class pointer for interpolator fields.
Interface for static magnetic fields that may or may not be local.
Interface for all 1D interpolators.
Interface for all 2D interpolators.
Interface for all 3D interpolators.
Interface for all 4D interpolators.
Efficient storage of magnet strengths.