@@ -11,13 +11,28 @@ Base.@kwdef mutable struct KSP{PetscLib, PetscScalar} <:
1111 P:: Union{AbstractMat, Nothing} = nothing
1212end
1313
14+ """
15+ KSP(A::AbstractMat, P::AbstractMat{PetscLib} = A; options...)
16+
17+ Create a `KSP` using the matrix `A` and preconditioner construction matrix `P`
18+ with the `options`.
19+
20+ The communicator is obtained from `A` and if it has size `1` then the garbage
21+ collector is set, otherwise the user is responsible for calling
22+ [`destroy`](@ref).
23+
24+ # External Links
25+ $(_doc_external (" KSP/KSPCreate" ))
26+ $(_doc_external (" KSP/KSPSetOperators" ))
27+ $(_doc_external (" KSP/KSPSetFromOptions" ))
28+ """
1429function KSP (
1530 A:: AbstractMat{PetscLib} ,
1631 P:: AbstractMat{PetscLib} = A;
17- kwargs ... ,
32+ options ... ,
1833) where {PetscLib}
1934 @assert initialized (PetscLib)
20- opts = Options (PetscLib; kwargs ... )
35+ opts = Options (PetscLib; options ... )
2136 PetscScalar = PetscLib. PetscScalar
2237 ksp = KSP {PetscLib, PetscScalar} (opts = opts)
2338 comm = getcomm (A)
@@ -70,6 +85,34 @@ function solve!(
7085 return x
7186end
7287
88+ """
89+ createvecs(ksp::AbstractKSP; nright = 0, nleft = 0)
90+
91+ Create `nright` right and `nleft` left vectors compatible with the `ksp`.
92+ Returned object `V` has `Tuple` members `V.right` and `V.left` containing the
93+ vectors.
94+
95+ # External Links
96+ $(_doc_external (" KSP/KSPCreateVecs" ))
97+ """
98+ function createvecs (ksp:: AbstractKSP{PetscLib} ; nright = 0 , nleft = 0 ) where PetscLib
99+ r_right = [Ref {CVec} () for i = 1 : nright]
100+ r_left = [Ref {CVec} () for i = 1 : nleft]
101+ LibPETSc. KSPCreateVecs (PetscLib, ksp, nright, r_right, nleft, r_left)
102+
103+ for i = 1 : nright
104+ @show r_right[i][]
105+ end
106+ for i = 1 : nleft
107+ @show r_left[i][]
108+ end
109+
110+ right = ntuple (i -> VecPtr (PetscLib, r_right[i][], false ), nright)
111+ left = ntuple (i -> VecPtr (PetscLib, r_left[i][], false ), nleft)
112+
113+ (right = right, left = left)
114+ end
115+
73116function LinearAlgebra. ldiv! (x:: AbstractVec , ksp:: AbstractKSP , b:: AbstractVec )
74117 solve! (x, ksp, b)
75118end
0 commit comments