|
1 | | - |
2 | 1 | const CKSP = Ptr{Cvoid} |
3 | 2 | const CKSPType = Cstring |
4 | 3 |
|
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} |
8 | 7 | 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 |
17 | 26 | end |
18 | 27 |
|
| 28 | +#= |
19 | 29 | struct WrappedKSP{T, PetscLib} <: AbstractKSP{T, PetscLib} |
20 | 30 | ptr::CKSP |
21 | 31 | end |
@@ -311,4 +321,4 @@ Gets the last (approximate preconditioned) residual norm that has been computed. |
311 | 321 | $(_doc_external("KSP/KSPGetResidualNorm")) |
312 | 322 | """ |
313 | 323 | resnorm |
314 | | - |
| 324 | +=# |
0 commit comments