8#include "gsl/gsl_fft_real.h"
19 if (fieldFile.good()) {
64 delete[] onAxisFieldP;
65 delete[] onAxisFieldPP;
66 delete[] onAxisFieldPPP;
93 std::vector<double> fieldComponents;
113 double& ,
double& ,
double& ,
double& ,
double& ,
141 std::vector<double> fourierCoefs,
double onAxisFieldP[],
double onAxisFieldPP[],
142 double onAxisFieldPPP[]) {
146 onAxisFieldP[zStepIndex] = 0.0;
147 onAxisFieldPP[zStepIndex] = 0.0;
148 onAxisFieldPPP[zStepIndex] = 0.0;
151 for (
unsigned int n = 1; n <
accuracy_m; ++n) {
153 double coskzn = cos(kz * n);
154 double sinkzn = sin(kz * n);
156 onAxisFieldP[zStepIndex] +=
158 * (-fourierCoefs.at(coefIndex) * sinkzn - fourierCoefs.at(coefIndex + 1) * coskzn);
160 double derivCoeff = pow(kn, 2.0);
161 onAxisFieldPP[zStepIndex] +=
163 * (-fourierCoefs.at(coefIndex) * coskzn + fourierCoefs.at(coefIndex + 1) * sinkzn);
165 onAxisFieldPPP[zStepIndex] +=
167 * (fourierCoefs.at(coefIndex) * sinkzn + fourierCoefs.at(coefIndex + 1) * coskzn);
176 std::vector<double> fieldComponents)
const {
177 double radiusSq = pow(R(0), 2.0) + pow(R(1), 2.0);
178 double transverseEFactor =
179 -fieldComponents.at(1) / 2.0 + radiusSq * fieldComponents.at(3) / 16.0;
181 E(0) += R(0) * transverseEFactor;
182 E(1) += R(1) * transverseEFactor;
183 E(2) += fieldComponents.at(0) - fieldComponents.at(2) * radiusSq / 4.0;
187 double z, std::vector<double>& fieldComponents)
const {
190 fieldComponents.push_back(
192 fieldComponents.push_back(
198 gsl_fft_real_wavetable* waveTable = gsl_fft_real_wavetable_alloc(totalSize);
199 gsl_fft_real_workspace* workSpace = gsl_fft_real_workspace_alloc(totalSize);
202 double* fieldDataReflected =
new double[totalSize];
208 gsl_fft_real_transform(fieldDataReflected, 1, totalSize, waveTable, workSpace);
210 std::vector<double> fourierCoefs;
211 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
212 for (
unsigned int coefIndex = 1; coefIndex + 1 < 2 *
accuracy_m; ++coefIndex)
213 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
215 delete[] fieldDataReflected;
216 gsl_fft_real_workspace_free(workSpace);
217 gsl_fft_real_wavetable_free(waveTable);
223 double onAxisFieldP[],
double onAxisFieldPP[],
double onAxisFieldPPP[]) {
231 z[zStepIndex] =
deltaZ_m * zStepIndex;
258 for (
auto fourierIt = fourierCoefs.begin(); fourierIt < fourierCoefs.end(); ++fourierIt)
266 if (std::abs(fieldData[dataIndex]) > maxEz)
267 maxEz = std::abs(fieldData[dataIndex]);
277 std::string tempString;
280 bool parsingPassed =
true;
285 fieldFile, tempString,
accuracy_m, tempString);
288 if (tempString !=
"TRUE" && tempString !=
"FALSE")
290 "FM1DElectroStatic_fast::readFileHeader",
291 "The third string on the first line of 1D field "
292 "maps has to be either TRUE or FALSE");
296 parsingPassed = parsingPassed
306 return parsingPassed;
310 std::string tempString;
312 getLine(fieldFile, tempString);
313 getLine(fieldFile, tempString);
314 getLine(fieldFile, tempString);
320 zSampling[zStepIndex] =
deltaZ_m * zStepIndex;
ippl::Vector< T, Dim > Vector_t
constexpr double two_pi
The value of.
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_spline * onAxisFieldPInterpolants_m
On axis field interpolation structure.
std::vector< double > computeFourierCoefficients(double fieldData[])
void computeFieldDerivatives(std::vector< double > fourierCoefs, double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
void normalizeField(double maxEz, std::vector< double > &fourierCoefs)
gsl_interp_accel * onAxisFieldPAccel_m
void computeFieldOnAxis(double z, std::vector< double > &fieldComponents) const
void stripFileHeader(std::ifstream &fieldFile)
unsigned int numberOfGridPoints_m
Field length.
virtual void getInfo(Inform *)
unsigned int accuracy_m
Field grid point spacing.
FM1DElectroStatic_fast(std::string aFilename)
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
double zEnd_m
Longitudinal start of field.
gsl_spline * onAxisFieldInterpolants_m
On axis field data.
virtual double getFrequency() const
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[])
virtual bool getFieldDerivative(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const
gsl_interp_accel * onAxisFieldPPPAccel_m
gsl_spline * onAxisFieldPPInterpolants_m
On axis field first derivative interpolation structure.
gsl_interp_accel * onAxisFieldAccel_m
On axis field third derivative interpolation structure.
double rEnd_m
Minimum radius of field.
virtual void setFrequency(double freq)
~FM1DElectroStatic_fast()
bool readFileHeader(std::ifstream &fieldFile)
double length_m
Longitudinal end of field.
double zBegin_m
Maximum radius of field.
bool checkFileData(std::ifstream &fieldFile, bool parsingPassed)
void computeFieldOffAxis(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, std::vector< double > fieldComponents) const
double deltaZ_m
Number of grid points in field input file.
gsl_spline * onAxisFieldPPPInterpolants_m
On axis field second derivative interpolation structure.
void computeInterpolationVectors(double onAxisFieldP[], double onAxisFieldPP[], double onAxisFieldPPP[])
gsl_interp_accel * onAxisFieldPPAccel_m
void prepareForMapCheck(std::vector< double > &fourierCoefs)