Skip to content

Commit afbe26f

Browse files
author
Jeremy E Kozdon
committed
WIP: Starting to work on KSP
1 parent 2405525 commit afbe26f

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/PETSc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ include("mat.jl")
2828
# include("dm.jl")
2929
# include("dmda.jl")
3030
include("matshell.jl")
31-
# include("ksp.jl")
31+
include("ksp.jl")
3232
# include("pc.jl")
3333
# include("snes.jl")
3434
include("sys.jl")

src/ksp.jl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
21
const CKSP = Ptr{Cvoid}
32
const CKSPType = Cstring
43

5-
abstract type AbstractKSP{T, PetscLib} <: Factorization{T} end
6-
7-
Base.@kwdef mutable struct KSP{T, PetscLib} <: AbstractKSP{T, PetscLib}
4+
abstract type AbstractKSP{PetscLib, PetscScalar} <: Factorization{PetscScalar} end
5+
6+
Base.@kwdef mutable struct KSP{PetscLib, PetscScalar} <: AbstractKSP{PetscLib, PetscScalar}
87
ptr::CKSP = C_NULL
9-
opts::Options{PetscLib}
10-
# Stuff to keep around so that they don't get gc'ed
11-
_A = nothing
12-
_P = nothing
13-
_dm = nothing
14-
# Function pointers
15-
ComputeRHS! = nothing
16-
ComputeOperators! = nothing
8+
opts::Options{PetscLib} = Options(PetscLib)
9+
A::Union{AbstractMat, Nothing} = nothing
10+
end
11+
12+
function KSP(A::AbstractMat{PetscLib}; kwargs...) where PetscLib
13+
@assert initialized(PetscLib)
14+
opts = Options(PetscLib; kwargs...)
15+
PetscScalar = PetscLib.PetscScalar
16+
ksp = KSP{PetscLib, PetscScalar}(opts=opts, A = A)
17+
#=
18+
with(ksp.opts) do
19+
@chk ccall((:KSPCreate, $libpetsc), PetscErrorCode, (MPI.MPI_Comm, Ptr{CKSP}), comm, ksp)
20+
end
21+
if comm == MPI.COMM_SELF
22+
finalizer(destroy, ksp)
23+
end
24+
=#
25+
return ksp
1726
end
1827

28+
#=
1929
struct WrappedKSP{T, PetscLib} <: AbstractKSP{T, PetscLib}
2030
ptr::CKSP
2131
end
@@ -311,4 +321,4 @@ Gets the last (approximate preconditioned) residual norm that has been computed.
311321
$(_doc_external("KSP/KSPGetResidualNorm"))
312322
"""
313323
resnorm
314-
324+
=#

0 commit comments

Comments
 (0)