59 layout->
getLayout().changeDomain(*fLayout);
81 "P3M solver not available during emission");
92 if(
fs_m->hasValidSolver()) {
116 double scaleFactor = 1;
122 double tmp2 = 1 /
hr_m[0] * 1 /
hr_m[1] * 1 /
hr_m[2] / (scaleFactor * scaleFactor * scaleFactor) / gammaz;
128 hr_scaled[2] *= gammaz;
132 imagePotential =
rho_m;
134 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
137 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
149 eg_m *=
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
155 int mx = (int)
nr_m[0];
156 int mx2 = (int)
nr_m[0] / 2;
157 int my = (int)
nr_m[1];
158 int my2 = (int)
nr_m[1] / 2;
159 int mz = (int)
nr_m[2];
160 int mz2 = (int)
nr_m[2] / 2;
162 for (
int i=0; i<mx; i++ )
163 *
gmsg <<
"Bin " << binNumber
164 <<
", Self Field along x axis E = " <<
eg_m[i][my2][mz2]
165 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
167 for (
int i=0; i<my; i++ )
168 *
gmsg <<
"Bin " << binNumber
169 <<
", Self Field along y axis E = " <<
eg_m[mx2][i][mz2]
170 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
172 for (
int i=0; i<mz; i++ )
173 *
gmsg <<
"Bin " << binNumber
174 <<
", Self Field along z axis E = " <<
eg_m[mx2][my2][i]
175 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
192 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz /
Physics::c;
205 double hz =
rho_m.get_mesh().get_meshSpacing(2);
206 double zshift = -(2 * origin(2) + (domain[2].first() + domain[2].last() + 1) * hz) * gammaz * scaleFactor;
210 fs_m->solver_m->computePotential(imagePotential, hr_scaled, zshift);
213 imagePotential *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
219#ifdef DBG_SCALARFIELD
220 const int dumpFreq = 100;
236 eg_m *=
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
249 for (
int i=0; i<mx; i++ )
250 *
gmsg <<
"Bin " << binNumber
251 <<
", Image Field along x axis E = " <<
eg_m[i][my2][mz2]
252 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
254 for (
int i=0; i<my; i++ )
255 *
gmsg <<
"Bin " << binNumber
256 <<
", Image Field along y axis E = " <<
eg_m[mx2][i][mz2]
257 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
259 for (
int i=0; i<mz; i++ )
260 *
gmsg <<
"Bin " << binNumber
261 <<
", Image Field along z axis E = " <<
eg_m[mx2][my2][i]
262 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
265#ifdef DBG_SCALARFIELD
302 double xmin =
fs_m->solver_m->getXRangeMin();
303 double xmax =
fs_m->solver_m->getXRangeMax();
304 double ymin =
fs_m->solver_m->getYRangeMin();
305 double ymax =
fs_m->solver_m->getYRangeMax();
312 if(
R[n](0) < xmin ||
R[n](0) > xmax ||
313 R[n](1) < ymin ||
R[n](1) > ymax) {
354 if(
fs_m->hasValidSolver()) {
367 gammaz = std::sqrt(gammaz + 1.0);
368 double scaleFactor = 1;
372 hr_scaled[2] *= gammaz;
375 double tmp2 = 1 / hr_scaled[0] * 1 / hr_scaled[1] * 1 / hr_scaled[2];
385#ifdef DBG_SCALARFIELD
391 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
399 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
408#ifdef DBG_SCALARFIELD
420 int mx = (int)
nr_m[0];
421 int mx2 = (int)
nr_m[0] / 2;
422 int my = (int)
nr_m[1];
423 int my2 = (int)
nr_m[1] / 2;
424 int mz = (int)
nr_m[2];
425 int mz2 = (int)
nr_m[2] / 2;
427 for (
int i=0; i<mx; i++ )
428 *
gmsg <<
"Field along x axis Ex = " <<
eg_m[i][my2][mz2] <<
" Pot = " <<
rho_m[i][my2][mz2] <<
endl;
430 for (
int i=0; i<my; i++ )
431 *
gmsg <<
"Field along y axis Ey = " <<
eg_m[mx2][i][mz2] <<
" Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
433 for (
int i=0; i<mz; i++ )
434 *
gmsg <<
"Field along z axis Ez = " <<
eg_m[mx2][my2][i] <<
" Pot = " <<
rho_m[mx2][my2][i] <<
endl;
437#ifdef DBG_SCALARFIELD
448 fs_m->solver_m->calculatePairForces(
this,gammaz);
451 Ef =
Ef *
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
460 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz /
Physics::c;
462 Bf(0) =
Bf(0) - betaC *
Ef(1);
463 Bf(1) =
Bf(1) + betaC *
Ef(0);
487 "P3M solver not available yet for cyclotrons");
496 if(
fs_m->hasValidSolver()) {
506 hr_scaled[1] *= gamma;
509 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
518#ifdef DBG_SCALARFIELD
525 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
533 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
540#ifdef DBG_SCALARFIELD
556 int mx = (int)
nr_m[0];
557 int mx2 = (int)
nr_m[0] / 2;
558 int my = (int)
nr_m[1];
559 int my2 = (int)
nr_m[1] / 2;
560 int mz = (int)
nr_m[2];
561 int mz2 = (int)
nr_m[2] / 2;
563 for (
int i=0; i<mx; i++ )
564 *
gmsg <<
"Field along x axis Ex = " <<
eg_m[i][my2][mz2] <<
" Pot = " <<
rho_m[i][my2][mz2] <<
endl;
566 for (
int i=0; i<my; i++ )
567 *
gmsg <<
"Field along y axis Ey = " <<
eg_m[mx2][i][mz2] <<
" Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
569 for (
int i=0; i<mz; i++ )
570 *
gmsg <<
"Field along z axis Ez = " <<
eg_m[mx2][my2][i] <<
" Pot = " <<
rho_m[mx2][my2][i] <<
endl;
573#ifdef DBG_SCALARFIELD
586 double betaC = std::sqrt(gamma * gamma - 1.0) / gamma /
Physics::c;
589 Bf(0) = betaC *
Ef(2);
590 Bf(2) = -betaC *
Ef(0);
626 "P3M solver not available yet for cyclotrons");
638 if(
fs_m->hasValidSolver()) {
648 hr_scaled[1] *= gamma;
651 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
655#ifdef DBG_SCALARFIELD
662 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
668 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
675#ifdef DBG_SCALARFIELD
691 int mx = (int)
nr_m[0];
692 int mx2 = (int)
nr_m[0] / 2;
693 int my = (int)
nr_m[1];
694 int my2 = (int)
nr_m[1] / 2;
695 int mz = (int)
nr_m[2];
696 int mz2 = (int)
nr_m[2] / 2;
698 for (
int i=0; i<mx; i++ )
699 *
gmsg <<
"Bin " << bin
700 <<
", Field along x axis Ex = " <<
eg_m[i][my2][mz2]
701 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
703 for (
int i=0; i<my; i++ )
704 *
gmsg <<
"Bin " << bin
705 <<
", Field along y axis Ey = " <<
eg_m[mx2][i][mz2]
706 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
708 for (
int i=0; i<mz; i++ )
709 *
gmsg <<
"Bin " << bin
710 <<
", Field along z axis Ez = " <<
eg_m[mx2][my2][i]
711 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
715#ifdef DBG_SCALARFIELD
725 double betaC = std::sqrt(gamma * gamma - 1.0) / gamma /
Physics::c;
766 for (
int i = 0; i < 2 * 3; ++i) {
785 for (
int i = 0; i < 2 * 3; ++i) {
795 for (
int i = 0; i < 2 * 3; ++ i) {
819 for (
unsigned int i = 0; i <
Dimension; i++)
820 grid[i] = domain[i].length();
Field< Vector_t, 3, Mesh_t, Center_t > VField_t
Field< double, 3, Mesh_t, Center_t > Field_t
ParticleSpatialLayout< double, 3, Mesh_t > Layout_t
CenteredFieldLayout< 3, Mesh_t, Center_t > FieldLayout_t
void BinaryRepartition(FieldLayout< Dim > &layout, BareField< double, Dim > &weights)
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Field< Vektor< T, 1U >, 1U, Cartesian< 1U, MFLOAT >, Cell > & Grad(Field< T, 1U, Cartesian< 1U, MFLOAT >, Vert > &x, Field< Vektor< T, 1U >, 1U, Cartesian< 1U, MFLOAT >, Cell > &r)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
T ParticlePeriodicBCond(const T t, const T minval, const T maxval)
T ParticleNoBCond(const T t, const T, const T)
Inform & level2(Inform &inf)
Inform & endl(Inform &inf)
Inform & level3(Inform &inf)
constexpr double q_e
The elementary charge in As.
constexpr double c
The velocity of light in m/s.
ParticleAttrib< Vector_t > Ef
std::shared_ptr< AbstractParticle< double, Dim > > pbase_m
long long localTrackStep_m
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
double getCouplingConstant() const
ParticleAttrib< Vector_t > Eftmp
size_t getLocalNum() const
size_t getTotalNum() const
ParticleBConds< Position_t, Dimension > & getBConds()
ParticleAttrib< Vector_t > P
Inform & print(Inform &os)
double getBinGamma(int bin)
ParticleAttrib< double > Q
PartBunchBase(AbstractParticle< double, Dim > *pb, const PartData *ref)
std::pair< Vector_t, Vector_t > VectorPair_t
ParticleAttrib< double > dt
static const unsigned Dimension
void destroy(size_t M, size_t I, bool doNow=false)
ParticleAttrib< Vector_t > Bf
virtual void swap(unsigned int i, unsigned int j)
IpplTimings::TimerRef selfFieldTimer_m
void resetInterpolationCache(bool clearCache=false)
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
IpplParticleBase< Layout_t > pbase_t
Field_t rho_m
scalar potential
void swap(unsigned int i, unsigned int j)
PartBunch(const PartData *ref)
Default constructor.
ParticleLayout< double, 3 > & getLayout()
void initialize(FieldLayout_t *fLayout)
bool interpolationCacheSet_m
Inform & print(Inform &os)
void updateDomainLength(Vektor< int, 3 > &grid)
FieldLayout_t & getFieldLayout()
VField_t eg_m
vector field on the grid
VectorPair_t getEExtrema()
const Mesh_t & getMesh() const
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
void resizeMesh()
resize mesh to geometry specified
BConds< Vector_t, 3, Mesh_t, Center_t > vbc_m
void computeSelfFields_cycl(double gamma)
Calculates the self electric field from the charge density distribution for use in cyclotrons.
void updateFields(const Vector_t &hr, const Vector_t &origin)
void dumpField(FieldType &field, std::string name, std::string unit, long long step, FieldType *image=nullptr)
Dump a scalar or vector field to a file.
const NDIndex< Dim > & getDomain() const
void set_origin(const Vektor< MFLOAT, Dim > &o)
void set_meshSpacing(MFLOAT *const del)
RegionLayout< T, Dim, Mesh > & getLayout()
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)
Vektor< double, 3 > Vector_t