OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FM1DProfile1.cpp
Go to the documentation of this file.
1 #include "Fields/FM1DProfile1.h"
2 #include "Fields/Fieldmap.hpp"
3 #include "Physics/Physics.h"
5 
6 #include <fstream>
7 #include <ios>
8 
9 FM1DProfile1::FM1DProfile1(std::string aFilename):
10  Fieldmap(aFilename),
11  entranceParameter1_m(0.0),
12  entranceParameter2_m(0.0),
13  entranceParameter3_m(0.0),
14  exitParameter1_m(0.0),
15  exitParameter2_m(0.0),
16  exitParameter3_m(0.0),
17  polyOrderEntry_m(5),
18  polyOrderExit_m(5),
19  gapHeight_m(0.02),
20  sBegin_m(0.0),
21  sEnd_m(0.0) {
22 
23  // Read file header information. Set field type.
24  Type = T1DProfile1;
25 
26  // Read file. Check if we are using the default field profile.
27  if(Filename_m == "1DPROFILE1-DEFAULT") {
28 
29  /*
30  * Use default field profile coefficients:
31  *
32  * polyOrderEntry_m = 5
33  * polyOrderExit_m = 5
34  * gapHeight_m = 0.02 m
35  *
36  */
37  polyOrderEntry_m = 5;
38  polyOrderExit_m = 5;
39  gapHeight_m = 0.02;
40 
41  entranceParameter1_m = -0.1;
44 
45  exitParameter1_m = -0.1;
46  exitParameter2_m = 0.0;
47  exitParameter3_m = 0.1;
48 
49  } else {
50 
51  std::ifstream inputFile(Filename_m.c_str());
52 
53  if(inputFile.good()) {
54 
55  int tempInt = 0;
56  std::string tempString = "";
57  double tempDouble = 0.0;
58 
59  bool parsingPassed = interpreteLine<std::string, int, int, double>
60  (inputFile,
61  tempString,
64  gapHeight_m);
65 
66  parsingPassed = parsingPassed &&
67  interpreteLine<double, double, double, int>
68  (inputFile,
72  tempInt,
73  false);
74 
75  parsingPassed = parsingPassed &&
76  interpreteLine<double, double, double, int>
77  (inputFile,
81  tempInt);
82 
83  for(int index = 0;
84  (index < polyOrderEntry_m + polyOrderExit_m + 2) && parsingPassed;
85  index++)
86  parsingPassed = parsingPassed &&
87  interpreteLine<double>(inputFile, tempDouble);
88 
89  parsingPassed = parsingPassed && interpreteEOF(inputFile);
90 
91  inputFile.close();
92 
93  if(!parsingPassed) {
94 
96  sBegin_m = 0.0;
97  sEnd_m = sBegin_m - 1.0e-3;
98 
99  } else {
100 
101  // Convert from cm to m. Make sure gap is positive.
102  entranceParameter1_m /= 100.0;
103  entranceParameter2_m /= 100.0;
104  entranceParameter3_m /= 100.0;
105 
106  exitParameter1_m /= 100.0;
107  exitParameter2_m /= 100.0;
108  exitParameter3_m /= 100.0;
109 
110  gapHeight_m = std::abs(gapHeight_m / 100.0);
111 
112  }
113 
114  } else {
115 
116  // No field map file or field map file is somehow flawed.
118  sBegin_m = 0.0;
119  sEnd_m = sBegin_m - 1.0e-3;
120 
121  }
122  }
123 }
124 
126 }
127 
129 
130  if(!engeCoeffsEntry_m.empty())
131  engeCoeffsEntry_m.clear();
132 
133  if(!engeCoeffsExit_m.empty())
134  engeCoeffsExit_m.clear();
135 
136  if(Filename_m == "1DPROFILE1-DEFAULT") {
137 
138  engeCoeffsEntry_m.push_back(0.478959);
139  engeCoeffsEntry_m.push_back(1.911289);
140  engeCoeffsEntry_m.push_back(-1.185953);
141  engeCoeffsEntry_m.push_back(1.630554);
142  engeCoeffsEntry_m.push_back(-1.082657);
143  engeCoeffsEntry_m.push_back(0.318111);
144 
145  engeCoeffsExit_m.push_back(0.478959);
146  engeCoeffsExit_m.push_back(1.911289);
147  engeCoeffsExit_m.push_back(-1.185953);
148  engeCoeffsExit_m.push_back(1.630554);
149  engeCoeffsExit_m.push_back(-1.082657);
150  engeCoeffsExit_m.push_back(0.31811);
151 
152  } else {
153 
154  std::ifstream inputFile(Filename_m.c_str());
155 
156  int tempInt;
157  std::string tempString;
158  double tempDouble;
159 
160  interpreteLine<std::string, int, int, double>(inputFile,
161  tempString,
162  tempInt,
163  tempInt,
164  tempDouble);
165  interpreteLine<double, double, double, int>(inputFile,
166  tempDouble,
167  tempDouble,
168  tempDouble,
169  tempInt);
170  interpreteLine<double, double, double, int>(inputFile,
171  tempDouble,
172  tempDouble,
173  tempDouble,
174  tempInt);
175 
176  for(int index = 0; index < polyOrderEntry_m + 1; index++) {
177  interpreteLine<double>(inputFile, tempDouble);
178  engeCoeffsEntry_m.push_back(tempDouble);
179  }
180 
181  for(int index = 0; index < polyOrderExit_m + 1; index++) {
182  interpreteLine<double>(inputFile, tempDouble);
183  engeCoeffsExit_m.push_back(tempDouble);
184  }
185 
186  inputFile.close();
187 
188  INFOMSG(level3 << typeset_msg("read in fieldmap '" + Filename_m + "'", "info")
189  << "\n" << endl);
190 
191  }
192 
194  for (int index = 0; index < polyOrderEntry_m + 1; ++ index) {
195  if (index % 2 == 0) continue;
196  engeCoeffsEntry_m[index] *= -1;
197  }
198  }
199 
201  for (int index = 0; index < polyOrderExit_m + 1; ++ index) {
202  if (index % 2 == 0) continue;
203  engeCoeffsExit_m[index] *= -1;
204  }
205  }
206 }
207 
209 }
210 
212 
213  /*
214  * For this type of field map, the elements who use it calculate the field
215  * amplitude using the field map parameters.
216  */
217  return true;
218 
219 }
220 
222  Vector_t &E,
223  Vector_t &B,
224  const DiffDirection &dir) const {
225  return false;
226 }
227 
229  double &sEnd,
230  double &rBegin,
231  double &rEnd) const {
232  sBegin = sBegin_m;
233  sEnd = sEnd_m;
234 }
236  double &xFinal,
237  double &yIni,
238  double &yFinal,
239  double &zIni,
240  double &zFinal) const {
241 
242 }
243 
245 {}
246 
248  (*msg) << Filename_m
249  << " (1D Profile type 1)"
250  << endl;
251 }
252 
254  return 0.0;
255 }
256 
257 void FM1DProfile1::setFrequency(double freq)
258 {}
259 
260 void FM1DProfile1::get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
261  std::vector<double> &engeCoeffsExit) {
262  engeCoeffsEntry = engeCoeffsEntry_m;
263  engeCoeffsExit = engeCoeffsExit_m;
264 
265 }
266 
267 void FM1DProfile1::get1DProfile1EntranceParam(double &entranceParameter1,
268  double &entranceParameter2,
269  double &entranceParameter3) {
270  entranceParameter1 = entranceParameter1_m;
271  entranceParameter2 = entranceParameter2_m;
272  entranceParameter3 = entranceParameter3_m;
273 }
274 
275 void FM1DProfile1::get1DProfile1ExitParam(double &exitParameter1,
276  double &exitParameter2,
277  double &exitParameter3) {
278  exitParameter1 = exitParameter1_m;
279  exitParameter2 = exitParameter2_m;
280  exitParameter3 = exitParameter3_m;
281 }
282 
284  return gapHeight_m;
285 }
286 void FM1DProfile1::setFieldGap(double gap) {
287 
288  gapHeight_m = gap;
289 
290 }
291 
292 double FM1DProfile1::computeEntranceFringe(double z) const {
294 }
295 
296 double FM1DProfile1::computeExitFringe(double z) const {
298 }
299 
300 double FM1DProfile1::computeFringe(const std::vector<double> &coefs, double z) const {
301 
302  const size_t N = coefs.size();
303  double expSum = coefs.at(0);
304 
305  for (size_t i = 1; i < N; ++ i) {
306  expSum += std::pow(z, i) * coefs.at(i);
307  }
308 
309  return 1.0 / (1.0 + exp(expSum));
310 }
double entranceParameter1_m
Definition: FM1DProfile1.h:71
virtual bool getFieldstrength(const Vector_t &X, Vector_t &strength, Vector_t &info) const
double exitParameter3_m
Definition: FM1DProfile1.h:76
virtual void readMap()
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double exitParameter1_m
Definition: FM1DProfile1.h:74
DiffDirection
Definition: Fieldmap.h:54
double gapHeight_m
Enge function order for entry region.
Definition: FM1DProfile1.h:84
virtual void swap()
Tps< T > exp(const Tps< T > &x)
Exponential.
Definition: TpsMath.h:165
double exitParameter2_m
Definition: FM1DProfile1.h:75
void disableFieldmapWarning()
Definition: Fieldmap.cpp:610
double sBegin_m
Full gap height of field map.
Definition: FM1DProfile1.h:86
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition: Fieldmap.cpp:647
double computeEntranceFringe(double z) const
void noFieldmapWarning()
Definition: Fieldmap.cpp:618
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
double computeFringe(const std::vector< double > &coefs, double z) const
virtual void getInfo(Inform *)
std::vector< double > engeCoeffsExit_m
Definition: FM1DProfile1.h:80
virtual double getFrequency() const
int polyOrderEntry_m
Definition: FM1DProfile1.h:82
virtual double getFieldGap()
bool interpreteEOF(std::ifstream &in)
Definition: Fieldmap.cpp:547
#define INFOMSG(msg)
Definition: IpplInfo.h:397
virtual void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const
virtual void freeMap()
double entranceParameter2_m
Definition: FM1DProfile1.h:72
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
virtual ~FM1DProfile1()
double sEnd_m
Start of field map in s coordinates (m).
Definition: FM1DProfile1.h:87
virtual void setFieldGap(double gap)
std::string Filename_m
Definition: Fieldmap.h:110
MapType Type
Definition: Fieldmap.h:107
Inform & level3(Inform &inf)
Definition: Inform.cpp:47
double computeExitFringe(double z) const
virtual bool getFieldDerivative(const Vector_t &X, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
double entranceParameter3_m
Definition: FM1DProfile1.h:73
Definition: Inform.h:41
int polyOrderExit_m
Enge function order for entry region.
Definition: FM1DProfile1.h:83
virtual void setFrequency(double freq)
FM1DProfile1(std::string Filename)
Constructor with field map file name.
Definition: FM1DProfile1.cpp:9
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
std::vector< double > engeCoeffsEntry_m
Enge coefficients for map entry and exit regions.
Definition: FM1DProfile1.h:79