OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
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 //
19 #include "Algorithms/PartBunch.h"
20 
21 #include <cfloat>
22 #include <memory>
23 #include <utility>
24 
25 #include "FixedAlgebra/FMatrix.h"
26 #include "FixedAlgebra/FVector.h"
28 
29 #include "Algorithms/ListElem.h"
31 #include "Structure/FieldSolver.h"
33 
34 #ifdef DBG_SCALARFIELD
35  #include "Structure/FieldWriter.h"
36 #endif
37 
38 //#define FIELDSTDOUT
39 
40 PartBunch::PartBunch(const PartData *ref): // Layout is set using setSolver()
41  PartBunchBase<double, 3>(new PartBunch::pbase_t(new Layout_t()), ref),
42  interpolationCacheSet_m(false)
43 {
44 
45 }
46 
47 
49 
50 }
51 
52 // PartBunch::pbase_t* PartBunch::clone() {
53 // return new pbase_t(new Layout_t());
54 // }
55 
56 
58  Layout_t* layout = static_cast<Layout_t*>(&getLayout());
59  layout->getLayout().changeDomain(*fLayout);
60 }
61 
63 
64  Vector_t ll(-0.005);
65  Vector_t ur(0.005);
66 
68 
69  NDIndex<3> domain = getFieldLayout().getDomain();
70  for (unsigned int i = 0; i < Dimension; i++)
71  nr_m[i] = domain[i].length();
72 
73  for (int i = 0; i < 3; i++)
74  hr_m[i] = (ur[i] - ll[i]) / nr_m[i];
75 
76  getMesh().set_meshSpacing(&(hr_m[0]));
77  getMesh().set_origin(ll);
78 
82  bc_m);
86  vbc_m);
87 
88  fs_m->solver_m->test(this);
89 }
90 
91 
94 
95  pbase_t* underlyingPbase =
96  dynamic_cast<pbase_t*>(pbase_m.get());
97 
98  BinaryRepartition(*underlyingPbase);
99  update();
101  boundp();
102 }
103 
104 
105 void PartBunch::computeSelfFields(int binNumber) {
107 
110  rho_m = 0.0;
111  Field_t imagePotential = rho_m;
112 
114  eg_m = Vector_t(0.0);
115 
116  if(fs_m->hasValidSolver()) {
118  resizeMesh();
119 
121  this->Q *= this->dt;
125  } else {
127  getLocalNum(),
128  true);
129  }
131  this->Q.scatter(this->rho_m, this->R, IntrplCIC_t(), interpolationCache_m);
132  } else {
134  }
135 
136  this->Q /= this->dt;
137  this->rho_m /= getdT();
138 
140  double scaleFactor = 1;
141  // double scaleFactor = Physics::c * getdT();
142  double gammaz = getBinGamma(binNumber);
143 
146  double tmp2 = 1 / hr_m[0] * 1 / hr_m[1] * 1 / hr_m[2] / (scaleFactor * scaleFactor * scaleFactor) / gammaz;
147  rho_m *= tmp2;
148 
151  Vector_t hr_scaled = hr_m * Vector_t(scaleFactor);
152  hr_scaled[2] *= gammaz;
153 
156  imagePotential = rho_m;
157 
158  fs_m->solver_m->computePotential(rho_m, hr_scaled);
159 
161  rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
162 
166 
169  eg_m = -Grad(rho_m, eg_m);
170 
173  eg_m *= Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
174 
175  // If desired write E-field and potential to terminal
176 #ifdef FIELDSTDOUT
177  // Immediate debug output:
178  // Output potential and e-field along the x-, y-, and z-axes
179  int mx = (int)nr_m[0];
180  int mx2 = (int)nr_m[0] / 2;
181  int my = (int)nr_m[1];
182  int my2 = (int)nr_m[1] / 2;
183  int mz = (int)nr_m[2];
184  int mz2 = (int)nr_m[2] / 2;
185 
186  for (int i=0; i<mx; i++ )
187  *gmsg << "Bin " << binNumber
188  << ", Self Field along x axis E = " << eg_m[i][my2][mz2]
189  << ", Pot = " << rho_m[i][my2][mz2] << endl;
190 
191  for (int i=0; i<my; i++ )
192  *gmsg << "Bin " << binNumber
193  << ", Self Field along y axis E = " << eg_m[mx2][i][mz2]
194  << ", Pot = " << rho_m[mx2][i][mz2] << endl;
195 
196  for (int i=0; i<mz; i++ )
197  *gmsg << "Bin " << binNumber
198  << ", Self Field along z axis E = " << eg_m[mx2][my2][i]
199  << ", Pot = " << rho_m[mx2][my2][i] << endl;
200 #endif
201 
207  //Eftmp.gather(eg_m, this->R, IntrplCIC_t());
208 
216  double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz / Physics::c;
217 
218  Bf(0) = Bf(0) - betaC * Eftmp(1);
219  Bf(1) = Bf(1) + betaC * Eftmp(0);
220 
221  Ef += Eftmp;
222 
225 
227  NDIndex<3> domain = getFieldLayout().getDomain();
228  Vector_t origin = rho_m.get_mesh().get_origin();
229  double hz = rho_m.get_mesh().get_meshSpacing(2);
230  double zshift = -(2 * origin(2) + (domain[2].first() + domain[2].last() + 1) * hz) * gammaz * scaleFactor;
231 
234  fs_m->solver_m->computePotential(imagePotential, hr_scaled, zshift);
235 
237  imagePotential *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
238 
241  imagePotential *= getCouplingConstant();
242 
243 #ifdef DBG_SCALARFIELD
244  const int dumpFreq = 100;
245  VField_t tmp_eg = eg_m;
246 
247  if ((localTrackStep_m + 1) % dumpFreq == 0) {
248  FieldWriter fwriter;
249  fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m / dumpFreq, &imagePotential);
250  }
251 #endif
252 
256  eg_m = -Grad(imagePotential, eg_m);
257 
260  eg_m *= Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
261 
262  // If desired write E-field and potential to terminal
263 #ifdef FIELDSTDOUT
264  // Immediate debug output:
265  // Output potential and e-field along the x-, y-, and z-axes
266  //int mx = (int)nr_m[0];
267  //int mx2 = (int)nr_m[0] / 2;
268  //int my = (int)nr_m[1];
269  //int my2 = (int)nr_m[1] / 2;
270  //int mz = (int)nr_m[2];
271  //int mz2 = (int)nr_m[2] / 2;
272 
273  for (int i=0; i<mx; i++ )
274  *gmsg << "Bin " << binNumber
275  << ", Image Field along x axis E = " << eg_m[i][my2][mz2]
276  << ", Pot = " << rho_m[i][my2][mz2] << endl;
277 
278  for (int i=0; i<my; i++ )
279  *gmsg << "Bin " << binNumber
280  << ", Image Field along y axis E = " << eg_m[mx2][i][mz2]
281  << ", Pot = " << rho_m[mx2][i][mz2] << endl;
282 
283  for (int i=0; i<mz; i++ )
284  *gmsg << "Bin " << binNumber
285  << ", Image Field along z axis E = " << eg_m[mx2][my2][i]
286  << ", Pot = " << rho_m[mx2][my2][i] << endl;
287 #endif
288 
289 #ifdef DBG_SCALARFIELD
290  tmp_eg += eg_m;
291  if ((localTrackStep_m + 1) % dumpFreq == 0) {
292  FieldWriter fwriter;
293  fwriter.dumpField(tmp_eg, "e", "V/m", localTrackStep_m / dumpFreq);
294  }
295 #endif
296 
302  //Eftmp.gather(eg_m, this->R, IntrplCIC_t());
303 
312  Bf(0) = Bf(0) + betaC * Eftmp(1);
313  Bf(1) = Bf(1) - betaC * Eftmp(0);
314 
315  Ef += Eftmp;
316 
317  }
319 }
320 
322  if (fs_m->getFieldSolverType() != "SAAMG") {
323  return;
324  }
325 
326  double xmin = fs_m->solver_m->getXRangeMin();
327  double xmax = fs_m->solver_m->getXRangeMax();
328  double ymin = fs_m->solver_m->getYRangeMin();
329  double ymax = fs_m->solver_m->getYRangeMax();
330 
331  if(xmin > rmin_m[0] || xmax < rmax_m[0] ||
332  ymin > rmin_m[1] || ymax < rmax_m[1]) {
333 
334  for (unsigned int n = 0; n < getLocalNum(); n++) {
335 
336  if(R[n](0) < xmin || R[n](0) > xmax ||
337  R[n](1) < ymin || R[n](1) > ymax) {
338 
339  // delete the particle
340  INFOMSG(level2 << "destroyed particle with id=" << ID[n] << endl);
341  destroy(1, n);
342  }
343 
344  }
345 
346  update();
347  boundp();
349  }
350 
351  Vector_t origin = Vector_t(0.0, 0.0, 0.0);
352 
353  // update the mesh origin and mesh spacing hr_m
354  fs_m->solver_m->resizeMesh(origin, hr_m, rmin_m, rmax_m, dh_m);
355 
356  getMesh().set_meshSpacing(&(hr_m[0]));
357  getMesh().set_origin(origin);
358 
360  getFieldLayout(),
362  bc_m);
364  getFieldLayout(),
366  vbc_m);
367 
368  update();
369 
370 // setGridIsFixed();
371 }
372 
375  rho_m = 0.0;
376  eg_m = Vector_t(0.0);
377 
378  if(fs_m->hasValidSolver()) {
379  //mesh the whole domain
380  resizeMesh();
381 
382  //scatter charges onto grid
383  this->Q *= this->dt;
384  this->Q.scatter(this->rho_m, this->R, IntrplCIC_t());
385  this->Q /= this->dt;
386  this->rho_m /= getdT();
387 
388  //calculating mesh-scale factor
389  double gammaz = sum(this->P)[2] / getTotalNum();
390  gammaz *= gammaz;
391  gammaz = std::sqrt(gammaz + 1.0);
392  double scaleFactor = 1;
393  // double scaleFactor = Physics::c * getdT();
394  //and get meshspacings in real units [m]
395  Vector_t hr_scaled = hr_m * Vector_t(scaleFactor);
396  hr_scaled[2] *= gammaz;
397 
398  //double tmp2 = 1/hr_m[0] * 1/hr_m[1] * 1/hr_m[2] / (scaleFactor*scaleFactor*scaleFactor) / gammaz;
399  double tmp2 = 1 / hr_scaled[0] * 1 / hr_scaled[1] * 1 / hr_scaled[2];
400  //divide charge by a 'grid-cube' volume to get [C/m^3]
401  rho_m *= tmp2;
402 
403 #ifdef DBG_SCALARFIELD
404  FieldWriter fwriter;
405  fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
406 #endif
407 
408  // charge density is in rho_m
409  fs_m->solver_m->computePotential(rho_m, hr_scaled);
410 
411  //do the multiplication of the grid-cube volume coming
412  //from the discretization of the convolution integral.
413  //this is only necessary for the FFT solver
414  //FIXME: later move this scaling into FFTPoissonSolver
415  if(fs_m->getFieldSolverType() == "FFT" || fs_m->getFieldSolverType() == "FFTBOX")
416  rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
417 
418  // the scalar potential is given back in rho_m in units
419  // [C/m] = [F*V/m] and must be divided by
420  // 4*pi*\epsilon_0 [F/m] resulting in [V]
422 
423  //write out rho
424 #ifdef DBG_SCALARFIELD
425  fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
426 #endif
427 
428  // IPPL Grad divides by hr_m [m] resulting in
429  // [V/m] for the electric field
430  eg_m = -Grad(rho_m, eg_m);
431 
432  eg_m *= Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
433 
434  //write out e field
435 #ifdef FIELDSTDOUT
436  // Immediate debug output:
437  // Output potential and e-field along the x-, y-, and z-axes
438  int mx = (int)nr_m[0];
439  int mx2 = (int)nr_m[0] / 2;
440  int my = (int)nr_m[1];
441  int my2 = (int)nr_m[1] / 2;
442  int mz = (int)nr_m[2];
443  int mz2 = (int)nr_m[2] / 2;
444 
445  for (int i=0; i<mx; i++ )
446  *gmsg << "Field along x axis Ex = " << eg_m[i][my2][mz2] << " Pot = " << rho_m[i][my2][mz2] << endl;
447 
448  for (int i=0; i<my; i++ )
449  *gmsg << "Field along y axis Ey = " << eg_m[mx2][i][mz2] << " Pot = " << rho_m[mx2][i][mz2] << endl;
450 
451  for (int i=0; i<mz; i++ )
452  *gmsg << "Field along z axis Ez = " << eg_m[mx2][my2][i] << " Pot = " << rho_m[mx2][my2][i] << endl;
453 #endif
454 
455 #ifdef DBG_SCALARFIELD
456  fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
457 #endif
458 
459  // interpolate electric field at particle positions. We reuse the
460  // cached information about where the particles are relative to the
461  // field, since the particles have not moved since this the most recent
462  // scatter operation.
463  Ef.gather(eg_m, this->R, IntrplCIC_t());
464 
472  double betaC = std::sqrt(gammaz * gammaz - 1.0) / gammaz / Physics::c;
473 
474  Bf(0) = Bf(0) - betaC * Ef(1);
475  Bf(1) = Bf(1) + betaC * Ef(0);
476  }
478 }
479 
494 
496 
498  rho_m = 0.0;
499 
501  eg_m = Vector_t(0.0);
502 
503  if(fs_m->hasValidSolver()) {
505  resizeMesh();
506 
508  this->Q.scatter(this->rho_m, this->R, IntrplCIC_t());
509 
512  Vector_t hr_scaled = hr_m ;
513  hr_scaled[1] *= gamma;
514 
516  double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
517  rho_m *= tmp2;
518 
519  // If debug flag is set, dump scalar field (charge density 'rho') into file under ./data/
520 #ifdef DBG_SCALARFIELD
521  FieldWriter fwriter;
522  fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
523 #endif
524 
527  fs_m->solver_m->computePotential(rho_m, hr_scaled);
528 
529  //do the multiplication of the grid-cube volume coming
530  //from the discretization of the convolution integral.
531  //this is only necessary for the FFT solver
532  //TODO FIXME: later move this scaling into FFTPoissonSolver
533  if(fs_m->getFieldSolverType() == "FFT" || fs_m->getFieldSolverType() == "FFTBOX")
534  rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
535 
538 
539  // If debug flag is set, dump scalar field (potential 'phi') into file under ./data/
540 #ifdef DBG_SCALARFIELD
541  fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
542 #endif
543 
545  eg_m = -Grad(rho_m, eg_m);
546 
551  eg_m *= Vector_t(gamma, 1.0 / gamma, gamma);
552 
553 #ifdef FIELDSTDOUT
554  // Immediate debug output:
555  // Output potential and e-field along the x-, y-, and z-axes
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;
562 
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;
565 
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;
568 
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;
571 #endif
572 
573 #ifdef DBG_SCALARFIELD
574  fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
575 #endif
576 
578  Ef.gather(eg_m, this->R, IntrplCIC_t());
579 
581  // Relativistic E&M says gamma*v/c^2 = gamma*beta/c = sqrt(gamma*gamma-1)/c
582  // but because we already transformed E_trans into the moving frame we have to
583  // add 1/gamma so we are using the E_trans from the rest frame -DW
584  double betaC = std::sqrt(gamma * gamma - 1.0) / gamma / Physics::c;
585 
587  Bf(0) = betaC * Ef(2);
588  Bf(2) = -betaC * Ef(0);
589 
590  }
591 
592  /*
593  *gmsg << "gamma =" << gamma << endl;
594  *gmsg << "dx,dy,dz =(" << hr_m[0] << ", " << hr_m[1] << ", " << hr_m[2] << ") [m] " << endl;
595  *gmsg << "max of bunch is (" << rmax_m(0) << ", " << rmax_m(1) << ", " << rmax_m(2) << ") [m] " << endl;
596  *gmsg << "min of bunch is (" << rmin_m(0) << ", " << rmin_m(1) << ", " << rmin_m(2) << ") [m] " << endl;
597  */
598 
600 }
601 
621 
623  rho_m = 0.0;
624 
626  eg_m = Vector_t(0.0);
627 
629  double gamma = getBinGamma(bin);
630 
631  if(fs_m->hasValidSolver()) {
633  resizeMesh();
634 
636  this->Q.scatter(this->rho_m, this->R, IntrplCIC_t());
637 
640  Vector_t hr_scaled = hr_m ;
641  hr_scaled[1] *= gamma;
642 
644  double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
645  rho_m *= tmp2;
646 
647  // If debug flag is set, dump scalar field (charge density 'rho') into file under ./data/
648 #ifdef DBG_SCALARFIELD
649  FieldWriter fwriter;
650  fwriter.dumpField(rho_m, "rho", "C/m^3", localTrackStep_m);
651 #endif
652 
655  fs_m->solver_m->computePotential(rho_m, hr_scaled);
656 
657  // Do the multiplication of the grid-cube volume coming from the discretization of the convolution integral.
658  // This is only necessary for the FFT solver. FIXME: later move this scaling into FFTPoissonSolver
659  if(fs_m->getFieldSolverType() == "FFT" || fs_m->getFieldSolverType() == "FFTBOX")
660  rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
661 
664 
665  // If debug flag is set, dump scalar field (potential 'phi') into file under ./data/
666 #ifdef DBG_SCALARFIELD
667  fwriter.dumpField(rho_m, "phi", "V", localTrackStep_m);
668 #endif
669 
671  eg_m = -Grad(rho_m, eg_m);
672 
677  eg_m *= Vector_t(gamma, 1.0 / gamma, gamma);
678 
679 #ifdef FIELDSTDOUT
680  // Immediate debug output:
681  // Output potential and e-field along the x-, y-, and z-axes
682  int mx = (int)nr_m[0];
683  int mx2 = (int)nr_m[0] / 2;
684  int my = (int)nr_m[1];
685  int my2 = (int)nr_m[1] / 2;
686  int mz = (int)nr_m[2];
687  int mz2 = (int)nr_m[2] / 2;
688 
689  for (int i=0; i<mx; i++ )
690  *gmsg << "Bin " << bin
691  << ", Field along x axis Ex = " << eg_m[i][my2][mz2]
692  << ", Pot = " << rho_m[i][my2][mz2] << endl;
693 
694  for (int i=0; i<my; i++ )
695  *gmsg << "Bin " << bin
696  << ", Field along y axis Ey = " << eg_m[mx2][i][mz2]
697  << ", Pot = " << rho_m[mx2][i][mz2] << endl;
698 
699  for (int i=0; i<mz; i++ )
700  *gmsg << "Bin " << bin
701  << ", Field along z axis Ez = " << eg_m[mx2][my2][i]
702  << ", Pot = " << rho_m[mx2][my2][i] << endl;
703 #endif
704 
705  // If debug flag is set, dump vector field (electric field) into file under ./data/
706 #ifdef DBG_SCALARFIELD
707  fwriter.dumpField(eg_m, "e", "V/m", localTrackStep_m);
708 #endif
709 
711  Eftmp.gather(eg_m, this->R, IntrplCIC_t());
712 
714  double betaC = std::sqrt(gamma * gamma - 1.0) / gamma / Physics::c;
715 
717  Bf(0) = Bf(0) + betaC * Eftmp(2);
718  Bf(2) = Bf(2) - betaC * Eftmp(0);
719 
720  Ef += Eftmp;
721  }
722 
723  /*
724  *gmsg << "gamma =" << gamma << endl;
725  *gmsg << "dx,dy,dz =(" << hr_m[0] << ", " << hr_m[1] << ", " << hr_m[2] << ") [m] " << endl;
726  *gmsg << "max of bunch is (" << rmax_m(0) << ", " << rmax_m(1) << ", " << rmax_m(2) << ") [m] " << endl;
727  *gmsg << "min of bunch is (" << rmin_m(0) << ", " << rmin_m(1) << ", " << rmin_m(2) << ") [m] " << endl;
728  */
729 
730 
732 }
733 
734 
735 // void PartBunch::setMesh(Mesh_t* mesh) {
736 // Layout_t* layout = static_cast<Layout_t*>(&getLayout());
737 // // layout->getLayout().setMesh(mesh);
738 // }
739 
740 
741 // void PartBunch::setFieldLayout(FieldLayout_t* fLayout) {
742 // Layout_t* layout = static_cast<Layout_t*>(&getLayout());
743 // // layout->getLayout().setFieldLayout(fLayout);
744 // // layout->rebuild_neighbor_data();
745 // layout->getLayout().changeDomain(*fLayout);
746 // }
747 
748 
750  Layout_t* layout = static_cast<Layout_t*>(&getLayout());
751  return dynamic_cast<FieldLayout_t &>(layout->getLayout().getFieldLayout());
752 }
753 
755  for (int i = 0; i < 2 * 3; ++i) {
756 
757  if (Ippl::getNodes()>1) {
759  //std periodic boundary conditions for gradient computations etc.
761  }
762  else {
764  //std periodic boundary conditions for gradient computations etc.
766  }
768  }
769  dcBeam_m=true;
770  INFOMSG(level3 << "BC set P3M, all periodic" << endl);
771 }
772 
774  for (int i = 0; i < 2 * 3; ++i) {
777  getBConds()[i] = ParticleNoBCond;
778  }
779  dcBeam_m=false;
780  INFOMSG(level3 << "BC set for normal Beam" << endl);
781 }
782 
784  for (int i = 0; i < 2 * 3; ++ i) {
785  if (i >= 4) {
786  if (Ippl::getNodes() > 1) {
789  } else {
792  }
793 
795  } else {
798  getBConds()[i] = ParticleNoBCond;
799  }
800  }
801  dcBeam_m=true;
802  INFOMSG(level3 << "BC set for DC-Beam, longitudinal periodic" << endl);
803 }
804 
805 
807  NDIndex<3> domain = getFieldLayout().getDomain();
808  for (unsigned int i = 0; i < Dimension; i++)
809  grid[i] = domain[i].length();
810 }
811 
812 
813 void PartBunch::updateFields(const Vector_t& /*hr*/, const Vector_t& origin) {
814  getMesh().set_meshSpacing(&(hr_m[0]));
815  getMesh().set_origin(origin);
817  getFieldLayout(),
819  bc_m);
821  getFieldLayout(),
823  vbc_m);
824 }
825 
826 inline
828  const Vector_t maxE = max(eg_m);
829  // const double maxL = max(dot(eg_m,eg_m));
830  const Vector_t minE = min(eg_m);
831  // INFOMSG("MaxE= " << maxE << " MinE= " << minE << endl);
832  return VectorPair_t(maxE, minE);
833 }
834 
835 
836 inline
837 void PartBunch::resetInterpolationCache(bool clearCache) {
838  interpolationCacheSet_m = false;
839  if(clearCache) {
841  }
842 }
843 
844 void PartBunch::swap(unsigned int i, unsigned int j) {
845 
846  // FIXME
848 
850  std::swap(interpolationCache_m[i], interpolationCache_m[j]);
851 }
852 
853 
856 }
Inform * gmsg
Definition: Main.cpp:62
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
IntCIC IntrplCIC_t
Definition: PBunchDefs.h:17
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
void BinaryRepartition(FieldLayout< Dim > &layout, BareField< double, Dim > &weights)
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)
Definition: Cartesian.hpp:2702
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 sum(const PETE_Expr< T > &expr)
Definition: PETE.h:1111
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
Inform & level2(Inform &inf)
Definition: Inform.cpp:46
Inform & level3(Inform &inf)
Definition: Inform.cpp:47
#define INFOMSG(msg)
Definition: IpplInfo.h:348
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
ParticleAttrib< Vector_t > Ef
std::shared_ptr< AbstractParticle< double, Dim > > pbase_m
long long localTrackStep_m
step in a TRACK command
ParticleBConds< Position_t, Dimension > & getBConds()
double getCouplingConstant() const
ParticleAttrib< Vector_t > Eftmp
Vector_t rmax_m
maximal extend of particles
ParticleAttrib< Vector_t > P
Inform & print(Inform &os)
double getBinGamma(int bin)
Get gamma of one bin.
ParticleAttrib< double > Q
Vector_t rmin_m
minimal extend of particles
FieldSolver * fs_m
stores the used field solver
std::pair< Vector_t, Vector_t > VectorPair_t
Definition: PartBunchBase.h:75
double dh_m
Mesh enlargement.
ParticleAttrib< double > dt
static const unsigned Dimension
Definition: PartBunchBase.h:77
void get_bounds(Vector_t &rmin, Vector_t &rmax)
Vector_t hr_m
meshspacing of cartesian 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)
Vektor< int, 3 > nr_m
meshsize of cartesian mesh
IpplTimings::TimerRef selfFieldTimer_m
timer for selfField calculation
void resetInterpolationCache(bool clearCache=false)
Definition: PartBunch.cpp:837
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
Definition: PartBunch.h:113
void computeSelfFields()
Definition: PartBunch.cpp:373
void runTests()
Definition: PartBunch.cpp:62
ParticleLayout< double, 3 > & getLayout()
Definition: PartBunch.h:122
void do_binaryRepart()
Definition: PartBunch.cpp:92
Field_t rho_m
scalar potential
Definition: PartBunch.h:96
PartBunch()=delete
void swap(unsigned int i, unsigned int j)
Definition: PartBunch.cpp:844
void initialize(FieldLayout_t *fLayout)
Definition: PartBunch.cpp:57
void setBCAllOpen()
Definition: PartBunch.cpp:773
bool interpolationCacheSet_m
Definition: PartBunch.h:117
Inform & print(Inform &os)
Definition: PartBunch.cpp:854
void updateDomainLength(Vektor< int, 3 > &grid)
Definition: PartBunch.cpp:806
void setBCForDCBeam()
Definition: PartBunch.cpp:783
FieldLayout_t & getFieldLayout()
Definition: PartBunch.cpp:749
VField_t eg_m
vector field on the grid
Definition: PartBunch.h:99
VectorPair_t getEExtrema()
Definition: PartBunch.cpp:827
void setBCAllPeriodic()
Definition: PartBunch.cpp:754
const Mesh_t & getMesh() const
Definition: PartBunch.h:140
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
Definition: PartBunch.h:119
void resizeMesh()
resize mesh to geometry specified
Definition: PartBunch.cpp:321
BConds< Vector_t, 3, Mesh_t, Center_t > vbc_m
Definition: PartBunch.h:114
void computeSelfFields_cycl(double gamma)
Calculates the self electric field from the charge density distribution for use in cyclotrons.
Definition: PartBunch.cpp:493
void updateFields(const Vector_t &hr, const Vector_t &origin)
Definition: PartBunch.cpp:813
Particle reference data.
Definition: PartData.h:35
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 resizeMesh(Vector_t &, Vector_t &, const Vector_t &, const Vector_t &, double)
Definition: PoissonSolver.h:68
virtual double getYRangeMax(unsigned short level=0)=0
virtual void test(PartBunchBase< double, 3 > *bunch)=0
virtual double getXRangeMax(unsigned short level=0)=0
PoissonSolver * solver_m
the actual solver, should be a base object
Definition: FieldSolver.h:114
bool hasValidSolver()
std::string getFieldSolverType()
Definition: FieldSolver.h:90
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.
Definition: FieldWriter.hpp:30
void initialize(Layout_t &)
Mesh_t & get_mesh() const
Definition: Field.h:110
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)
const NDIndex< Dim > & getDomain() const
Definition: FieldLayout.h:325
void set_origin(const Vektor< MFLOAT, Dim > &o)
void set_meshSpacing(MFLOAT *const del)
RegionLayout< T, Dim, Mesh > & getLayout()
Definition: Inform.h:42
static int getNodes()
Definition: IpplInfo.cpp:670
static void stopTimer(TimerRef t)
Definition: IpplTimings.h:192
static void startTimer(TimerRef t)
Definition: IpplTimings.h:187
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6