8#include "gsl/gsl_fft_real.h"
22 if (fieldFile.good()) {
66 onAxisFieldPP, onAxisFieldPPP);
72 delete [] onAxisFieldP;
73 delete [] onAxisFieldPP;
74 delete [] onAxisFieldPPP;
103 std::vector<double> fieldComponents;
128 double &,
double &)
const {}
135 <<
" (1D dynamic); zini= "
160 bool parsingPassed) {
164 parsingPassed = parsingPassed
165 && interpretLine<double>(fieldFile, tempDouble);
172 double onAxisFieldP[],
173 double onAxisFieldPP[],
174 double onAxisFieldPPP[]) {
180 onAxisFieldP[zStepIndex] = 0.0;
181 onAxisFieldPP[zStepIndex] = 0.0;
182 onAxisFieldPPP[zStepIndex] = 0.0;
188 double coskzn =
cos(kz *
n);
189 double sinkzn =
sin(kz *
n);
191 onAxisFieldP[zStepIndex] += kn * (-fourierCoefs.at(coefIndex) * sinkzn
192 - fourierCoefs.at(coefIndex + 1) * coskzn);
194 double derivCoeff =
pow(kn, 2.0);
195 onAxisFieldPP[zStepIndex] += derivCoeff * (-fourierCoefs.at(coefIndex) * coskzn
196 + fourierCoefs.at(coefIndex + 1) * sinkzn);
198 onAxisFieldPPP[zStepIndex] += derivCoeff * (fourierCoefs.at(coefIndex) * sinkzn
199 + fourierCoefs.at(coefIndex + 1) * coskzn);
210 std::vector<double> fieldComponents)
const {
212 double radiusSq =
pow(
R(0), 2.0) +
pow(
R(1), 2.0);
213 double transverseEFactor = (fieldComponents.at(1)
215 - radiusSq * fieldComponents.at(3) / 16.0);
216 double transverseBFactor = ((fieldComponents.at(0)
218 - radiusSq * fieldComponents.at(2) / 16.0)
221 E(0) += -
R(0) * transverseEFactor;
222 E(1) += -
R(1) * transverseEFactor;
224 - radiusSq * fieldComponents.at(2) / 4.0);
226 B(0) += -
R(1) * transverseBFactor;
227 B(1) +=
R(0) * transverseBFactor;
232 std::vector<double> &fieldComponents)
247 gsl_fft_real_wavetable *waveTable = gsl_fft_real_wavetable_alloc(totalSize);
248 gsl_fft_real_workspace *workSpace = gsl_fft_real_workspace_alloc(totalSize);
251 double *fieldDataReflected =
new double[totalSize];
254 = fieldData[dataIndex];
257 = fieldData[dataIndex];
260 gsl_fft_real_transform(fieldDataReflected, 1,
262 waveTable, workSpace);
264 std::vector<double> fourierCoefs;
265 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
266 for (
unsigned int coefIndex = 1; coefIndex < 2 *
accuracy_m - 1; ++ coefIndex)
267 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
269 delete [] fieldDataReflected;
270 gsl_fft_real_workspace_free(workSpace);
271 gsl_fft_real_wavetable_free(waveTable);
278 double onAxisFieldPP[],
279 double onAxisFieldPPP[]) {
292 z[zStepIndex] =
deltaZ_m * zStepIndex;
325 std::vector<double> &fourierCoefs) {
331 fourierIterator < fourierCoefs.end(); ++ fourierIterator)
337 double fieldData[]) {
341 interpretLine<double>(fieldFile, fieldData[dataIndex]);
342 if (
std::abs(fieldData[dataIndex]) > maxEz)
343 maxEz =
std::abs(fieldData[dataIndex]);
353 std::vector<std::pair<double, double>> &eZ) {
358 eZ.at(dataIndex).first = deltaZ * dataIndex;
359 interpretLine<double>(fieldFile, eZ.at(dataIndex).second);
360 if (
std::abs(eZ.at(dataIndex).second) > maxEz)
361 maxEz =
std::abs(eZ.at(dataIndex).second);
372 std::string tempString;
375 bool parsingPassed =
true;
377 parsingPassed = interpretLine<std::string, unsigned int>(fieldFile,
381 parsingPassed = interpretLine<std::string, unsigned int, std::string>(fieldFile,
387 if (tempString !=
"TRUE" &&
388 tempString !=
"FALSE")
390 "The third string on the first line of 1D field "
391 "maps has to be either TRUE or FALSE");
395 parsingPassed = parsingPassed &&
396 interpretLine<double, double, unsigned int>(fieldFile,
400 parsingPassed = parsingPassed &&
402 parsingPassed = parsingPassed &&
403 interpretLine<double, double, int>(fieldFile,
413 return parsingPassed;
417 std::vector<std::pair<double, double>> &eZ) {
421 eZ.at(dataIndex).second /= maxEz;
426 std::string tempString;
428 getLine(fieldFile, tempString);
429 getLine(fieldFile, tempString);
430 getLine(fieldFile, tempString);
431 getLine(fieldFile, tempString);
437 zSampling[zStepIndex] =
deltaZ_m * zStepIndex;
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sin(const Tps< T > &x)
Sine.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
Inform & level3(Inform &inf)
constexpr double two_pi
The value of.
constexpr double e
The value of.
constexpr double c
The velocity of light in m/s.
constexpr double pi
The value of.
constexpr double Vpm2MVpm
std::string::iterator iterator
std::string toUpper(const std::string &str)
bool interpreteEOF(std::ifstream &in)
void checkMap(unsigned int accuracy, std::pair< double, double > fieldDimensions, double deltaZ, const std::vector< double > &fourierCoefficients, gsl_spline *splineCoefficients, gsl_interp_accel *splineAccelerator)
void disableFieldmapWarning()
static std::string typeset_msg(const std::string &msg, const std::string &title)
void getLine(std::ifstream &in, std::string &buffer)
gsl_interp_accel * onAxisFieldAccel_m
On axis field third derivative interpolation structure.
FM1DDynamic_fast(std::string aFilename)
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
gsl_spline * onAxisFieldPInterpolants_m
On axis field interpolation structure.
void stripFileHeader(std::ifstream &fieldFile)
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
gsl_spline * onAxisFieldInterpolants_m
On axis field data.
double rEnd_m
Minimum radius of field.
double zBegin_m
Maximum radius of field.
gsl_interp_accel * onAxisFieldPPPAccel_m
void computeFieldOffAxis(const Vector_t &R, Vector_t &E, Vector_t &B, std::vector< double > fieldComponents) const
double zEnd_m
Longitudinal start of field.
void computeFieldOnAxis(double z, std::vector< double > &fieldComponents) const
virtual void setFrequency(double freq)
gsl_interp_accel * onAxisFieldPPAccel_m
std::vector< double > computeFourierCoefficients(double fieldData[])
double length_m
Longitudinal end of field.
gsl_spline * onAxisFieldPPPInterpolants_m
On axis field second derivative interpolation structure.
virtual double getFrequency() const
void normalizeField(double maxEz, std::vector< double > &fourierCoefs)
void scaleField(double maxEz, std::vector< std::pair< double, double > > &eZ)
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &eZ)
void computeInterpolationVectors(double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
double readFileData(std::ifstream &fieldFile, double fieldData[])
void prepareForMapCheck(std::vector< double > &fourierCoefs)
unsigned int numberOfGridPoints_m
Field length.
void computeFieldDerivatives(std::vector< double > fourierCoefs, double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
gsl_spline * onAxisFieldPPInterpolants_m
On axis field first derivative interpolation structure.
bool checkFileData(std::ifstream &fieldFile, bool parsingPassed)
bool readFileHeader(std::ifstream &fieldFile)
virtual void getInfo(Inform *)
gsl_interp_accel * onAxisFieldPAccel_m
unsigned int accuracy_m
Field grid point spacing.
double deltaZ_m
Number of grid points in field input file.
double rBegin_m
2 Pi divided by the field RF wavelength squared.
double twoPiOverLambdaSq_m
Field angular frequency (Hz).