OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
14 enum MapType {
15  UNKNOWN = 0,
36 };
37 
38 enum SwapType {
39 
40  XZ = 0,
41  ZX,
42  XYZ = 10,
52 };
53 
55  DX = 0,
56  DY,
58 };
59 
60 class Fieldmap {
61 
62 public:
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  virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const = 0;
75  virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const = 0;
76  virtual void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const = 0;
77  virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const = 0;
78  virtual void swap() = 0;
79  virtual void getInfo(Inform *msg) = 0;
80  virtual double getFrequency() const = 0;
81  virtual void setFrequency(double freq) = 0;
82  virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle);
83  virtual void setFieldLength(const double &);
84 
85  virtual void get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
86  std::vector<double> &engeCoeffsExit);
87  virtual void get1DProfile1EntranceParam(double &entranceParameter1,
88  double &entranceParameter2,
89  double &entranceParameter3);
90  virtual void get1DProfile1ExitParam(double &exitParameter1,
91  double &exitParameter2,
92  double &exitParameter3);
93  virtual double getFieldGap();
94  virtual void setFieldGap(double gap);
95 
96  MapType getType() { return Type;}
97 
98  virtual void getOnaxisEz(std::vector<std::pair<double, double> > & onaxis);
99 
100  virtual bool isInside(const Vector_t &r) const;
101 
102  virtual void readMap() = 0;
103  virtual void freeMap() = 0;
104 
105 protected:
106  Fieldmap(const std::string &aFilename);
107  virtual ~Fieldmap() { ;};
108  MapType Type;
109 
110  std::string Filename_m;
112 
114  void getLine(std::ifstream &in, std::string &buffer);
115  static void getLine(std::ifstream &in, int &lines_read, std::string &buffer);
116  template<class S>
117  bool interpreteLine(std::ifstream &in, S &value, const bool &file_length_known = true);
118  template<class S, class T>
119  bool interpreteLine(std::ifstream &in, S &value1, T &value2, const bool &file_length_known = true);
120  template<class S, class T, class U>
121  bool interpreteLine(std::ifstream &in, S &value1, T &value2, U &value3, const bool &file_length_known = true);
122  template<class S, class T, class U, class V>
123  bool interpreteLine(std::ifstream &in, S &value1, T &value2, U &value3, V &value4, const bool &file_length_known = true);
124  template<class S>
125  bool interpreteLine(std::ifstream &in, S &value1, S &value2, S &value3, S &value4, S &value5, S &value6, const bool &file_length_known = true);
126 
127  bool interpreteEOF(std::ifstream &in);
128 
129  void interpreteWarning(const std::string &error_msg, const std::string &expecting, const std::string &found);
130  void interpreteWarning(const std::ios_base::iostate &state,
131  const bool &read_all,
132  const std::string &error_msg,
133  const std::string &found);
134  void missingValuesWarning();
135  void exceedingValuesWarning();
136 
137  void disableFieldmapWarning();
138  void noFieldmapWarning();
139 
140  void lowResolutionWarning(double squareError, double maxError);
141 
142  void checkMap(unsigned int accuracy,
143  std::pair<double, double> fieldDimensions,
144  double deltaZ,
145  const std::vector<double> &fourierCoefficients,
146  gsl_spline *splineCoefficients,
147  gsl_interp_accel *splineAccelerator);
148 
149  void checkMap(unsigned int accuracy,
150  double length,
151  const std::vector<double> &zSampling,
152  const std::vector<double> &fourierCoefficients,
153  gsl_spline *splineCoefficients,
154  gsl_interp_accel *splineAccelerator);
155 
156  void write3DField(unsigned int nx,
157  unsigned int ny,
158  unsigned int nz,
159  const std::pair<double, double> &xrange,
160  const std::pair<double, double> &yrange,
161  const std::pair<double, double> &zrange,
162  const std::vector<Vector_t> &ef,
163  const std::vector<Vector_t> &bf);
164 
165 private:
166  template<typename T>
168  static const char *name;
169  };
170 
172  static std::string alpha_numeric;
173 
177  unsigned int RefCounter;
178  bool read;
180  Type(aType),
181  Map(aMap),
182  RefCounter(1),
183  read(false)
184  { }
185  };
186 
187  static std::map<std::string, FieldmapDescription> FieldmapDictionary;
188 
189 };
190 
191 inline Fieldmap::Fieldmap(const std::string & aFilename) :
192  Filename_m(aFilename),
193  lines_read_m(0),
194  normalize_m(true)
195 { }
196 
197 
198 inline void Fieldmap::getLine(std::ifstream & in, std::string & buffer)
199 {
200  getLine(in, lines_read_m, buffer);
201 }
202 
203 inline bool Fieldmap::isInside(const Vector_t &r) const
204 {
205  return true;
206 }
207 
208 #endif
virtual void getInfo(Inform *msg)=0
virtual void freeMap()=0
Definition: Fieldmap.h:40
static void clearDictionary()
Definition: Fieldmap.cpp:271
static MapType readHeader(std::string Filename)
Definition: Fieldmap.cpp:280
Definition: rbendmap.h:8
virtual void readMap()=0
static const char * name
Definition: Fieldmap.h:168
Definition: Fieldmap.h:45
DiffDirection
Definition: Fieldmap.h:54
Definition: Fieldmap.h:50
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &onaxis)
Definition: Fieldmap.cpp:704
Definition: Fieldmap.h:49
virtual double getFieldGap()
Definition: Fieldmap.cpp:724
Definition: Fieldmap.h:51
virtual bool isInside(const Vector_t &r) const
Definition: Fieldmap.h:203
Definition: Fieldmap.h:48
void disableFieldmapWarning()
Definition: Fieldmap.cpp:610
virtual void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const =0
MapType
Definition: Fieldmap.h:14
SwapType
Definition: Fieldmap.h:38
FieldmapDescription(MapType aType, Fieldmap *aMap)
Definition: Fieldmap.h:179
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition: Fieldmap.cpp:647
static Fieldmap * getFieldmap(std::string Filename, bool fast=false)
Definition: Fieldmap.cpp:46
Definition: Fieldmap.h:41
void noFieldmapWarning()
Definition: Fieldmap.cpp:618
bool normalize_m
Definition: Fieldmap.h:113
static void deleteFieldmap(std::string Filename)
Definition: Fieldmap.cpp:267
Definition: Fieldmap.h:43
int lines_read_m
Definition: Fieldmap.h:111
Fieldmap(const std::string &aFilename)
Definition: Fieldmap.h:191
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const =0
Definition: Fieldmap.h:55
virtual void setFrequency(double freq)=0
static char buffer_m[256]
Definition: Fieldmap.h:171
void missingValuesWarning()
Definition: Fieldmap.cpp:590
virtual void setFieldGap(double gap)
Definition: Fieldmap.cpp:728
Definition: Fieldmap.h:56
static std::map< std::string, FieldmapDescription > FieldmapDictionary
Definition: Fieldmap.h:187
bool interpreteEOF(std::ifstream &in)
Definition: Fieldmap.cpp:547
virtual void setFieldLength(const double &)
Definition: Fieldmap.cpp:521
MapType getType()
Definition: Fieldmap.h:96
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
Definition: Fieldmap.cpp:712
virtual double getFrequency() const =0
void interpreteWarning(const std::string &error_msg, const std::string &expecting, const std::string &found)
Definition: Fieldmap.cpp:563
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
Definition: Fieldmap.cpp:707
Definition: Fieldmap.h:46
bool interpreteLine(std::ifstream &in, S &value, const bool &file_length_known=true)
Definition: Fieldmap.h:57
static std::vector< std::string > getListFieldmapNames()
Definition: Fieldmap.cpp:259
virtual void swap()=0
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
Definition: Fieldmap.cpp:518
static std::string alpha_numeric
Definition: Fieldmap.h:172
Definition: Fieldmap.h:42
void getLine(std::ifstream &in, std::string &buffer)
Definition: Fieldmap.h:198
std::string Filename_m
Definition: Fieldmap.h:110
Definition: Fieldmap.h:44
void exceedingValuesWarning()
Definition: Fieldmap.cpp:600
MapType Type
Definition: Fieldmap.h:107
virtual ~Fieldmap()
Definition: Fieldmap.h:107
Definition: Fieldmap.h:47
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:443
Definition: Inform.h:41
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const =0
void lowResolutionWarning(double squareError, double maxError)
Definition: Fieldmap.cpp:626
#define READ_BUFFER_LENGTH
Definition: Fieldmap.h:4
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:732
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
Definition: Fieldmap.cpp:718