Skip to content

Commit 542b81a

Browse files
committed
Updates and bug fixes
1 parent b9db2d6 commit 542b81a

9 files changed

+71
-44
lines changed

ctk_nda_src/Tim_CMFD/cmfd.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ end
2222

2323

2424
"""
25-
cmfd_krylov(N=4096*4, Nx=512, Nc=64, na2=11; s=1.0, tol=1.e-10)
25+
cmfd_krylov(N=4096*4, Nx=512, Nc=64, na2=11; s=1.0, tol=1.e-10, tau=5.0)
2626
Solves the linear system you get from CMFD with GMRES.
2727
"""
28-
function cmfd_krylov(N=4096*4, Nx=512, Nc=64, na2=11; s=1.0, tol=1.e-10)
28+
function cmfd_krylov(N=4096*4, Nx=512, Nc=64, na2=11; s=1.0,
29+
tol=1.e-10, tau=5.0)
2930
phi_c = zeros(Nc)
3031
phi_c0 = zeros(Nc)
31-
cmfd_data=cmfd_init(N, Nx, Nc, na2, s)
32+
cmfd_data=cmfd_init(N, Nx, Nc, na2, s; tau=tau)
3233
linop_data=linop_init(Nc, cmfd_data)
3334
b=linop_data.frhs
3435
V=zeros(Nc,20)
@@ -91,14 +92,14 @@ return Mprod
9192
end
9293

9394

94-
function cmfd_init(N, Nx, Nc, na2, s)
95+
function cmfd_init(N, Nx, Nc, na2, s; tau=5.0)
9596
phi_f = zeros(Nx)
9697
J_c = zeros(Nc)
97-
sn_data=sn_init(Nx+1, 2*na2, s)
98-
qmc_data = qmc_init(N, Nx, na2, s);
99-
nda_data=nda_cmfd_init(Nx, Nc, 2*na2, s)
98+
sn_data=sn_init(Nx+1, 2*na2, s; tau=tau)
99+
qmc_data = qmc_init(N, Nx, na2, s; Lx = tau);
100+
nda_data=nda_cmfd_init(Nx, Nc, 2*na2, s; tau=tau)
100101
return(phi_f=phi_f, J_c = J_c, qmc_data=qmc_data, sn_data=nda_data.sn_data,
101-
nda_data=nda_data)
102+
nda_data=nda_data, tau=tau)
102103
end
103104

104105
function linop_init(Nc, cmfd_data)

ctk_nda_src/Tim_CMFD/compare_cmfd.jl

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
function compare_cmfd(N=4096*4, Nx=1024, Nc=64, na2=11; s=1.0, tol=1.e-10)
1+
function compare_cmfd(N=4096*4, Nx=1024, Nc=64, na2=11;
2+
tau=5.0, s=1.0, tol=1.e-10, plotme=true)
23
phi_c = zeros(Nc)
34
phi_c0 = zeros(Nc)
4-
cmfd_data=cmfd_init(N, Nx, Nc, na2, s)
5+
dx=tau/Nc
6+
x=dx*.5:dx:tau-dx*.5
7+
cmfd_data=cmfd_init(N, Nx, Nc, na2, s; tau=tau)
58
#
69
# QMC-GMRES is the baseline
710
#
8-
goutgm=qmc_krylov(N, Nx, na2; s=s)
11+
goutgm=qmc_krylov(N, Nx, na2; s=s, tau=tau)
12+
solgmf=goutgm.sol
13+
solgm=zeros(Nc)
14+
solgm.=ftoc(solgmf,solgm)
915
reshistg=goutgm.reshistg
1016
itgmax=length(reshistg)
1117
#
1218
# Newton-GMRES + NDA
1319
#
14-
nout=cmfd_nsoli(Nc; s=s)
20+
nout=cmfd_nsoli(N, Nx, Nc; s=s, tau=tau)
21+
soln=nout.solution
1522
fout=nout.stats.ifun+nout.stats.ijac+nout.stats.iarm
1623
#
1724
# count the warm-up qmc-si sweep
@@ -22,18 +29,32 @@ reshistn=nout.history
2229
#
2330
# NDA-Picard
2431
#
25-
pout=test_cmfd(Nc; s=s)
32+
pout=test_cmfd(N, Nx, Nc; s=s, tau=tau)
33+
solp=pout.solution
34+
println(norm(soln-solp,Inf)," ",norm(soln-solgm,Inf))
2635
reshistp=pout.history
2736
itpic=length(reshistp)
2837
#
2938
# Plot the results
3039
#
40+
Itau=Int(tau)
41+
if plotme
42+
figure(1)
43+
plot(x,soln,"k-",x,solgm,"k--",x,solp,"k-.")
44+
figure(2)
3145
semilogy(1:itgmax,reshistg/reshistg[1],"k-",
3246
1:itpic,reshistp/reshistp[1],"k.-",
3347
ftot,reshistn/reshistn[1],"k--")
34-
title("N=$N, Nx=$Nx, Nc=$Nc")
48+
stri=L"\infty"
49+
xxst="N=$N, Nx=$Nx, Nc=$Nc, s="*stri*", Lx = $Itau"
50+
if s==Inf
51+
#title("N=$N, Nx=$Nx, Nc=$Nc, s=, Lx = $Itau")
52+
title(xxst)
53+
else
54+
title("N=$N, Nx=$Nx, Nc=$Nc, s=1.0, Lx = $Itau")
55+
end
3556
xlabel("Transport sweeps")
3657
legend(["QMC-GMRES","NDA-Picard","NDA-Newton"])
37-
58+
end
3859
end
3960

