Skip to content

Commit f416d98

Browse files
committed
Adding BiCGSTAB to the linear solver mix; getting ready for QMC-NDA
1 parent acb2397 commit f416d98

10 files changed

Lines changed: 671 additions & 180 deletions

File tree

NDA_Notebook.ipynb

Lines changed: 611 additions & 165 deletions
Large diffs are not rendered by default.

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[deps]
22
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
3-
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
43
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
54
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
65
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

src/NDA_QMC.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using Sobol
1414
export testgauss
1515
export sn_angles
1616
export source_iteration
17-
export gmres_iteration
17+
export krylov_iteration
1818
export sn_init
1919
export sn_tabulate
2020
export compare
@@ -37,7 +37,7 @@ export tab_test
3737
include("validate.jl")
3838
include("sn_angles.jl")
3939
include("source_iteration.jl")
40-
include("gmres_iteration.jl")
40+
include("krylov_iteration.jl")
4141
include("transport_sweep.jl")
4242
include("sn_init.jl")
4343
include("sn_tabulate.jl")

src/Tim_QMC/ctk_qmc_sweep.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ function qmc_sweep(phi_avg, qmc_data)
176176

177177
return (phi_avg = phi_avg,
178178
phi_edge = phi_edge,
179+
dphi = dphi,
179180
J_avg = J_avg,
180181
J_edge = J_edge,
181182
exit_right_bins = exit_right_bins,

src/Tim_QMC/gmres_test.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
qmc_gmres(N=10^4, Nx=100, na2=11; s=1.0)
3+
Solves the linear system you get from QMC with GMRES.
34
"""
45
function qmc_gmres(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-10)
56
mdata=mdata_init(N, Nx, na2, s)
@@ -12,13 +13,21 @@ return gmout
1213
end
1314

1415

16+
"""
17+
tab_test(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-8)
18+
Makes a table to compare to Garcia-Siewert
19+
"""
1520
function tab_test(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-8)
1621
itout=qmc_gmres(N, Nx, na2; s=s, tol=tol)
1722
qmctab=sn_tabulate(s, Nx, itout.sol; maketab=false, phiedge=false)
1823
return [qmctab.left qmctab.right]
1924
end
2025

2126

27+
"""
28+
qmc_si(N=10^4, Nx=100, na2=11; s=1.0, tol=1.e-8, maxit=100)
29+
Source iteration using QMC. Nothing magic here.
30+
"""
2231
function qmc_si(N=10^4, Nx=100, na2=11; s=1.0, tol=1.e-8, maxit=100)
2332
qmc_data=qmc_init(N, Nx, na2, s)
2433
phic=zeros(Nx,);
@@ -37,21 +46,40 @@ return ( sol=phic, history=reshist)
3746
end
3847

3948

49+
"""
50+
axb(phi,mdata)
51+
Matrix-vector product to feed to linear solvers.
52+
"""
4053
function axb(phi,mdata)
4154
qmc_data=mdata.qmc_data;
4255
frhs=mdata.frhs
4356
matvec=Qlin(phi,qmc_data,frhs)
4457
end
4558

59+
"""
60+
Qlin(phi,qmc_data,frhs)
61+
Does a QMC transport sweep with flux phi, subtracts off the zero bc solution
62+
to obtain the linear integral operator. The subtract that from the identity.
63+
"""
4664
function Qlin(phi,qmc_data,frhs)
4765
nullout=qmc_sweep(phi,qmc_data)
4866
Mprod=phi-(nullout.phi_avg-frhs)
4967
end
5068

69+
70+
"""
71+
mdata_init(N, Nx, na2, s)
72+
Collects the precomputed data for QMC and does a sweep with
73+
zero boundary data to get the right hand side for the linear
74+
equation forumlation.
75+
"""
5176
function mdata_init(N, Nx, na2, s)
77+
# Precomputed data
5278
qmc_data = qmc_init(N, Nx, na2, s);
79+
# Sweep with zero RHS
5380
phizero=zeros(Nx,);
5481
nullout=qmc_sweep(phizero,qmc_data);
5582
frhs=nullout.phi_avg;
83+
#
5684
mdata=(frhs=frhs, qmc_data =qmc_data)
5785
end

src/compare.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,26 @@ function compare(s = 1.0; qmc=false)
2222
fout = sout.flux
2323
end
2424
#
25-
# and now GMRES
25+
# and now GMRES and BiCGSTAB
2626
#
2727
if qmc
2828
gout=qmc_gmres(N, nx, na2; s=s)
2929
else
30-
gout=gmres_iteration(sn_data,s)
30+
gout=krylov_iteration(sn_data,s)
3131
end
3232
fgm = gout.sol
33+
fgmb = gout.solb
3334
#
3435
# Make a nice plot
3536
#
3637
snhist = sout.history ./ sout.history[1]
37-
ghist = gout.reshist ./ gout.reshist[1]
38-
semilogy(ghist, "k-", snhist, "k--")
39-
legend(["gmres", "source iteration"])
38+
slen=collect(1:length(snhist))
39+
ghist = gout.reshistg ./ gout.reshistg[1]
40+
glen=collect(1:length(ghist))
41+
bhist = gout.reshistb ./ gout.reshistb[1]
42+
blen=2*collect(1:length(bhist))
43+
semilogy(glen,ghist, "k-", slen,snhist, "k--", blen, bhist, "k-.")
44+
legend(["gmres", "source iteration", "bicgstab"])
4045
xlabel("Transport Sweeps")
4146
ylabel("Relative Residual")
4247
s == Inf ? strs = L"\infty" : strs = string(s)
@@ -53,5 +58,6 @@ function compare(s = 1.0; qmc=false)
5358
# (solverdelta < 1.e-6) || error("results not the same")
5459
(solverdelta < 1.e-6) || println(solverdelta)
5560
sn_tabulate(s,nx,fgm)
56-
println("Norm of result difference = ", norm(fout - fgm, Inf))
61+
println("Norm of result differences: GMRES = ", norm(fout - fgm, Inf),
62+
", BiCGSTAB = ",norm(fout - fgmb, Inf))
5763
end
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
function gmres_iteration(sn_data,s,tol=1.e-8)
1+
"""
2+
krlov_iteration(sn_data,s,tol=1.e-8; onlygmres=false)
3+
Solves the transport equation with GMRES and BiCGSTAB
4+
"""
5+
function krylov_iteration(sn_data,s,tol=1.e-8; onlygmres=false)
26
#
3-
# Set up the linear system for GMRES
7+
# Set up the linear system for the Krylov solvers
48
#
59
nx=sn_data.nx
610
#
@@ -23,16 +27,23 @@ function gmres_iteration(sn_data,s,tol=1.e-8)
2327
f0 = zeros(size(rhs))
2428
V = zeros(nx, 20)
2529
#
26-
# kl_gmres solves the problem.
30+
# kl_gmres and kl_bicgstab solve the problem.
2731
#
2832
gout = kl_gmres(f0, rhs, sn_matvec, V, tol; pdata = sn_data)
33+
if onlygmres
34+
bout=(solb=[], reshist=[])
35+
else
36+
bout = kl_bicgstab(f0, rhs, sn_matvec, V, tol; pdata = sn_data)
37+
end
2938
#
3039
sol = gout.sol
31-
reshist=gout.reshist
40+
solb = bout.sol
41+
reshistg=gout.reshist
42+
reshistb=bout.reshist
3243
#
3344
# Tabulate the exit distributions to check results.
3445
#
35-
return(sol=sol , reshist=reshist)
46+
return(sol=sol, solb=solb, reshistg=reshistg, reshistb=reshistb)
3647
end
3748

3849
"""

src/siewert.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function siewert(s=1.0; filedump=false, na2=80, nx=16001, phiedge=true)
1313
#
1414
# Solve the problem
1515
#
16-
gout=gmres_iteration(sn_data,s)
16+
gout=krylov_iteration(sn_data,s; onlygmres=true)
1717
if phiedge
1818
fgm = gout.sol
1919
else

0 commit comments

Comments
 (0)