8#include "gsl/gsl_fft_real.h"
22 if (fieldFile.good()) {
58 std::vector<double> fourierCoefs
66 onAxisFieldPP, onAxisFieldPPP);
72 delete [] onAxisFieldP;
73 delete [] onAxisFieldPP;
74 delete [] onAxisFieldPPP;
103 std::vector<double> fieldComponents;
129 double &,
double &)
const {}
136 <<
" (1D electrotostatic); zini= "
149 bool parsingPassed) {
153 parsingPassed = parsingPassed
154 && interpretLine<double>(fieldFile, tempDouble);
161 double onAxisFieldP[],
162 double onAxisFieldPP[],
163 double onAxisFieldPPP[]) {
169 onAxisFieldP[zStepIndex] = 0.0;
170 onAxisFieldPP[zStepIndex] = 0.0;
171 onAxisFieldPPP[zStepIndex] = 0.0;
177 double coskzn =
cos(kz *
n);
178 double sinkzn =
sin(kz *
n);
180 onAxisFieldP[zStepIndex] += kn * (-fourierCoefs.at(coefIndex) * sinkzn
181 - fourierCoefs.at(coefIndex + 1) * coskzn);
183 double derivCoeff =
pow(kn, 2.0);
184 onAxisFieldPP[zStepIndex] += derivCoeff * (-fourierCoefs.at(coefIndex) * coskzn
185 + fourierCoefs.at(coefIndex + 1) * sinkzn);
187 onAxisFieldPPP[zStepIndex] += derivCoeff * (fourierCoefs.at(coefIndex) * sinkzn
188 + fourierCoefs.at(coefIndex + 1) * coskzn);
196 std::vector<double> fieldComponents)
const {
198 double radiusSq =
pow(
R(0), 2.0) +
pow(
R(1), 2.0);
199 double transverseEFactor = -fieldComponents.at(1) / 2.0
200 + radiusSq * fieldComponents.at(3) / 16.0;
202 E(0) +=
R(0) * transverseEFactor;
203 E(1) +=
R(1) * transverseEFactor;
204 E(2) += fieldComponents.at(0) - fieldComponents.at(2) * radiusSq / 4.0;
209 std::vector<double> &fieldComponents)
const {
224 gsl_fft_real_wavetable *waveTable = gsl_fft_real_wavetable_alloc(totalSize);
225 gsl_fft_real_workspace *workSpace = gsl_fft_real_workspace_alloc(totalSize);
228 double *fieldDataReflected =
new double[totalSize];
231 fieldData[dataIndex];
233 fieldData[dataIndex];
236 gsl_fft_real_transform(fieldDataReflected, 1,
238 waveTable, workSpace);
240 std::vector<double> fourierCoefs;
241 fourierCoefs.push_back(fieldDataReflected[0] / totalSize);
242 for (
unsigned int coefIndex = 1; coefIndex + 1 < 2 *
accuracy_m; ++ coefIndex)
243 fourierCoefs.push_back(2.0 * fieldDataReflected[coefIndex] / totalSize);
245 delete [] fieldDataReflected;
246 gsl_fft_real_workspace_free(workSpace);
247 gsl_fft_real_wavetable_free(waveTable);
254 double onAxisFieldPP[],
255 double onAxisFieldPPP[]) {
268 z[zStepIndex] =
deltaZ_m * zStepIndex;
302 for (
auto fourierIt = fourierCoefs.begin(); fourierIt < fourierCoefs.end(); ++ fourierIt)
308 double fieldData[]) {
312 interpretLine<double>(fieldFile, fieldData[dataIndex]);
313 if (
std::abs(fieldData[dataIndex]) > maxEz)
314 maxEz =
std::abs(fieldData[dataIndex]);
325 std::string tempString;
328 bool parsingPassed =
true;
330 parsingPassed = interpretLine<std::string, unsigned int>(fieldFile,
334 parsingPassed = interpretLine<std::string, unsigned int, std::string>(fieldFile,
340 if (tempString !=
"TRUE" &&
341 tempString !=
"FALSE")
343 "The third string on the first line of 1D field "
344 "maps has to be either TRUE or FALSE");
348 parsingPassed = parsingPassed &&
349 interpretLine<double, double, unsigned int>(fieldFile,
353 parsingPassed = parsingPassed &&
354 interpretLine<double, double, int>(fieldFile,
363 return parsingPassed;
368 std::string tempString;
370 getLine(fieldFile, tempString);
371 getLine(fieldFile, tempString);
372 getLine(fieldFile, tempString);
378 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 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)
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)
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const
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
double readFileData(std::ifstream &fieldFile, double fieldData[])
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.
void computeFieldOffAxis(const Vector_t &R, Vector_t &E, Vector_t &B, std::vector< double > fieldComponents) const
bool checkFileData(std::ifstream &fieldFile, bool parsingPassed)
double deltaZ_m
Number of grid points in field input file.
virtual bool getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const
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)