Skip to content
Merged
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
38 changes: 19 additions & 19 deletions src/Dofs/ConstraintHandler.jl
Comment thread
termi-official marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mutable struct ConstraintHandler{DH <: AbstractDofHandler, T}
const dofcoefficients::Vector{Union{Nothing, DofCoefficients{T}}}
# global dof -> index into dofs and inhomogeneities and dofcoefficients
const dofmapping::Dict{Int, Int}
const isconstrained::BitVector # Fast check if dof is constrained or not
const bcvalues::Vector{BCValues{T}}
const dh::DH
closed::Bool
Expand All @@ -177,7 +178,7 @@ function ConstraintHandler(::Type{T}, dh::AbstractDofHandler) where {T <: Number
@assert isclosed(dh)
return ConstraintHandler(
Dirichlet[], ProjectedDirichlet[], Int[], Int[], T[], Union{Nothing, T}[],
Union{Nothing, DofCoefficients{T}}[], Dict{Int, Int}(), BCValues{T}[], dh, false,
Union{Nothing, DofCoefficients{T}}[], Dict{Int, Int}(), BitVector(), BCValues{T}[], dh, false,
)
end

Expand Down Expand Up @@ -259,21 +260,15 @@ isclosed(ch::ConstraintHandler) = ch.closed
free_dofs(ch::ConstraintHandler) = ch.free_dofs
prescribed_dofs(ch::ConstraintHandler) = ch.prescribed_dofs

# Equivalent to `copy!(out, setdiff(1:n_entries, diff))`, but requires that
# `issorted(diff)` and that `1 ≤ diff[1] ≤ diff[end] ≤ n_entries`
function _sorted_setdiff!(out::Vector{Int}, n_entries::Int, diff::Vector{Int})
n_diff = length(diff)
resize!(out, n_entries - n_diff)
diff_ind = out_ind = 1
for i in 1:n_entries
if diff_ind ≤ n_diff && i == diff[diff_ind]
diff_ind += 1
else
out[out_ind] = i
out_ind += 1
end
function set_freedofs!(free_dofs::Vector{Int}, isconstrained::BitVector, num_dofs::Int, num_prescribed::Int)
Comment thread
termi-official marked this conversation as resolved.
Outdated
resize!(free_dofs, num_dofs - num_prescribed)
j = 1
for i in 1:num_dofs
isconstrained[i] && continue
free_dofs[j] = i
j += 1
end
return out
return free_dofs
end

"""
Expand All @@ -291,7 +286,12 @@ function close!(ch::ConstraintHandler)
ch.affine_inhomogeneities .= ch.affine_inhomogeneities[I]
ch.dofcoefficients .= ch.dofcoefficients[I]

_sorted_setdiff!(ch.free_dofs, ndofs(ch.dh), ch.prescribed_dofs)
resize!(ch.isconstrained, ndofs(ch.dh))
fill!(ch.isconstrained, false)
for dof in ch.prescribed_dofs
ch.isconstrained[dof] = true
end
set_freedofs!(ch.free_dofs, ch.isconstrained, ndofs(ch.dh), length(ch.prescribed_dofs))

for i in 1:length(ch.prescribed_dofs)
ch.dofmapping[ch.prescribed_dofs[i]] = i
Expand Down Expand Up @@ -915,9 +915,9 @@ end
function zero_out_rows!(K::AbstractSparseMatrixCSC, ch::ConstraintHandler)
rowval = K.rowval
nzval = K.nzval
@inbounds for i in eachindex(rowval, nzval)
if haskey(ch.dofmapping, rowval[i])
nzval[i] = 0
@inbounds for (i, row) in pairs(rowval)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same w.r.t pairs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, but here the storage types in AbstractSparseMatrixCSC could be offset arrays, and then I assume that it should be pairs since we assume rowval and nzval have the same indexing?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if ch.isconstrained[row]
nzval[i] = zero(eltype(K))
end
end
return
Expand Down
Loading