Skip to content
Draft
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
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.4.23"
authors = ["Olav Møyner <olav.moyner@gmail.com>"]

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down Expand Up @@ -40,6 +39,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[weakdeps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
AMGCLWrap = "4f76b812-4ba5-496d-b042-d70715554288"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
Expand All @@ -55,6 +55,7 @@ PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[extensions]
JutulAlgebraicMultigridExt = "AlgebraicMultigrid"
JutulAMGCLWrapExt = "AMGCLWrap"
JutulGLMakieExt = "GLMakie"
JutulGmshExt = "Gmsh"
Expand Down Expand Up @@ -107,6 +108,7 @@ WriteVTK = "1"
julia = "1.7"

[extras]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
CPUSummary = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
Expand All @@ -121,4 +123,4 @@ NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"

[targets]
test = ["KaHyPar", "HYPRE", "LBFGSB"]
test = ["AlgebraicMultigrid", "KaHyPar", "HYPRE", "LBFGSB"]
33 changes: 33 additions & 0 deletions ext/JutulAlgebraicMultigridExt/JutulAlgebraicMultigridExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module JutulAlgebraicMultigridExt
using Jutul
using AlgebraicMultigrid
using SparseArrays
using LinearAlgebra
using Polyester

import LinearAlgebra: ldiv!, lu, mul!
import Jutul: AMGPreconditioner,
update_preconditioner!,
partial_update_preconditioner!,
operator_nrows,
StaticSparsityMatrixCSR,
SPAI0Preconditioner,
ILUZeroPreconditioner,
JacobiPreconditioner,
default_executor,
get_factorization,
nthreads,
minbatch,
colvals,
@tic

function Jutul.check_algebraicmultigrid_availability_impl()
return true
end

function Jutul.amg_default_cycle_impl()
return AlgebraicMultigrid.V()
end

include(joinpath(@__DIR__, "..", "..", "src", "linsolve", "precond", "amg.jl"))
end
1 change: 0 additions & 1 deletion src/Jutul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module Jutul
using ILUZero
using LinearOperators
using Krylov
using AlgebraicMultigrid

# Misc. utils
using ExprTools
Expand Down
53 changes: 53 additions & 0 deletions src/ext/algebraicmultigrid_ext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
mutable struct AMGPreconditioner{T} <: JutulPreconditioner
method_kwarg
cycle
factor
dim
hierarchy
smoothers
smoother_type::Symbol
npre::Int
npost::Int
end

function AMGPreconditioner(method::Symbol; smoother_type = :default, cycle = nothing, npre = 1, npost = npre, kwarg...)
check_algebraicmultigrid_availability()
@assert method == :smoothed_aggregation || method == :ruge_stuben || method == :aggregation
if isnothing(cycle)
cycle = amg_default_cycle_impl()
end
return AMGPreconditioner{method}(kwarg, cycle, nothing, nothing, nothing, nothing, smoother_type, npre, npost)
end

"""
check_algebraicmultigrid_availability(; throw = true)

Check if AlgebraicMultigrid extension is available. If `throw=true` this will be
an error, otherwise a Boolean indicating if the extension is available will be
returned.
"""
function check_algebraicmultigrid_availability(; throw = true)
ok = true
try
ok = check_algebraicmultigrid_availability_impl()
catch e
if throw
if e isa MethodError
error("AlgebraicMultigrid is not available. To fix: using Pkg; Pkg.add(\"AlgebraicMultigrid\") and then call import AlgebraicMultigrid to enable AlgebraicMultigrid.")
else
rethrow(e)
end
else
ok = false
end
end
return ok
end

function amg_default_cycle_impl

end

function check_algebraicmultigrid_availability_impl

end
1 change: 1 addition & 0 deletions src/ext/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include("algebraicmultigrid_ext.jl")
include("amgclwrap_ext.jl")
include("makie_ext.jl")
include("glmakie_ext.jl")
Expand Down
19 changes: 0 additions & 19 deletions src/linsolve/precond/amg.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@

"""
AMG on CPU (Julia native)
"""
mutable struct AMGPreconditioner{T} <: JutulPreconditioner
method_kwarg
cycle
factor
dim
hierarchy
smoothers
smoother_type::Symbol
npre::Int
npost::Int
function AMGPreconditioner(method::Symbol; smoother_type = :default, cycle = AlgebraicMultigrid.V(), npre = 1, npost = npre, kwarg...)
@assert method == :smoothed_aggregation || method == :ruge_stuben || method == :aggregation
new{method}(kwarg, cycle, nothing, nothing, nothing, nothing, smoother_type, npre, npost)
end
end

matrix_for_amg(A) = A
matrix_for_amg(A::StaticSparsityMatrixCSR) = copy(A.At')

Expand Down
2 changes: 0 additions & 2 deletions src/linsolve/precond/precond.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ abstract type JutulPreconditioner end
abstract type DiagonalPreconditioner <: JutulPreconditioner end

include("utils.jl")
include("amg.jl")
include("diagonal.jl")
include("ilu.jl")
include("spai.jl")
include("jacobi.jl")
include("various.jl")

1 change: 1 addition & 0 deletions test/test_systems/heat_2d.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Jutul
using AlgebraicMultigrid
using Test

function test_heat_2d(nx = 3, ny = nx; kwarg...)
Expand Down
Loading