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.590845  0.566237
 0.766797  0.460085

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

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

julia> A ⋅ B
2-element Vec{2, Float64}:
 0.9527955925660736
 1.0018368881367576
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.590845  0.766797  0.566237
 0.766797  0.460085  0.794026
 0.566237  0.794026  0.854147

julia> dot(A)
3×3 SymmetricTensor{2, 3, Float64, 6}:
 1.2577   1.25546  1.42706
 1.25546  1.43013  1.47772
 1.42706  1.47772  1.68067
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)
1.9732018397544984

julia> A ⊡ B
1.9732018397544984
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.271839  0.352792
 0.352792  0.260518

[:, :, 2, 1] =
 0.469146  0.608857
 0.608857  0.449607

[:, :, 1, 2] =
 0.469146  0.608857
 0.608857  0.449607

[:, :, 2, 2] =
 0.504668  0.654957
 0.654957  0.48365
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.5908446386657102
 0.7667970365022592

julia> otimes(A)
2×2 SymmetricTensor{2, 2, Float64, 3}:
 0.349097  0.453058
 0.453058  0.587978
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.271839  0.469146
 0.352792  0.608857

[:, :, 2, 1] =
 0.352792  0.608857
 0.260518  0.449607

[:, :, 1, 2] =
 0.469146  0.504668
 0.608857  0.654957

[:, :, 2, 2] =
 0.608857  0.654957
 0.449607  0.48365
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.271839  0.469146
 0.352792  0.608857

[:, :, 2, 1] =
 0.469146  0.504668
 0.608857  0.654957

[:, :, 1, 2] =
 0.352792  0.608857
 0.260518  0.449607

[:, :, 2, 2] =
 0.608857  0.654957
 0.449607  0.48365
source