Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assemble function for non-square matrices #471

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
lijas marked this conversation as resolved.
Show resolved Hide resolved
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