Skip to content

Commit 6b231de

Browse files
committed
Adding Bi-CGSTAB to the linear solver list.
1 parent f416d98 commit 6b231de

11 files changed

+310
-140
lines changed

NDA_Notebook.ipynb

+115-84
Large diffs are not rendered by default.

nda_note.jl

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ using LinearAlgebra
33
using BenchmarkTools
44
using PyPlot
55
push!(LOAD_PATH,"./src")
6+
push!(LOAD_PATH,".")
67
using NDA_QMC

ndaqmc.html

+65-37
Original file line numberDiff line numberDiff line change
@@ -74,100 +74,128 @@
7474

7575
<tr valign="top">
7676
<td align="right" class="bibtexnumber">
77-
[<a name="knoll08">KPS08</a>]
77+
[<a name="ctk:fajulia">Kel20c</a>]
7878
</td>
7979
<td class="bibtexitem">
80-
D.&nbsp;A. Knoll, H.&nbsp;Park, and K.&nbsp;Smith.
81-
A new look at nonlinear acceleration.
82-
<em>Nuclear Science and Engineering</em>, 99:332-334, 2008.
80+
C.&nbsp;T. Kelley.
81+
Solving Nonlinear Equations with Iterative Methods: Solvers and
82+
Examples in Julia, 2020.
83+
Unpublished book ms, under contract with SIAM.
8384

8485
</td>
8586
</tr>
8687

8788

8889
<tr valign="top">
8990
<td align="right" class="bibtexnumber">
90-
[<a name="knollnda">KPS11</a>]
91+
[<a name="ctk:notebooknl">Kel20a</a>]
92+
</td>
93+
<td class="bibtexitem">
94+
C.&nbsp;T. Kelley.
95+
Notebook for Solving Nonlinear Equations with Iterative Methods:
96+
Solvers and Examples in Julia.
97+
https://github.com/ctkelley/NotebookSIAMFANL, 2020.
98+
IJulia Notebook.
99+
[&nbsp;<a href="http://dx.doi.org/10.5281/zenodo.4284687">DOI</a>&nbsp;|
100+
<a href="https://github.com/ctkelley/NotebookSIAMFANL">http</a>&nbsp;]
101+
102+
</td>
103+
</tr>
104+
105+
106+
<tr valign="top">
107+
<td align="right" class="bibtexnumber">
108+
[<a name="ctk:siamfanl">Kel20b</a>]
109+
</td>
110+
<td class="bibtexitem">
111+
C.&nbsp;T. Kelley.
112+
SIAMFANLEquations.jl.
113+
https://github.com/ctkelley/SIAMFANLEquations.jl, 2020.
114+
Julia Package.
115+
[&nbsp;<a href="http://dx.doi.org/10.5281/zenodo.4284807">DOI</a>&nbsp;|
116+
<a href="https://github.com/ctkelley/SIAMFANLEquations.jl">http</a>&nbsp;]
117+
118+
</td>
119+
</tr>
120+
121+
122+
<tr valign="top">
123+
<td align="right" class="bibtexnumber">
124+
[<a name="knoll08">KPS08</a>]
91125
</td>
92126
<td class="bibtexitem">
93127
D.&nbsp;A. Knoll, H.&nbsp;Park, and K.&nbsp;Smith.
94-
Application of the Jacobian-free Newton-Krylov method to
95-
nonlinear acceleration of transport source iteration in slab geometry.
96-
<em>Nuclear Science and Engineering</em>, 167:122-132, 2011.
128+
A new look at nonlinear acceleration.
129+
<em>Nuclear Science and Engineering</em>, 99:332-334, 2008.
97130

98131
</td>
99132
</tr>
100133

101134

102135
<tr valign="top">
103136
<td align="right" class="bibtexnumber">
104-
[<a name="ctk:jeff1">WKKP13b</a>]
137+
[<a name="knollnda">KPS11</a>]
105138
</td>
106139
<td class="bibtexitem">
107-
Jeff Willert, C.&nbsp;T. Kelley, D.&nbsp;A. Knoll, and H.&nbsp;K. Park.
108-
Hybrid deterministic/Monte Carlo neutronics.
109-
35:S62-S83, 2013.
140+
D.&nbsp;A. Knoll, H.&nbsp;Park, and K.&nbsp;Smith.
141+
Application of the Jacobian-free Newton-Krylov method to
142+
nonlinear acceleration of transport source iteration in slab geometry.
143+
<em>Nuclear Science and Engineering</em>, 167:122-132, 2011.
110144

111145
</td>
112146
</tr>
113147

114148

