Skip to main content

Tensor2

Struct Tensor2 

Source
pub struct Tensor2 {
    pub data: [[f64; 3]; 3],
}
Expand description

Second-order tensor (3×3 matrix) stored as row-major [[f64; 3]; 3].

Fields§

§data: [[f64; 3]; 3]

Row-major 3×3 component array: data[i][j] is the (i,j) component.

Implementations§

Source§

impl Tensor2

Source

pub fn new(data: [[f64; 3]; 3]) -> Self

Create a new Tensor2 from a 3×3 array.

Source

pub fn zero() -> Self

Zero tensor.

Source

pub fn identity() -> Self

Second-order identity tensor.

Source

pub fn add(&self, other: &Tensor2) -> Tensor2

Component-wise addition.

Source

pub fn sub(&self, other: &Tensor2) -> Tensor2

Component-wise subtraction.

Source

pub fn scale(&self, s: f64) -> Tensor2

Scalar multiplication.

Source

pub fn dot(&self, other: &Tensor2) -> Tensor2

Matrix–matrix product (A · B).

Source

pub fn transpose(&self) -> Tensor2

Transpose A^T.

Source

pub fn trace(&self) -> f64

Trace: sum of diagonal components.

Source

pub fn det(&self) -> f64

Determinant of the 3×3 matrix.

Source

pub fn inverse(&self) -> Option<Tensor2>

Inverse via cofactor expansion; returns None if |det| < 1e-14.

Source

pub fn sym(&self) -> Tensor2

Symmetric part: (A + A^T) / 2.

Source

pub fn skew(&self) -> Tensor2

Skew-symmetric part: (A − A^T) / 2.

Source

pub fn double_contract(&self, other: &Tensor2) -> f64

Double contraction A:B = Σ_ij A_ij B_ij.

Source

pub fn norm(&self) -> f64

Frobenius norm √(A:A).

Source

pub fn deviatoric(&self) -> Tensor2

Deviatoric part: A − (tr(A)/3) · I.

Source

pub fn hydrostatic(&self) -> f64

Hydrostatic (mean normal) stress: tr(A) / 3.

Source

pub fn von_mises(&self) -> f64

von Mises equivalent: √(3/2 · s:s) where s = deviatoric part.

Source

pub fn eigenvalues_symmetric(&self) -> [f64; 3]

Eigenvalues of a symmetric 3×3 tensor via Cardano’s analytical formula.

The tensor is assumed symmetric; only the lower-triangular part is used. Returns eigenvalues sorted in ascending order.

Source

pub fn outer_product(a: [f64; 3], b: [f64; 3]) -> Tensor2

Outer (dyadic) product a ⊗ b: result_ij = a_i * b_j.

Source

pub fn apply(&self, v: [f64; 3]) -> [f64; 3]

Matrix–vector product: result_i = Σ_j A_ij v_j.

Source§

impl Tensor2

Source

pub fn contract_vec(&self, v: [f64; 3]) -> [f64; 3]

Single contraction: c_i = A_ij * v_j (same as apply, alias).

Source

pub fn dyadic(a: [f64; 3], b: [f64; 3]) -> Tensor2

Tensor outer (dyadic) product from two vectors (static method alias).

Source

pub fn rotate(&self, r: &Tensor2) -> Tensor2

Rotate a tensor by a rotation matrix R: R * A * R^T.

Source

pub fn invariant_i1(&self) -> f64

First invariant I1 = trace(A).

Source

pub fn invariant_i2(&self) -> f64

Second invariant I2 = 0.5 * (trace(A)^2 - trace(A^2)).

Source

pub fn invariant_i3(&self) -> f64

Third invariant I3 = det(A).

Source

pub fn principal_invariants(&self) -> [f64; 3]

Principal invariants as an array [I1, I2, I3].

Source

pub fn decompose_dev_hydro(&self) -> (Tensor2, f64)

Deviatoric and hydrostatic decomposition.

Returns (deviatoric, hydrostatic_scalar).

Source

pub fn from_voigt(v: [f64; 6]) -> Tensor2

Create a tensor from Voigt notation [xx, yy, zz, xy, yz, xz].

Source

pub fn to_voigt(&self) -> [f64; 6]

Convert to Voigt notation.

Source

pub fn effective_strain(&self) -> f64

Effective strain (von Mises strain equivalent).

For a strain tensor: eps_eff = sqrt(2/3 * e_ij * e_ij) where e is the deviatoric strain.

Source

pub fn diagonal(d: [f64; 3]) -> Tensor2

Create a diagonal tensor with given diagonal values.

Source

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

Check if the tensor is symmetric within tolerance.

Source

pub fn matrix_exp_approx(&self) -> Tensor2

Matrix exponential approximation using Taylor series (for small tensors).

exp(A) ≈ I + A + A²/2! + A³/3! + … Uses 10 terms by default.

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> 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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.