OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Fieldmap.h
Go to the documentation of this file.
1#ifndef CLASSIC_FIELDMAP_HH
2#define CLASSIC_FIELDMAP_HH
3
4#define READ_BUFFER_LENGTH 256
5
6#include <string>
7#include <map>
8#include <vector>
9#include "Algorithms/Vektor.h"
10
11#include "gsl/gsl_interp.h"
12#include "gsl/gsl_spline.h"
13
14enum MapType {
36};
37
39
40 XZ = 0,
42 XYZ = 10,
51 MZYX
52};
53
55 DX = 0,
57 DZ
58};
59
60class Fieldmap {
61
62public:
63
64 static Fieldmap *getFieldmap(std::string Filename, bool fast = false);
65 static std::vector<std::string> getListFieldmapNames();
66 static void deleteFieldmap(std::string Filename);
67 static void clearDictionary();
68 static MapType readHeader(std::string Filename);
69 static void readMap(std::string Filename);
70 static void freeMap(std::string Filename);
71
72 static std::string typeset_msg(const std::string &msg, const std::string &title);
73
74 // Note: getFieldstrength() returns true if R is outside of the field!
75 virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const = 0;
76 virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const = 0;
77 virtual void getFieldDimensions(double &zBegin, double &zEnd) const = 0;
78 virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const = 0;
79 virtual void swap() = 0;
80 virtual void getInfo(Inform *msg) = 0;
81 virtual double getFrequency() const = 0;
82 virtual void setFrequency(double freq) = 0;
83 virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle);
84 virtual void setFieldLength(const double &);
85
86 virtual void get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
87 std::vector<double> &engeCoeffsExit);
88 virtual void get1DProfile1EntranceParam(double &entranceParameter1,
89 double &entranceParameter2,
90 double &entranceParameter3);
91 virtual void get1DProfile1ExitParam(double &exitParameter1,
92 double &exitParameter2,
93 double &exitParameter3);
94 virtual double getFieldGap();
95 virtual void setFieldGap(double gap);
96
97 MapType getType() { return Type;}
98
99 virtual void getOnaxisEz(std::vector<std::pair<double, double> > & onaxis);
100
101 virtual bool isInside(const Vector_t &/*r*/) const { return true; }
102
103 virtual void readMap() = 0;
104 virtual void freeMap() = 0;
105
106protected:
107 Fieldmap () = delete;
108
109 Fieldmap(const std::string& aFilename)
110 : Filename_m(aFilename),
111 lines_read_m(0),
112 normalize_m(true) { };
113
114 virtual ~Fieldmap() { ;};
116
117 std::string Filename_m;
119
121 void getLine(std::ifstream & in, std::string & buffer) {
122 getLine(in, lines_read_m, buffer);
123 }
124
125 static void getLine(std::ifstream &in, int &lines_read, std::string &buffer);
126
127 template<class S>
128 bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known = true);
129 template<class S, class T>
130 bool interpretLine(std::ifstream &in, S &value1, T &value2, const bool &file_length_known = true);
131 template<class S, class T, class U>
132 bool interpretLine(std::ifstream &in, S &value1, T &value2, U &value3, const bool &file_length_known = true);
133 template<class S, class T, class U, class V>
134 bool interpretLine(std::ifstream &in, S &value1, T &value2, U &value3, V &value4, const bool &file_length_known = true);
135 template<class S>
136 bool interpretLine(std::ifstream &in, S &value1, S &value2, S &value3, S &value4, S &value5, S &value6, const bool &file_length_known = true);
137
138 bool interpreteEOF(std::ifstream &in);
139
140 void interpretWarning(const std::ios_base::iostate &state,
141 const bool &read_all,
142 const std::string &error_msg,
143 const std::string &found);
146
148 void noFieldmapWarning();
149
150 void lowResolutionWarning(double squareError, double maxError);
151
152 void checkMap(unsigned int accuracy,
153 std::pair<double, double> fieldDimensions,
154 double deltaZ,
155 const std::vector<double> &fourierCoefficients,
156 gsl_spline *splineCoefficients,
157 gsl_interp_accel *splineAccelerator);
158
159 void checkMap(unsigned int accuracy,
160 double length,
161 const std::vector<double> &zSampling,
162 const std::vector<double> &fourierCoefficients,
163 gsl_spline *splineCoefficients,
164 gsl_interp_accel *splineAccelerator);
165
166 void write3DField(unsigned int nx,
167 unsigned int ny,
168 unsigned int nz,
169 const std::pair<double, double> &xrange,
170 const std::pair<double, double> &yrange,
171 const std::pair<double, double> &zrange,
172 const std::vector<Vector_t> &ef,
173 const std::vector<Vector_t> &bf);
174
175private:
176 template<typename T>
178 static const char *name;
179 };
180
182 static std::string alpha_numeric;
183
187 unsigned int RefCounter;
188 bool read;
190 Type(aType),
191 Map(aMap),
192 RefCounter(1),
193 read(false)
194 { }
195 };
196
197 static std::map<std::string, FieldmapDescription> FieldmapDictionary;
198
199};
200
201#endif
#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:55
@ DY
Definition: Fieldmap.h:56
@ DZ
Definition: Fieldmap.h:57
MapType Type
Definition: Fieldmap.h:114
virtual void getInfo(Inform *msg)=0
virtual void getFieldDimensions(double &zBegin, double &zEnd) const =0
static Fieldmap * getFieldmap(std::string Filename, bool fast=false)
Definition: Fieldmap.cpp:50
MapType getType()
Definition: Fieldmap.h:97
static void deleteFieldmap(std::string Filename)
Definition: Fieldmap.cpp:271
static std::string alpha_numeric
Definition: Fieldmap.h:182
static std::map< std::string, FieldmapDescription > FieldmapDictionary
Definition: Fieldmap.h:197
static MapType readHeader(std::string Filename)
Definition: Fieldmap.cpp:284
virtual void setFrequency(double freq)=0
bool interpreteEOF(std::ifstream &in)
Definition: Fieldmap.cpp:558
virtual void setFieldLength(const double &)
Definition: Fieldmap.cpp:533
virtual bool isInside(const Vector_t &) const
Definition: Fieldmap.h:101
virtual void freeMap()=0
void missingValuesWarning()
Definition: Fieldmap.cpp:593
Fieldmap()=delete
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &onaxis)
Definition: Fieldmap.cpp:709
virtual void swap()=0
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const =0
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
Definition: Fieldmap.cpp:717
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:451
void lowResolutionWarning(double squareError, double maxError)
Definition: Fieldmap.cpp:629
void interpretWarning(const std::ios_base::iostate &state, const bool &read_all, const std::string &error_msg, const std::string &found)
Definition: Fieldmap.cpp:574
virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const =0
Fieldmap(const std::string &aFilename)
Definition: Fieldmap.h:109
void disableFieldmapWarning()
Definition: Fieldmap.cpp:613
virtual double getFrequency() const =0
bool normalize_m
Definition: Fieldmap.h:120
static char buffer_m[256]
Definition: Fieldmap.h:181
int lines_read_m
Definition: Fieldmap.h:118
static std::vector< std::string > getListFieldmapNames()
Definition: Fieldmap.cpp:263
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition: Fieldmap.cpp:652
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const =0
static void clearDictionary()
Definition: Fieldmap.cpp:275
virtual ~Fieldmap()
Definition: Fieldmap.h:114
virtual double getFieldGap()
Definition: Fieldmap.cpp:729
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
Definition: Fieldmap.cpp:530
std::string Filename_m
Definition: Fieldmap.h:117
virtual void setFieldGap(double gap)
Definition: Fieldmap.cpp:733
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
void exceedingValuesWarning()
Definition: Fieldmap.cpp:603
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
Definition: Fieldmap.cpp:712
void getLine(std::ifstream &in, std::string &buffer)
Definition: Fieldmap.h:121
void noFieldmapWarning()
Definition: Fieldmap.cpp:621
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
Definition: Fieldmap.cpp:723
virtual void readMap()=0
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 > &ef, const std::vector< Vector_t > &bf)
Definition: Fieldmap.cpp:737
static const char * name
Definition: Fieldmap.h:178
FieldmapDescription(MapType aType, Fieldmap *aMap)
Definition: Fieldmap.h:189
Definition: Inform.h:42