Skip to content

Commit

Permalink
Merge pull request #140 from WIAS-PDELib/jf/linearsolve_precs
Browse files Browse the repository at this point in the history
Use LinearSolve precs API to control preconditioners
  • Loading branch information
j-fu authored Nov 10, 2024
2 parents 30c0301 + b1e6922 commit cbbcd50
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 291 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# Changes

## v3.0 Planned (pending some improvements in LinearSolve)
- use `precs` based linear solver API, see https://github.com/SciML/LinearSolve.jl/pull/514
- stop re-exporting ForwardDiff.value
- try to remove type piracies
- remove `params` from edge, node structs (appearantly never used)
- Remove VoronoiFVM solver strategies
- Stop re-exporting ForwardDiff.value
- Try to remove type piracies
- Remove `params` from edge, node structs (appearantly never used)

## v2.4.0 November 11, 2024
- Use `precs` based linear solver API, see https://github.com/SciML/LinearSolve.jl/pull/514 with ExtendableSparse 1.6
- Deprecate VoronoiFVM solver strategies

## v2.3.0 November 5, 2024
- Allow to use result of time embedding a steady state for impedance
- Move to WIAS-PDELib org

## v2.2.0 October 30, 2024
- Add `params` to SystemState, allow to pass params to ODEProblem
Expand Down
2 changes: 1 addition & 1 deletion docs/src/citations.bib → CITATIONS.bib
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ @techreport{qureshi4921855reduced
title={Reduced Order Cfd Modeling Approach Based on the Asymptotic Expansion-An Application for Heterogeneous Catalytic Systems},
author={Qureshi, Muhammad Uzair and Matera, Sebastian and Runge, Daniel and Merdon, Christian and Fuhrmann, J{\"u}rgen and Repke, Jens-Uwe and Br{\"o}sigke, Georg},
institution = "SSRN",
url = {https://ssrn.com/abstract=4921855}
url = {https://ssrn.com/abstract=4921855},
year={2024}
}

Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VoronoiFVM"
uuid = "82b139dc-5afc-11e9-35da-9b9bdfd336f3"
authors = ["Jürgen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Patrick Jaap", "Daniel Runge", "Dilara Abdel", "Jan Weidner", "Alexander Seiler", "Patricio Farrell", "Matthias Liero"]
version = "2.3.0"
version = "2.4.0"

[deps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Expand Down Expand Up @@ -42,13 +42,13 @@ DiffResults = "1"
DocStringExtensions = "0.8,0.9"
ExtendableFEMBase = "0.7,0.8"
ExtendableGrids = "1.10.1"
ExtendableSparse = "1.5.1"
ExtendableSparse = "1.6"
ForwardDiff = "0.10.35"
GridVisualize = "0.5.2,0.6.1,1"
InteractiveUtils = "1.9"
JLD2 = "0.4.29, 0.5"
LinearAlgebra = "1.9"
LinearSolve = "2.2"
LinearSolve = "2.36"
Printf = "1.9"
Random = "1.9"
RecursiveArrayTools = "2,3"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ VoronoiFVM.jl and most of these packages are part of the meta package [PDELib.j

## Some projects and packages using VoronoiFVM.jl

- [ChargeTransport.jl: Drift diffusion simulator for semiconductor devices](https://github.com/PatricioFarrell/ChargeTransport.jl)
- [LiquidElectrolytes.jl: Generalized Nernst-Planck-Poisson model for liquid electrolytes](https://github.com/j-fu/LiquidElectrolytes.jl)
- [MultiComponentReactiveMixtureProject: Model for heat and multi-component, reactive gas phase transport in porous media.](https://github.com/DavidBrust/MultiComponentReactiveMixtureProject)
- [RfbScFVM: Performance prediction of flow battery cells](https://github.com/Isomorph-Electrochemical-Cells/RfbScFVM)
- [ChargeTransport.jl: Drift diffusion simulator for semiconductor devices](https://github.com/PatricioFarrell/ChargeTransport.jl)
- [MosLab.jl: From semiconductor to transistor level modeling in Julia](https://github.com/Rapos0/MOSLab.jl)
- [LiquidElectrolytes.jl: Generalized Nernst-Planck-Poisson model for liquid electrolytes](https://github.com/j-fu/LiquidElectrolytes.jl)


## Citation

If you use this package in your work, please cite it according to [CITATION.cff](https://raw.githubusercontent.com/WIAS-PDELib/VoronoiFVM.jl/master/CITATION.cff)
If you use this package in your work, please cite it according to [CITATION.cff](https://raw.githubusercontent.com/WIAS-PDELib/VoronoiFVM.jl/master/CITATION.cff).
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function make(; with_examples = true,
with_notebooks = true)

bib = CitationBibliography(
joinpath(@__DIR__, "src", "citations.bib");
joinpath(@__DIR__, "..", "CITATIONS.bib");
style=:numeric
)

Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $(read("../../README.md",String))

# Papers and preprints using this package

Please consider a pull request if you have published work which could be added to this list.
Please consider a pull request updating `CITATION.bib` if you have published work which could be added to this list.


```@bibliography
Expand Down
44 changes: 28 additions & 16 deletions docs/src/solver.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Overview:
- [Solve method](@ref "Solve method")
- [Solver control](@ref "Solver control")
- [System state](@ref "System state")
- [Linear solver stragies](@ref "Linear solver strategies")
- [Linear solver control](@ref "Linear solver control")
- [Block preconditioning](@ref "Block preconditioning")
- [History handling](@ref "History handling")
- [Matrix extraction](@ref "Matrix extraction")
Expand All @@ -42,28 +42,22 @@ VoronoiFVM.solve!(state::VoronoiFVM.SystemState; kwargs...)
Base.similar(state::VoronoiFVM.SystemState; kwargs...)
```

### Linear solver strategies
```@docs
VoronoiFVM.LinearSolverStrategy
DirectSolver
CGIteration
BICGstabIteration
GMRESIteration
```
### Linear solver control
Linear systems are solved using LinearSolve.jl.
Linear solve compatible solver strategies (factorizations, iterative solvers) can be
specified wia `method_linear` keyword argument to LinearSolve (equivalent to the `method_linear`
entry of [`SolverControl`](@ref).

### Block preconditioning
This feature is under development as of 1.6.
Currently supported possibilities are documented in the
[documentation of ExtendableSparse.jl](https://wias-pdelib.github.io/ExtendableSparse.jl/stable/linearsolve/#Solving-with-LinearSolve.jl).

VoronoiFVM.jl provides partitioning methods for block preconditioners.
```@docs
VoronoiFVM.BlockStrategy
NoBlock
EquationBlock
PointBlock
Equationwise
partitioning
```



### History handling
If `log` is set to true in `solve`, the history of newton iterations and time/embedding
steps is recorded and returned as `history(solution)`
Expand Down Expand Up @@ -147,5 +141,23 @@ are supported for backward compatibility.
NewtonControl
```

## Deprecated API
The methods and struct in this section are deprecated as of version 2.4 and will be removed in version 3.
### Linear solver strategies
```@docs
VoronoiFVM.LinearSolverStrategy
DirectSolver
CGIteration
BICGstabIteration
GMRESIteration
```

### Block preconditioning

```@docs
VoronoiFVM.BlockStrategy
NoBlock
EquationBlock
PointBlock
```

158 changes: 158 additions & 0 deletions examples/Example003_Solvers.jl
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
5 changes: 2 additions & 3 deletions examples/Example206_JouleHeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ function main(; nref = 0, Plotter = nothing, verbose = "and", unknown_storage =
species = [iϕ, iT], assembly = assembly)

sol = solve(sys; verbose,
method_linear = KrylovJL_BICGSTAB(),
precon_linear = UMFPACKFactorization(),
keepcurrent_linear =false,
method_linear = KrylovJL_BICGSTAB(precs=LinearSolvePreconBuilder(UMFPACKFactorization())),
keepcurrent_linear =false
)

vis = GridVisualizer(; Plotter, layout = (2, 1))
Expand Down
14 changes: 6 additions & 8 deletions examples/Example207_NonlinearPoisson2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ module Example207_NonlinearPoisson2D
using Printf
using VoronoiFVM
using ExtendableGrids
using ExtendableSparse
using ExtendableSparse: ILUZeroPreconBuilder
using GridVisualize
using LinearSolve
using ILUZero

function main(; n = 10, Plotter = nothing, verbose = false, unknown_storage = :sparse,
method_linear = nothing, assembly = :edgewise,
precon_linear = A -> VoronoiFVM.Identity())
method_linear = nothing, assembly = :edgewise)
h = 1.0 / convert(Float64, n)
X = collect(0.0:h:1.0)
Y = collect(0.0:h:1.0)
Expand Down Expand Up @@ -46,7 +45,6 @@ function main(; n = 10, Plotter = nothing, verbose = false, unknown_storage = :s
control.verbose = verbose
control.reltol_linear = 1.0e-5
control.method_linear = method_linear
control.precon_linear = precon_linear
tstep = 0.01
time = 0.0
u15 = 0
Expand All @@ -69,15 +67,15 @@ function runtests()
testval = 0.3554284760906605
@test main(; unknown_storage = :sparse, assembly = :edgewise) testval &&
main(; unknown_storage = :dense, assembly = :edgewise) testval &&
main(; unknown_storage = :sparse, method_linear = KrylovJL_CG(), precon_linear = ILUZeroPreconditioner,
main(; unknown_storage = :sparse, method_linear = KrylovJL_CG(precs=ILUZeroPreconBuilder()),
assembly = :edgewise) testval &&
main(; unknown_storage = :dense, method_linear = KrylovJL_CG(), precon_linear = ILUZeroPreconditioner,
main(; unknown_storage = :dense, method_linear = KrylovJL_CG(precs=ILUZeroPreconBuilder()),
assembly = :edgewise) testval &&
main(; unknown_storage = :sparse, assembly = :cellwise) testval &&
main(; unknown_storage = :dense, assembly = :cellwise) testval &&
main(; unknown_storage = :sparse, method_linear = KrylovJL_CG(), precon_linear = ILUZeroPreconditioner,
main(; unknown_storage = :sparse, method_linear = KrylovJL_CG(precs=ILUZeroPreconBuilder()),
assembly = :cellwise) testval &&
main(; unknown_storage = :dense, method_linear = KrylovJL_CG(), precon_linear = ILUZeroPreconditioner,
main(; unknown_storage = :dense, method_linear = KrylovJL_CG(precs=ILUZeroPreconBuilder()),
assembly = :cellwise) testval
end
end
3 changes: 2 additions & 1 deletion examples/Example430_ParameterDerivativesStationary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Example430_ParameterDerivativesStationary
using VoronoiFVM, ExtendableGrids
using GridVisualize
using ExtendableSparse
using ExtendableSparse: ILUZeroPreconBuilder
using ForwardDiff, DiffResults
using SparseDiffTools, SparseArrays
using ILUZero, LinearSolve
Expand Down Expand Up @@ -116,7 +117,7 @@ function rung(; Plotter = nothing, method_linear = SparspakFactorization(), n =
tfc = testfunction(tff, [1], [3])
end
data.p = P[1]
sol = solve(sys; inival = 0.5, method_linear, precon_linear = ILUZeroPreconditioner())
sol = solve(sys; inival = 0.5, method_linear)
[integrate(sys, tfc, sol)[1]]
end

Expand Down
Loading

2 comments on commit cbbcd50

@j-fu
Copy link
Member Author

@j-fu j-fu commented on cbbcd50 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

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:

git tag -a v2.4.0 -m "<description of version>" cbbcd50222d01f499f77b3bf889878c2f5e065b7
git push origin v2.4.0

Please sign in to comment.