OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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
10_FM1DProfile1::_FM1DProfile1(const std::string& filename):
11 _Fieldmap(filename),
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
61 (inputFile,
62 tempString,
66
67 parsingPassed = parsingPassed &&
69 (inputFile,
73 tempInt,
74 false);
75
76 parsingPassed = parsingPassed &&
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
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
128
129FM1DProfile1 _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
167 tempString,
168 tempInt,
169 tempInt,
170 tempDouble);
172 tempDouble,
173 tempDouble,
174 tempDouble,
175 tempInt);
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
216
217bool _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}
240 double &/*xFinal*/,
241 double &/*yIni*/,
242 double &/*yFinal*/,
243 double &/*zIni*/,
244 double &/*zFinal*/) const {
245
246}
247
250
252 (*msg) << Filename_m
253 << " (1D Profile type 1)"
254 << endl;
255}
256
258 return 0.0;
259}
260
261void _FM1DProfile1::setFrequency(double /*freq*/)
262{}
263
264void _FM1DProfile1::get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
265 std::vector<double> &engeCoeffsExit) {
266 engeCoeffsEntry = engeCoeffsEntry_m;
267 engeCoeffsExit = engeCoeffsExit_m;
268
269}
270
271void _FM1DProfile1::get1DProfile1EntranceParam(double &entranceParameter1,
272 double &entranceParameter2,
273 double &entranceParameter3) {
274 entranceParameter1 = entranceParameter1_m;
275 entranceParameter2 = entranceParameter2_m;
276 entranceParameter3 = entranceParameter3_m;
277}
278
279void _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}
291
292 gapHeight_m = gap;
293
294}
295
299
300double _FM1DProfile1::computeExitFringe(double z) const {
302}
303
304double _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}
std::shared_ptr< _FM1DProfile1 > FM1DProfile1
@ T1DProfile1
Definition Fieldmap.h:23
DiffDirection
Definition Fieldmap.h:55
Tps< T > exp(const Tps< T > &x)
Exponential.
Definition TpsMath.h:165
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
bool interpreteEOF(std::ifstream &in)
Definition Fieldmap.cpp:555
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition Fieldmap.cpp:649
void disableFieldmapWarning()
Definition Fieldmap.cpp:610
void noFieldmapWarning()
Definition Fieldmap.cpp:618
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
std::string Filename_m
Definition Fieldmap.h:118
MapType Type
Definition Fieldmap.h:116
double computeExitFringe(double z) const
_FM1DProfile1(const std::string &filename)
Constructor with field map file name.
double computeEntranceFringe(double z) const
friend class _Fieldmap
End of field map in s coordinates (m).
virtual void freeMap()
double exitParameter2_m
virtual void getInfo(Inform *)
virtual bool getFieldDerivative(const Vector_t &X, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
double exitParameter3_m
virtual void readMap()
static FM1DProfile1 create(const std::string &filename)
double computeFringe(const std::vector< double > &coefs, double z) const
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
std::vector< double > engeCoeffsEntry_m
Enge coefficients for map entry and exit regions.
virtual ~_FM1DProfile1()
double entranceParameter1_m
double entranceParameter2_m
virtual void get1DProfile1ExitParam(double &exitParameter1, double &exitParameter2, double &exitParameter3)
double sBegin_m
Full gap height of field map.
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
double exitParameter1_m
std::vector< double > engeCoeffsExit_m
virtual bool getFieldstrength(const Vector_t &X, Vector_t &strength, Vector_t &info) const
virtual double getFrequency() const
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
virtual double getFieldGap()
virtual void setFrequency(double freq)
int polyOrderExit_m
Enge function order for entry region.
double gapHeight_m
Enge function order for entry region.
virtual void swap()
double sEnd_m
Start of field map in s coordinates (m).
virtual void setFieldGap(double gap)
double entranceParameter3_m
Vektor< double, 3 > Vector_t