Eliminate Dirichlet boundary conditions differently

Slicing is very expensive operation on sparse matrices. Avoid slicing
by calculating matrix product `K_red = C1*K*C1`, where C1 is diagonal
matrix. This should be much cheaper.
This commit is contained in:
Jukka Aho
2017-08-19 14:15:11 +03:00
parent 6e036878c8
commit a08a928796
+7 -6
View File
@@ -44,12 +44,13 @@ function eliminate_boundary_conditions!(K_red::SparseMatrixCSC,
@assert nnz(g) == 0
@assert C1 == C2
@assert isdiag(C1)
nz = get_nonzero_rows(C1)
info("bc $(problem.name): $(length(nz)) nonzeros, $nz")
K_red[nz,:] = 0.0
K_red[:,nz] = 0.0
M_red[nz,:] = 0.0
M_red[:,nz] = 0.0
fixed_dofs = get_nonzero_rows(C1)
P = ones(ndim)
P[fixed_dofs] = 0.0
Q = spdiagm(P)
K_red[:,:] = Q' * K_red * Q
M_red[:,:] = Q' * M_red * Q
return
end
""" Given data vector, return slave displacements. """