diff --git a/NEWS.md b/NEWS.md index cb1ae62f9..e17247191 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed issue where `FineToCoarseField` would not work for vector-valued fields. Since PR[#970](https://github.com/gridap/Gridap.jl/pull/970). +- Fixed issue where `BlockSparseMatrixAssembler` would not work correctly when permuting variables. Since PR[#971](https://github.com/gridap/Gridap.jl/pull/971). ## [0.17.21] - 2023-12-04 diff --git a/src/MultiField/BlockSparseMatrixAssemblers.jl b/src/MultiField/BlockSparseMatrixAssemblers.jl index b4a336d74..b8a6e2ae2 100644 --- a/src/MultiField/BlockSparseMatrixAssemblers.jl +++ b/src/MultiField/BlockSparseMatrixAssemblers.jl @@ -36,17 +36,20 @@ function FESpaces.get_vector_builder(a::BlockSparseMatrixAssembler{NB,NV}) where return expand_blocks(a,builders) end -expand_blocks(::BlockSparseMatrixAssembler{NB,NB},blocks::MatrixBlock) where NB = blocks -expand_blocks(::BlockSparseMatrixAssembler{NB,NB},blocks::VectorBlock) where NB = blocks - -function expand_blocks(a::BlockSparseMatrixAssembler{NB,NV},blocks::MatrixBlock) where {NB,NV} +function expand_blocks(a::BlockSparseMatrixAssembler{NB,NV,SB,P},blocks::MatrixBlock) where {NB,NV,SB,P} + if (NB == NV) && all(x -> x[1] == x[2], enumerate(P)) + return blocks + end block_map = get_block_map(a) - ArrayBlockView(blocks,block_map) + return ArrayBlockView(blocks,block_map) end -function expand_blocks(a::BlockSparseMatrixAssembler{NB,NV},blocks::VectorBlock) where {NB,NV} +function expand_blocks(a::BlockSparseMatrixAssembler{NB,NV,SB,P},blocks::VectorBlock) where {NB,NV,SB,P} + if (NB == NV) && all(x -> x[1] == x[2], enumerate(P)) + return blocks + end block_map = map(idx -> CartesianIndex(idx[1]), diag(get_block_map(a))) - ArrayBlockView(blocks,block_map) + return ArrayBlockView(blocks,block_map) end function get_block_ranges(NB::Integer,SB,P)