Skip to content

Commit

Permalink
Added block assemblers tests to testset
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Aug 22, 2023
1 parent 0f9bf91 commit 7bc9706
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 59 deletions.
122 changes: 63 additions & 59 deletions test/BlockSparseMatrixAssemblersTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,72 +53,76 @@ function is_same_matrix(Ab::BlockMatrix,A::PSparseMatrix,Xb,X)
return is_same_vector(yb,y,Xb,X)
end

nparts = (2,2)
parts = with_debug() do distribute
distribute(LinearIndices((prod(nparts),)))
function _main(n_spaces,mfs,weakform,Ω,dΩ,U,V)
biform, liform = weakform

# Normal assembly
Y = MultiFieldFESpace(fill(V,n_spaces))
X = MultiFieldFESpace(fill(U,n_spaces))

u = get_trial_fe_basis(X)
v = get_fe_basis(Y)

data = collect_cell_matrix_and_vector(X,Y,biform(u,v),liform(v))
matdata = collect_cell_matrix(X,Y,biform(u,v))
vecdata = collect_cell_vector(Y,liform(v))

assem = SparseMatrixAssembler(X,Y,FullyAssembledRows())
A1 = assemble_matrix(assem,matdata)
b1 = assemble_vector(assem,vecdata)
A2,b2 = assemble_matrix_and_vector(assem,data);

# Block Assembly
Yb = MultiFieldFESpace(fill(V,n_spaces);style=mfs)
Xb = MultiFieldFESpace(fill(U,n_spaces);style=mfs)

ub = get_trial_fe_basis(Xb)
vb = get_fe_basis(Yb)

bdata = collect_cell_matrix_and_vector(Xb,Yb,biform(ub,vb),liform(vb))
bmatdata = collect_cell_matrix(Xb,Yb,biform(ub,vb))
bvecdata = collect_cell_vector(Yb,liform(vb))

assem_blocks = SparseMatrixAssembler(Xb,Yb,FullyAssembledRows())
A1_blocks = assemble_matrix(assem_blocks,bmatdata);
b1_blocks = assemble_vector(assem_blocks,bvecdata);
@test is_same_vector(b1_blocks,b1,Yb,Y)
@test is_same_matrix(A1_blocks,A1,Xb,X)

A2_blocks, b2_blocks = assemble_matrix_and_vector(assem_blocks,bdata)
@test is_same_vector(b2_blocks,b2,Yb,Y)
@test is_same_matrix(A2_blocks,A2,Xb,X)

op = AffineFEOperator(biform,liform,X,Y)
block_op = AffineFEOperator(biform,liform,Xb,Yb)
@test is_same_vector(get_vector(block_op),get_vector(op),Yb,Y)
@test is_same_matrix(get_matrix(block_op),get_matrix(op),Xb,X)
end

sol(x) = sum(x)

model = CartesianDiscreteModel(parts,nparts,(0.0,1.0,0.0,1.0),(8,8))
Ω = Triangulation(model)

reffe = LagrangianRefFE(Float64,QUAD,1)
V = FESpace(Ω, reffe)
U = TrialFESpace(sol,V)

= Measure(Ω, 4)
biform((u1,u2,u3),(v1,v2,v3)) = ((u1)(v1) + u2v2 + u1v2 + u2v1 + v3u3 + v3u1 + v1u3)*
liform((v1,v2,v3)) = (v1 + v2 + v3)*
#biform((u1,u2),(v1,v2)) = ∫(∇(u1)⋅∇(v1) + u2⋅v2 + u1⋅v2 - u2⋅v1)*dΩ
#liform((v1,v2)) = ∫(v1 + v2)*dΩ

############################################################################################
# Normal assembly

Y = MultiFieldFESpace([V,V,V])
X = MultiFieldFESpace([U,U,U])

u = get_trial_fe_basis(X)
v = get_fe_basis(Y)

data = collect_cell_matrix_and_vector(X,Y,biform(u,v),liform(v))
matdata = collect_cell_matrix(X,Y,biform(u,v))
vecdata = collect_cell_vector(Y,liform(v))

assem = SparseMatrixAssembler(X,Y,FullyAssembledRows())
A1 = assemble_matrix(assem,matdata)
b1 = assemble_vector(assem,vecdata)
A2,b2 = assemble_matrix_and_vector(assem,data);

