21 #include <boost/numeric/ublas/matrix.hpp>
25 template<
typename Value_type,
typename Size_type>
34 typedef boost::numeric::ublas::matrix<value_type>
matrix_type;
59 std::vector<matrix_type>
computeMap(
const std::string,
const std::string,
const int);
62 std::pair<value_type, value_type>
getTunes();
85 std::pair<value_type, value_type>
tunes_m;
109 template<
typename Value_type,
typename Size_type>
112 : wo_m(wo), Emin_m(Emin), Emax_m(Emax), nth_m(nth), nr_m(nr), nSector_m(nSector), E_m(E), E0_m(E0)
115 template<
typename Value_type,
typename Size_type>
129 unsigned int cnt = 0;
135 std::vector<matrix_type> Mcyc(nth_m);
139 std::vector<value_type> gamma(nr_m), E(nr_m), PC(nr_m), nur(nr_m), nuz(nr_m);
141 std::vector<value_type>
R(nr_m), r(nr_m);
142 std::vector<value_type> Bmag(nr_m), k(nr_m);
143 std::vector<value_type>
alpha(nr_m), beta(nr_m);
147 std::ifstream infile2(filename2);
148 std::ifstream infile1(filename1);
150 if (!infile1.is_open() || !infile2.is_open()) {
151 std::cerr <<
"Couldn't open files!" <<
std::endl;
156 value_type rN1, cN1, sN1, aN1, phN1, rN2, cN2, sN2, aN2, phN2;
158 while (infile1 >> rN1 >> cN1 >> sN1 >> aN1 >> phN1 &&
159 infile2 >> rN2 >> cN2 >> sN2 >> aN2 >> phN2) {
167 Bmag[
n] = 0.5 * (f4 + f8);
179 std::vector<value_type> dalp(nr_m), dbet(nr_m), len2(nr_m), len(nr_m), t1eff(nr_m), t2eff(nr_m);
180 std::vector<value_type> t1(nr_m), t2(nr_m), t3(nr_m);
183 dalp[n-1] = (
alpha[n-1] -
alpha[n-2]) / (
R[n-1] -
R[n-2]);
184 dbet[0] = (beta[1] -
alpha[0]) / (
R[1] -
R[0]);
185 dbet[n-1] = (beta[n-1] - beta[n-2]) / (
R[n-1] -
R[n-2]);
187 for (
unsigned int i = 1; i < n - 1; ++i) {
188 dalp[i] =
R[i] * (
alpha[i+1] -
alpha[i-1]) / (
R[i+1] -
R[i-1]);
189 dbet[i] =
R[i] * (beta[i+1] - beta[i-1]) / (
R[i+1] -
R[i-1]);
192 for (
unsigned int i = 0; i <
n; ++i) {
203 len[i] = two_pi * r[i] + 2.0 * len2[i] *
value_type(N);
205 value_type g1 = phi + eps1;
206 value_type g2 = - phi + eps2;
212 value_type fac = gap / r[i] * K1;
221 gamma[i] = 1.0 /
std::sqrt(1.0 - beta_m * beta_m);
222 E[i] = E0_m * (gamma[i] - 1.0);
223 PC[i] = E0_m * gamma[i] * beta_m;
224 Bmag[i] = E0_m * 1.0e6 /
Physics::c * beta_m * gamma[i] / r[i] * 10.0;
226 if (!set && E[i] >= E_m) {
233 for (
unsigned int i = 0; i <
n; ++i) {
236 dBdr = (Bmag[1] - Bmag[0]) / (
R[1] -
R[0]);
238 dBdr = (Bmag[n-1] - Bmag[n-2]) / (
R[n-1] -
R[n-2]);
240 dBdr = (Bmag[i+1] - Bmag[i-1]) / (
R[i+1] -
R[i-1]);
246 k[i] = r[i] * r[i] / (
R[i] * BaV) * dBdr * (1.0 + bb *
value_type(N) / M_PI * s);
249 for (
unsigned int i = 0; i <
n; ++i) {
250 if ((k[1] > -0.999) && (E[i] > Emin_m) && (E[i] < Emax_m + 1.0)) {
272 nur[i] =
std::acos(Cx * (1.0 + lrho * tav) + Sx / kx * (tav - lrho * 0.5 * (kx * kx + tmul))) / tpiN;
274 tav = 0.5 * (t1eff[i] - t2eff[i]);
275 tmul = t1eff[i] * t2eff[i];
277 nuz[i] =
std::acos(Cy * (1.0 - lrho * tav) + Sy / ky * (0.5 * lrho * (pm * ky * ky - tmul) - tav)) / tpiN;
286 tunes_m = { nur[i], nuz[i] };
296 gam2 = gamma[i] * gamma[i];
299 matrix_type Mx = __Mix6(- t2[i], - t2eff[i], r[i]);
301 matrix_type Mb = __Mb6k(ds_m / r[i], r[i], k[i], gam2);
305 matrix_type M0 = boost::numeric::ublas::zero_matrix<value_type>(6);
306 matrix_type M1 = boost::numeric::ublas::zero_matrix<value_type>(6);
318 M0 = __Mb6k(ss / r[i], r[i], k[i], gam2);
319 M1 = __Md6(ds_m - ss, gam2);
321 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mx, M0);
323 ss = smax - slim - (ds_m - ss);
325 while ((ss > ds_m) && (j < nth_m)) {
331 Mcyc[j++] = __Md6(ss, gam2);
344 M0 = __Mb6k(ss / r[i], r[i], k[i], gam2);
345 M1 = __Md6(ds_m - ss, gam2);
347 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mx, M0);
349 ss = smax - slim - (ds_m - ss);
356 M0 = __Md6(ss, gam2);
357 M1 = __Mb6k((ds_m - ss) / r[i], r[i], k[i], gam2);
359 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mi, M0);
361 ss = slim * 0.5 - (ds_m - ss);
363 while ((ss > ds_m) && (j < nth_m)) {
369 Mcyc[j++] = __Mb6k(ss / r[i], r[i], k[i], gam2);
378 ss = smax - slim - ds_m;
385 M0 = __Md6(ss, gam2);
386 M1 = __Mb6k((ds_m - ss) / r[i], r[i], k[i], gam2);
388 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mi, M0);
390 ss = slim - (ds_m - ss);
392 while ((ss > ds_m) && (j < nth_m)) {
398 Mcyc[j++] = __Mb6k(ss / r[i], r[i], k[i], gam2);
405 ss = (smax - slim) * 0.5;
412 M0 = __Md6(ss, gam2);
413 M1 = __Mb6k((ds_m - ss) / r[i], r[i], k[i], gam2);
415 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mi, M0);
417 ss = slim - (ds_m - ss);
423 M0 = __Mb6k(ss / r[i], r[i], k[i], gam2);
424 M1 = __Md6(ds_m - ss, gam2);
426 Mcyc[j++] = matt_boost::gemmm<matrix_type>(M1, Mx, M0);
428 ss = (smax - slim) * 0.5 - (ds_m - ss);
429 while ((ss > ds_m) && (j < nth_m)) {
435 Mcyc[j++] = __Md6(ss, gam2);
441 return std::vector<matrix_type>(Mcyc);
444 template<
typename Value_type,
typename Size_type>
449 template<
typename Value_type,
typename Size_type>
454 template<
typename Value_type,
typename Size_type>
464 template<
typename Value_type,
typename Size_type>
466 matrix_type M = boost::numeric::ublas::identity_matrix<value_type>(6);
474 template<
typename Value_type,
typename Size_type>
476 matrix_type M = boost::numeric::ublas::identity_matrix<value_type>(6);
485 template<
typename Value_type,
typename Size_type>
487 matrix_type M = boost::numeric::ublas::identity_matrix<value_type>(6);
497 M(4,5) = l / gam2 - l + r * S;
498 M(4,0) = - (M(1,5) = S);
499 M(4,1) = - (M(0,5) = r * (1.0 - C));
504 template<
typename Value_type,
typename Size_type>
506 matrix_type M = boost::numeric::ublas::identity_matrix<value_type>(6);
510 if (k == 0.0)
return __Mb6(phi,r,gam2);
529 M(1,0) = - s * fx / r;
535 M(3,2) = sign * S * fy / r;
536 M(4,5) = l / gam2 - r / (1.0 + k) * (phi - s / fx);
537 M(4,0)= - (M(1,5) = s / fx);
538 M(4,1)= - (M(0,5) = r * (1.0 -
c) / (1.0 + k));
matrix_type __Md6(value_type, value_type)
Compute some matrix (ask Dr. C. Baumgarten)
boost::numeric::ublas::matrix< value_type > matrix_type
Type for specifying matrices.
PETE_TUTree< FnArcCos, typename T::PETE_Expr_t > acos(const PETE_Expr< T > &l)
value_type E0_m
Stores the potential energy [MeV].
Value_type value_type
Type of variable.
value_type Emin_m
Stores the minimum energy in MeV.
value_type getRadius()
Returns the radius.
std::pair< value_type, value_type > tunes_m
Stores the tunes (radial, vertical)
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Tps< T > sin(const Tps< T > &x)
Sine.
value_type Emax_m
Stores the maximum energy in MeV.
constexpr double two_pi
The value of .
value_type ds_m
Stores the path length.
Harmonics(value_type, value_type, value_type, size_type, size_type, size_type, value_type, value_type)
Constructor.
Tps< T > tan(const Tps< T > &x)
Tangent.
Tps< T > cot(const Tps< T > &x)
Cotangent.
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
constexpr double alpha
The fine structure constant, no dimension.
Size_type size_type
Type of size.
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
constexpr double c
The velocity of light in m/s.
value_type wo_m
Stores the nominal orbital frequency in Hz.
value_type getPathLength()
Returns step size.
matrix_type __Mb6k(value_type, value_type, value_type, value_type)
Compute some matrix (ask Dr. C. Baumgarten)
matrix_type __Mix6(value_type, value_type, value_type)
Compute some matrix (ask Dr. C. Baumgarten)
T * value_type(const SliceIterator< T > &)
size_type nSector_m
Stores the number of sectors.
Tps< T > sqrt(const Tps< T > &x)
Square root.
value_type radius_m
Stores the radius.
Tps< T > cos(const Tps< T > &x)
Cosine.
START
Defines starting point of computation.
T::PETE_Expr_t::PETE_Return_t prod(const PETE_Expr< T > &expr)
matrix_type __Mb6(value_type, value_type, value_type)
Compute some matrix (ask Dr. C. Baumgarten)
size_type nth_m
Stores the number of angle splits.
size_type nr_m
Stores the number of radial splits.
std::pair< value_type, value_type > getTunes()
Returns the radial and vertical tunes.
std::vector< matrix_type > computeMap(const std::string, const std::string, const int)
Compute all maps of the cyclotron using harmonics.
Tps< T > sinh(const Tps< T > &x)
Hyperbolic sine.
Inform & endl(Inform &inf)
value_type E_m
Stores the energy for which we perform the computation.