From 22159ce5f2410a69972b2586f05f59bc8d1d719a Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Wed, 18 Mar 2026 11:01:28 +0100 Subject: [PATCH 1/4] faster combinedofs operator assembly --- examples/Example312_PeriodicElasticity3D.jl | 2 +- src/common_operators/combinedofs.jl | 26 ++++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/examples/Example312_PeriodicElasticity3D.jl b/examples/Example312_PeriodicElasticity3D.jl index 6d64f99e..78cb2228 100644 --- a/examples/Example312_PeriodicElasticity3D.jl +++ b/examples/Example312_PeriodicElasticity3D.jl @@ -129,7 +129,7 @@ end function main(; order = 1, - periodic_coupling = :none, # :restriction, :operator, :high_level_restriction + periodic_coupling = :high_level_restriction, # :restriction, :operator, :high_level_restriction Plotter = nothing, force = 1.0, h = 1.0e-4, diff --git a/src/common_operators/combinedofs.jl b/src/common_operators/combinedofs.jl index a98252b8..6147b87a 100644 --- a/src/common_operators/combinedofs.jl +++ b/src/common_operators/combinedofs.jl @@ -107,29 +107,27 @@ function build_assembler!(CD::CombineDofs{UT, CT}, FE::Array{<:FEVectorBlock, 1} function assemble!(A::AbstractSparseArray{T}, b::AbstractVector{T}, assemble_matrix::Bool, assemble_rhs::Bool, kwargs...) where {T} if assemble_matrix + + @showtime @views AT = sparse(A.cscmatrix[fixed_dofs .+ offsetX, :]') + # go through each constrained dof and update the FE adjacency info # of the coupled dofs - for dof_i in fixed_dofs + @time for (i, dof_i) in enumerate(fixed_dofs) # this col-view is efficient coupling_i = @views coupling_matrix[:, dof_i] - # write the FE adjacency of the constrained dofs into this row - sourcerow = dof_i + offsetX - # extract the constrained dofs and the weights coupled_dofs_i, weights_i = findnz(coupling_i) # parse through sourcerow and add the contents to the coupled dofs - for col in 1:size(A, 2) - r = findindex(A.cscmatrix, sourcerow, col) - if r > 0 - val = A.cscmatrix.nzval[r] - if abs(val) > 1.0e-15 - for (dof_k, weight_ik) in zip(coupled_dofs_i, weights_i) - targetrow = dof_k + offsetX - _addnz(A, targetrow, col, val, weight_ik) - end - end + A_row = @views AT[:, i] + cols_i, vals_i = findnz(A_row) + + # copy values of sourcerow to the coupled targetrow + for (col, val) in zip(cols_i, vals_i) + for (dof_k, weight_ik) in zip(coupled_dofs_i, weights_i) + targetrow = dof_k + offsetX + _addnz(A, targetrow, col, val, weight_ik) end end end From bc585b8bb27c1598ed0f2ce5a35013c88dbca9ec Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Wed, 18 Mar 2026 12:28:51 +0100 Subject: [PATCH 2/4] remove stale dependency --- src/ExtendableFEM.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExtendableFEM.jl b/src/ExtendableFEM.jl index bd7fb705..0febdb08 100644 --- a/src/ExtendableFEM.jl +++ b/src/ExtendableFEM.jl @@ -61,7 +61,7 @@ using ExtendableGrids: ExtendableGrids, AT_NODES, AbstractElementGeometry, unique, update_trafo!, xrefFACE2xrefCELL, xrefFACE2xrefOFACE using ExtendableSparse: ExtendableSparse, ExtendableSparseMatrix, flush!, - MTExtendableSparseMatrixCSC, findindex, + MTExtendableSparseMatrixCSC, rawupdateindex! using ForwardDiff: ForwardDiff using GridVisualize: GridVisualize, GridVisualizer, gridplot!, reveal, save, From cdfc026b473bb5bb90adc46e0d728a7fac9f2e86 Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Wed, 18 Mar 2026 12:33:16 +0100 Subject: [PATCH 3/4] version bump + changelog --- CHANGELOG.md | 7 +++++++ Project.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a0eb083..c6a63040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGES + +## v.1.10.4 + +### Fixed + - assembly of CombineDofs operator now much faster + + ## v.1.10.3 ### Fixed diff --git a/Project.toml b/Project.toml index 1c7662d7..68d0710a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ExtendableFEM" uuid = "a722555e-65e0-4074-a036-ca7ce79a4aed" -version = "1.10.3" +version = "1.10.4" authors = ["Christian Merdon ", "Patrick Jaap "] [deps] From bc536eaa9e9019795cbe7fc240c8d8b98548975d Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Wed, 18 Mar 2026 12:34:25 +0100 Subject: [PATCH 4/4] removed timing macros --- src/common_operators/combinedofs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common_operators/combinedofs.jl b/src/common_operators/combinedofs.jl index 6147b87a..d8b5afeb 100644 --- a/src/common_operators/combinedofs.jl +++ b/src/common_operators/combinedofs.jl @@ -108,11 +108,11 @@ function build_assembler!(CD::CombineDofs{UT, CT}, FE::Array{<:FEVectorBlock, 1} function assemble!(A::AbstractSparseArray{T}, b::AbstractVector{T}, assemble_matrix::Bool, assemble_rhs::Bool, kwargs...) where {T} if assemble_matrix - @showtime @views AT = sparse(A.cscmatrix[fixed_dofs .+ offsetX, :]') + @views AT = sparse(A.cscmatrix[fixed_dofs .+ offsetX, :]') # go through each constrained dof and update the FE adjacency info # of the coupled dofs - @time for (i, dof_i) in enumerate(fixed_dofs) + for (i, dof_i) in enumerate(fixed_dofs) # this col-view is efficient coupling_i = @views coupling_matrix[:, dof_i]