35#include <gsl/gsl_math.h>
36#include <gsl/gsl_eigen.h>
37#include <gsl/gsl_linalg.h>
41 : mapAnalysis_m(
IpplTimings::getTimer(
"mapAnalysis"))
42 , bunchAnalysis_m(
IpplTimings::getTimer(
"bunchAnalysis"))
50 for (
int i = 0; i < 6; i++) {
51 for (
int j = 0; j < 6; j++) {
57 gsl_matrix_view m = gsl_matrix_view_array(data, 6, 6);
58 gsl_vector_complex *eval = gsl_vector_complex_alloc(6);
59 gsl_matrix_complex *evec = gsl_matrix_complex_alloc(6, 6);
60 gsl_matrix_complex *eveci = gsl_matrix_complex_alloc(6, 6);
61 gsl_permutation * p = gsl_permutation_alloc(6);
62 gsl_eigen_nonsymmv_workspace * w = gsl_eigen_nonsymmv_alloc(6);
65 gsl_eigen_nonsymmv(&m.matrix, eval, evec, w);
66 gsl_eigen_nonsymmv_free(w);
67 gsl_eigen_nonsymmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);
69 for (
int i = 0; i < 6; ++i) {
70 eigenVal[i][i] = std::complex<double>(
71 GSL_REAL(gsl_vector_complex_get(eval, i)),
72 GSL_IMAG(gsl_vector_complex_get(eval, i)));
73 for (
int j = 0; j < 6; ++j) {
74 eigenVec[i][j] = std::complex<double>(
75 GSL_REAL(gsl_matrix_complex_get(evec, i, j)),
76 GSL_IMAG(gsl_matrix_complex_get(evec, i, j)));
81 gsl_linalg_complex_LU_decomp(evec, p, &s);
82 gsl_linalg_complex_LU_invert(evec, p, eveci);
85 for (
int i = 0; i < 6; ++i) {
86 for (
int j = 0; j < 6; ++j) {
87 invEigenVec[i][j] = std::complex<double>(
88 GSL_REAL(gsl_matrix_complex_get(eveci, i, j)),
89 GSL_IMAG(gsl_matrix_complex_get(eveci, i, j)));
94 gsl_vector_complex_free(eval);
95 gsl_matrix_complex_free(evec);
96 gsl_matrix_complex_free(eveci);
104 cfMatrix_t cM, qMatrix, invqMatrix, nMatrix, invnMatrix, rMatrix;
106 for (
int i = 0; i < 6; i++){
107 for (
int j = 0; j < 6; j++){
108 cM[i][j]=std::complex<double>(M[i][j], 0);
112 for (
int i = 0; i < 6; i = i+2){
113 qMatrix[ i][ i] = std::complex<double>(1., 0);
114 qMatrix[ i][1+i] = std::complex<double>(0, 1.);
115 qMatrix[1+i][ i] = std::complex<double>(1., 0);
116 qMatrix[1+i][1+i] = std::complex<double>(0, -1);
118 invqMatrix[ i][ i] = std::complex<double>(1., 0);
119 invqMatrix[ i][1+i] = std::complex<double>(1., 0);
120 invqMatrix[1+i][ i] = std::complex<double>(0., -1.);
121 invqMatrix[1+i][1+i] = std::complex<double>(0, 1.);
126 nMatrix = eigenVecM*qMatrix;
127 invnMatrix = invqMatrix* invEigenVecM;
130 rMatrix = invnMatrix * cM * nMatrix;
140 for (
int i = 0; i < 6; i++){
141 for (
int j = 0; j < 6; j++){
142 ctM[i][j] = std::complex<double>(tM[i][j], 0);
151 std::array<double, 3> phi;
153 for (
int i = 0; i < 3; i++){
159 for (
int i = 0; i < 6; i++){
160 for (
int j = 0; j < 6; j++){
161 cR[i][j] = std::complex<double>(R1[i][j], 0);
162 N1[i][j] = oldN[i][j].real();
170 cfMatrix_t eigenValM, eigenVecM, invEigenVecM, eigenVecMT;
174 cfMatrix_t cM, qMatrix, invqMatrix, nMatrix, invnMatrix, rMatrix;
181 for (
int i = 0; i < 6; i++){
182 for (
int j = 0; j < 6; j++){
183 cM[i][j] = std::complex<double>(M[i][j], 0);
187 for (
int i = 0; i < 6; i = i+2){
188 qMatrix[ i][ i] = std::complex<double>(1., 0);
189 qMatrix[ i][1+i] = std::complex<double>(0, 1.);
190 qMatrix[1+i][ i] = std::complex<double>(1., 0);
191 qMatrix[1+i][1+i] = std::complex<double>(0, -1);
193 invqMatrix[ i][ i] = std::complex<double>(1., 0);
194 invqMatrix[ i][1+i] = std::complex<double>(1., 0);
195 invqMatrix[1+i][ i] = std::complex<double>(0., -1.);
196 invqMatrix[1+i][1+i] = std::complex<double>(0, 1.);
202 N = eigenVecM*qMatrix;
203 invN = invqMatrix* invEigenVecM;
210 for (
int i = 0; i < 3; i++){
212 R[2*i+1][2*i+1] =
R[2*i][2*i];
214 R[2*i+1][2*i] = -
R[2*i][2*i+1];
223 for (
int i = 0; i < 3; i++){
233 for (
int i = 0; i < 6; i++){
234 for (
int j = 0; j < 6; j++){
235 M[i][j] = cM[i][j].real();
243 for (
int i = 0; i < 6; i++){
244 for (
int j = 0; j < 6; j++){
245 M[i][j] = cM[i][j].imag();
253 for (
int i = 0; i < 6; i++){
254 for (
int j = 0; j < 6; j++){
255 cM[i][j] = std::complex<double>(M[i][j], 0);
263 gsl_set_error_handler_off();
265 gsl_matrix_complex *m = gsl_matrix_complex_alloc(6, 6);
266 gsl_matrix_complex *invm = gsl_matrix_complex_alloc(6, 6);
267 gsl_permutation * p = gsl_permutation_alloc(6);
273 for (
int i = 0; i < 6; ++i) {
274 for (
int j = 0; j < 6; ++j) {
276 gsl_matrix_complex_set( m, i, j, temp);
281 int eigenDecompStatus = gsl_linalg_complex_LU_decomp(m, p, &s);
282 if (eigenDecompStatus != 0){
283 std::cout<<
"This actually works" <<
std::endl;
288 int invertStatus = gsl_linalg_complex_LU_invert(m, p, invm);
290 if ( invertStatus ) {
296 if (invertStatus != 0){
297 std::cout<<
"This actually works" <<
std::endl;
304 for (
int i = 0; i < 6; ++i) {
305 for (
int j = 0; j < 6; ++j) {
306 invM[i][j] = std::complex<double>(
307 GSL_REAL(gsl_matrix_complex_get(invm, i, j)),
308 GSL_IMAG(gsl_matrix_complex_get(invm, i, j)));
313 gsl_matrix_complex_free(m);
314 gsl_matrix_complex_free(invm);
315 gsl_permutation_free(p);
323 for (
int i = 0; i < 6; i++){
326 for (
int j = 0; j < 6; j += 2){
327 temp += 2 * (eigenVecM[j][i] *
std::conj(eigenVecM[j+1][i])).
imag();
332 for (
int j = 0; j < 6; j++){
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
FLieGenerator< T, N > imag(const FLieGenerator< std::complex< T >, N > &)
Take imaginary part of a complex generator.
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
Tps< T > sqrt(const Tps< T > &x)
Square root.
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
m_complex conj(const m_complex &c)
constexpr double e
The value of.
cfMatrix_t invertMatrix_m(const cfMatrix_t &M)
fMatrix_t createSkewMatrix_m()
cfMatrix_t complexTypeMatrix_m(fMatrix_t M)
void printPhaseShift_m(fMatrix_t &Sigma, fMatrix_t tM, cfMatrix_t &oldN)
void normalizeEigen_m(cfMatrix_t &eigenVec, cfMatrix_t &invEigenVec)
cfMatrix_t getBlockDiagonal_m(const fMatrix_t &M, cfMatrix_t &eigenVecM, cfMatrix_t &invEigenVecM)
fMatrix_t realPartOfMatrix_m(cfMatrix_t cM)
void eigenDecomp_m(const fMatrix_t &M, cfMatrix_t &eigenVal, cfMatrix_t &eigenVec, cfMatrix_t &invEigenVec)
fMatrix_t imagPartOfMatrix_m(cfMatrix_t cM)
void setNMatrix_m(fMatrix_t &M, cfMatrix_t &N, cfMatrix_t &invN)
fMatrix_t createRotMatrix_m(std::array< double, 3 > phi)