Skip to content

Commit 9ea6190

Browse files
add B to docstring
1 parent 04005d5 commit 9ea6190

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/aggregation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function smoothed_aggregation(A::TA, _B = nothing,
1414
coarse_solver = Pinv, kwargs...) where {T,V,bs,TA<:SparseMatrixCSC{T,V}}
1515

1616
n = size(A, 1)
17-
B = isnothing(_B) ? ones(T,n,1) : copy(_B)
17+
B = isnothing(_B) ? ones(T,n) : copy(_B)
1818
@assert size(A, 1) == size(B, 1)
1919

2020
#=max_levels, max_coarse, strength =

src/multilevel.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,38 @@ abstract type AMGAlg end
289289
struct RugeStubenAMG <: AMGAlg end
290290

291291
"""
292+
SmoothedAggregationAMG(B=nothing)
293+
294+
Smoothed Aggregation AMG (Algebraic Multigrid) algorithm configuration.
295+
296+
# Arguments
297+
- `B::Union{AbstractArray, Nothing}`: The **near null space** in SA-AMG represents the low energy that cannot be attenuated by relaxtion, and thus needs to be perserved across the coarse grid.
298+
299+
- `B` can be:
300+
- a `Vector` (e.g., for scalar PDEs),
301+
- a `Matrix` (e.g., for vector PDEs or systems with multiple equations),
302+
- or `nothing`.
303+
304+
# Notes
305+
If `B` is set to `nothing`, it will be internally defaulted to `B = ones(T, n)`, where `T = eltype(A)` and `n = size(A, 1)`.
306+
307+
# Examples
308+
309+
**Poisson equation (scalar PDE):**
310+
```julia
311+
n = size(A, 1)
312+
B = ones(Float64, n)
313+
amg = SmoothedAggregationAMG(B)
314+
```
315+
316+
**Linear elasticity equation in 2d (vector PDE):**
317+
```julia
318+
n = size(A, 1) # Ndof = 2 * number of nodes
319+
B = zeros(Float64, n, 3)
320+
B[1:2:end, :] = [1.0, 0.0, -y]
321+
B[2:2:end, :] = [0.0, 1.0, x]
322+
amg = SmoothedAggregationAMG(B)
323+
```
292324
"""
293325
struct SmoothedAggregationAMG <: AMGAlg
294326
B::Union{<:AbstractArray,Nothing} # `B` can be `Vector`, `Matrix`, or `nothing`

test/nns_test.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
## Test `B` as an argument for `SmoothedAggregationAMG`
2+
@testset "Different `B` as an argument for `SmoothedAggregationAMG` " begin
3+
A = poisson(100);
4+
b = rand(100);
5+
n = size(A,1)
6+
T = eltype(A)
7+
8+
#1. pass `B`` as nothing (Default case)
9+
x_nothing = solve(A, b, SmoothedAggregationAMG(), maxiter = 1, abstol = 1e-6)
10+
11+
#2. pass `B` as vector
12+
B = ones(T,n)
13+
x_vec = solve(A, b, SmoothedAggregationAMG(B), maxiter = 1, abstol = 1e-6)
14+
@test x_vec x_nothing
15+
16+
#3. pass `B` as matrix
17+
B = ones(T,n,1)
18+
x_mat = solve(A, b, SmoothedAggregationAMG(B), maxiter = 1, abstol = 1e-6)
19+
@test x_mat x_nothing
20+
end
21+
22+
123
## Test QR factorization
224
@testset "fit_candidates unit test cases" begin
325
cases = Vector{Tuple{SparseMatrixCSC{Float64,Int},Matrix{Float64}}}()

0 commit comments

Comments
 (0)