summaryrefslogtreecommitdiff
path: root/xmds2/check_perturbative_approach/pp.m
blob: e9c3847d654a2803a73bc9a90a767768a8fdaa81 (plain)
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
% We check results of  calculations via full solver vs the  case of strong E1
% and E3. This two field create steady state coherences and populations which
% we treat as constant (along z and t) during propagation. We keep track only of coherences
% created by week fields E2 and E4.

% In perturbative approach:
% rho11, rho22, rho33, rho13, rho24, and rho44 dpepend  only on E1 and E2.
% They are also treated ad time independent.
% only r12 r14 r23 r34 treated fully since they are driven by weak fields E2 and E4
% which are strongly z dependent as well as E1 and E2 and time.

% Code below  checks result  of two  solvers. User  should double  check that
% scripts are run with the same  command line and internal dimensions are the
% same.

% Notice that all fields feel the propagation but E1 and E2 will look like time 
% independent in the perturbation approach.


%% Loading fields data files
% let's load exact solver solutions
fname='./Nlevels_no_dopler_with_z_4wm_mg0.dat';
fpDat = fopen(fname, 'r', 'ieee-le');
if (fpDat < 0)
  msg=strcat('Cannot open binary data file: ', fname);
  disp(msg)
  return
end
z_1Len = fread(fpDat, 1, 'uint32');
z_Exact = zeros(1, z_1Len);
z_Exact(:) = fread(fpDat, z_1Len, 'double');
t_1Len = fread(fpDat, 1, 'uint32');
t_Exact = zeros(1, t_1Len);
t_Exact(:) = fread(fpDat, t_1Len, 'double');
I1_out_1Len = fread(fpDat, 1, 'uint32');
I1_Exact = fread(fpDat, [t_1Len, z_1Len], 'double');
I2_out_1Len = fread(fpDat, 1, 'uint32');
I2_Exact = fread(fpDat, [t_1Len, z_1Len], 'double');
I3_out_1Len = fread(fpDat, 1, 'uint32');
I3_Exact = fread(fpDat, [t_1Len, z_1Len], 'double');
I4_out_1Len = fread(fpDat, 1, 'uint32');
I4_Exact = fread(fpDat, [t_1Len, z_1Len], 'double');
fclose(fpDat);
clear fpDat z_1Len t_1Len I1_out_1Len I2_out_1Len I3_out_1Len I4_out_1Len 


% let's load perturbative solver solutions
fname  = './Nlevels_no_dopler_with_z_4wm_with_perturbations_mg0.dat';
fpDat = fopen(fname, 'r', 'ieee-le');
if (fpDat < 0)
  msg=strcat('Cannot open binary data file: ', fname);
  disp(msg)
  return
end
z_1Len = fread(fpDat, 1, 'uint32');
z_Perturbative = zeros(1, z_1Len);
z_Perturbative(:) = fread(fpDat, z_1Len, 'double');
t_1Len = fread(fpDat, 1, 'uint32');
t_Perturbative = zeros(1, t_1Len);
t_Perturbative(:) = fread(fpDat, t_1Len, 'double');
I1_out_1Len = fread(fpDat, 1, 'uint32');
I1_Perturbative = fread(fpDat, [t_1Len, z_1Len], 'double');
I2_out_1Len = fread(fpDat, 1, 'uint32');
I2_Perturbative = fread(fpDat, [t_1Len, z_1Len], 'double');
I3_out_1Len = fread(fpDat, 1, 'uint32');
I3_Perturbative = fread(fpDat, [t_1Len, z_1Len], 'double');
I4_out_1Len = fread(fpDat, 1, 'uint32');
I4_Perturbative = fread(fpDat, [t_1Len, z_1Len], 'double');
fclose(fpDat);
clear fpDat z_1Len t_1Len I1_out_1Len I2_out_1Len I3_out_1Len I4_out_1Len 

%% extracting fields at the end of the cell
I1_Exact_out=I1_Exact(:,end);
I2_Exact_out=I2_Exact(:,end);
I3_Exact_out=I3_Exact(:,end);
I4_Exact_out=I4_Exact(:,end);

I1_Perturbative_out=I1_Perturbative(:,end);
I2_Perturbative_out=I2_Perturbative(:,end);
I3_Perturbative_out=I3_Perturbative(:,end);
I4_Perturbative_out=I4_Perturbative(:,end);

%% time to uS
t_Exact=t_Exact*1e6;
t_Perturbative=t_Perturbative*1e6;

%% comparison plot
figure(1);
subplot(2,2,1);
plot(t_Exact, I1_Exact_out, '-k' , t_Perturbative, I1_Perturbative_out, '-r' )
legend('exact', 'perturbative');
xlabel('time (uS)');
title('I_1 vs time');

subplot(2,2,2);
plot(t_Exact, I2_Exact_out, '-k' , t_Perturbative, I2_Perturbative_out, '-r' )
legend('exact', 'perturbative');
xlabel('time (uS)');
title('I_2 vs time');

subplot(2,2,3);
plot(t_Exact, I3_Exact_out, '-k' , t_Perturbative, I3_Perturbative_out, '-r' )
legend('exact', 'perturbative');
xlabel('time (uS)');
title('I_3 vs time');

subplot(2,2,4);
plot(t_Exact, I4_Exact_out, '-k' , t_Perturbative, I4_Perturbative_out, '-r' )
legend('exact', 'perturbative');
xlabel('time (uS)');
title('I_4 vs time');

print('-color','fields_after_the_cell.eps')