Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor {
    pub xx: f64,
    pub xy: f64,
    pub xz: f64,
    pub yx: f64,
    pub yy: f64,
    pub yz: f64,
    pub zx: f64,
    pub zy: f64,
    pub zz: f64,
}
Expand description

Full (non-symmetric) 3×3 tensor stored row-major. Component order: xx, xy, xz, yx, yy, yz, zx, zy, zz. Maps to Foam::tensor (Foam::Tensor<scalar>).

Fields§

§xx: f64§xy: f64§xz: f64§yx: f64§yy: f64§yz: f64§zx: f64§zy: f64§zz: f64

Implementations§

Source§

impl Tensor

Source

pub const ZERO: Self

The zero tensor (all nine components 0).

Source

pub const IDENTITY: Self

The identity tensor (unit diagonal, zero off-diagonal).

Source

pub fn new( xx: f64, xy: f64, xz: f64, yx: f64, yy: f64, yz: f64, zx: f64, zy: f64, zz: f64, ) -> Self

Construct a tensor from its nine components in row-major order.

Source

pub fn from_rows(x: Vector3, y: Vector3, z: Vector3) -> Self

Construct from three row vectors.

Source

pub fn from_cols(x: Vector3, y: Vector3, z: Vector3) -> Self

Construct from three column vectors.

Source

pub fn row_x(self) -> Vector3

First (x) row as a vector: (xx, xy, xz).

Source

pub fn row_y(self) -> Vector3

Second (y) row as a vector: (yx, yy, yz).

Source

pub fn row_z(self) -> Vector3

Third (z) row as a vector: (zx, zy, zz).

Source

pub fn col_x(self) -> Vector3

First (x) column as a vector: (xx, yx, zx).

Source

pub fn col_y(self) -> Vector3

Second (y) column as a vector: (xy, yy, zy).

Source

pub fn col_z(self) -> Vector3

Third (z) column as a vector: (xz, yz, zz).

Source

pub fn diag(self) -> Vector3

Diagonal as a vector

Source

pub fn tr(self) -> f64

Trace

Source

pub fn diag_sqr(self) -> f64

Sum of squared diagonal entries (not Frobenius)

Source

pub fn transpose(self) -> Self

Transpose. C++ .T().

Source

pub fn det(self) -> f64

Determinant

Source

pub fn adjunct(self) -> Self

Adjunct (transpose of cofactor matrix)

Source

pub fn cof(self) -> Self

Cofactor matrix = adjunct().T()

Source

pub fn inv(self) -> Self

Inverse = adjunct / det. Panics (debug) if singular.

Source

pub fn safe_inv(self) -> Self

Inverse with 2-D fallback: returns ZERO if nearly singular.

Source

pub fn mat_mul(self, t: Self) -> Self

Matrix multiply: self & rhs. C++ operator&(Tensor, Tensor) / .inner(t2).

Source

pub fn schur(self, t: Self) -> Self

Element-wise product (Schur/Hadamard product).

Source

pub fn mat_vec(self, v: Vector3) -> Vector3

Matrix-vector multiply: T · v. C++ operator&(Tensor, Vector).

Source

pub fn vec_mat(v: Vector3, t: Self) -> Vector3

Vector-matrix multiply: v · T. C++ operator&(Vector, Tensor).

Source

pub fn double_inner(self, t: Self) -> f64

Double contraction (full Frobenius inner product). C++ operator&&(Tensor, Tensor).

Source

pub fn symm(self) -> SymmTensor

Symmetric part: 0.5*(T + T^T). Returns SymmTensor.

Source

pub fn two_symm(self) -> SymmTensor

Twice the symmetric part: T + T^T. Returns SymmTensor.

Source

pub fn skew(self) -> Self

Skew-symmetric (antisymmetric) part: 0.5*(T - T^T).

Source

pub fn dev(self) -> Self

Deviatoric part: T - (tr/3)*I.

Source

pub fn dev2(self) -> Self

Two-thirds deviatoric: T - (2*tr/3)*I.

Source

pub fn dev_symm(self) -> SymmTensor

Deviatoric of symmetric part: symm(T) - (tr/3)*I. Returns SymmTensor.

Source

pub fn dev_two_symm(self) -> SymmTensor

Deviatoric of twice the symmetric part: twoSymm(T) - (2*tr/3)*I. Returns SymmTensor.

Source

pub fn hodge_dual(self) -> Vector3

Hodge dual as a Vector. C++ operator*(Tensor).

Source

pub fn invariant_i(self) -> f64

First invariant: trace

Source

pub fn invariant_ii(self) -> f64

Second invariant: (xxyy + yyzz + xxzz) - (xyyx + yzzy + xzzx)

Source

pub fn invariant_iii(self) -> f64

Third invariant: determinant

Source

pub fn is_identity(self, tol: f64) -> bool

True if approximately the identity.

Source

pub fn lerp(a: Self, b: Self, t: f64) -> Self

Linear interpolation

Trait Implementations§

Source§

impl Add for Tensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, r: Self) -> Self

Performs the + operation. Read more
Source§

impl Add<SphericalTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, st: SphericalTensor) -> Self

Performs the + operation. Read more
Source§

impl Add<SymmTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, st: SymmTensor) -> Self

Performs the + operation. Read more
Source§

impl Add<Tensor> for SphericalTensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, t: Tensor) -> Tensor

Performs the + operation. Read more
Source§

impl Add<Tensor> for SymmTensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, t: Tensor) -> Tensor

Performs the + operation. Read more
Source§

impl AddAssign for Tensor

Source§

fn add_assign(&mut self, r: Self)

Performs the += operation. Read more
Source§

impl Clone for Tensor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Tensor

Source§

impl Debug for Tensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tensor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div<f64> for Tensor

Source§

type Output = Tensor

The resulting type after applying the / operator.
Source§

fn div(self, s: f64) -> Self

Performs the / operation. Read more
Source§

impl From<SphericalTensor> for Tensor

Source§

fn from(st: SphericalTensor) -> Self

Converts to this type from the input type.
Source§

impl From<SymmTensor> for Tensor

Source§

fn from(st: SymmTensor) -> Self

Converts to this type from the input type.
Source§

impl Mul<SphericalTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, st: SphericalTensor) -> Self

Performs the * operation. Read more
Source§

impl Mul<SymmTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, st: SymmTensor) -> Self

Performs the * operation. Read more
Source§

impl Mul<Tensor> for f64

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, t: Tensor) -> Tensor

Performs the * operation. Read more
Source§

impl Mul<Tensor> for SphericalTensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, t: Tensor) -> Tensor

Performs the * operation. Read more
Source§

impl Mul<Tensor> for SymmTensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, t: Tensor) -> Tensor

Performs the * operation. Read more
Source§

impl Mul<f64> for Tensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, s: f64) -> Self

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Tensor

Source§

fn mul_assign(&mut self, s: f64)

Performs the *= operation. Read more
Source§

impl Neg for Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Tensor

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Tensor

Source§

impl Sub for Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, r: Self) -> Self

Performs the - operation. Read more
Source§

impl Sub<SphericalTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, st: SphericalTensor) -> Self

Performs the - operation. Read more
Source§

impl Sub<SymmTensor> for Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, st: SymmTensor) -> Self

Performs the - operation. Read more
Source§

impl Sub<Tensor> for SphericalTensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, t: Tensor) -> Tensor

Performs the - operation. Read more
Source§

impl Sub<Tensor> for SymmTensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, t: Tensor) -> Tensor

Performs the - operation. Read more
Source§

impl SubAssign for Tensor

Source§

fn sub_assign(&mut self, r: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.