ctk_nda_src/Tim_CMFD/nda_cmfd.jl

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ FS.=phi-cmfd_fixed(phi,cmfd_data)
77
return FS
88
end
99

10-
function cmfd_nsoli(Nc=64; s=1.0)
10+
function cmfd_nsoli(N=4096*4, Nx=1024, Nc=64; s=1.0, tau=5.0)
1111
FS=zeros(Nc,)
1212
FPS=zeros(Nc,20)
1313
phi0=zeros(Nc,)
14-
N=4096*4; Nx=1024; na2=11;
15-
cmfd_data=cmfd_init(N, Nx, Nc, na2, s);
14+
#N=4096*4; Nx=1024;
15+
na2=11;
16+
cmfd_data=cmfd_init(N, Nx, Nc, na2, s; tau=tau);
1617
#
1718
# Fix the initial iterate if you want decent results.
1819
#
@@ -42,7 +43,8 @@ function cmfd_fixed(phi_in, cmfd_data)
4243
# Solve high order problem
4344
#
4445
qmc_data=cmfd_data.qmc_data
45-
nc=length(phi_in); dx=5.0/nc
46+
tau=cmfd_data.tau
47+
nc=length(phi_in); dx=tau/nc
4648
#
4749
# we get the cell average flux, so convert to cell edges
4850
#
@@ -83,8 +85,8 @@ phiout=copy(phi)
8385
return phiout
8486
end
8587

86-
function nda_cmfd_init(nx, nc, na2, s)
87-
sn_data=sn_init(nc+1, na2, s)
88+
function nda_cmfd_init(nx, nc, na2, s; tau=5.0)
89+
sn_data=sn_init(nc+1, na2, s; tau=tau)
8890
dx=sn_data.dx
8991
c=sn_data.c
9092
nout=cmfdD2(nc+1,dx,c)

ctk_nda_src/Tim_CMFD/result_quality.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
function result_quality(Nc = 64)
1+
function result_quality(Nc = 64; tau=5.0)
22
na2=11
33
Nx=512
4-
dx=5.0/Float64(Nc)
4+
dx=tau/Float64(Nc)
55
x=.5*dx:dx:5.0-.5*dx
66
sol=zeros(Nc,3)
77
N=[1024, 2048, 4096]
88
#N *= 4
99
for in=1:3
10-
nout=cmfd_krylov(N[in], Nx, Nc, na2)
10+
nout=cmfd_krylov(N[in], Nx, Nc, na2; tau=tau)
1111
sol[:,in]=nout.sol
1212
end
1313
plot(x,sol[:,1],"k-",x,sol[:,2],"k--",x,sol[:,3],"k-.")

ctk_nda_src/Tim_CMFD/test_cmfd.jl

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
function test_cmfd(Nc=64; s=1.0)
2-
N=4096*4; Nx=1024; na2=11;
1+
function test_cmfd(N=4096*4, Nx=1024, Nc=64; s=1.0, tau=5.0)
2+
#N=4096*4; Nx=1024;
3+
na2=11;
34
#N=4096*2; Nx=1024; na2=11;
4-
tau=5.0; dx=tau/Nc; x=.5*dx:dx:tau-.5*dx
5-
cmfd_data=cmfd_init(N, Nx, Nc, na2, s);
5+
dx=tau/Nc; x=.5*dx:dx:tau-.5*dx
6+
cmfd_data=cmfd_init(N, Nx, Nc, na2, s; tau=tau);
67
phi0=zeros(Nc);
78
phic=copy(phi0)
89
reshist=Float64[]
910
plotit=false
1011
itc=0
1112
resid=1.0
12-
while (itc < 100) && (resid > 1.e-11)
13+
while (itc < 200) && (resid > 1.e-11)
1314
itc+=1
1415
phip=cmfd_fixed(phic, cmfd_data)
1516
resid=norm(phip-phic)

