Skip to content

Commit

Permalink
Modifications to add! (#41)
Browse files Browse the repository at this point in the history
With these changes it's possible to give `dofs1` and `dofs2` eg. in
sub-arrays or tuples, not only vectors. Also, `data` can be a long
vector in row-major order (`data_vec = vec(data)`).
  • Loading branch information
ahojukka5 committed Apr 8, 2019
1 parent 53db388 commit 02637af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ Matrix(A)
0.0 0.0 0.0 0.0 0.0 8.0 9.0 10.0
```
"""
function add!(A::SparseMatrixCOO, dofs1::Vector{Int}, dofs2::Vector{Int}, data)
n, m = size(data)
function add!(A::SparseMatrixCOO, dofs1::AbstractVector{Int}, dofs2::AbstractVector{Int}, data)
n, m = length(dofs1), length(dofs2)
@assert length(data) == n*m
k = 1
for j=1:m
for i=1:n
add!(A, dofs1[i], dofs2[j], data[i,j])
add!(A, dofs1[i], dofs2[j], data[k])
k += 1
end
end
return nothing
Expand Down
4 changes: 2 additions & 2 deletions test/test_assembly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ end
A = Assembly()
B = Assembly()
@test isempty(A)
add!(A.K, [1,2,3,4], [1,2,3,4], [1.0 2.0; 3.0 4.0])
add!(B.K, [1,2,3,4], [1,2,3,4], [1.0 2.0; 3.0 4.0])
add!(A.K, [1,2], [1,2], [1.0 2.0; 3.0 4.0])
add!(B.K, [1,2], [1,2], [1.0 2.0; 3.0 4.0])
@test isapprox(A, B)
@test !isempty(A)
empty!(A)
Expand Down

0 comments on commit 02637af

Please sign in to comment.