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 1 commit
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
21 changes: 21 additions & 0 deletions src/assembler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ function assemble!(a::Assembler{T}, dofs::AbstractVector{Int}, Ke::AbstractMatri
end
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 i in 1:ncols
for j in 1:nrows
push!(a.J, coldofs[i])
push!(a.I, rowdofs[j])
end
end
end

"""
end_assemble(a::Assembler) -> K

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