Skip to content

Commit 9119a4e

Browse files
authored
Merge pull request #76 from MultiSimOLab/Allocs_DBC
Fixes allocations in Dirichlet boundary conditions
2 parents 0efc66e + 95cc5d8 commit 9119a4e

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/ComputationalModels/FESpaces.jl

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,48 @@ function Gridap.FESpaces.TestFESpace(model, reffe, ::NothingBC; kwargs...)
88
end
99

1010
function Gridap.FESpaces.TrialFESpace!(space::SingleFieldFESpace, bc::DirichletBC, Λ::Float64)
11-
TrialFESpace!(space, map(f -> f(Λ), bc.values))
11+
# TrialFESpace!(space, map(f -> f(Λ), bc.values))
12+
values = Vector{Any}(undef, length(bc.tags))
13+
@inbounds for i in eachindex(bc.tags)
14+
if bc.caches[i] isa Union{Vector,Float64}
15+
values[i] = bc.values[i](Λ)(0.0)
16+
else
17+
values[i] = bc.values[i](Λ)
18+
end
19+
end
20+
TrialFESpace!(space, values)
1221
## actualizar DirichletCoupling
1322
@inbounds for i in eachindex(bc.tags)
1423
if bc.caches[i] isa InterpolableBC
1524
bc.caches[i](Λ)
1625
space.dirichlet_values[bc.caches[i].caches[2]] = bc.caches[i].caches[1]
1726
end
18-
end
19-
return space
27+
end
28+
return space
2029
end
2130

2231

2332
function Gridap.FESpaces.TrialFESpace!(space::SingleFieldFESpace, bc::DirichletBC, Λ::Float64, ΔΛ::Float64)
24-
TrialFESpace!(space, map(f -> ((x) -> f(Λ)(x) - f- ΔΛ)(x)), bc.values))
33+
# TrialFESpace!(space, map(f -> ((x) -> f(Λ)(x) - f(Λ - ΔΛ)(x)), bc.values))
34+
values = Vector{Any}(undef, length(bc.tags))
35+
@inbounds for i in eachindex(bc.tags)
36+
if bc.caches[i] isa Union{Vector,Float64}
37+
values[i] = bc.values[i](Λ)(0.0) - bc.values[i](Λ - ΔΛ)(0.0)
38+
else
39+
values[i] = (x) -> bc.values[i](Λ)(x) - bc.values[i](Λ - ΔΛ)(x)
40+
end
41+
end
42+
TrialFESpace!(space, values)
43+
2544
@inbounds for i in eachindex(bc.tags)
2645
if bc.caches[i] isa InterpolableBC
2746
bc.caches[i](Λ - ΔΛ)
2847
v0 = copy(bc.caches[i].caches[1])
2948
bc.caches[i](Λ)
30-
space.dirichlet_values[bc.caches[i].caches[2]] = bc.caches[i].caches[1]-v0
49+
space.dirichlet_values[bc.caches[i].caches[2]] = bc.caches[i].caches[1] - v0
3150
end
32-
end
33-
return space
51+
end
52+
return space
3453
end
3554

3655

@@ -61,17 +80,28 @@ end
6180

6281

6382
function Gridap.FESpaces.TrialFESpace(space::SingleFieldFESpace, bc::DirichletBC, Λ::Float64=0.0)
64-
trialspace= TrialFESpace(space, map(f -> f(Λ), bc.values))
65-
@inbounds for i in eachindex(bc.tags)
83+
# trialspace= TrialFESpace(space, map(f -> f(Λ), bc.values))
84+
85+
values = Vector{Any}(undef, length(bc.tags))
86+
87+
@inbounds for i in eachindex(bc.tags)
88+
if bc.caches[i] isa Union{Vector,Float64}
89+
values[i] = bc.values[i](Λ)(0.0)
90+
else
91+
values[i] = bc.values[i](Λ)
92+
end
93+
end
94+
95+
trialspace = TrialFESpace(space, values)
96+
@inbounds for i in eachindex(bc.tags)
6697
if bc.caches[i] isa InterpolableBC
6798
bc.caches[i](Λ)
6899
trialspace.dirichlet_values[bc.caches[i].caches[2]] = bc.caches[i].caches[1]
69100
end
70-
end
71-
return trialspace
101+
end
102+
return trialspace
72103
end
73104

74-
75105
function Gridap.FESpaces.TrialFESpace(space::MultiFieldFESpace, bc::MultiFieldBC, Λ::Float64=0.0)
76106
U_ = Vector{Union{TrialFESpace,UnconstrainedFESpace}}(undef, length(space))
77107
@inbounds for (i, space) in enumerate(space.spaces)

0 commit comments

Comments
 (0)