OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
PartBunch.cpp
Go to the documentation of this file.
1//
2// Class PartBunch
3// Particle Bunch.
4// A representation of a particle bunch as a vector of particles.
5//
6// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
20
21#include <algorithm>
22#include <cfloat>
23#include <functional>
24#include <memory>
25#include <sstream>
26#include <string>
27#include <utility>
28#include <vector>
29
30#include <mpi.h>
31
35
36#include "Algorithms/ListElem.h"
40
41#ifdef DBG_SCALARFIELD
43#endif
44
45//#define FIELDSTDOUT
46
47PartBunch::PartBunch(const PartData *ref): // Layout is set using setSolver()
48 PartBunchBase<double, 3>(new PartBunch::pbase_t(new Layout_t()), ref),
49 interpolationCacheSet_m(false)
50{
51
52}
53
54
58
59// PartBunch::pbase_t* PartBunch::clone() {
60// return new pbase_t(new Layout_t());
61// }
62
63
65 Layout_t* layout = static_cast<Layout_t*>(&getLayout());
66 layout->getLayout().changeDomain(*fLayout);
67}
68
69
72
73 pbase_t* underlyingPbase =
74 dynamic_cast<pbase_t*>(pbase_m.get());
75
76 BinaryRepartition(*underlyingPbase);
77 update();
79 boundp();
80}
81
82
83void PartBunch::computeSelfFields(int binNumber) {
85
87 throw GeneralClassicException("PartBunch::computeSelfFields(int binNumber)",
88 "P3M solver not available during emission");
89 }
90
93 rho_m = 0.0;
94 Field_t imagePotential = rho_m;
95
97 eg_m = Vector_t(0.0);
98
99 if(fs_m->hasValidSolver()) {
101 resizeMesh();
102
104 checkUnmaskedInterpolation("PartBunch::computeSelfFields(int binNumber)");
105 this->Q *= this->dt;
109 } else {
111 getLocalNum(),
112 true);
113 }
115 this->Q.scatter(this->rho_m, this->R, IntrplCIC_t(), interpolationCache_m);
116 } else {
118 }
119
120 this->Q /= this->dt;
121 this->rho_m /= getdT();
122
124 double scaleFactor = 1;
125 // double scaleFactor = Physics::c * getdT();
126 double gammaz = getBinGamma(binNumber);
127
130 double tmp2 = 1 / hr_m[0] * 1 / hr_m[1] * 1 / hr_m[2] / (scaleFactor * scaleFactor * scaleFactor) / gammaz;
131 rho_m *= tmp2;
132
135 Vector_t hr_scaled = hr_m * Vector_t(scaleFactor);
136 hr_scaled[2] *= gammaz;
137
140 imagePotential = rho_m;
141
142 fs_m->solver_m->computePotential(rho_m, hr_scaled);
143
145 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
146
150
153 eg_m = -Grad(rho_m, eg_m);
154
157 eg_m *= Vector_t({gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz)});
158
159 // If desired write E-field and potential to terminal
160#ifdef FIELDSTDOUT
161 // Immediate debug output:
162 // Output potential and e-field along the x-, y-, and z-axes
163 int mx = (int)nr_m[0];
164 int mx2 = (int)nr_m[0] / 2;
165 int my = (int)nr_m[1];
166 int my2 = (int)nr_m[1] / 2;
167 int mz = (int)nr_m[2];
168 int mz2 = (int)nr_m[2] / 2;
169
170 for (int i=0; i<mx; i++ )
171 *gmsg << "Bin " << binNumber
172 << ", Self Field along x axis E = " << eg_m[i][my2][mz2]
173 << ", Pot = " << rho_m[i][my2][mz2] << endl;
174
175 for (int i=0; i<my; i++ )
176 *gmsg << "Bin " << binNumber
177 << ", Self Field along y axis E = " << eg_m[mx2][i][mz2]
178 << ", Pot = " << rho_m[mx2][i][mz2] << endl;
179
180 for (int i=0; i<mz; i++ )
181 *gmsg << "Bin " << binNumber
182 << ", Self Field along z axis E = " << eg_m[mx2][my2][i]
183 << ", Pot = " << rho_m[mx2][my2][i] << endl;
184#endif
185
191 //Eftmp.gather(eg_m, this->R, IntrplCIC_t());
192
200 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz / Physics::c;
201
202 Bf(0) = Bf(0) - betaC * Eftmp(1);
203 Bf(1) = Bf(1) + betaC * Eftmp(0);
204
205 Ef += Eftmp;
206
209
212 Vector_t origin = rho_m.get_mesh().get_origin();
213 double hz = rho_m.get_mesh().get_meshSpacing(2);
214 double zshift = -(2 * origin(2) + (domain[2].first() + domain[2].last() + 1) * hz) * gammaz * scaleFactor;
215
218 fs_m->solver_m->computePotential(imagePotential, hr_scaled, zshift);
219
221 imagePotential *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
222
225 imagePotential *= getCouplingConstant();
226
227#ifdef DBG_SCALARFIELD
228 const int dumpFreq = 100;
229 VField_t tmp_eg = eg_m;
230
231 if ((localTrackStep_m + 1) % dumpFreq == 0) {
232 FieldWriter fwriter;
233 fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m / dumpFreq, &imagePotential);
234 }
235#endif
236
240 eg_m = -Grad(imagePotential, eg_m);
241
244 eg_m *= Vector_t({gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz)});
245
246 // If desired write E-field and potential to terminal
247#ifdef FIELDSTDOUT
248 // Immediate debug output:
249 // Output potential and e-field along the x-, y-, and z-axes
250 //int mx = (int)nr_m[0];
251 //int mx2 = (int)nr_m[0] / 2;
252 //int my = (int)nr_m[1];
253 //int my2 = (int)nr_m[1] / 2;
254 //int mz = (int)nr_m[2];
255 //int mz2 = (int)nr_m[2] / 2;
256
257 for (int i=0; i<mx; i++ )
258 *gmsg << "Bin " << binNumber
259 << ", Image Field along x axis E = " << eg_m[i][my2][mz2]
260 << ", Pot = " << rho_m[i][my2][mz2] << endl;
261
262 for (int i=0; i<my; i++ )
263 *gmsg << "Bin " << binNumber
264 << ", Image Field along y axis E = " << eg_m[mx2][i][mz2]
265 << ", Pot = " << rho_m[mx2][i][mz2] << endl;
266
267 for (int i=0; i<mz; i++ )
268 *gmsg << "Bin " << binNumber
269 << ", Image Field along z axis E = " << eg_m[mx2][my2][i]
270 << ", Pot = " << rho_m[mx2][my2][i] << endl;
271#endif
272
273#ifdef DBG_SCALARFIELD
274 tmp_eg += eg_m;
275 if ((localTrackStep_m + 1) % dumpFreq == 0) {
276 FieldWriter fwriter;
277 fwriter.dumpField(tmp_eg, "e", "V/m", localTrackStep_m / dumpFreq);
278 }
279#endif
280
286 //Eftmp.gather(eg_m, this->R, IntrplCIC_t());
287
296 Bf(0) = Bf(0) + betaC * Eftmp(1);
297 Bf(1) = Bf(1) - betaC * Eftmp(0);
298
299 Ef += Eftmp;
300
301 }
303}
304
307 return;
308 }
309
310 double xmin = fs_m->solver_m->getXRangeMin();
311 double xmax = fs_m->solver_m->getXRangeMax();
312 double ymin = fs_m->solver_m->getYRangeMin();
313 double ymax = fs_m->solver_m->getYRangeMax();
314
315 if(xmin > rmin_m[0] || xmax < rmax_m[0] ||
316 ymin > rmin_m[1] || ymax < rmax_m[1]) {
317
318 for (unsigned int n = 0; n < getLocalNum(); n++) {
319
320 if(R[n](0) < xmin || R[n](0) > xmax ||
321 R[n](1) < ymin || R[n](1) > ymax) {
322
323 // delete the particle
324 INFOMSG(level2 << "destroyed particle with id=" << ID[n] << endl);
325 destroy(1, n);
326 }
327
328 }
329
330 update();
331 boundp();
333 }
334
335 Vector_t origin = Vector_t({0.0, 0.0, 0.0});
336
337 // update the mesh origin and mesh spacing hr_m
339
341 getMesh().set_origin(origin);
342
346 bc_m);
350 vbc_m);
351
352 update();
353
354// setGridIsFixed();
355}
356
359 rho_m = 0.0;
360 eg_m = Vector_t(0.0);
361
362 if(fs_m->hasValidSolver()) {
363 //mesh the whole domain
364 resizeMesh();
365
366 //scatter charges onto grid
367 checkUnmaskedInterpolation("PartBunch::computeSelfFields()");
368 this->Q *= this->dt;
369 this->Q.scatter(this->rho_m, this->R, IntrplCIC_t());
370 this->Q /= this->dt;
371 this->rho_m /= getdT();
372
373 //calculating mesh-scale factor
374 double gammaz = sum(this->P)[2] / getTotalNum();
375 gammaz *= gammaz;
376 gammaz = std::sqrt(gammaz + 1.0);
377 double scaleFactor = 1;
378 // double scaleFactor = Physics::c * getdT();
379 //and get meshspacings in real units [m]
380 Vector_t hr_scaled = hr_m * Vector_t(scaleFactor);
381 hr_scaled[2] *= gammaz;
382
383 //double tmp2 = 1/hr_m[0] * 1/hr_m[1] * 1/hr_m[2] / (scaleFactor*scaleFactor*scaleFactor) / gammaz;
384 double tmp2 = 1 / hr_scaled[0] * 1 / hr_scaled[1] * 1 / hr_scaled[2];
385 //divide charge by a 'grid-cube' volume to get [C/m^3]
386 rho_m *= tmp2;
387
388 double Npoints = nr_m[0] * nr_m[1] * nr_m[2];
389 rmsDensity_m = std::sqrt((1.0 /Npoints) * sum((rho_m / Physics::q_e) * (rho_m / Physics::q_e)));
390
392
393
394#ifdef DBG_SCALARFIELD
395 FieldWriter fwriter;
396 fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
397#endif
398
399 // charge density is in rho_m
400 fs_m->solver_m->computePotential(rho_m, hr_scaled);
401
402 //do the multiplication of the grid-cube volume coming
403 //from the discretization of the convolution integral.
404 //this is only necessary for the FFT solver
405 //FIXME: later move this scaling into FFTPoissonSolver
408 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
409 }
410
411 // the scalar potential is given back in rho_m in units
412 // [C/m] = [F*V/m] and must be divided by
413 // 4*pi*\epsilon_0 [F/m] resulting in [V]
415
416 //write out rho
417#ifdef DBG_SCALARFIELD
418 fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
419#endif
420
421 // IPPL Grad divides by hr_m [m] resulting in
422 // [V/m] for the electric field
423 eg_m = -Grad(rho_m, eg_m);
424
425 //write out e field
426#ifdef FIELDSTDOUT
427 // Immediate debug output:
428 // Output potential and e-field along the x-, y-, and z-axes
429 int mx = (int)nr_m[0];
430 int mx2 = (int)nr_m[0] / 2;
431 int my = (int)nr_m[1];
432 int my2 = (int)nr_m[1] / 2;
433 int mz = (int)nr_m[2];
434 int mz2 = (int)nr_m[2] / 2;
435
436 for (int i=0; i<mx; i++ )
437 *gmsg << "Field along x axis Ex = " << eg_m[i][my2][mz2] << " Pot = " << rho_m[i][my2][mz2] << endl;
438
439 for (int i=0; i<my; i++ )
440 *gmsg << "Field along y axis Ey = " << eg_m[mx2][i][mz2] << " Pot = " << rho_m[mx2][i][mz2] << endl;
441
442 for (int i=0; i<mz; i++ )
443 *gmsg << "Field along z axis Ez = " << eg_m[mx2][my2][i] << " Pot = " << rho_m[mx2][my2][i] << endl;
444#endif
445
446#ifdef DBG_SCALARFIELD
447 fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
448#endif
449
450 // interpolate electric field at particle positions. We reuse the
451 // cached information about where the particles are relative to the
452 // field, since the particles have not moved since this the most recent
453 // scatter operation.
454 Ef.gather(eg_m, this->R, IntrplCIC_t());
455
457 fs_m->solver_m->calculatePairForces(this,gammaz);
458 }
459
460 Ef = Ef * Vector_t({gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz)});
461
469 double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz / Physics::c;
470
471 Bf(0) = Bf(0) - betaC * Ef(1);
472 Bf(1) = Bf(1) + betaC * Ef(0);
473 }
475}
476
491
492 if (getTotalNum() == 0) {
493 return;
494 }
495
497 std::size_t numGridPoints = static_cast<std::size_t>(nr_m[0]) * static_cast<std::size_t>(nr_m[1]) * static_cast<std::size_t>(nr_m[2]);
498 if (getTotalNum() < numGridPoints) {
499 WARNMSG("The number of particles decreased below the grid points. Skip space-charge calculation." << endl);
500 return;
501 }
502 }
503
505
507 throw GeneralClassicException("PartBunch::computeSelfFields_cycl(double gamma)",
508 "P3M solver not available yet for cyclotrons");
509 }
510
512 rho_m = 0.0;
513
515 eg_m = Vector_t(0.0);
516
517 if (fs_m->hasValidSolver()) {
519 resizeMesh();
520
524 scStatistics_m.meshSpacing = hr_m;
525 }
526
530 const bool coreMesh = isMeshFitToCore();
531 std::vector<CoreFitSC::ParticleClass> particleClass;
532 ParticleMask_t isCore;
533 if (coreMesh) {
534 const size_t localNum = getLocalNum();
535 const ParticleAttrib<Vector_t>& Rc = this->R;
536 const ParticleAttrib<int>& Binc = this->Bin;
537 particleClass.resize(localNum);
538 for (size_t i = 0; i < localNum; ++i) {
539 particleClass[i] = CoreFitSC::classify(Binc[i], Rc[i],
542 }
543 isCore = [&particleClass](size_t i) {
544 return particleClass[i] == CoreFitSC::ParticleClass::CORE;
545 };
546 } else {
547 checkUnmaskedInterpolation("PartBunch::computeSelfFields_cycl(double gamma)");
548 }
549
552 scatterMasked(isCore);
553
556 Vector_t hr_scaled = hr_m ;
557 hr_scaled[1] *= gamma;
558
560 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
561 rho_m *= tmp2;
562
563 // Diagnostics for the stat file only: a field reduction and two particle passes
564 // with collectives, skipped when the tracker says no stat row needs them. On a mesh
565 // fitted to the core (MESHFIT=CORE) the rms density, and with it the Debye length,
566 // are those of the core charge on the core mesh.
568 double Npoints = nr_m[0] * nr_m[1] * nr_m[2];
569 rmsDensity_m = std::sqrt((1.0 /Npoints) * sum((rho_m / Physics::q_e) * (rho_m / Physics::q_e)));
570
572 }
573
574 // If debug flag is set, dump scalar field (charge density 'rho') into file under ./data/
575#ifdef DBG_SCALARFIELD
576 FieldWriter fwriter;
577 fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
578#endif
579
582 fs_m->solver_m->computePotential(rho_m, hr_scaled);
583
584 //do the multiplication of the grid-cube volume coming
585 //from the discretization of the convolution integral.
586 //this is only necessary for the FFT solver
587 //TODO FIXME: later move this scaling into FFTPoissonSolver
590 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
591 }
592
595
596 // If debug flag is set, dump scalar field (potential 'phi') into file under ./data/
597#ifdef DBG_SCALARFIELD
598 fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
599#endif
600
602 eg_m = -Grad(rho_m, eg_m);
603
608 eg_m *= Vector_t({gamma, 1.0 / gamma, gamma});
609
610#ifdef FIELDSTDOUT
611 // Immediate debug output:
612 // Output potential and e-field along the x-, y-, and z-axes
613 int mx = (int)nr_m[0];
614 int mx2 = (int)nr_m[0] / 2;
615 int my = (int)nr_m[1];
616 int my2 = (int)nr_m[1] / 2;
617 int mz = (int)nr_m[2];
618 int mz2 = (int)nr_m[2] / 2;
619
620 for (int i=0; i<mx; i++ )
621 *gmsg << "Field along x axis Ex = " << eg_m[i][my2][mz2] << " Pot = " << rho_m[i][my2][mz2] << endl;
622
623 for (int i=0; i<my; i++ )
624 *gmsg << "Field along y axis Ey = " << eg_m[mx2][i][mz2] << " Pot = " << rho_m[mx2][i][mz2] << endl;
625
626 for (int i=0; i<mz; i++ )
627 *gmsg << "Field along z axis Ez = " << eg_m[mx2][my2][i] << " Pot = " << rho_m[mx2][my2][i] << endl;
628#endif
629
630#ifdef DBG_SCALARFIELD
631 fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
632#endif
633
634 if (coreMesh) {
637 gatherMasked([&particleClass](size_t i) {
638 return particleClass[i] != CoreFitSC::ParticleClass::FAR;
639 });
640 computeFarField(gamma, particleClass);
641 } else {
643 Ef.gather(eg_m, this->R, IntrplCIC_t());
644 }
645
647 // Relativistic E&M says gamma*v/c^2 = gamma*beta/c = sqrt(gamma*gamma-1)/c
648 // but because we already transformed E_trans into the moving frame we have to
649 // add 1/gamma so we are using the E_trans from the rest frame -DW
650 double betaC = std::sqrt(gamma * gamma - 1.0) / gamma / Physics::c;
651
653 Bf(0) = betaC * Ef(2);
654 Bf(2) = -betaC * Ef(0);
655 }
656
657 /*
658 *gmsg << "gamma =" << gamma << endl;
659 *gmsg << "dx,dy,dz =(" << hr_m[0] << ", " << hr_m[1] << ", " << hr_m[2] << ") [m] " << endl;
660 *gmsg << "max of bunch is (" << rmax_m(0) << ", " << rmax_m(1) << ", " << rmax_m(2) << ") [m] " << endl;
661 *gmsg << "min of bunch is (" << rmin_m(0) << ", " << rmin_m(1) << ", " << rmin_m(2) << ") [m] " << endl;
662 */
663
665}
666
686
688 throw GeneralClassicException("PartBunch::computeSelfFields_cycl(int bin)",
689 "P3M solver not available yet for cyclotrons");
690 }
691
693 rho_m = 0.0;
694
696 eg_m = Vector_t(0.0);
697
699 double gamma = getBinGamma(bin);
700
701 if(fs_m->hasValidSolver()) {
703 resizeMesh();
704
706 checkUnmaskedInterpolation("PartBunch::computeSelfFields_cycl(int bin)");
707 this->Q.scatter(this->rho_m, this->R, IntrplCIC_t());
708
711 Vector_t hr_scaled = hr_m ;
712 hr_scaled[1] *= gamma;
713
715 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
716 rho_m *= tmp2;
717
718 // If debug flag is set, dump scalar field (charge density 'rho') into file under ./data/
719#ifdef DBG_SCALARFIELD
720 FieldWriter fwriter;
721 fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
722#endif
723
726 fs_m->solver_m->computePotential(rho_m, hr_scaled);
727
728 // Do the multiplication of the grid-cube volume coming from the discretization of the convolution integral.
729 // This is only necessary for the FFT solver. FIXME: later move this scaling into FFTPoissonSolver
732 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
733 }
734
737
738 // If debug flag is set, dump scalar field (potential 'phi') into file under ./data/
739#ifdef DBG_SCALARFIELD
740 fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
741#endif
742
744 eg_m = -Grad(rho_m, eg_m);
745
750 eg_m *= Vector_t({gamma, 1.0 / gamma, gamma});
751
752#ifdef FIELDSTDOUT
753 // Immediate debug output:
754 // Output potential and e-field along the x-, y-, and z-axes
755 int mx = (int)nr_m[0];
756 int mx2 = (int)nr_m[0] / 2;
757 int my = (int)nr_m[1];
758 int my2 = (int)nr_m[1] / 2;
759 int mz = (int)nr_m[2];
760 int mz2 = (int)nr_m[2] / 2;
761
762 for (int i=0; i<mx; i++ )
763 *gmsg << "Bin " << bin
764 << ", Field along x axis Ex = " << eg_m[i][my2][mz2]
765 << ", Pot = " << rho_m[i][my2][mz2] << endl;
766
767 for (int i=0; i<my; i++ )
768 *gmsg << "Bin " << bin
769 << ", Field along y axis Ey = " << eg_m[mx2][i][mz2]
770 << ", Pot = " << rho_m[mx2][i][mz2] << endl;
771
772 for (int i=0; i<mz; i++ )
773 *gmsg << "Bin " << bin
774 << ", Field along z axis Ez = " << eg_m[mx2][my2][i]
775 << ", Pot = " << rho_m[mx2][my2][i] << endl;
776#endif
777
778 // If debug flag is set, dump vector field (electric field) into file under ./data/
779#ifdef DBG_SCALARFIELD
780 fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
781#endif
782
784 Eftmp.gather(eg_m, this->R, IntrplCIC_t());
785
786
787
789 double betaC = std::sqrt(gamma * gamma - 1.0) / gamma / Physics::c;
790
792 Bf(0) = Bf(0) + betaC * Eftmp(2);
793 Bf(2) = Bf(2) - betaC * Eftmp(0);
794
795 Ef += Eftmp;
796 }
797
798 /*
799 *gmsg << "gamma =" << gamma << endl;
800 *gmsg << "dx,dy,dz =(" << hr_m[0] << ", " << hr_m[1] << ", " << hr_m[2] << ") [m] " << endl;
801 *gmsg << "max of bunch is (" << rmax_m(0) << ", " << rmax_m(1) << ", " << rmax_m(2) << ") [m] " << endl;
802 *gmsg << "min of bunch is (" << rmin_m(0) << ", " << rmin_m(1) << ", " << rmin_m(2) << ") [m] " << endl;
803 */
804
805
807}
808
809
821 std::vector<std::pair<size_t, double>> lostCharge;
822 if (accept) {
823 const size_t localNum = getLocalNum();
824 if (maskedQ_m.size() < localNum) {
825 const size_t missing = localNum - maskedQ_m.size();
826 maskedQ_m.create(missing);
827 maskedR_m.create(missing);
828 }
829 size_t numAccepted = 0;
830 for (size_t i = 0; i < localNum; ++i) {
831 if (this->Bin[i] >= 0 && accept(i)) {
832 maskedQ_m[numAccepted] = this->Q[i];
833 maskedR_m[numAccepted] = this->R[i];
834 ++numAccepted;
835 }
836 }
837 const size_t numUnused = maskedQ_m.size() - numAccepted;
838 maskedQ_m.destroy(numUnused, numAccepted);
839 maskedR_m.destroy(numUnused, numAccepted);
840 } else {
841 for (size_t i = 0; i < getLocalNum(); ++i) {
842 if (this->Bin[i] < 0) {
843 lostCharge.emplace_back(i, this->Q[i]);
844 this->Q[i] = 0.0;
845 }
846 }
847 }
848
849 const ParticleAttrib<double>& charge = accept ? maskedQ_m : this->Q;
850 const ParticleAttrib<Vector_t>& position = accept ? maskedR_m : this->R;
851 charge.scatter(rho_m, position, IntrplCIC_t());
852
853 for (const auto& lost : lostCharge) {
854 this->Q[lost.first] = lost.second;
855 }
856}
857
858
862 if (eg_m.isDirty()) {
863 eg_m.fillGuardCells(true);
864 }
865
866 const Mesh_t& mesh = eg_m.get_mesh();
867 for (size_t i = 0; i < getLocalNum(); ++i) {
868 if (accept(i)) {
869 IntrplCIC_t::gather(Ef[i], eg_m, this->R[i], mesh);
870 }
871 }
872
873 eg_m.Compress();
874}
875
876
878 const std::vector<CoreFitSC::ParticleClass>& particleClass) {
880
881 typedef CoreFitSC::ParticleClass Class_t;
882 const int numNodes = Ippl::getNodes();
883 const int myNode = Ippl::myNode();
884 MPI_Comm comm = Ippl::getComm();
885 const size_t localNum = getLocalNum();
886 const ParticleAttrib<Vector_t>& Rc = this->R;
887 const ParticleAttrib<double>& Qc = this->Q;
888 const ParticleAttrib<int>& Binc = this->Bin;
889 const ParticleIndex_t& IDc = this->ID;
890
891 // rest-frame positions about the centre of the core bounds, for conditioning
892 const Vector_t centre = 0.5 * (scBoxMin_m + scBoxMax_m);
893
894 // This rank's part of the far table: the particles outside the core bounds, with their
895 // rest-frame position, charge (0 for those flagged lost), class (1 for FAR, 0 for MESH)
896 // and ID, which picks the subsample of the far-far sources.
897 const int tableWidth = 6;
898 std::vector<size_t> farIndex;
899 std::vector<double> localTable;
900 for (size_t i = 0; i < localNum; ++i) {
901 if (particleClass[i] != Class_t::MESH && particleClass[i] != Class_t::FAR) {
902 continue;
903 }
904 const Vector_t s = CoreFitSC::toRestFrame(Rc[i], centre, gamma);
905 farIndex.push_back(i);
906 localTable.insert(localTable.end(),
907 {s(0), s(1), s(2), Binc[i] >= 0 ? Qc[i] : 0.0,
908 particleClass[i] == Class_t::FAR ? 1.0 : 0.0,
909 static_cast<double>(IDc[i])});
910 }
911
912 // the table of all ranks, in rank order
913 const int localCount = farIndex.size();
914 std::vector<int> counts(numNodes), offsets(numNodes + 1, 0);
915 MPI_Allgather(&localCount, 1, MPI_INT, counts.data(), 1, MPI_INT, comm);
916 for (int p = 0; p < numNodes; ++p) {
917 offsets[p + 1] = offsets[p] + counts[p];
918 }
919 const size_t numTable = offsets[numNodes];
920 scStatistics_m.numFlagged = 0;
921 if (numTable == 0) {
923 return;
924 }
925
926 // monopole, centroid and quadrupole of the charge on the mesh
927 CoreFitSC::MomentSums sums(centre, gamma);
928 for (size_t i = 0; i < localNum; ++i) {
929 if (particleClass[i] == Class_t::CORE) {
930 sums.add(Qc[i], Rc[i]);
931 }
932 }
934
935 std::vector<int> recvCounts(numNodes), displs(numNodes);
936 for (int p = 0; p < numNodes; ++p) {
937 recvCounts[p] = tableWidth * counts[p];
938 displs[p] = tableWidth * offsets[p];
939 }
940 std::vector<double> table(tableWidth * numTable);
941 MPI_Allgatherv(localTable.data(), tableWidth * localCount, MPI_DOUBLE,
942 table.data(), recvCounts.data(), displs.data(), MPI_DOUBLE, comm);
943
944 // The live entries are the sources and the targets of the far-far field. The entries of
945 // particles flagged lost get the multipole field (FAR) or keep their mesh field (MESH).
946 std::vector<Vector_t> position(numTable);
947 std::vector<size_t> liveRow;
948 std::vector<Vector_t> livePosition;
949 for (size_t j = 0; j < numTable; ++j) {
950 const double* entry = &table[tableWidth * j];
951 position[j] = Vector_t({entry[0], entry[1], entry[2]});
952 if (entry[3] != 0.0) {
953 liveRow.push_back(j);
954 livePosition.push_back(position[j]);
955 }
956 }
957 const size_t numLive = liveRow.size();
958
959 // This rank's share of the table and of its live entries, by index: the far particles
960 // sit on the few ranks that own the faces of the mesh nearest to them.
961 const std::pair<size_t, size_t> range = CoreFitSC::getTableRange(numTable, myNode, numNodes);
962 const std::pair<size_t, size_t> liveRange = CoreFitSC::getTableRange(numLive, myNode,
963 numNodes);
964 const FarFieldModel model = meshFit_m.farField;
965 std::vector<Vector_t> multipole(numTable);
966 std::vector<double> indicator(numTable);
967 CoreFitSC::computeMultipoleField(moments, position, range.first, range.second,
968 model != FarFieldModel::MONOPOLE, multipole, indicator);
969 std::vector<Vector_t> liveFarFar(numLive, Vector_t(0.0));
970 size_t farFarStride = 1;
971 if (model == FarFieldModel::FULL) {
972 // Above CoreFitSC::maxFarFarPairs pairs the sources are the live entries whose ID is
973 // in the subsample, with their charge scaled to that of all live entries.
974 farFarStride = CoreFitSC::getSampleStride(numLive, numLive, CoreFitSC::maxFarFarPairs);
975 std::vector<Vector_t> sourcePosition;
976 std::vector<double> sourceCharge;
977 double liveCharge = 0.0;
978 double sampledCharge = 0.0;
979 for (const size_t j: liveRow) {
980 const double* entry = &table[tableWidth * j];
981 liveCharge += entry[3];
982 if (CoreFitSC::isSampled(static_cast<size_t>(entry[5]), farFarStride)) {
983 sourcePosition.push_back(position[j]);
984 sourceCharge.push_back(entry[3]);
985 sampledCharge += entry[3];
986 }
987 }
988 if (farFarStride > 1 && sampledCharge != 0.0) {
989 const double scale = liveCharge / sampledCharge;
990 for (double& q: sourceCharge) {
991 q *= scale;
992 }
993 }
994 // softened by the smallest rest-frame cell of the core mesh
995 const double eps = std::min({hr_m[0], gamma * hr_m[1], hr_m[2]});
996 CoreFitSC::addDirectField(livePosition, liveRange.first, liveRange.second,
997 sourcePosition, sourceCharge, eps, liveFarFar);
998 }
999
1000 // The results of all ranks: the multipole field and the indicator of their share of the
1001 // table, then the far-far field of their share of the live entries.
1002 std::vector<double> localResult;
1003 localResult.reserve(4 * (range.second - range.first) +
1004 3 * (liveRange.second - liveRange.first));
1005 for (size_t j = range.first; j < range.second; ++j) {
1006 localResult.insert(localResult.end(),
1007 {multipole[j](0), multipole[j](1), multipole[j](2), indicator[j]});
1008 }
1009 for (size_t k = liveRange.first; k < liveRange.second; ++k) {
1010 localResult.insert(localResult.end(),
1011 {liveFarFar[k](0), liveFarFar[k](1), liveFarFar[k](2)});
1012 }
1013 int numResults = 0;
1014 for (int p = 0; p < numNodes; ++p) {
1015 const std::pair<size_t, size_t> rangeP = CoreFitSC::getTableRange(numTable, p, numNodes);
1016 const std::pair<size_t, size_t> liveRangeP = CoreFitSC::getTableRange(numLive, p,
1017 numNodes);
1018 recvCounts[p] = 4 * (rangeP.second - rangeP.first) +
1019 3 * (liveRangeP.second - liveRangeP.first);
1020 displs[p] = numResults;
1021 numResults += recvCounts[p];
1022 }
1023 std::vector<double> result(numResults);
1024 MPI_Allgatherv(localResult.data(), static_cast<int>(localResult.size()), MPI_DOUBLE,
1025 result.data(), recvCounts.data(), displs.data(), MPI_DOUBLE, comm);
1026 std::vector<Vector_t> farFar(numTable, Vector_t(0.0));
1027 for (int p = 0; p < numNodes; ++p) {
1028 const std::pair<size_t, size_t> rangeP = CoreFitSC::getTableRange(numTable, p, numNodes);
1029 const std::pair<size_t, size_t> liveRangeP = CoreFitSC::getTableRange(numLive, p,
1030 numNodes);
1031 const double* entry = &result[displs[p]];
1032 for (size_t j = rangeP.first; j < rangeP.second; ++j, entry += 4) {
1033 multipole[j] = Vector_t({entry[0], entry[1], entry[2]});
1034 indicator[j] = entry[3];
1035 }
1036 for (size_t k = liveRangeP.first; k < liveRangeP.second; ++k, entry += 3) {
1037 farFar[liveRow[k]] = Vector_t({entry[0], entry[1], entry[2]});
1038 }
1039 }
1040
1041 // The live FAR entries where the expansion is not valid get the exact field of the core
1042 // particles instead: every rank sums over its own, one sum over the ranks. Above
1043 // CoreFitSC::maxCorePairsPerCore pairs per core particle, the core particles in the outer
1044 // shell of the box and the others are summed apart (one more sum, of the shell count),
1045 // each over the particles whose ID is in its subsample if its pairs exceed that budget,
1046 // with their charge scaled to that of the part (one more sum).
1047 std::vector<size_t> flagged;
1048 for (const size_t j: liveRow) {
1049 const Class_t c = (table[tableWidth * j + 4] != 0.0 ? Class_t::FAR : Class_t::MESH);
1050 if (CoreFitSC::needsExactCoreField(c, indicator[j])) {
1051 flagged.push_back(j);
1052 }
1053 }
1054 scStatistics_m.numFlagged = flagged.size();
1055 // strides of the core particles in the shell of the box and of the others
1056 size_t coreStride[2] = {1, 1};
1057 if (model == FarFieldModel::FULL && !flagged.empty()) {
1059 std::vector<Vector_t> target(flagged.size());
1060 for (size_t k = 0; k < flagged.size(); ++k) {
1061 target[k] = position[flagged[k]];
1062 }
1063
1064 const double maxPairs = CoreFitSC::maxCorePairsPerCore * scNumCore_m;
1065 const bool split = (static_cast<double>(flagged.size()) * scNumCore_m > maxPairs);
1066 if (split) {
1067 double numShell = 0.0;
1068 for (size_t i = 0; i < localNum; ++i) {
1069 if (particleClass[i] == Class_t::CORE &&
1071 numShell += 1.0;
1072 }
1073 }
1074 allreduce(&numShell, 1, std::plus<double>());
1075 const size_t numShellCore = static_cast<size_t>(numShell);
1076 coreStride[0] = CoreFitSC::getSampleStride(flagged.size(), numShellCore, maxPairs);
1077 coreStride[1] = CoreFitSC::getSampleStride(flagged.size(),
1078 scNumCore_m - numShellCore, maxPairs);
1079 }
1080
1081 // the sources of the two parts (all of them in the first without a split), and the
1082 // charge of each part and of its subsample
1083 std::vector<Vector_t> corePosition[2];
1084 std::vector<double> coreCharge[2];
1085 double charges[4] = {0.0, 0.0, 0.0, 0.0};
1086 for (size_t i = 0; i < localNum; ++i) {
1087 if (particleClass[i] != Class_t::CORE) {
1088 continue;
1089 }
1090 const int part = (split && !CoreFitSC::isInCoreShell(Rc[i], scBoxMin_m,
1091 scBoxMax_m)) ? 1 : 0;
1092 charges[2 * part] += Qc[i];
1093 if (CoreFitSC::isSampled(IDc[i], coreStride[part])) {
1094 corePosition[part].push_back(CoreFitSC::toRestFrame(Rc[i], centre, gamma));
1095 coreCharge[part].push_back(Qc[i]);
1096 charges[2 * part + 1] += Qc[i];
1097 }
1098 }
1099 const bool sampled = (coreStride[0] > 1 || coreStride[1] > 1);
1100 if (sampled) {
1101 allreduce(charges, 4, std::plus<double>());
1102 ++ scStatistics_m.nearSampled;
1103 }
1104 std::vector<Vector_t> exact(flagged.size(), Vector_t(0.0));
1105 for (int part = 0; part < 2; ++part) {
1106 if (coreStride[part] > 1 && charges[2 * part + 1] != 0.0) {
1107 const double scale = charges[2 * part] / charges[2 * part + 1];
1108 for (double& q: coreCharge[part]) {
1109 q *= scale;
1110 }
1111 }
1112 CoreFitSC::addDirectField(target, 0, flagged.size(), corePosition[part],
1113 coreCharge[part], 0.0, exact);
1114 }
1115 allreduce(&(exact[0](0)), 3 * static_cast<int>(flagged.size()), std::plus<double>());
1116 for (size_t k = 0; k < flagged.size(); ++k) {
1117 multipole[flagged[k]] = exact[k];
1118 }
1120 }
1121
1122 // Lab-frame field of this rank's particles, with the coupling constant of the mesh
1123 // field; the MESH particles have their mesh field already.
1124 const double couplingConstant = getCouplingConstant();
1125 for (int j = 0; j < localCount; ++j) {
1126 const size_t row = offsets[myNode] + j;
1127 const size_t i = farIndex[j];
1128 if (particleClass[i] == Class_t::FAR) {
1129 Ef[i] = couplingConstant * CoreFitSC::toLabFrame(multipole[row] + farFar[row], gamma);
1130 } else {
1131 Ef[i] += couplingConstant * CoreFitSC::toLabFrame(farFar[row], gamma);
1132 }
1133 }
1134
1135 if (farFarStride > 1) {
1136 ++ scStatistics_m.farFarSampled;
1137 std::ostringstream message;
1138 message << "the far-far field of the " << numLive << " far particles is summed over "
1139 << "about 1 in " << farFarStride << " of them, as " << numLive << " x "
1140 << numLive << " pairs exceed " << CoreFitSC::maxFarFarPairs;
1141 warnMeshFitOnce(FarFarWarning, message.str());
1142 }
1143
1145}
1146
1147
1148void PartBunch::checkUnmaskedInterpolation(const std::string& where) const {
1149 if (meshFit_m.type == MeshFitType::CORE && scStatistics_m.numOutside > 0) {
1151 "FIELDSOLVER, MESHFIT=\"CORE\": " +
1152 std::to_string(scStatistics_m.numOutside) +
1153 " particles are outside the space-charge mesh, which "
1154 "the unmasked charge scatter and field gather cannot "
1155 "handle.");
1156 }
1157}
1158
1159
1160// void PartBunch::setMesh(Mesh_t* mesh) {
1161// Layout_t* layout = static_cast<Layout_t*>(&getLayout());
1162// // layout->getLayout().setMesh(mesh);
1163// }
1164
1165
1166// void PartBunch::setFieldLayout(FieldLayout_t* fLayout) {
1167// Layout_t* layout = static_cast<Layout_t*>(&getLayout());
1168// // layout->getLayout().setFieldLayout(fLayout);
1169// // layout->rebuild_neighbor_data();
1170// layout->getLayout().changeDomain(*fLayout);
1171// }
1172
1173
1175 Layout_t* layout = static_cast<Layout_t*>(&getLayout());
1176 return dynamic_cast<FieldLayout_t &>(layout->getLayout().getFieldLayout());
1177}
1178
1180 for (int i = 0; i < 2 * 3; ++i) {
1181
1182 if (Ippl::getNodes()>1) {
1184 //std periodic boundary conditions for gradient computations etc.
1186 }
1187 else {
1189 //std periodic boundary conditions for gradient computations etc.
1191 }
1193 }
1194 dcBeam_m=true;
1195 INFOMSG(level3 << "BC set all periodic" << endl);
1196}
1197
1199 for (int i = 0; i < 2 * 3; ++i) {
1203 }
1204 dcBeam_m=false;
1205 INFOMSG(level3 << "BC set for normal Beam" << endl);
1206}
1207
1209 for (int i = 0; i < 2 * 3; ++ i) {
1210 if (i >= 4) {
1211 if (Ippl::getNodes() > 1) {
1214 } else {
1217 }
1218
1220 } else {
1224 }
1225 }
1226 dcBeam_m=true;
1227 INFOMSG(level3 << "BC set for DC-Beam, longitudinal periodic" << endl);
1228}
1229
1230
1232 NDIndex<3> domain = getFieldLayout().getDomain();
1233 for (unsigned int i = 0; i < Dimension; i++)
1234 grid[i] = domain[i].length();
1235}
1236
1237
1238void PartBunch::updateFields(const Vector_t& /*hr*/, const Vector_t& origin) {
1239 getMesh().set_meshSpacing(&(hr_m[0]));
1240 getMesh().set_origin(origin);
1244 bc_m);
1248 vbc_m);
1249}
1250
1251inline
1253 const Vector_t maxE = max(eg_m);
1254 // const double maxL = max(dot(eg_m,eg_m));
1255 const Vector_t minE = min(eg_m);
1256 // INFOMSG("MaxE= " << maxE << " MinE= " << minE << endl);
1257 return VectorPair_t(maxE, minE);
1258}
1259
1260
1261inline
1264 if(clearCache) {
1266 }
1267}
1268
1269void PartBunch::swap(unsigned int i, unsigned int j) {
1270
1271 // FIXME
1273
1276}
1277
1278
FarFieldModel
Field of the particles outside the core-fitted mesh (MESHFITFARFIELD)
Definition FieldSolver.h:58
Inform * gmsg
Definition Main.cpp:70
IntCIC IntrplCIC_t
Definition PBunchDefs.h:17
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)
void BinaryRepartition(FieldLayout< Dim > &layout, BareField< double, Dim > &weights)
T ParticlePeriodicBCond(const T t, const T minval, const T maxval)
T ParticleNoBCond(const T t, const T, const T)
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)
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Definition PETE.h:1111
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)
void allreduce(const T *input, T *output, int count, Op op)
#define INFOMSG(msg)
Definition IpplInfo.h:348
#define WARNMSG(msg)
Definition IpplInfo.h:349
Inform & level2(Inform &inf)
Definition Inform.cpp:46
Inform & endl(Inform &inf)
Definition Inform.cpp:42
Inform & level3(Inform &inf)
Definition Inform.cpp:47
constexpr double maxFarFarPairs
Definition CoreFitSC.h:66
constexpr double maxCorePairsPerCore
Definition CoreFitSC.h:72
void addDirectField(const std::vector< Vector_t > &target, std::size_t begin, std::size_t end, const std::vector< Vector_t > &source, const std::vector< double > &charge, double eps, std::vector< Vector_t > &field)
ParticleClass classify(int bin, const Vector_t &r, const Vector_t &boundsMin, const Vector_t &boundsMax, const Vector_t &meshMin, const Vector_t &meshMax)
void computeMultipoleField(const CoreMoments &moments, const std::vector< Vector_t > &position, std::size_t begin, std::size_t end, bool withQuadrupole, std::vector< Vector_t > &field, std::vector< double > &indicator)
std::pair< std::size_t, std::size_t > getTableRange(std::size_t n, int rank, int numRanks)
bool isInCoreShell(const Vector_t &r, const Vector_t &lower, const Vector_t &upper)
bool needsExactCoreField(ParticleClass c, double indicator)
Definition CoreFitSC.h:252
@ FAR
outside that range: multipole (or exact core) field, plus far-far
@ CORE
live, inside the core bounds: deposited, field gathered from the mesh
bool isSampled(std::size_t id, std::size_t stride)
Definition CoreFitSC.h:290
std::size_t getSampleStride(std::size_t numTargets, std::size_t numSources, double maxPairs)
Vector_t toRestFrame(const Vector_t &r, const Vector_t &r0, double gamma)
Definition CoreFitSC.h:198
Vector_t toLabFrame(const Vector_t &E, double gamma)
Definition CoreFitSC.h:205
constexpr double q_e
The elementary charge in As.
Definition Physics.h:69
constexpr double c
The velocity of light in m/s.
Definition Physics.h:45
ParticleAttrib< Vector_t > Ef
std::shared_ptr< AbstractParticle< double, Dim > > pbase_m
long long localTrackStep_m
step in a TRACK command
ParticleAttrib< int > Bin
void get_bounds(Vector_t &rmin, Vector_t &rmax) const
ParticleAttrib< Vector_t > Eftmp
Vector_t rmax_m
maximal extend of particles
ParticleBConds< Position_t, Dimension > & getBConds()
ParticleAttrib< Vector_t > P
Inform & print(Inform &os)
MeshFitStatistics scStatistics_m
IpplTimings::TimerRef farFieldTimer_m
double getBinGamma(int bin)
Get gamma of one bin.
ParticleAttrib< double > Q
Vector_t rmin_m
minimal extend of particles
bool computeSCDiagnostics_m
See setComputeSCDiagnostics().
FieldSolver * fs_m
stores the used field solver
std::pair< Vector_t, Vector_t > VectorPair_t
void warnMeshFitOnce(MeshFitWarning warning, const std::string &message)
double dh_m
Mesh enlargement.
ParticleAttrib< double > dt
static const unsigned Dimension
Vector_t hr_m
meshspacing of cartesian mesh
MeshFitParameters meshFit_m
relative enlargement of the mesh
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 exactCoreTimer_m
void calcDebyeLength()
Compute the (global) Debye length for the beam.
Vektor< int, 3 > nr_m
meshsize of cartesian mesh
IpplTimings::TimerRef selfFieldTimer_m
timer for selfField calculation
size_t size(void) const
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &) const
virtual void destroy(size_t M, size_t I, bool optDestroy=true)
virtual void create(size_t)
All IPPL nodes, through allreduce().
Definition CoreFitSC.h:110
Rest-frame moments of the core charge.
Definition CoreFitSC.h:210
void add(double q, const Vector_t &r)
Adds a particle of charge q at r (local frame, not rest frame)
CoreMoments reduce(const Reducer &reducer) const
Moments of all ranks' particles: one sum of 10 doubles.
void resetInterpolationCache(bool clearCache=false)
ParticleAttrib< double > maskedQ_m
scatterMasked(): the charges and positions of the particles that a predicate accepts
Definition PartBunch.h:172
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
Definition PartBunch.h:163
void computeSelfFields()
void scatterMasked(const ParticleMask_t &accept)
CIC scatter of Q onto rho_m, of the particles with Bin >= 0 and accept(i) true.
void do_binaryRepart()
Definition PartBunch.cpp:70
Field_t rho_m
scalar potential
Definition PartBunch.h:120
PartBunch()=delete
void swap(unsigned int i, unsigned int j)
void computeFarField(double gamma, const std::vector< CoreFitSC::ParticleClass > &particleClass)
MESHFIT=CORE: field of the particles outside the core bounds.
ParticleLayout< double, 3 > & getLayout()
Definition PartBunch.h:176
void initialize(FieldLayout_t *fLayout)
Definition PartBunch.cpp:64
void gatherMasked(const ParticleMask_t &accept)
CIC gather of eg_m into Ef, at the particles with accept(i) true.
void setBCAllOpen()
bool interpolationCacheSet_m
Definition PartBunch.h:167
Inform & print(Inform &os)
ParticleAttrib< Vector_t > maskedR_m
Definition PartBunch.h:173
void checkUnmaskedInterpolation(const std::string &where) const
void updateDomainLength(Vektor< int, 3 > &grid)
void setBCForDCBeam()
FieldLayout_t & getFieldLayout()
VField_t eg_m
vector field on the grid
Definition PartBunch.h:123
VectorPair_t getEExtrema()
void setBCAllPeriodic()
const Mesh_t & getMesh() const
Definition PartBunch.h:194
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
Definition PartBunch.h:169
void resizeMesh()
resize mesh to geometry specified
BConds< Vector_t, 3, Mesh_t, Center_t > vbc_m
Definition PartBunch.h:164
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)
std::function< bool(size_t)> ParticleMask_t
Per-particle predicate on the local index, for scatterMasked() and gatherMasked().
Definition PartBunch.h:96
virtual void computePotential(Field_t &rho, Vector_t hr)=0
virtual double getYRangeMin(unsigned short level=0)=0
virtual double getXRangeMin(unsigned short level=0)=0
virtual void calculatePairForces(PartBunchBase< double, 3 > *, double)
virtual void resizeMesh(Vector_t &, Vector_t &, const Vector_t &, const Vector_t &, double)
virtual double getYRangeMax(unsigned short level=0)=0
virtual double getXRangeMax(unsigned short level=0)=0
FarFieldModel farField
Definition FieldSolver.h:71
MeshFitType type
Definition FieldSolver.h:67
PoissonSolver * solver_m
the actual solver, should be a base object
FieldSolverType getFieldSolverType() const
bool hasValidSolver()
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.
void initialize(Layout_t &)
void fillGuardCells(bool reallyFill=true) const
Mesh_t & get_mesh() const
Definition Field.h:110
bool isDirty() const
Definition BareField.h:116
void Uncompress() const
void Compress() const
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 gather(FT &pdata, const Field< FT, Dim, M, C > &f, const Vektor< PT, Dim > &ppos, const M &mesh)
Definition IntCIC.h:1231
static MPI_Comm getComm()
Definition IpplInfo.h:152
static int getNodes()
Definition IpplInfo.cpp:689
static int myNode()
Definition IpplInfo.cpp:710
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)
Vektor< double, 3 > Vector_t
Definition Vektor.h:6