115149
<tr valign="top">
116150
<td align="right" class="bibtexnumber">
117-
[<a name="ctk:jeff2">WCK15</a>]
151+
[<a name="gmres">SS86</a>]
118152
</td>
119153
<td class="bibtexitem">
120-
Jeffrey Willert, Xiaojun Chen, and C.&nbsp;T. Kelley.
121-
Newton's method for Monte Carlo-based residuals.
122-
<em>SIAM J. Numer. Anal.</em>, 53:1738-1757, 2015.
123-
[&nbsp;<a href="http://dx.doi.org/10.1137/130905691">DOI</a>&nbsp;]
154+
Y.&nbsp;Saad and M.H. Schultz.
155+
GMRES a generalized minimal residual algorithm for solving
156+
nonsymmetric linear systems.
157+
<em>SIAM J. Sci. Stat. Comp.</em>, 7:856-869, 1986.
124158

125159
</td>
126160
</tr>
127161

128162

129163
<tr valign="top">
130164
<td align="right" class="bibtexnumber">
131-
[<a name="ctk:fajulia">Kel20c</a>]
165+
[<a name="bicgstab">vdV92</a>]
132166
</td>
133167
<td class="bibtexitem">
134-
C.&nbsp;T. Kelley.
135-
Solving Nonlinear Equations with Iterative Methods: Solvers and
136-
Examples in Julia, 2020.
137-
Unpublished book ms, under contract with SIAM.
168+
H.&nbsp;A. van&nbsp;der Vorst.
169+
Bi-CGSTAB: A fast and smoothly converging variant to Bi-CG for
170+
the solution of nonsymmetric systems.
171+
13:631-644, 1992.
138172

139173
</td>
140174
</tr>
141175

142176

143177
<tr valign="top">
144178
<td align="right" class="bibtexnumber">
145-
[<a name="ctk:notebooknl">Kel20a</a>]
179+
[<a name="ctk:jeff1">WKKP13b</a>]
146180
</td>
147181
<td class="bibtexitem">
148-
C.&nbsp;T. Kelley.
149-
Notebook for Solving Nonlinear Equations with Iterative Methods:
150-
Solvers and Examples in Julia.
151-
https://github.com/ctkelley/NotebookSIAMFANL, 2020.
152-
IJulia Notebook.
153-
[&nbsp;<a href="http://dx.doi.org/10.5281/zenodo.4284687">DOI</a>&nbsp;|
154-
<a href="https://github.com/ctkelley/NotebookSIAMFANL">http</a>&nbsp;]
182+
Jeff Willert, C.&nbsp;T. Kelley, D.&nbsp;A. Knoll, and H.&nbsp;K. Park.
183+
Hybrid deterministic/Monte Carlo neutronics.
184+
<em>SIAM J. Sci. Comp.</em>, 35:S62-S83, 2013.
155185

156186
</td>
157187
</tr>
158188

159189

160190
<tr valign="top">
161191
<td align="right" class="bibtexnumber">
162-
[<a name="ctk:siamfanl">Kel20b</a>]
192+
[<a name="ctk:jeff2">WCK15</a>]
163193
</td>
164194
<td class="bibtexitem">
165-
C.&nbsp;T. Kelley.
166-
SIAMFANLEquations.jl.
167-
https://github.com/ctkelley/SIAMFANLEquations.jl, 2020.
168-
Julia Package.
169-
[&nbsp;<a href="http://dx.doi.org/10.5281/zenodo.4284807">DOI</a>&nbsp;|
170-
<a href="https://github.com/ctkelley/SIAMFANLEquations.jl">http</a>&nbsp;]
195+
Jeffrey Willert, Xiaojun Chen, and C.&nbsp;T. Kelley.
196+
Newton's method for Monte Carlo-based residuals.
197+
<em>SIAM J. Numer. Anal.</em>, 53:1738-1757, 2015.
198+
[&nbsp;<a href="http://dx.doi.org/10.1137/130905691">DOI</a>&nbsp;]
171199

172200
</td>
173201
</tr>

src/NDA_QMC.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ export readdata
3030
export sn_validate
3131
export qmc_sweep
3232
export qmc_init
33-
export qmc_gmres
33+
export qmc_krylov
3434
export qmc_si
3535
export tab_test
36+
export nda_fixed
37+
export nda_init
38+
export dhateval!
39+
export ctk_qmc_nda_test
3640

