Skip to content

Commit 7cb9201

Browse files
committed
Add tests for numeric types to CSR assembler
1 parent 4f227b2 commit 7cb9201

1 file changed

Lines changed: 51 additions & 51 deletions

File tree

test/test_assemble.jl

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -73,60 +73,60 @@ import LinearAlgebra: Symmetric
7373
@test_throws ArgumentError assemble!(assembler, rdofs, Ke, fe) # Not in sparsity pattern
7474
@test all(K[rdofs, cdofs] .== 2Ke)
7575
@test all(f[rdofs] .== 2fe)
76-
end
77-
78-
# CSCAssembler: Assemble rectangular part in quadratic matrix
79-
K = SparseMatrixCSC(6, 6, [K.colptr..., 7, 7, 7], K.rowval, K.nzval)
80-
assembler = start_assemble(K, f)
81-
rdofs = [1, 4, 6]
82-
cdofs = [1, 3]
83-
Ke = rand(length(rdofs), length(cdofs))
84-
fe = rand(length(rdofs))
85-
assemble!(assembler, rdofs, cdofs, Ke, fe)
86-
assemble!(assembler, rdofs, cdofs, Ke, fe)
87-
@test_throws ArgumentError assemble!(assembler, rdofs, Ke, fe) # Not in sparsity pattern
88-
@test all(K[rdofs, cdofs] .== 2Ke)
89-
@test all(f[rdofs] .== 2fe)
90-
91-
# SparseMatrix assembler
92-
K = spzeros(10, 10)
93-
f = zeros(10)
94-
ke = [rand(4, 4), rand(4, 4)]
95-
fe = [rand(4), rand(4)]
96-
dofs = [[1, 5, 3, 7], [10, 8, 2, 5]]
97-
for i in 1:2
98-
K[dofs[i], dofs[i]] += ke[i]
99-
f[dofs[i]] += fe[i]
100-
end
10176

102-
Kc = copy(K)
103-
fc = copy(f)
104-
105-
assembler = start_assemble(Kc)
106-
@test all(iszero, Kc.nzval) # start_assemble zeroes
107-
for i in 1:2
108-
assemble!(assembler, dofs[i], ke[i])
109-
end
110-
@test Kc K
77+
# CSCAssembler: Assemble rectangular part in quadratic matrix
78+
K = SparseMatrixCSC(6, 6, [K.colptr..., 7, 7, 7], K.rowval, K.nzval)
79+
assembler = start_assemble(K, f)
80+
rdofs = [1, 4, 6]
81+
cdofs = [1, 3]
82+
Ke = rand(T, length(rdofs), length(cdofs))
83+
fe = rand(T, length(rdofs))
84+
assemble!(assembler, rdofs, cdofs, Ke, fe)
85+
assemble!(assembler, rdofs, cdofs, Ke, fe)
86+
@test_throws ArgumentError assemble!(assembler, rdofs, Ke, fe) # Not in sparsity pattern
87+
@test all(K[rdofs, cdofs] .== 2Ke)
88+
@test all(f[rdofs] .== 2fe)
11189

112-
assembler = start_assemble(Kc, fc)
113-
@test all(iszero, Kc.nzval)
114-
@test all(iszero, fc)
115-
for i in 1:2
116-
assemble!(assembler, dofs[i], ke[i], fe[i])
117-
end
118-
@test Kc K
119-
@test fc f
120-
121-
# No zero filling
122-
assembler = start_assemble(Kc, fc; fillzero = false)
123-
@test Kc K
124-
@test fc f
125-
for i in 1:2
126-
assemble!(assembler, dofs[i], ke[i], fe[i])
90+
# SparseMatrix assembler
91+
K = spzeros(T, 10, 10)
92+
f = zeros(T, 10)
93+
ke = [rand(T, 4, 4), rand(4, 4)]
94+
fe = [rand(T, 4), rand(4)]
95+
dofs = [[1, 5, 3, 7], [10, 8, 2, 5]]
96+
for i in 1:2
97+
K[dofs[i], dofs[i]] += ke[i]
98+
f[dofs[i]] += fe[i]
99+
end
100+
101+
Kc = copy(K)
102+
fc = copy(f)
103+
104+
assembler = start_assemble(Kc)
105+
@test all(iszero, Kc.nzval) # start_assemble zeroes
106+
for i in 1:2
107+
assemble!(assembler, dofs[i], ke[i])
108+
end
109+
@test Kc K
110+
111+
assembler = start_assemble(Kc, fc)
112+
@test all(iszero, Kc.nzval)
113+
@test all(iszero, fc)
114+
for i in 1:2
115+
assemble!(assembler, dofs[i], ke[i], fe[i])
116+
end
117+
@test Kc K
118+
@test fc f
119+
120+
# No zero filling
121+
assembler = start_assemble(Kc, fc; fillzero = false)
122+
@test Kc K
123+
@test fc f
124+
for i in 1:2
125+
assemble!(assembler, dofs[i], ke[i], fe[i])
126+
end
127+
@test Kc 2K
128+
@test fc 2f
127129
end
128-
@test Kc 2K
129-
@test fc 2f
130130

131131
# Error paths
132132
assembler = start_assemble(Kc, fc)

0 commit comments

Comments
 (0)