Skip to content

Commit

Permalink
WIP: Starting to work on KSP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy E Kozdon committed Aug 2, 2021
1 parent 2405525 commit afbe26f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/PETSc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include("mat.jl")
# include("dm.jl")
# include("dmda.jl")
include("matshell.jl")
# include("ksp.jl")
include("ksp.jl")
# include("pc.jl")
# include("snes.jl")
include("sys.jl")
Expand Down
36 changes: 23 additions & 13 deletions src/ksp.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@

const CKSP = Ptr{Cvoid}
const CKSPType = Cstring

abstract type AbstractKSP{T, PetscLib} <: Factorization{T} end

Base.@kwdef mutable struct KSP{T, PetscLib} <: AbstractKSP{T, PetscLib}
abstract type AbstractKSP{PetscLib, PetscScalar} <: Factorization{PetscScalar} end
Base.@kwdef mutable struct KSP{PetscLib, PetscScalar} <: AbstractKSP{PetscLib, PetscScalar}
ptr::CKSP = C_NULL
opts::Options{PetscLib}
# Stuff to keep around so that they don't get gc'ed
_A = nothing
_P = nothing
_dm = nothing
# Function pointers
ComputeRHS! = nothing
ComputeOperators! = nothing
opts::Options{PetscLib} = Options(PetscLib)
A::Union{AbstractMat, Nothing} = nothing
end

function KSP(A::AbstractMat{PetscLib}; kwargs...) where PetscLib
@assert initialized(PetscLib)
opts = Options(PetscLib; kwargs...)
PetscScalar = PetscLib.PetscScalar
ksp = KSP{PetscLib, PetscScalar}(opts=opts, A = A)
#=
with(ksp.opts) do
@chk ccall((:KSPCreate, $libpetsc), PetscErrorCode, (MPI.MPI_Comm, Ptr{CKSP}), comm, ksp)
end
if comm == MPI.COMM_SELF
finalizer(destroy, ksp)
end
=#
return ksp
end

#=
struct WrappedKSP{T, PetscLib} <: AbstractKSP{T, PetscLib}
ptr::CKSP
end
Expand Down Expand Up @@ -311,4 +321,4 @@ Gets the last (approximate preconditioned) residual norm that has been computed.
$(_doc_external("KSP/KSPGetResidualNorm"))
"""
resnorm

=#

0 comments on commit afbe26f

Please sign in to comment.