32 #ifndef SIGMAGENERATOR_H
33 #define SIGMAGENERATOR_H
41 #include <boost/numeric/ublas/matrix.hpp>
67 typedef std::function<Series(double,double,double)>
Hamiltonian;
69 typedef std::function<Series(double,double,double)>
SpaceCharge;
88 double E,
double m,
double q,
const Cyclotron* cycl,
89 unsigned int N,
unsigned int Nsectors,
unsigned int truncOrder,
bool write =
true);
104 bool match(
double accuracy,
unsigned int maxit,
unsigned int maxitOrbit,
105 Cyclotron* cycl,
double denergy,
double rguess,
bool full);
242 const std::vector<matrix_t>&);
277 template<
class matrix>
280 template<
class matrix>
311 return std::array<double,3>{{
319 template<
class matrix>
333 for (
unsigned int i = 0; i < 2; ++i) {
338 M4x4(i + 2,0) = M(i + 4,0);
339 M4x4(i + 2,1) = M(i + 4,1);
344 M4x4(i + 2,2) = M(i + 4,4);
345 M4x4(i + 2,3) = M(i + 4,5);
352 template<
class matrix>
364 matrix M6x6 = boost::numeric::ublas::identity_matrix<double>(6,6);
366 for (
unsigned int i = 0; i < 2; ++i) {
371 M6x6(i + 4,0) = M(i + 2,0);
372 M6x6(i + 4,1) = M(i + 2,1);
377 M6x6(i + 4,4) = M(i + 2,2);
378 M6x6(i + 4,5) = M(i + 2,3);
double getError() const
Returns the error (if the program didn't converged, one can call this function to check the error) ...
boost::numeric::ublas::vector< double, std::vector< double > > vector_t
Dense vector type definition.
std::vector< matrix_t > sigmas_m
Vector storing the second moment matrix for each angle.
matrix_t sigma_m
Stores the stationary distribution (sigma matrix)
void initialize(double, double)
double I_m
Stores the value of the current, .
void writeMatrix(std::ofstream &, const matrix_t &)
boost::numeric::ublas::matrix< double > matrix_t
Dense matrix type definition.
RealDiracMatrix::matrix_t matrix_t
Type for storing maps.
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.
constexpr double rad2mrad
unsigned int nSectors_m
Number of (symmetric) sectors the field is averaged over.
const double & getInjectionRadius() const
constexpr double pi
The value of .
double L2ErrorNorm(const matrix_t &, const matrix_t &)
Returns the L2-error norm between the old and new sigma-matrix.
RealDiracMatrix::sparse_matrix_t sparse_matrix_t
Type for storing the sparse maps.
SpaceCharge Hsc_m
Stores the Hamiltonian for the space charge.
matrix_t updateInitialSigma(const matrix_t &, const vector_t &, sparse_matrix_t &, sparse_matrix_t &)
Computes the new initial sigma matrix.
std::function< Series(double, double, double)> Hamiltonian
Type of the Hamiltonian for the cyclotron.
double gamma2_m
Relativistic factor squared.
bool match(double accuracy, unsigned int maxit, unsigned int maxitOrbit, Cyclotron *cycl, double denergy, double rguess, bool full)
Searches for a matched distribution.
Series x_m
All variables x, px, z, pz, l, delta.
const double & getInjectionMomentum() const
double Emax_m
Maximum energy reached in cyclotron, .
RealDiracMatrix rdm_m
RealDiracMatrix-class member used for decoupling
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.
RealDiracMatrix::vector_t vector_t
Type for storing vectors.
boost::numeric::ublas::compressed_matrix< double, boost::numeric::ublas::row_major > sparse_matrix_t
Sparse matrix type definition.
double isEigenEllipse(const matrix_t &Mturn, const matrix_t &sigma)
Checks if the sigma-matrix is an eigenellipse and returns the L2 error.
double E_m
Stores the user-define energy, .
bool converged_m
Is true if converged, false otherwise.
double beta_m
Velocity (c/v), .
FTps< double, 2 *3 > Series
Type of the truncated power series.
unsigned int niterations_m
Is the number of iterations needed for convergence.
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().
matrix_t & getSigma()
Returns the converged stationary distribution.
double error_m
Error of computation.
std::vector< double > container_t
Container for storing the properties for each angle.
Vector truncated power series in n variables.
std::array< double, 3 > getEmittances() const
Hamiltonian H_m
Stores the Hamiltonian of the cyclotron.
unsigned int getIterations() const
Returns the number of iterations needed for convergence (if not converged, it returns zero) ...
std::string float2string(double val)
Transforms a floating point value to a string.
double Emin_m
Minimum energy needed in cyclotron, .
std::array< double, 3 > emittance_m
std::function< Series(double, double, double)> SpaceCharge
Type of the Hamiltonian for the space charge.
double q_m
Is the particle charge [e].
double nh_m
Harmonic number, .
void updateSigma(const std::vector< matrix_t > &, const std::vector< matrix_t > &)
Computes new sigma matrices (one for each angle)
unsigned int nSteps_m
Number of integration steps in total.
bool write_m
Decides for writing output (default: true)
unsigned int truncOrder_m
Truncation order of the power series for the Hamiltonian (cyclotron and space charge) ...
unsigned int nStepsPerSector_m
Number of integration steps per sector (–> also: number of maps per sector)
unsigned int N_m
Number of integration steps for closed orbit computation.
double wo_m
Is the orbital frequency, .
FVps< double, 2 *3 > Map
Type of a map.
double mass_m
Is the mass of the particles, .