11# AbstractVec
2- # - VecSeq : wrap
2+ # - VecSeqWithArray : wrap
33# - VecMPI (TODO )
44# - VecGhost (TODO )
55# for the MPI variants we won't be able to attach finalizers, as destroy needs to be called collectively.
@@ -18,6 +18,11 @@ Base.eltype(
1818) where {PetscLib, PetscScalar} = PetscScalar
1919Base. size (v:: AbstractVec ) = (length (v),)
2020
21+ function destroy (v:: AbstractVec{PetscLib} ) where {PetscLib}
22+ finalized (PetscLib) || LibPETSc. VecDestroy (PetscLib, v)
23+ return nothing
24+ end
25+
2126"""
2227 VecPtr(petsclib, v::Vector)
2328
@@ -34,7 +39,7 @@ VecPtr(::Type{PetscLib}, ptr::CVec) where {PetscLib <: PetscLibType} =
3439 VecPtr (getlib (PetscLib), ptr)
3540
3641"""
37- VecSeq (petsclib, v::Vector)
42+ VecSeqWithArray (petsclib, v::Vector)
3843
3944A standard, sequentially-stored serial PETSc vector, wrapping the Julia vector
4045`v`.
@@ -49,22 +54,22 @@ performed automatically
4954# External Links
5055$(_doc_external (" Vec/VecCreateSeqWithArray" ))
5156"""
52- mutable struct VecSeq {PetscLib, PetscScalar} < :
57+ mutable struct VecSeqWithArray {PetscLib, PetscScalar} < :
5358 AbstractVec{PetscLib, PetscScalar}
5459 ptr:: CVec
5560 array:: Vector{PetscScalar}
5661end
57- Base. parent (v:: VecSeq ) = v. array
62+ Base. parent (v:: VecSeqWithArray ) = v. array
5863
59- function VecSeq (
64+ function VecSeqWithArray (
6065 petsclib:: PetscLib ,
6166 array:: Vector{PetscScalar} ;
6267 blocksize = 1 ,
6368) where {PetscLib <: PetscLibType , PetscScalar}
6469 comm = MPI. COMM_SELF
6570 @assert initialized (petsclib)
6671 @assert PetscScalar == petsclib. PetscScalar
67- v = VecSeq {PetscLib, PetscScalar} (C_NULL , array)
72+ v = VecSeqWithArray {PetscLib, PetscScalar} (C_NULL , array)
6873 LibPETSc. VecCreateSeqWithArray (
6974 petsclib,
7075 comm,
@@ -76,23 +81,22 @@ function VecSeq(
7681 finalizer (destroy, v)
7782 return v
7883end
79-
80- function destroy (v:: AbstractVec{PetscLib} ) where {PetscLib}
81- finalized (PetscLib) || LibPETSc. VecDestroy (PetscLib, v)
82- return nothing
83- end
84+ VecSeqWithArray (
85+ :: Type{PetscLib} ,
86+ x... ;
87+ kw... ,
88+ ) where {PetscLib <: PetscLibType } =
89+ VecSeqWithArray (getlib (PetscLib), x... ; kw... )
8490
8591function Base. length (v:: AbstractVec{PetscLib} ) where {PetscLib}
86- petsclib = getlib (PetscLib)
87- PetscInt = petsclib. PetscInt
92+ PetscInt = PetscLib. PetscInt
8893 r_sz = Ref {PetscInt} ()
8994 LibPETSc. VecGetSize (PetscLib, v, r_sz)
9095 return r_sz[]
9196end
9297
9398function locallength (v:: AbstractVec{PetscLib} ) where {PetscLib}
94- petsclib = getlib (PetscLib)
95- PetscInt = petsclib. PetscInt
99+ PetscInt = PetscLib. PetscInt
96100 r_sz = Ref {PetscInt} ()
97101 LibPETSc. VecGetLocalSize (PetscLib, v, r_sz)
98102 return r_sz[]
@@ -102,8 +106,7 @@ function LinearAlgebra.norm(
102106 v:: AbstractVec{PetscLib} ,
103107 normtype:: LibPETSc.NormType = LibPETSc. NORM_2,
104108) where {PetscLib}
105- petsclib = getlib (PetscLib)
106- PetscReal = petsclib. PetscReal
109+ PetscReal = PetscLib. PetscReal
107110 r_val = Ref {PetscReal} ()
108111 LibPETSc. VecNorm (PetscLib, v, normtype, r_val)
109112 return r_val[]
@@ -141,8 +144,7 @@ function ownershiprange(
141144 vec:: AbstractVec{PetscLib} ,
142145 base_one:: Bool = true ,
143146) where {PetscLib}
144- petsclib = getlib (PetscLib)
145- PetscInt = petsclib. PetscInt
147+ PetscInt = PetscLib. PetscInt
146148 r_lo = Ref {PetscInt} ()
147149 r_hi = Ref {PetscInt} ()
148150 LibPETSc. VecGetOwnershipRange (PetscLib, vec, r_lo, r_hi)
@@ -173,8 +175,7 @@ function unsafe_localarray(
173175 read:: Bool = true ,
174176 write:: Bool = true ,
175177) where {PetscLib}
176- petsclib = getlib (PetscLib)
177- PetscScalar = petsclib. PetscScalar
178+ PetscScalar = PetscLib. PetscScalar
178179 r_pv = Ref {Ptr{PetscScalar}} ()
179180 if write && read
180181 LibPETSc. VecGetArray (PetscLib, vec, r_pv)
0 commit comments