OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
|
#include <SigmaGenerator.h>
Public Types | |
typedef RealDiracMatrix::matrix_t | matrix_t |
Type for storing maps. More... | |
typedef RealDiracMatrix::sparse_matrix_t | sparse_matrix_t |
Type for storing the sparse maps. More... | |
typedef RealDiracMatrix::vector_t | vector_t |
Type for storing vectors. More... | |
typedef std::vector< double > | container_t |
Container for storing the properties for each angle. More... | |
typedef FTps< double, 2 *3 > | Series |
Type of the truncated power series. More... | |
typedef FVps< double, 2 *3 > | Map |
Type of a map. More... | |
typedef std::function< Series(double, double, double)> | Hamiltonian |
Type of the Hamiltonian for the cyclotron. More... | |
typedef std::function< Series(double, double, double)> | SpaceCharge |
Type of the Hamiltonian for the space charge. More... | |
Public Member Functions | |
SigmaGenerator (double I, double ex, double ey, double ez, double E, double m, double q, const Cyclotron *cycl, unsigned int N, unsigned int Nsectors, unsigned int truncOrder, bool write=true) | |
Constructs an object of type SigmaGenerator. More... | |
bool | match (double accuracy, unsigned int maxit, unsigned int maxitOrbit, Cyclotron *cycl, double denergy, double rguess, bool full) |
Searches for a matched distribution. More... | |
vector_t | decouple (const matrix_t &Mturn, sparse_matrix_t &R, sparse_matrix_t &invR) |
Block diagonalizes the symplex part of the one turn transfer matrix. More... | |
double | isEigenEllipse (const matrix_t &Mturn, const matrix_t &sigma) |
Checks if the sigma-matrix is an eigenellipse and returns the L2 error. More... | |
matrix_t & | getSigma () |
Returns the converged stationary distribution. More... | |
unsigned int | getIterations () const |
Returns the number of iterations needed for convergence (if not converged, it returns zero) More... | |
double | getError () const |
Returns the error (if the program didn't converged, one can call this function to check the error) More... | |
std::array< double, 3 > | getEmittances () const |
const double & | getInjectionRadius () const |
const double & | getInjectionMomentum () const |
Private Member Functions | |
void | initialize (double, double) |
matrix_t | updateInitialSigma (const matrix_t &, const vector_t &, sparse_matrix_t &, sparse_matrix_t &) |
Computes the new initial sigma matrix. More... | |
void | updateSigma (const std::vector< matrix_t > &, const std::vector< matrix_t > &) |
Computes new sigma matrices (one for each angle) More... | |
double | L2ErrorNorm (const matrix_t &, const matrix_t &) |
Returns the L2-error norm between the old and new sigma-matrix. More... | |
std::string | float2string (double val) |
Transforms a floating point value to a string. More... | |
void | writeOrbitOutput_m (const container_t &r_turn, const container_t &peo, const container_t &h_turn, const container_t &fidx_turn, const container_t &ds_turn) |
Called within SigmaGenerator::match(). More... | |
void | writeMatrix (std::ofstream &, const matrix_t &) |
template<class matrix > | |
void | reduce (matrix &) |
template<class matrix > | |
void | expand (matrix &) |
Private Attributes | |
double | I_m |
Stores the value of the current, \( \left[I\right] = A \). More... | |
std::array< double, 3 > | emittance_m |
double | wo_m |
Is the orbital frequency, \( \left[\omega_{o}\right] = \frac{1}{s} \). More... | |
double | E_m |
Stores the user-define energy, \( \left[E\right] = MeV \). More... | |
double | gamma_m |
double | gamma2_m |
Relativistic factor squared. More... | |
double | nh_m |
Harmonic number, \( \left[N_{h}\right] = 1 \). More... | |
double | beta_m |
Velocity (c/v), \( \left[\beta\right] = 1 \). More... | |
double | mass_m |
Is the mass of the particles, \( \left[m\right] = \frac{MeV}{c^{2}} \). More... | |
double | q_m |
Is the particle charge [e]. More... | |
unsigned int | niterations_m |
Is the number of iterations needed for convergence. More... | |
bool | converged_m |
Is true if converged, false otherwise. More... | |
double | Emin_m |
Minimum energy needed in cyclotron, \( \left[E_{min}\right] = MeV \). More... | |
double | Emax_m |
Maximum energy reached in cyclotron, \( \left[E_{max}\right] = MeV \). More... | |
unsigned int | N_m |
Number of integration steps for closed orbit computation. More... | |
unsigned int | nSectors_m |
Number of (symmetric) sectors the field is averaged over. More... | |
unsigned int | nStepsPerSector_m |
Number of integration steps per sector (--> also: number of maps per sector) More... | |
unsigned int | nSteps_m |
Number of integration steps in total. More... | |
double | error_m |
Error of computation. More... | |
unsigned int | truncOrder_m |
Truncation order of the power series for the Hamiltonian (cyclotron and space charge) More... | |
bool | write_m |
Decides for writing output (default: true) More... | |
matrix_t | sigma_m |
Stores the stationary distribution (sigma matrix) More... | |
std::vector< matrix_t > | sigmas_m |
Vector storing the second moment matrix for each angle. More... | |
Hamiltonian | H_m |
Stores the Hamiltonian of the cyclotron. More... | |
SpaceCharge | Hsc_m |
Stores the Hamiltonian for the space charge. More... | |
Series | x_m |
All variables x, px, z, pz, l, delta. More... | |
Series | px_m |
Series | z_m |
Series | pz_m |
Series | l_m |
Series | delta_m |
double | rinit_m |
double | prinit_m |
RealDiracMatrix | rdm_m |
RealDiracMatrix-class member used for decoupling More... | |
Definition at line 51 of file SigmaGenerator.h.
typedef std::vector<double> SigmaGenerator::container_t |
Container for storing the properties for each angle.
Definition at line 61 of file SigmaGenerator.h.
typedef std::function<Series(double,double,double)> SigmaGenerator::Hamiltonian |
Type of the Hamiltonian for the cyclotron.
Definition at line 67 of file SigmaGenerator.h.
typedef FVps<double,2*3> SigmaGenerator::Map |
Type of a map.
Definition at line 65 of file SigmaGenerator.h.
Type for storing maps.
Definition at line 55 of file SigmaGenerator.h.
typedef FTps<double,2*3> SigmaGenerator::Series |
Type of the truncated power series.
Definition at line 63 of file SigmaGenerator.h.
typedef std::function<Series(double,double,double)> SigmaGenerator::SpaceCharge |
Type of the Hamiltonian for the space charge.
Definition at line 69 of file SigmaGenerator.h.
Type for storing the sparse maps.
Definition at line 57 of file SigmaGenerator.h.
Type for storing vectors.
Definition at line 59 of file SigmaGenerator.h.
SigmaGenerator::SigmaGenerator | ( | double | I, |
double | ex, | ||
double | ey, | ||
double | ez, | ||
double | E, | ||
double | m, | ||
double | q, | ||
const Cyclotron * | cycl, | ||
unsigned int | N, | ||
unsigned int | Nsectors, | ||
unsigned int | truncOrder, | ||
bool | write = true |
||
) |
Constructs an object of type SigmaGenerator.
I | specifies the current for which a matched distribution should be found, \( [I] = A \) |
ex | is the emittance in x-direction (horizontal), \( \left[\varepsilon_{x}\right] = \pi\ mm\ mrad \) |
ey | is the emittance in y-direction (longitudinal), \( \left[\varepsilon_{y}\right] = \pi\ mm\ mrad \) |
ez | is the emittance in z-direction (vertical), \( \left[\varepsilon_{z}\right] = \pi\ mm\ mrad \) |
E | is the energy, \( \left[E\right] = MeV \) |
m | is the mass of the particles \( \left[m\right] = \frac{MeV}{c^{2}} \) |
q | is the particle charge [e] |
cycl | is the cyclotron element |
N | is the number of integration steps (closed orbit computation). That's why its also the number of maps (for each integration step a map) |
Nsectors | is the number of sectors that the field map is averaged over (closed orbit computation) |
truncOrder | is the truncation order for power series of the Hamiltonian |
write | is a boolean (default: true). If true all maps of all iterations are stored, otherwise not. |
Definition at line 55 of file SigmaGenerator.cpp.
References abs(), beta_m, Physics::c, delta_m, Emin_m, emittance_m, Physics::epsilon_0, gamma2_m, gamma_m, Util::getBetaGamma(), H_m, Hsc_m, I_m, l_m, FTps< double, 2 *3 >::makeVariable(), mass_m, Units::MeV2eV, Units::mm2m, Units::mrad2rad, nh_m, Physics::pi, px_m, pz_m, q_m, FTps< double, 2 *3 >::setGlobalTruncOrder(), sqrt(), truncOrder_m, Physics::two_pi, wo_m, x_m, and z_m.
SigmaGenerator::vector_t SigmaGenerator::decouple | ( | const matrix_t & | Mturn, |
sparse_matrix_t & | R, | ||
sparse_matrix_t & | invR | ||
) |
Block diagonalizes the symplex part of the one turn transfer matrix.
It computes the transformation matrix R and its inverse invR.
Mturn | is a 6x6 dimensional one turn transfer matrix |
R | is the 6x6 dimensional transformation matrix (gets computed) |
invR | is the 6x6 dimensional inverse transformation (gets computed) |
Definition at line 410 of file SigmaGenerator.cpp.
References RealDiracMatrix::diagonalize(), Attrib::Distribution::R, rdm_m, and RealDiracMatrix::symplex().
Referenced by match().
|
private |
Definition at line 353 of file SigmaGenerator.h.
|
private |
Transforms a floating point value to a string.
val | is the floating point value which is transformed to a string |
Definition at line 814 of file SigmaGenerator.cpp.
Referenced by initialize(), match(), updateInitialSigma(), updateSigma(), and writeOrbitOutput_m().
|
inline |
Returns the emittances (ex,ey,ez) in \( \pi\ mm\ mrad \) for which the code converged (since the whole simulation is done on normalized emittances)
Definition at line 308 of file SigmaGenerator.h.
References beta_m, emittance_m, gamma_m, Units::m2mm, Physics::pi, and Units::rad2mrad.
Referenced by match().
|
inline |
Returns the error (if the program didn't converged, one can call this function to check the error)
Definition at line 301 of file SigmaGenerator.h.
References error_m.
|
inline |
Definition at line 142 of file SigmaGenerator.h.
References prinit_m.
|
inline |
Definition at line 138 of file SigmaGenerator.h.
References rinit_m.
|
inline |
Returns the number of iterations needed for convergence (if not converged, it returns zero)
Definition at line 294 of file SigmaGenerator.h.
References converged_m, and niterations_m.
|
inline |
Returns the converged stationary distribution.
Definition at line 287 of file SigmaGenerator.h.
References sigma_m.
|
private |
Initializes a first guess of the sigma matrix with the assumption of a spherical symmetric beam (ex = ey = ez). For each angle split the same initial guess is taken.
nuz | is the vertical tune |
ravg | is the average radius of the closed orbit |
Definition at line 459 of file SigmaGenerator.cpp.
References a, abs(), Physics::alpha, beta_m, Physics::c, Util::combineFilePath(), E_m, emittance_m, Physics::epsilon_0, float2string(), gamma2_m, gamma_m, OpalData::getAuxiliaryOutputDirectory(), OpalData::getInstance(), I_m, mass_m, Units::MeV2eV, Physics::mu_0, nh_m, nSteps_m, Physics::pi, pow(), q_m, sigmas_m, sqrt(), Physics::two_pi, wo_m, write_m, and writeMatrix().
Referenced by match().
Checks if the sigma-matrix is an eigenellipse and returns the L2 error.
The idea of this function is taken from Dr. Christian Baumgarten's program.
Mturn | is the one turn transfer matrix |
sigma | is the sigma matrix to be tested |
Definition at line 446 of file SigmaGenerator.cpp.
References L2ErrorNorm().
Returns the L2-error norm between the old and new sigma-matrix.
oldS | is the old sigma matrix |
newS | is the new sigma matrix |
Definition at line 800 of file SigmaGenerator.cpp.
References sqrt().
Referenced by isEigenEllipse(), and match().
bool SigmaGenerator::match | ( | double | accuracy, |
unsigned int | maxit, | ||
unsigned int | maxitOrbit, | ||
Cyclotron * | cycl, | ||
double | denergy, | ||
double | rguess, | ||
bool | full | ||
) |
Searches for a matched distribution.
Returns "true" if a matched distribution within the accuracy could be found, returns "false" otherwise.
accuracy | is used for computing the equilibrium orbit (to a certain accuracy) |
maxit | is the maximum number of iterations (the program stops if within this value no stationary distribution was found) |
maxitOrbit | is the maximum number of iterations for finding closed orbit |
angle | defines the start of the sector (one can choose any angle between 0° and 360°) |
denergy | energy step size for closed orbit finder [MeV] |
rguess | value of radius for closed orbit finder |
type | specifies the magnetic field format (e.g. CARBONCYCL) |
full | match over full turn not just single sector |
Definition at line 155 of file SigmaGenerator.cpp.
References Util::combineFilePath(), converged_m, decouple(), Physics::e, E_m, endl(), error_m, float2string(), OpalData::getAuxiliaryOutputDirectory(), getEmittances(), OpalData::getInstance(), Cyclotron::getPHIinit(), gmsg, H_m, Hsc_m, initialize(), L2ErrorNorm(), mass_m, N_m, niterations_m, nSectors_m, nSteps_m, nStepsPerSector_m, prinit_m, q_m, Attrib::Distribution::R, rinit_m, sigma_m, sigmas_m, truncOrder_m, updateInitialSigma(), updateSigma(), write_m, writeMatrix(), and writeOrbitOutput_m().
|
private |
Definition at line 320 of file SigmaGenerator.h.
|
private |
Computes the new initial sigma matrix.
M | is the 6x6 one turn transfer matrix |
R | is the transformation matrix |
invR | is the inverse transformation matrix |
Definition at line 618 of file SigmaGenerator.cpp.
References beta_m, Util::combineFilePath(), E_m, emittance_m, fabs(), float2string(), gamma_m, OpalData::getAuxiliaryOutputDirectory(), OpalData::getInstance(), prod(), Attrib::Distribution::R, sign(), sqrt(), write_m, and writeMatrix().
Referenced by match().
|
private |
Computes new sigma matrices (one for each angle)
Mscs is a vector of all space charge maps Mcycs is a vector of all cyclotron maps
Definition at line 762 of file SigmaGenerator.cpp.
References Util::combineFilePath(), E_m, float2string(), OpalData::getAuxiliaryOutputDirectory(), OpalData::getInstance(), niterations_m, nSteps_m, prod(), sigmas_m, write_m, and writeMatrix().
Referenced by match().
|
private |
Definition at line 858 of file SigmaGenerator.cpp.
References endl(), and write_m.
Referenced by initialize(), match(), updateInitialSigma(), and updateSigma().
|
private |
Called within SigmaGenerator::match().
r_turn | is the radius [m] |
peo | is the momentum |
h_turn | is the inverse bending radius |
fidx_turn | is the field index |
ds_turn | is the path length element |
Definition at line 821 of file SigmaGenerator.cpp.
References Util::combineFilePath(), E_m, endl(), float2string(), OpalData::getAuxiliaryOutputDirectory(), OpalData::getInstance(), and write_m.
Referenced by match().
|
private |
Velocity (c/v), \( \left[\beta\right] = 1 \).
Definition at line 166 of file SigmaGenerator.h.
Referenced by getEmittances(), initialize(), SigmaGenerator(), and updateInitialSigma().
|
private |
Is true if converged, false otherwise.
Definition at line 174 of file SigmaGenerator.h.
Referenced by getIterations(), and match().
|
private |
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Stores the user-define energy, \( \left[E\right] = MeV \).
Definition at line 156 of file SigmaGenerator.h.
Referenced by initialize(), match(), updateInitialSigma(), updateSigma(), and writeOrbitOutput_m().
|
private |
Maximum energy reached in cyclotron, \( \left[E_{max}\right] = MeV \).
Definition at line 178 of file SigmaGenerator.h.
|
private |
Minimum energy needed in cyclotron, \( \left[E_{min}\right] = MeV \).
Definition at line 176 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Stores the desired emittances, \( \left[\varepsilon_{x}\right] = \left[\varepsilon_{y}\right] = \left[\varepsilon_{z}\right] = m \ rad \)
Definition at line 152 of file SigmaGenerator.h.
Referenced by getEmittances(), initialize(), SigmaGenerator(), and updateInitialSigma().
|
private |
Error of computation.
Definition at line 190 of file SigmaGenerator.h.
Referenced by getError(), and match().
|
private |
Relativistic factor squared.
Definition at line 162 of file SigmaGenerator.h.
Referenced by initialize(), and SigmaGenerator().
|
private |
Relativistic factor (which can be computed out ot the kinetic energy and rest mass (potential energy)), \( \left[\gamma\right] = 1 \)
Definition at line 160 of file SigmaGenerator.h.
Referenced by getEmittances(), initialize(), SigmaGenerator(), and updateInitialSigma().
|
private |
Stores the Hamiltonian of the cyclotron.
Definition at line 205 of file SigmaGenerator.h.
Referenced by match(), and SigmaGenerator().
|
private |
Stores the Hamiltonian for the space charge.
Definition at line 208 of file SigmaGenerator.h.
Referenced by match(), and SigmaGenerator().
|
private |
Stores the value of the current, \( \left[I\right] = A \).
Definition at line 148 of file SigmaGenerator.h.
Referenced by initialize(), and SigmaGenerator().
|
private |
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Is the mass of the particles, \( \left[m\right] = \frac{MeV}{c^{2}} \).
Definition at line 168 of file SigmaGenerator.h.
Referenced by initialize(), match(), and SigmaGenerator().
|
private |
Number of integration steps for closed orbit computation.
Definition at line 180 of file SigmaGenerator.h.
Referenced by match().
|
private |
Harmonic number, \( \left[N_{h}\right] = 1 \).
Definition at line 164 of file SigmaGenerator.h.
Referenced by initialize(), and SigmaGenerator().
|
private |
Is the number of iterations needed for convergence.
Definition at line 172 of file SigmaGenerator.h.
Referenced by getIterations(), match(), and updateSigma().
|
private |
Number of (symmetric) sectors the field is averaged over.
Definition at line 182 of file SigmaGenerator.h.
Referenced by match().
|
private |
Number of integration steps in total.
Definition at line 187 of file SigmaGenerator.h.
Referenced by initialize(), match(), and updateSigma().
|
private |
Number of integration steps per sector (--> also: number of maps per sector)
Definition at line 184 of file SigmaGenerator.h.
Referenced by match().
|
private |
Definition at line 214 of file SigmaGenerator.h.
Referenced by getInjectionMomentum(), and match().
|
private |
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Is the particle charge [e].
Definition at line 170 of file SigmaGenerator.h.
Referenced by initialize(), match(), and SigmaGenerator().
|
private |
RealDiracMatrix-class member used for decoupling
Definition at line 274 of file SigmaGenerator.h.
Referenced by decouple().
|
private |
Definition at line 213 of file SigmaGenerator.h.
Referenced by getInjectionRadius(), and match().
|
private |
Stores the stationary distribution (sigma matrix)
Definition at line 199 of file SigmaGenerator.h.
Referenced by getSigma(), and match().
|
private |
Vector storing the second moment matrix for each angle.
Definition at line 202 of file SigmaGenerator.h.
Referenced by initialize(), match(), and updateSigma().
|
private |
Truncation order of the power series for the Hamiltonian (cyclotron and space charge)
Definition at line 193 of file SigmaGenerator.h.
Referenced by match(), and SigmaGenerator().
|
private |
Is the orbital frequency, \( \left[\omega_{o}\right] = \frac{1}{s} \).
Definition at line 154 of file SigmaGenerator.h.
Referenced by initialize(), and SigmaGenerator().
|
private |
Decides for writing output (default: true)
Definition at line 196 of file SigmaGenerator.h.
Referenced by initialize(), match(), updateInitialSigma(), updateSigma(), writeMatrix(), and writeOrbitOutput_m().
|
private |
All variables x, px, z, pz, l, delta.
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().
|
private |
Definition at line 211 of file SigmaGenerator.h.
Referenced by SigmaGenerator().