From 3692737f5b601396e0d81bf41bfbd54db0c33762 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Wed, 16 Oct 2024 04:57:03 +0000 Subject: [PATCH] build based on fe5e478 --- dev/.documenter-siteinfo.json | 2 +- dev/Automatic differentiation/index.html | 4 +-- dev/Benchmarks/index.html | 4 +-- dev/Broadcast/index.html | 2 +- dev/Cheat Sheet/index.html | 2 +- dev/Constructors/index.html | 2 +- dev/Continuum Mechanics/index.html | 20 ++++++------- dev/Einstein summation/index.html | 2 +- dev/Quaternion/index.html | 8 ++--- dev/Tensor Inversion/index.html | 4 +-- dev/Tensor Operations/index.html | 38 ++++++++++++------------ dev/Tensor Type/index.html | 2 +- dev/Voigt form/index.html | 6 ++-- dev/index.html | 2 +- dev/search_index.js | 2 +- 15 files changed, 50 insertions(+), 50 deletions(-) diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 46a2019..9259f12 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.0","generation_timestamp":"2024-10-16T03:31:39","documenter_version":"1.7.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.0","generation_timestamp":"2024-10-16T04:56:58","documenter_version":"1.7.0"}} \ No newline at end of file diff --git a/dev/Automatic differentiation/index.html b/dev/Automatic differentiation/index.html index 5273d45..d524bfe 100644 --- a/dev/Automatic differentiation/index.html +++ b/dev/Automatic differentiation/index.html @@ -13,7 +13,7 @@ 0.0 0.0 1.0 julia> ∇f, f = gradient(tr, x, :all) -([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0], 1.1733382401532275)source
Tensorial.hessianMethod
hessian(f, x)
+([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0], 1.1733382401532275)
source
Tensorial.hessianMethod
hessian(f, x)
 hessian(f, x, :all)

Compute the hessian of f with respect to x by the automatic differentiation. If pseudo keyword :all is given, the value of f(x) is also returned.

Examples

julia> x = rand(Vec{3})
 3-element Vec{3, Float64}:
  0.32597672886359486
@@ -27,4 +27,4 @@
  -0.231782  -0.390397   1.32626
 
 julia> ∇∇f, ∇f, f = hessian(norm, x, :all)
-([1.1360324375454411 -0.5821964220304534 -0.23178236037013888; -0.5821964220304533 0.5010791569244991 -0.39039709608344814; -0.23178236037013886 -0.39039709608344814 1.3262640626479867], [0.4829957515506539, 0.8135223859352438, 0.3238771859304809], 0.6749059962060727)
source
+([1.1360324375454411 -0.5821964220304534 -0.23178236037013888; -0.5821964220304533 0.5010791569244991 -0.39039709608344814; -0.23178236037013886 -0.39039709608344814 1.3262640626479867], [0.4829957515506539, 0.8135223859352438, 0.3238771859304809], 0.6749059962060727)source diff --git a/dev/Benchmarks/index.html b/dev/Benchmarks/index.html index ab79667..5dea1e6 100644 --- a/dev/Benchmarks/index.html +++ b/dev/Benchmarks/index.html @@ -4,7 +4,7 @@ S = rand(SymmetricSecondOrderTensor{3}) B = rand(Tensor{Tuple{3,3,3}}) AA = rand(FourthOrderTensor{3}) -SS = rand(SymmetricFourthOrderTensor{3})
OperationTensorArrayspeed-up
Single contraction
a ⋅ a2.785 ns9.256 ns×3.3
A ⋅ a3.095 ns53.999 ns×17.4
S ⋅ a3.396 ns53.775 ns×15.8
Double contraction
A ⊡ A3.406 ns11.422 ns×3.4
S ⊡ S3.095 ns11.422 ns×3.7
B ⊡ A5.410 ns128.613 ns×23.8
AA ⊡ A7.732 ns144.599 ns×18.7
SS ⊡ S15.719 ns152.234 ns×9.7
Tensor product
a ⊗ a3.716 ns33.597 ns×9.0
Cross product
a × a3.716 ns33.597 ns×9.0
Determinant
det(A)3.406 ns170.710 ns×50.1
det(S)3.406 ns169.943 ns×49.9
Inverse
inv(A)5.931 ns478.118 ns×80.6
inv(S)12.032 ns472.719 ns×39.3
inv(AA)964.143 ns1.531 μs×1.6
inv(SS)357.154 ns1.529 μs×4.3

The benchmarks are generated by runbenchmarks.jl on the following system:

julia> versioninfo()
+SS = rand(SymmetricFourthOrderTensor{3})
OperationTensorArrayspeed-up
Single contraction
a ⋅ a3.095 ns9.256 ns×3.0
A ⋅ a3.396 ns53.634 ns×15.8
S ⋅ a3.706 ns53.512 ns×14.4
Double contraction
A ⊡ A3.706 ns11.422 ns×3.1
S ⊡ S3.396 ns11.422 ns×3.4
B ⊡ A5.420 ns122.123 ns×22.5
AA ⊡ A7.732 ns143.526 ns×18.6
SS ⊡ S4.197 ns146.164 ns×34.8
Tensor product
a ⊗ a3.406 ns33.150 ns×9.7
Cross product
a × a3.406 ns33.150 ns×9.7
Determinant
det(A)3.406 ns175.817 ns×51.6
det(S)3.406 ns180.956 ns×53.1
Inverse
inv(A)6.001 ns479.621 ns×79.9
inv(S)5.250 ns484.469 ns×92.3
inv(AA)958.182 ns1.521 μs×1.6
inv(SS)363.676 ns1.530 μs×4.2

The benchmarks are generated by runbenchmarks.jl on the following system:

julia> versioninfo()
 Julia Version 1.11.0
 Commit 501a4f25c2b (2024-10-07 11:40 UTC)
 Build Info:
@@ -15,4 +15,4 @@
   WORD_SIZE: 64
   LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
 Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
-
+ diff --git a/dev/Broadcast/index.html b/dev/Broadcast/index.html index 8227d90..4f1acad 100644 --- a/dev/Broadcast/index.html +++ b/dev/Broadcast/index.html @@ -46,4 +46,4 @@ 3-element Vec{3, Int64}: 3 5 - 7 + 7 diff --git a/dev/Cheat Sheet/index.html b/dev/Cheat Sheet/index.html index a8b3608..bd6abaa 100644 --- a/dev/Cheat Sheet/index.html +++ b/dev/Cheat Sheet/index.html @@ -121,4 +121,4 @@ const SecondOrderTensor{dim, T, L} = Tensor{NTuple{2, dim}, T, 2, L} const FourthOrderTensor{dim, T, L} = Tensor{NTuple{4, dim}, T, 4, L} const SymmetricSecondOrderTensor{dim, T, L} = Tensor{Tuple{@Symmetry{dim, dim}}, T, 2, L} -const SymmetricFourthOrderTensor{dim, T, L} = Tensor{NTuple{2, @Symmetry{dim, dim}}, T, 4, L} +const SymmetricFourthOrderTensor{dim, T, L} = Tensor{NTuple{2, @Symmetry{dim, dim}}, T, 4, L} diff --git a/dev/Constructors/index.html b/dev/Constructors/index.html index 114ead1..49edbc6 100644 --- a/dev/Constructors/index.html +++ b/dev/Constructors/index.html @@ -121,4 +121,4 @@ [:, :, 3] = 0 1 0 -1 0 0 - 0 0 0source + 0 0 0source diff --git a/dev/Continuum Mechanics/index.html b/dev/Continuum Mechanics/index.html index a771866..3147528 100644 --- a/dev/Continuum Mechanics/index.html +++ b/dev/Continuum Mechanics/index.html @@ -7,14 +7,14 @@ 0.218587 0.394255 0.49425 julia> mean(x) -0.3911127467177425source
Tensorial.vonmisesFunction
vonmises(::AbstractSymmetricSecondOrderTensor{3})

Compute the von Mises stress.

\[q = \sqrt{\frac{3}{2} \mathrm{dev}(\bm{\sigma}) : \mathrm{dev}(\bm{\sigma})} = \sqrt{3J_2}\]

Examples

julia> σ = rand(SymmetricSecondOrderTensor{3})
+0.3911127467177425
source
Tensorial.vonmisesFunction
vonmises(::AbstractSymmetricSecondOrderTensor{3})

Compute the von Mises stress.

\[q = \sqrt{\frac{3}{2} \mathrm{dev}(\bm{\sigma}) : \mathrm{dev}(\bm{\sigma})} = \sqrt{3J_2}\]

Examples

julia> σ = rand(SymmetricSecondOrderTensor{3})
 3×3 SymmetricSecondOrderTensor{3, Float64, 6}:
  0.325977  0.549051  0.218587
  0.549051  0.894245  0.353112
  0.218587  0.353112  0.394255
 
 julia> vonmises(σ)
-1.3078860814690232
source

Deviatoric–volumetric additive split

Tensorial.volFunction
vol(::AbstractSecondOrderTensor{3})
+1.3078860814690232
source

Deviatoric–volumetric additive split

Tensorial.volFunction
vol(::AbstractSecondOrderTensor{3})
 vol(::AbstractSymmetricSecondOrderTensor{3})

Compute the volumetric part of a square tensor. This is only available in 3D.

Examples

julia> x = rand(Mat{3,3})
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.325977  0.894245  0.953125
@@ -28,7 +28,7 @@
  0.0       0.0       0.391113
 
 julia> vol(x) + dev(x) ≈ x
-true
source
vol(::AbstractVec{3})

Compute the volumetric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.

Examples

julia> x = rand(Vec{3})
+true
source
vol(::AbstractVec{3})

Compute the volumetric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.

Examples

julia> x = rand(Vec{3})
 3-element Vec{3, Float64}:
  0.32597672886359486
  0.5490511363155669
@@ -41,7 +41,7 @@
  0.3645381733326641
 
 julia> vol(x) + dev(x) ≈ x
-true
source
vol(::Type{FourthOrderTensor{3}})
+true
source
vol(::Type{FourthOrderTensor{3}})
 vol(::Type{SymmetricFourthOrderTensor{3}})

Construct volumetric fourth order identity tensor. This is only available in 3D.

Examples

julia> x = rand(Mat{3,3});
 
 julia> I_vol = vol(FourthOrderTensor{3});
@@ -50,7 +50,7 @@
 true
 
 julia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})
-true
source
Tensorial.devFunction
dev(::AbstractSecondOrderTensor{3})
+true
source
Tensorial.devFunction
dev(::AbstractSecondOrderTensor{3})
 dev(::AbstractSymmetricSecondOrderTensor{3})

Compute the deviatoric part of a square tensor. This is only available in 3D.

Examples

julia> x = rand(Mat{3,3})
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.325977  0.894245  0.953125
@@ -64,7 +64,7 @@
   0.218587   0.394255   0.103137
 
 julia> tr(dev(x))
-5.551115123125783e-17
source
dev(::AbstractVec{3})

Compute the deviatoric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.

Examples

julia> x = rand(Vec{3})
+5.551115123125783e-17
source
dev(::AbstractVec{3})

Compute the deviatoric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.

Examples

julia> x = rand(Vec{3})
 3-element Vec{3, Float64}:
  0.32597672886359486
  0.5490511363155669
@@ -77,7 +77,7 @@
  -0.14595151851383342
 
 julia> vol(x) + dev(x) ≈ x
-true
source
dev(::Type{FourthOrderTensor{3}})
+true
source
dev(::Type{FourthOrderTensor{3}})
 dev(::Type{SymmetricFourthOrderTensor{3}})

Construct deviatoric fourth order identity tensor. This is only available in 3D.

Examples

julia> x = rand(Mat{3,3});
 
 julia> I_dev = dev(FourthOrderTensor{3});
@@ -86,7 +86,7 @@
 true
 
 julia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})
-true
source

Stress invariants

Tensorial.stress_invariantsFunction
stress_invariants(::AbstractSecondOrderTensor{3})
+true
source

Stress invariants

Tensorial.stress_invariantsFunction
stress_invariants(::AbstractSecondOrderTensor{3})
 stress_invariants(::AbstractSymmetricSecondOrderTensor{3})
 stress_invariants(::Vec{3})

Return a tuple storing stress invariants.

