8#include "gsl/gsl_fft_real.h"
18 if (fieldFile.good()) {
63 delete[] onAxisFieldP;
64 delete[] onAxisFieldPP;
65 delete[] onAxisFieldPPP;
91 std::vector<double> fieldComponents;
112 double& ,
double& ,
double& ,
double& ,
double& ,
150 std::vector<double> fourierCoefs,
double onAxisFieldP[],
double onAxisFieldPP[],
151 double onAxisFieldPPP[]) {
155 onAxisFieldP[zStepIndex] = 0.0;
156 onAxisFieldPP[zStepIndex] = 0.0;
157 onAxisFieldPPP[zStepIndex] = 0.0;
160 for (
unsigned int n = 1; n <
accuracy_m; ++n) {
162 double coskzn = cos(kz * n);
163 double sinkzn = sin(kz * n);
165 onAxisFieldP[zStepIndex] +=
167 * (-fourierCoefs.at(coefIndex) * sinkzn - fourierCoefs.at(coefIndex + 1) * coskzn);
169 double derivCoeff = pow(kn, 2.0);
170 onAxisFieldPP[zStepIndex] +=
172 * (-fourierCoefs.at(coefIndex) * coskzn + fourierCoefs.at(coefIndex + 1) * sinkzn);
174 onAxisFieldPPP[zStepIndex] +=
176 * (fourierCoefs.at(coefIndex) * sinkzn + fourierCoefs.at(coefIndex + 1) * coskzn);
185 std::vector<double> fieldComponents)
const {
186 double radiusSq = pow(R(0), 2.0) + pow(R(1), 2.0);
187 double transverseEFactor =
189 - radiusSq * fieldComponents.at(3) / 16.0);
190 double transverseBFactor =
192 - radiusSq * fieldComponents.at(2) / 16.0)
195 E(0) += -R(0) * transverseEFactor;
196 E(1) += -R(1) * transverseEFactor;
199 - radiusSq * fieldComponents.at(2) / 4.0);
201 B(0) += -R(1) * transverseBFactor;
202 B(1) += R(0) * transverseBFactor;
208 fieldComponents.push_back(
210 fieldComponents.push_back(
216 gsl_fft_real_wavetable* waveTable = gsl_fft_real_wavetable_alloc(totalSize);
217 gsl_fft_real_workspace* workSpace = gsl_fft_real_workspace_alloc(totalSize);
220 double* fieldDataReflected =
new double[totalSize];
227 gsl_fft_real_transform(fieldDataReflected, 1, totalSize, waveTable, workSpace);
229 std::vector<double> fourierCoefs;
230 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
231 for (
unsigned int coefIndex = 1; coefIndex < 2 *
accuracy_m - 1; ++coefIndex)
232 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
234 delete[] fieldDataReflected;
235 gsl_fft_real_workspace_free(workSpace);
236 gsl_fft_real_wavetable_free(waveTable);
242 double onAxisFieldP[],
double onAxisFieldPP[],
double onAxisFieldPPP[]) {
250 z[zStepIndex] =
deltaZ_m * zStepIndex;
281 for (std::vector<double>::iterator fourierIterator = fourierCoefs.begin();
282 fourierIterator < fourierCoefs.end(); ++fourierIterator)
290 if (std::abs(fieldData[dataIndex]) > maxEz)
291 maxEz = std::abs(fieldData[dataIndex]);
301 std::ifstream& fieldFile, std::vector<std::pair<double, double>>& eZ) {
305 eZ.at(dataIndex).first = deltaZ * dataIndex;
307 if (std::abs(eZ.at(dataIndex).second) > maxEz)
308 maxEz = std::abs(eZ.at(dataIndex).second);
318 std::string tempString;
321 bool parsingPassed =
true;
326 fieldFile, tempString,
accuracy_m, tempString);
329 if (tempString !=
"TRUE" && tempString !=
"FALSE")
331 "FM1DDynamic_fast::readFileHeader",
332 "The third string on the first line of 1D field "
333 "maps has to be either TRUE or FALSE");
337 parsingPassed = parsingPassed
349 return parsingPassed;
357 eZ.at(dataIndex).second /= maxEz;
361 std::string tempString;
363 getLine(fieldFile, tempString);
364 getLine(fieldFile, tempString);
365 getLine(fieldFile, tempString);
366 getLine(fieldFile, tempString);
372 zSampling[zStepIndex] =
deltaZ_m * zStepIndex;
ippl::Vector< T, Dim > Vector_t
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)
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)
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
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 computeFieldOffAxis(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, std::vector< double > fieldComponents) const
void stripFileHeader(std::ifstream &fieldFile)
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
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[])
virtual bool getFieldstrength(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const
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[])
gsl_spline * onAxisFieldPPInterpolants_m
On axis field first derivative interpolation structure.
virtual bool getFieldDerivative(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const
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).