Skip to content

Commit fd2a682

Browse files
authored
Merge pull request #1050 from Antoinemarteau/master
Fix AttachDirichletMap type stability
2 parents 21c4751 + 6462fd0 commit fd2a682

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
### Fixed
9+
10+
- Fixed #974, an error when weak form is real but unknown vector is complex. Since PR[#1050](https://github.com/gridap/Gridap.jl/pull/1050).
11+
812
## [0.18.7] - 2024-10-8
913

1014
### Added

src/Arrays/AlgebraMaps.jl

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function evaluate!(cache,k::MulAddMap,a,b,c)
3535
setsize!(cache,size(c))
3636
d = cache.array
3737
copyto!(d,c)
38+
iszero(k.α) && isone(k.β) && return d
3839
mul!(d,a,b,k.α,k.β)
3940
d
4041
end

src/CellData/AttachDirichlet.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ function Arrays.return_cache(k::AttachDirichletMap,matvec::Tuple,vals,mask)
7070
end
7171

7272
function Arrays.evaluate!(cache,k::AttachDirichletMap,matvec::Tuple,vals,mask)
73+
mat, vec = matvec
7374
if mask
74-
mat, vec = matvec
7575
vec_with_bcs = evaluate!(cache,k.muladd,mat,vals,vec)
76-
(mat, vec_with_bcs)
7776
else
78-
matvec
77+
identity_muladd = MulAddMap(0,1)
78+
vec_with_bcs = evaluate!(cache,identity_muladd ,mat,vals,vec)
7979
end
80+
(mat, vec_with_bcs)
8081
end
8182

8283
function Arrays.return_value(k::AttachDirichletMap,mat,vals,mask)

src/Fields/ArrayBlocks.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,7 @@ function evaluate!(cache,k::MulAddMap,a::ArrayBlock,b::ArrayBlock,c::ArrayBlock)
12811281
_setsize_mul!(c1,a,b)
12821282
d = evaluate!(c2,unwrap_cached_array,c1)
12831283
copyto!(d,c)
1284+
iszero(k.α) && isone(k.β) && return d
12841285
mul!(d,a,b,k.α,k.β)
12851286
d
12861287
end
@@ -1517,4 +1518,4 @@ function Base.show(io::IO,o::ArrayBlockView)
15171518
end
15181519

15191520
LinearAlgebra.diag(a::MatrixBlockView) = view(a.array.array, diag(a.block_map))
1520-
LinearAlgebra.diag(a::MatrixBlock) = view(a.array,diag(CartesianIndices(a.array)))
1521+
LinearAlgebra.diag(a::MatrixBlock) = view(a.array,diag(CartesianIndices(a.array)))

test/GridapTests/issue_974.jl

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Gridap
2+
3+
T = ComplexF64
4+
5+
# Operator creating a linear system where the matrix and RHS are Float64 but the unknown vector is ComplexF64.
6+
domain = (0, 1, 0, 1)
7+
partition = (4, 4)
8+
model = CartesianDiscreteModel(domain, partition)
9+
10+
order = 1
11+
reffe = ReferenceFE(lagrangian, Float64, order)
12+
13+
V1 = TestFESpace(model, reffe; conformity=:H1, vector_type=Vector{T})
14+
V2 = TestFESpace(model, reffe; conformity=:H1, vector_type=Vector{T})
15+
16+
U1 = TrialFESpace(V1)
17+
U2 = TrialFESpace(V2)
18+
19+
Y = MultiFieldFESpace([V1, V2])
20+
X = MultiFieldFESpace([U1, U2])
21+
22+
degree = 2 * order
23+
Ω = Triangulation(model)
24+
= Measure(Ω, degree)
25+
26+
# Project constant 1 into both spaces.
27+
a((u1, u2), (v1, v2)) = (v1 * u1)dΩ + (v2 * u2)dΩ
28+
l((v1, v2)) = (v1 + v2)dΩ
29+
30+
op = AffineFEOperator(a, l, X, Y)
31+
uh1, uh2 = solve(op)

0 commit comments

Comments
 (0)