Skip to content

Commit

Permalink
Remove some unnecessary allocations in affine constraint condensation (
Browse files Browse the repository at this point in the history
…#537)

This patch removes some unnecessary allocations of a sparse matrix
column which was needed before when the sparse matrix changed in-place.
Since #436 we create a new matrix for the new entries and then add them
in the end instead.
  • Loading branch information
fredrikekre committed Nov 27, 2022
1 parent c90c188 commit 404219f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Dofs/ConstraintHandler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,10 @@ function _condense_sparsity_pattern!(K::SparseMatrixCSC{T}, dofcoefficients::Vec

cnt = 0
for col in 1:ndofs
# Since we will possibly be pushing new entries to K, the field K.rowval will grow.
# Therefor we must extract this before iterating over K
range = nzrange(K, col)
_rows = K.rowval[range]
col_coeffs = coefficients_for_dof(dofmapping, dofcoefficients, col)
if col_coeffs === nothing
for row in _rows
for ri in nzrange(K, col)
row = K.rowval[ri]
row_coeffs = coefficients_for_dof(dofmapping, dofcoefficients, row)
row_coeffs === nothing && continue
for (d, _) in row_coeffs
Expand All @@ -700,7 +697,8 @@ function _condense_sparsity_pattern!(K::SparseMatrixCSC{T}, dofcoefficients::Vec
end
end
else
for row in _rows
for ri in nzrange(K, col)
row = K.rowval[ri]
row_coeffs = coefficients_for_dof(dofmapping, dofcoefficients, row)
if row_coeffs === nothing
for (d, _) in col_coeffs
Expand Down

0 comments on commit 404219f

Please sign in to comment.