8#include "gsl/gsl_fft_real.h"
9#include "gsl/gsl_interp.h"
10#include "gsl/gsl_spline.h"
16 :
Fieldmap(aFilename), FourCoefs_m(nullptr) {
18 int skippedValues = 0;
19 std::string tmpString;
27 bool parsing_passed =
true;
29 parsing_passed = interpretLine<std::string, int>(file, tmpString,
accuracy_m);
31 parsing_passed = interpretLine<std::string, int, std::string>(
35 if (tmpString !=
"TRUE" && tmpString !=
"FALSE")
37 "Astra1DElectroStatic::Astra1DElectroStatic",
38 "The third string on the first line of 1D field "
39 "maps has to be either TRUE or FALSE");
44 parsing_passed = parsing_passed && interpretLine<double, double>(file,
zbegin_m, tmpDouble);
47 while (!file.eof() && parsing_passed) {
48 parsing_passed = interpretLine<double, double>(file,
zend_m, tmpDouble,
false);
49 if (
zend_m - tmpDouble2 > 1
e-10) {
51 }
else if (parsing_passed) {
59 if (!parsing_passed && !file.eof()) {
63 "Astra1DElectroStatic::Astra1DElectroStatic",
64 "An error occured when reading the fieldmap '" +
Filename_m +
"'");
85 bool parsing_passed =
true;
87 std::string tmpString;
96 gsl_spline* Ez_interpolant = gsl_spline_alloc(gsl_interp_cspline,
num_gridpz_m);
97 gsl_interp_accel* Ez_accel = gsl_interp_accel_alloc();
99 gsl_fft_real_wavetable* real = gsl_fft_real_wavetable_alloc(2 *
num_gridpz_m);
100 gsl_fft_real_workspace* work = gsl_fft_real_workspace_alloc(2 *
num_gridpz_m);
109 parsing_passed = interpretLine<double, double>(in, zvals[i], RealValues[i]);
112 if (zvals[i] - tmpDouble > 1
e-10) {
113 if (std::abs(RealValues[i]) > Ez_max) {
114 Ez_max = std::abs(RealValues[i]);
116 tmpDouble = zvals[i];
122 gsl_spline_init(Ez_interpolant, zvals, RealValues,
num_gridpz_m);
129 RealValues[ii] = gsl_spline_eval(Ez_interpolant, z, Ez_accel);
135 RealValues[i] = RealValues[ii];
140 gsl_fft_real_transform(RealValues, 1,
num_gridpz_m, real, work);
147 for (
int i = 1; i < 2 *
accuracy_m - 1; i++) {
151 gsl_fft_real_workspace_free(work);
152 gsl_fft_real_wavetable_free(real);
154 gsl_spline_free(Ez_interpolant);
155 gsl_interp_accel_free(Ez_accel);
177 const double RR2 = R(0) * R(0) + R(1) * R(1);
187 for (
int l = 1; l <
accuracy_m; l++, n += 2) {
189 double somefactor = 1.0;
190 double coskzl = cos(kz * l);
191 double sinkzl = sin(kz * l);
193 somefactor *= somefactor_base;
195 somefactor *= somefactor_base;
197 somefactor *= somefactor_base;
202 const double EfieldR = -ezp / 2. + ezppp / 16. * RR2;
204 E(0) += EfieldR * R(0);
205 E(1) += EfieldR * R(1);
206 E(2) += ez - ezpp * RR2 / 4.;
222 double& ,
double& ,
double& ,
double& ,
double& ,
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 MVpm2Vpm
std::string toUpper(const std::string &str)
std::unique_ptr< Inform > Info
virtual double getFrequency() const
Astra1DElectroStatic(std::string aFilename)
virtual void setFrequency(double freq)
virtual void getFieldDimensions(double &zBegin, double &zEnd) const
virtual void getInfo(Inform *)
virtual bool getFieldDerivative(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B, const DiffDirection &dir) const
virtual bool getFieldstrength(const Vector_t< double, 3 > &R, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B) const
void disableFieldmapWarning()
static std::string typeset_msg(const std::string &msg, const std::string &title)
void getLine(std::ifstream &in, std::string &buffer)