37 filters_m(filters.
begin(), filters.
end()),
54 std::pair<double, double> meshInfo;
56 const double &meshOrigin = meshInfo.first;
57 const double &meshSpacing = meshInfo.second;
60 if (
Ez_m.size() < numOfSlices) {
61 Ez_m.resize(numOfSlices, 0.0);
62 Chi_m.resize(numOfSlices, 0.0);
63 Grn_m.resize(numOfSlices, 0.0);
64 Psi_m.resize(numOfSlices, 0.0);
67 for (
unsigned int i = 0; i < numOfSlices; ++i) {
74 for (
unsigned int i = 1; i < numOfSlices; i++) {
75 double pathLengthOfSlice = minPathLength + i * meshSpacing;
87 for (
unsigned int i = 0; i < bunch->
getLocalNum(); ++i) {
89 unsigned int indexz = (
unsigned int)
floor((
R(2) - meshOrigin) / meshSpacing);
90 double leverz = (
R(2) - meshOrigin) / meshSpacing - indexz;
93 bunch->
Ef[i](2) += (1. - leverz) *
Ez_m[indexz] + leverz *
Ez_m[indexz + 1];
97 static std::string oldBendName;
98 static unsigned long counter = 0;
103 bool print_criterion = (counter + 1) % every == 0;
104 if (print_criterion) {
105 static unsigned int file_number = 0;
106 if (counter == 0) file_number = 0;
109 std::stringstream filename_str;
110 filename_str <<
bendName_m <<
"-CSRWake" << std::setw(5) << std::setfill(
'0') << file_number <<
".txt";
117 std::ofstream csr(fname);
118 csr << spos <<
", " <<
FieldBegin_m <<
", " << smin(2) <<
", " << smax(2) <<
", " << meshSpacing*64 <<
std::endl;
120 csr << i *meshSpacing <<
"\t"
125 msg <<
"** wrote " << fname <<
endl;
151 std::pair<double, double>& meshInfo) {
155 std::vector<Filter *>::const_iterator fit;
164 double meshSpacing) {
167 double xmu_const = 3.0 * gamma * gamma * gamma / (2.0 *
bendRadius_m);
168 double chi_const = 9.0 / 16.0 * (6.0 -
std::log(27.0 / 4.0));
170 for (
unsigned int i = 0; i < numOfSlices; ++i) {
172 double z = i * meshSpacing;
173 double xmu = xmu_const * z;
174 double b =
std::sqrt(xmu * xmu + 1.0) + xmu;
181 double grn_const = -16.0/(27.0 * gamma * gamma * meshSpacing);
183 Grn_m[numOfSlices - 1] = 0.0;
184 for (
unsigned int i = 1; i < numOfSlices - 1; ++i) {
193 int startSliceNum = 0;
194 for (
int j = sliceNumber; j >= startSliceNum; j--)
200 double meshSpacing) {
210 if (Ds_max2 / meshSpacing < sliceNumber) {
211 j = sliceNumber -
static_cast<int>(
std::floor(Ds_max2 / meshSpacing));
212 frac = Ds_max2 / meshSpacing - (sliceNumber - j);
218 if (Ds_max / meshSpacing < sliceNumber) {
219 j = sliceNumber -
static_cast<int>(
std::floor(Ds_max / meshSpacing));
220 frac = Ds_max / meshSpacing - (sliceNumber - j);
229 if (Ds_max / meshSpacing < sliceNumber) {
241 for (
unsigned int l = sliceNumber - k + 1; l < sliceNumber; ++ l) {
249 Psi_m[sliceNumber] =
calcPsi(
Psi_m[sliceNumber], angleOverlap, meshSpacing / 4.0);
254 Ez_m[sliceNumber] *= prefactor;
265 const int Nmax = 100;
266 const double eps = 1
e-10;
268 if (psiInitial != 0.0) psi = psiInitial;
270 for (
int i = 0; i < Nmax; ++i) {
271 double residual =
bendRadius_m * psi * psi * psi * (psi + 4. * x) - 24. * Ds * psi - 24. * Ds * x;
281 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 > log(const Tps< T > &x)
Natural logarithm.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
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
double get_meanKineticEnergy() const
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 calculateGreenFunction(PartBunchBase< double, 3 > *bunch, double meshSpacing)
void apply(PartBunchBase< double, 3 > *bunch) override
void calculateLineDensity(PartBunchBase< double, 3 > *bunch, std::pair< double, double > &meshInfo)
std::vector< double > Chi_m
std::vector< double > Grn_m
CSRIGFWakeFunction(const std::string &name, std::vector< Filter * > filters, const unsigned int &N)
LineDensity lineDensity_m
void initialize(const ElementBase *ref) override
void calculateContributionAfter(size_t sliceNumber, double angleOfSlice, double meshSpacing)
std::vector< double > Psi_m
std::vector< double > Ez_m
std::shared_ptr< Filter > defaultFilter_m
LineDensity dlineDensitydz_m
std::vector< Filter * > filters_m
void calculateContributionInside(size_t sliceNumber, double angleOfSlice, double meshSpacing)
double calcPsi(const double &psiInitial, const double &x, const double &Ds) const
virtual WakeType getType() const override
double searchRoot(const double &tol)
bool hasPositiveRealRoots()
const unsigned int nBins_m