8#include "gsl/gsl_fft_real.h"
22 if (fieldFile.good()) {
70 onAxisFieldPP, onAxisFieldPPP);
76 delete [] onAxisFieldP;
77 delete [] onAxisFieldPP;
78 delete [] onAxisFieldPPP;
104 std::vector<double> fieldComponents;
129 double &,
double &)
const {}
136 <<
" (1D dynamic); zini= "
161 bool parsingPassed) {
165 parsingPassed = parsingPassed
173 double onAxisFieldP[],
174 double onAxisFieldPP[],
175 double onAxisFieldPPP[]) {
181 onAxisFieldP[zStepIndex] = 0.0;
182 onAxisFieldPP[zStepIndex] = 0.0;
183 onAxisFieldPPP[zStepIndex] = 0.0;
186 for (
unsigned int n = 1; n <
accuracy_m; ++ n) {
189 double coskzn =
cos(kz * n);
190 double sinkzn =
sin(kz * n);
192 onAxisFieldP[zStepIndex] += kn * (-fourierCoefs.at(coefIndex) * sinkzn
193 - fourierCoefs.at(coefIndex + 1) * coskzn);
195 double derivCoeff =
pow(kn, 2.0);
196 onAxisFieldPP[zStepIndex] += derivCoeff * (-fourierCoefs.at(coefIndex) * coskzn
197 + fourierCoefs.at(coefIndex + 1) * sinkzn);
199 onAxisFieldPPP[zStepIndex] += derivCoeff * (fourierCoefs.at(coefIndex) * sinkzn
200 + fourierCoefs.at(coefIndex + 1) * coskzn);
211 std::vector<double> fieldComponents)
const {
213 double radiusSq =
pow(R(0), 2.0) +
pow(R(1), 2.0);
214 double transverseEFactor = (fieldComponents.at(1)
216 - radiusSq * fieldComponents.at(3) / 16.0);
217 double transverseBFactor = ((fieldComponents.at(0)
219 - radiusSq * fieldComponents.at(2) / 16.0)
222 E(0) += - R(0) * transverseEFactor;
223 E(1) += - R(1) * transverseEFactor;
225 - radiusSq * fieldComponents.at(2) / 4.0);
227 B(0) += - R(1) * transverseBFactor;
228 B(1) += R(0) * transverseBFactor;
233 std::vector<double> &fieldComponents)
248 gsl_fft_real_wavetable *waveTable = gsl_fft_real_wavetable_alloc(totalSize);
249 gsl_fft_real_workspace *workSpace = gsl_fft_real_workspace_alloc(totalSize);
252 double *fieldDataReflected =
new double[totalSize];
255 = fieldData[dataIndex];
258 = fieldData[dataIndex];
261 gsl_fft_real_transform(fieldDataReflected, 1,
263 waveTable, workSpace);
265 std::vector<double> fourierCoefs;
266 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
267 for (
unsigned int coefIndex = 1; coefIndex < 2 *
accuracy_m - 1; ++ coefIndex)
268 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
270 delete [] fieldDataReflected;
271 gsl_fft_real_workspace_free(workSpace);
272 gsl_fft_real_wavetable_free(waveTable);
279 double onAxisFieldPP[],
280 double onAxisFieldPPP[]) {
293 z[zStepIndex] =
deltaZ_m * zStepIndex;
326 std::vector<double> &fourierCoefs) {
331 for (std::vector<double>::iterator fourierIterator = fourierCoefs.begin();
332 fourierIterator < fourierCoefs.end(); ++ fourierIterator)
338 double fieldData[]) {
343 if (std::abs(fieldData[dataIndex]) > maxEz)
344 maxEz = std::abs(fieldData[dataIndex]);
354 std::vector<std::pair<double, double>> &eZ) {
359 eZ.at(dataIndex).first = deltaZ * dataIndex;
361 if (std::abs(eZ.at(dataIndex).second) > maxEz)
362 maxEz = std::abs(eZ.at(dataIndex).second);
373 std::string tempString;
376 bool parsingPassed =
true;
388 if (tempString !=
"TRUE" &&
389 tempString !=
"FALSE")
391 "The third string on the first line of 1D field "
392 "maps has to be either TRUE or FALSE");
396 parsingPassed = parsingPassed &&
401 parsingPassed = parsingPassed &&
403 parsingPassed = parsingPassed &&
414 return parsingPassed;
418 std::vector<std::pair<double, double>> &eZ) {
422 eZ.at(dataIndex).second /= maxEz;
427 std::string tempString;
429 getLine(fieldFile, tempString);
430 getLine(fieldFile, tempString);
431 getLine(fieldFile, tempString);
432 getLine(fieldFile, tempString);
438 zSampling[zStepIndex] =
deltaZ_m * zStepIndex;
std::shared_ptr< _FM1DDynamic_fast > FM1DDynamic_fast
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.
Inform & endl(Inform &inf)
constexpr double two_pi
The value of.
constexpr double c
The velocity of light in m/s.
constexpr double pi
The value of.
constexpr double Vpm2MVpm
std::string toUpper(const std::string &str)
bool interpreteEOF(std::ifstream &in)
static std::string typeset_msg(const std::string &msg, const std::string &title)
void disableFieldmapWarning()
void getLine(std::ifstream &in, std::string &buffer)
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
void checkMap(unsigned int accuracy, std::pair< double, double > fieldDimensions, double deltaZ, const std::vector< double > &fourierCoefficients, gsl_spline *splineCoefficients, gsl_interp_accel *splineAccelerator)
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
double length_m
Longitudinal end of field.
virtual void getOnaxisEz(std::vector< std::pair< double, double > > &eZ)
void scaleField(double maxEz, std::vector< std::pair< double, double > > &eZ)
double twoPiOverLambdaSq_m
Field angular frequency (Hz).
static FM1DDynamic_fast create(const std::string &filename)
void computeFieldOffAxis(const Vector_t &R, Vector_t &E, Vector_t &B, std::vector< double > fieldComponents) const
gsl_interp_accel * onAxisFieldAccel_m
On axis field third derivative interpolation structure.
double rEnd_m
Minimum radius of field.
void prepareForMapCheck(std::vector< double > &fourierCoefs)
virtual double getFrequency() const
_FM1DDynamic_fast(const std::string &filename)
void computeInterpolationVectors(double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
double deltaZ_m
Number of grid points in field input file.
double zEnd_m
Longitudinal start of field.
gsl_spline * onAxisFieldPInterpolants_m
On axis field interpolation structure.
std::vector< double > computeFourierCoefficients(double fieldData[])
unsigned int accuracy_m
Field grid point spacing.
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
virtual void setFrequency(double freq)
gsl_spline * onAxisFieldPPInterpolants_m
On axis field first derivative interpolation structure.
bool checkFileData(std::ifstream &fieldFile, bool parsingPassed)
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
gsl_interp_accel * onAxisFieldPAccel_m
virtual ~_FM1DDynamic_fast()
bool readFileHeader(std::ifstream &fieldFile)
gsl_spline * onAxisFieldPPPInterpolants_m
On axis field second derivative interpolation structure.
void computeFieldOnAxis(double z, std::vector< double > &fieldComponents) const
double rBegin_m
2 Pi divided by the field RF wavelength squared.
gsl_interp_accel * onAxisFieldPPAccel_m
void normalizeField(double maxEz, std::vector< double > &fourierCoefs)
gsl_interp_accel * onAxisFieldPPPAccel_m
virtual void getInfo(Inform *)
gsl_spline * onAxisFieldInterpolants_m
On axis field data.
double zBegin_m
Maximum radius of field.
double readFileData(std::ifstream &fieldFile, double fieldData[])
unsigned int numberOfGridPoints_m
Field length.
void computeFieldDerivatives(std::vector< double > fourierCoefs, double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
void stripFileHeader(std::ifstream &fieldFile)
Vektor< double, 3 > Vector_t