6 #include <boost/numeric/ublas/matrix.hpp>
12 # define PS_Dim MomentState::maxsize // Set to 7; to include orbit.
18 std::vector<double> s,
21 void RdData(std::istream &inf);
22 void show(std::ostream&,
const int)
const;
23 void show(std::ostream&)
const;
27 class CavTLMLineType {
29 std::vector<double> s;
30 std::vector<std::string> Elem;
31 std::vector<double> E0,
37 void set(
const double,
const std::string &,
const double,
38 const double,
const double,
const double);
39 void show(
const int)
const;
46 typedef ElementRFCavity self_t;
48 typedef typename base_t::state_t
state_t;
51 std::string name, type;
52 double length, aperature, E0;
54 std::vector<RawParams> lattice;
59 std::vector<CavTLMLineType> CavTLMLineTab;
69 ElementRFCavity(
const Config& c);
71 void GetCavMatParams(
const int cavi,
72 const double beta_tab[],
const double gamma_tab[],
const double IonK[],
73 CavTLMLineType& lineref)
const;
75 void GetCavMat(
const int cavi,
const int cavilabel,
const double Rm,
Particle &real,
76 const double EfieldScl,
const double IonFyi_s,
77 const double IonEk_s, state_t::matrix_t &M,
78 CavTLMLineType &linetab)
const;
80 void GenCavMat2(
const int cavi,
const double dis,
const double EfieldScl,
const double TTF_tab[],
81 const double beta_tab[],
const double gamma_tab[],
const double Lambda,
82 Particle &real,
const double IonFys[],
const double Rm, state_t::matrix_t &M,
83 const CavTLMLineType& linetab)
const;
85 void PropagateLongRFCav(
Particle &ref,
double &phi_ref)
const;
87 void calRFcaviEmitGrowth(
const state_t::matrix_t &matIn,
Particle &state,
const int n,
88 const double betaf,
const double gamaf,
89 const double aveX2i,
const double cenX,
const double aveY2i,
const double cenY,
90 state_t::matrix_t &matOut);
92 void InitRFCav(
Particle &real, state_t::matrix_t &M, CavTLMLineType &linetab);
95 const double EfieldScl,
double &IonFy)
const;
97 void TransFacts(
const int cavilabel,
double beta,
const double CaviIonK,
const int gaplabel,
const double EfieldScl,
98 double &Ecen,
double &T,
double &Tp,
double &S,
double &Sp,
double &V0)
const;
100 void TransitFacMultipole(
const int cavi,
const std::string &flabel,
const double CaviIonK,
101 double &T,
double &S)
const;
103 virtual ~ElementRFCavity() {}
107 const self_t* O=
static_cast<const self_t*
>(other);
109 lattice = O->lattice;
110 mlptable = O->mlptable;
111 CavData = O->CavData;
112 CavTLMLineTab = O->CavTLMLineTab;
115 phi_ref = O->phi_ref;
116 EmitGrowth = O->EmitGrowth;
117 MpoleLevel = O->MpoleLevel;
119 forcettfcalc = O->forcettfcalc;
124 state_t& ST =
static_cast<state_t&
>(s);
125 using namespace boost::numeric::ublas;
132 if(!check_cache(ST)) {
133 last_ref_in = ST.ref;
134 last_real_in = ST.real;
138 recompute_matrix(ST);
140 for(
size_t i=0; i<last_real_in.size(); i++)
141 get_misalign(ST, ST.real[i], misalign[i], misalign_inv[i]);
145 last_ref_out = ST.ref;
146 last_real_out = ST.real;
148 ST.ref = last_ref_out;
149 assert(last_real_out.size()==ST.real.size());
150 std::copy(last_real_out.begin(),
158 for(
size_t i=0; i<last_real_in.size(); i++) {
159 ST.moment0[i] = prod(misalign[i], ST.moment0[i]);
162 x0[0] = ST.moment0[i][state_t::PS_X];
163 x0[1] = ST.moment0[i][state_t::PS_Y];
164 x2[0] = ST.moment1[i](0, 0);
165 x2[1] = ST.moment1[i](2, 2);
167 ST.moment0[i] = prod(transfer[i], ST.moment0[i]);
169 ST.moment0[i][state_t::PS_S] = ST.real[i].phis - ST.ref.
phis;
170 ST.moment0[i][state_t::PS_PS] = (ST.real[i].IonEk-ST.ref.
IonEk)/MeVtoeV;
172 ST.moment0[i] = prod(misalign_inv[i], ST.moment0[i]);
174 scratch = prod(misalign[i], ST.moment1[i]);
175 ST.moment1[i] = prod(scratch, trans(misalign[i]));
177 scratch = prod(transfer[i], ST.moment1[i]);
178 ST.moment1[i] = prod(scratch, trans(transfer[i]));
181 calRFcaviEmitGrowth(ST.moment1[i], ST.ref, i, ST.real[i].beta, ST.real[i].gamma, x2[0], x0[0], x2[1], x0[1], scratch);
182 ST.moment1[i] = scratch;
185 scratch = prod(misalign_inv[i], ST.moment1[i]);
186 ST.moment1[i] = prod(scratch, trans(misalign_inv[i]));
196 CavTLMLineTab.resize(last_real_in.size());
198 PropagateLongRFCav(ST.ref, phi_ref);
200 for(
size_t i=0; i<last_real_in.size(); i++) {
202 transfer[i] = boost::numeric::ublas::identity_matrix<double>(state_t::maxsize);
203 transfer[i](state_t::PS_X, state_t::PS_PX) = length;
204 transfer[i](state_t::PS_Y, state_t::PS_PY) = length;
207 double SampleIonK = ST.real[i].SampleIonK;
210 InitRFCav(ST.real[i], transfer[i], CavTLMLineTab[i]);
213 ST.real[i].SampleIonK = SampleIonK;
217 virtual const char*
type_name()
const {
return "rfcavity";}
Base class for all simulated elements.
double IonEk
Kinetic energy.
virtual const char * type_name() const =0
The abstract base class for all simulation state objects.
virtual void advance(StateBase &s)
Propogate the given State through this Element.
double phis
Absolute synchrotron phase [rad].
Associative configuration container.
virtual void recompute_matrix(state_t &ST)
recalculate 'transfer' taking into consideration the provided input state
double pos
absolute longitudinal position at end of Element
virtual void assign(const ElementVoid *other)=0
std::vector< value_t > transfer
final transfer matricies
An Element which propagates the statistical moments of a bunch.