OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ParallelSliceTracker.cpp
Go to the documentation of this file.
3 #include "Algorithms/IndexMap.h"
5 
7 #include "Beamlines/Beamline.h"
10 #include "Lines/Sequence.h"
11 #include "Utilities/Timer.h"
12 #include "Utilities/Util.h"
14 
15 #include <memory>
16 #include <string>
17 
18 class PartData;
19 
21  const PartData &reference, bool revBeam, bool revTrack):
22  Tracker(beamline, reference, revBeam, revTrack) {
23 
24  CoordinateSystemTrafo labToRef(beamline.getOrigin3D(),
25  beamline.getInitialDirection());
26  referenceToLabCSTrafo_m = labToRef.inverted();
27 
28 }
29 
30 
32  EnvelopeBunch &bunch,
33  DataSink &ds,
34  const PartData &reference,
35  bool revBeam,
36  bool revTrack,
37  const std::vector<unsigned long long> &maxSteps,
38  double zstart,
39  const std::vector<double> &zstop,
40  const std::vector<double> &dt):
41  Tracker(beamline, reference, revBeam, revTrack),
42  itsOpalBeamline_m(),
43  zstart_m(zstart) {
44 
45  itsBunch_m = &bunch;
46  itsDataSink_m = &ds;
47 
48  CoordinateSystemTrafo labToRef(beamline.getOrigin3D(),
49  beamline.getInitialDirection());
50  referenceToLabCSTrafo_m = labToRef.inverted();
51 
52  for (std::vector<unsigned long long>::const_iterator it = maxSteps.begin(); it != maxSteps.end(); ++ it) {
53  localTrackSteps_m.push(*it);
54  }
55  for (std::vector<double>::const_iterator it = dt.begin(); it != dt.end(); ++ it) {
56  dtAllTracks_m.push(*it);
57  }
58  for (std::vector<double>::const_iterator it = zstop.begin(); it != zstop.end(); ++ it) {
59  zStop_m.push(*it);
60  }
61 
62  timeIntegrationTimer1_m = IpplTimings::getTimer("Time integration1");
63  timeIntegrationTimer2_m = IpplTimings::getTimer("Time integration2");
64  timeFieldEvaluation_m = IpplTimings::getTimer("Field evaluation");
65  BinRepartTimer_m = IpplTimings::getTimer("Time of Binary repart.");
66  WakeFieldTimer_m = IpplTimings::getTimer("Time of Wake Field calc.");
67 
70  cavities_m.merge(travelingwaves, ClassicField::SortAsc);
71 }
72 
73 
75 { }
76 
77 
78 void ParallelSliceTracker::visitBeamline(const Beamline &bl) { // borrowed from ParallelTTracker
79  const FlaggedBeamline* fbl = static_cast<const FlaggedBeamline*>(&bl);
80  if (fbl->getRelativeFlag()) {
81  OpalBeamline stash(fbl->getOrigin3D(), fbl->getInitialDirection());
82  stash.swap(itsOpalBeamline_m);
83  fbl->iterate(*this, false);
86  stash.merge(itsOpalBeamline_m);
87  stash.swap(itsOpalBeamline_m);
88  } else {
89  fbl->iterate(*this, false);
90  }
91 }
92 
93 
94 void ParallelSliceTracker::saveCavityPhases() { // borrowed from ParallelTTracker
96 }
97 
98 void ParallelSliceTracker::restoreCavityPhases() { // borrowed from ParallelTTracker
100 
101  if (OpalData::getInstance()->hasPriorTrack() ||
102  OpalData::getInstance()->inRestartRun()) {
103  iterator_t it = OpalData::getInstance()->getFirstMaxPhases();
104  iterator_t end = OpalData::getInstance()->getLastMaxPhases();
105  for (; it < end; ++ it) {
106  updateRFElement((*it).first, (*it).second);
107  }
108  }
109 }
110 
111 /*
112  * The maximum phase is added to the nominal phase of
113  * the element. This is done on all nodes except node 0 where
114  * the Autophase took place.
115  */
116 void ParallelSliceTracker::updateRFElement(std::string elName, double maxPhase) {
117  double phase = 0.0;
118 
119  for (FieldList::iterator fit = cavities_m.begin(); fit != cavities_m.end(); ++fit) {
120  if ((*fit).getElement()->getName() == elName) {
121  if ((*fit).getElement()->getType() == ElementBase::TRAVELINGWAVE) {
122  phase = static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem();
123  static_cast<TravelingWave *>((*fit).getElement().get())->setPhasem(phase + maxPhase);
124  } else {
125  phase = static_cast<RFCavity *>((*fit).getElement().get())->getPhasem();
126  static_cast<RFCavity *>((*fit).getElement().get())->setPhasem(phase + maxPhase);
127  }
128 
129  break;
130  }
131  }
132 }
133 
134 
135 /*
136  * All RF-Elements gets updated, where the phiShift is the
137  * global phase shift in units of seconds.
138  */
140  Inform msg("ParallelSliceTracker ");
141 
142  FieldList &cl = cavities_m;
143 
144  const double RADDEG = 180.0 / Physics::pi;
145  const double globalTimeShift = OpalData::getInstance()->getGlobalPhaseShift();
146 
147  msg << "\n-------------------------------------------------------------------------------------\n";
148 
149  for (FieldList::iterator it = cl.begin(); it != cl.end(); ++it) {
150  std::shared_ptr<Component> element(it->getElement());
151  std::string name = element->getName();
152  double frequency;
153  double phase;
154 
155  if (element->getType() == ElementBase::TRAVELINGWAVE) {
156  phase = static_cast<TravelingWave *>(element.get())->getPhasem();
157  frequency = static_cast<TravelingWave *>(element.get())->getFrequencym();
158  } else {
159  phase = static_cast<RFCavity *>(element.get())->getPhasem();
160  frequency = static_cast<RFCavity *>(element.get())->getFrequencym();
161  }
162 
163  msg << (it == cl.begin()? "": "\n")
164  << name
165  << ": phi = phi_nom + phi_maxE + global phase shift = " << (phase - globalTimeShift * frequency) * RADDEG << " degree, "
166  << "(global phase shift = " << -globalTimeShift *frequency *RADDEG << " degree) \n";
167  }
168 
169  msg << "-------------------------------------------------------------------------------------\n"
170  << endl;
171 }
172 
173 void ParallelSliceTracker::applyEntranceFringe(double angle, double curve,
174  const BMultipoleField &field, double scale) {
175 }
176 
177 
178 void ParallelSliceTracker::applyExitFringe(double angle, double curve,
179  const BMultipoleField &field, double scale) {
180 }
181 
182 
184 
185  Inform msg("ParallelSliceTracker", *gmsg);
186  BorisPusher pusher(itsReference);
187  const double globalTimeShift = itsBunch_m->doEmission()? OpalData::getInstance()->getGlobalPhaseShift(): 0.0;
188 
190 
191  setTime();
192  setLastStep();
193 
194  prepareSections();
196 
197  std::queue<double> timeStepSizes(dtAllTracks_m);
198  std::queue<unsigned long long> numSteps(localTrackSteps_m);
199  double minTimeStep = timeStepSizes.front();
200  unsigned long long totalNumSteps = 0;
201  while (timeStepSizes.size() > 0) {
202  if (minTimeStep > timeStepSizes.front()) {
203  totalNumSteps = std::ceil(totalNumSteps * minTimeStep / timeStepSizes.front());
204  minTimeStep = timeStepSizes.front();
205  }
206  totalNumSteps += std::ceil(numSteps.front() * timeStepSizes.front() / minTimeStep);
207 
208  numSteps.pop();
209  timeStepSizes.pop();
210  }
211 
213 
214  if ( OpalData::getInstance()->hasPriorTrack() ||
215  OpalData::getInstance()->inRestartRun()) {
216 
220 
223 
225  } else {
226  RefPartR_m = Vector_t(0.0);
228 
229  if (itsBunch_m->getTotalNum() > 0) {
231  RefPartP_m = itsReference.getP() / itsBunch_m->getM() * Vector_t(0, 0, 1);
232  }
233 
234  if (zstart_m > pathLength_m) {
235  findStartPosition(pusher);
236  }
237 
239  }
240  }
241 
242  Vector_t rmin, rmax;
243  itsBunch_m->get_bounds(rmin, rmax);
247  pathLength_m,
248  0.0,//-rmin(2),
249  itsBunch_m->getT(),
250  minTimeStep,
251  totalNumSteps,
252  zStop_m.back() + 2 * rmax(2),
254 
255  oth.execute();
256 
258 
259  setTime();
260 
261  double t = itsBunch_m->getT() - globalTimeShift;
262  itsBunch_m->setT(t);
263 
266 
267  *gmsg << level1 << *itsBunch_m << endl;
268 
269  unsigned long long step = itsBunch_m->getGlobalTrackStep();
270  OPALTimer::Timer myt1;
271  *gmsg << "Track start at: " << myt1.time() << ", t= " << Util::getTimeString(t) << "; "
272  << "zstart at: " << Util::getLengthString(pathLength_m)
273  << endl;
274 
275  // prepareEmission();
276 
277  *gmsg << level1
278  << "Executing ParallelSliceTracker, initial dt= " << Util::getTimeString(itsBunch_m->getdT()) << ";\n"
279  << "max integration steps " << getMaxSteps(localTrackSteps_m) << ", next step= " << step << endl
280  << "the mass is: " << itsReference.getM() * 1e-6 << " MeV, its charge: "
281  << itsReference.getQ() << " [e]" << endl;
282 
283 
284  // setOptionalVariables();
285  *gmsg << std::scientific;
287  while (localTrackSteps_m.size() > 0) {
288  localTrackSteps_m.front() += step;
290  selectDT();
291 
292  for (; step < localTrackSteps_m.front(); ++step) {
293 
294  globalEOL_m = false;
295 
296  switchElements();
298 
299  //reduce(&globalEOL_m, &globalEOL_m, OpBitwiseOrAssign());
300  //reduce(&globalEOL_m, &globalEOL_m + 1, &globalEOL_m, OpBitwiseAndAssign());
301  MPI_Allreduce(MPI_IN_PLACE, &globalEOL_m, 1, MPI_INT, MPI_LAND, Ippl::getComm());
302 
304  timeIntegration();
305 
306  if (step % 1000 + 1 == 1000) {
307  msg << level1;
308  } else if (step % 100 + 1 == 100) {
309  msg << level2;
310  } else {
311  msg << level3;
312  }
313 
314  msg << " Step " << step << " at " << itsBunch_m->zAvg() << " [m] t= "
315  << itsBunch_m->getT() << " [s] E=" << itsBunch_m->Eavg() * 1e-6
316  << " [MeV]" << endl;
317 
320 
321  dumpStats(step);
322 
323  if (hasEndOfLineReached())
324  break;
325 
326  double gamma = itsBunch_m->Eavg() / (Physics::m_e * 1e9) + 1.0;
327  double beta = sqrt(1.0 - 1.0 / (gamma * gamma));
328 
329  double driftPerTimeStep = itsBunch_m->getdT() * Physics::c * beta;
330  if (std::abs(zStop_m.front() - itsBunch_m->zAvg()) < 0.5 * driftPerTimeStep)
331  localTrackSteps_m.front() = step;
332  }
333 
334  if (globalEOL_m)
335  break;
336 
337  dtAllTracks_m.pop();
338  localTrackSteps_m.pop();
339  zStop_m.pop();
340  }
341 
345  msg << "done executing ParallelSliceTracker" << endl;
346 }
347 
348 
350 
354 }
355 
356 
358 
359  if (Options::autoPhase == 0) return;
360 
361  if(!OpalData::getInstance()->inRestartRun()) {
363  }
364 
366  auto end = OpalData::getInstance()->getLastMaxPhases();
367  for (; it != end; ++ it) {
368  updateRFElement((*it).first, (*it).second);
369  }
370  printRFPhases();
371 }
372 
373 
375 
376  itsBeamline_m.accept(*this);
378 
382 }
383 
384 
386 
388 
389  Vector_t externalE, externalEThis, externalB, externalBThis, KR, KRThis, KT, KTThis;
390 
391  const unsigned int localNum = itsBunch_m->getLocalNum();
392  // bool locPartOutOfBounds = false, globPartOutOfBounds = false;
393  Vector_t rmin, rmax;
394  itsBunch_m->get_bounds(rmin, rmax);
396 
397  try {
398  elements = oth.query(pathLength_m + 0.5 * (rmax(2) + rmin(2)), rmax(2) - rmin(2));
399  } catch(IndexMap::OutOfBounds &e) {
400  globalEOL_m = true;
401  return;
402  }
403 
404  const double time = itsBunch_m->getT() + 0.5 * itsBunch_m->getdT();
405  const IndexMap::value_t::const_iterator end = elements.end();
406 
407  for (unsigned int i = 0; i < localNum; ++ i) {
408 
409  externalB = Vector_t(0.0);
410  externalE = Vector_t(0.0);
411  KR = Vector_t(0.0);
412  KT = Vector_t(0.0);
413 
414  IndexMap::value_t::const_iterator it = elements.begin();
415  for (; it != end; ++ it) {
418  const CoordinateSystemTrafo fromLocal = toLocal.inverted();
419 
420  //FIXME: why not x=y=0.0?
421  // for (unsigned int k = 0; k < 100; ++ k) {
422  externalEThis = Vector_t(0.0);
423  externalBThis = Vector_t(0.0);
424  KRThis = Vector_t(0.0);
425  KTThis = Vector_t(0.0);
426 
427  Vector_t pos = itsBunch_m->getR(i);
428  Vector_t mom = itsBunch_m->getP(i);
429 
430  itsBunch_m->setR(i, toLocal.transformTo(pos));
431  itsBunch_m->setP(i, toLocal.rotateTo(mom));
432 
433  if ((*it)->apply(itsBunch_m->getR(i),
434  itsBunch_m->getP(i),
435  time,
436  externalEThis,
437  externalBThis)) {
438  itsBunch_m->Bin[i] = -1;
439  continue;
440  }
441 
442  (*it)->addKR(i, time, KRThis);
443  (*it)->addKT(i, time, KTThis);
444 
445  externalE += fromLocal.rotateTo(externalEThis);
446  externalB += fromLocal.rotateTo(externalBThis);
447 
448  KR += fromLocal.rotateTo(KRThis);
449  KT += fromLocal.rotateTo(KTThis);
450 
451  itsBunch_m->setR(i, pos);
452  itsBunch_m->setP(i, mom);
453  }
454 
455  itsBunch_m->setExternalFields(i, externalE, externalB, KR, KT);
456  }
457 
459 }
460 
461 
463 
465 }
466 
467 
468 void ParallelSliceTracker::dumpStats(long long step) {
469 
470  double sposRef = itsBunch_m->get_sPos();
471  if (step != 0 && (step % Options::psDumpFreq == 0 || step % Options::statDumpFreq == 0))
472  writePhaseSpace(step, sposRef);
473 }
474 
475 
476 void ParallelSliceTracker::switchElements(double scaleMargin) {
477 
478  double margin = 1.0;
479 
482  itsBunch_m->zHead() + margin,
483  itsBunch_m->Eavg() * 1e-6);
484 }
485 
486 
488 
489  // unsigned long long step = 0;
490 
491  // if (OpalData::getInstance()->inRestartRun()) {
492 
493  // int prevDumpFreq = OpalData::getInstance()->getRestartDumpFreq();
494  // step = OpalData::getInstance()->getRestartStep() * prevDumpFreq + 1;
495  // maxSteps_m += step;
496  // } else {
497 
498  // step = OpalData::getInstance()->getLastStep() + 1;
499  // maxSteps_m += step;
500  // }
501 
502  // OpalData::getInstance()->setLastStep(step);
503 }
504 
505 
507 
508  if (OpalData::getInstance()->inRestartRun())
510  else
512 }
513 
514 
517  return globalEOL_m;
518 }
519 
520 void ParallelSliceTracker::findStartPosition(const BorisPusher &pusher) { // borrowed from ParallelTTracker
521 
522  double t = 0.0;
523  itsBunch_m->setT(t);
524 
526  selectDT();
527 
528  if (Util::getEnergy(RefPartP_m, itsBunch_m->getM()) < 1e-3) {
529  double gamma = 0.1 / itsBunch_m->getM() + 1.0;
530  RefPartP_m = sqrt(std::pow(gamma, 2) - 1) * Vector_t(0, 0, 1);
531  }
532 
533  while (true) {
534  autophaseCavities(pusher);
535 
536  t += itsBunch_m->getdT();
537  itsBunch_m->setT(t);
538 
539  Vector_t oldR = RefPartR_m;
540  updateReferenceParticle(pusher);
542 
543  if (pathLength_m > zStop_m.front()) {
544  if (localTrackSteps_m.size() == 0) return;
545 
546  dtAllTracks_m.pop();
547  localTrackSteps_m.pop();
548  zStop_m.pop();
549 
550  selectDT();
551  }
552 
553  double speed = euclidean_norm(RefPartP_m) * Physics::c / sqrt(dot(RefPartP_m, RefPartP_m) + 1);
554  if (std::abs(pathLength_m - zstart_m) <= 0.5 * itsBunch_m->getdT() * speed) {
555  double tau = (pathLength_m - zstart_m) / speed;
556 
557  t += tau;
558  itsBunch_m->setT(t);
559 
560  RefPartR_m /= (Physics::c * tau);
561  pusher.push(RefPartR_m, RefPartP_m, tau);
562  RefPartR_m *= (Physics::c * tau);
563 
565 
567  getQuaternion(RefPartP_m, Vector_t(0, 0, 1)));
569 
571  RefPartP_m = update.rotateTo(RefPartP_m);
572 
573  return;
574  }
575  }
576 }
577 
578 void ParallelSliceTracker::updateReferenceParticle(const BorisPusher &pusher) { // borrowed from ParallelTTracker
579  //static size_t step = 0;
580  const double dt = std::min(itsBunch_m->getT(), itsBunch_m->getdT());
581  const double scaleFactor = Physics::c * dt;
582  Vector_t Ef(0.0), Bf(0.0);
583  // Vector_t oldR = RefPartR_m;
584 
585  RefPartR_m /= scaleFactor;
586  pusher.push(RefPartR_m, RefPartP_m, dt);
587  RefPartR_m *= scaleFactor;
588 
590  IndexMap::value_t::const_iterator it = elements.begin();
591  const IndexMap::value_t::const_iterator end = elements.end();
592 
593  for (; it != end; ++ it) {
595 
596  Vector_t localR = refToLocalCSTrafo.transformTo(RefPartR_m);
597  Vector_t localP = refToLocalCSTrafo.rotateTo(RefPartP_m);
598  Vector_t localE(0.0), localB(0.0);
599 
600  if ((*it)->applyToReferenceParticle(localR,
601  localP,
602  itsBunch_m->getT() - 0.5 * dt,
603  localE,
604  localB)) {
605  *gmsg << level1 << "The reference particle hit an element" << endl;
606  globalEOL_m = true;
607  }
608 
609  Ef += refToLocalCSTrafo.rotateFrom(localE);
610  Bf += refToLocalCSTrafo.rotateFrom(localB);
611  }
612 
613  pusher.kick(RefPartR_m, RefPartP_m, Ef, Bf, dt);
614 
615  RefPartR_m /= scaleFactor;
616  pusher.push(RefPartR_m, RefPartP_m, dt);
617  RefPartR_m *= scaleFactor;
618  //++ step;
619 }
620 
621 void ParallelSliceTracker::autophaseCavities(const BorisPusher &pusher) { // borrowed from ParallelTTracker
622 
623  double t = itsBunch_m->getT();
624  Vector_t nextR = RefPartR_m / (Physics::c * itsBunch_m->getdT());
625  pusher.push(nextR, RefPartP_m, itsBunch_m->getdT());
626  nextR *= Physics::c * itsBunch_m->getdT();
627 
629  for (auto element: elementSet) {
630  if (element->getType() == ElementBase::TRAVELINGWAVE) {
631  const TravelingWave *TWelement = static_cast<const TravelingWave *>(element.get());
632  if (!TWelement->getAutophaseVeto()) {
635  CavityAutophaser ap(itsReference, element);
638  t, itsBunch_m->getdT());
641  }
642 
643  } else if (element->getType() == ElementBase::RFCAVITY) {
644  const RFCavity *RFelement = static_cast<const RFCavity *>(element.get());
645  if (!RFelement->getAutophaseVeto()) {
648  CavityAutophaser ap(itsReference, element);
651  t, itsBunch_m->getdT());
654  }
655  }
656  }
657 }
658 
659 void ParallelSliceTracker::selectDT() { // borrowed from ParallelTTracker
660 
661  if (itsBunch_m->getIfBeamEmitting()) {
662  double dt = itsBunch_m->getEmissionDeltaT();
663  itsBunch_m->setdT(dt);
664  } else {
665  double dt = dtCurrentTrack_m;
666  itsBunch_m->setdT(dt);
667  }
668 }
669 
670 void ParallelSliceTracker::changeDT() { // borrowed from ParallelTTracker
671  selectDT();
672  const unsigned int localNum = itsBunch_m->getLocalNum();
673  for (unsigned int i = 0; i < localNum; ++ i) {
674  itsBunch_m->dt[i] = itsBunch_m->getdT();
675  }
676 }
IpplTimings::TimerRef WakeFieldTimer_m
void setR(int i, const Vector_t &R)
elements
Definition: IndexMap.cpp:141
void setP(int i, const Vector_t &P)
FieldList cavities_m
set multipacting flag
Definition: Tracker.h:143
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
Definition: OpalData.cpp:447
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
void applyExitFringe(double edge, double curve, const BMultipoleField &field, double scale)
constexpr double e
The value of .
Definition: Physics.h:40
double getT()
returns the current time of the bunch
Vector_t RefPartR_m
void prepareSections()
bool getRelativeFlag() const
Definition: TBeamline.h:470
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
core of the envelope tracker based on Rene Bakkers BET implementation
Definition: EnvelopeBunch.h:60
Vector_t rotateTo(const Vector_t &r) const
void applyEntranceFringe(double edge, double curve, const BMultipoleField &field, double scale)
void switchElements(const double &, const double &, const double &kineticEnergy, const bool &nomonitors=false)
const Beamline & itsBeamline_m
Definition: Tracker.h:145
IpplTimings::TimerRef timeIntegrationTimer2_m
void compute3DLattice()
std::list< ClassicField > FieldList
Definition: ClassicField.h:47
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
Definition: PETE.h:811
Particle reference data.
Definition: PartData.h:38
double getdT() const
Inform * gmsg
Definition: Main.cpp:21
double getM() const
double getPhaseAtMaxEnergy(const Vector_t &R, const Vector_t &P, double t, double dt)
CoordinateSystemTrafo referenceToLabCSTrafo_m
Vector_t transformTo(const Vector_t &r) const
Quaternion getQuaternion(Vector_t u, Vector_t ref)
Definition: Quaternion.cpp:34
void computeExternalFields(OrbitThreader &oth)
double zAvg()
calculate &lt;z&gt; [m]
virtual bool getAutophaseVeto() const
Definition: RFCavity.h:458
Vector_t get_pmean_Distribution() const
void setdT(double dt)
virtual Quaternion getInitialDirection() const
Definition: Beamline.cpp:53
void updateReferenceParticle(const BorisPusher &pusher)
static bool SortAsc(const ClassicField &fle1, const ClassicField &fle2)
Definition: ClassicField.h:26
std::string getLengthString(double spos, unsigned int precision=3)
Definition: Util.h:63
std::queue< double > zStop_m
where to stop
Vector_t getOrigin3D() const
Definition: TBeamline.h:450
std::queue< double > dtAllTracks_m
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
double zHead()
calculate the head of the bunch [m]
bool containsSource()
Definition: OpalBeamline.h:224
int statDumpFreq
The frequency to dump statistical values, e.e. dump data when stepstatDumpFreq==0.
Definition: Options.cpp:54
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:185
constexpr double m_e
The electron rest mass in GeV.
Definition: Physics.h:85
Inform & level2(Inform &inf)
Definition: Inform.cpp:46
void set_sPos(double s)
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
Definition: GlobalComm.hpp:55
static OpalData * getInstance()
Definition: OpalData.cpp:209
IpplTimings::TimerRef BinRepartTimer_m
void activateElements()
Template class for beam lines.
Definition: TBeamline.h:40
double getGlobalPhaseShift()
units: (sec)
Definition: OpalData.cpp:497
constexpr double pi
The value of .
Definition: Physics.h:31
unsigned long long getMaxSteps(std::queue< unsigned long long > numSteps)
double getQ() const
The constant charge per particle.
Definition: PartData.h:107
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
void switchElements(double scaleMargin=3.0)
double zTail()
calculate tail of bunch [m]
bool getIfBeamEmitting()
std::string getTimeString(double time, unsigned int precision=3)
Definition: Util.h:40
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:52
static void startTimer(TimerRef t)
Definition: IpplTimings.h:187
void switchElementsOff(const double &, ElementBase::ElementType eltype=ElementBase::ANY)
void kick(const Vector_t &R, Vector_t &P, const Vector_t &Ef, const Vector_t &Bf, const double &dt) const
Definition: BorisPusher.h:48
CoordinateSystemTrafo toLabTrafo_m
Interface for RF cavity.
Definition: TravelingWave.h:37
double get_sPos()
return reference position
virtual void iterate(BeamlineVisitor &, bool r2l) const
Apply visitor to all elements of the line.
Definition: TBeamline.h:215
void setExternalFields(int i, const Vector_t &EF, const Vector_t &BF, const Vector_t &KR, const Vector_t &KT)
IndexMap::value_t query(IndexMap::key_t::first_type step, IndexMap::key_t::second_type length)
Definition: OrbitThreader.h:94
Vector_t RefPartP_m
FieldList getElementByType(ElementBase::ElementType)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
virtual void execute()
Apply the algorithm to the top-level beamline.
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
void writeLastStepPhaseSpace(const long long step, const double &sposRef)
void swap(OpalBeamline &rhs)
int autoPhase
Definition: Options.cpp:45
int getLocalNum()
returns the number of local slices
An abstract sequence of beam line components.
Definition: Beamline.h:37
static MPI_Comm getComm()
Definition: IpplInfo.h:178
const PartData itsReference
The reference information.
double Eavg()
calculate the average energy of the bunch
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
Definition: OpalData.cpp:443
double beta
Definition: PartData.h:99
void updateRFElement(std::string elName, double maxPhi)
std::queue< unsigned long long > localTrackSteps_m
The maximal number of steps the system is integrated per TRACK.
int psDumpFreq
The frequency to dump the phase space, i.e.dump data when steppsDumpFreq==0.
Definition: Options.cpp:48
ParticleAttrib< double > dt
Vector_t getP(int i)
double getP() const
The constant reference momentum per particle.
Definition: PartData.h:117
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
Definition: OpalData.cpp:385
IpplTimings::TimerRef timeIntegrationTimer1_m
The magnetic field of a multipole.
std::string time() const
Return time.
Definition: Timer.cpp:42
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
Definition: OpalBeamline.h:197
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
void computeSpaceCharge()
Interface for RF cavity.
Definition: RFCavity.h:37
double getM() const
The constant mass per particle.
Definition: PartData.h:112
CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr< Component > &comp) const
Definition: OpalBeamline.h:209
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Definition: Vector.h:243
Vector_t rotateFrom(const Vector_t &r) const
void setT(double t)
void findStartPosition(const BorisPusher &pusher)
const std::string name
CoordinateSystemTrafo getMisalignment(const std::shared_ptr< Component > &comp) const
Definition: OpalBeamline.h:219
void autophaseCavities(const BorisPusher &pusher)
std::string::const_iterator iterator_t
Definition: array.cpp:8
ParticleAttrib< int > Bin
CoordinateSystemTrafo inverted() const
Vector_t getR(int i)
double getEnergy(Vector_t p, double mass)
Definition: Util.h:29
Quaternion getInitialDirection() const
Definition: TBeamline.h:460
void save3DLattice()
void timeStep(double tStep, double zCat=0.0)
performs a time-step for all active slices (also handles emission)
Inform & level3(Inform &inf)
Definition: Inform.cpp:47
std::string::iterator iterator
Definition: MSLang.h:16
double zstart_m
where to start
void get_bounds(Vector_t &min, Vector_t &max)
returns bounds of envelope bunch
void dumpStats(long long step)
double getEmissionDeltaT()
static TimerRef getTimer(const char *nm)
Definition: IpplTimings.h:182
virtual Vector_t getOrigin3D() const
Definition: Beamline.cpp:49
static void stopTimer(TimerRef t)
Definition: IpplTimings.h:192
int getTotalNum()
returns the total number of slices
Definition: Inform.h:41
IpplTimings::TimerRef timeFieldEvaluation_m
Inform & level1(Inform &inf)
Definition: Inform.cpp:45
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:95
void push(Vector_t &R, const Vector_t &P, const double &dt) const
Definition: BorisPusher.h:116
double gamma
Definition: PartData.h:100
void writePhaseSpace(const long long step, const double &sposRef)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
void storeCavityInformation()
Write cavity information from H5 file.
Definition: DataSink.cpp:131
std::set< std::shared_ptr< Component > > value_t
Definition: IndexMap.h:18
long long getGlobalTrackStep() const
Vector_t transformFrom(const Vector_t &r) const
void save3DInput()
Track particles or bunches.
Definition: Tracker.h:84