Skip to content

SOR Smoother #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AlgebraicMultigrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export poisson

include("smoother.jl")
export GaussSeidel, SymmetricSweep, ForwardSweep, BackwardSweep,
JacobiProlongation
JacobiProlongation, SOR

include("multilevel.jl")
export RugeStubenAMG, SmoothedAggregationAMG
Expand Down
42 changes: 41 additions & 1 deletion src/smoother.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,44 @@
end
ret
end
scale_rows(S, v) = scale_rows!(deepcopy(S), S, v)
scale_rows(S, v) = scale_rows!(deepcopy(S), S, v)

struct SOR{S} <: Smoother
ω::Float64
sweep::S
iter::Int
end

SOR(ω; iter = 1) = SOR(ω, SymmetricSweep(), iter)
SOR(ω, f::ForwardSweep) = SOR(ω, f, 1)
SOR(ω, b::BackwardSweep) = SOR(ω, b, 1)
SOR(ω, s::SymmetricSweep) = SOR(ω, s, 1)

Check warning on line 219 in src/smoother.jl

View check run for this annotation

Codecov / codecov/patch

src/smoother.jl#L216-L219

Added lines #L216 - L219 were not covered by tests

function (sor::SOR{S})(A, x, b) where {S<:Sweep}
for i in 1:sor.iter
if S === ForwardSweep || S === SymmetricSweep
sor_step!(A, b, x, sor.ω, 1, 1, size(A, 1))

Check warning on line 224 in src/smoother.jl

View check run for this annotation

Codecov / codecov/patch

src/smoother.jl#L221-L224

Added lines #L221 - L224 were not covered by tests
end
if S === BackwardSweep || S === SymmetricSweep
sor_step!(A, b, x, sor.ω, size(A, 1), -1, 1)

Check warning on line 227 in src/smoother.jl

View check run for this annotation

Codecov / codecov/patch

src/smoother.jl#L226-L227

Added lines #L226 - L227 were not covered by tests
end
end

Check warning on line 229 in src/smoother.jl

View check run for this annotation

Codecov / codecov/patch

src/smoother.jl#L229

Added line #L229 was not covered by tests
end

function sor_step!(A, b, x, ω, start, step, stop)
n = size(A, 1)
z = zero(eltype(A))
@inbounds for col in 1:size(x, 2)
for i in start:step:stop
rsum = z
d = z
for j in nzrange(A, i)
row = A.rowval[j]
val = A.nzval[j]
d = ifelse(i == row, val, d)
rsum += ifelse(i == row, z, val * x[row, col])
end
x[i, col] = ifelse(d == 0, x[i, col], (1 - ω) * x[i, col] + (ω / d) * (b[i, col] - rsum))
end
end

Check warning on line 247 in src/smoother.jl

View check run for this annotation

Codecov / codecov/patch

src/smoother.jl#L232-L247

Added lines #L232 - L247 were not covered by tests
end
Loading