\[\begin{aligned} I_1(\bm{\sigma}) &= \mathrm{tr}(\bm{\sigma}) \\ @@ -99,7 +99,7 @@ 0.218587 0.353112 0.394255 julia> I₁, I₂, I₃ = stress_invariants(σ) -(1.6144775244804341, 0.2986572249840249, -0.0025393241133506677)

source
Tensorial.deviatoric_stress_invariantsFunction
deviatoric_stress_invariants(::AbstractSecondOrderTensor{3})
+(1.6144775244804341, 0.2986572249840249, -0.0025393241133506677)
source
Tensorial.deviatoric_stress_invariantsFunction
deviatoric_stress_invariants(::AbstractSecondOrderTensor{3})
 deviatoric_stress_invariants(::AbstractSymmetricSecondOrderTensor{3})
 deviatoric_stress_invariants(::Vec{3})

Return a tuple storing deviatoric stress invariants.

\[\begin{aligned} J_1(\bm{\sigma}) &= \mathrm{tr}(\mathrm{dev}(\bm{\sigma})) = 0 \\ @@ -112,4 +112,4 @@ 0.218587 0.353112 0.394255 julia> J₁, J₂, J₃ = deviatoric_stress_invariants(σ) -(0.0, 0.5701886673667987, 0.14845380911930367)

source
+(0.0, 0.5701886673667987, 0.14845380911930367)source diff --git a/dev/Einstein summation/index.html b/dev/Einstein summation/index.html index e700e96..6d657fb 100644 --- a/dev/Einstein summation/index.html +++ b/dev/Einstein summation/index.html @@ -14,4 +14,4 @@ true julia> (@einsum SymmetricSecondOrderTensor{3} A[k,i] * A[k,j]) ≈ A' ⋅ A -truesource +truesource diff --git a/dev/Quaternion/index.html b/dev/Quaternion/index.html index 75c1ea6..c3070fa 100644 --- a/dev/Quaternion/index.html +++ b/dev/Quaternion/index.html @@ -6,7 +6,7 @@ 1 + 0𝙞 + 0𝙟 + 0𝙠 julia> Quaternion(Vec(1,2,3)) -0 + 1𝙞 + 2𝙟 + 3𝙠

See also quaternion.

Note

Quaternion is experimental and could change or disappear in future versions of Tensorial.

source
Base.expMethod
exp(::Quaternion)

Compute the exponential of quaternion as

\[\exp(q) = e^{q_w} \left( \cos\| \bm{v} \| + \frac{\bm{v}}{\| \bm{v} \|} \sin\| \bm{v} \| \right)\]

source
Base.logMethod
log(::Quaternion)

Compute the logarithm of quaternion as

\[\ln(q) = \ln\| q \| + \frac{\bm{v}}{\| \bm{v} \|} \arccos\frac{q_w}{\| q \|}\]

source
Tensorial.quaternionMethod
quaternion(θ, n::Vec; normalize = true)

Construct Quaternion from angle θ and axis n as

\[q = \cos\frac{\theta}{2} + \bm{n} \sin\frac{\theta}{2}\]

The constructed quaternion is normalized such as norm(q) ≈ 1 by default.

Examples

julia> q = quaternion(π/4, Vec(0,0,1))
+0 + 1𝙞 + 2𝙟 + 3𝙠

See also quaternion.

Note

Quaternion is experimental and could change or disappear in future versions of Tensorial.

source
Base.expMethod
exp(::Quaternion)

Compute the exponential of quaternion as

\[\exp(q) = e^{q_w} \left( \cos\| \bm{v} \| + \frac{\bm{v}}{\| \bm{v} \|} \sin\| \bm{v} \| \right)\]

source
Base.logMethod
log(::Quaternion)

Compute the logarithm of quaternion as

\[\ln(q) = \ln\| q \| + \frac{\bm{v}}{\| \bm{v} \|} \arccos\frac{q_w}{\| q \|}\]

source
Tensorial.quaternionMethod
quaternion(θ, n::Vec; normalize = true)

Construct Quaternion from angle θ and axis n as

\[q = \cos\frac{\theta}{2} + \bm{n} \sin\frac{\theta}{2}\]

The constructed quaternion is normalized such as norm(q) ≈ 1 by default.

Examples

julia> q = quaternion(π/4, Vec(0,0,1))
 0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠
 
 julia> x = rand(Vec{3})
@@ -16,7 +16,7 @@
  0.21858665481883066
 
 julia> (q * x / q).vector ≈ rotmatz(π/4) ⋅ x
-true
source
Tensorial.rotateMethod
rotate(x::Vec, q::Quaternion)

Rotate x by quaternion q.

Examples

julia> v = Vec(1.0, 0.0, 0.0)
+true
source
Tensorial.rotateMethod
rotate(x::Vec, q::Quaternion)

Rotate x by quaternion q.

Examples

julia> v = Vec(1.0, 0.0, 0.0)
 3-element Vec{3, Float64}:
  1.0
  0.0
@@ -26,11 +26,11 @@
 3-element Vec{3, Float64}:
  0.7071067811865475
  0.7071067811865476
- 0.0
source
Tensorial.rotmatMethod
rotmat(::Quaternion)

Construct rotation matrix from quaternion.

Examples

julia> q = quaternion(π/4, Vec(0,0,1))
+ 0.0
source
Tensorial.rotmatMethod
rotmat(::Quaternion)

Construct rotation matrix from quaternion.

Examples

julia> q = quaternion(π/4, Vec(0,0,1))
 0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠
 
 julia> rotmat(q)
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.707107  -0.707107  0.0
  0.707107   0.707107  0.0
- 0.0        0.0       1.0
source
+ 0.0 0.0 1.0source diff --git a/dev/Tensor Inversion/index.html b/dev/Tensor Inversion/index.html index 5cfde1e..9203554 100644 --- a/dev/Tensor Inversion/index.html +++ b/dev/Tensor Inversion/index.html @@ -15,8 +15,8 @@ 588.35 282.819 -1587.79 julia> x ⋅ inv(x) ≈ one(I) -truesource
Tensorial.adjFunction
adj(::AbstractSecondOrderTensor)
+true
source
Tensorial.adjFunction
adj(::AbstractSecondOrderTensor)
 adj(::AbstractSymmetricSecondOrderTensor)

Compute the adjugate matrix.

Examples

julia> x = rand(Mat{3,3});
 
 julia> Tensorial.adj(x) / det(x) ≈ inv(x)
-true
source
+truesource diff --git a/dev/Tensor Operations/index.html b/dev/Tensor Operations/index.html index b41bce3..715499d 100644 --- a/dev/Tensor Operations/index.html +++ b/dev/Tensor Operations/index.html @@ -1,5 +1,5 @@ -Tensor Operations · Tensorial.jl

Tensor Operations

LinearAlgebra.crossMethod
cross(x::Vec{3}, y::Vec{3}) -> Vec{3}
+Tensor Operations · Tensorial.jl

Tensor Operations

LinearAlgebra.crossMethod
cross(x::Vec{3}, y::Vec{3}) -> Vec{3}
 cross(x::Vec{2}, y::Vec{2}) -> Vec{3}
 cross(x::Vec{1}, y::Vec{1}) -> Vec{3}
 x × y

Compute the cross product between two vectors. The vectors are expanded to 3D frist for dimensions 1 and 2. The infix operator × (written \times) can also be used. x × y (where × can be typed by \times<tab>) is a synonym for cross(x, y).

Examples

julia> x = rand(Vec{3})
@@ -18,7 +18,7 @@
 3-element Vec{3, Float64}:
   0.13928086435138393
   0.0669520417303531
- -0.37588028973385323
source
LinearAlgebra.dotMethod
dot(x::AbstractTensor, y::AbstractTensor)
 x ⋅ y

Compute dot product such as $a = x_i y_i$. This is equivalent to contract(::AbstractTensor, ::AbstractTensor, Val(1)). x ⋅ y (where can be typed by \cdot<tab>) is a synonym for dot(x, y).

Examples

julia> x = rand(Vec{3})
 3-element Vec{3, Float64}:
  0.32597672886359486
@@ -32,14 +32,14 @@
  0.39425536741585077
 
 julia> a = x ⋅ y
-0.5715585109976284
source
LinearAlgebra.normMethod
norm(::AbstractTensor)

Compute norm of a tensor.

Examples

julia> x = rand(Mat{3, 3})
+0.5715585109976284
source
LinearAlgebra.normMethod
norm(::AbstractTensor)

Compute norm of a tensor.

Examples

julia> x = rand(Mat{3, 3})
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.325977  0.894245  0.953125
  0.549051  0.353112  0.795547
  0.218587  0.394255  0.49425
 
 julia> norm(x)
-1.8223398556552728
source
LinearAlgebra.trMethod
tr(::AbstractSecondOrderTensor)
 tr(::AbstractSymmetricSecondOrderTensor)

Compute the trace of a square tensor.

Examples

julia> x = rand(Mat{3,3})
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.325977  0.894245  0.953125
@@ -47,7 +47,7 @@
  0.218587  0.394255  0.49425
 
 julia> tr(x)
-1.1733382401532275
source
Tensorial.contractMethod
contract(::AbstractTensor, ::AbstractTensor, ::Val{N})

Conduct contraction of N inner indices. For example, N=2 contraction for third-order tensors $A_{ij} = B_{ikl} C_{klj}$ can be computed as follows:

julia> B = rand(Tensor{Tuple{3,3,3}});
+1.1733382401532275
source
Tensorial.contractMethod
contract(::AbstractTensor, ::AbstractTensor, ::Val{N})

Conduct contraction of N inner indices. For example, N=2 contraction for third-order tensors $A_{ij} = B_{ikl} C_{klj}$ can be computed as follows:

julia> B = rand(Tensor{Tuple{3,3,3}});
 
 julia> C = rand(Tensor{Tuple{3,3,3}});
 
@@ -55,10 +55,10 @@
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  3.70978  2.47156  3.91807
  2.90966  2.30881  3.25965
- 1.78391  1.38714  2.2079

Following symbols are also available for specific contractions:

  • x ⊗ y (where can be typed by \otimes<tab>): contract(x, y, Val(0))
  • x ⋅ y (where can be typed by \cdot<tab>): contract(x, y, Val(1))
  • x ⊡ y (where can be typed by \boxdot<tab>): contract(x, y, Val(2))
source
Tensorial.minorsymmetricMethod
minorsymmetric(::AbstractFourthOrderTensor) -> SymmetricFourthOrderTensor

Compute the minor symmetric part of a fourth order tensor.

Examples

julia> x = rand(Tensor{Tuple{3,3,3,3}});
+ 1.78391  1.38714  2.2079

Following symbols are also available for specific contractions:

  • x ⊗ y (where can be typed by \otimes<tab>): contract(x, y, Val(0))
  • x ⋅ y (where can be typed by \cdot<tab>): contract(x, y, Val(1))
  • x ⊡ y (where can be typed by \boxdot<tab>): contract(x, y, Val(2))
source
Tensorial.minorsymmetricMethod
minorsymmetric(::AbstractFourthOrderTensor) -> SymmetricFourthOrderTensor

Compute the minor symmetric part of a fourth order tensor.

Examples

julia> x = rand(Tensor{Tuple{3,3,3,3}});
 
 julia> minorsymmetric(x) ≈ @einsum (i,j,k,l) -> (x[i,j,k,l] + x[j,i,k,l] + x[i,j,l,k] + x[j,i,l,k]) / 4
-true
source
Tensorial.otimesMethod
otimes(x::AbstractTensor, y::AbstractTensor)
 x ⊗ y

Compute tensor product such as $A_{ij} = x_i y_j$. x ⊗ y (where can be typed by \otimes<tab>) is a synonym for otimes(x, y).

Examples

julia> x = rand(Vec{3})
 3-element Vec{3, Float64}:
  0.32597672886359486
@@ -75,7 +75,7 @@
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.291503  0.115106   0.128518
  0.490986  0.193876   0.216466
- 0.19547   0.0771855  0.086179
source
Tensorial.rotateMethod
rotate(x::Vec, R::SecondOrderTensor)
 rotate(x::SecondOrderTensor, R::SecondOrderTensor)
 rotate(x::SymmetricSecondOrderTensor, R::SecondOrderTensor)

Rotate x by rotation matrix R. This function can hold the symmetry of SymmetricSecondOrderTensor.

Examples

julia> A = rand(SymmetricSecondOrderTensor{3})
 3×3 SymmetricSecondOrderTensor{3, Float64, 6}:
@@ -99,7 +99,7 @@
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
   0.0610599  -0.284134  -0.0951235
  -0.284134    1.15916    0.404252
- -0.0951235   0.404252   0.394255
source
Tensorial.rotmatMethod
rotmat(θ, n::Vec)

Construct rotation matrix from angle θ and axis n.

Examples

julia> x = Vec(1.0, 0.0, 0.0)
+ -0.0951235   0.404252   0.394255
source
Tensorial.rotmatMethod
rotmat(θ, n::Vec)

Construct rotation matrix from angle θ and axis n.

Examples

julia> x = Vec(1.0, 0.0, 0.0)
 3-element Vec{3, Float64}:
  1.0
  0.0
@@ -115,13 +115,13 @@
 3-element Vec{3, Float64}:
  6.123233995736766e-17
  1.0
- 0.0
source
Tensorial.rotmatMethod
rotmat(θ::Number)

Construct 2D rotation matrix.

\[\bm{R} = \begin{bmatrix} + 0.0

source
Tensorial.rotmatMethod
rotmat(θ::Number)

Construct 2D rotation matrix.

\[\bm{R} = \begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \end{bmatrix}\]

Examples

julia> rotmat(deg2rad(30))
 2×2 Tensor{Tuple{2, 2}, Float64, 2, 4}:
  0.866025  -0.5
- 0.5        0.866025
source
Tensorial.rotmatMethod
rotmat(θ::Vec{3}; sequence::Symbol)

Convert Euler angles to rotation matrix. Use 3 characters belonging to the set (X, Y, Z) for intrinsic rotations, or (x, y, z) for extrinsic rotations.

Examples

julia> α, β, γ = map(deg2rad, rand(3));
+ 0.5        0.866025
source
Tensorial.rotmatMethod
rotmat(θ::Vec{3}; sequence::Symbol)

Convert Euler angles to rotation matrix. Use 3 characters belonging to the set (X, Y, Z) for intrinsic rotations, or (x, y, z) for extrinsic rotations.

Examples

julia> α, β, γ = map(deg2rad, rand(3));
 
 julia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmatx(α) ⋅ rotmaty(β) ⋅ rotmatz(γ)
 true
@@ -130,7 +130,7 @@
 true
 
 julia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmat(Vec(γ,β,α), sequence = :zyx)
-true
source
Tensorial.rotmatMethod
rotmat(a => b)

Construct rotation matrix rotating vector a to b. The norms of two vectors must be the same.

Examples

julia> a = normalize(rand(Vec{3}))
+true
source
Tensorial.rotmatMethod
rotmat(a => b)

Construct rotation matrix rotating vector a to b. The norms of two vectors must be the same.

Examples

julia> a = normalize(rand(Vec{3}))
 3-element Vec{3, Float64}:
  0.4829957515506539
  0.8135223859352438
@@ -149,20 +149,20 @@
   0.520617     0.446905  -0.727485
 
 julia> R ⋅ a ≈ b
-true
source
Tensorial.rotmatxMethod
rotmatx(θ::Number)

Construct rotation matrix around x axis.

\[\bm{R}_x = \begin{bmatrix} +true

source
Tensorial.rotmatxMethod
rotmatx(θ::Number)

Construct rotation matrix around x axis.

\[\bm{R}_x = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos{\theta} & -\sin{\theta} \\ 0 & \sin{\theta} & \cos{\theta} -\end{bmatrix}\]

source
Tensorial.rotmatyMethod
rotmaty(θ::Number)

Construct rotation matrix around y axis.

\[\bm{R}_y = \begin{bmatrix} +\end{bmatrix}\]

source
Tensorial.rotmatyMethod
rotmaty(θ::Number)

Construct rotation matrix around y axis.

\[\bm{R}_y = \begin{bmatrix} \cos{\theta} & 0 & \sin{\theta} \\ 0 & 1 & 0 \\ -\sin{\theta} & 0 & \cos{\theta} -\end{bmatrix}\]

source
Tensorial.rotmatzMethod
rotmatz(θ::Number)

Construct rotation matrix around z axis.

\[\bm{R}_z = \begin{bmatrix} +\end{bmatrix}\]

source
Tensorial.rotmatzMethod
rotmatz(θ::Number)

Construct rotation matrix around z axis.

\[\bm{R}_z = \begin{bmatrix} \cos{\theta} & -\sin{\theta} & 0 \\ \sin{\theta} & \cos{\theta} & 0 \\ 0 & 0 & 1 -\end{bmatrix}\]

source
Tensorial.skewMethod
skew(::AbstractSecondOrderTensor)
-skew(::AbstractSymmetricSecondOrderTensor)

Compute skew-symmetric (anti-symmetric) part of a second order tensor.

source
Tensorial.skewMethod
skew(ω::Vec{3})

Construct a skew-symmetric (anti-symmetric) tensor W from a vector ω as

\[\bm{\omega} = \begin{Bmatrix} +\end{bmatrix}\]

source
Tensorial.skewMethod
skew(::AbstractSecondOrderTensor)
+skew(::AbstractSymmetricSecondOrderTensor)

Compute skew-symmetric (anti-symmetric) part of a second order tensor.

source
Tensorial.skewMethod
skew(ω::Vec{3})

Construct a skew-symmetric (anti-symmetric) tensor W from a vector ω as

\[\bm{\omega} = \begin{Bmatrix} \omega_1 \\ \omega_2 \\ \omega_3 @@ -175,7 +175,7 @@ 3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}: 0 -3 2 3 0 -1 - -2 1 0

source
Tensorial.symmetricMethod
symmetric(::AbstractSecondOrderTensor)
 symmetric(::AbstractSecondOrderTensor, uplo)

Compute the symmetric part of a second order tensor.

Examples

julia> x = rand(Mat{3,3})
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  0.325977  0.894245  0.953125
@@ -192,4 +192,4 @@
 3×3 SymmetricSecondOrderTensor{3, Float64, 6}:
  0.325977  0.894245  0.953125
  0.894245  0.353112  0.795547
- 0.953125  0.795547  0.49425
source
+ 0.953125 0.795547 0.49425source diff --git a/dev/Tensor Type/index.html b/dev/Tensor Type/index.html index 66b93e3..457a351 100644 --- a/dev/Tensor Type/index.html +++ b/dev/Tensor Type/index.html @@ -1,2 +1,2 @@ -Tensor type · Tensorial.jl

Tensor type

Type parameters

All tensors in Tensorial.jl are represented by the type Tensor{S, T, N, L}, where each type parameter represents the following:

  • S: The size of Tensors which is specified by using Tuple (e.g., 3x2 tensor becomes Tensor{Tuple{3,2}}).
  • T: The type of element which must be T <: Real.
  • N: The number of dimensions (the order of tensor).
  • L: The number of independent components.

Basically, the type parameters N and L do not need to be specified for constructing tensors because it can be inferred from the size of tensor S.

Symmetry

Specifying the symmetry of a tensor can improve performance, as Tensorial.jl provides optimized computations for symmetric tensors. Symmetries can be applied using Symmetry in the type parameter S (e.g., Symmetry{Tuple{3,3}}). The @Symmetry macro simplifies this process by allowing you to omit Tuple, as in @Symmetry{2,2}. Below are some examples of how to specify symmetries:

  • $A_{(ij)}$ with 3x3: Tensor{Tuple{@Symmetry{3,3}}}
  • $A_{(ij)k}$ with 3x3x2: Tensor{Tuple{@Symmetry{3,3}, 2}}
  • $A_{(ijk)}$ with 3x3x3: Tensor{Tuple{@Symmetry{3,3,3}}}
  • $A_{(ij)(kl)}$ with 3x3x3x3: Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}

where the bracket $()$ in indices denotes the symmetry.

+Tensor type · Tensorial.jl

Tensor type

Type parameters

All tensors in Tensorial.jl are represented by the type Tensor{S, T, N, L}, where each type parameter represents the following:

  • S: The size of Tensors which is specified by using Tuple (e.g., 3x2 tensor becomes Tensor{Tuple{3,2}}).
  • T: The type of element which must be T <: Real.
  • N: The number of dimensions (the order of tensor).
  • L: The number of independent components.

Basically, the type parameters N and L do not need to be specified for constructing tensors because it can be inferred from the size of tensor S.

Symmetry

Specifying the symmetry of a tensor can improve performance, as Tensorial.jl provides optimized computations for symmetric tensors. Symmetries can be applied using Symmetry in the type parameter S (e.g., Symmetry{Tuple{3,3}}). The @Symmetry macro simplifies this process by allowing you to omit Tuple, as in @Symmetry{2,2}. Below are some examples of how to specify symmetries:

  • $A_{(ij)}$ with 3x3: Tensor{Tuple{@Symmetry{3,3}}}
  • $A_{(ij)k}$ with 3x3x2: Tensor{Tuple{@Symmetry{3,3}, 2}}
  • $A_{(ijk)}$ with 3x3x3: Tensor{Tuple{@Symmetry{3,3,3}}}
  • $A_{(ij)(kl)}$ with 3x3x3x3: Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}

where the bracket $()$ in indices denotes the symmetry.

diff --git a/dev/Voigt form/index.html b/dev/Voigt form/index.html index c69e296..c9d5162 100644 --- a/dev/Voigt form/index.html +++ b/dev/Voigt form/index.html @@ -1,5 +1,5 @@ -Voigt Form · Tensorial.jl

Voigt Form

Tensorial.frommandelMethod
frommandel(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T})

Create a tensor of type S from Mandel form. This is equivalent to fromvoigt(S, A, offdiagscale = √2).

See also fromvoigt.

source
Tensorial.fromvoigtFunction
fromvoigt(S::Type{<: Union{SecondOrderTensor, FourthOrderTensor}}, A::AbstractArray{T}; [order])
+Voigt Form · Tensorial.jl

Voigt Form

Tensorial.frommandelMethod
frommandel(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T})

