43 const double ke=2.532638e8;
45 template<
unsigned int Dim>
50 template<
class T,
class FT,
class FT2>
54 grn = grnI[0] * hrsq[0] + grnI[1] * hrsq[1] + grnI[2] * hrsq[2];
55 NDIndex<3> lDomain_m = grn.getLayout().getLocalNDIndex();
57 for (
int i=lDomain_m[0].
min(); i<=lDomain_m[0].max(); ++i) {
59 for (
int j=lDomain_m[1].
min(); j<=lDomain_m[1].max(); ++j) {
61 for (
int k=lDomain_m[2].
min(); k<=lDomain_m[2].max(); ++k) {
65 grn.localElement(elem) = 0 ;
68 grn.localElement(elem) =
ke*std::complex<double>(
std::erf(
alpha*r)/(r+eps));
83 for (
unsigned d = 0; d<
Dim; ++d)
84 sqr += diff[d]*diff[d];
90 if (P.
Q[i]!=0 && P.
Q[j]!=0) {
99 P.
Ef[i] -= P.
Q[j]*Fij;
100 P.
Ef[j] += P.
Q[i]*Fij;
102 P.
Phi[i] += P.
Q[j]*phi;
103 P.
Phi[j] += P.
Q[i]*phi;
122 interaction_radius_m(interaction_radius),
126 Inform msg(
"P3MPoissonSolver::P3MPoissonSolver ");
130 for (
unsigned int i = 0; i < 2 *
Dim; ++i) {
145 for (
unsigned int i = 0; i < 2 *
Dim; ++i) {
174 for(
unsigned int i = 0; i < 3; i++) {
186 bool compressTemps =
true;
189 fft_m->setDirectionName(+1,
"forward");
190 fft_m->setDirectionName(-1,
"inverse");
197 for (
unsigned int i = 0; i < 2 *
Dim; ++i) {
212 for (
unsigned int i = 0; i < 2 *
Dim; ++i) {
227 for(
unsigned int i = 0; i < 3; i++) {
239 bool compressTemps =
true;
245 fft_m->setDirectionName(+1,
"forward");
246 fft_m->setDirectionName(-1,
"inverse");
258 if (interaction_radius>0){
275 Inform msg (
"calculateGridForces ");
291 for (
int i = 0; i < 3; ++i) {
337 Inform m(
"computeAvgSpaceChargeForces ");
339 const double N =
static_cast<double>(bunch->
getTotalNum());
340 double locAvgEf[
Dim]={};
347 reduce(&(locAvgEf[0]), &(locAvgEf[0]) +
Dim,
364 Rrel=bunch->
R[i] - beam_center;
365 bunch->
Ef[i] += Rrel/r*f*scFoc;
379 Inform m(
"compute_temperature ");
381 double loc_avg_vel[
Dim]={0.0,0.0,0.0};
382 double avg_vel[
Dim]={0.0,0.0,0.0};
384 for(
unsigned long k = 0; k < bunch->
getLocalNum(); ++k) {
385 for(
unsigned i = 0; i <
Dim; i++) {
386 loc_avg_vel[i] += bunch->
P[k](i);
389 reduce(&(loc_avg_vel[0]), &(loc_avg_vel[0]) +
Dim,
392 const double N =
static_cast<double>(bunch->
getTotalNum());
393 avg_vel[0]=avg_vel[0]/N;
394 avg_vel[1]=avg_vel[1]/N;
395 avg_vel[2]=avg_vel[2]/N;
397 m <<
"avg_vel[0]= " << avg_vel[0] <<
" avg_vel[1]= " << avg_vel[1] <<
" avg_vel[2]= " << avg_vel[2] <<
endl;
414 Inform msg(
"P3MPoissonSolver::test ");
417 const double mi = 1.0;
418 const double qi = -1.0;
419 const double qom = qi/mi;
420 const double beam_radius = 0.001774;
421 const double f = 1.5;
422 const double dt = bunch->
getdT();
437 for (
int i=0; i<3; i++) {
442 msg << *
this <<
endl;
451 for (
int it=0; it<1000; it++) {
457 assign(bunch->
R, bunch->
R + dt * bunch->
P);
465 assign(bunch->
P, bunch->
P + dt * qom * bunch->
Ef);
471 msg <<
"Finished iteration " << it <<
endl;
477 os <<
"* ************* P 3 M - P o i s s o n S o l v e r *************** " <<
endl;
478 os <<
"* h " <<
hr_m <<
'\n';
480 os <<
"* ALPHA " <<
alpha_m <<
'\n';
481 os <<
"* EPSILON " <<
eps_m <<
'\n';
482 os <<
"* Extend L " <<
extend_l <<
'\n';
483 os <<
"* Extend R " <<
extend_r <<
'\n';
484 os <<
"* hr " <<
hr_m <<
'\n';
485 os <<
"* nr " <<
nr_m <<
'\n';
486 os <<
"* *************************************************************** " <<
endl;
Tps< T > exp(const Tps< T > &x)
Exponential.
Tps< T > sqrt(const Tps< T > &x)
Square root.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
FTps< T, N > erf(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Error function.
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Field< Vektor< T, 3U >, 3U, UniformCartesian< 3U, MFLOAT >, Cell > & Grad1Ord(Field< T, 3U, UniformCartesian< 3U, MFLOAT >, Vert > &x, Field< Vektor< T, 3U >, 3U, UniformCartesian< 3U, MFLOAT >, Cell > &r)
Old Grad operator.
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
PETE_TTTree< OpWhere, typename Cond_t::PETE_Expr_t, typename True_t::PETE_Expr_t, PETE_Scalar< Vektor< T, Dim > > > where(const PETE_Expr< Cond_t > &c, const PETE_Expr< True_t > &t, const Vektor< T, Dim > &f)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
constexpr double alpha
The fine structure constant, no dimension.
constexpr double c
The velocity of light in m/s.
bool lt(double x, double y)
ParticleAttrib< Vector_t > Ef
size_t getLocalNum() const
ParticleAttrib< double > M
size_t getTotalNum() const
ParticleAttrib< Vector_t > P
ParticleAttrib< double > Q
void calcBeamParameters()
ParticleAttrib< double > Phi
The global OPAL structure.
static OpalData * getInstance()
static void calculate(Vektor< T, 3 > &hrsq, FT &grn, FT2 *grnI, double alpha, double eps)
void operator()(std::size_t i, std::size_t j, PartBunch &P, Vektor< double, 3 > &shift) const
ApplyField(T c, double r, double epsilon, double alpha)
Vektor< double, 3 > extend_l
BConds< Vector_t, Dim, Mesh_t, Center_t > vbc_m
void compute_temperature(PartBunchBase< double, 3 > *bunch)
void test(PartBunchBase< double, 3 > *bunch)
BConds< double, Dim, Mesh_t, Center_t > bc_m
double interaction_radius_m
BConds< double, Dim, Mesh_t, Center_t > bcp_m
void calculatePairForces(PartBunchBase< double, 3 > *bunch, double interaction_radius, double alpha, double eps)
void applyConstantFocusing(PartBunchBase< double, 3 > *bunch, double f, double r)
Vektor< double, 3 > extend_r
void calculateGridForces(PartBunchBase< double, 3 > *bunch, double interaction_radius, double alpha, double eps)
Vektor< double, Dim > avgEF_m
std::unique_ptr< FFTC_t > fft_m
Inform & print(Inform &os) const
void computePotential(Field_t &rho, Vector_t hr, double zshift)
FFT< CCTransform, 3, double > FFTC_t
void computeAvgSpaceChargeForces(PartBunchBase< double, 3 > *bunch)
P3MPoissonSolver(Mesh_t *mesh, FieldLayout_t *fl, double interaction_radius, double alpha, double eps)
void dumpSDDS(PartBunchBase< double, 3 > *beam, Vector_t FDext[], const double &azimuth=-1) const
void initialize(Layout_t &)
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &) const
void gather(const Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &)
const NDIndex< Dim > & getDomain() const
MFLOAT get_meshSpacing(unsigned d) const
void for_each(const Pred &pred, const OP &op, Vektor< double, 3 > extend_l, Vektor< double, 3 > extend_r)
void for_each(const Pred &pred, const OP &op, Vektor< double, 3 > extend_l, Vektor< double, 3 > extend_r)