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