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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added extension for `TikzPictures.jl`. Since PR[#1150](https://github.com/gridap/Gridap.jl/pull/1150).
- Added `eigen` function support for `TensorValue` objects. Fixes issue [#1156](https://github.com/gridap/Gridap.jl/issues/1156). Since PR[#1157](https://github.com/gridap/Gridap.jl/pull/1157).

## [0.19.4] - 2025-08-09

Expand Down
8 changes: 8 additions & 0 deletions src/TensorValues/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,14 @@ function inv(a::MultiValue{Tuple{3,3}})
TensorValue{3}(data)
end

"""
eigen(a::MultiValue{Tuple{D,D}})

Eigenvalue decomposition of a square second order tensor.
"""
eigen(a::MultiValue{Tuple{D,D}}) where D = eigen(get_array(a))
eigen(a::MultiValue) = @unreachable "eigen undefined for this tensor shape: $(size(a))"

###############################################################
# Measure
###############################################################
Expand Down
4 changes: 2 additions & 2 deletions src/TensorValues/TensorValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ import Base: adjoint
import Base: transpose
import Base: rand

import LinearAlgebra: det, inv, tr, cross, dot, norm
import LinearAlgebra: det, inv, tr, cross, dot, norm, eigen
# Reexport from LinearAlgebra (just for convenience)
export det, inv, tr, cross, dot, norm, ×, ⋅
export det, inv, tr, cross, dot, norm, eigen, ×, ⋅

import Gridap.Arrays: get_array

Expand Down
38 changes: 38 additions & 0 deletions test/TensorValuesTests/OperationsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,44 @@ t = TensorValue{2,3}(1:6...)
@test_throws ErrorException det(t)
@test_throws ErrorException inv(t)

# Test eigen function
t = TensorValue(1.0,2.0,3.0,4.0)
result = eigen(t)
expected = eigen(get_array(t))
@test result.values ≈ expected.values
@test result.vectors ≈ expected.vectors

# Test different tensor types with eigen
st = SymTensorValue(9.0,8.0,7.0,5.0,4.0,1.0)
result_st = eigen(st)
expected_st = eigen(get_array(st))
@test result_st.values ≈ expected_st.values
@test result_st.vectors ≈ expected_st.vectors

qt = SymTracelessTensorValue(9.0,8.0,7.0,5.0,4.0)
result_qt = eigen(qt)
expected_qt = eigen(get_array(qt))
@test result_qt.values ≈ expected_qt.values
@test result_qt.vectors ≈ expected_qt.vectors

# Test 1x1 case
t1 = TensorValue(5.0)
result1 = eigen(t1)
expected1 = eigen(get_array(t1))
@test result1.values ≈ expected1.values
@test result1.vectors ≈ expected1.vectors

# Test 3x3 case
t3 = TensorValue(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,10.0)
result3 = eigen(t3)
expected3 = eigen(get_array(t3))
@test result3.values ≈ expected3.values
@test result3.vectors ≈ expected3.vectors

# Test error handling for non-square matrices
t_nonsquare = TensorValue{2,3}(1:6...)
@test_throws ErrorException eigen(t_nonsquare)

# Measure

a = VectorValue(1,2,3)
Expand Down
Loading