Skip to content

Commit

Permalink
Merge pull request #771 from gridap/fix_issue_770
Browse files Browse the repository at this point in the history
Fixes related with 2nd order derivatives on vector-valued fields
  • Loading branch information
fverdugo committed Mar 23, 2022
2 parents edf2f90 + 4aeb153 commit e328bd0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
26 changes: 21 additions & 5 deletions src/Fields/AffineMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,29 @@ function push_∇∇(∇∇a::Field,ϕ::AffineMap)
Operation(push_∇∇)(∇∇a, Jt_inv)
end

function push_∇∇(∇∇a::Number,Jt_inv::MultiValue{Tuple{D,D}} where D)
#Jt_inv⋅Jt_inv⋅∇∇a
Jt_inv∇∇atranspose(Jt_inv)
end
#function push_∇∇(∇∇a::Number,Jt_inv::MultiValue{Tuple{D,D}} where D)
# #Jt_inv⋅Jt_inv⋅∇∇a
# Jt_inv⋅∇∇a⋅transpose(Jt_inv)
#end

function push_∇∇(∇∇a::Number,Jt_inv::MultiValue{Tuple{D1,D2}} where {D1,D2})
Jt_inv∇∇atranspose(Jt_inv)
_permdims_for_∇∇(Jt_inv_permdims_for_∇∇(∇∇a)transpose(Jt_inv))
end

function _permdims_for_∇∇(a::MultiValue{Tuple{D1,D2}}) where {D1,D2}
a
end
@generated function _permdims_for_∇∇(a::MultiValue{Tuple{D1,D2,D3}}) where {D1,D2,D3}
ss = String[]
for k in 1:D2
for j in 1:D3
for i in 1:D1
push!(ss,"a[$i,$k,$j],")
end
end
end
str = join(ss)
Meta.parse("ThirdOrderTensorValue{$D1,$D3,$D2}($str)")
end

function lazy_map(
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/FieldsInterfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ function _zero_size(a::VoidBasis{T,1} where T)
end

function _zero_size(a::VoidBasis{T,2} where T)
@check size(a,1) == 1
@check size(a,1) in (0,1)
(1,0)
end

Expand Down
12 changes: 6 additions & 6 deletions src/TensorValues/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ end
end

# a_ilm = b_ij*c_jlm
@generated function dot(a::A,b::B) where {A<:MultiValue{Tuple{D,D}},B<:ThirdOrderTensorValue{D,D,L}} where {D,L}
@generated function dot(a::A,b::B) where {A<:MultiValue{Tuple{D1,D2}},B<:ThirdOrderTensorValue{D2,D3,D4}} where {D1,D2,D3,D4}
ss = String[]
for m in 1:L
for l in 1:D
for i in 1:D
s = join([ "a[$i,$j]*b[$j,$l,$m]+" for j in 1:D])
for m in 1:D4
for l in 1:D3
for i in 1:D1
s = join([ "a[$i,$j]*b[$j,$l,$m]+" for j in 1:D2])
push!(ss,s[1:(end-1)]*", ")
end
end
end
str = join(ss)
Meta.parse("ThirdOrderTensorValue{$D,$D,$L}($str)")
Meta.parse("ThirdOrderTensorValue{$D1,$D3,$D4}($str)")
end

const ¹ = dot
Expand Down
26 changes: 26 additions & 0 deletions test/GridapTests/issue_770.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Issue770

using Gridap
using Test

domain = (0,1,0,1)
cells = (2,2)
model = CartesianDiscreteModel(domain,cells) |> simplexify
Ω = Interior(model)
= Measure(Ω,4)
m = 2
u(x) = VectorValue(sum(x)^m, sum(x)^m)
reffe = ReferenceFE(lagrangian,VectorValue{2,Float64},m)
V = FESpace(Ω,reffe)
uh = interpolate(u,V)
t = Δ(u) - Δ(uh)
@test sum((tt)dΩ) < 1.0e-12

s(x) = sum(x)^m
reffe = ReferenceFE(lagrangian,Float64,m)
V = FESpace(Ω,reffe)
sh = interpolate(s,V)
t = Δ(s) - Δ(sh)
@test sum((tt)dΩ) < 1.0e-12

end # module
2 changes: 2 additions & 0 deletions test/GridapTests/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ using Test

@time @testset "Issue760" begin include("issue_760.jl") end

@time @testset "Issue770" begin include("issue_770.jl") end

end # module

0 comments on commit e328bd0

Please sign in to comment.