Skip to content
Closed
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
2 changes: 2 additions & 0 deletions benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ SUITE["Tensor algebra"]["δδ_μ_2d"] = @benchmarkable δᵢₖδⱼₗ2D + δ
SUITE["Tensor algebra"]["δδ_λ_2d"] = @benchmarkable 1.0 * δᵢⱼδₖₗ2D
SUITE["Tensor algebra"]["Cofactor"] = @benchmarkable cof(A)
SUITE["Tensor algebra"]["Det(A)Inv(A')"] = @benchmarkable det(A)*inv(A')
SUITE["Tensor algebra"]["A:A"] = @benchmarkable A:A
SUITE["Tensor algebra"]["tr(A'·A)"] = @benchmarkable tr(A'·A)
1 change: 1 addition & 0 deletions src/TensorAlgebra/Functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ end


function trAA(A::TensorValue{3, 3, T, N}) where {T, N}
@warn "The function trAA is deprecated and will be removed. Use the double contraction operator : instead." maxlog=1
return sum(A.data[i]*A.data[i] for i in 1:N)
end

Expand Down
8 changes: 8 additions & 0 deletions src/TensorAlgebra/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ function (*)(Ten1::TensorValue, Ten2::TensorValue)
end


"""
Double contraction of second order tensors, which is equivalent to tr(a'·b)
"""
function (:)(a::TensorValue{D1,D2}, b::TensorValue{D1,D2}) where {D1,D2}
sum(a.data .* b.data)
end


@generated function (+)(A::TensorValue{D,D,Float64}, B::TensorValue{D,D,Float64}) where {D}
str = ""
for i in 1:D*D
Expand Down
5 changes: 1 addition & 4 deletions src/TensorAlgebra/TensorAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ using Gridap
using Gridap.TensorValues
using StaticArrays
using LinearAlgebra
import Base: *
import Base: +
import Base: sqrt
import Base: *, +, (:), sqrt

export (*)
export (×ᵢ⁴)
export (+)
export (⊗₁₂³)
Expand Down
7 changes: 7 additions & 0 deletions test/TestTensorAlgebra/TensorAlgebraTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ end
end


@testset "double contraction" begin
A = TensorValue(1.:9...)
@test A:A == tr(A'·A)
@test A:A == sum(i -> i^2, 1:9)
end


@testset "sqrt" begin
A = TensorValue(1.:9...)
A = A'*A + I3
Expand Down