Create a tensor of type S from Mandel form. This is equivalent to fromvoigt(S, A, offdiagscale = √2).

See also fromvoigt.

source
Tensorial.fromvoigtFunction
fromvoigt(S::Type{<: Union{SecondOrderTensor, FourthOrderTensor}}, A::AbstractArray{T}; [order])
 fromvoigt(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T}; [order, offdiagscale])

Converts an array A stored in Voigt format to a Tensor of type S.

Keyword arguments:

  • offdiagscale: Determines the scaling factor for the offdiagonal elements.
  • order: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.
Note

Since offdiagscale is the scaling factor for the offdiagonal elements in Voigt form, they are multiplied by 1/offdiagscale in fromvoigt unlike tovoigt. Thus fromvoigt(tovoigt(x, offdiagscale = 2), offdiagscale = 2) returns original x.

See also tovoigt.

Examples

julia> fromvoigt(Mat{3,3}, 1.0:1.0:9.0)
 3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:
  1.0  6.0  5.0
@@ -13,7 +13,7 @@
 3×3 SymmetricSecondOrderTensor{3, Float64, 6}:
  1.0  2.0  2.5
  2.0  2.0  3.0
- 2.5  3.0  3.0
source
Tensorial.tomandelMethod
tomandel(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor})

Convert a tensor to Mandel form which is equivalent to tovoigt(A, offdiagscale = √2).

See also tovoigt.

source
Tensorial.tomandelMethod
tomandel(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor})

Convert a tensor to Mandel form which is equivalent to tovoigt(A, offdiagscale = √2).

See also tovoigt.

source
Tensorial.tovoigtFunction
tovoigt(A::Union{SecondOrderTensor, FourthOrderTensor}; [order])
 tovoigt(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}; [order, offdiagonal])

Convert a tensor to Voigt form.

Keyword arguments:

  • offdiagscale: Determines the scaling factor for the offdiagonal elements.
  • order: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.

See also fromvoigt.

Examples

julia> x = Mat{3,3}(1:9...)
 3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}:
  1  4  7
@@ -46,4 +46,4 @@
   6
   4
   6
- 10
source
+ 10
source
diff --git a/dev/index.html b/dev/index.html index e3cc5cd..b358e75 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · Tensorial.jl

Tensorial

Introduction

Tensorial provides useful tensor operations, such as contraction, tensor product (), and inversion (inv), implemented in the Julia programming language. The library supports tensors of arbitrary size, including both symmetric and non-symmetric tensors, where symmetries can be specified to avoid redundant computations. The approach for defining the size of a tensor is similar to that used in StaticArrays.jl, and tensor symmetries can be specified using the @Symmetry macro. For instance, a symmetric fourth-order tensor (a symmetrized tensor) is represented in this library as Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}. The library also includes an Einstein summation macro @einsum and functions for automatic differentiation, such as gradient and hessian.

Installation

pkg> add Tensorial

Other tensor packages

Inspiration

+Home · Tensorial.jl

Tensorial

Introduction

Tensorial provides useful tensor operations, such as contraction, tensor product (), and inversion (inv), implemented in the Julia programming language. The library supports tensors of arbitrary size, including both symmetric and non-symmetric tensors, where symmetries can be specified to avoid redundant computations. The approach for defining the size of a tensor is similar to that used in StaticArrays.jl, and tensor symmetries can be specified using the @Symmetry macro. For instance, a symmetric fourth-order tensor (a symmetrized tensor) is represented in this library as Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}. The library also includes an Einstein summation macro @einsum and functions for automatic differentiation, such as gradient and hessian.

Installation

pkg> add Tensorial

Other tensor packages

Inspiration

