Skip to content

Commit 43bea06

Browse files
committed
[documentation] Update the example for the Poisson equation with halo regions
1 parent 5f992b7 commit 43bea06

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

docs/src/custom_workspaces.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ function LinearAlgebra.mul!(y::HaloVector{Float64}, A::LaplacianOperator, u::Hal
136136
137137
# Update the output vector with the Laplacian result
138138
y.data[i,j] = dx2 + dy2
139+
140+
# Add a tiny value ε to the diagonal to ensure the operator is
141+
# symmetric positive definite (SPD) and to avoid numerical issues
142+
if i == j
143+
y.data[i,j] += 1e-8
144+
end
139145
end
140146
end
141147
@@ -330,7 +336,7 @@ kc = KrylovConstructor(b)
330336
workspace = CgWorkspace(kc)
331337
332338
# Solve the system with CG
333-
Krylov.cg!(workspace, A, b, atol=1e-12, rtol=0.0, verbose=1)
339+
Krylov.cg!(workspace, A, b, atol=1e-10, rtol=0.0, verbose=1)
334340
u_sol = solution(workspace)
335341
stats = statistics(workspace)
336342
```

src/cg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
160160
MisI || mulorldiv!(z, M, r, ldiv)
161161
kcopy!(n, p, z) # p ← z
162162
γ = kdotr(n, r, z)
163-
γ 0 || error("The preconditioner `M` is not symmetric positive definite.")
163+
γ 0 || error("The linear operator `A` or the preconditioner `M` is not symmetric positive definite.")
164164
rNorm = sqrt(γ)
165165
history && push!(rNorms, rNorm)
166166
if γ == 0
@@ -240,7 +240,7 @@ kwargs_cg = (:M, :ldiv, :radius, :linesearch, :atol, :rtol, :itmax, :timemax, :v
240240
kaxpy!(n, -α, Ap, r)
241241
MisI || mulorldiv!(z, M, r, ldiv)
242242
γ_next = kdotr(n, r, z)
243-
γ_next 0 || error("The preconditioner `M` is not symmetric positive definite.")
243+
γ_next 0 || error("The linear operator `A` or the preconditioner `M` is not symmetric positive definite.")
244244
rNorm = sqrt(γ_next)
245245
history && push!(rNorms, rNorm)
246246

0 commit comments

Comments
 (0)