-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassembler.jl
More file actions
60 lines (55 loc) · 1.38 KB
/
Copy pathassembler.jl
File metadata and controls
60 lines (55 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
struct Assembler{T}
I::Vector{Int}
J::Vector{Int}
V::Vector{T}
end
function Assembler(N)
I = Int[]
J = Int[]
V = Float64[]
sizehint!(I, N)
sizehint!(J, N)
sizehint!(V, N)
Assembler(I, J, V)
end
"""
start_assemble([N=0]) -> Assembler
Call before starting an assembly.
Returns an `Assembler` type that is used to hold the intermediate
data before an assembly is finished.
"""
function start_assemble(N::Int=0)
return Assembler(N)
end
"""
assemble!(a, Ke, edof)
Assembles the element matrix `Ke` into `a`.
"""
function assemble!(a::Assembler{T}, edof::Union{AbstractVector{Int},NTuple{N,Int}}, Ke::AbstractMatrix{T}) where {N,T}
n_dofs = length(edof)
append!(a.V, Ke)
@inbounds for j in 1:n_dofs
append!(a.I, edof)
for i in 1:n_dofs
push!(a.J, edof[j])
end
end
end
"""
end_assemble(a::Assembler) -> K
Finalizes an assembly. Returns a sparse matrix with the
assembled values.
"""
function end_assemble(a::Assembler)
return sparse(a.I, a.J, a.V)
end
"""
assemble!(g, ge, edof)
Assembles the element residual `ge` into the global residual vector `g`.
"""
@propagate_inbounds function assemble!(g::AbstractVector{T}, edof::AbstractVector{Int}, ge::AbstractVector{T}) where {T,N}
@boundscheck checkbounds(g, edof)
@inbounds for i in 1:length(edof)
g[edof[i]] += ge[i]
end
end