OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Hamiltonian.h
Go to the documentation of this file.
1 //
2 // Class: Hamiltonian
3 // Constructs thick lens Hamiltonian up to arbitrary order for beamline elements
4 //
5 // Copyright (c) 2018, Philippe Ganz, ETH Zürich
6 // All rights reserved
7 //
8 // Implemented as part of the Master thesis
9 // "s-based maps from TPS & Lie-Series applied to Proton-Therapy Gantries"
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 
22 #ifndef HAMILTONIAN_H
23 #define HAMILTONIAN_H
24 
28 #define PSdim 6
29 
30 #include <functional>
31 
33 {
34 
35 public:
37 
38  explicit Hamiltonian(int truncOrder);
39 
57  Hamiltonian::series_t drift(const double& gamma0);
58 
66  Hamiltonian::series_t rbend(double& beta0,
67  double& gamma0,
68  double& q,
69  double& h,
70  double& K0);
71 
87  Hamiltonian::series_t sbend(const double& gamma0,
88  const double& h,
89  const double& k0);
90 
106  Hamiltonian::series_t bendFringe(double& beta0,
107  double& gamma0,
108  double& h,
109  double& k0,
110  series_t& ax,
111  series_t& az);
112 
113 
129  Hamiltonian::series_t quadrupole(const double& gamma0,
130  const double& q,
131  const double& k1);
132 
133 
143  Hamiltonian::series_t fringeField(const double& phi,
144  const double& k0);
145 
146 private:
152  double getBeta_m(const double& gamma);
153 
154 private:
155  int truncOrder_m;
156 
157 };
158 
159 
160 // /**Hamiltonian for Space Charges
161 // * \f[ K = \frac{3 q I \lambda}{20 \sqrt{5} \pi \epsilon_0 m c^3 \beta^2 \gamma^3} , \;
162 // * H_{sc} = -\frac{1}{2} K_x x^2
163 // * -\frac{1}{2} K_y y^2
164 // * -\frac{1}{2} K_z z^2 \gamma^2\f]
165 // */
166 // void spaceCharge(series_t& H,
167 // PartBunchBase<double, 3>* bunch)
168 // {
169 // //Derived form Distribution/SigmaGenerator.cpp
170 // // convert m from MeV/c^2 to eV*s^{2}/m^{2}
171 //
172 // double m = bunch->getM() / (Physics::c * Physics::c);
173 //
174 // // formula (57)
175 // double gamma = bunch->get_gamma();
176 // double beta = std::sqrt( 1. - 1/( gamma*gamma ) );
177 //
178 // double gamma2=gamma * gamma;
179 //
180 // double freq = itsBeam_m->getFrequency() * 1e6; // [freq] = Hz (form MHz)
181 // double I = itsBeam_m->getCurrent(); // [I] = A
182 // double q = bunch->getQ(); // [q] = e
183 //
184 // #ifdef PHIL_WRITE
185 // std::ofstream dAngle;
186 // dAngle.open("dipoleAngle.txt", std::ios::app);
187 // #endif
188 //
189 // dAngle << "Freq:" << freq << std::endl;
190 // dAngle << "I: " << I << std::endl;
191 // dAngle << "SigmaMatirx" << bunch->getSigmaMatrix() << std::endl;
192 // dAngle << "mass" << bunch->getM()<< std::endl;
193 // dAngle << "charge" << q << std::endl;
194 //
195 // //TODO check formula for lambda
196 // double lam = Physics::c / freq; // wavelength, [lam] = m
197 // double K3 = 3.0 * I * q * lam / (20.0 * std::sqrt(5.0) * Physics::pi * Physics::epsilon_0 * m *
198 // Physics::c * Physics::c * Physics::c * beta * beta * gamma * gamma2); // [K3] = m
199 // dAngle << "K3: " << K3 << std::endl;
200 // dAngle << "K3: " << lam << std::endl;
201 // dAngle << "gamma: " << gamma << std::endl;
202 // dAngle << "beta: " << beta << std::endl;
203 // // formula (30), (31)
204 // fMatrix_t sigmMatrix = bunch->getSigmaMatrix();
205 //
206 // double sx = std::sqrt(std::fabs(sigmMatrix(0,0))); //[sx] = m
207 // double sy = std::sqrt(std::fabs(sigmMatrix(2,2))); //[sy] = m
208 // double sz = std::sqrt(std::fabs(sigmMatrix(4,4))); //[sz] = m
209 //
210 // dAngle << "sx: " << sx << std::endl;
211 // dAngle << "sz: " << sz << std::endl;
212 // double tmp = sx * sy; // [tmp] = m^{2}
213 //
214 // double f = std::sqrt(tmp) / (3.0 * gamma * sz); // [f] = 1
215 // double kxy = K3 * std::fabs(1.0 - f) / ((sx + sy) * sz); // [kxy] = 1/m
216 //
217 // dAngle << "f: " << f << std::endl;
218 // dAngle << "kxy: " << kxy << std::endl;
219 // double Kx = kxy / sx; //[Kx] = 1/m^{2}
220 // double Ky = kxy / sy; //[Ky] = 1/m^{2}
221 // double Kz = K3 * f / (tmp * sz); //[Kz] = 1/m^{2}
222 //
223 // // Change units for application on [m], [p/p0] and [E/p0-1/b0]
224 // // (these units are for [mm], [mrad] and [promille])
225 // // according Hinterberger - Physik der Teilcherbeschleuniger Eq.4.8
226 //
227 // double mm2m = 1e3;
228 // double mrad2pnorm= 1e3; // for small angles (tan(a) ~ a)
229 // double promille2delta = 1/(10 * bunch->getInitialBeta()); // [E/p0-1/b0] = [1/b0 * (E0 - E)/E0]
230 //
231 //
232 // H = ( -0.5 * Kx * x * x
233 // -0.5 * Ky * y * y ) * mm2m / mrad2pnorm
234 // - (0.5 * Kz * z * z * gamma2) * promille2delta ;
235 // }
236 
237 
238 #endif
series_t delta
Definition: Hamiltonian.h:45
Hamiltonian::series_t sbend(const double &gamma0, const double &h, const double &k0)
Definition: Hamiltonian.cpp:76
Hamiltonian::series_t drift(const double &gamma0)
Definition: Hamiltonian.cpp:37
Hamiltonian::series_t rbend(double &beta0, double &gamma0, double &q, double &h, double &K0)
Definition: Hamiltonian.cpp:49
series_t z
Definition: Hamiltonian.h:44
Hamiltonian::series_t quadrupole(const double &gamma0, const double &q, const double &k1)
Hamiltonian(int truncOrder)
Definition: Hamiltonian.cpp:24
series_t y
Definition: Hamiltonian.h:42
series_t py
Definition: Hamiltonian.h:43
series_t x
Definition: Hamiltonian.h:40
Hamiltonian::series_t bendFringe(double &beta0, double &gamma0, double &h, double &k0, series_t &ax, series_t &az)
Definition: Hamiltonian.cpp:98
Hamiltonian::series_t fringeField(const double &phi, const double &k0)
FTps< double, 6 > series_t
Definition: Hamiltonian.h:36
series_t px
Definition: Hamiltonian.h:41
Truncated power series in N variables of type T.
Definition: FTps.h:45