Binary Operations

Dot product (single contraction)

The dot product (or single contraction) between a tensor of order n and a tensor of order m is a tensor of order m + n - 2. For example, single contraction between two vectors $\mathbf{b}$ and $\mathbf{c}$ can be written as:

\[a = \mathbf{b} \cdot \mathbf{c} \Leftrightarrow a = b_i c_i\]

and single contraction between a second order tensor $\mathbf{B}$ and a vector $\mathbf{c}$:

\[\mathbf{a} = \mathbf{B} \cdot \mathbf{c} \Leftrightarrow a_i = B_{ij} c_j\]

LinearAlgebra.dotFunction
dot(::Vec, ::Vec)
dot(::Vec, ::SecondOrderTensor)
dot(::SecondOrderTensor, ::Vec)
dot(::SecondOrderTensor, ::SecondOrderTensor)

Computes the dot product (single contraction) between two tensors. The symbol , written \cdot, is overloaded for single contraction.

Examples

julia> A = rand(Tensor{2, 2})
2×2 Tensor{2, 2, Float64, 4}:
 0.325977  0.218587
 0.549051  0.894245

julia> B = rand(Tensor{1, 2})
2-element Vec{2, Float64}:
 0.35311164439921205
 0.39425536741585077

julia> dot(A, B)
2-element Vec{2, Float64}:
 0.2012851406726999
 0.5464374094589712

julia> A ⋅ B
2-element Vec{2, Float64}:
 0.2012851406726999
 0.5464374094589712
source
dot(::SymmetricTensor{2})

Compute the dot product of a symmetric second order tensor with itself. Return a SymmetricTensor.

See also tdot and dott.

Examples

julia> A = rand(SymmetricTensor{2,3})
3×3 SymmetricTensor{2, 3, Float64, 6}:
 0.325977  0.549051  0.218587
 0.549051  0.894245  0.353112
 0.218587  0.353112  0.394255

julia> dot(A)
3×3 SymmetricTensor{2, 3, Float64, 6}:
 0.455498  0.74715  0.351309
 0.74715   1.22582  0.575
 0.351309  0.575    0.327905
source

Double contraction

A double contraction between two tensors contracts the two most inner indices. The result of a double contraction between a tensor of order n and a tensor of order m is a tensor of order m + n - 4. For example, double contraction between two second order tensors $\mathbf{B}$ and $\mathbf{C}$ can be written as:

\[a = \mathbf{B} : \mathbf{C} \Leftrightarrow a = B_{ij} C_{ij}\]

and double contraction between a fourth order tensor $\mathsf{B}$ and a second order tensor $\mathbf{C}$:

\[\mathbf{A} = \mathsf{B} : \mathbf{C} \Leftrightarrow A_{ij} = B_{ijkl} C_{kl}\]

Tensors.dcontractFunction
dcontract(::SecondOrderTensor, ::SecondOrderTensor)
dcontract(::SecondOrderTensor, ::FourthOrderTensor)
dcontract(::FourthOrderTensor, ::SecondOrderTensor)
dcontract(::FourthOrderTensor, ::FourthOrderTensor)

Compute the double contraction between two tensors. The symbol , written \boxdot, is overloaded for double contraction. The reason : is not used is because it does not have the same precedence as multiplication.

Examples

julia> A = rand(SymmetricTensor{2, 2});

julia> B = rand(SymmetricTensor{2, 2});

julia> dcontract(A,B)
0.7654348606012742

julia> A ⊡ B
0.7654348606012742
source

Tensor product (open product)

The tensor product (or open product) between a tensor of order n and a tensor of order m is a tensor of order m + n. For example, open product between two vectors $\mathbf{b}$ and $\mathbf{c}$ can be written as:

\[\mathbf{A} = \mathbf{b} \otimes \mathbf{c} \Leftrightarrow A_{ij} = b_i c_j\]

and open product between two second order tensors $\mathbf{B}$ and $\mathbf{C}$:

\[\mathsf{A} = \mathbf{B} \otimes \mathbf{C} \Leftrightarrow A_{ijkl} = B_{ij} C_{kl}\]

Tensors.otimesFunction
otimes(::Vec, ::Vec)
otimes(::SecondOrderTensor, ::SecondOrderTensor)

Compute the open product between two tensors. The symbol , written \otimes, is overloaded for tensor products.

Examples

julia> A = rand(SymmetricTensor{2, 2});

julia> B = rand(SymmetricTensor{2, 2});

julia> A ⊗ B
2×2×2×2 SymmetricTensor{4, 2, Float64, 9}:
[:, :, 1, 1] =
 0.291503  0.490986
 0.490986  0.19547

[:, :, 2, 1] =
 0.115106  0.193876
 0.193876  0.0771855

[:, :, 1, 2] =
 0.115106  0.193876
 0.193876  0.0771855

[:, :, 2, 2] =
 0.128518  0.216466
 0.216466  0.086179
source
otimes(::Vec)

Compute the open product of a vector with itself. Return a SymmetricTensor.

Examples

julia> A = rand(Vec{2})
2-element Vec{2, Float64}:
 0.32597672886359486
 0.5490511363155669

julia> otimes(A)
2×2 SymmetricTensor{2, 2, Float64, 3}:
 0.106261  0.178978
 0.178978  0.301457
source

Permuted tensor products

Two commonly used permutations of the open product are the "upper" open product ($\bar{\otimes}$) and "lower" open product ($\underline{\otimes}$) defined between second order tensors $\mathbf{B}$ and $\mathbf{C}$ as

\[\mathsf{A} = \mathbf{B} \bar{\otimes} \mathbf{C} \Leftrightarrow A_{ijkl} = B_{ik} C_{jl}\\ \mathsf{A} = \mathbf{B} \underline{\otimes} \mathbf{C} \Leftrightarrow A_{ijkl} = B_{il} C_{jk}\]

Tensors.otimesuFunction
otimesu(::SecondOrderTensor, ::SecondOrderTensor)

Compute the "upper" open product between two tensors.

Examples

julia> A = rand(SymmetricTensor{2, 2});

julia> B = rand(SymmetricTensor{2, 2});

julia> otimesu(A, B)
2×2×2×2 Tensor{4, 2, Float64, 16}:
[:, :, 1, 1] =
 0.291503  0.115106
 0.490986  0.193876

[:, :, 2, 1] =
 0.490986  0.193876
 0.19547   0.0771855

[:, :, 1, 2] =
 0.115106  0.128518
 0.193876  0.216466

[:, :, 2, 2] =
 0.193876   0.216466
 0.0771855  0.086179
source
Tensors.otimeslFunction
otimesl(::SecondOrderTensor, ::SecondOrderTensor)

Compute the "lower" open product between two tensors.

Examples

julia> A = rand(SymmetricTensor{2, 2});

julia> B = rand(SymmetricTensor{2, 2});

julia> otimesl(A, B)
2×2×2×2 Tensor{4, 2, Float64, 16}:
[:, :, 1, 1] =
 0.291503  0.115106
 0.490986  0.193876

[:, :, 2, 1] =
 0.115106  0.128518
 0.193876  0.216466

[:, :, 1, 2] =
 0.490986  0.193876
 0.19547   0.0771855

[:, :, 2, 2] =
 0.193876   0.216466
 0.0771855  0.086179
source