Skip to content

Commit 3fc816a

Browse files
authored
Merge pull request #229 from gridap/bugfix_in_multi_field_array
Fixed a bug in add_to_array! function in MultiFieldArray
2 parents eed1765 + ec46fba commit 3fc816a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/MultiField/MultiFieldArrays.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ function Base.show(io::IO,::MIME"text/plain",a::MultiFieldArray)
103103
end
104104

105105
function add_to_array!(a::MultiFieldArray{Ta,N},b::MultiFieldArray{Tb,N},combine=+) where {Ta,Tb,N}
106-
for k in 1:length(a.blocks)
107-
ak = a.blocks[k]
108-
bk = b.blocks[k]
106+
for coords in b.coordinates
107+
ak = a[coords...]
108+
bk = b[coords...]
109109
add_to_array!(ak,bk,combine)
110110
end
111+
a
111112
end
112113

113114
function add_to_array!(a::MultiFieldArray,b::Number,combine=+)

test/MultiFieldTests/MultiFieldArraysTests.jl

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ using Gridap.MultiField: _resize_for_mul!
99
using Gridap.MultiField: _move_cached_arrays!
1010
using Gridap.MultiField: CachedMultiFieldArray
1111

12+
B1 = 10*ones(Int,3)
13+
B2 = 20*ones(Int,5)
14+
blocks = [B1,B2]
15+
coordinates = [(1,),(2,)]
16+
b = MultiFieldArray(blocks,coordinates)
17+
18+
C1 = 1*ones(Int,3)
19+
C2 = 2*ones(Int,5)
20+
blocks = [C2]
21+
coordinates = [(2,)]
22+
c = MultiFieldArray(blocks,coordinates)
23+
24+
add_to_array!(b,c)
25+
@test b.blocks == [[10, 10, 10], [22, 22, 22, 22, 22]]
26+
1227
A11 = ones(Int,2,3)
1328
A21 = 2*ones(Int,4,3)
1429
A12 = 3*ones(Int,2,5)

0 commit comments

Comments
 (0)