Skip to content

Commit

Permalink
Add assemble function for non-square matrices (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijas committed Sep 13, 2022
1 parent 357e35b commit 6eab785
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/assembler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ end
Assembles the element matrix `Ke` into `a`.
"""
function assemble!(a::Assembler{T}, dofs::AbstractVector{Int}, Ke::AbstractMatrix{T}) where {T}
n_dofs = length(dofs)
assemble!(a, dofs, dofs, Ke)
end

"""
assemble!(a::Assembler, rowdofs, coldofs, Ke)
Assembles the matrix `Ke` into `a` according to the dofs specified by `rowdofs` and `coldofs`.
"""
function assemble!(a::Ferrite.Assembler{T}, rowdofs::AbstractVector{Int}, coldofs::AbstractVector{Int}, Ke::AbstractMatrix{T}) where {T}
nrows = length(rowdofs)
ncols = length(coldofs)

@assert(size(Ke,1) == nrows)
@assert(size(Ke,2) == ncols)

append!(a.V, Ke)
@inbounds for j in 1:n_dofs
append!(a.I, dofs)
for i in 1:n_dofs
push!(a.J, dofs[j])
@inbounds for i in 1:ncols
append!(a.I, rowdofs)
for _ in 1:nrows
push!(a.J, coldofs[i])
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/test_assemble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@
@test K[1,1] == Ke[1,1]
@test K[1,5] == Ke[1,3]
@test K[5,1] == Ke[3,1]

# assemble with different row and col dofs
rdofs = [1,4,6]
cdofs = [1,7]
a = start_assemble()
Ke = rand(length(rdofs), length(cdofs))
assemble!(a, rdofs, cdofs, Ke)
K = end_assemble(a)
@test (K[rdofs,cdofs] .== Ke) |> all

end

0 comments on commit 6eab785

Please sign in to comment.