1- # 1D bratu equation
1+ # # 1D bratu equation
22
33using NewtonKrylov, Krylov
44using KrylovPreconditioners
55using SparseArrays, LinearAlgebra
6+ using CairoMakie
67
78function bratu! (res, y, Δx, λ)
89 N = length (y)
@@ -23,7 +24,7 @@ function bratu(y, dx, λ)
2324end
2425
2526function true_sol_bratu (x)
26- # for λ = 3.51382, 2nd sol θ = 4.8057
27+ # # for λ = 3.51382, 2nd sol θ = 4.8057
2728 θ = 4.79173
2829 return - 2 * log (cosh (θ * (x - 0.5 ) / 2 ) / (cosh (θ / 4 )))
2930end
@@ -52,34 +53,32 @@ uₖ_2 = newton_krylov(
5253ϵ1 = abs2 .(uₖ_1 .- reference)
5354ϵ2 = abs2 .(uₖ_1 .- reference)
5455
55- # #
56- # Solving with a fixed forcing
56+ # ## Solving with a fixed forcing
5757newton_krylov! (
5858 (res, u) -> bratu! (res, u, dx, λ),
5959 copy (u₀), similar (u₀);
6060 Solver = CgSolver,
6161 forcing = NewtonKrylov. Fixed ()
6262)
6363
64- # #
65- # Solving with no forcing
64+ # ## Solving with no forcing
6665newton_krylov! (
6766 (res, u) -> bratu! (res, u, dx, λ),
6867 copy (u₀), similar (u₀);
6968 Solver = CgSolver,
7069 forcing = nothing
7170)
7271
73- # #
74- # Solve using GMRES -- very slow
72+ # ## Solve using GMRES -- very slow
73+ # ```julia
7574# @time newton_krylov!(
7675# (res, u) -> bratu!(res, u, dx, λ),
7776# copy(u₀), similar(u₀);
7877# Solver = GmresSolver,
7978# )
79+ # ```
8080
81- # #
82- # Solve using GMRES + ILU Preconditoner
81+ # ## Solve using GMRES + ILU Preconditoner
8382@time newton_krylov! (
8483 (res, u) -> bratu! (res, u, dx, λ),
8584 copy (u₀), similar (u₀);
@@ -88,8 +87,7 @@ newton_krylov!(
8887 ldiv = true ,
8988)
9089
91- # #
92- # Solve using FGMRES + ILU Preconditoner
90+ # ## Solve using FGMRES + ILU Preconditoner
9391@time newton_krylov! (
9492 (res, u) -> bratu! (res, u, dx, λ),
9593 copy (u₀), similar (u₀);
@@ -98,8 +96,7 @@ newton_krylov!(
9896 ldiv = true ,
9997)
10098
101- # #
102- # Solve using FGMRES + GMRES Preconditoner
99+ # ## Solve using FGMRES + GMRES Preconditoner
103100struct GmresPreconditioner{JOp}
104101 J:: JOp
105102 itmax:: Int
@@ -117,18 +114,22 @@ end
117114 N = (J) -> GmresPreconditioner (J, 30 ),
118115)
119116
120- # # Explodes..
117+ # ## Explodes..
118+ # ```julia
121119# newton_krylov!(
122120# (res, u) -> bratu!(res, u, dx, λ),
123121# copy(u₀), similar(u₀);
124122# verbose = 1,
125123# Solver = CglsSolver, # CgneSolver
126124# )
127-
125+ # ```
126+ #
127+ # ```julia
128128# newton_krylov!(
129129# (res, u) -> bratu!(res, u, dx, λ),
130130# copy(u₀), similar(u₀);
131131# verbose = 1,
132132# Solver = BicgstabSolver,
133133# η_max = nothing
134134# )
135+ # ```
0 commit comments