OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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),
20 gapHeight_m(0.02),
21 sBegin_m(0.0),
22 sEnd_m(0.0) {
23 // Read file header information. Set field type.
25
26 // Read file. Check if we are using the default field profile.
27 if (Filename_m == "1DPROFILE1-DEFAULT") {
28 /*
29 * Use default field profile coefficients:
30 *
31 * polyOrderEntry_m = 5
32 * polyOrderExit_m = 5
33 * gapHeight_m = 0.02 m
34 *
35 */
38 gapHeight_m = 0.02;
39
43
44 exitParameter1_m = -0.1;
45 exitParameter2_m = 0.0;
46 exitParameter3_m = 0.1;
47
48 } else {
49 std::ifstream inputFile(Filename_m.c_str());
50
51 if (inputFile.good()) {
52 int tempInt = 0;
53 std::string tempString;
54 double tempDouble = 0.0;
55
57 inputFile, tempString, polyOrderEntry_m, polyOrderExit_m, gapHeight_m);
58
59 parsingPassed = parsingPassed
62 entranceParameter3_m, tempInt, false);
63
64 parsingPassed =
65 parsingPassed
68
69 for (int index = 0; (index < polyOrderEntry_m + polyOrderExit_m + 2) && parsingPassed;
70 index++)
71 parsingPassed = parsingPassed && interpretLine<double>(inputFile, tempDouble);
72
73 parsingPassed = parsingPassed && interpreteEOF(inputFile);
74
75 inputFile.close();
76
77 if (!parsingPassed) {
79 sBegin_m = 0.0;
80 sEnd_m = sBegin_m - 1.0e-3;
81
82 } else {
83 // Convert from cm to m. Make sure gap is positive.
87
91
92 gapHeight_m = std::abs(gapHeight_m / 100.0);
93 }
94
95 } else {
96 // No field map file or field map file is somehow flawed.
98 sBegin_m = 0.0;
99 sEnd_m = sBegin_m - 1.0e-3;
100 }
101 }
102}
103
106
108 if (!engeCoeffsEntry_m.empty())
109 engeCoeffsEntry_m.clear();
110
111 if (!engeCoeffsExit_m.empty())
112 engeCoeffsExit_m.clear();
113
114 if (Filename_m == "1DPROFILE1-DEFAULT") {
115 engeCoeffsEntry_m.push_back(0.478959);
116 engeCoeffsEntry_m.push_back(1.911289);
117 engeCoeffsEntry_m.push_back(-1.185953);
118 engeCoeffsEntry_m.push_back(1.630554);
119 engeCoeffsEntry_m.push_back(-1.082657);
120 engeCoeffsEntry_m.push_back(0.318111);
121
122 engeCoeffsExit_m.push_back(0.478959);
123 engeCoeffsExit_m.push_back(1.911289);
124 engeCoeffsExit_m.push_back(-1.185953);
125 engeCoeffsExit_m.push_back(1.630554);
126 engeCoeffsExit_m.push_back(-1.082657);
127 engeCoeffsExit_m.push_back(0.31811);
128
129 } else {
130 std::ifstream inputFile(Filename_m.c_str());
131
132 int tempInt;
133 std::string tempString;
134 double tempDouble;
135
137 inputFile, tempString, tempInt, tempInt, tempDouble);
139 inputFile, tempDouble, tempDouble, tempDouble, tempInt);
141 inputFile, tempDouble, tempDouble, tempDouble, tempInt);
142
143 for (int index = 0; index < polyOrderEntry_m + 1; index++) {
144 interpretLine<double>(inputFile, tempDouble);
145 engeCoeffsEntry_m.push_back(tempDouble);
146 }
147
148 for (int index = 0; index < polyOrderExit_m + 1; index++) {
149 interpretLine<double>(inputFile, tempDouble);
150 engeCoeffsExit_m.push_back(tempDouble);
151 }
152
153 inputFile.close();
154
155 *ippl::Info << level3 << typeset_msg("read in fieldmap '" + Filename_m + "'", "info")
156 << "\n"
157 << endl;
158 }
159
161 for (int index = 0; index < polyOrderEntry_m + 1; ++index) {
162 if (index % 2 == 0)
163 continue;
164 engeCoeffsEntry_m[index] *= -1;
165 }
166 }
167
169 for (int index = 0; index < polyOrderExit_m + 1; ++index) {
170 if (index % 2 == 0)
171 continue;
172 engeCoeffsExit_m[index] *= -1;
173 }
174 }
175}
176
179
181 const Vector_t<double, 3>& /*R*/, Vector_t<double, 3>& /*E*/,
182 Vector_t<double, 3>& /*B*/) const {
183 /*
184 * For this type of field map, the elements who use it calculate the field
185 * amplitude using the field map parameters.
186 */
187 return true;
188}
189
192 const DiffDirection& /*dir*/) const {
193 return false;
194}
195
196void FM1DProfile1::getFieldDimensions(double& sBegin, double& sEnd) const {
197 sBegin = sBegin_m;
198 sEnd = sEnd_m;
199}
201 double& /*xIni*/, double& /*xFinal*/, double& /*yIni*/, double& /*yFinal*/, double& /*zIni*/,
202 double& /*zFinal*/) const {
203}
204
206}
207
208void FM1DProfile1::getInfo(Inform* msg) {
209 (*msg) << Filename_m << " (1D Profile type 1)" << endl;
210}
211
213 return 0.0;
214}
215
216void FM1DProfile1::setFrequency(double /*freq*/) {
217}
218
220 std::vector<double>& engeCoeffsEntry, std::vector<double>& engeCoeffsExit) {
221 engeCoeffsEntry = engeCoeffsEntry_m;
222 engeCoeffsExit = engeCoeffsExit_m;
223}
224
226 double& entranceParameter1, double& entranceParameter2, double& entranceParameter3) {
227 entranceParameter1 = entranceParameter1_m;
228 entranceParameter2 = entranceParameter2_m;
229 entranceParameter3 = entranceParameter3_m;
230}
231
233 double& exitParameter1, double& exitParameter2, double& exitParameter3) {
234 exitParameter1 = exitParameter1_m;
235 exitParameter2 = exitParameter2_m;
236 exitParameter3 = exitParameter3_m;
237}
238
240 return gapHeight_m;
241}
243 gapHeight_m = gap;
244}
245
249
250double FM1DProfile1::computeExitFringe(double z) const {
252}
253
254double FM1DProfile1::computeFringe(const std::vector<double>& coefs, double z) const {
255 const size_t N = coefs.size();
256 double expSum = coefs.at(0);
257
258 for (size_t i = 1; i < N; ++i) {
259 expSum += std::pow(z, i) * coefs.at(i);
260 }
261
262 return 1.0 / (1.0 + exp(expSum));
263}
ippl::Vector< T, Dim > Vector_t
@ T1DProfile1
Definition Fieldmap.h:23
DiffDirection
Definition Fieldmap.h:55
constexpr double cm2m
Definition Units.h:35
MapType Type
Definition Fieldmap.h:118
bool interpreteEOF(std::ifstream &in)
Definition Fieldmap.cpp:516
void disableFieldmapWarning()
Definition Fieldmap.cpp:569
static std::string typeset_msg(const std::string &msg, const std::string &title)
Definition Fieldmap.cpp:607
std::string Filename_m
Definition Fieldmap.h:120
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
void noFieldmapWarning()
Definition Fieldmap.cpp:576
double entranceParameter2_m
double entranceParameter3_m
virtual void setFrequency(double freq)
double entranceParameter1_m
double gapHeight_m
Enge function order for entry region.
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
double exitParameter1_m
virtual void get1DProfile1EngeCoeffs(std::vector< double > &engeCoeffsEntry, std::vector< double > &engeCoeffsExit)
friend class Fieldmap
End of field map in s coordinates (m).
virtual double getFrequency() const
virtual bool getFieldDerivative(const Vector_t< double, 3 > &X, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const
virtual double getFieldGap()
virtual void setFieldGap(double gap)
virtual bool getFieldstrength(const Vector_t< double, 3 > &X, Vector_t< double, 3 > &strength, Vector_t< double, 3 > &info) const
virtual void swap()
double exitParameter3_m
virtual void readMap()
virtual void getInfo(Inform *)
double sEnd_m
Start of field map in s coordinates (m).
FM1DProfile1(std::string Filename)
Constructor with field map file name.
double sBegin_m
Full gap height of field map.
std::vector< double > engeCoeffsEntry_m
Enge coefficients for map entry and exit regions.
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
int polyOrderExit_m
Enge function order for entry region.
virtual void get1DProfile1EntranceParam(double &entranceParameter1, double &entranceParameter2, double &entranceParameter3)
double computeEntranceFringe(double z) const
std::vector< double > engeCoeffsExit_m