37 filters_m(filters.
begin(), filters.
end()),
54 const double sPos = bunch->
get_sPos();
55 std::pair<double, double> meshInfo;
57 const double &meshSpacing = meshInfo.second;
58 const double &meshOrigin = meshInfo.first + 0.5 * meshSpacing;
75 double angleOfSlice = 0.0;
76 double pathLengthOfSlice = minPathLength + i * meshSpacing;
77 if (pathLengthOfSlice > 0.0)
87 for (
unsigned int i = 0; i < bunch->
getLocalNum(); ++i) {
89 double distanceToOrigin = (
R(2) - meshOrigin) / meshSpacing;
91 unsigned int indexz = (
unsigned int)
floor(distanceToOrigin);
92 double leverz = distanceToOrigin - indexz;
95 bunch->
Ef[i](2) += (1. - leverz) *
Ez_m[indexz] + leverz *
Ez_m[indexz + 1];
99 static std::string oldBendName;
100 static unsigned long counter = 0;
105 bool print_criterion = (counter + 1) % every == 0;
106 if (print_criterion) {
107 static unsigned int file_number = 0;
108 if (counter == 0) file_number = 0;
110 std::stringstream filename_str;
111 filename_str <<
bendName_m <<
"-CSRWake" << std::setw(5) << std::setfill(
'0') << file_number <<
".txt";
117 std::ofstream csr(fname);
118 csr << std::setprecision(8);
121 csr << i *meshSpacing <<
"\t"
127 msg <<
"** wrote " << fname <<
endl;
155 std::vector<Filter *>::const_iterator fit;
167 const double meshSpacingsup =
std::pow(meshSpacing, -1. / 3.);
169 double relativeSlippageLength = SlippageLength / meshSpacing;
170 if (relativeSlippageLength > sliceNumber) {
177 double dx1 =
std::pow(sliceNumber, 2. / 3.);
178 double dx2 =
std::pow(sliceNumber, 5. / 3.);
179 double dx3 =
std::pow(sliceNumber - 1., 5. / 3.);
180 Ez_m[sliceNumber] += 0.3 * meshSpacingsup *
dlineDensitydz_m[0] * (5. * dx1 - 3. * dx2 + 3. * dx3);
181 for (
unsigned int j = 1; j < sliceNumber; ++ j) {
184 dx3 =
std::pow(sliceNumber - j - 1., 5. / 3.);
189 }
else if (relativeSlippageLength < 1) {
192 if (4.0 * relativeSlippageLength <= 1) {
197 if (4.0 * relativeSlippageLength < sliceNumber) {
199 int j = sliceNumber -
static_cast<int>(
floor(4.0 * relativeSlippageLength));
200 double frac = 4.0 * relativeSlippageLength - (sliceNumber - j);
214 if (4. * relativeSlippageLength < sliceNumber) {
216 int j = sliceNumber -
static_cast<int>(
floor(4. * relativeSlippageLength));
217 double frac = 4. * relativeSlippageLength - (sliceNumber - j);
222 int j = sliceNumber -
static_cast<int>(
floor(SlippageLength / meshSpacing));
223 double frac = relativeSlippageLength - (sliceNumber - j);
226 double dx1 =
std::pow(sliceNumber - j + frac, 2. / 3.);
227 double dx2 =
std::pow(sliceNumber - j, 2. / 3.);
228 double dx3 =
std::pow(sliceNumber - j + frac, 5. / 3.);
229 double dx4 =
std::pow(sliceNumber - j, 5. / 3.);
236 dx3 =
std::pow(sliceNumber - j - 1., 5. / 3.);
238 for (
unsigned int k = j + 1; k < sliceNumber; ++ k) {
241 dx3 =
std::pow(sliceNumber - k - 1., 5. / 3.);
247 Ez_m[sliceNumber] *= prefactor;
260 if (Ds_max2 / meshSpacing < sliceNumber) {
261 j = sliceNumber -
static_cast<int>(
floor(Ds_max2 / meshSpacing));
262 frac = Ds_max2 / meshSpacing - (sliceNumber - j);
268 if (Ds_max / meshSpacing < sliceNumber) {
269 j = sliceNumber -
static_cast<int>(
floor(Ds_max / meshSpacing));
270 frac = Ds_max / meshSpacing - (sliceNumber - j);
279 if (Ds_max / meshSpacing < sliceNumber) {
291 for (
unsigned int l = sliceNumber - k + 1; l < sliceNumber; ++ l) {
299 Psi_m[sliceNumber] =
calcPsi(
Psi_m[sliceNumber], angleOverlap, meshSpacing / 4.0);
304 Ez_m[sliceNumber] *= prefactor;
315 const int Nmax = 100;
316 const double eps = 1
e-10;
319 if (psiInitial != 0.0) psi = psiInitial;
321 for (
int i = 0; i < Nmax; ++i) {
322 double residual =
bendRadius_m * psi * psi * psi * (psi + 4. * x) - 24. * Ds * psi - 24. * Ds * x;
334 ERRORMSG(
"In CSRWakeFunction::calcPsi(): exceed maximum number of iterations!" <<
endl);
339 return "CSRWakeFunction";
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
PartBunchBase< T, Dim >::ConstIterator begin(PartBunchBase< T, Dim > const &bunch)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(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
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.
void get_bounds(Vector_t &rmin, Vector_t &rmax)
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)
virtual const std::string getType() const
LineDensity dlineDensitydz_m
double calcPsi(const double &psiInitial, const double &x, const double &Ds) const
void calculateContributionInside(size_t sliceNumber, double angleOfSlice, double meshSpacing)
std::vector< double > Ez_m
std::vector< Filter * > filters_m
std::vector< double > Psi_m
void initialize(const ElementBase *ref)
CSRWakeFunction(const std::string &name, std::vector< Filter * > filters, const unsigned int &N)
LineDensity lineDensity_m
std::shared_ptr< Filter > defaultFilter_m
void apply(PartBunchBase< double, 3 > *bunch)
double searchRoot(const double &tol)
bool hasPositiveRealRoots()
const unsigned int nBins_m