Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes related with 2nd order derivatives on vector-valued fields #771

Merged
merged 3 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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⋅∇∇a⋅transpose(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⋅∇∇a⋅transpose(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)
dΩ = 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(∫(t⋅t)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(∫(t⋅t)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