diff --git a/dev/search_index.js b/dev/search_index.js index 8c9576a..89af60b 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"Benchmarks/#Benchmarks","page":"Benchmarks","title":"Benchmarks","text":"","category":"section"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"a = rand(Vec{3})\nA = rand(SecondOrderTensor{3})\nS = rand(SymmetricSecondOrderTensor{3})\nB = rand(Tensor{Tuple{3,3,3}})\nAA = rand(FourthOrderTensor{3})\nSS = rand(SymmetricFourthOrderTensor{3})","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"Operation Tensor Array speed-up\nSingle contraction \na ⋅ a 2.785 ns 9.256 ns ×3.3\nA ⋅ a 3.095 ns 53.999 ns ×17.4\nS ⋅ a 3.396 ns 53.775 ns ×15.8\nDouble contraction \nA ⊡ A 3.406 ns 11.422 ns ×3.4\nS ⊡ S 3.095 ns 11.422 ns ×3.7\nB ⊡ A 5.410 ns 128.613 ns ×23.8\nAA ⊡ A 7.732 ns 144.599 ns ×18.7\nSS ⊡ S 15.719 ns 152.234 ns ×9.7\nTensor product \na ⊗ a 3.716 ns 33.597 ns ×9.0\nCross product \na × a 3.716 ns 33.597 ns ×9.0\nDeterminant \ndet(A) 3.406 ns 170.710 ns ×50.1\ndet(S) 3.406 ns 169.943 ns ×49.9\nInverse \ninv(A) 5.931 ns 478.118 ns ×80.6\ninv(S) 12.032 ns 472.719 ns ×39.3\ninv(AA) 964.143 ns 1.531 μs ×1.6\ninv(SS) 357.154 ns 1.529 μs ×4.3","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"The benchmarks are generated by runbenchmarks.jl on the following system:","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"julia> versioninfo()\nJulia Version 1.11.0\nCommit 501a4f25c2b (2024-10-07 11:40 UTC)\nBuild Info:\n Official https://julialang.org/ release\nPlatform Info:\n OS: Linux (x86_64-linux-gnu)\n CPU: 4 × AMD EPYC 7763 64-Core Processor\n WORD_SIZE: 64\n LLVM: libLLVM-16.0.6 (ORCJIT, znver3)\nThreads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)\n","category":"page"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Einstein summation/#Einstein-summation","page":"Einstein summation","title":"Einstein summation","text":"","category":"section"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"Order = [:type, :function, :macro]\nPages = [\"Einstein summation.md\"]","category":"page"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"Modules = [Tensorial]\nOrder = [:type, :function, :macro]\nPages = [\"einsum.jl\"]","category":"page"},{"location":"Einstein summation/#Tensorial.@einsum-Tuple{Any}","page":"Einstein summation","title":"Tensorial.@einsum","text":"@einsum [TensorType] (i,j...) -> expr\n@einsum [TensorType] expr\n\nPerforms tensor computations using the Einstein summation convention. The arguments of the anonymous function are treated as free indices. If no arguments are provided, they are inferred based on the order in which the indices appear from left to right. Since @einsum cannot fully infer tensor symmetries, it is possible to annotate the returned tensor type (though this is not checked for correctness). This can help eliminate the computation of the symmetric part, improving performance.\n\nExamples\n\njulia> A = rand(Mat{3,3});\n\njulia> B = rand(Mat{3,3});\n\njulia> (@einsum (i,j) -> A[j,k] * B[k,i]) ≈ (A ⋅ B)'\ntrue\n\njulia> (@einsum A[i,k] * B[k,j]) ≈ A ⋅ B\ntrue\n\njulia> (@einsum A[i,j] * A[i,j]) ≈ A ⊡ A\ntrue\n\njulia> (@einsum SymmetricSecondOrderTensor{3} A[k,i] * A[k,j]) ≈ A' ⋅ A\ntrue\n\n\n\n\n\n","category":"macro"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Tensor Operations/#Tensor-Operations","page":"Tensor Operations","title":"Tensor Operations","text":"","category":"section"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"Order = [:function]\nPages = [\"Tensor Operations.md\"]","category":"page"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"ops.jl\"]","category":"page"},{"location":"Tensor Operations/#LinearAlgebra.cross-Union{Tuple{T2}, Tuple{T1}, Tuple{Vec{1, T1}, Vec{1, T2}}} where {T1, T2}","page":"Tensor Operations","title":"LinearAlgebra.cross","text":"cross(x::Vec{3}, y::Vec{3}) -> Vec{3}\ncross(x::Vec{2}, y::Vec{2}) -> Vec{3}\ncross(x::Vec{1}, y::Vec{1}) -> Vec{3}\nx × y\n\nCompute the cross product between two vectors. The vectors are expanded to 3D frist for dimensions 1 and 2. The infix operator × (written \\times) can also be used. x × y (where × can be typed by \\times) is a synonym for cross(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> x × y\n3-element Vec{3, Float64}:\n 0.13928086435138393\n 0.0669520417303531\n -0.37588028973385323\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.dot-Tuple{AbstractTensor, AbstractTensor}","page":"Tensor Operations","title":"LinearAlgebra.dot","text":"dot(x::AbstractTensor, y::AbstractTensor)\nx ⋅ y\n\nCompute dot product such as a = x_i y_i. This is equivalent to contract(::AbstractTensor, ::AbstractTensor, Val(1)). x ⋅ y (where ⋅ can be typed by \\cdot) is a synonym for dot(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> a = x ⋅ y\n0.5715585109976284\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.norm-Tuple{AbstractTensor}","page":"Tensor Operations","title":"LinearAlgebra.norm","text":"norm(::AbstractTensor)\n\nCompute norm of a tensor.\n\nExamples\n\njulia> x = rand(Mat{3, 3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> norm(x)\n1.8223398556552728\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.tr-Tuple{Union{AbstractSymmetricSecondOrderTensor{dim, T}, AbstractMat{dim, dim, T}} where {dim, T}}","page":"Tensor Operations","title":"LinearAlgebra.tr","text":"tr(::AbstractSecondOrderTensor)\ntr(::AbstractSymmetricSecondOrderTensor)\n\nCompute the trace of a square tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> tr(x)\n1.1733382401532275\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.contract-Union{Tuple{N}, Tuple{AbstractTensor, AbstractTensor, Val{N}}} where N","page":"Tensor Operations","title":"Tensorial.contract","text":"contract(::AbstractTensor, ::AbstractTensor, ::Val{N})\n\nConduct contraction of N inner indices. For example, N=2 contraction for third-order tensors A_ij = B_ikl C_klj can be computed as follows:\n\njulia> B = rand(Tensor{Tuple{3,3,3}});\n\njulia> C = rand(Tensor{Tuple{3,3,3}});\n\njulia> A = contract(B, C, Val(2))\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 3.70978 2.47156 3.91807\n 2.90966 2.30881 3.25965\n 1.78391 1.38714 2.2079\n\nFollowing symbols are also available for specific contractions:\n\nx ⊗ y (where ⊗ can be typed by \\otimes): contract(x, y, Val(0))\nx ⋅ y (where ⋅ can be typed by \\cdot): contract(x, y, Val(1))\nx ⊡ y (where ⊡ can be typed by \\boxdot): contract(x, y, Val(2))\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.minorsymmetric-Union{Tuple{AbstractFourthOrderTensor{dim}}, Tuple{dim}} where dim","page":"Tensor Operations","title":"Tensorial.minorsymmetric","text":"minorsymmetric(::AbstractFourthOrderTensor) -> SymmetricFourthOrderTensor\n\nCompute the minor symmetric part of a fourth order tensor.\n\nExamples\n\njulia> x = rand(Tensor{Tuple{3,3,3,3}});\n\njulia> minorsymmetric(x) ≈ @einsum (i,j,k,l) -> (x[i,j,k,l] + x[j,i,k,l] + x[i,j,l,k] + x[j,i,l,k]) / 4\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.otimes-Tuple{Union{Number, AbstractTensor}, Union{Number, AbstractTensor}}","page":"Tensor Operations","title":"Tensorial.otimes","text":"otimes(x::AbstractTensor, y::AbstractTensor)\nx ⊗ y\n\nCompute tensor product such as A_ij = x_i y_j. x ⊗ y (where ⊗ can be typed by \\otimes) is a synonym for otimes(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> A = x ⊗ y\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.291503 0.115106 0.128518\n 0.490986 0.193876 0.216466\n 0.19547 0.0771855 0.086179\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotate-Tuple{Vec, Tensor{Tuple{dim, dim}, T, 2} where {dim, T}}","page":"Tensor Operations","title":"Tensorial.rotate","text":"rotate(x::Vec, R::SecondOrderTensor)\nrotate(x::SecondOrderTensor, R::SecondOrderTensor)\nrotate(x::SymmetricSecondOrderTensor, R::SecondOrderTensor)\n\nRotate x by rotation matrix R. This function can hold the symmetry of SymmetricSecondOrderTensor.\n\nExamples\n\njulia> A = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> R = rotmatz(π/4)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.707107 -0.707107 0.0\n 0.707107 0.707107 0.0\n 0.0 0.0 1.0\n\njulia> rotate(A, R)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.0610599 -0.284134 -0.0951235\n -0.284134 1.15916 0.404252\n -0.0951235 0.404252 0.394255\n\njulia> R ⋅ A ⋅ R'\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.0610599 -0.284134 -0.0951235\n -0.284134 1.15916 0.404252\n -0.0951235 0.404252 0.394255\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Number, Vec{3}}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ, n::Vec)\n\nConstruct rotation matrix from angle θ and axis n.\n\nExamples\n\njulia> x = Vec(1.0, 0.0, 0.0)\n3-element Vec{3, Float64}:\n 1.0\n 0.0\n 0.0\n\njulia> n = Vec(0.0, 0.0, 1.0)\n3-element Vec{3, Float64}:\n 0.0\n 0.0\n 1.0\n\njulia> rotmat(π/2, n) ⋅ x\n3-element Vec{3, Float64}:\n 6.123233995736766e-17\n 1.0\n 0.0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ::Number)\n\nConstruct 2D rotation matrix.\n\nbmR = beginbmatrix\ncostheta -sintheta \nsintheta costheta\nendbmatrix\n\nExamples\n\njulia> rotmat(deg2rad(30))\n2×2 Tensor{Tuple{2, 2}, Float64, 2, 4}:\n 0.866025 -0.5\n 0.5 0.866025\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Vec{3}}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ::Vec{3}; sequence::Symbol)\n\nConvert Euler angles to rotation matrix. Use 3 characters belonging to the set (X, Y, Z) for intrinsic rotations, or (x, y, z) for extrinsic rotations.\n\nExamples\n\njulia> α, β, γ = map(deg2rad, rand(3));\n\njulia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmatx(α) ⋅ rotmaty(β) ⋅ rotmatz(γ)\ntrue\n\njulia> rotmat(Vec(α,β,γ), sequence = :xyz) ≈ rotmatz(γ) ⋅ rotmaty(β) ⋅ rotmatx(α)\ntrue\n\njulia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmat(Vec(γ,β,α), sequence = :zyx)\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Union{Tuple{Pair{Vec{dim, T}, Vec{dim, T}}}, Tuple{T}, Tuple{dim}} where {dim, T}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(a => b)\n\nConstruct rotation matrix rotating vector a to b. The norms of two vectors must be the same.\n\nExamples\n\njulia> a = normalize(rand(Vec{3}))\n3-element Vec{3, Float64}:\n 0.4829957515506539\n 0.8135223859352438\n 0.3238771859304809\n\njulia> b = normalize(rand(Vec{3}))\n3-element Vec{3, Float64}:\n 0.8605677447967596\n 0.3398133016944055\n 0.3794075336718636\n\njulia> R = rotmat(a => b)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -0.00540771 0.853773 0.520617\n 0.853773 -0.267108 0.446905\n 0.520617 0.446905 -0.727485\n\njulia> R ⋅ a ≈ b\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmatx-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmatx","text":"rotmatx(θ::Number)\n\nConstruct rotation matrix around x axis.\n\nbmR_x = beginbmatrix\n1 0 0 \n0 costheta -sintheta \n0 sintheta costheta\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmaty-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmaty","text":"rotmaty(θ::Number)\n\nConstruct rotation matrix around y axis.\n\nbmR_y = beginbmatrix\ncostheta 0 sintheta \n0 1 0 \n-sintheta 0 costheta\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmatz-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmatz","text":"rotmatz(θ::Number)\n\nConstruct rotation matrix around z axis.\n\nbmR_z = beginbmatrix\ncostheta -sintheta 0 \nsintheta costheta 0 \n0 0 1\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.skew-Tuple{AbstractTensor{Tuple{dim, dim}, T, 2} where {dim, T}}","page":"Tensor Operations","title":"Tensorial.skew","text":"skew(::AbstractSecondOrderTensor)\nskew(::AbstractSymmetricSecondOrderTensor)\n\nCompute skew-symmetric (anti-symmetric) part of a second order tensor.\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.skew-Tuple{Vec{3}}","page":"Tensor Operations","title":"Tensorial.skew","text":"skew(ω::Vec{3})\n\nConstruct a skew-symmetric (anti-symmetric) tensor W from a vector ω as\n\nbmomega = beginBmatrix\n omega_1 \n omega_2 \n omega_3\nendBmatrix quad\nbmW = beginbmatrix\n 0 -omega_3 omega_2 \n omega_3 0 -omega_1 \n -omega_2 omega_1 0\nendbmatrix\n\nExamples\n\njulia> skew(Vec(1,2,3))\n3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}:\n 0 -3 2\n 3 0 -1\n -2 1 0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.symmetric-Tuple{AbstractSymmetricSecondOrderTensor}","page":"Tensor Operations","title":"Tensorial.symmetric","text":"symmetric(::AbstractSecondOrderTensor)\nsymmetric(::AbstractSecondOrderTensor, uplo)\n\nCompute the symmetric part of a second order tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> symmetric(x)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.721648 0.585856\n 0.721648 0.353112 0.594901\n 0.585856 0.594901 0.49425\n\njulia> symmetric(x, :U)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.894245 0.953125\n 0.894245 0.353112 0.795547\n 0.953125 0.795547 0.49425\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Quaternion/#Quaternion","page":"Quaternion","title":"Quaternion","text":"","category":"section"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"Order = [:type, :function]\nPages = [\"Quaternion.md\"]","category":"page"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"Modules = [Tensorial]\nOrder = [:type, :function]\nPages = [\"quaternion.jl\"]","category":"page"},{"location":"Quaternion/#Tensorial.Quaternion","page":"Quaternion","title":"Tensorial.Quaternion","text":"Quaternion represents q_w + q_x bmi + q_y bmj + q_z bmk. The salar part and vector part can be accessed by q.scalar and q.vector, respectively.\n\nExamples\n\njulia> Quaternion(1,2,3,4)\n1 + 2𝙞 + 3𝙟 + 4𝙠\n\njulia> Quaternion(1)\n1 + 0𝙞 + 0𝙟 + 0𝙠\n\njulia> Quaternion(Vec(1,2,3))\n0 + 1𝙞 + 2𝙟 + 3𝙠\n\nSee also quaternion.\n\nnote: Note\nQuaternion is experimental and could change or disappear in future versions of Tensorial.\n\n\n\n\n\n","category":"type"},{"location":"Quaternion/#Base.exp-Tuple{Quaternion}","page":"Quaternion","title":"Base.exp","text":"exp(::Quaternion)\n\nCompute the exponential of quaternion as\n\nexp(q) = e^q_w left( cos bmv + fracbmv bmv sin bmv right)\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Base.log-Tuple{Quaternion}","page":"Quaternion","title":"Base.log","text":"log(::Quaternion)\n\nCompute the logarithm of quaternion as\n\nln(q) = ln q + fracbmv bmv arccosfracq_w q \n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.quaternion-Union{Tuple{T}, Tuple{Type{T}, Real, Vec{3}}} where T","page":"Quaternion","title":"Tensorial.quaternion","text":"quaternion(θ, n::Vec; normalize = true)\n\nConstruct Quaternion from angle θ and axis n as\n\nq = cosfractheta2 + bmn sinfractheta2\n\nThe constructed quaternion is normalized such as norm(q) ≈ 1 by default.\n\nExamples\n\njulia> q = quaternion(π/4, Vec(0,0,1))\n0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> (q * x / q).vector ≈ rotmatz(π/4) ⋅ x\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.rotate-Tuple{Vec, Quaternion}","page":"Quaternion","title":"Tensorial.rotate","text":"rotate(x::Vec, q::Quaternion)\n\nRotate x by quaternion q.\n\nExamples\n\njulia> v = Vec(1.0, 0.0, 0.0)\n3-element Vec{3, Float64}:\n 1.0\n 0.0\n 0.0\n\njulia> rotate(v, quaternion(π/4, Vec(0,0,1)))\n3-element Vec{3, Float64}:\n 0.7071067811865475\n 0.7071067811865476\n 0.0\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.rotmat-Tuple{Quaternion}","page":"Quaternion","title":"Tensorial.rotmat","text":"rotmat(::Quaternion)\n\nConstruct rotation matrix from quaternion.\n\nExamples\n\njulia> q = quaternion(π/4, Vec(0,0,1))\n0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠\n\njulia> rotmat(q)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.707107 -0.707107 0.0\n 0.707107 0.707107 0.0\n 0.0 0.0 1.0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Type/#Tensor-type","page":"Tensor type","title":"Tensor type","text":"","category":"section"},{"location":"Tensor Type/#Type-parameters","page":"Tensor type","title":"Type parameters","text":"","category":"section"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"All tensors in Tensorial.jl are represented by the type Tensor{S, T, N, L}, where each type parameter represents the following:","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"S: The size of Tensors which is specified by using Tuple (e.g., 3x2 tensor becomes Tensor{Tuple{3,2}}).\nT: The type of element which must be T <: Real.\nN: The number of dimensions (the order of tensor).\nL: The number of independent components.","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"Basically, the type parameters N and L do not need to be specified for constructing tensors because it can be inferred from the size of tensor S.","category":"page"},{"location":"Tensor Type/#Symmetry","page":"Tensor type","title":"Symmetry","text":"","category":"section"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"Specifying the symmetry of a tensor can improve performance, as Tensorial.jl provides optimized computations for symmetric tensors. Symmetries can be applied using Symmetry in the type parameter S (e.g., Symmetry{Tuple{3,3}}). The @Symmetry macro simplifies this process by allowing you to omit Tuple, as in @Symmetry{2,2}. Below are some examples of how to specify symmetries:","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"A_(ij) with 3x3: Tensor{Tuple{@Symmetry{3,3}}}\nA_(ij)k with 3x3x2: Tensor{Tuple{@Symmetry{3,3}, 2}}\nA_(ijk) with 3x3x3: Tensor{Tuple{@Symmetry{3,3,3}}}\nA_(ij)(kl) with 3x3x3x3: Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"where the bracket () in indices denotes the symmetry.","category":"page"},{"location":"Cheat Sheet/#Cheat-Sheet","page":"Cheat Sheet","title":"Cheat Sheet","text":"","category":"section"},{"location":"Cheat Sheet/#Constructors","page":"Cheat Sheet","title":"Constructors","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# tensor aliases\nrand(Vec{3}) # vector\nrand(Mat{2,3}) # matrix\nrand(SecondOrderTensor{3}) # 3x3 second-order tensor (this is the same as the Mat{3,3})\nrand(SymmetricSecondOrderTensor{3}) # 3x3 symmetric second-order tensor (3x3 symmetric matrix)\nrand(FourthOrderTensor{3}) # 3x3x3x3 fourth-order tensor\nrand(SymmetricFourthOrderTensor{3}) # 3x3x3x3 symmetric fourth-order tensor\n\n# identity tensors\none(SecondOrderTensor{3,3}) # second-order identity tensor\none(SymmetricSecondOrderTensor{3}) # symmetric second-order identity tensor\none(FourthOrderTensor{3}) # fourth-order identity tensor\none(SymmetricFourthOrderTensor{3}) # symmetric fourth-order identity tensor (symmetrizing tensor)\n\n# zero tensors\nzero(Mat{2,3}) == zeros(2,3)\nzero(SymmetricSecondOrderTensor{3}) == zeros(3,3)\n\n# random tensors\nrand(Mat{2,3})\nrandn(Mat{2,3})\n\n# from arrays\nMat{2,2}([1 2; 3 4]) == [1 2; 3 4]\nSymmetricSecondOrderTensor{2}([1 2; 3 4]) == [1 3; 3 4] # lower triangular part is used\n\n# from functions\nMat{2,2}((i,j) -> i == j ? 1 : 0) == one(Mat{2,2})\nSymmetricSecondOrderTensor{2}((i,j) -> i == j ? 1 : 0) == one(SymmetricSecondOrderTensor{2})\n\n# macros (same interface as StaticArrays.jl)\n@Vec [1,2,3]\n@Vec rand(4)\n@Mat [1 2\n 3 4]\n@Mat rand(4,4)\n@Tensor rand(2,2,2)\n\n# statically sized getindex by `@Tensor`\nx = @Mat [1 2\n 3 4\n 5 6]\n@Tensor(x[2:3, :]) === @Mat [3 4\n 5 6]\n@Tensor(x[[1,3], :]) === @Mat [1 2\n 5 6]","category":"page"},{"location":"Cheat Sheet/#Tensor-Operations","page":"Cheat Sheet","title":"Tensor Operations","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# 2nd-order vs. 2nd-order\nx = rand(Mat{2,2})\ny = rand(SymmetricSecondOrderTensor{2})\nx ⊗ y isa Tensor{Tuple{2,2,@Symmetry{2,2}}} # tensor product\nx ⋅ y isa Tensor{Tuple{2,2}} # single contraction (x_ij * y_jk)\nx ⊡ y isa Real # double contraction (x_ij * y_ij)\n\n# 3rd-order vs. 1st-order\nA = rand(Tensor{Tuple{@Symmetry{2,2},2}})\nv = rand(Vec{2})\nA ⊗ v isa Tensor{Tuple{@Symmetry{2,2},2,2}} # A_ijk * v_l\nA ⋅ v isa Tensor{Tuple{@Symmetry{2,2}}} # A_ijk * v_k\nA ⊡ v # error\n\n# 4th-order vs. 2nd-order\nII = one(SymmetricFourthOrderTensor{2}) # equal to one(Tensor{Tuple{@Symmetry{2,2}, @Symmetry{2,2}}})\nA = rand(Mat{2,2})\nS = rand(SymmetricSecondOrderTensor{2})\nII ⊡ A == (A + A') / 2 == symmetric(A) # symmetrizing A, resulting in Tensor{Tuple{@Symmetry{2,2}}}\nII ⊡ S == S\n\n# contraction\nx = rand(Tensor{Tuple{2,2,2}})\ny = rand(Tensor{Tuple{2,@Symmetry{2,2}}})\ncontraction(x, y, Val(1)) isa Tensor{Tuple{2,2, @Symmetry{2,2}}} # single contraction (== ⋅)\ncontraction(x, y, Val(2)) isa Tensor{Tuple{2,2}} # double contraction (== ⊡)\ncontraction(x, y, Val(3)) isa Real # triple contraction (x_ijk * y_ijk)\ncontraction(x, y, Val(0)) isa Tensor{Tuple{2,2,2,2, @Symmetry{2,2}}} # tensor product (== ⊗)\n\n# norm/tr/mean/vol/dev\nx = rand(SecondOrderTensor{3}) # equal to rand(Tensor{Tuple{3,3}})\nv = rand(Vec{3})\nnorm(v)\ntr(x)\nmean(x) == tr(x) / 3 # useful for computing mean stress\nvol(x) + dev(x) == x # decomposition into volumetric part and deviatoric part\n\n# det/inv for 2nd-order tensor\nA = rand(SecondOrderTensor{3}) # equal to one(Tensor{Tuple{3,3}})\nS = rand(SymmetricSecondOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}}})\ndet(A); det(S)\ninv(A) ⋅ A ≈ one(A)\ninv(S) ⋅ S ≈ one(S)\n\n# inv for 4th-order tensor\nAA = rand(FourthOrderTensor{3}) # equal to one(Tensor{Tuple{3,3,3,3}})\nSS = rand(SymmetricFourthOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}})\ninv(AA) ⊡ AA ≈ one(AA)\ninv(SS) ⊡ SS ≈ one(SS)\n\n# Einstein summation convention\nA = rand(Mat{3,3})\nB = rand(Mat{3,3})\n(@einsum (i,j) -> A[i,k] * B[k,j]) == A ⋅ B\n(@einsum A[i,j] * B[i,j]) == A ⊡ B","category":"page"},{"location":"Cheat Sheet/#Automatic-differentiation","page":"Cheat Sheet","title":"Automatic differentiation","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# Real -> Real\ngradient(x -> 2x^2 + x + 3, 3) == (x = 3; 4x + 1)\ngradient(x -> 2.0, 3) == 0.0\n\n# Real -> Tensor\ngradient(x -> Mat{2,2}((i,j) -> i*x^2), 3) == (x = 3; Mat{2,2}((i,j) -> 2i*x))\ngradient(x -> one(Mat{2,2}), 3) == zero(Mat{2,2})\n\n# Tensor -> Real\ngradient(tr, rand(Mat{3,3})) == one(Mat{3,3})\n\n# Tensor -> Tensor\nA = rand(Mat{3,3})\nD = gradient(dev, A) # deviatoric projection tensor\nDs = gradient(dev, symmetric(A)) # symmetric deviatoric projection tensor\nA ⊡ D ≈ dev(A)\nA ⊡ Ds ≈ symmetric(dev(A))\ngradient(identity, A) == one(FourthOrderTensor{3}) # 4th-order identity tensor\ngradient(identity, symmetric(A)) == one(SymmetricFourthOrderTensor{3}) # symmetric 4th-order identity tensor","category":"page"},{"location":"Cheat Sheet/#Aliases","page":"Cheat Sheet","title":"Aliases","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"const Vec{dim, T} = Tensor{Tuple{dim}, T, 1, dim}\nconst Mat{m, n, T, L} = Tensor{Tuple{m, n}, T, 2, L}\nconst SecondOrderTensor{dim, T, L} = Tensor{NTuple{2, dim}, T, 2, L}\nconst FourthOrderTensor{dim, T, L} = Tensor{NTuple{4, dim}, T, 4, L}\nconst SymmetricSecondOrderTensor{dim, T, L} = Tensor{Tuple{@Symmetry{dim, dim}}, T, 2, L}\nconst SymmetricFourthOrderTensor{dim, T, L} = Tensor{NTuple{2, @Symmetry{dim, dim}}, T, 4, L}","category":"page"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Continuum Mechanics/#Continuum-Mechanics","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"Tensor operations for continuum mechanics.","category":"page"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"mean(::Tensorial.AbstractSquareTensor{3})\nvonmises","category":"page"},{"location":"Continuum Mechanics/#Statistics.mean-Tuple{Union{AbstractSecondOrderTensor{3, T}, AbstractSymmetricSecondOrderTensor{3, T}, AbstractMat{3, 3, T}} where T}","page":"Continuum Mechanics","title":"Statistics.mean","text":"mean(::AbstractSecondOrderTensor{3})\nmean(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the mean value of diagonal entries of a square tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> mean(x)\n0.3911127467177425\n\n\n\n\n\n","category":"method"},{"location":"Continuum Mechanics/#Tensorial.vonmises","page":"Continuum Mechanics","title":"Tensorial.vonmises","text":"vonmises(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the von Mises stress.\n\nq = sqrtfrac32 mathrmdev(bmsigma) mathrmdev(bmsigma) = sqrt3J_2\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> vonmises(σ)\n1.3078860814690232\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Deviatoric–volumetric-additive-split","page":"Continuum Mechanics","title":"Deviatoric–volumetric additive split","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"vol\ndev","category":"page"},{"location":"Continuum Mechanics/#Tensorial.vol","page":"Continuum Mechanics","title":"Tensorial.vol","text":"vol(::AbstractSecondOrderTensor{3})\nvol(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the volumetric part of a square tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> vol(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.391113 0.0 0.0\n 0.0 0.391113 0.0\n 0.0 0.0 0.391113\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\nvol(::AbstractVec{3})\n\nCompute the volumetric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> vol(x)\n3-element Vec{3, Float64}:\n 0.3645381733326641\n 0.3645381733326641\n 0.3645381733326641\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\nvol(::Type{FourthOrderTensor{3}})\nvol(::Type{SymmetricFourthOrderTensor{3}})\n\nConstruct volumetric fourth order identity tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> I_vol = vol(FourthOrderTensor{3});\n\njulia> I_vol ⊡ x ≈ vol(x)\ntrue\n\njulia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Tensorial.dev","page":"Continuum Mechanics","title":"Tensorial.dev","text":"dev(::AbstractSecondOrderTensor{3})\ndev(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the deviatoric part of a square tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> dev(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -0.065136 0.894245 0.953125\n 0.549051 -0.0380011 0.795547\n 0.218587 0.394255 0.103137\n\njulia> tr(dev(x))\n5.551115123125783e-17\n\n\n\n\n\ndev(::AbstractVec{3})\n\nCompute the deviatoric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> dev(x)\n3-element Vec{3, Float64}:\n -0.03856144446906923\n 0.18451296298290282\n -0.14595151851383342\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\ndev(::Type{FourthOrderTensor{3}})\ndev(::Type{SymmetricFourthOrderTensor{3}})\n\nConstruct deviatoric fourth order identity tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> I_dev = dev(FourthOrderTensor{3});\n\njulia> I_dev ⊡ x ≈ dev(x)\ntrue\n\njulia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Stress-invariants","page":"Continuum Mechanics","title":"Stress invariants","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"stress_invariants\ndeviatoric_stress_invariants","category":"page"},{"location":"Continuum Mechanics/#Tensorial.stress_invariants","page":"Continuum Mechanics","title":"Tensorial.stress_invariants","text":"stress_invariants(::AbstractSecondOrderTensor{3})\nstress_invariants(::AbstractSymmetricSecondOrderTensor{3})\nstress_invariants(::Vec{3})\n\nReturn a tuple storing stress invariants.\n\nbeginaligned\nI_1(bmsigma) = mathrmtr(bmsigma) \nI_2(bmsigma) = frac12 (mathrmtr(bmsigma)^2 - mathrmtr(bmsigma^2)) \nI_3(bmsigma) = det(bmsigma)\nendaligned\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> I₁, I₂, I₃ = stress_invariants(σ)\n(1.6144775244804341, 0.2986572249840249, -0.0025393241133506677)\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Tensorial.deviatoric_stress_invariants","page":"Continuum Mechanics","title":"Tensorial.deviatoric_stress_invariants","text":"deviatoric_stress_invariants(::AbstractSecondOrderTensor{3})\ndeviatoric_stress_invariants(::AbstractSymmetricSecondOrderTensor{3})\ndeviatoric_stress_invariants(::Vec{3})\n\nReturn a tuple storing deviatoric stress invariants.\n\nbeginaligned\nJ_1(bmsigma) = mathrmtr(mathrmdev(bmsigma)) = 0 \nJ_2(bmsigma) = frac12 mathrmtr(mathrmdev(bmsigma)^2) \nJ_3(bmsigma) = frac13 mathrmtr(mathrmdev(bmsigma)^3)\nendaligned\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> J₁, J₂, J₃ = deviatoric_stress_invariants(σ)\n(0.0, 0.5701886673667987, 0.14845380911930367)\n\n\n\n\n\n","category":"function"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Voigt form/#Voigt-Form","page":"Voigt Form","title":"Voigt Form","text":"","category":"section"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"Order = [:function]\nPages = [\"Voigt form.md\"]","category":"page"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"voigt.jl\"]","category":"page"},{"location":"Voigt form/#Tensorial.frommandel-Union{Tuple{T}, Tuple{Type{<:Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, AbstractArray{T}}} where T","page":"Voigt Form","title":"Tensorial.frommandel","text":"frommandel(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T})\n\nCreate a tensor of type S from Mandel form. This is equivalent to fromvoigt(S, A, offdiagscale = √2).\n\nSee also fromvoigt.\n\n\n\n\n\n","category":"method"},{"location":"Voigt form/#Tensorial.fromvoigt","page":"Voigt Form","title":"Tensorial.fromvoigt","text":"fromvoigt(S::Type{<: Union{SecondOrderTensor, FourthOrderTensor}}, A::AbstractArray{T}; [order])\nfromvoigt(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T}; [order, offdiagscale])\n\nConverts an array A stored in Voigt format to a Tensor of type S.\n\nKeyword arguments:\n\noffdiagscale: Determines the scaling factor for the offdiagonal elements.\norder: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.\n\nnote: Note\nSince offdiagscale is the scaling factor for the offdiagonal elements in Voigt form, they are multiplied by 1/offdiagscale in fromvoigt unlike tovoigt. Thus fromvoigt(tovoigt(x, offdiagscale = 2), offdiagscale = 2) returns original x.\n\nSee also tovoigt.\n\nExamples\n\njulia> fromvoigt(Mat{3,3}, 1.0:1.0:9.0)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 6.0 5.0\n 9.0 2.0 4.0\n 8.0 7.0 3.0\n\njulia> fromvoigt(SymmetricSecondOrderTensor{3},\n 1.0:1.0:6.0,\n offdiagscale = 2.0,\n order = [(1,1), (2,2), (3,3), (1,2), (1,3), (2,3)])\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 1.0 2.0 2.5\n 2.0 2.0 3.0\n 2.5 3.0 3.0\n\n\n\n\n\n","category":"function"},{"location":"Voigt form/#Tensorial.tomandel-Tuple{Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}","page":"Voigt Form","title":"Tensorial.tomandel","text":"tomandel(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor})\n\nConvert a tensor to Mandel form which is equivalent to tovoigt(A, offdiagscale = √2).\n\nSee also tovoigt.\n\n\n\n\n\n","category":"method"},{"location":"Voigt form/#Tensorial.tovoigt","page":"Voigt Form","title":"Tensorial.tovoigt","text":"tovoigt(A::Union{SecondOrderTensor, FourthOrderTensor}; [order])\ntovoigt(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}; [order, offdiagonal])\n\nConvert a tensor to Voigt form.\n\nKeyword arguments:\n\noffdiagscale: Determines the scaling factor for the offdiagonal elements.\norder: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.\n\nSee also fromvoigt.\n\nExamples\n\njulia> x = Mat{3,3}(1:9...)\n3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}:\n 1 4 7\n 2 5 8\n 3 6 9\n\njulia> tovoigt(x)\n9-element StaticArraysCore.SVector{9, Int64} with indices SOneTo(9):\n 1\n 5\n 9\n 8\n 7\n 4\n 6\n 3\n 2\n\njulia> x = SymmetricSecondOrderTensor{3}(1:6...)\n3×3 SymmetricSecondOrderTensor{3, Int64, 6}:\n 1 2 3\n 2 4 5\n 3 5 6\n\njulia> tovoigt(x; offdiagscale = 2,\n order = [(1,1), (2,2), (3,3), (1,2), (1,3), (2,3)])\n6-element StaticArraysCore.SVector{6, Int64} with indices SOneTo(6):\n 1\n 4\n 6\n 4\n 6\n 10\n\n\n\n\n\n","category":"function"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Broadcast/#Broadcast","page":"Broadcast","title":"Broadcast","text":"","category":"section"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"In Tensorial.jl, subtypes of AbstractTensor basically behave like scalars rather than Array. For example, broadcasting operations on tensors and arrays of tensors will be performed as","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"julia> x = Vec(1,2,3)\n3-element Vec{3, Int64}:\n 1\n 2\n 3\n\njulia> V = [Vec{3}(i:i+2) for i in 1:4]\n4-element Vector{Vec{3, Int64}}:\n [1, 2, 3]\n [2, 3, 4]\n [3, 4, 5]\n [4, 5, 6]\n\njulia> x .+ V\n4-element Vector{Vec{3, Int64}}:\n [2, 4, 6]\n [3, 5, 7]\n [4, 6, 8]\n [5, 7, 9]\n\njulia> V .= zero(x)\n4-element Vector{Vec{3, Int64}}:\n [0, 0, 0]\n [0, 0, 0]\n [0, 0, 0]\n [0, 0, 0]","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"On the other hand, broadcasting itself or with scalars and tuples behave the same as built-in Array as","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"julia> x = Vec(1,2,3)\n3-element Vec{3, Int64}:\n 1\n 2\n 3\n\njulia> sqrt.(x)\n3-element Vec{3, Float64}:\n 1.0\n 1.4142135623730951\n 1.7320508075688772\n\njulia> x .+ 2\n3-element Vec{3, Int64}:\n 3\n 4\n 5\n\njulia> x .+ (2,3,4)\n3-element Vec{3, Int64}:\n 3\n 5\n 7","category":"page"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Automatic differentiation/#Automatic-differentiation","page":"Automatic differentiation","title":"Automatic differentiation","text":"","category":"section"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"Order = [:type, :function]\nPages = [\"Automatic differentiation.md\"]","category":"page"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"Modules = [Tensorial]\nOrder = [:type, :function]\nPages = [\"ad.jl\"]","category":"page"},{"location":"Automatic differentiation/#Tensorial.gradient-Tuple{Any, Union{Number, AbstractTensor}}","page":"Automatic differentiation","title":"Tensorial.gradient","text":"gradient(f, x)\ngradient(f, x, :all)\n\nCompute the gradient of f with respect to x by the automatic differentiation. If pseudo keyword :all is given, the value of f(x) is also returned.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> gradient(tr, x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> ∇f, f = gradient(tr, x, :all)\n([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0], 1.1733382401532275)\n\n\n\n\n\n","category":"method"},{"location":"Automatic differentiation/#Tensorial.hessian-Tuple{Any, Union{Number, AbstractTensor}}","page":"Automatic differentiation","title":"Tensorial.hessian","text":"hessian(f, x)\nhessian(f, x, :all)\n\nCompute the hessian of f with respect to x by the automatic differentiation. If pseudo keyword :all is given, the value of f(x) is also returned.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> hessian(norm, x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.13603 -0.582196 -0.231782\n -0.582196 0.501079 -0.390397\n -0.231782 -0.390397 1.32626\n\njulia> ∇∇f, ∇f, f = hessian(norm, x, :all)\n([1.1360324375454411 -0.5821964220304534 -0.23178236037013888; -0.5821964220304533 0.5010791569244991 -0.39039709608344814; -0.23178236037013886 -0.39039709608344814 1.3262640626479867], [0.4829957515506539, 0.8135223859352438, 0.3238771859304809], 0.6749059962060727)\n\n\n\n\n\n","category":"method"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Tensor Inversion/#Tensor-Inversion","page":"Tensor Inversion","title":"Tensor Inversion","text":"","category":"section"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Inversion of 2nd and 4th order tensors are supported.","category":"page"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Order = [:function]\nPages = [\"Tensor Inversion.md\"]","category":"page"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"inv.jl\"]","category":"page"},{"location":"Tensor Inversion/#Base.inv","page":"Tensor Inversion","title":"Base.inv","text":"inv(::AbstractSecondOrderTensor)\ninv(::AbstractSymmetricSecondOrderTensor)\ninv(::AbstractFourthOrderTensor)\ninv(::AbstractSymmetricFourthOrderTensor)\n\nCompute the inverse of a tensor.\n\nExamples\n\njulia> x = rand(SecondOrderTensor{3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> inv(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -587.685 -279.668 1583.46\n -411.743 -199.494 1115.12\n 588.35 282.819 -1587.79\n\njulia> x ⋅ inv(x) ≈ one(I)\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Tensor Inversion/#Tensorial.adj","page":"Tensor Inversion","title":"Tensorial.adj","text":"adj(::AbstractSecondOrderTensor)\nadj(::AbstractSymmetricSecondOrderTensor)\n\nCompute the adjugate matrix.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> Tensorial.adj(x) / det(x) ≈ inv(x)\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Constructors/#Constructors","page":"Constructors","title":"Constructors","text":"","category":"section"},{"location":"Constructors/#Identity-tensors","page":"Constructors","title":"Identity tensors","text":"","category":"section"},{"location":"Constructors/#Second-order-tensor","page":"Constructors","title":"Second order tensor","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"julia> one(SecondOrderTensor{3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> one(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> one(Mat{2,2})\n2×2 Tensor{Tuple{2, 2}, Float64, 2, 4}:\n 1.0 0.0\n 0.0 1.0","category":"page"},{"location":"Constructors/#Fourth-order-tensor","page":"Constructors","title":"Fourth order tensor","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"julia> one(FourthOrderTensor{3})\n3×3×3×3 FourthOrderTensor{3, Float64, 81}:\n[:, :, 1, 1] =\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 1] =\n 0.0 0.0 0.0\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 1] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 1.0 0.0 0.0\n\n[:, :, 1, 2] =\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 2] =\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 2] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n\n[:, :, 1, 3] =\n 0.0 0.0 1.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 1.0\n 0.0 0.0 0.0\n\n[:, :, 3, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 1.0\n\njulia> one(SymmetricFourthOrderTensor{3})\n3×3×3×3 SymmetricFourthOrderTensor{3, Float64, 36}:\n[:, :, 1, 1] =\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 1] =\n 0.0 0.5 0.0\n 0.5 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 1] =\n 0.0 0.0 0.5\n 0.0 0.0 0.0\n 0.5 0.0 0.0\n\n[:, :, 1, 2] =\n 0.0 0.5 0.0\n 0.5 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 2] =\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 2] =\n 0.0 0.0 0.0\n 0.0 0.0 0.5\n 0.0 0.5 0.0\n\n[:, :, 1, 3] =\n 0.0 0.0 0.5\n 0.0 0.0 0.0\n 0.5 0.0 0.0\n\n[:, :, 2, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.5\n 0.0 0.5 0.0\n\n[:, :, 3, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 1.0","category":"page"},{"location":"Constructors/#Other-special-tensors","page":"Constructors","title":"Other special tensors","text":"","category":"section"},{"location":"Constructors/#Levi-Civita","page":"Constructors","title":"Levi-Civita","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"levicivita","category":"page"},{"location":"Constructors/#Tensorial.levicivita","page":"Constructors","title":"Tensorial.levicivita","text":"levicivita(::Val{N} = Val(3))\n\nReturn N dimensional Levi-Civita tensor.\n\nExamples\n\njulia> ϵ = levicivita()\n3×3×3 Tensor{Tuple{3, 3, 3}, Int64, 3, 27}:\n[:, :, 1] =\n 0 0 0\n 0 0 1\n 0 -1 0\n\n[:, :, 2] =\n 0 0 -1\n 0 0 0\n 1 0 0\n\n[:, :, 3] =\n 0 1 0\n -1 0 0\n 0 0 0\n\n\n\n\n\n","category":"function"},{"location":"#Tensorial","page":"Home","title":"Tensorial","text":"","category":"section"},{"location":"#Introduction","page":"Home","title":"Introduction","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Tensorial provides useful tensor operations, such as contraction, tensor product (⊗), and inversion (inv), implemented in the Julia programming language. The library supports tensors of arbitrary size, including both symmetric and non-symmetric tensors, where symmetries can be specified to avoid redundant computations. The approach for defining the size of a tensor is similar to that used in StaticArrays.jl, and tensor symmetries can be specified using the @Symmetry macro. For instance, a symmetric fourth-order tensor (a symmetrized tensor) is represented in this library as Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}. The library also includes an Einstein summation macro @einsum and functions for automatic differentiation, such as gradient and hessian.","category":"page"},{"location":"#Installation","page":"Home","title":"Installation","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"pkg> add Tensorial","category":"page"},{"location":"#Other-tensor-packages","page":"Home","title":"Other tensor packages","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Einsum.jl\nTensorOprations.jl\nTensors.jl","category":"page"},{"location":"#Inspiration","page":"Home","title":"Inspiration","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"StaticArrays.jl\nTensors.jl","category":"page"}] +[{"location":"Benchmarks/#Benchmarks","page":"Benchmarks","title":"Benchmarks","text":"","category":"section"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"a = rand(Vec{3})\nA = rand(SecondOrderTensor{3})\nS = rand(SymmetricSecondOrderTensor{3})\nB = rand(Tensor{Tuple{3,3,3}})\nAA = rand(FourthOrderTensor{3})\nSS = rand(SymmetricFourthOrderTensor{3})","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"Operation Tensor Array speed-up\nSingle contraction \na ⋅ a 3.095 ns 9.256 ns ×3.0\nA ⋅ a 3.396 ns 53.634 ns ×15.8\nS ⋅ a 3.706 ns 53.512 ns ×14.4\nDouble contraction \nA ⊡ A 3.706 ns 11.422 ns ×3.1\nS ⊡ S 3.396 ns 11.422 ns ×3.4\nB ⊡ A 5.420 ns 122.123 ns ×22.5\nAA ⊡ A 7.732 ns 143.526 ns ×18.6\nSS ⊡ S 4.197 ns 146.164 ns ×34.8\nTensor product \na ⊗ a 3.406 ns 33.150 ns ×9.7\nCross product \na × a 3.406 ns 33.150 ns ×9.7\nDeterminant \ndet(A) 3.406 ns 175.817 ns ×51.6\ndet(S) 3.406 ns 180.956 ns ×53.1\nInverse \ninv(A) 6.001 ns 479.621 ns ×79.9\ninv(S) 5.250 ns 484.469 ns ×92.3\ninv(AA) 958.182 ns 1.521 μs ×1.6\ninv(SS) 363.676 ns 1.530 μs ×4.2","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"The benchmarks are generated by runbenchmarks.jl on the following system:","category":"page"},{"location":"Benchmarks/","page":"Benchmarks","title":"Benchmarks","text":"julia> versioninfo()\nJulia Version 1.11.0\nCommit 501a4f25c2b (2024-10-07 11:40 UTC)\nBuild Info:\n Official https://julialang.org/ release\nPlatform Info:\n OS: Linux (x86_64-linux-gnu)\n CPU: 4 × AMD EPYC 7763 64-Core Processor\n WORD_SIZE: 64\n LLVM: libLLVM-16.0.6 (ORCJIT, znver3)\nThreads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)\n","category":"page"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Einstein summation/#Einstein-summation","page":"Einstein summation","title":"Einstein summation","text":"","category":"section"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"Order = [:type, :function, :macro]\nPages = [\"Einstein summation.md\"]","category":"page"},{"location":"Einstein summation/","page":"Einstein summation","title":"Einstein summation","text":"Modules = [Tensorial]\nOrder = [:type, :function, :macro]\nPages = [\"einsum.jl\"]","category":"page"},{"location":"Einstein summation/#Tensorial.@einsum-Tuple{Any}","page":"Einstein summation","title":"Tensorial.@einsum","text":"@einsum [TensorType] (i,j...) -> expr\n@einsum [TensorType] expr\n\nPerforms tensor computations using the Einstein summation convention. The arguments of the anonymous function are treated as free indices. If no arguments are provided, they are inferred based on the order in which the indices appear from left to right. Since @einsum cannot fully infer tensor symmetries, it is possible to annotate the returned tensor type (though this is not checked for correctness). This can help eliminate the computation of the symmetric part, improving performance.\n\nExamples\n\njulia> A = rand(Mat{3,3});\n\njulia> B = rand(Mat{3,3});\n\njulia> (@einsum (i,j) -> A[j,k] * B[k,i]) ≈ (A ⋅ B)'\ntrue\n\njulia> (@einsum A[i,k] * B[k,j]) ≈ A ⋅ B\ntrue\n\njulia> (@einsum A[i,j] * A[i,j]) ≈ A ⊡ A\ntrue\n\njulia> (@einsum SymmetricSecondOrderTensor{3} A[k,i] * A[k,j]) ≈ A' ⋅ A\ntrue\n\n\n\n\n\n","category":"macro"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Tensor Operations/#Tensor-Operations","page":"Tensor Operations","title":"Tensor Operations","text":"","category":"section"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"Order = [:function]\nPages = [\"Tensor Operations.md\"]","category":"page"},{"location":"Tensor Operations/","page":"Tensor Operations","title":"Tensor Operations","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"ops.jl\"]","category":"page"},{"location":"Tensor Operations/#LinearAlgebra.cross-Union{Tuple{T2}, Tuple{T1}, Tuple{Vec{1, T1}, Vec{1, T2}}} where {T1, T2}","page":"Tensor Operations","title":"LinearAlgebra.cross","text":"cross(x::Vec{3}, y::Vec{3}) -> Vec{3}\ncross(x::Vec{2}, y::Vec{2}) -> Vec{3}\ncross(x::Vec{1}, y::Vec{1}) -> Vec{3}\nx × y\n\nCompute the cross product between two vectors. The vectors are expanded to 3D frist for dimensions 1 and 2. The infix operator × (written \\times) can also be used. x × y (where × can be typed by \\times) is a synonym for cross(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> x × y\n3-element Vec{3, Float64}:\n 0.13928086435138393\n 0.0669520417303531\n -0.37588028973385323\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.dot-Tuple{AbstractTensor, AbstractTensor}","page":"Tensor Operations","title":"LinearAlgebra.dot","text":"dot(x::AbstractTensor, y::AbstractTensor)\nx ⋅ y\n\nCompute dot product such as a = x_i y_i. This is equivalent to contract(::AbstractTensor, ::AbstractTensor, Val(1)). x ⋅ y (where ⋅ can be typed by \\cdot) is a synonym for dot(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> a = x ⋅ y\n0.5715585109976284\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.norm-Tuple{AbstractTensor}","page":"Tensor Operations","title":"LinearAlgebra.norm","text":"norm(::AbstractTensor)\n\nCompute norm of a tensor.\n\nExamples\n\njulia> x = rand(Mat{3, 3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> norm(x)\n1.8223398556552728\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#LinearAlgebra.tr-Tuple{Union{AbstractSymmetricSecondOrderTensor{dim, T}, AbstractMat{dim, dim, T}} where {dim, T}}","page":"Tensor Operations","title":"LinearAlgebra.tr","text":"tr(::AbstractSecondOrderTensor)\ntr(::AbstractSymmetricSecondOrderTensor)\n\nCompute the trace of a square tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> tr(x)\n1.1733382401532275\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.contract-Union{Tuple{N}, Tuple{AbstractTensor, AbstractTensor, Val{N}}} where N","page":"Tensor Operations","title":"Tensorial.contract","text":"contract(::AbstractTensor, ::AbstractTensor, ::Val{N})\n\nConduct contraction of N inner indices. For example, N=2 contraction for third-order tensors A_ij = B_ikl C_klj can be computed as follows:\n\njulia> B = rand(Tensor{Tuple{3,3,3}});\n\njulia> C = rand(Tensor{Tuple{3,3,3}});\n\njulia> A = contract(B, C, Val(2))\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 3.70978 2.47156 3.91807\n 2.90966 2.30881 3.25965\n 1.78391 1.38714 2.2079\n\nFollowing symbols are also available for specific contractions:\n\nx ⊗ y (where ⊗ can be typed by \\otimes): contract(x, y, Val(0))\nx ⋅ y (where ⋅ can be typed by \\cdot): contract(x, y, Val(1))\nx ⊡ y (where ⊡ can be typed by \\boxdot): contract(x, y, Val(2))\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.minorsymmetric-Union{Tuple{AbstractFourthOrderTensor{dim}}, Tuple{dim}} where dim","page":"Tensor Operations","title":"Tensorial.minorsymmetric","text":"minorsymmetric(::AbstractFourthOrderTensor) -> SymmetricFourthOrderTensor\n\nCompute the minor symmetric part of a fourth order tensor.\n\nExamples\n\njulia> x = rand(Tensor{Tuple{3,3,3,3}});\n\njulia> minorsymmetric(x) ≈ @einsum (i,j,k,l) -> (x[i,j,k,l] + x[j,i,k,l] + x[i,j,l,k] + x[j,i,l,k]) / 4\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.otimes-Tuple{Union{Number, AbstractTensor}, Union{Number, AbstractTensor}}","page":"Tensor Operations","title":"Tensorial.otimes","text":"otimes(x::AbstractTensor, y::AbstractTensor)\nx ⊗ y\n\nCompute tensor product such as A_ij = x_i y_j. x ⊗ y (where ⊗ can be typed by \\otimes) is a synonym for otimes(x, y).\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> y = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.8942454282009883\n 0.35311164439921205\n 0.39425536741585077\n\njulia> A = x ⊗ y\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.291503 0.115106 0.128518\n 0.490986 0.193876 0.216466\n 0.19547 0.0771855 0.086179\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotate-Tuple{Vec, Tensor{Tuple{dim, dim}, T, 2} where {dim, T}}","page":"Tensor Operations","title":"Tensorial.rotate","text":"rotate(x::Vec, R::SecondOrderTensor)\nrotate(x::SecondOrderTensor, R::SecondOrderTensor)\nrotate(x::SymmetricSecondOrderTensor, R::SecondOrderTensor)\n\nRotate x by rotation matrix R. This function can hold the symmetry of SymmetricSecondOrderTensor.\n\nExamples\n\njulia> A = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> R = rotmatz(π/4)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.707107 -0.707107 0.0\n 0.707107 0.707107 0.0\n 0.0 0.0 1.0\n\njulia> rotate(A, R)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.0610599 -0.284134 -0.0951235\n -0.284134 1.15916 0.404252\n -0.0951235 0.404252 0.394255\n\njulia> R ⋅ A ⋅ R'\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.0610599 -0.284134 -0.0951235\n -0.284134 1.15916 0.404252\n -0.0951235 0.404252 0.394255\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Number, Vec{3}}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ, n::Vec)\n\nConstruct rotation matrix from angle θ and axis n.\n\nExamples\n\njulia> x = Vec(1.0, 0.0, 0.0)\n3-element Vec{3, Float64}:\n 1.0\n 0.0\n 0.0\n\njulia> n = Vec(0.0, 0.0, 1.0)\n3-element Vec{3, Float64}:\n 0.0\n 0.0\n 1.0\n\njulia> rotmat(π/2, n) ⋅ x\n3-element Vec{3, Float64}:\n 6.123233995736766e-17\n 1.0\n 0.0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ::Number)\n\nConstruct 2D rotation matrix.\n\nbmR = beginbmatrix\ncostheta -sintheta \nsintheta costheta\nendbmatrix\n\nExamples\n\njulia> rotmat(deg2rad(30))\n2×2 Tensor{Tuple{2, 2}, Float64, 2, 4}:\n 0.866025 -0.5\n 0.5 0.866025\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Tuple{Vec{3}}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(θ::Vec{3}; sequence::Symbol)\n\nConvert Euler angles to rotation matrix. Use 3 characters belonging to the set (X, Y, Z) for intrinsic rotations, or (x, y, z) for extrinsic rotations.\n\nExamples\n\njulia> α, β, γ = map(deg2rad, rand(3));\n\njulia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmatx(α) ⋅ rotmaty(β) ⋅ rotmatz(γ)\ntrue\n\njulia> rotmat(Vec(α,β,γ), sequence = :xyz) ≈ rotmatz(γ) ⋅ rotmaty(β) ⋅ rotmatx(α)\ntrue\n\njulia> rotmat(Vec(α,β,γ), sequence = :XYZ) ≈ rotmat(Vec(γ,β,α), sequence = :zyx)\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmat-Union{Tuple{Pair{Vec{dim, T}, Vec{dim, T}}}, Tuple{T}, Tuple{dim}} where {dim, T}","page":"Tensor Operations","title":"Tensorial.rotmat","text":"rotmat(a => b)\n\nConstruct rotation matrix rotating vector a to b. The norms of two vectors must be the same.\n\nExamples\n\njulia> a = normalize(rand(Vec{3}))\n3-element Vec{3, Float64}:\n 0.4829957515506539\n 0.8135223859352438\n 0.3238771859304809\n\njulia> b = normalize(rand(Vec{3}))\n3-element Vec{3, Float64}:\n 0.8605677447967596\n 0.3398133016944055\n 0.3794075336718636\n\njulia> R = rotmat(a => b)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -0.00540771 0.853773 0.520617\n 0.853773 -0.267108 0.446905\n 0.520617 0.446905 -0.727485\n\njulia> R ⋅ a ≈ b\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmatx-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmatx","text":"rotmatx(θ::Number)\n\nConstruct rotation matrix around x axis.\n\nbmR_x = beginbmatrix\n1 0 0 \n0 costheta -sintheta \n0 sintheta costheta\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmaty-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmaty","text":"rotmaty(θ::Number)\n\nConstruct rotation matrix around y axis.\n\nbmR_y = beginbmatrix\ncostheta 0 sintheta \n0 1 0 \n-sintheta 0 costheta\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.rotmatz-Tuple{Number}","page":"Tensor Operations","title":"Tensorial.rotmatz","text":"rotmatz(θ::Number)\n\nConstruct rotation matrix around z axis.\n\nbmR_z = beginbmatrix\ncostheta -sintheta 0 \nsintheta costheta 0 \n0 0 1\nendbmatrix\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.skew-Tuple{AbstractTensor{Tuple{dim, dim}, T, 2} where {dim, T}}","page":"Tensor Operations","title":"Tensorial.skew","text":"skew(::AbstractSecondOrderTensor)\nskew(::AbstractSymmetricSecondOrderTensor)\n\nCompute skew-symmetric (anti-symmetric) part of a second order tensor.\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.skew-Tuple{Vec{3}}","page":"Tensor Operations","title":"Tensorial.skew","text":"skew(ω::Vec{3})\n\nConstruct a skew-symmetric (anti-symmetric) tensor W from a vector ω as\n\nbmomega = beginBmatrix\n omega_1 \n omega_2 \n omega_3\nendBmatrix quad\nbmW = beginbmatrix\n 0 -omega_3 omega_2 \n omega_3 0 -omega_1 \n -omega_2 omega_1 0\nendbmatrix\n\nExamples\n\njulia> skew(Vec(1,2,3))\n3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}:\n 0 -3 2\n 3 0 -1\n -2 1 0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Operations/#Tensorial.symmetric-Tuple{AbstractSymmetricSecondOrderTensor}","page":"Tensor Operations","title":"Tensorial.symmetric","text":"symmetric(::AbstractSecondOrderTensor)\nsymmetric(::AbstractSecondOrderTensor, uplo)\n\nCompute the symmetric part of a second order tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> symmetric(x)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.721648 0.585856\n 0.721648 0.353112 0.594901\n 0.585856 0.594901 0.49425\n\njulia> symmetric(x, :U)\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.894245 0.953125\n 0.894245 0.353112 0.795547\n 0.953125 0.795547 0.49425\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Quaternion/#Quaternion","page":"Quaternion","title":"Quaternion","text":"","category":"section"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"Order = [:type, :function]\nPages = [\"Quaternion.md\"]","category":"page"},{"location":"Quaternion/","page":"Quaternion","title":"Quaternion","text":"Modules = [Tensorial]\nOrder = [:type, :function]\nPages = [\"quaternion.jl\"]","category":"page"},{"location":"Quaternion/#Tensorial.Quaternion","page":"Quaternion","title":"Tensorial.Quaternion","text":"Quaternion represents q_w + q_x bmi + q_y bmj + q_z bmk. The salar part and vector part can be accessed by q.scalar and q.vector, respectively.\n\nExamples\n\njulia> Quaternion(1,2,3,4)\n1 + 2𝙞 + 3𝙟 + 4𝙠\n\njulia> Quaternion(1)\n1 + 0𝙞 + 0𝙟 + 0𝙠\n\njulia> Quaternion(Vec(1,2,3))\n0 + 1𝙞 + 2𝙟 + 3𝙠\n\nSee also quaternion.\n\nnote: Note\nQuaternion is experimental and could change or disappear in future versions of Tensorial.\n\n\n\n\n\n","category":"type"},{"location":"Quaternion/#Base.exp-Tuple{Quaternion}","page":"Quaternion","title":"Base.exp","text":"exp(::Quaternion)\n\nCompute the exponential of quaternion as\n\nexp(q) = e^q_w left( cos bmv + fracbmv bmv sin bmv right)\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Base.log-Tuple{Quaternion}","page":"Quaternion","title":"Base.log","text":"log(::Quaternion)\n\nCompute the logarithm of quaternion as\n\nln(q) = ln q + fracbmv bmv arccosfracq_w q \n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.quaternion-Union{Tuple{T}, Tuple{Type{T}, Real, Vec{3}}} where T","page":"Quaternion","title":"Tensorial.quaternion","text":"quaternion(θ, n::Vec; normalize = true)\n\nConstruct Quaternion from angle θ and axis n as\n\nq = cosfractheta2 + bmn sinfractheta2\n\nThe constructed quaternion is normalized such as norm(q) ≈ 1 by default.\n\nExamples\n\njulia> q = quaternion(π/4, Vec(0,0,1))\n0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> (q * x / q).vector ≈ rotmatz(π/4) ⋅ x\ntrue\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.rotate-Tuple{Vec, Quaternion}","page":"Quaternion","title":"Tensorial.rotate","text":"rotate(x::Vec, q::Quaternion)\n\nRotate x by quaternion q.\n\nExamples\n\njulia> v = Vec(1.0, 0.0, 0.0)\n3-element Vec{3, Float64}:\n 1.0\n 0.0\n 0.0\n\njulia> rotate(v, quaternion(π/4, Vec(0,0,1)))\n3-element Vec{3, Float64}:\n 0.7071067811865475\n 0.7071067811865476\n 0.0\n\n\n\n\n\n","category":"method"},{"location":"Quaternion/#Tensorial.rotmat-Tuple{Quaternion}","page":"Quaternion","title":"Tensorial.rotmat","text":"rotmat(::Quaternion)\n\nConstruct rotation matrix from quaternion.\n\nExamples\n\njulia> q = quaternion(π/4, Vec(0,0,1))\n0.9238795325112867 + 0.0𝙞 + 0.0𝙟 + 0.3826834323650898𝙠\n\njulia> rotmat(q)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.707107 -0.707107 0.0\n 0.707107 0.707107 0.0\n 0.0 0.0 1.0\n\n\n\n\n\n","category":"method"},{"location":"Tensor Type/#Tensor-type","page":"Tensor type","title":"Tensor type","text":"","category":"section"},{"location":"Tensor Type/#Type-parameters","page":"Tensor type","title":"Type parameters","text":"","category":"section"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"All tensors in Tensorial.jl are represented by the type Tensor{S, T, N, L}, where each type parameter represents the following:","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"S: The size of Tensors which is specified by using Tuple (e.g., 3x2 tensor becomes Tensor{Tuple{3,2}}).\nT: The type of element which must be T <: Real.\nN: The number of dimensions (the order of tensor).\nL: The number of independent components.","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"Basically, the type parameters N and L do not need to be specified for constructing tensors because it can be inferred from the size of tensor S.","category":"page"},{"location":"Tensor Type/#Symmetry","page":"Tensor type","title":"Symmetry","text":"","category":"section"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"Specifying the symmetry of a tensor can improve performance, as Tensorial.jl provides optimized computations for symmetric tensors. Symmetries can be applied using Symmetry in the type parameter S (e.g., Symmetry{Tuple{3,3}}). The @Symmetry macro simplifies this process by allowing you to omit Tuple, as in @Symmetry{2,2}. Below are some examples of how to specify symmetries:","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"A_(ij) with 3x3: Tensor{Tuple{@Symmetry{3,3}}}\nA_(ij)k with 3x3x2: Tensor{Tuple{@Symmetry{3,3}, 2}}\nA_(ijk) with 3x3x3: Tensor{Tuple{@Symmetry{3,3,3}}}\nA_(ij)(kl) with 3x3x3x3: Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}","category":"page"},{"location":"Tensor Type/","page":"Tensor type","title":"Tensor type","text":"where the bracket () in indices denotes the symmetry.","category":"page"},{"location":"Cheat Sheet/#Cheat-Sheet","page":"Cheat Sheet","title":"Cheat Sheet","text":"","category":"section"},{"location":"Cheat Sheet/#Constructors","page":"Cheat Sheet","title":"Constructors","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# tensor aliases\nrand(Vec{3}) # vector\nrand(Mat{2,3}) # matrix\nrand(SecondOrderTensor{3}) # 3x3 second-order tensor (this is the same as the Mat{3,3})\nrand(SymmetricSecondOrderTensor{3}) # 3x3 symmetric second-order tensor (3x3 symmetric matrix)\nrand(FourthOrderTensor{3}) # 3x3x3x3 fourth-order tensor\nrand(SymmetricFourthOrderTensor{3}) # 3x3x3x3 symmetric fourth-order tensor\n\n# identity tensors\none(SecondOrderTensor{3,3}) # second-order identity tensor\none(SymmetricSecondOrderTensor{3}) # symmetric second-order identity tensor\none(FourthOrderTensor{3}) # fourth-order identity tensor\none(SymmetricFourthOrderTensor{3}) # symmetric fourth-order identity tensor (symmetrizing tensor)\n\n# zero tensors\nzero(Mat{2,3}) == zeros(2,3)\nzero(SymmetricSecondOrderTensor{3}) == zeros(3,3)\n\n# random tensors\nrand(Mat{2,3})\nrandn(Mat{2,3})\n\n# from arrays\nMat{2,2}([1 2; 3 4]) == [1 2; 3 4]\nSymmetricSecondOrderTensor{2}([1 2; 3 4]) == [1 3; 3 4] # lower triangular part is used\n\n# from functions\nMat{2,2}((i,j) -> i == j ? 1 : 0) == one(Mat{2,2})\nSymmetricSecondOrderTensor{2}((i,j) -> i == j ? 1 : 0) == one(SymmetricSecondOrderTensor{2})\n\n# macros (same interface as StaticArrays.jl)\n@Vec [1,2,3]\n@Vec rand(4)\n@Mat [1 2\n 3 4]\n@Mat rand(4,4)\n@Tensor rand(2,2,2)\n\n# statically sized getindex by `@Tensor`\nx = @Mat [1 2\n 3 4\n 5 6]\n@Tensor(x[2:3, :]) === @Mat [3 4\n 5 6]\n@Tensor(x[[1,3], :]) === @Mat [1 2\n 5 6]","category":"page"},{"location":"Cheat Sheet/#Tensor-Operations","page":"Cheat Sheet","title":"Tensor Operations","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# 2nd-order vs. 2nd-order\nx = rand(Mat{2,2})\ny = rand(SymmetricSecondOrderTensor{2})\nx ⊗ y isa Tensor{Tuple{2,2,@Symmetry{2,2}}} # tensor product\nx ⋅ y isa Tensor{Tuple{2,2}} # single contraction (x_ij * y_jk)\nx ⊡ y isa Real # double contraction (x_ij * y_ij)\n\n# 3rd-order vs. 1st-order\nA = rand(Tensor{Tuple{@Symmetry{2,2},2}})\nv = rand(Vec{2})\nA ⊗ v isa Tensor{Tuple{@Symmetry{2,2},2,2}} # A_ijk * v_l\nA ⋅ v isa Tensor{Tuple{@Symmetry{2,2}}} # A_ijk * v_k\nA ⊡ v # error\n\n# 4th-order vs. 2nd-order\nII = one(SymmetricFourthOrderTensor{2}) # equal to one(Tensor{Tuple{@Symmetry{2,2}, @Symmetry{2,2}}})\nA = rand(Mat{2,2})\nS = rand(SymmetricSecondOrderTensor{2})\nII ⊡ A == (A + A') / 2 == symmetric(A) # symmetrizing A, resulting in Tensor{Tuple{@Symmetry{2,2}}}\nII ⊡ S == S\n\n# contraction\nx = rand(Tensor{Tuple{2,2,2}})\ny = rand(Tensor{Tuple{2,@Symmetry{2,2}}})\ncontraction(x, y, Val(1)) isa Tensor{Tuple{2,2, @Symmetry{2,2}}} # single contraction (== ⋅)\ncontraction(x, y, Val(2)) isa Tensor{Tuple{2,2}} # double contraction (== ⊡)\ncontraction(x, y, Val(3)) isa Real # triple contraction (x_ijk * y_ijk)\ncontraction(x, y, Val(0)) isa Tensor{Tuple{2,2,2,2, @Symmetry{2,2}}} # tensor product (== ⊗)\n\n# norm/tr/mean/vol/dev\nx = rand(SecondOrderTensor{3}) # equal to rand(Tensor{Tuple{3,3}})\nv = rand(Vec{3})\nnorm(v)\ntr(x)\nmean(x) == tr(x) / 3 # useful for computing mean stress\nvol(x) + dev(x) == x # decomposition into volumetric part and deviatoric part\n\n# det/inv for 2nd-order tensor\nA = rand(SecondOrderTensor{3}) # equal to one(Tensor{Tuple{3,3}})\nS = rand(SymmetricSecondOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}}})\ndet(A); det(S)\ninv(A) ⋅ A ≈ one(A)\ninv(S) ⋅ S ≈ one(S)\n\n# inv for 4th-order tensor\nAA = rand(FourthOrderTensor{3}) # equal to one(Tensor{Tuple{3,3,3,3}})\nSS = rand(SymmetricFourthOrderTensor{3}) # equal to one(Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}})\ninv(AA) ⊡ AA ≈ one(AA)\ninv(SS) ⊡ SS ≈ one(SS)\n\n# Einstein summation convention\nA = rand(Mat{3,3})\nB = rand(Mat{3,3})\n(@einsum (i,j) -> A[i,k] * B[k,j]) == A ⋅ B\n(@einsum A[i,j] * B[i,j]) == A ⊡ B","category":"page"},{"location":"Cheat Sheet/#Automatic-differentiation","page":"Cheat Sheet","title":"Automatic differentiation","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"# Real -> Real\ngradient(x -> 2x^2 + x + 3, 3) == (x = 3; 4x + 1)\ngradient(x -> 2.0, 3) == 0.0\n\n# Real -> Tensor\ngradient(x -> Mat{2,2}((i,j) -> i*x^2), 3) == (x = 3; Mat{2,2}((i,j) -> 2i*x))\ngradient(x -> one(Mat{2,2}), 3) == zero(Mat{2,2})\n\n# Tensor -> Real\ngradient(tr, rand(Mat{3,3})) == one(Mat{3,3})\n\n# Tensor -> Tensor\nA = rand(Mat{3,3})\nD = gradient(dev, A) # deviatoric projection tensor\nDs = gradient(dev, symmetric(A)) # symmetric deviatoric projection tensor\nA ⊡ D ≈ dev(A)\nA ⊡ Ds ≈ symmetric(dev(A))\ngradient(identity, A) == one(FourthOrderTensor{3}) # 4th-order identity tensor\ngradient(identity, symmetric(A)) == one(SymmetricFourthOrderTensor{3}) # symmetric 4th-order identity tensor","category":"page"},{"location":"Cheat Sheet/#Aliases","page":"Cheat Sheet","title":"Aliases","text":"","category":"section"},{"location":"Cheat Sheet/","page":"Cheat Sheet","title":"Cheat Sheet","text":"const Vec{dim, T} = Tensor{Tuple{dim}, T, 1, dim}\nconst Mat{m, n, T, L} = Tensor{Tuple{m, n}, T, 2, L}\nconst SecondOrderTensor{dim, T, L} = Tensor{NTuple{2, dim}, T, 2, L}\nconst FourthOrderTensor{dim, T, L} = Tensor{NTuple{4, dim}, T, 4, L}\nconst SymmetricSecondOrderTensor{dim, T, L} = Tensor{Tuple{@Symmetry{dim, dim}}, T, 2, L}\nconst SymmetricFourthOrderTensor{dim, T, L} = Tensor{NTuple{2, @Symmetry{dim, dim}}, T, 4, L}","category":"page"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Continuum Mechanics/#Continuum-Mechanics","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"Tensor operations for continuum mechanics.","category":"page"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"mean(::Tensorial.AbstractSquareTensor{3})\nvonmises","category":"page"},{"location":"Continuum Mechanics/#Statistics.mean-Tuple{Union{AbstractSecondOrderTensor{3, T}, AbstractSymmetricSecondOrderTensor{3, T}, AbstractMat{3, 3, T}} where T}","page":"Continuum Mechanics","title":"Statistics.mean","text":"mean(::AbstractSecondOrderTensor{3})\nmean(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the mean value of diagonal entries of a square tensor.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> mean(x)\n0.3911127467177425\n\n\n\n\n\n","category":"method"},{"location":"Continuum Mechanics/#Tensorial.vonmises","page":"Continuum Mechanics","title":"Tensorial.vonmises","text":"vonmises(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the von Mises stress.\n\nq = sqrtfrac32 mathrmdev(bmsigma) mathrmdev(bmsigma) = sqrt3J_2\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> vonmises(σ)\n1.3078860814690232\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Deviatoric–volumetric-additive-split","page":"Continuum Mechanics","title":"Deviatoric–volumetric additive split","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"vol\ndev","category":"page"},{"location":"Continuum Mechanics/#Tensorial.vol","page":"Continuum Mechanics","title":"Tensorial.vol","text":"vol(::AbstractSecondOrderTensor{3})\nvol(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the volumetric part of a square tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> vol(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.391113 0.0 0.0\n 0.0 0.391113 0.0\n 0.0 0.0 0.391113\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\nvol(::AbstractVec{3})\n\nCompute the volumetric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> vol(x)\n3-element Vec{3, Float64}:\n 0.3645381733326641\n 0.3645381733326641\n 0.3645381733326641\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\nvol(::Type{FourthOrderTensor{3}})\nvol(::Type{SymmetricFourthOrderTensor{3}})\n\nConstruct volumetric fourth order identity tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> I_vol = vol(FourthOrderTensor{3});\n\njulia> I_vol ⊡ x ≈ vol(x)\ntrue\n\njulia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Tensorial.dev","page":"Continuum Mechanics","title":"Tensorial.dev","text":"dev(::AbstractSecondOrderTensor{3})\ndev(::AbstractSymmetricSecondOrderTensor{3})\n\nCompute the deviatoric part of a square tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> dev(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -0.065136 0.894245 0.953125\n 0.549051 -0.0380011 0.795547\n 0.218587 0.394255 0.103137\n\njulia> tr(dev(x))\n5.551115123125783e-17\n\n\n\n\n\ndev(::AbstractVec{3})\n\nCompute the deviatoric part of a vector (assuming principal values of stresses and strains). This is only available in 3D.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> dev(x)\n3-element Vec{3, Float64}:\n -0.03856144446906923\n 0.18451296298290282\n -0.14595151851383342\n\njulia> vol(x) + dev(x) ≈ x\ntrue\n\n\n\n\n\ndev(::Type{FourthOrderTensor{3}})\ndev(::Type{SymmetricFourthOrderTensor{3}})\n\nConstruct deviatoric fourth order identity tensor. This is only available in 3D.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> I_dev = dev(FourthOrderTensor{3});\n\njulia> I_dev ⊡ x ≈ dev(x)\ntrue\n\njulia> vol(FourthOrderTensor{3}) + dev(FourthOrderTensor{3}) ≈ one(FourthOrderTensor{3})\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Stress-invariants","page":"Continuum Mechanics","title":"Stress invariants","text":"","category":"section"},{"location":"Continuum Mechanics/","page":"Continuum Mechanics","title":"Continuum Mechanics","text":"stress_invariants\ndeviatoric_stress_invariants","category":"page"},{"location":"Continuum Mechanics/#Tensorial.stress_invariants","page":"Continuum Mechanics","title":"Tensorial.stress_invariants","text":"stress_invariants(::AbstractSecondOrderTensor{3})\nstress_invariants(::AbstractSymmetricSecondOrderTensor{3})\nstress_invariants(::Vec{3})\n\nReturn a tuple storing stress invariants.\n\nbeginaligned\nI_1(bmsigma) = mathrmtr(bmsigma) \nI_2(bmsigma) = frac12 (mathrmtr(bmsigma)^2 - mathrmtr(bmsigma^2)) \nI_3(bmsigma) = det(bmsigma)\nendaligned\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> I₁, I₂, I₃ = stress_invariants(σ)\n(1.6144775244804341, 0.2986572249840249, -0.0025393241133506677)\n\n\n\n\n\n","category":"function"},{"location":"Continuum Mechanics/#Tensorial.deviatoric_stress_invariants","page":"Continuum Mechanics","title":"Tensorial.deviatoric_stress_invariants","text":"deviatoric_stress_invariants(::AbstractSecondOrderTensor{3})\ndeviatoric_stress_invariants(::AbstractSymmetricSecondOrderTensor{3})\ndeviatoric_stress_invariants(::Vec{3})\n\nReturn a tuple storing deviatoric stress invariants.\n\nbeginaligned\nJ_1(bmsigma) = mathrmtr(mathrmdev(bmsigma)) = 0 \nJ_2(bmsigma) = frac12 mathrmtr(mathrmdev(bmsigma)^2) \nJ_3(bmsigma) = frac13 mathrmtr(mathrmdev(bmsigma)^3)\nendaligned\n\nExamples\n\njulia> σ = rand(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 0.325977 0.549051 0.218587\n 0.549051 0.894245 0.353112\n 0.218587 0.353112 0.394255\n\njulia> J₁, J₂, J₃ = deviatoric_stress_invariants(σ)\n(0.0, 0.5701886673667987, 0.14845380911930367)\n\n\n\n\n\n","category":"function"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Voigt form/#Voigt-Form","page":"Voigt Form","title":"Voigt Form","text":"","category":"section"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"Order = [:function]\nPages = [\"Voigt form.md\"]","category":"page"},{"location":"Voigt form/","page":"Voigt Form","title":"Voigt Form","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"voigt.jl\"]","category":"page"},{"location":"Voigt form/#Tensorial.frommandel-Union{Tuple{T}, Tuple{Type{<:Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, AbstractArray{T}}} where T","page":"Voigt Form","title":"Tensorial.frommandel","text":"frommandel(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T})\n\nCreate a tensor of type S from Mandel form. This is equivalent to fromvoigt(S, A, offdiagscale = √2).\n\nSee also fromvoigt.\n\n\n\n\n\n","category":"method"},{"location":"Voigt form/#Tensorial.fromvoigt","page":"Voigt Form","title":"Tensorial.fromvoigt","text":"fromvoigt(S::Type{<: Union{SecondOrderTensor, FourthOrderTensor}}, A::AbstractArray{T}; [order])\nfromvoigt(S::Type{<: Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}, A::AbstractArray{T}; [order, offdiagscale])\n\nConverts an array A stored in Voigt format to a Tensor of type S.\n\nKeyword arguments:\n\noffdiagscale: Determines the scaling factor for the offdiagonal elements.\norder: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.\n\nnote: Note\nSince offdiagscale is the scaling factor for the offdiagonal elements in Voigt form, they are multiplied by 1/offdiagscale in fromvoigt unlike tovoigt. Thus fromvoigt(tovoigt(x, offdiagscale = 2), offdiagscale = 2) returns original x.\n\nSee also tovoigt.\n\nExamples\n\njulia> fromvoigt(Mat{3,3}, 1.0:1.0:9.0)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 6.0 5.0\n 9.0 2.0 4.0\n 8.0 7.0 3.0\n\njulia> fromvoigt(SymmetricSecondOrderTensor{3},\n 1.0:1.0:6.0,\n offdiagscale = 2.0,\n order = [(1,1), (2,2), (3,3), (1,2), (1,3), (2,3)])\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 1.0 2.0 2.5\n 2.0 2.0 3.0\n 2.5 3.0 3.0\n\n\n\n\n\n","category":"function"},{"location":"Voigt form/#Tensorial.tomandel-Tuple{Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}}","page":"Voigt Form","title":"Tensorial.tomandel","text":"tomandel(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor})\n\nConvert a tensor to Mandel form which is equivalent to tovoigt(A, offdiagscale = √2).\n\nSee also tovoigt.\n\n\n\n\n\n","category":"method"},{"location":"Voigt form/#Tensorial.tovoigt","page":"Voigt Form","title":"Tensorial.tovoigt","text":"tovoigt(A::Union{SecondOrderTensor, FourthOrderTensor}; [order])\ntovoigt(A::Union{SymmetricSecondOrderTensor, SymmetricFourthOrderTensor}; [order, offdiagonal])\n\nConvert a tensor to Voigt form.\n\nKeyword arguments:\n\noffdiagscale: Determines the scaling factor for the offdiagonal elements.\norder: A vector of cartesian indices (Tuple{Int, Int}) determining the Voigt order. The default order is [(1,1), (2,2), (3,3), (2,3), (1,3), (1,2), (3,2), (3,1), (2,1)] for dim=3.\n\nSee also fromvoigt.\n\nExamples\n\njulia> x = Mat{3,3}(1:9...)\n3×3 Tensor{Tuple{3, 3}, Int64, 2, 9}:\n 1 4 7\n 2 5 8\n 3 6 9\n\njulia> tovoigt(x)\n9-element StaticArraysCore.SVector{9, Int64} with indices SOneTo(9):\n 1\n 5\n 9\n 8\n 7\n 4\n 6\n 3\n 2\n\njulia> x = SymmetricSecondOrderTensor{3}(1:6...)\n3×3 SymmetricSecondOrderTensor{3, Int64, 6}:\n 1 2 3\n 2 4 5\n 3 5 6\n\njulia> tovoigt(x; offdiagscale = 2,\n order = [(1,1), (2,2), (3,3), (1,2), (1,3), (2,3)])\n6-element StaticArraysCore.SVector{6, Int64} with indices SOneTo(6):\n 1\n 4\n 6\n 4\n 6\n 10\n\n\n\n\n\n","category":"function"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Broadcast/#Broadcast","page":"Broadcast","title":"Broadcast","text":"","category":"section"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"In Tensorial.jl, subtypes of AbstractTensor basically behave like scalars rather than Array. For example, broadcasting operations on tensors and arrays of tensors will be performed as","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"julia> x = Vec(1,2,3)\n3-element Vec{3, Int64}:\n 1\n 2\n 3\n\njulia> V = [Vec{3}(i:i+2) for i in 1:4]\n4-element Vector{Vec{3, Int64}}:\n [1, 2, 3]\n [2, 3, 4]\n [3, 4, 5]\n [4, 5, 6]\n\njulia> x .+ V\n4-element Vector{Vec{3, Int64}}:\n [2, 4, 6]\n [3, 5, 7]\n [4, 6, 8]\n [5, 7, 9]\n\njulia> V .= zero(x)\n4-element Vector{Vec{3, Int64}}:\n [0, 0, 0]\n [0, 0, 0]\n [0, 0, 0]\n [0, 0, 0]","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"On the other hand, broadcasting itself or with scalars and tuples behave the same as built-in Array as","category":"page"},{"location":"Broadcast/","page":"Broadcast","title":"Broadcast","text":"julia> x = Vec(1,2,3)\n3-element Vec{3, Int64}:\n 1\n 2\n 3\n\njulia> sqrt.(x)\n3-element Vec{3, Float64}:\n 1.0\n 1.4142135623730951\n 1.7320508075688772\n\njulia> x .+ 2\n3-element Vec{3, Int64}:\n 3\n 4\n 5\n\njulia> x .+ (2,3,4)\n3-element Vec{3, Int64}:\n 3\n 5\n 7","category":"page"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Automatic differentiation/#Automatic-differentiation","page":"Automatic differentiation","title":"Automatic differentiation","text":"","category":"section"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"Order = [:type, :function]\nPages = [\"Automatic differentiation.md\"]","category":"page"},{"location":"Automatic differentiation/","page":"Automatic differentiation","title":"Automatic differentiation","text":"Modules = [Tensorial]\nOrder = [:type, :function]\nPages = [\"ad.jl\"]","category":"page"},{"location":"Automatic differentiation/#Tensorial.gradient-Tuple{Any, Union{Number, AbstractTensor}}","page":"Automatic differentiation","title":"Tensorial.gradient","text":"gradient(f, x)\ngradient(f, x, :all)\n\nCompute the gradient of f with respect to x by the automatic differentiation. If pseudo keyword :all is given, the value of f(x) is also returned.\n\nExamples\n\njulia> x = rand(Mat{3,3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> gradient(tr, x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> ∇f, f = gradient(tr, x, :all)\n([1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0], 1.1733382401532275)\n\n\n\n\n\n","category":"method"},{"location":"Automatic differentiation/#Tensorial.hessian-Tuple{Any, Union{Number, AbstractTensor}}","page":"Automatic differentiation","title":"Tensorial.hessian","text":"hessian(f, x)\nhessian(f, x, :all)\n\nCompute the hessian of f with respect to x by the automatic differentiation. If pseudo keyword :all is given, the value of f(x) is also returned.\n\nExamples\n\njulia> x = rand(Vec{3})\n3-element Vec{3, Float64}:\n 0.32597672886359486\n 0.5490511363155669\n 0.21858665481883066\n\njulia> hessian(norm, x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.13603 -0.582196 -0.231782\n -0.582196 0.501079 -0.390397\n -0.231782 -0.390397 1.32626\n\njulia> ∇∇f, ∇f, f = hessian(norm, x, :all)\n([1.1360324375454411 -0.5821964220304534 -0.23178236037013888; -0.5821964220304533 0.5010791569244991 -0.39039709608344814; -0.23178236037013886 -0.39039709608344814 1.3262640626479867], [0.4829957515506539, 0.8135223859352438, 0.3238771859304809], 0.6749059962060727)\n\n\n\n\n\n","category":"method"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Tensor Inversion/#Tensor-Inversion","page":"Tensor Inversion","title":"Tensor Inversion","text":"","category":"section"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Inversion of 2nd and 4th order tensors are supported.","category":"page"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Order = [:function]\nPages = [\"Tensor Inversion.md\"]","category":"page"},{"location":"Tensor Inversion/","page":"Tensor Inversion","title":"Tensor Inversion","text":"Modules = [Tensorial]\nOrder = [:function]\nPages = [\"inv.jl\"]","category":"page"},{"location":"Tensor Inversion/#Base.inv","page":"Tensor Inversion","title":"Base.inv","text":"inv(::AbstractSecondOrderTensor)\ninv(::AbstractSymmetricSecondOrderTensor)\ninv(::AbstractFourthOrderTensor)\ninv(::AbstractSymmetricFourthOrderTensor)\n\nCompute the inverse of a tensor.\n\nExamples\n\njulia> x = rand(SecondOrderTensor{3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 0.325977 0.894245 0.953125\n 0.549051 0.353112 0.795547\n 0.218587 0.394255 0.49425\n\njulia> inv(x)\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n -587.685 -279.668 1583.46\n -411.743 -199.494 1115.12\n 588.35 282.819 -1587.79\n\njulia> x ⋅ inv(x) ≈ one(I)\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Tensor Inversion/#Tensorial.adj","page":"Tensor Inversion","title":"Tensorial.adj","text":"adj(::AbstractSecondOrderTensor)\nadj(::AbstractSymmetricSecondOrderTensor)\n\nCompute the adjugate matrix.\n\nExamples\n\njulia> x = rand(Mat{3,3});\n\njulia> Tensorial.adj(x) / det(x) ≈ inv(x)\ntrue\n\n\n\n\n\n","category":"function"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"DocTestSetup = :(using Tensorial)","category":"page"},{"location":"Constructors/#Constructors","page":"Constructors","title":"Constructors","text":"","category":"section"},{"location":"Constructors/#Identity-tensors","page":"Constructors","title":"Identity tensors","text":"","category":"section"},{"location":"Constructors/#Second-order-tensor","page":"Constructors","title":"Second order tensor","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"julia> one(SecondOrderTensor{3})\n3×3 Tensor{Tuple{3, 3}, Float64, 2, 9}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> one(SymmetricSecondOrderTensor{3})\n3×3 SymmetricSecondOrderTensor{3, Float64, 6}:\n 1.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 1.0\n\njulia> one(Mat{2,2})\n2×2 Tensor{Tuple{2, 2}, Float64, 2, 4}:\n 1.0 0.0\n 0.0 1.0","category":"page"},{"location":"Constructors/#Fourth-order-tensor","page":"Constructors","title":"Fourth order tensor","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"julia> one(FourthOrderTensor{3})\n3×3×3×3 FourthOrderTensor{3, Float64, 81}:\n[:, :, 1, 1] =\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 1] =\n 0.0 0.0 0.0\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 1] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 1.0 0.0 0.0\n\n[:, :, 1, 2] =\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 2] =\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 2] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n\n[:, :, 1, 3] =\n 0.0 0.0 1.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 1.0\n 0.0 0.0 0.0\n\n[:, :, 3, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 1.0\n\njulia> one(SymmetricFourthOrderTensor{3})\n3×3×3×3 SymmetricFourthOrderTensor{3, Float64, 36}:\n[:, :, 1, 1] =\n 1.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 1] =\n 0.0 0.5 0.0\n 0.5 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 1] =\n 0.0 0.0 0.5\n 0.0 0.0 0.0\n 0.5 0.0 0.0\n\n[:, :, 1, 2] =\n 0.0 0.5 0.0\n 0.5 0.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 2, 2] =\n 0.0 0.0 0.0\n 0.0 1.0 0.0\n 0.0 0.0 0.0\n\n[:, :, 3, 2] =\n 0.0 0.0 0.0\n 0.0 0.0 0.5\n 0.0 0.5 0.0\n\n[:, :, 1, 3] =\n 0.0 0.0 0.5\n 0.0 0.0 0.0\n 0.5 0.0 0.0\n\n[:, :, 2, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.5\n 0.0 0.5 0.0\n\n[:, :, 3, 3] =\n 0.0 0.0 0.0\n 0.0 0.0 0.0\n 0.0 0.0 1.0","category":"page"},{"location":"Constructors/#Other-special-tensors","page":"Constructors","title":"Other special tensors","text":"","category":"section"},{"location":"Constructors/#Levi-Civita","page":"Constructors","title":"Levi-Civita","text":"","category":"section"},{"location":"Constructors/","page":"Constructors","title":"Constructors","text":"levicivita","category":"page"},{"location":"Constructors/#Tensorial.levicivita","page":"Constructors","title":"Tensorial.levicivita","text":"levicivita(::Val{N} = Val(3))\n\nReturn N dimensional Levi-Civita tensor.\n\nExamples\n\njulia> ϵ = levicivita()\n3×3×3 Tensor{Tuple{3, 3, 3}, Int64, 3, 27}:\n[:, :, 1] =\n 0 0 0\n 0 0 1\n 0 -1 0\n\n[:, :, 2] =\n 0 0 -1\n 0 0 0\n 1 0 0\n\n[:, :, 3] =\n 0 1 0\n -1 0 0\n 0 0 0\n\n\n\n\n\n","category":"function"},{"location":"#Tensorial","page":"Home","title":"Tensorial","text":"","category":"section"},{"location":"#Introduction","page":"Home","title":"Introduction","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Tensorial provides useful tensor operations, such as contraction, tensor product (⊗), and inversion (inv), implemented in the Julia programming language. The library supports tensors of arbitrary size, including both symmetric and non-symmetric tensors, where symmetries can be specified to avoid redundant computations. The approach for defining the size of a tensor is similar to that used in StaticArrays.jl, and tensor symmetries can be specified using the @Symmetry macro. For instance, a symmetric fourth-order tensor (a symmetrized tensor) is represented in this library as Tensor{Tuple{@Symmetry{3,3}, @Symmetry{3,3}}}. The library also includes an Einstein summation macro @einsum and functions for automatic differentiation, such as gradient and hessian.","category":"page"},{"location":"#Installation","page":"Home","title":"Installation","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"pkg> add Tensorial","category":"page"},{"location":"#Other-tensor-packages","page":"Home","title":"Other tensor packages","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Einsum.jl\nTensorOprations.jl\nTensors.jl","category":"page"},{"location":"#Inspiration","page":"Home","title":"Inspiration","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"StaticArrays.jl\nTensors.jl","category":"page"}] }