OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Fieldmap.h
Go to the documentation of this file.
1#ifndef OPALX_FIELDMAP_HH
2#define OPALX_FIELDMAP_HH
3
4#define READ_BUFFER_LENGTH 256
5
6#include <map>
7#include <string>
8#include <vector>
9
10#include "OPALTypes.h"
11
12#include "Utilities/GSLSpline.h"
13
37
53
54enum DiffDirection { DX = 0, DY, DZ };
55
62class Fieldmap {
63public:
64 /* ========================================================================== */
65 /* ======================== Dictionary Functions ============================ */
75 static Fieldmap* getFieldmap(std::string Filename, bool fast = false);
76
81 static std::vector<std::string> getListFieldmapNames();
82
87 static void deleteFieldmap(std::string Filename);
88
92 static void clearDictionary();
93
99 static MapType readHeader(std::string Filename);
100
105 static void readMap(std::string Filename);
106
111 static void freeMap(std::string Filename);
112
113 static std::string typeset_msg(const std::string& msg, const std::string& title);
114
115 /* ========================================================================== */
116 /* =========================== Field Functions=============================== */
123 virtual void applyField(std::shared_ptr<ParticleContainer_t> pc, double scale = 1.0) = 0;
124
133 virtual bool getFieldstrength(
135
145 virtual bool getFieldDerivative(
147 const DiffDirection& dir) const = 0;
148
154 virtual void getFieldDimensions(double& zBegin, double& zEnd) const = 0;
155
166 virtual void getFieldDimensions(
167 double& xIni, double& xFinal, double& yIni, double& yFinal, double& zIni,
168 double& zFinal) const = 0;
169
171 virtual void swap() = 0;
172
174 virtual void getInfo(Inform* msg) = 0;
175
180 virtual double getFrequency() const = 0;
181
186 virtual void setFrequency(double freq) = 0;
187
188 virtual void setEdgeConstants(
189 const double& bendAngle, const double& entranceAngle, const double& exitAngle);
190
191 virtual void setFieldLength(const double&);
192
193 virtual void get1DProfile1EngeCoeffs(
194 std::vector<double>& engeCoeffsEntry, std::vector<double>& engeCoeffsExit);
195
196 virtual void get1DProfile1EntranceParam(
197 double& entranceParameter1, double& entranceParameter2, double& entranceParameter3);
198
199 virtual void get1DProfile1ExitParam(
200 double& exitParameter1, double& exitParameter2, double& exitParameter3);
201
202 virtual double getFieldGap();
203
204 virtual void setFieldGap(double gap);
205
206 MapType getType() { return Type; }
207
208 virtual void getOnaxisEz(std::vector<std::pair<double, double>>& onaxis);
209
211 virtual bool isInside(const Vector_t<double, 3>& /*r*/) const = 0;
212
217 virtual void readMap() = 0;
218
222 virtual void freeMap() = 0;
223
224protected:
225 Fieldmap() = delete;
226
227 Fieldmap(const std::string& aFilename)
228 : Filename_m(aFilename), lines_read_m(0), normalize_m(true) {};
229
230 virtual ~Fieldmap() { ; };
232
233 std::string Filename_m;
235
237 void getLine(std::ifstream& in, std::string& buffer) { getLine(in, lines_read_m, buffer); }
238
239 static void getLine(std::ifstream& in, int& lines_read, std::string& buffer);
240
241 template <class S>
242 bool interpretLine(std::ifstream& in, S& value, const bool& file_length_known = true);
243
244 template <class S, class T>
245 bool interpretLine(
246 std::ifstream& in, S& value1, T& value2, const bool& file_length_known = true);
247
248 template <class S, class T, class U>
249 bool interpretLine(
250 std::ifstream& in, S& value1, T& value2, U& value3,
251 const bool& file_length_known = true);
252
253 template <class S, class T, class U, class V>
254 bool interpretLine(
255 std::ifstream& in, S& value1, T& value2, U& value3, V& value4,
256 const bool& file_length_known = true);
257
258 template <class S>
259 bool interpretLine(
260 std::ifstream& in, S& value1, S& value2, S& value3, S& value4, S& value5, S& value6,
261 const bool& file_length_known = true);
262
263 bool interpreteEOF(std::ifstream& in);
264
265 void interpretWarning(
266 const std::ios_base::iostate& state, const bool& read_all, const std::string& error_msg,
267 const std::string& found);
268
270
272
274
275 void noFieldmapWarning();
276
277 void lowResolutionWarning(double squareError, double maxError);
278
279 void checkMap(
280 unsigned int accuracy, std::pair<double, double> fieldDimensions, double deltaZ,
281 const std::vector<double>& fourierCoefficients, gsl_spline* splineCoefficients,
282 gsl_interp_accel* splineAccelerator);
283
284 void checkMap(
285 unsigned int accuracy, double length, const std::vector<double>& zSampling,
286 const std::vector<double>& fourierCoefficients, gsl_spline* splineCoefficients,
287 gsl_interp_accel* splineAccelerator);
288
289 void write3DField(
290 unsigned int nx, unsigned int ny, unsigned int nz,
291 const std::pair<double, double>& xrange, const std::pair<double, double>& yrange,
292 const std::pair<double, double>& zrange, const std::vector<Vector_t<double, 3>>& ef,
293 const std::vector<Vector_t<double, 3>>& bf);
294
295private:
296 template <typename T>
298 static const char* name;
299 };
300
302 static std::string alpha_numeric;
303
307 unsigned int RefCounter;
308 bool read;
310 : Type(aType), Map(aMap), RefCounter(1), read(false) {}
311 };
312
313 static std::map<std::string, FieldmapDescription> FieldmapDictionary;
314};
315
316#endif
ippl::Vector< T, Dim > Vector_t
#define READ_BUFFER_LENGTH
Definition Fieldmap.h:4
SwapType
Definition Fieldmap.h:38
@ XZ
Definition Fieldmap.h:40
@ YMXZ
Definition Fieldmap.h:46
@ MYXZ
Definition Fieldmap.h:48
@ MZYX
Definition Fieldmap.h:51
@ MXYMZ
Definition Fieldmap.h:50
@ XMYMZ
Definition Fieldmap.h:44
@ XMZY
Definition Fieldmap.h:45
@ XZMY
Definition Fieldmap.h:43
@ XYZ
Definition Fieldmap.h:42
@ ZX
Definition Fieldmap.h:41
@ MXMYZ
Definition Fieldmap.h:47
@ ZYMX
Definition Fieldmap.h:49
MapType
Definition Fieldmap.h:14
@ T1DProfile2
Definition Fieldmap.h:23
@ TAstraElectroStatic
Definition Fieldmap.h:19
@ T3DElectroStatic
Definition Fieldmap.h:31
@ T3DDynamic
Definition Fieldmap.h:30
@ T2DDynamic
Definition Fieldmap.h:24
@ T2DElectroStatic_cspline
Definition Fieldmap.h:27
@ T2DMagnetoStatic
Definition Fieldmap.h:28
@ T3DMagnetoStatic
Definition Fieldmap.h:32
@ T1DDynamic
Definition Fieldmap.h:16
@ UNKNOWN
Definition Fieldmap.h:15
@ T2DMagnetoStatic_cspline
Definition Fieldmap.h:29
@ TAstraMagnetoStatic
Definition Fieldmap.h:21
@ T3DMagnetoStatic_Extended
Definition Fieldmap.h:33
@ T2DDynamic_cspline
Definition Fieldmap.h:25
@ T1DProfile1
Definition Fieldmap.h:22
@ T3DMagnetoStaticH5Block
Definition Fieldmap.h:34
@ T3DDynamicH5Block
Definition Fieldmap.h:35
@ T1DElectroStatic
Definition Fieldmap.h:18
@ T1DMagnetoStatic
Definition Fieldmap.h:20
@ T2DElectroStatic
Definition Fieldmap.h:26
@ TAstraDynamic
Definition Fieldmap.h:17
DiffDirection
Definition Fieldmap.h:54
@ DX
Definition Fieldmap.h:54
@ DY
Definition Fieldmap.h:54
@ DZ
Definition Fieldmap.h:54
double T
Definition OPALTypes.h:8
Accelerator caching last interval indices.
Base class for the linear and cubic interpolation spline classes.
Abstract base class for all field maps. It acts as a factory for creating specific field map types ba...
Definition Fieldmap.h:62
MapType Type
Definition Fieldmap.h:231
virtual bool getFieldstrength(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const =0
Get the field strength at a given point.
virtual void getInfo(Inform *msg)=0
Print info about the field map.
virtual void getFieldDimensions(double &zBegin, double &zEnd) const =0
Get the longitudinal dimensions of the field.
static Fieldmap * getFieldmap(std::string Filename, bool fast=false)
Get a field map instance. Use this factory method to obtain a field map. It checks the cache (Fieldma...
Definition Fieldmap.cpp:72
virtual bool getFieldDerivative(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const =0
Get the field derivative with respect to a direction.
MapType getType()
Definition Fieldmap.h:206
static void deleteFieldmap(std::string Filename)
Delete a specific field map from the cache and memory.
Definition Fieldmap.cpp:158
static std::string alpha_numeric
Definition Fieldmap.h:302
static std::map< std::string, FieldmapDescription > FieldmapDictionary
Definition Fieldmap.h:313
static MapType readHeader(std::string Filename)
Read the header of a field map file to determine its type.
Definition Fieldmap.cpp:174
virtual void setFrequency(double freq)=0
Set the frequency.
bool interpreteEOF(std::ifstream &in)
Definition Fieldmap.cpp:436
virtual void setFieldLength(const double &)
Definition Fieldmap.cpp:412
virtual void freeMap()=0
Pure virtual method to free the map data.
void missingValuesWarning()
Definition Fieldmap.cpp:470
Fieldmap()=delete
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &onaxis)
Definition Fieldmap.cpp:588
virtual void swap()=0
Swap coordinates (implementation dependent).
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
Definition Fieldmap.cpp:593
virtual void applyField(std::shared_ptr< ParticleContainer_t > pc, double scale=1.0)=0
Apply the FM to all the particles.
void checkMap(unsigned int accuracy, std::pair< double, double > fieldDimensions, double deltaZ, const std::vector< double > &fourierCoefficients, gsl_spline *splineCoefficients, gsl_interp_accel *splineAccelerator)
Definition Fieldmap.cpp:330
void lowResolutionWarning(double squareError, double maxError)
Definition Fieldmap.cpp:503
void interpretWarning(const std::ios_base::iostate &state, const bool &read_all, const std::string &error_msg, const std::string &found)
Definition Fieldmap.cpp:452
virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const =0
Get the full 3D bounding box of the field.
Fieldmap(const std::string &aFilename)
Definition Fieldmap.h:227
void disableFieldmapWarning()
Definition Fieldmap.cpp:489
virtual double getFrequency() const =0
Get the frequency.
bool normalize_m
Definition Fieldmap.h:236
static char buffer_m[256]
Definition Fieldmap.h:301
int lines_read_m
Definition Fieldmap.h:234
static std::vector< std::string > getListFieldmapNames()
Get a list of all loaded field map names.
Definition Fieldmap.cpp:149
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition Fieldmap.cpp:527
static void clearDictionary()
Clear the entire field map cache.
Definition Fieldmap.cpp:160
virtual ~Fieldmap()
Definition Fieldmap.h:230
virtual double getFieldGap()
Definition Fieldmap.cpp:600
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
Definition Fieldmap.cpp:408
std::string Filename_m
Definition Fieldmap.h:233
virtual void setFieldGap(double gap)
Definition Fieldmap.cpp:602
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
virtual bool isInside(const Vector_t< double, 3 > &) const =0
Check if a point is inside the field map.
void exceedingValuesWarning()
Definition Fieldmap.cpp:479
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
Definition Fieldmap.cpp:590
void getLine(std::ifstream &in, std::string &buffer)
Definition Fieldmap.h:237
void noFieldmapWarning()
Definition Fieldmap.cpp:496
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
Definition Fieldmap.cpp:597
virtual void readMap()=0
Pure virtual method to read the map data. Called by the public static readMap().
void write3DField(unsigned int nx, unsigned int ny, unsigned int nz, const std::pair< double, double > &xrange, const std::pair< double, double > &yrange, const std::pair< double, double > &zrange, const std::vector< Vector_t< double, 3 > > &ef, const std::vector< Vector_t< double, 3 > > &bf)
Definition Fieldmap.cpp:604
FieldmapDescription(MapType aType, Fieldmap *aMap)
Definition Fieldmap.h:309
static const char * name
Definition Fieldmap.h:298