OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
FM1DProfile1.cpp
Go to the documentation of this file.
2#include "Fields/Fieldmap.hpp"
3#include "Physics/Physics.h"
4#include "Physics/Units.h"
6
7#include <fstream>
8#include <ios>
9
10FM1DProfile1::FM1DProfile1(std::string aFilename):
11 Fieldmap(aFilename),
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.
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 */
40 gapHeight_m = 0.02;
41
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,
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.
106
110
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
130
131 if(!engeCoeffsEntry_m.empty())
132 engeCoeffsEntry_m.clear();
133
134 if(!engeCoeffsExit_m.empty())
135 engeCoeffsExit_m.clear();
136
137 if(Filename_m == "1DPROFILE1-DEFAULT") {
138
139 engeCoeffsEntry_m.push_back(0.478959);
140 engeCoeffsEntry_m.push_back(1.911289);
141 engeCoeffsEntry_m.push_back(-1.185953);
142 engeCoeffsEntry_m.push_back(1.630554);
143 engeCoeffsEntry_m.push_back(-1.082657);
144 engeCoeffsEntry_m.push_back(0.318111);
145
146 engeCoeffsExit_m.push_back(0.478959);
147 engeCoeffsExit_m.push_back(1.911289);
148 engeCoeffsExit_m.push_back(-1.185953);
149 engeCoeffsExit_m.push_back(1.630554);
150 engeCoeffsExit_m.push_back(-1.082657);
151 engeCoeffsExit_m.push_back(0.31811);
152
153 } else {
154
155 std::ifstream inputFile(Filename_m.c_str());
156
157 int tempInt;
158 std::string tempString;
159 double tempDouble;
160
161 interpretLine<std::string, int, int, double>(inputFile,
162 tempString,
163 tempInt,
164 tempInt,
165 tempDouble);
166 interpretLine<double, double, double, int>(inputFile,
167 tempDouble,
168 tempDouble,
169 tempDouble,
170 tempInt);
171 interpretLine<double, double, double, int>(inputFile,
172 tempDouble,
173 tempDouble,
174 tempDouble,
175 tempInt);
176
177 for(int index = 0; index < polyOrderEntry_m + 1; index++) {
178 interpretLine<double>(inputFile, tempDouble);
179 engeCoeffsEntry_m.push_back(tempDouble);
180 }
181
182 for(int index = 0; index < polyOrderExit_m + 1; index++) {
183 interpretLine<double>(inputFile, tempDouble);
184 engeCoeffsExit_m.push_back(tempDouble);
185 }
186
187 inputFile.close();
188
189 INFOMSG(level3 << typeset_msg("read in fieldmap '" + Filename_m + "'", "info")
190 << "\n" << endl);
191
192 }
193
195 for (int index = 0; index < polyOrderEntry_m + 1; ++ index) {
196 if (index % 2 == 0) continue;
197 engeCoeffsEntry_m[index] *= -1;
198 }
199 }
200
202 for (int index = 0; index < polyOrderExit_m + 1; ++ index) {
203 if (index % 2 == 0) continue;
204 engeCoeffsExit_m[index] *= -1;
205 }
206 }
207}
208
210}
211
212bool FM1DProfile1::getFieldstrength(const Vector_t &/*R*/, Vector_t &/*E*/, Vector_t &/*B*/) const {
213
214 /*
215 * For this type of field map, the elements who use it calculate the field
216 * amplitude using the field map parameters.
217 */
218 return true;
219
220}
221
223 Vector_t &/*E*/,
224 Vector_t &/*B*/,
225 const DiffDirection &/*dir*/) const {
226 return false;
227}
228
230 double &sEnd) const {
231 sBegin = sBegin_m;
232 sEnd = sEnd_m;
233}
235 double &/*xFinal*/,
236 double &/*yIni*/,
237 double &/*yFinal*/,
238 double &/*zIni*/,
239 double &/*zFinal*/) const {
240
241}
242
244{}
245
247 (*msg) << Filename_m
248 << " (1D Profile type 1)"
249 << endl;
250}
251
253 return 0.0;
254}
255
256void FM1DProfile1::setFrequency(double /*freq*/)
257{}
258
259void FM1DProfile1::get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
260 std::vector<double> &engeCoeffsExit) {
261 engeCoeffsEntry = engeCoeffsEntry_m;
262 engeCoeffsExit = engeCoeffsExit_m;
263
264}
265
266void FM1DProfile1::get1DProfile1EntranceParam(double &entranceParameter1,
267 double &entranceParameter2,
268 double &entranceParameter3) {
269 entranceParameter1 = entranceParameter1_m;
270 entranceParameter2 = entranceParameter2_m;
271 entranceParameter3 = entranceParameter3_m;
272}
273
274void FM1DProfile1::get1DProfile1ExitParam(double &exitParameter1,
275 double &exitParameter2,
276 double &exitParameter3) {
277 exitParameter1 = exitParameter1_m;
278 exitParameter2 = exitParameter2_m;
279 exitParameter3 = exitParameter3_m;
280}
281
283 return gapHeight_m;
284}
286
287 gapHeight_m = gap;
288
289}
290
293}
294
295double FM1DProfile1::computeExitFringe(double z) const {
297}
298
299double FM1DProfile1::computeFringe(const std::vector<double> &coefs, double z) const {
300
301 const size_t N = coefs.size();
302 double expSum = coefs.at(0);
303
304 for (size_t i = 1; i < N; ++ i) {
305 expSum += std::pow(z, i) * coefs.at(i);
306 }
307
308 return 1.0 / (1.0 + exp(expSum));
309}
@ T1DProfile1
Definition: Fieldmap.h:22
DiffDirection
Definition: Fieldmap.h:54
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
Tps< T > exp(const Tps< T > &x)
Exponential.
Definition: TpsMath.h:165
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
Inform & level3(Inform &inf)
Definition: Inform.cpp:47
#define INFOMSG(msg)
Definition: IpplInfo.h:348
constexpr double cm2m
Definition: Units.h:35
MapType Type
Definition: Fieldmap.h:114
bool interpreteEOF(std::ifstream &in)
Definition: Fieldmap.cpp:558
void disableFieldmapWarning()
Definition: Fieldmap.cpp:613
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition: Fieldmap.cpp:652
std::string Filename_m
Definition: Fieldmap.h:117
void noFieldmapWarning()
Definition: Fieldmap.cpp:621
double entranceParameter2_m
Definition: FM1DProfile1.h:70
double entranceParameter3_m
Definition: FM1DProfile1.h:71
virtual void setFrequency(double freq)
double entranceParameter1_m
Definition: FM1DProfile1.h:69
double gapHeight_m
Enge function order for entry region.
Definition: FM1DProfile1.h:82
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
double computeExitFringe(double z) const
virtual void freeMap()
double computeFringe(const std::vector< double > &coefs, double z) const
virtual ~FM1DProfile1()
double exitParameter2_m
Definition: FM1DProfile1.h:73
double exitParameter1_m
Definition: FM1DProfile1.h:72
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
virtual double getFrequency() const
virtual bool getFieldDerivative(const Vector_t &X, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
int polyOrderEntry_m
Definition: FM1DProfile1.h:80
virtual double getFieldGap()
virtual void setFieldGap(double gap)
virtual void swap()
double exitParameter3_m
Definition: FM1DProfile1.h:74
virtual void readMap()
virtual void getInfo(Inform *)
double sEnd_m
Start of field map in s coordinates (m).
Definition: FM1DProfile1.h:85
FM1DProfile1(std::string Filename)
Constructor with field map file name.
double sBegin_m
Full gap height of field map.
Definition: FM1DProfile1.h:84
std::vector< double > engeCoeffsEntry_m
Enge coefficients for map entry and exit regions.
Definition: FM1DProfile1.h:77
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
int polyOrderExit_m
Enge function order for entry region.
Definition: FM1DProfile1.h:81
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
double computeEntranceFringe(double z) const
std::vector< double > engeCoeffsExit_m
Definition: FM1DProfile1.h:78
Definition: Inform.h:42