7 #include "gsl/gsl_fft_real.h"
21 if (fieldFile.good()) {
65 onAxisFieldPP, onAxisFieldPPP);
71 delete [] onAxisFieldP;
72 delete [] onAxisFieldPP;
73 delete [] onAxisFieldPPP;
102 std::vector<double> fieldComponents;
121 double &rBegin,
double &rEnd)
const {
129 double &yIni,
double &yFinal,
130 double &zIni,
double &zFinal)
const {}
137 <<
" (1D dynamic); zini= "
162 bool parsingPassed) {
166 parsingPassed = parsingPassed
167 && interpreteLine<double>(fieldFile, tempDouble);
174 double onAxisFieldP[],
175 double onAxisFieldPP[],
176 double onAxisFieldPPP[]) {
182 onAxisFieldP[zStepIndex] = 0.0;
183 onAxisFieldPP[zStepIndex] = 0.0;
184 onAxisFieldPPP[zStepIndex] = 0.0;
190 double coskzn =
cos(kz *
n);
191 double sinkzn =
sin(kz * n);
193 onAxisFieldP[zStepIndex] += kn * (-fourierCoefs.at(coefIndex) * sinkzn
194 - fourierCoefs.at(coefIndex + 1) * coskzn);
196 double derivCoeff =
pow(kn, 2.0);
197 onAxisFieldPP[zStepIndex] += derivCoeff * (-fourierCoefs.at(coefIndex) * coskzn
198 + fourierCoefs.at(coefIndex + 1) * sinkzn);
200 onAxisFieldPPP[zStepIndex] += derivCoeff * (fourierCoefs.at(coefIndex) * sinkzn
201 + fourierCoefs.at(coefIndex + 1) * coskzn);
212 std::vector<double> fieldComponents)
const {
214 double radiusSq =
pow(
R(0), 2.0) +
pow(
R(1), 2.0);
215 double transverseEFactor = (fieldComponents.at(1)
217 - radiusSq * fieldComponents.at(3) / 16.0);
218 double transverseBFactor = ((fieldComponents.at(0)
220 - radiusSq * fieldComponents.at(2) / 16.0)
223 E(0) += -
R(0) * transverseEFactor;
224 E(1) += -
R(1) * transverseEFactor;
226 - radiusSq * fieldComponents.at(2) / 4.0);
228 B(0) += -
R(1) * transverseBFactor;
229 B(1) +=
R(0) * transverseBFactor;
234 std::vector<double> &fieldComponents)
249 gsl_fft_real_wavetable *waveTable = gsl_fft_real_wavetable_alloc(totalSize);
250 gsl_fft_real_workspace *workSpace = gsl_fft_real_workspace_alloc(totalSize);
253 double *fieldDataReflected =
new double[totalSize];
255 fieldDataReflected[numberOfGridPoints_m - 1 + dataIndex]
256 = fieldData[dataIndex];
258 fieldDataReflected[numberOfGridPoints_m - 1 - dataIndex]
259 = fieldData[dataIndex];
262 gsl_fft_real_transform(fieldDataReflected, 1,
264 waveTable, workSpace);
266 std::vector<double> fourierCoefs;
267 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
268 for (
unsigned int coefIndex = 1; coefIndex < 2 *
accuracy_m - 1; ++ coefIndex)
269 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
271 delete [] fieldDataReflected;
272 gsl_fft_real_workspace_free(workSpace);
273 gsl_fft_real_wavetable_free(waveTable);
280 double onAxisFieldPP[],
281 double onAxisFieldPPP[]) {
294 z[zStepIndex] =
deltaZ_m * zStepIndex;
298 onAxisFieldP, numberOfGridPoints_m);
300 onAxisFieldPP, numberOfGridPoints_m);
302 onAxisFieldPPP, numberOfGridPoints_m);
327 std::vector<double> &fourierCoefs) {
333 fourierIterator < fourierCoefs.end(); ++ fourierIterator)
334 *fourierIterator *= 1.0e6 / maxEz;
339 double fieldData[]) {
343 interpreteLine<double>(fieldFile, fieldData[dataIndex]);
344 if (
std::abs(fieldData[dataIndex]) > maxEz)
345 maxEz =
std::abs(fieldData[dataIndex]);
355 std::vector<std::pair<double, double>> &eZ) {
360 eZ.at(dataIndex).first = deltaZ * dataIndex;
361 interpreteLine<double>(fieldFile, eZ.at(dataIndex).second);
362 if (
std::abs(eZ.at(dataIndex).second) > maxEz)
363 maxEz =
std::abs(eZ.at(dataIndex).second);
374 std::string tempString;
377 bool parsingPassed =
true;
379 parsingPassed = interpreteLine<std::string, unsigned int>(fieldFile,
383 parsingPassed = interpreteLine<std::string, unsigned int, std::string>(fieldFile,
389 if (tempString !=
"TRUE" &&
390 tempString !=
"FALSE")
392 "The third string on the first line of 1D field "
393 "maps has to be either TRUE or FALSE");
397 parsingPassed = parsingPassed &&
398 interpreteLine<double, double, unsigned int>(fieldFile,
402 parsingPassed = parsingPassed &&
404 parsingPassed = parsingPassed &&
405 interpreteLine<double, double, int>(fieldFile,
415 return parsingPassed;
419 std::vector<std::pair<double, double>> &eZ) {
423 eZ.at(dataIndex).second /= maxEz;
428 std::string tempString;
430 getLine(fieldFile, tempString);
431 getLine(fieldFile, tempString);
432 getLine(fieldFile, tempString);
433 getLine(fieldFile, tempString);
439 zSampling[zStepIndex] =
deltaZ_m * zStepIndex;
gsl_interp_accel * onAxisFieldPPPAccel_m
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
virtual void getInfo(Inform *)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of .
virtual void setFrequency(double freq)
void stripFileHeader(std::ifstream &fieldFile)
double zBegin_m
Maximum radius of field.
Tps< T > sin(const Tps< T > &x)
Sine.
double readFileData(std::ifstream &fieldFile, double fieldData[])
constexpr double two_pi
The value of .
void prepareForMapCheck(std::vector< double > &fourierCoefs)
std::string toUpper(const std::string &str)
void disableFieldmapWarning()
FM1DDynamic_fast(std::string aFilename)
static std::string typeset_msg(const std::string &msg, const std::string &title)
virtual void getOnaxisEz(std::vector< std::pair< double, double >> &eZ)
double deltaZ_m
Number of grid points in field input file.
void scaleField(double maxEz, std::vector< std::pair< double, double >> &eZ)
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
bool checkFileData(std::ifstream &fieldFile, bool parsingPassed)
constexpr double pi
The value of .
unsigned int accuracy_m
Field grid point spacing.
gsl_interp_accel * onAxisFieldAccel_m
On axis field third derivative interpolation structure.
unsigned int numberOfGridPoints_m
Field length.
constexpr double c
The velocity of light in m/s.
bool interpreteEOF(std::ifstream &in)
double twoPiOverLambdaSq_m
Field angular frequency (Hz).
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
void computeInterpolationVectors(double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
double rBegin_m
2 Pi divided by the field RF wavelength squared.
double length_m
Longitudinal end of field.
void computeFieldOffAxis(const Vector_t &R, Vector_t &E, Vector_t &B, std::vector< double > fieldComponents) const
gsl_spline * onAxisFieldInterpolants_m
On axis field data.
Tps< T > cos(const Tps< T > &x)
Cosine.
double zEnd_m
Longitudinal start of field.
void getLine(std::ifstream &in, std::string &buffer)
gsl_spline * onAxisFieldPPInterpolants_m
On axis field first derivative interpolation structure.
gsl_interp_accel * onAxisFieldPPAccel_m
gsl_spline * onAxisFieldPPPInterpolants_m
On axis field second derivative interpolation structure.
double rEnd_m
Minimum radius of field.
void computeFieldOnAxis(double z, std::vector< double > &fieldComponents) const
gsl_interp_accel * onAxisFieldPAccel_m
Inform & level3(Inform &inf)
std::string::iterator iterator
virtual double getFrequency() const
void checkMap(unsigned int accuracy, std::pair< double, double > fieldDimensions, double deltaZ, const std::vector< double > &fourierCoefficients, gsl_spline *splineCoefficients, gsl_interp_accel *splineAccelerator)
gsl_spline * onAxisFieldPInterpolants_m
On axis field interpolation structure.
bool readFileHeader(std::ifstream &fieldFile)
std::vector< double > computeFourierCoefficients(double fieldData[])
void normalizeField(double maxEz, std::vector< double > &fourierCoefs)
void computeFieldDerivatives(std::vector< double > fourierCoefs, double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
Inform & endl(Inform &inf)
virtual void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const