diff --git a/src/JuliaFEM.jl b/src/JuliaFEM.jl index 47d6471..418cc04 100644 --- a/src/JuliaFEM.jl +++ b/src/JuliaFEM.jl @@ -60,7 +60,7 @@ include("integrate.jl") # default integration points for elements export get_integration_points include("sparse.jl") -export add!, SparseMatrixCOO, get_nonzero_rows, get_nonzero_columns +export add!, SparseMatrixCOO, SparseVectorCOO, get_nonzero_rows, get_nonzero_columns include("problems.jl") # common problem routines export Problem, AbstractProblem, FieldProblem, BoundaryProblem, diff --git a/src/sparse.jl b/src/sparse.jl index 48c466d..a93e990 100644 --- a/src/sparse.jl +++ b/src/sparse.jl @@ -10,8 +10,14 @@ type SparseMatrixCOO{T<:Real} V :: Vector{T} end +typealias SparseVectorCOO SparseMatrixCOO + function SparseMatrixCOO() - SparseMatrixCOO{Float64}([], [], []) + return SparseMatrixCOO{Float64}([], [], []) +end + +function SparseVectorCOO(I::Vector, V::Vector) + return SparseVectorCOO(I, ones(I), V) end function convert(::Type{SparseMatrixCOO}, A::SparseMatrixCSC) @@ -132,7 +138,15 @@ function add!(A::SparseMatrixCOO, dofs::Vector{Int}, data::Array{Float64}, dim:: append!(A.V, vec(data)) end -""" Combine (I,J,V) values is possible to reduce memory usage. """ +""" Add SparseVector to SparseVectorCOO. """ +function add!(a::SparseVectorCOO, b::SparseVector) + I, V = findnz(b) + c = SparseVectorCOO(I, V) + append!(a, c) + return +end + +""" Combine (I,J,V) values if possible to reduce memory usage. """ function optimize!(A::SparseMatrixCOO) I, J, V = findnz(sparse(A)) A.I = I diff --git a/test/test_interfaces.jl b/test/test_interfaces.jl deleted file mode 100644 index cee9355..0000000 --- a/test/test_interfaces.jl +++ /dev/null @@ -1,12 +0,0 @@ -# This file is a part of JuliaFEM. -# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md - -module InterfaceTests - -using JuliaFEM.Testing - -function test_foo() - @test 1+2 == 3 -end - -end diff --git a/test/test_sparse.jl b/test/test_sparse.jl new file mode 100644 index 0000000..bdf4515 --- /dev/null +++ b/test/test_sparse.jl @@ -0,0 +1,19 @@ +# This file is a part of JuliaFEM. +# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md + +using JuliaFEM +using JuliaFEM.Testing + +@testset "Add to SparseMatrixCOO" begin + A = SparseMatrixCOO() + A2 = reshape(collect(1:9), 3, 3) + add!(A, sparse(A2)) + @test isapprox(full(A), full(A2)) +end + +@testset "Add to SparseVectorCOO" begin + b = SparseVectorCOO() + b2 = collect(1:3) + add!(b, sparse(b2)) + @test isapprox(full(b), full(b2)) +end