Skip to content

Commit 48383a1

Browse files
committed
Cleanup and minor optimization
1 parent 6ee174c commit 48383a1

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

benchmark/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[deps]
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
34
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
45
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
6+
SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"

benchmark/benchmark-sparsitypattern.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ function make_df(timings)
7979
end
8080

8181
display(make_df(make_timings(SparseMatrixCSC{Float64, Int})))
82-
display(make_df(make_timings(SparseMatrixCSR)))
82+
# display(make_df(make_timings(SparseMatrixCSR)))

src/Dofs/sparsity_pattern.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -739,17 +739,23 @@ end
739739
getncols(sp::FastSparsityPattern) = length(sp.marker)
740740
getnrows(sp::FastSparsityPattern) = length(sp.rowlen)
741741

742-
function create_celldofs(dh)
742+
function create_celldofs(dh::DofHandler)
743+
isclosed(dh) || throw(ArgumentError("DofHandler must be closed"))
743744
ncells = getncells(dh.grid)
744745
indices = similar(dh.cell_dofs_offset, ncells + 1)
745746
cell_dofs = similar(dh.cell_dofs)
746747
n = 1
747-
for cell_idx in 1:getncells(dh.grid)
748+
for cell_idx in 1:ncells
748749
indices[cell_idx] = n
749-
r = n:(n + ndofs_per_cell(dh, cell_idx) - 1)
750-
celldofs!(view(cell_dofs, r), dh, cell_idx)
750+
num = ndofs_per_cell(dh, cell_idx)
751+
num == 0 && continue
752+
r = n:(n + num - 1)
753+
#celldofs!(view(cell_dofs, r), dh, cell_idx), but faster without view:
754+
soffs = dh.cell_dofs_offset[cell_idx]
755+
copyto!(cell_dofs, n, dh.cell_dofs, soffs, num)
751756
n = last(r) + 1
752757
end
758+
indices[end] = n
753759
return ArrayOfVectorViews(indices, cell_dofs, LinearIndices((ncells,)))
754760
end
755761

@@ -764,7 +770,6 @@ function create_row_to_cells(cell_dofs::ArrayOfVectorViews, sp)
764770
n_connected += 1
765771
end
766772
end
767-
# n_connected = sum(num_cells) better?
768773

769774
# 2: Create the correct datastructure
770775
data = Vector{Int}(undef, n_connected)

0 commit comments

Comments
 (0)