-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdensity_matrix.cpp
174 lines (152 loc) · 5.23 KB
/
density_matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <iostream>
#include <complex>
#include <cmath>
#include <fstream>
#include "density_matrix.h"
//initial condition fuction
Density_matrix::Density_matrix()
{
//initial conditions
num_steps=0;
density_matrix[0][0]={1,0};
//save initial conditions density matrix in output directory
std::ofstream outdata;
outdata.open("output/step_0.dat"); // opens the file
if( !outdata )
{
std::cerr << "Error: file could not be opened" << std::endl;
exit(1);
}
std::string outvalue;
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
double re=real(density_matrix[i][j]);
double im=imag(density_matrix[i][j]);
outvalue=std::to_string(re)+" "+std::to_string(im)+" 0.0";
outdata << outvalue << std::endl;
};
};
outdata.close();
};
//evolve density matrix function
double Density_matrix::evolve_density_matrix(double dt,double theta_12,double theta_13,double theta_23,double m1,double m2,double m3,double delta_cp,double E)
{
//light velocity
double c=1.0;
//hbar
double hbar=1.0;
// sin and cos for U matix
double s12=sin(theta_12);
double c12=cos(theta_12);
double s13=sin(theta_13);
double c13=cos(theta_13);
double s23=sin(theta_23);
double c23=cos(theta_23);
double sdcp=sin(delta_cp);
double cdcp=cos(delta_cp);
//obtain mixing matrix U
std::complex<double> mixing_matrix[3][3]={
{ {c12*c13,0} , {s12*c13,0} , {s13*cdcp,-s13*sdcp} } ,
{ {-s12*c23-c12*s13*s23*cdcp,-c12*s13*s23*sdcp} , {c12*c23-s12*s13*s23*cdcp,-s12*s13*s23*sdcp} , {c13*s23,0} },
{ {s12*s23-c12*s13*c23*cdcp,-c12*s13*c23*sdcp} , {-c12*s23-s12*s13*c23*cdcp,-s12*s13*c23*sdcp} , {c13*c23,0} }
};
//obtain mixin matrix U daguer
std::complex<double> mixing_matrix_daguer[3][3];
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
mixing_matrix_daguer[j][i]=std::conj(mixing_matrix[i][j]);
};
};
//mass matrix
std::complex<double> mass_matrix[3][3];
mass_matrix[0][0]={m1*m1/(2*E),0};
mass_matrix[1][1]={m2*m2/(2*E),0};
mass_matrix[2][2]={m3*m3/(2*E),0};
// obtain hamiltonian
std::complex<double> hamiltonian[3][3];
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
hamiltonian[i][j]=0;
for (int a=0;a<3;a++){
for (int b=0;b<3;b++){
hamiltonian[i][j]=hamiltonian[i][j]+mixing_matrix[i][a]*mass_matrix[a][b]*mixing_matrix_daguer[b][j];
};
};
};
};
//doing a step with RK4
std::complex<double> k1[3][3];
std::complex<double> k2[3][3];
std::complex<double> k3[3][3];
std::complex<double> k4[3][3];
std::complex<double> minus_i_over_hbar={0,-1/hbar};
//found k1
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
k1[i][j]=0;
for (int a=0;a<3;a++){
k1[i][j]=k1[i][j]+hamiltonian[i][a]*density_matrix[a][j]-density_matrix[i][a]*hamiltonian[a][j];
};
k1[i][j]=minus_i_over_hbar*k1[i][j];
};
};
//found k2
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
k2[i][j]=0;
for (int a=0;a<3;a++){
k2[i][j]=k2[i][j]+hamiltonian[i][a]*(density_matrix[a][j]+0.5*k1[a][j]*dt)-(density_matrix[i][a]+0.5*k1[i][a]*dt)*hamiltonian[a][j];
};
k2[i][j]=minus_i_over_hbar*k2[i][j];
};
};
//found k3
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
k3[i][j]=0;
for (int a=0;a<3;a++){
k3[i][j]=k3[i][j]+hamiltonian[i][a]*(density_matrix[a][j]+0.5*k2[a][j]*dt)-(density_matrix[i][a]+0.5*k2[i][a]*dt)*hamiltonian[a][j];
};
k3[i][j]=minus_i_over_hbar*k3[i][j];
};
};
//found k4
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
k4[i][j]=0;
for (int a=0;a<3;a++){
k4[i][j]=k4[i][j]+hamiltonian[i][a]*(density_matrix[a][j]+k3[a][j]*dt)-(density_matrix[i][a]+k3[i][a]*dt)*hamiltonian[a][j];
};
k4[i][j]=minus_i_over_hbar*k4[i][j];
};
};
//found next step density matrix
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
density_matrix[i][j]=density_matrix[i][j]+(1.0/6.0)*dt*(k1[i][j]+2.0*k2[i][j]+2.0*k3[i][j]+k4[i][j]);
};
};
//sum one to the count step variable
num_steps=num_steps+1;
//save new density matrix in output directory
std::ofstream outdata;
outdata.open("output/step_"+std::to_string(num_steps)+".dat"); // opens the file
if( !outdata ) { // file couldn't be opened
std::cerr << "Error: file could not be opened" << std::endl;
exit(1);
}
std::string outvalue;
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
double re=real(density_matrix[i][j]);
double im=imag(density_matrix[i][j]);
double time=num_steps*dt;
outvalue=std::to_string(re)+" "+std::to_string(im)+" "+std::to_string(time);
outdata << outvalue << std::endl;
};
};
outdata.close();
return 0,0;
};