From afbe26feb7ea1e1c70b156ea4e7953ed5b77b68c Mon Sep 17 00:00:00 2001 From: Jeremy E Kozdon Date: Mon, 2 Aug 2021 16:32:05 -0700 Subject: [PATCH] WIP: Starting to work on KSP --- src/PETSc.jl | 2 +- src/ksp.jl | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/PETSc.jl b/src/PETSc.jl index fef4e47b..679dd90c 100644 --- a/src/PETSc.jl +++ b/src/PETSc.jl @@ -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") diff --git a/src/ksp.jl b/src/ksp.jl index f2a5ba13..e2bd2628 100644 --- a/src/ksp.jl +++ b/src/ksp.jl @@ -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 @@ -311,4 +321,4 @@ Gets the last (approximate preconditioned) residual norm that has been computed. $(_doc_external("KSP/KSPGetResidualNorm")) """ resnorm - +=#