ctk_nda_src/Tim_QMC/ctk_qmc_init.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#using Sobol
22

3-
function qmc_init(N, Nx, na2, s)
3+
function qmc_init(N, Nx, na2, s; Lx=5.0)
44

5-
Lx = 5.0
5+
# Lx = 5.0
66
dx = Lx/Nx
77
#define tally mesh
88
low_edges = range(0, stop=Lx-dx, length=Nx)

ctk_nda_src/Tim_QMC/qmc_krylov.jl

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
2-
qmc_krylov(N=10^4, Nx=100, na2=11; s=1.0)
2+
qmc_krylov(N=10^4, Nx=100, na2=11; s=1.0, tau=5.0)
33
Solves the linear system you get from QMC with GMRES.
44
"""
5-
function qmc_krylov(N=1024, Nx=128, na2=11; s=1.0, tol=1.e-10, onlygmres=true)
6-
mdata=mdata_init(N, Nx, na2, s)
5+
function qmc_krylov(N=1024, Nx=128, na2=11;
6+
s=1.0, tol=1.e-10, onlygmres=true, tau=5.0)
7+
mdata=mdata_init(N, Nx, na2, s; tau=tau)
78
phi0=zeros(Nx,);
89
b=mdata.frhs;
9-
V=zeros(Nx,20)
10+
V=zeros(Nx,80)
1011
eta=tol
1112
#
1213
# kl_gmres and kl_bicgstab solve the problem.
@@ -38,11 +39,12 @@ end
3839

3940

4041
"""
41-
qmc_si(N=10^4, Nx=100, na2=11; s=1.0, tol=1.e-8, maxit=100)
42+
qmc_si(N=10^4, Nx=100, na2=11; tau=5.0, s=1.0, tol=1.e-8, maxit=100)
4243
Source iteration using QMC. Nothing magic here.
4344
"""
44-
function qmc_si(N=10^4, Nx=100, na2=11; s=1.0, tol=1.e-8, maxit=100)
45-
qmc_data=qmc_init(N, Nx, na2, s)
45+
function qmc_si(N=10^4, Nx=100, na2=11;
46+
s=1.0, tol=1.e-8, maxit=100)
47+
qmc_data=qmc_init(N, Nx, na2, s; tau=tau)
4648
phic=zeros(Nx,);
4749
delflux=1.0
4850
reshist=[]
@@ -86,9 +88,9 @@ Collects the precomputed data for QMC and does a sweep with
8688
zero boundary data to get the right hand side for the linear
8789
equation forumlation.
8890
"""
89-
function mdata_init(N, Nx, na2, s)
91+
function mdata_init(N, Nx, na2, s; tau=5.0)
9092
# Precomputed data
91-
qmc_data = qmc_init(N, Nx, na2, s);
93+
qmc_data = qmc_init(N, Nx, na2, s; Lx=tau);
9294
# Sweep with zero RHS
9395
phizero=zeros(Nx,);
9496
nullout=qmc_sweep(phizero,qmc_data);

ctk_nda_src/qmc_init.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Sobol
22

3-
function qmc_init(N, Nx, na2, s)
3+
function qmc_init(N, Nx, na2, s; Lx = 5.0)
44

5-
Lx = 5.0
5+
# Lx = 5.0
66
dx = Lx/Nx
77
#define tally mesh
88
low_edges = range(0, stop=Lx-dx, length=Nx)

ctk_nda_src/sn_init.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ s = parameter in Garcia/Siewert
1414
1515
angles, weights = nodes and weights for the angular quadrature
1616
"""
17-
function sn_init(nx, na2, s; siewert=false, phiedge=true)
17+
function sn_init(nx, na2, s; siewert=false, phiedge=true, tau=5.0)
1818
if siewert
1919
angles = [-.05; collect(-.1:-.1:-1.0); 0.05; collect(0.1:0.1:1.0)]
2020
weights = angles
2121
else
2222
(angles, weights) = sn_angles(na2)
2323
end
24-
tau = 5.0
24+
# tau = 5.0
2525
dx = tau / (nx - 1)
2626
na = floor(Int, na2 / 2)
2727
x = collect(0:dx:tau)

0 commit comments

Comments
 (0)