You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/vec.jl
+79-52Lines changed: 79 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -6,60 +6,99 @@
6
6
7
7
const CVec = Ptr{Cvoid}
8
8
9
-
abstract type AbstractVec{T} <:AbstractVector{T}end
10
-
scalartype(::AbstractVec{T}) where {T} = T
9
+
abstract type AbstractVec{PetscLib, PetscScalar} <:AbstractVector{PetscScalar}end
10
+
11
+
Base.eltype(
12
+
::Type{V},
13
+
) where {
14
+
V <:AbstractVec{PetscLib, PetscScalar},
15
+
} where {PetscLib, PetscScalar} = PetscScalar
16
+
Base.eltype(
17
+
v::AbstractVec{PetscLib, PetscScalar},
18
+
) where {PetscLib, PetscScalar} = PetscScalar
19
+
Base.size(v::AbstractVec) = (length(v),)
11
20
12
21
"""
13
22
VecSeq(v::Vector)
14
23
15
-
A standard, sequentially-stored serial PETSc vector, wrapping the Julia vector `v`.
24
+
A standard, sequentially-stored serial PETSc vector, wrapping the Julia vector
25
+
`v`.
16
26
17
-
This reuses the array `v` as storage, and so `v` should not be `resize!`-ed or otherwise have its length modified while the PETSc object exists.
27
+
This reuses the array `v` as storage, and so `v` should not be `resize!`-ed or
28
+
otherwise have its length modified while the PETSc object exists.
18
29
19
-
This should only be need to be called for more advanced uses, for most simple usecases, users should be able to pass `Vector`s directly and have the wrapping performed automatically
30
+
This should only be need to be called for more advanced uses, for most simple
31
+
usecases, users should be able to pass `Vector`s directly and have the wrapping
32
+
performed automatically
20
33
21
34
# External Links
22
35
$(_doc_external("Vec/VecCreateSeqWithArray"))
23
36
"""
24
-
mutable struct VecSeq{T} <:AbstractVec{T}
37
+
mutable struct VecSeq{PetscLib, PetscScalar} <:
38
+
AbstractVec{PetscLib, PetscScalar}
25
39
ptr::CVec
26
-
array::Vector{T}
40
+
array::Vector{PetscScalar}
41
+
end
42
+
Base.parent(v::VecSeq) = v.array
43
+
44
+
functionVecSeq(
45
+
petsclib::PetscLib,
46
+
array::Vector{PetscScalar};
47
+
blocksize =1,
48
+
comm::MPI.Comm= MPI.COMM_SELF,
49
+
) where {PetscLib, PetscScalar}
50
+
@assertinitialized(petsclib)
51
+
@assert PetscScalar == petsclib.PetscScalar
52
+
v =VecSeq{PetscLib, PetscScalar}(C_NULL, array)
53
+
LibPETSc.VecCreateSeqWithArray(
54
+
petsclib,
55
+
comm,
56
+
blocksize,
57
+
length(array),
58
+
array,
59
+
v,
60
+
)
61
+
finalizer(destroy, v)
62
+
return v
27
63
end
28
64
29
-
Base.eltype(::Type{V}) where {V<:AbstractVec{T}} where T = T
30
-
Base.eltype(v::AbstractVec{T}) where {T} = T
31
-
Base.size(v::AbstractVec) = (length(v),)
32
-
Base.parent(v::AbstractVec) = v.array
65
+
functiondestroy(v::AbstractVec{PetscLib}) where {PetscLib}
0 commit comments