21 const PartData &reference,
bool revBeam,
bool revTrack):
22 Tracker(beamline, reference, revBeam, revTrack) {
37 const std::vector<unsigned long long> &maxSteps,
39 const std::vector<double> &zstop,
40 const std::vector<double> &dt):
41 Tracker(beamline, reference, revBeam, revTrack),
52 for (std::vector<unsigned long long>::const_iterator it = maxSteps.begin(); it != maxSteps.end(); ++ it) {
55 for (std::vector<double>::const_iterator it = dt.begin(); it != dt.end(); ++ it) {
58 for (std::vector<double>::const_iterator it = zstop.begin(); it != zstop.end(); ++ it) {
105 for (; it < end; ++ it) {
120 if ((*fit).getElement()->getName() == elName) {
122 phase =
static_cast<TravelingWave *
>((*fit).getElement().get())->getPhasem();
123 static_cast<TravelingWave *
>((*fit).getElement().get())->setPhasem(phase + maxPhase);
125 phase =
static_cast<RFCavity *
>((*fit).getElement().get())->getPhasem();
126 static_cast<RFCavity *
>((*fit).getElement().get())->setPhasem(phase + maxPhase);
140 Inform msg(
"ParallelSliceTracker ");
147 msg <<
"\n-------------------------------------------------------------------------------------\n";
150 std::shared_ptr<Component> element(it->getElement());
151 std::string
name = element->getName();
156 phase =
static_cast<TravelingWave *
>(element.get())->getPhasem();
157 frequency =
static_cast<TravelingWave *
>(element.get())->getFrequencym();
159 phase =
static_cast<RFCavity *
>(element.get())->getPhasem();
160 frequency =
static_cast<RFCavity *
>(element.get())->getFrequencym();
163 msg << (it == cl.begin()?
"":
"\n")
165 <<
": phi = phi_nom + phi_maxE + global phase shift = " << (phase - globalTimeShift * frequency) * RADDEG <<
" degree, "
166 <<
"(global phase shift = " << -globalTimeShift *frequency *RADDEG <<
" degree) \n";
169 msg <<
"-------------------------------------------------------------------------------------\n"
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();
206 totalNumSteps +=
std::ceil(numSteps.front() * timeStepSizes.front() / minTimeStep);
285 *
gmsg << std::scientific;
306 if (step % 1000 + 1 == 1000) {
308 }
else if (step % 100 + 1 == 100) {
314 msg <<
" Step " << step <<
" at " <<
itsBunch_m->
zAvg() <<
" [m] t= "
327 double beta =
sqrt(1.0 - 1.0 / (gamma * gamma));
345 msg <<
"done executing ParallelSliceTracker" <<
endl;
367 for (; it != end; ++ it) {
389 Vector_t externalE, externalEThis, externalB, externalBThis, KR, KRThis, KT, KTThis;
398 elements = oth.
query(
pathLength_m + 0.5 * (rmax(2) + rmin(2)), rmax(2) - rmin(2));
405 const IndexMap::value_t::const_iterator end = elements.end();
407 for (
unsigned int i = 0; i < localNum; ++ i) {
414 IndexMap::value_t::const_iterator it = elements.begin();
415 for (; it != end; ++ it) {
442 (*it)->addKR(i, time, KRThis);
443 (*it)->addKT(i, time, KTThis);
445 externalE += fromLocal.
rotateTo(externalEThis);
446 externalB += fromLocal.
rotateTo(externalBThis);
590 IndexMap::value_t::const_iterator it = elements.begin();
591 const IndexMap::value_t::const_iterator end = elements.end();
593 for (; it != end; ++ it) {
600 if ((*it)->applyToReferenceParticle(localR,
605 *
gmsg <<
level1 <<
"The reference particle hit an element" <<
endl;
629 for (
auto element: elementSet) {
673 for (
unsigned int i = 0; i < localNum; ++ i) {
IpplTimings::TimerRef WakeFieldTimer_m
void setR(int i, const Vector_t &R)
void setP(int i, const Vector_t &P)
FieldList cavities_m
set multipacting flag
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
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 .
double getT()
returns the current time of the bunch
bool getRelativeFlag() const
virtual void visitBeamline(const Beamline &)
Apply the algorithm to a beam line.
core of the envelope tracker based on Rene Bakkers BET implementation
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
IpplTimings::TimerRef timeIntegrationTimer2_m
std::list< ClassicField > FieldList
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
OpalBeamline itsOpalBeamline_m
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)
void computeExternalFields(OrbitThreader &oth)
double zAvg()
calculate <z> [m]
virtual bool getAutophaseVeto() const
Vector_t get_pmean_Distribution() const
virtual Quaternion getInitialDirection() const
void updateReferenceParticle(const BorisPusher &pusher)
static bool SortAsc(const ClassicField &fle1, const ClassicField &fle2)
std::string getLengthString(double spos, unsigned int precision=3)
std::queue< double > zStop_m
where to stop
Vector_t getOrigin3D() const
std::queue< double > dtAllTracks_m
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
double zHead()
calculate the head of the bunch [m]
int statDumpFreq
The frequency to dump statistical values, e.e. dump data when stepstatDumpFreq==0.
Vector_t transformToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
constexpr double m_e
The electron rest mass in GeV.
virtual ~ParallelSliceTracker()
Inform & level2(Inform &inf)
bool reduce(Communicate &, InputIterator, InputIterator, OutputIterator, const ReduceOp &, bool *IncludeVal=0)
void restoreCavityPhases()
static OpalData * getInstance()
IpplTimings::TimerRef BinRepartTimer_m
Template class for beam lines.
double getGlobalPhaseShift()
units: (sec)
constexpr double pi
The value of .
unsigned long long getMaxSteps(std::queue< unsigned long long > numSteps)
double getQ() const
The constant charge per particle.
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
void computeSpaceChargeFields()
void switchElements(double scaleMargin=3.0)
double zTail()
calculate tail of bunch [m]
std::string getTimeString(double time, unsigned int precision=3)
constexpr double c
The velocity of light in m/s.
static void startTimer(TimerRef t)
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
CoordinateSystemTrafo toLabTrafo_m
double get_sPos()
return reference position
double currentSimulationTime_m
virtual void iterate(BeamlineVisitor &, bool r2l) const
Apply visitor to all elements of the line.
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)
FieldList getElementByType(ElementBase::ElementType)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
virtual void execute()
Apply the algorithm to the top-level beamline.
Vektor< double, 3 > Vector_t
void writeLastStepPhaseSpace(const long long step, const double &sposRef)
void swap(OpalBeamline &rhs)
int getLocalNum()
returns the number of local slices
An abstract sequence of beam line components.
static MPI_Comm getComm()
const PartData itsReference
The reference information.
double Eavg()
calculate the average energy of the bunch
Tps< T > sqrt(const Tps< T > &x)
Square root.
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
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.
ParticleAttrib< double > dt
double getP() const
The constant reference momentum per particle.
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
IpplTimings::TimerRef timeIntegrationTimer1_m
The magnetic field of a multipole.
bool hasEndOfLineReached()
std::string time() const
Return time.
Vector_t rotateToLocalCS(const std::shared_ptr< Component > &comp, const Vector_t &r) const
std::set< std::shared_ptr< Component > > getElements(const Vector_t &x)
void computeSpaceCharge()
double getM() const
The constant mass per particle.
CoordinateSystemTrafo getCSTrafoLab2Local(const std::shared_ptr< Component > &comp) const
EnvelopeBunch * itsBunch_m
T euclidean_norm(const Vector< T > &)
Euclidean norm.
Vector_t rotateFrom(const Vector_t &r) const
void findStartPosition(const BorisPusher &pusher)
CoordinateSystemTrafo getMisalignment(const std::shared_ptr< Component > &comp) const
void autophaseCavities(const BorisPusher &pusher)
std::string::const_iterator iterator_t
ParticleAttrib< int > Bin
CoordinateSystemTrafo inverted() const
double getEnergy(Vector_t p, double mass)
Quaternion getInitialDirection() const
void timeStep(double tStep, double zCat=0.0)
performs a time-step for all active slices (also handles emission)
Inform & level3(Inform &inf)
std::string::iterator iterator
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)
virtual Vector_t getOrigin3D() const
static void stopTimer(TimerRef t)
int getTotalNum()
returns the total number of slices
IpplTimings::TimerRef timeFieldEvaluation_m
Inform & level1(Inform &inf)
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
void push(Vector_t &R, const Vector_t &P, const double &dt) const
void writePhaseSpace(const long long step, const double &sposRef)
Inform & endl(Inform &inf)
void storeCavityInformation()
Write cavity information from H5 file.
std::set< std::shared_ptr< Component > > value_t
long long getGlobalTrackStep() const
Vector_t transformFrom(const Vector_t &r) const
Track particles or bunches.