############################################################################################
# Block MultiFieldStyle

#mfs = BlockMultiFieldStyle()
mfs = BlockMultiFieldStyle(2,(1,2))
function main(distribute,parts)
ranks = distribute(LinearIndices((prod(parts),)))

Yb = MultiFieldFESpace([V,V,V];style=mfs)
Xb = MultiFieldFESpace([U,U,U];style=mfs)
model = CartesianDiscreteModel(ranks,parts,(0,1,0,1),(8,8))
Ω = Triangulation(model)

ub = get_trial_fe_basis(Xb)
vb = get_fe_basis(Yb)
sol(x) = sum(x)
reffe = LagrangianRefFE(Float64,QUAD,1)
V = FESpace(Ω, reffe; dirichlet_tags="boundary")
U = TrialFESpace(sol,V)

bdata = collect_cell_matrix_and_vector(Xb,Yb,biform(ub,vb),liform(vb))
bmatdata = collect_cell_matrix(Xb,Yb,biform(ub,vb))
bvecdata = collect_cell_vector(Yb,liform(vb))
= Measure(Ω, 2)
biform2((u1,u2),(v1,v2)) = ((u1)(v1) + u2v2 + u1v2)*
liform2((v1,v2)) = (v1 + v2)*
biform3((u1,u2,u3),(v1,v2,v3)) = ((u1)(v1) + u2v2 + u1v2 + u3v2 + u2v3)*
liform3((v1,v2,v3)) = (v1 + v2 + v3)*

############################################################################################
# Block Assembly

assem_blocks = SparseMatrixAssembler(Xb,Yb,FullyAssembledRows())
A1_blocks = assemble_matrix(assem_blocks,bmatdata);
b1_blocks = assemble_vector(assem_blocks,bvecdata);
is_same_vector(b1_blocks,b1,Yb,Y)
is_same_matrix(A1_blocks,A1,Xb,X)

op = AffineFEOperator(biform,liform,X,Y)
block_op = AffineFEOperator(biform,liform,Xb,Yb)
is_same_vector(get_vector(block_op),get_vector(op),Yb,Y)
is_same_matrix(get_matrix(block_op),get_matrix(op),Xb,X)
for (n_spaces,weakform) in zip([2,3],[(biform2,liform2),(biform3,liform3)])
for mfs in [BlockMultiFieldStyle(),BlockMultiFieldStyle(2,(1,n_spaces-1))]
_main(n_spaces,mfs,weakform,Ω,dΩ,U,V)
end
end
end

end
1 change: 1 addition & 0 deletions test/TestApp/src/TestApp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module TestApp
include("../../HeatEquationTests.jl")
include("../../StokesOpenBoundaryTests.jl")
include("../../AdaptivityTests.jl")
include("../../BlockSparseMatrixAssemblersTests.jl")
end
3 changes: 3 additions & 0 deletions test/mpi/runtests_np4_body.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ function all_tests(distribute,parts)
PArrays.toc!(t,"Adaptivity")
end

TestApp.BlockSparseMatrixAssemblersTests.main(distribute,parts)
PArrays.toc!(t,"BlockSparseMatrixAssemblers")

display(t)
end
17 changes: 17 additions & 0 deletions test/sequential/BlockSparseMatrixAssemblersTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module BlockSparseMatrixAssemblersTestsSeq
using PartitionedArrays
include("../BlockSparseMatrixAssemblersTests.jl")

with_debug() do distribute
BlockSparseMatrixAssemblersTests.main(distribute,(2,2))
end

with_debug() do distribute
BlockSparseMatrixAssemblersTests.main(distribute,(2,1))
end

with_debug() do distribute
BlockSparseMatrixAssemblersTests.main(distribute,(1,2))
end

end # module
3 changes: 3 additions & 0 deletions test/sequential/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ end

@time @testset "StokesHdivDGTests.jl" begin include("StokesHdivDGTests.jl") end

@time @testset "BlockSparseMatrixAssemblers" begin
include("BlockSparseMatrixAssemblersTests.jl")
end

end # module

0 comments on commit 7bc9706

Please sign in to comment.