3741
include("validate.jl")
3842
include("sn_angles.jl")
@@ -47,6 +51,7 @@ include("nda.jl")
4751
include("nda_iteration.jl")
4852
include("siewert.jl")
4953
include("Tim_QMC/ctk_qmc_init.jl")
50-
include("Tim_QMC/gmres_test.jl")
54+
include("Tim_QMC/qmc_krylov.jl")
5155
include("Tim_QMC/ctk_qmc_sweep.jl")
56+
include("Tim_QMC/ctk_qmc_nda_test.jl")
5257
end

src/Tim_QMC/.ctk_qmc_nda_test.jl.swp

12 KB
Binary file not shown.

src/Tim_QMC/ctk_qmc_nda_test.jl

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
function ctk_qmc_nda_test(N,Nx)
2+
s=1.0
3+
na=20
4+
nx=Nx+1
5+
nda_data=nda_init(nx,na,s)
6+
sn_data=nda_data.sn_data
7+
angles=sn_data.angles;
8+
nx=sn_data.nx;
9+
dx=sn_data.dx;
10+
na=length(angles);
11+
psi=sn_data.psi;
12+
phi=zeros(nx,)
13+
phix=copy(phi)
14+
phiout=flux_map!(phix,sn_data)
15+
psix=copy(psi); phiy=copy(phi)
16+
psiout=transport_sweep!(psix, phiy, sn_data; phiedge=true)
17+
dhat=zeros(nx-1,)
18+
classout=fluxdata(psiout,sn_data)
19+
qmc_data=qmc_init(N, Nx, 10, 1.0)
20+
phiq=nda_data.AV*phi
21+
qout=qmc_sweep(phiq, qmc_data)
22+
phip=nda_data.AV*qout.phi_edge
23+
phix=nda_data.AV*phiout
24+
println("L infty absolute errors")
25+
println("Flux edge difference = ", norm(qout.phi_edge-phiout,Inf))
26+
println("Flux average difference = ", norm(phip-phix,Inf))
27+
println("Current edge difference = ",norm(classout.hocurrent-qout.J_edge,Inf))
28+
Jx=nda_data.AV*classout.hocurrent
29+
println("Current average difference = ",norm(Jx-qout.J_avg,Inf))
30+
println("dphi difference = ", norm(3.0*classout.dflux-qout.dphi,Inf))
31+
# relative l infty errors
32+
println("L infty relative errors")
33+
println("Flux edge difference = ", relerr(qout.phi_edge,phiout,Inf))
34+
println("Flux average difference = ", relerr(phip,phix,Inf))
35+
println("Current edge difference = ",relerr(classout.hocurrent,qout.J_edge,Inf))
36+
println("Current average difference = ",relerr(Jx,qout.J_avg,Inf))
37+
println("dphi difference = ", relerr(3.0*classout.dflux,qout.dphi,Inf))
38+
# relative l2 errors
39+
println("L2 relative errors")
40+
println("Flux edge difference = ", relerr(qout.phi_edge,phiout))
41+
println("Flux average difference = ", relerr(phip,phix))
42+
println("Current edge difference = ", relerr(classout.hocurrent,qout.J_edge))
43+
println("Current average difference = ",relerr(Jx,qout.J_avg))
44+
println("dphi difference = ", relerr(3.0*classout.dflux,qout.dphi))
45+
end
46+
47+
function relerr(xf,yf,p=2)
48+
df=xf-yf
49+
relerr=norm(df,p)/norm(yf,p)
50+
return relerr
51+
end
52+
53+
function fluxdata(psi,sn_data)
54+
weights=sn_data.weights;
55+
angles=sn_data.angles;
56+
nx=sn_data.nx;
57+
dx=sn_data.dx;
58+
hoflux=zeros(nx,);
59+
hocurrent=zeros(nx,);
60+
pa=weights.*angles;
61+
hoflux=(weights' * psi)';
62+
bcl=hoflux[1];
63+
bcr=hoflux[nx];
64+
hocurrent=(pa' * psi)';
65+
dflux=zeros(nx-1,)
66+
dhat=zeros(nx-1,)
67+
phiav=zeros(nx-1,)
68+
jav=zeros(nx-1,)
69+
dflux.=(hoflux[2:nx]-hoflux[1:nx-1])
70+
dflux./= (3.0*dx)
71+
phiav.=.5*(hoflux[2:nx] .+ hoflux[1:nx-1])
72+
jav.=.5*(hocurrent[2:nx] .+ hocurrent[1:nx-1])
73+
dhat.=(jav + dflux)./phiav
74+
return (dhat=dhat, bcl=bcl, bcr=bcr, dflux=dflux,
75+
hoflux=hoflux, hocurrent=hocurrent)
76+
end
77+
78+

src/Tim_QMC/ctk_qmc_sweep.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function qmc_sweep(phi_avg, qmc_data)
170170
dphi[i] = phi_edge[i+1] - phi_edge[i]
171171
end
172172

173-
dphi /= (dx)
173+
dphi ./= (dx)
174174
exit_left_bins[:,2] /= dmu
175175
exit_right_bins[:,2] /= dmu
176176

src/Tim_QMC/gmres_test.jl src/Tim_QMC/qmc_krylov.jl

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
"""
2-
qmc_gmres(N=10^4, Nx=100, na2=11; s=1.0)
2+
qmc_krylov(N=10^4, Nx=100, na2=11; s=1.0)
33
Solves the linear system you get from QMC with GMRES.
44
"""
5-
function qmc_gmres(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-10)
5+
function qmc_krylov(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-10, onlygmres=false)
66
mdata=mdata_init(N, Nx, na2, s)
77
phi0=zeros(Nx,);
88
b=mdata.frhs;
99
V=zeros(Nx,20)
1010
eta=tol
11-
gmout=kl_gmres(phi0,b,axb,V,eta; pdata=mdata);
12-
return gmout
11+
#
12+
# kl_gmres and kl_bicgstab solve the problem.
13+
#
14+
gout = kl_gmres(phi0, b, axb, V, tol; pdata = mdata)
15+
if onlygmres
16+
bout=(solb=[], reshist=[])
17+
else
18+
bout = kl_bicgstab(phi0, b, axb, V, tol; pdata = mdata)
19+
end
20+
#gmout=kl_gmres(phi0,b,axb,V,eta; pdata=mdata);
21+
sol=gout.sol
22+
solb=bout.sol
23+
reshistg=gout.reshist
24+
reshistb=bout.reshist
25+
#
26+
# Tabulate the exit distributions to check results.
27+
#
28+
return(sol=sol, solb=solb, reshistg=reshistg, reshistb=reshistb)
1329
end
1430

1531

@@ -18,7 +34,7 @@ tab_test(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-8)
1834
Makes a table to compare to Garcia-Siewert
1935
"""
2036
function tab_test(N=10^3, Nx=100, na2=11; s=1.0, tol=1.e-8)
21-
itout=qmc_gmres(N, Nx, na2; s=s, tol=tol)
37+
itout=qmc_krylov(N, Nx, na2; s=s, tol=tol)
2238
qmctab=sn_tabulate(s, Nx, itout.sol; maketab=false, phiedge=false)
2339
return [qmctab.left qmctab.right]
2440
end

src/compare.jl

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
compare(s = 1.0; qmc=false)
3+
4+
Makes the Krylov comparison tables/figures
5+
"""
16
function compare(s = 1.0; qmc=false)
27
na2 = 20
38
N=1000
@@ -22,10 +27,10 @@ function compare(s = 1.0; qmc=false)
2227
fout = sout.flux
2328
end
2429
#
25-
# and now GMRES and BiCGSTAB
30+
# and now GMRES and Bi-CGSTAB
2631
#
2732
if qmc
28-
gout=qmc_gmres(N, nx, na2; s=s)
33+
gout=qmc_krylov(N, nx, na2; s=s)
2934
else
3035
gout=krylov_iteration(sn_data,s)
3136
end
@@ -40,6 +45,7 @@ function compare(s = 1.0; qmc=false)
4045
glen=collect(1:length(ghist))
4146
bhist = gout.reshistb ./ gout.reshistb[1]
4247
blen=2*collect(1:length(bhist))
48+
blen[1]=1
4349
semilogy(glen,ghist, "k-", slen,snhist, "k--", blen, bhist, "k-.")
4450
legend(["gmres", "source iteration", "bicgstab"])
4551
xlabel("Transport Sweeps")
@@ -59,5 +65,5 @@ function compare(s = 1.0; qmc=false)
5965
(solverdelta < 1.e-6) || println(solverdelta)
6066
sn_tabulate(s,nx,fgm)
6167
println("Norm of result differences: GMRES = ", norm(fout - fgm, Inf),
62-
", BiCGSTAB = ",norm(fout - fgmb, Inf))
68+
", Bi-CGSTAB = ",norm(fout - fgmb, Inf))
6369
end

src/krylov_iteration.jl

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ function krylov_iteration(sn_data,s,tol=1.e-8; onlygmres=false)
4040
solb = bout.sol
4141
reshistg=gout.reshist
4242
reshistb=bout.reshist
43-
#
44-
# Tabulate the exit distributions to check results.
45-
#
4643
return(sol=sol, solb=solb, reshistg=reshistg, reshistb=reshistb)
4744
end
4845

0 commit comments

Comments
 (0)