19#include "Algorithms/PartBunch.h"
25#include "Particle/ParticleBalancer.h"
28#include "Structure/FieldSolver.h"
56 layout->getLayout().changeDomain(*fLayout);
67 for (
unsigned int i = 0; i <
Dimension; i++)
68 nr_m[i] = domain[i].length();
70 for (
int i = 0; i < 3; i++)
78 GuardCellSizes<Dimension>(1),
82 GuardCellSizes<Dimension>(1),
85 fs_m->solver_m->test(
this);
93 dynamic_cast<pbase_t*
>(pbase_m.get());
95 BinaryRepartition(*underlyingPbase);
103 IpplTimings::startTimer(selfFieldTimer_m);
113 if(fs_m->hasValidSolver()) {
137 double scaleFactor = 1;
143 double tmp2 = 1 /
hr_m[0] * 1 /
hr_m[1] * 1 /
hr_m[2] / (scaleFactor * scaleFactor * scaleFactor) / gammaz;
149 hr_scaled[2] *= gammaz;
153 imagePotential =
rho_m;
155 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
158 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
176 int mx = (int)
nr_m[0];
177 int mx2 = (int)
nr_m[0] / 2;
178 int my = (int)
nr_m[1];
179 int my2 = (int)
nr_m[1] / 2;
180 int mz = (int)
nr_m[2];
181 int mz2 = (int)
nr_m[2] / 2;
183 for (
int i=0; i<mx; i++ )
184 *
gmsg <<
"Bin " << binNumber
185 <<
", Self Field along x axis E = " <<
eg_m[i][my2][mz2]
186 <<
", Pot = " <<
rho_m[i][my2][mz2] << endl;
188 for (
int i=0; i<my; i++ )
189 *
gmsg <<
"Bin " << binNumber
190 <<
", Self Field along y axis E = " <<
eg_m[mx2][i][mz2]
191 <<
", Pot = " <<
rho_m[mx2][i][mz2] << endl;
193 for (
int i=0; i<mz; i++ )
194 *
gmsg <<
"Bin " << binNumber
195 <<
", Self Field along z axis E = " <<
eg_m[mx2][my2][i]
196 <<
", Pot = " <<
rho_m[mx2][my2][i] << endl;
213 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz /
Physics::c;
226 double hz =
rho_m.get_mesh().get_meshSpacing(2);
227 double zshift = -(2 * origin(2) + (domain[2].first() + domain[2].last() + 1) * hz) * gammaz * scaleFactor;
231 fs_m->solver_m->computePotential(imagePotential, hr_scaled, zshift);
234 imagePotential *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
240#ifdef DBG_SCALARFIELD
241 const int dumpFreq = 100;
270 for (
int i=0; i<mx; i++ )
271 *
gmsg <<
"Bin " << binNumber
272 <<
", Image Field along x axis E = " <<
eg_m[i][my2][mz2]
273 <<
", Pot = " <<
rho_m[i][my2][mz2] << endl;
275 for (
int i=0; i<my; i++ )
276 *
gmsg <<
"Bin " << binNumber
277 <<
", Image Field along y axis E = " <<
eg_m[mx2][i][mz2]
278 <<
", Pot = " <<
rho_m[mx2][i][mz2] << endl;
280 for (
int i=0; i<mz; i++ )
281 *
gmsg <<
"Bin " << binNumber
282 <<
", Image Field along z axis E = " <<
eg_m[mx2][my2][i]
283 <<
", Pot = " <<
rho_m[mx2][my2][i] << endl;
286#ifdef DBG_SCALARFIELD
315 IpplTimings::stopTimer(selfFieldTimer_m);
325 IpplTimings::startTimer(selfFieldTimer_m);
329 if(fs_m->hasValidSolver()) {
335 this->
Q.scatter(this->
rho_m, this->
R, IntrplCIC_t());
342 gammaz = std::sqrt(gammaz + 1.0);
343 double scaleFactor = 1;
347 hr_scaled[2] *= gammaz;
350 double tmp2 = 1 / hr_scaled[0] * 1 / hr_scaled[1] * 1 / hr_scaled[2];
354#ifdef DBG_SCALARFIELD
360 fs_m->solver_m->computePotential(
rho_m, hr_scaled);
366 if (fs_m->getFieldSolverType() == FieldSolverType::FFT ||
367 fs_m->getFieldSolverType() == FieldSolverType::FFTBOX) {
368 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
377#ifdef DBG_SCALARFIELD
391 int mx = (int)
nr_m[0];
392 int mx2 = (int)
nr_m[0] / 2;
393 int my = (int)
nr_m[1];
394 int my2 = (int)
nr_m[1] / 2;
395 int mz = (int)
nr_m[2];
396 int mz2 = (int)
nr_m[2] / 2;
398 for (
int i=0; i<mx; i++ )
399 *
gmsg <<
"Field along x axis Ex = " <<
eg_m[i][my2][mz2] <<
" Pot = " <<
rho_m[i][my2][mz2] << endl;
401 for (
int i=0; i<my; i++ )
402 *
gmsg <<
"Field along y axis Ey = " <<
eg_m[mx2][i][mz2] <<
" Pot = " <<
rho_m[mx2][i][mz2] << endl;
404 for (
int i=0; i<mz; i++ )
405 *
gmsg <<
"Field along z axis Ez = " <<
eg_m[mx2][my2][i] <<
" Pot = " <<
rho_m[mx2][my2][i] << endl;
408#ifdef DBG_SCALARFIELD
416 Ef.gather(
eg_m, this->
R, IntrplCIC_t());
425 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz /
Physics::c;
427 Bf(0) =
Bf(0) - betaC *
Ef(1);
428 Bf(1) =
Bf(1) + betaC *
Ef(0);
430 IpplTimings::stopTimer(selfFieldTimer_m);
439 for (
int i = 0; i < 2 * 3; ++i) {
441 if (Ippl::getNodes()>1) {
442 bc_m[i] =
new ParallelInterpolationFace<double, Dimension, Mesh_t, Center_t>(i);
447 bc_m[i] =
new InterpolationFace<double, Dimension, Mesh_t, Center_t>(i);
454 *ippl::Info << level3 <<
"BC set P3M, all periodic" << endl);
458 for (
int i = 0; i < 2 * 3; ++i) {
459 bc_m[i] =
new ZeroFace<double, 3, Mesh_t, Center_t>(i);
464 *ippl::Info << level3 <<
"BC set for normal Beam" << endl);
468 for (
int i = 0; i < 2 * 3; ++ i) {
470 if (Ippl::getNodes() > 1) {
471 bc_m[i] =
new ParallelPeriodicFace<double, 3, Mesh_t, Center_t>(i);
474 bc_m[i] =
new PeriodicFace<double, 3, Mesh_t, Center_t>(i);
480 bc_m[i] =
new ZeroFace<double, 3, Mesh_t, Center_t>(i);
486 *ippl::Info << level3 <<
"BC set for DC-Beam, longitudinal periodic" << endl);
492 for (
unsigned int i = 0; i <
Dimension; i++)
493 grid[i] = domain[i].length();
502 GuardCellSizes<Dimension>(1),
506 GuardCellSizes<Dimension>(1),
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
ippl::FieldLayout< Dim > FieldLayout_t
ippl::Field< double, Dim, ViewArgs... > Field_t
ippl::ParticleSpatialLayout< double, 3, Mesh_t > Layout_t
ippl::Field< ippl::Vector< T, Dim >, Dim, ViewArgs... > VField_t
ippl::UniformCartesian< double, 3 > Mesh_t
ippl::Vector< T, Dim > Vector_t
constexpr double c
The velocity of light in m/s.
long long localTrackStep_m
step in a TRACK command
void updateDomainLength(Vector_t< int, 3 > &grid)
void updateFields(const Vector_t< T, Dim > &, const Vector_t< T, Dim > &origin)
Vector_t< double, Dim > rmin_m
ParticleLayout< double, 3 > & getLayout()
const Mesh_t< Dim > & getMesh() const
std::pair< Vector_t< double, 3 >, Vector_t< double, 3 > > VectorPair_t
static const unsigned Dimension
ParticleAttrib< Vector_t< T, Dim > > Ef
void swap(unsigned int i, unsigned int j)
IpplParticleBase< Layout_t > pbase_t
void resetInterpolationCache(bool clearCache=false)
Vector_t< double, Dim > rmax_m
ParticleAttrib< double > dt
bool interpolationCacheSet_m
void get_bounds(Vector_t< T, Dim > &rmin, Vector_t< T, Dim > &rmax) const
size_t getLocalNum() const
Vector_t< double, Dim > R(size_t i)
ParticleAttrib< Vector_t< T, Dim > > P
ParticleAttrib< Vector_t< T, Dim > > Eftmp
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
VectorPair_t getEExtrema()
BConds< Vector_t< double, 3 >, 3, Mesh_t, Center_t > vbc_m
ParticleBConds< Position_t, Dimension > & getBConds()
PartBunch(PLayout &pl, Vector_t< double, Dim > hr, Vector_t< double, Dim > rmin, Vector_t< double, Dim > rmax, std::array< bool, Dim > decomp, double Qtot)
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
Vector_t< double, Dim > hr_m
mesh size [m]
void initialize(FieldLayout_t< Dim > &fl, Mesh_t< Dim > &mesh)
Inform & print(Inform &os)
FieldLayout_t< Dim > & getFieldLayout()
double getCouplingConstant() const
size_t getTotalNum() const
ParticleAttrib< double > Q
double getBinGamma(int bin)
Get gamma of one bin.
ParticleAttrib< Vector_t< T, Dim > > Bf
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.