-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoC_LS_module.m
177 lines (162 loc) · 5.38 KB
/
MoC_LS_module.m
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
175
176
177
% 1D MoC Module
% Input:
% Geometry Tau
% Spatial discretization J (or mesh size)
% Angular discretization N
% Material: all cross sections and stuff
% Boundary condition
% Distributed source, can be MMS
% Output:
% Cell-averaged scalar flux
function [phi0_j,phi0_hat_j]=MoC_LS_module(J,N,Tau,mat,...
psi_b1_n,psi_b2_n,Q_MMS_j_n,Q_MMS_hat_j_n,...
error_ang_j,error_hat_ang_j,...
phi0_old_outer_j,phi0_hat_old_outer_j)
% Input parameter
if ~exist('Tau','var')
Tau=10;
end
if ~exist('J','var')
J=5*2;%*2%*2*2*2*2*2*2*2*2
end
if ~exist('N','var')
N=16;
end
if ~exist('mat','var')
% Material
field1='Sig_t_j'; value1=ones(J,1);
field2='Sig_ss_j'; value2=ones(J,1)*0.5;
field3='Sig_gamma_j'; value3=ones(J,1)*0.4;
field4='Sig_f_j'; value4=ones(J,1)*0.1;
field5='nuSig_f_j'; value5=ones(J,1)*0.2;
field6='thermal_cond_k_j'; value6=ones(J,1);
field7='kappaSig_f_j'; value7=ones(J,1)*0.1; % kappa=1.0;
mat = struct(field1,value1,field2,value2,field3,value3,...
field4,value4,field5,value5,field6,value6,field7,value7);
end
if ~exist('psi_b1_n','var')
psi_b1_n=ones(N,1)*1.0;
end
if ~exist('psi_b2_n','var')
psi_b2_n=ones(N,1)*1.0;
end
if ~exist('Q_MMS_j_n','var')
Q_MMS_j_n=ones(J,N)*0.3;
end
if ~exist('Q_MMS_hat_j_n','var')
Q_MMS_hat_j_n=ones(J,N)*0.1;
end
if ~exist('phi0_old_outer_j','var')
phi0_old_outer_j=ones(J,1);
end
if ~exist('phi0_hat_old_outer_j','var')
phi0_hat_old_outer_j=ones(J,1);
end
% Material
Sig_ss_j=mat.Sig_ss_j;
nuSig_f_j=mat.nuSig_f_j;
Sig_t_j=mat.Sig_t_j;
% Sig_ss_j=ones(J,1)*0.5;
% nuSig_f_j=ones(J,1)*0.2;
% Sig_t_j=ones(J,1);
Sig_t_inv_j=1./Sig_t_j;
% Default variables, can be customized.
maxIterate=2000;
epsilon_phi0=1e-13;
[mu_n,weight_n]=lgwt(N,-1,1); mu_n=flipud(mu_n);
h_j=ones(J,1)*Tau/J;
% N rays to trace, each angle has only 1 ray, no ray-spacing
% n for each angle, and j for FSR region index
segLen_j_n=zeros(J,1);
for n=1:N
for j=1:J
segLen_j_n(j,n)=h_j(j)/abs(mu_n(n));
end
end
% From copy and paste
phi0_old_j=phi0_old_outer_j;%ones(1,J)*1.0; % so the 1st dimension is consistently the angle.
phi0_old_hat_j=phi0_hat_old_outer_j;%ones(1,J)*1.0; % so the 1st dimension is consistently the angle.
Q_x_j_n=zeros(J,N); % these are actually angular quantities, already have 0.5's in them.
q_j_n=zeros(J,N);
q_sm_j_n=zeros(J,N);
% new quantities for linear source
Q_x_hat_j_n=zeros(J,N);
q_hat_j_n=zeros(J,N);
q_sm_hat_j_n=zeros(J,N);
%% Inner iteration to converge scattering source
for iIterate=1:maxIterate
for j=1:J
for n=1:N
Q_x_j_n(j,n)=0.5*(Sig_ss_j(j))*(phi0_old_j(j))+Q_MMS_j_n(j,n);
q_j_n(j,n)=Q_x_j_n(j,n);
q_sm_j_n(j,n)=q_j_n(j,n);
Q_x_hat_j_n(j,n)=0.5*(Sig_ss_j(j))*(phi0_old_hat_j(j))+Q_MMS_hat_j_n(j,n);
q_hat_j_n(j,n)=Q_x_hat_j_n(j,n)/(h_j(j)*h_j(j)/12);
q_sm_hat_j_n(j,n)=q_hat_j_n(j,n)*(mu_n(n)); % NO ABS IS NEEDED!
end
end
% phi_j_old_hat
% q_n_j
% q_n_j_hat
phi0_new_j=zeros(J,1);
phi0_hat_new_j=zeros(J,1);
% ray tracing
for n=N/2+1:N
psi_in=psi_b1_n(n);
for j=1:J
tau_temp=Sig_t_j(j)*segLen_j_n(j,n);
F1=1-exp(-tau_temp);
F2=2*(tau_temp-F1)-tau_temp*F1;
psi_out=psi_in+(q_sm_j_n(j,n)*Sig_t_inv_j(j)-psi_in)*F1...
+(q_sm_hat_j_n(j,n)*0.5*Sig_t_inv_j(j)*Sig_t_inv_j(j))*F2;
psi_avg=q_sm_j_n(j,n)*Sig_t_inv_j(j)+(psi_in-psi_out)/tau_temp;
phi0_new_j(j)=phi0_new_j(j)+weight_n(n)*psi_avg;
G1=1+tau_temp*0.5-(1+1/tau_temp)*F1;
G2=2/3*tau_temp-(1+2/tau_temp)*G1;
psi_hat=psi_in*0.5*segLen_j_n(j,n) ...
+ (q_sm_j_n(j,n)*Sig_t_inv_j(j)-psi_in)*G1*Sig_t_inv_j(j) ...
+ (q_sm_hat_j_n(j,n)*0.5*Sig_t_inv_j(j)*Sig_t_inv_j(j))*segLen_j_n(j,n)*G2; %changed here
phi0_hat_new_j(j)=phi0_hat_new_j(j)+...
weight_n(n)*(-h_j(j)*0.5*psi_avg+abs(mu_n(n))*psi_hat);
psi_in=psi_out;
end
end
for n=1:N/2
psi_in=psi_b2_n(n);
for j=J:-1:1
tau_temp=Sig_t_j(j)*segLen_j_n(j,n);
F1=1-exp(-tau_temp);
F2=2*(tau_temp-F1)-tau_temp*F1;
psi_out=psi_in+(q_sm_j_n(j,n)*Sig_t_inv_j(j)-psi_in)*F1 ...
+(q_sm_hat_j_n(j,n)*0.5*Sig_t_inv_j(j)*Sig_t_inv_j(j))*F2;
psi_avg=q_sm_j_n(j,n)*Sig_t_inv_j(j)+(psi_in-psi_out)/tau_temp;
phi0_new_j(j)=phi0_new_j(j)+weight_n(n)*psi_avg;
G1=1+tau_temp*0.5-(1+1/tau_temp)*F1;
G2=2/3*tau_temp-(1+2/tau_temp)*G1;
psi_hat=psi_in*0.5*segLen_j_n(j,n) ...
+ (q_sm_j_n(j,n)*Sig_t_inv_j(j)-psi_in)*G1*Sig_t_inv_j(j) ...
+ (q_sm_hat_j_n(j,n)*0.5*Sig_t_inv_j(j)*Sig_t_inv_j(j))*segLen_j_n(j,n)*G2; %changed here
phi0_hat_new_j(j)=phi0_hat_new_j(j)+...
weight_n(n)*(+h_j(j)*0.5*psi_avg-abs(mu_n(n))*psi_hat);
psi_in=psi_out;
end
end
phi0_new_j=phi0_new_j-error_ang_j;
phi0_hat_new_j=phi0_hat_new_j-error_hat_ang_j;
% test for convergence
error=norm(phi0_new_j-phi0_old_j);
if error<epsilon_phi0
break;
end
phi0_old_j=phi0_new_j;
phi0_old_hat_j=phi0_hat_new_j;
end
% error
% phi_j_old=phi_j_new;
% display(iIterate);
% figure(19);
% plot(phi0_new_j,'*-')
% openvar('phi_j_new')
phi0_j=phi0_new_j;
phi0_hat_j=phi0_hat_new_j;
end