-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from WIAS-PDELib/jf/linearsolve_precs
Use LinearSolve precs API to control preconditioners
- Loading branch information
Showing
17 changed files
with
501 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#= | ||
# 003: New linear solver API | ||
([source code](@__SOURCE_URL__)) | ||
=# | ||
|
||
module Example003_Solvers | ||
|
||
## under development | ||
|
||
using Printf | ||
using VoronoiFVM | ||
using ExtendableGrids | ||
using GridVisualize | ||
using LinearSolve | ||
using ExtendableSparse | ||
using ExtendableSparse: ILUZeroPreconBuilder, JacobiPreconBuilder, SmoothedAggregationPreconBuilder | ||
using SparseArrays | ||
using AMGCLWrap | ||
using AlgebraicMultigrid | ||
using LinearAlgebra | ||
|
||
|
||
using Test | ||
|
||
|
||
function main(; n = 10, Plotter = nothing, assembly = :edgwwise, kwargs...) | ||
h = 1.0 / convert(Float64, n) | ||
X = collect(0.0:h:1.0) | ||
Y = collect(0.0:h:1.0) | ||
|
||
grid = simplexgrid(X, Y) | ||
nn = num_nodes(grid) | ||
|
||
eps = 1.0e-2 | ||
|
||
function reaction(f, u, node, data) | ||
f[1] = u[1]^2 | ||
end | ||
|
||
function flux(f, u, edge, data) | ||
f[1] = eps * (u[1, 1]^2 - u[1, 2]^2) | ||
end | ||
|
||
function source(f, node, data) | ||
x1 = node[1] - 0.5 | ||
x2 = node[2] - 0.5 | ||
f[1] = exp(-20.0 * (x1^2 + x2^2)) | ||
end | ||
|
||
function storage(f, u, node, data) | ||
f[1] = u[1] | ||
end | ||
|
||
function bcondition(f, u, node, data) | ||
boundary_dirichlet!(f, | ||
u, | ||
node; | ||
species = 1, | ||
region = 2, | ||
value = ramp(node.time; dt = (0, 0.1), du = (0, 1))) | ||
boundary_dirichlet!(f, | ||
u, | ||
node; | ||
species = 1, | ||
region = 4, | ||
value = ramp(node.time; dt = (0, 0.1), du = (0, 1))) | ||
end | ||
|
||
sys = VoronoiFVM.System(grid; reaction, flux, source, storage, bcondition, assembly, | ||
species = [1]) | ||
@info "UMFPACK:" | ||
umf_sol = solve(sys; inival = 0.5, method_linear = LinearSolve.UMFPACKFactorization(), kwargs...) | ||
|
||
@info "KLU:" | ||
sol = solve(sys; inival = 0.5, method_linear = LinearSolve.KLUFactorization(), kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Sparspak:" | ||
sol = solve(sys; inival = 0.5, method_linear = LinearSolve.SparspakFactorization(), kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov-ilu0:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(precs=ILUZeroPreconBuilder()), | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov-block1" | ||
precs=BlockPreconBuilder(;precs=ILUZeroPreconBuilder(), partitioning= A-> [1:(size(A,1) ÷ 2), (size(A,1) ÷ 2 + 1):size(A,1)]) | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs), | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov-block2" | ||
precs=BlockPreconBuilder(;precs=ILUZeroPreconBuilder(), partitioning= A-> [1:2:size(A,1), 2:2:size(A,1)]) | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs), | ||
log=true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov - delayed factorization:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs=LinearSolvePreconBuilder(SparspakFactorization())), | ||
keepcurrent_linear =false, | ||
log=true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
@test summary(history(sol)).factorizations == 1 | ||
|
||
@info "Krylov - jacobi:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs=JacobiPreconBuilder()), | ||
keepcurrent_linear = true, log=true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
@test summary(history(sol)).factorizations > 1 | ||
|
||
@info "Krylov - SA_AMG:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs=SmoothedAggregationPreconBuilder()), | ||
keepcurrent_linear = true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov - AMGCL_AMG:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs=AMGPreconBuilder()), | ||
keepcurrent_linear = true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
|
||
@info "Krylov - AMGnCL_RLX:" | ||
sol = solve(sys; | ||
inival = 0.5, | ||
method_linear = KrylovJL_BICGSTAB(;precs=RLXPreconBuilder()), | ||
keepcurrent_linear = true, | ||
kwargs...) | ||
@test norm(sol - umf_sol, Inf)<1.0e-7 | ||
end | ||
|
||
function runtests() | ||
@testset "edgewise" begin | ||
main(; assembly = :edgewise) | ||
end | ||
@testset "cellwise" begin | ||
main(; assembly = :cellwise) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
cbbcd50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
cbbcd50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/119128
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: