35 std::vector<Filter*> filters,
36 const unsigned int& N):
38 filters_m(filters.
begin(), filters.
end()),
55 const double sPos = bunch->
get_sPos();
56 std::pair<double, double> meshInfo;
58 const double &meshSpacing = meshInfo.second;
59 const double &meshOrigin = meshInfo.first + 0.5 * meshSpacing;
76 double angleOfSlice = 0.0;
77 double pathLengthOfSlice = minPathLength + i * meshSpacing;
78 if (pathLengthOfSlice > 0.0)
88 for (
unsigned int i = 0; i < bunch->
getLocalNum(); ++i) {
90 double distanceToOrigin = (
R(2) - meshOrigin) / meshSpacing;
92 unsigned int indexz = (
unsigned int)
floor(distanceToOrigin);
93 double leverz = distanceToOrigin - indexz;
96 bunch->
Ef[i](2) += (1. - leverz) *
Ez_m[indexz] + leverz *
Ez_m[indexz + 1];
100 static std::string oldBendName;
101 static unsigned long counter = 0;
106 bool print_criterion = (counter + 1) % every == 0;
107 if (print_criterion) {
108 static unsigned int file_number = 0;
109 if (counter == 0) file_number = 0;
111 std::stringstream filename_str;
112 filename_str <<
bendName_m <<
"-CSRWake" << std::setw(5) << std::setfill(
'0') << file_number <<
".txt";
118 std::ofstream csr(fname);
119 csr << std::setprecision(8);
122 csr << i *meshSpacing <<
"\t"
128 msg <<
"** wrote " << fname <<
endl;
154 std::pair<double, double>& meshInfo) {
157 std::vector<Filter *>::const_iterator fit;
169 const double meshSpacingsup =
std::pow(meshSpacing, -1. / 3.);
171 double relativeSlippageLength = SlippageLength / meshSpacing;
172 if (relativeSlippageLength > sliceNumber) {
179 double dx1 =
std::pow(sliceNumber, 2. / 3.);
180 double dx2 =
std::pow(sliceNumber, 5. / 3.);
181 double dx3 =
std::pow(sliceNumber - 1., 5. / 3.);
182 Ez_m[sliceNumber] += 0.3 * meshSpacingsup *
dlineDensitydz_m[0] * (5. * dx1 - 3. * dx2 + 3. * dx3);
183 for (
unsigned int j = 1; j < sliceNumber; ++ j) {
186 dx3 =
std::pow(sliceNumber - j - 1., 5. / 3.);
191 }
else if (relativeSlippageLength < 1) {
194 if (4.0 * relativeSlippageLength <= 1) {
199 if (4.0 * relativeSlippageLength < sliceNumber) {
201 int j = sliceNumber -
static_cast<int>(
std::floor(4.0 * relativeSlippageLength));
202 double frac = 4.0 * relativeSlippageLength - (sliceNumber - j);
216 if (4. * relativeSlippageLength < sliceNumber) {
218 int j = sliceNumber -
static_cast<int>(
std::floor(4. * relativeSlippageLength));
219 double frac = 4. * relativeSlippageLength - (sliceNumber - j);
224 int j = sliceNumber -
static_cast<int>(
std::floor(SlippageLength / meshSpacing));
225 double frac = relativeSlippageLength - (sliceNumber - j);
228 double dx1 =
std::pow(sliceNumber - j + frac, 2. / 3.);
229 double dx2 =
std::pow(sliceNumber - j, 2. / 3.);
230 double dx3 =
std::pow(sliceNumber - j + frac, 5. / 3.);
231 double dx4 =
std::pow(sliceNumber - j, 5. / 3.);
238 dx3 =
std::pow(sliceNumber - j - 1., 5. / 3.);
240 for (
unsigned int k = j + 1; k < sliceNumber; ++ k) {
243 dx3 =
std::pow(sliceNumber - k - 1., 5. / 3.);
249 Ez_m[sliceNumber] *= prefactor;
262 if (Ds_max2 / meshSpacing < sliceNumber) {
263 j = sliceNumber -
static_cast<int>(
floor(Ds_max2 / meshSpacing));
264 frac = Ds_max2 / meshSpacing - (sliceNumber - j);
270 if (Ds_max / meshSpacing < sliceNumber) {
271 j = sliceNumber -
static_cast<int>(
floor(Ds_max / meshSpacing));
272 frac = Ds_max / meshSpacing - (sliceNumber - j);
281 if (Ds_max / meshSpacing < sliceNumber) {
293 for (
unsigned int l = sliceNumber - k + 1; l < sliceNumber; ++ l) {
301 Psi_m[sliceNumber] =
calcPsi(
Psi_m[sliceNumber], angleOverlap, meshSpacing / 4.0);
306 Ez_m[sliceNumber] *= prefactor;
317 const int Nmax = 100;
318 const double eps = 1
e-10;
321 if (psiInitial != 0.0) psi = psiInitial;
323 for (
int i = 0; i < Nmax; ++i) {
324 double residual =
bendRadius_m * psi * psi * psi * (psi + 4. * x) - 24. * Ds * psi - 24. * Ds * x;
336 ERRORMSG(
"In CSRWakeFunction::calcPsi(): exceed maximum number of iterations!" <<
endl);
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
constexpr double epsilon_0
The permittivity of vacuum in As/Vm.
constexpr double e
The value of.
constexpr double pi
The value of.
std::string combineFilePath(std::initializer_list< std::string > ilist)
ParticleAttrib< Vector_t > Ef
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
size_t getLocalNum() const
void calcLineDensity(unsigned int nBins, std::vector< double > &lineDensity, std::pair< double, double > &meshInfo)
calculates the 1d line density (not normalized) and append it to a file.
static OpalData * getInstance()
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
virtual void getDimensions(double &sBegin, double &sEnd) const override
double getEffectiveLength() const
double getEffectiveCenter() const
double getBendRadius() const
double getBendAngle() const
virtual const std::string & getName() const
Get element name.
virtual void calc_derivative(std::vector< double > &histogram, const double &h)=0
void calculateLineDensity(PartBunchBase< double, 3 > *bunch, std::pair< double, double > &meshInfo)
void calculateContributionAfter(size_t sliceNumber, double angleOfSlice, double meshSpacing)
std::vector< Filter * > filters_m
LineDensity dlineDensitydz_m
double calcPsi(const double &psiInitial, const double &x, const double &Ds) const
void apply(PartBunchBase< double, 3 > *bunch) override
void calculateContributionInside(size_t sliceNumber, double angleOfSlice, double meshSpacing)
std::vector< double > Ez_m
std::vector< double > Psi_m
CSRWakeFunction(const std::string &name, std::vector< Filter * > filters, const unsigned int &N)
virtual WakeType getType() const override
LineDensity lineDensity_m
std::shared_ptr< Filter > defaultFilter_m
void initialize(const ElementBase *ref) override
double searchRoot(const double &tol)
bool hasPositiveRealRoots()
const unsigned int nBins_m