Skip to content

Commit f13d1f8

Browse files
authored
Merge pull request #274 from TzuYaoHuang/fix/DotInPeriodicBC
Fix Gram-Schmidt parameter in PCG under periodic BC
2 parents 1ccaf76 + 8fa2b92 commit f13d1f8

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Poisson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function pcg!(p::Poisson{T};it=6) where T
129129
for i in 1:it
130130
perBC!(ϵ,p.perdir)
131131
@inside z[I] = mult(I,p.L,p.D,ϵ)
132-
alpha = rho/(zϵ)
132+
alpha = rho/perdot(z,ϵ,p.perdir)
133133
(abs(alpha)<1e-2 || abs(alpha)>1e2) && return # alpha should be O(1)
134134
@loop (x[I] += alpha*ϵ[I];
135135
r[I] -= alpha*z[I]) over I inside(x)

src/util.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ perBC!(a, perdir, N = size(a)) = for j ∈ perdir
257257
@loop a[I] = a[CIj(j,I,N[j]-1)] over I slice(N,1,j)
258258
@loop a[I] = a[CIj(j,I,2)] over I slice(N,N[j],j)
259259
end
260+
using LinearAlgebra:
261+
"""
262+
perdot(a,b,perdir)
263+
264+
Apply dot product to the inner cells of two _scalar_ fields, assuming zero values in ghost cell when using Neumann BC.
265+
"""
266+
perdot(a,b,::Tuple{}) = ab
267+
perdot(a,b,perdir,R=inside(a)) = @view(a[R])@view(b[R])
260268
"""
261269
interp(x::SVector, arr::AbstractArray)
262270

test/maintests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ backend != "KernelAbstractions" && throw(ArgumentError("SIMD backend not allowed
9494
@test GPUArrays.@allowscalar WaterLily.interp(SVector(3.5,3),b) 3.5
9595
@test GPUArrays.@allowscalar eltype(WaterLily.interp(SVector(3.5,3),b))==Float64
9696
@test_throws MethodError GPUArrays.@allowscalar WaterLily.interp(SVector(2.5f0,1.f0),b)
97+
98+
# test on perdot
99+
σ1 = rand(Ng...) |> f # scalar
100+
σ2 = rand(Ng...) |> f # another scalar
101+
# use ≈ instead of == as summation in different order might result in slight difference in floating point expressions
102+
@test GPUArrays.@allowscalar WaterLily.perdot(σ1,σ2,()) sum(σ1[I]*σ2[I] for ICartesianIndices(σ1))
103+
@test GPUArrays.@allowscalar WaterLily.perdot(σ1,σ2,(1,)) sum(σ1[I]*σ2[I] for Iinside(σ1))
104+
@test GPUArrays.@allowscalar WaterLily.perdot(σ1,σ2,(1,2)) sum(σ1[I]*σ2[I] for Iinside(σ1))
97105
end
98106
end
99107

0 commit comments

Comments
 (0)