OPAL (Object Oriented Parallel Accelerator Library)  2024.1
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 
25 #include "FixedAlgebra/FTps.h"
26 #include "FixedAlgebra/FVps.h"
27 #include "FixedAlgebra/FTpsMath.h"
28 #include "Physics/Units.h"
29 
30 #define PSdim 6
31 
32 #include <functional>
33 
35 {
36 
37 public:
39 
40  explicit Hamiltonian(int truncOrder);
41 
59  Hamiltonian::series_t drift(const double& gamma0);
60 
68  Hamiltonian::series_t rbend(double& beta0,
69  double& gamma0,
70  double& q,
71  double& h,
72  double& K0);
73 
89  Hamiltonian::series_t sbend(const double& gamma0,
90  const double& h,
91  const double& k0);
92 
108  Hamiltonian::series_t bendFringe(double& beta0,
109  double& gamma0,
110  double& h,
111  double& k0,
112  series_t& ax,
113  series_t& az);
114 
115 
131  Hamiltonian::series_t quadrupole(const double& gamma0,
132  const double& q,
133  const double& k1);
134 
135 
145  Hamiltonian::series_t fringeField(const double& phi,
146  const double& k0);
147 
148 private:
154  double getBeta_m(const double& gamma);
155 
156 private:
157  int truncOrder_m;
158 
159 };
160 
161 
162 // /**Hamiltonian for Space Charges
163 // * \f[ K = \frac{3 q I \lambda}{20 \sqrt{5} \pi \epsilon_0 m c^3 \beta^2 \gamma^3} , \;
164 // * H_{sc} = -\frac{1}{2} K_x x^2
165 // * -\frac{1}{2} K_y y^2
166 // * -\frac{1}{2} K_z z^2 \gamma^2\f]
167 // */
168 // void spaceCharge(series_t& H,
169 // PartBunchBase<double, 3>* bunch)
170 // {
171 // //Derived form Distribution/SigmaGenerator.cpp
172 // // convert m from MeV/c^2 to eV*s^{2}/m^{2}
173 //
174 // double m = bunch->getM() / (Physics::c * Physics::c);
175 //
176 // // formula (57)
177 // double gamma = bunch->get_gamma();
178 // double beta = std::sqrt( 1. - 1/( gamma*gamma ) );
179 //
180 // double gamma2=gamma * gamma;
181 //
182 // double freq = itsBeam_m->getFrequency() * Units::MHz2Hz; // [freq] = Hz (form MHz)
183 // double I = itsBeam_m->getCurrent(); // [I] = A
184 // double q = bunch->getQ(); // [q] = e
185 //
186 // #ifdef PHIL_WRITE
187 // std::ofstream dAngle;
188 // dAngle.open("dipoleAngle.txt", std::ios::app);
189 // #endif
190 //
191 // dAngle << "Freq:" << freq << std::endl;
192 // dAngle << "I: " << I << std::endl;
193 // dAngle << "SigmaMatirx" << bunch->getSigmaMatrix() << std::endl;
194 // dAngle << "mass" << bunch->getM()<< std::endl;
195 // dAngle << "charge" << q << std::endl;
196 //
197 // //TODO check formula for lambda
198 // double lam = Physics::c / freq; // wavelength, [lam] = m
199 // double K3 = 3.0 * I * q * lam / (20.0 * std::sqrt(5.0) * Physics::pi * Physics::epsilon_0 * m *
200 // Physics::c * Physics::c * Physics::c * beta * beta * gamma * gamma2); // [K3] = m
201 // dAngle << "K3: " << K3 << std::endl;
202 // dAngle << "K3: " << lam << std::endl;
203 // dAngle << "gamma: " << gamma << std::endl;
204 // dAngle << "beta: " << beta << std::endl;
205 // // formula (30), (31)
206 // fMatrix_t sigmMatrix = bunch->getSigmaMatrix();
207 //
208 // double sx = std::sqrt(std::fabs(sigmMatrix(0,0))); //[sx] = m
209 // double sy = std::sqrt(std::fabs(sigmMatrix(2,2))); //[sy] = m
210 // double sz = std::sqrt(std::fabs(sigmMatrix(4,4))); //[sz] = m
211 //
212 // dAngle << "sx: " << sx << std::endl;
213 // dAngle << "sz: " << sz << std::endl;
214 // double tmp = sx * sy; // [tmp] = m^{2}
215 //
216 // double f = std::sqrt(tmp) / (3.0 * gamma * sz); // [f] = 1
217 // double kxy = K3 * std::fabs(1.0 - f) / ((sx + sy) * sz); // [kxy] = 1/m
218 //
219 // dAngle << "f: " << f << std::endl;
220 // dAngle << "kxy: " << kxy << std::endl;
221 // double Kx = kxy / sx; //[Kx] = 1/m^{2}
222 // double Ky = kxy / sy; //[Ky] = 1/m^{2}
223 // double Kz = K3 * f / (tmp * sz); //[Kz] = 1/m^{2}
224 //
225 // // Change units for application on [m], [p/p0] and [E/p0-1/b0]
226 // // (these units are for [mm], [mrad] and [promille])
227 // // according Hinterberger - Physik der Teilcherbeschleuniger Eq.4.8
228 //
229 // double mrad2pnorm= 1e3; // for small angles (tan(a) ~ a)
230 // double promille2delta = 1/(10 * bunch->getInitialBeta()); // [E/p0-1/b0] = [1/b0 * (E0 - E)/E0]
231 //
232 //
233 // H = ( -0.5 * Kx * x * x
234 // -0.5 * Ky * y * y ) * Units::mm2m / mrad2pnorm
235 // - (0.5 * Kz * z * z * gamma2) * promille2delta ;
236 // }
237 
238 
239 #endif
Hamiltonian::series_t drift(const double &gamma0)
Definition: Hamiltonian.cpp:37
series_t delta
Definition: Hamiltonian.h:47
Hamiltonian(int truncOrder)
Definition: Hamiltonian.cpp:24
series_t py
Definition: Hamiltonian.h:45
Hamiltonian::series_t fringeField(const double &phi, const double &k0)
Truncated power series in N variables of type T.
Definition: FLieGenerator.h:29
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 quadrupole(const double &gamma0, const double &q, const double &k1)
series_t y
Definition: Hamiltonian.h:44
Hamiltonian::series_t sbend(const double &gamma0, const double &h, const double &k0)
Definition: Hamiltonian.cpp:76
series_t x
Definition: Hamiltonian.h:42
series_t px
Definition: Hamiltonian.h:43
series_t z
Definition: Hamiltonian.h:46
Hamiltonian::series_t rbend(double &beta0, double &gamma0, double &q, double &h, double &K0)
Definition: Hamiltonian.cpp:49
FTps< double, 6 > series_t
Definition: Hamiltonian.h:38