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,23 @@ 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
84+ function VecSeqWithArray (
85+ :: Type{PetscLib} ,
86+ x... ;
87+ kw... ,
88+ ) where {PetscLib <: PetscLibType }
89+ VecSeqWithArray (getlib (PetscLib), x... ; kw... )
8390end
8491
8592function Base. length (v:: AbstractVec{PetscLib} ) where {PetscLib}
86- petsclib = getlib (PetscLib)
87- PetscInt = petsclib. PetscInt
93+ PetscInt = PetscLib. PetscInt
8894 r_sz = Ref {PetscInt} ()
8995 LibPETSc. VecGetSize (PetscLib, v, r_sz)
9096 return r_sz[]
9197end
9298
9399function locallength (v:: AbstractVec{PetscLib} ) where {PetscLib}
94- petsclib = getlib (PetscLib)
95- PetscInt = petsclib. PetscInt
100+ PetscInt = PetscLib. PetscInt
96101 r_sz = Ref {PetscInt} ()
97102 LibPETSc. VecGetLocalSize (PetscLib, v, r_sz)
98103 return r_sz[]
@@ -102,8 +107,7 @@ function LinearAlgebra.norm(
102107 v:: AbstractVec{PetscLib} ,
103108 normtype:: LibPETSc.NormType = LibPETSc. NORM_2,
104109) where {PetscLib}
105- petsclib = getlib (PetscLib)
106- PetscReal = petsclib. PetscReal
110+ PetscReal = PetscLib. PetscReal
107111 r_val = Ref {PetscReal} ()
108112 LibPETSc. VecNorm (PetscLib, v, normtype, r_val)
109113 return r_val[]
@@ -141,8 +145,7 @@ function ownershiprange(
141145 vec:: AbstractVec{PetscLib} ,
142146 base_one:: Bool = true ,
143147) where {PetscLib}
144- petsclib = getlib (PetscLib)
145- PetscInt = petsclib. PetscInt
148+ PetscInt = PetscLib. PetscInt
146149 r_lo = Ref {PetscInt} ()
147150 r_hi = Ref {PetscInt} ()
148151 LibPETSc. VecGetOwnershipRange (PetscLib, vec, r_lo, r_hi)
@@ -173,8 +176,7 @@ function unsafe_localarray(
173176 read:: Bool = true ,
174177 write:: Bool = true ,
175178) where {PetscLib}
176- petsclib = getlib (PetscLib)
177- PetscScalar = petsclib. PetscScalar
179+ PetscScalar = PetscLib. PetscScalar
178180 r_pv = Ref {Ptr{PetscScalar}} ()
179181 if write && read
180182 LibPETSc. VecGetArray (PetscLib, vec, r_pv)
0 commit comments