Skip to content
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
5 changes: 5 additions & 0 deletions benchmark/TensorAlgebraBenchmarks/TensorAlgebraBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ function _δδ_λ_2D(λ::Float64)
λ)
end

A = TensorValue(1.:9...)
A = A + A' + I3

SUITE["Tensor algebra"]["δδ_μ_2d"] = @benchmarkable δᵢₖδⱼₗ2D + δᵢₗδⱼₖ2D
SUITE["Tensor algebra"]["δδ_λ_2d"] = @benchmarkable 1.0 * δᵢⱼδₖₗ2D
SUITE["Tensor algebra"]["Cofactor"] = cof(A)
SUITE["Tensor algebra"]["Det(A)Inv(A')"] = det(A)*inv(A')
2 changes: 1 addition & 1 deletion src/TensorAlgebra/Functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
Calculate the cofactor of a matrix.
"""
function cof(A::TensorValue)
return det(A)*inv(A')
0.5A×A
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,13 @@ end
@testset "sqrt" begin
A = TensorValue(1.:9...)
A = A'*A + I3
@test isapprox(sqrt(A), TensorValue(sqrt(get_array(A))), rtol=1e-14)
sqrtA = TensorValue(sqrt(get_array(A)))
@test isapprox(sqrt(A), sqrtA, rtol=1e-14)
end


@testset "cofactor" begin
A = TensorValue(1.:9...) + I3
cofA = det(A) * inv(A')
@test isapprox(cof(A), cofA)
end
12 changes: 8 additions & 4 deletions test/TestTensorAlgebra/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using HyperFEM
using Gridap
using Test

@testset "TensorAlgebra" begin

@time begin
include("TensorAlgebra.jl")
end
@time begin
include("TensorAlgebraTests.jl")
end

end
end