16 std::shared_ptr<Component> cavity):
20 double zbegin = 0.0, zend = 0.0;
22 cavity->initialise(fakeBunch, zbegin, zend);
36 throw OpalException(
"CavityAutophaser::getPhaseAtMaxEnergy()",
37 "given element is not a cavity");
45 double originalPhase = element->
getPhasem();
47 double optimizedPhase = 0.0;
48 double finalEnergy = 0.0;
49 double newPhase = 0.0;
56 element->
setPhasem(optimizedPhase + originalPhase);
59 originalPhase += optimizedPhase;
68 ss << std::setw(2) << std::left <<
c;
71 << std::left << std::setw(68) << std::setfill(
'*') << ss.str()
72 << std::setfill(
' ') <<
endl);
75 double AstraPhase = 0.0;
78 if (amplitude < 0.0) {
79 amplitude = -amplitude;
85 if (amplitude == 0.0 && designEnergy <= 0.0) {
86 throw OpalException(
"CavityAutophaser::getPhaseAtMaxEnergy()",
87 "neither amplitude or design energy given to cavity " + element->
getName());
90 if (designEnergy > 0.0) {
91 const double length =
itsCavity_m->getElementLength();
93 throw OpalException(
"CavityAutophaser::getPhaseAtMaxEnergy()",
94 "length of cavity " + element->
getName() +
" is zero");
102 while (count < 1000) {
106 optimizedPhase = status.first;
107 finalEnergy = status.second;
109 if (
std::abs(designEnergy - finalEnergy) < 1
e-7)
break;
111 amplitude *=
std::abs(designEnergy / finalEnergy);
113 initialPhase = optimizedPhase;
120 optimizedPhase = status.first;
121 finalEnergy = status.second;
132 if (!opal->isOptimizerRun()) {
133 std::ofstream out(
"data/" +
itsCavity_m->getName() +
"_AP.dat");
143 <<
"E = " << finalEnergy <<
" [MeV], " <<
"phi_nom = " << originalPhase *
Physics::rad2deg <<
" [deg]\n"
144 <<
"Ez_0 = " << amplitude <<
" [MV/m]" <<
"\n"
145 <<
"time = " << (t + tErr) * 1e9 <<
" [ns], dt = " << dt * 1e12 <<
" [ps]" <<
endl);
150 finalEnergy = status.second;
161 <<
"E = " << finalEnergy <<
" [MeV], " <<
"phi_nom = " << originalPhase *
Physics::rad2deg <<
" [deg]\n"
162 <<
"Ez_0 = " << amplitude <<
" [MV/m]" <<
"\n"
163 <<
"time = " << (t + tErr) * 1e9 <<
" [ns], dt = " << dt * 1e12 <<
" [ps]" <<
endl);
168 optimizedPhase = originalPhase;
170 INFOMSG(
level1 <<
"* " << std::right << std::setw(83) << std::setfill(
'*') <<
"*\n"
171 << std::setfill(
' ') <<
endl);
173 return optimizedPhase;
200 double originalPhase = element->
getPhasem();
206 std::pair<double, double> status(originalPhase, E);
210 double Phimax = initialPhase;
211 double phi = initialPhase;
240 for(
int rl = 0; rl < numRefinements; ++ rl) {
242 phi = initialPhase - dphi;
248 phi = initialPhase + dphi;
259 std::pair<double, double> status(Phimax, E);
269 std::ofstream *out)
const {
286 return finalKineticEnergy;
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
constexpr double e
The value of .
The base class for all OPAL exceptions.
constexpr double two_pi
The value of .
virtual double getAmplitudem() const
double getPhaseAtMaxEnergy(const Vector_t &R, const Vector_t &P, double t, double dt)
virtual const std::string & getName() const
Get element name.
virtual void setAmplitudem(double vPeak)
virtual double getFrequencym() const
virtual bool getAutophaseVeto() const
constexpr double rad2deg
The conversion factor from radians to degrees.
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
static OpalData * getInstance()
std::shared_ptr< Component > itsCavity_m
double track(Vector_t R, Vector_t P, double t, const double dt, const double phase, std::ofstream *out=NULL) const
constexpr double pi
The value of .
double getQ() const
The constant charge per particle.
virtual double getPhasem() const
double getEnergyMeV(const Vector_t &P)
const PartData & itsReference_m
constexpr double c
The velocity of light in m/s.
Vektor< double, 3 > Vector_t
double guessCavityPhase(double t)
PETE_TBTree< FnFmod, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > fmod(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Tps< T > sqrt(const Tps< T > &x)
Square root.
virtual void setAutophaseVeto(bool veto=true)
virtual void setPhasem(double phase)
double getM() const
The constant mass per particle.
T euclidean_norm(const Vector< T > &)
Euclidean norm.
std::pair< double, double > optimizeCavityPhase(double initialGuess, double t, double dt)
double getEnergy(Vector_t p, double mass)
virtual std::pair< double, double > trackOnAxisParticle(const double &p0, const double &t0, const double &dt, const double &q, const double &mass, std::ofstream *out=NULL)
CavityAutophaser(const PartData &ref, std::shared_ptr< Component > cavity)
virtual double getDesignEnergy() const override
Inform & level1(Inform &inf)
void setMaxPhase(std::string elName, double phi)
Inform & endl(Inform &inf)
virtual double getAutoPhaseEstimate(const double &E0, const double &t0, const double &q, const double &m)