Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a test for convert to PETScMatrix #79

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion test/PoissonTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using GridapPETSc
using GridapPETSc: PETSC
using PartitionedArrays
using Test
using SparseMatricesCSR


# Setup solver via low level PETSC API calls
function mykspsetup(ksp)
Expand Down Expand Up @@ -67,14 +69,33 @@ function main(parts,solver)

a(u,v) = ∫( ∇(v)⋅∇(u) )dΩ
l(v) = ∫( v*f )dΩ + ∫( v*g )dΓn
assem=SparseMatrixAssembler(SparseMatrixCSR{0,PetscScalar,PetscInt},Vector{Float64},U,V)

Tm=SparseMatrixCSR{0,PetscScalar,PetscInt}
Tv=Vector{PetscScalar}
assem=SparseMatrixAssembler(Tm,Tv,U,V)
op = AffineFEOperator(a,l,U,V,assem)

v_julia = get_vector(op)
v_petsc = convert(PETScVector,v_julia)
copy!(v_julia,v_petsc)
copy!(v_petsc,v_julia)

# Checking that convert performs deep copies and does not modify A
A=get_matrix(op)
vals_copy=map_parts(A.values) do A
@test typeof(A)==SparseMatrixCSR{0,PetscScalar,PetscInt}
i=copy(A.rowptr)
j=copy(A.colval)
a=copy(A.nzval)
i,j,a
end
Apetsc=convert(PETScMatrix,A)
map_parts(A.values,vals_copy) do A, (i,j,a)
@test all(i .== A.rowptr)
@test all(j .== A.colval)
@test all(a .== A.nzval)
end

if solver == :mumps
ls = PETScLinearSolver(mykspsetup)
else
Expand Down