Skip to content

Commit

Permalink
Deprecate assemble! with local vector before local matrix
Browse files Browse the repository at this point in the history
This patch deprecates the signature
`assemble!(assembler, dofs, local_vector, local_matrix)` in favor of
`assemble!(assembler, dofs, local_matrix, local_vector)`. The former
signature was not used in many places, not supported by e.g. the block
matrix assembler, and it is confusing that there are two options. See
also #707 for a similar change to `start_assemble`.

In addition, if the assembler is used just for matrix assembly, this
patch removes an unnecessary allocation of an empty vector for every
call to `assemble!`.
  • Loading branch information
fredrikekre committed Sep 19, 2024
1 parent 5ec6c84 commit 54f93fc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function assemble_global!(K::SparseMatrixCSC, f, cellvalues_u::CellValues,
ue = w[global_dofsu] # displacement dofs for the current cell
pe = w[global_dofsp] # pressure dofs for the current cell
assemble_element!(ke, fe, cell, cellvalues_u, cellvalues_p, mp, ue, pe)
assemble!(assembler, global_dofs, fe, ke)
assemble!(assembler, global_dofs, ke, fe)
end
end;

Expand Down
2 changes: 1 addition & 1 deletion docs/src/literate-tutorials/hyperelasticity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function assemble_global!(K, g, dh, cv, fv, mp, u, ΓN)
global_dofs = celldofs(cell)
ue = u[global_dofs] # element dofs
@timeit "element assemble" assemble_element!(ke, ge, cell, cv, fv, mp, ue, ΓN)
assemble!(assembler, global_dofs, ge, ke)
assemble!(assembler, global_dofs, ke, ge)
end
end;

Expand Down
2 changes: 1 addition & 1 deletion docs/src/literate-tutorials/incompressible_elasticity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function doassemble(
fill!(ke, 0)
fill!(fe, 0)
assemble_up!(ke, fe, cell, cellvalues_u, cellvalues_p, facetvalues_u, grid, mp, ɛdev, t)
assemble!(assembler, celldofs(cell), fe, ke)
assemble!(assembler, celldofs(cell), ke, fe)
end

return K, f
Expand Down
14 changes: 4 additions & 10 deletions src/assembler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,10 @@ stiffness matrix and `f` the global force/residual vector, but more efficient.
"""
assemble!(::AbstractAssembler, ::AbstractVector{<:Integer}, ::AbstractMatrix, ::AbstractVector)

@propagate_inbounds function assemble!(A::AbstractAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix)
assemble!(A, dofs, Ke, eltype(Ke)[])
end
@propagate_inbounds function assemble!(A::AbstractAssembler, dofs::AbstractVector{<:Integer}, fe::AbstractVector, Ke::AbstractMatrix)
assemble!(A, dofs, Ke, fe)
end
@propagate_inbounds function assemble!(A::AbstractAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::AbstractVector)
@propagate_inbounds function assemble!(A::AbstractAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::Union{AbstractVector, Nothing} = nothing)
_assemble!(A, dofs, Ke, fe, false)
end
@propagate_inbounds function assemble!(A::SymmetricCSCAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::AbstractVector)
@propagate_inbounds function assemble!(A::SymmetricCSCAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::Union{AbstractVector, Nothing} = nothing)
_assemble!(A, dofs, Ke, fe, true)
end

Expand All @@ -215,10 +209,10 @@ Sorts the dofs into a separate buffer and returns it together with a permutation
return sorteddofs, permutation
end

@propagate_inbounds function _assemble!(A::AbstractCSCAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::AbstractVector, sym::Bool)
@propagate_inbounds function _assemble!(A::AbstractCSCAssembler, dofs::AbstractVector{<:Integer}, Ke::AbstractMatrix, fe::Union{AbstractVector, Nothing}, sym::Bool)
ld = length(dofs)
@boundscheck checkbounds(Ke, keys(dofs), keys(dofs))
if length(fe) != 0
if fe !== nothing
@boundscheck checkbounds(fe, keys(dofs))
@boundscheck checkbounds(A.f, dofs)
@inbounds assemble!(A.f, dofs, fe)
Expand Down
5 changes: 5 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,8 @@ export VTKFile
function VTKFile(args...)
throw(DeprecationError("VTKFile(args...)" => "VTKGridFile(args...)"))
end

# assemble with vector first
function assemble!(::AbstractAssembler, ::AbstractVector{<:Integer}, ::AbstractVector, ::AbstractMatrix)
throw(DeprecationError("assemble!(assembler, dofs, fe, Ke)" => "assemble!(assembler, dofs, Ke, fe)"))

Check warning on line 444 in src/deprecations.jl

View check run for this annotation

Codecov / codecov/patch

src/deprecations.jl#L443-L444

Added lines #L443 - L444 were not covered by tests
end
2 changes: 1 addition & 1 deletion test/test_abstractgrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
end
end
end
assemble!(assembler, celldofs(dh,cellid), fe, Ke)
assemble!(assembler, celldofs(dh,cellid), Ke, fe)
end
return K, f
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_apply_rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function test_apply_rhs()
end
end

assemble!(assembler, celldofs(cell), fe, Ke)
assemble!(assembler, celldofs(cell), Ke, fe)
end
return K, f
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_mixeddofhandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function test_2_element_heat_eq()
end
end
end
assemble!(assembler, eldofs, fe, Ke)
assemble!(assembler, eldofs, Ke, fe)
end
end

Expand Down

0 comments on commit 54f93fc

Please sign in to comment.