Skip to main content

TensorTrain

Struct TensorTrain 

Source
pub struct TensorTrain {
    pub cores: Vec<TtCore>,
    pub shape: [usize; 6],
    pub ranks: Vec<usize>,
    pub domain: Domain,
    pub tolerance: f64,
    pub max_rank: usize,
}
Expand description

Tensor-Train representation of the 6D phase-space distribution f(x,v).

The TT decomposition factors a 6D tensor into a chain of d=6 three-way cores with TT ranks r_0=1, r_1, r_2, r_3, r_4, r_5, r_6=1.

Fields§

§cores: Vec<TtCore>

The 6 TT cores. cores[k] has shape (ranks[k], shape[k], ranks[k+1]).

§shape: [usize; 6]

Grid sizes: [nx1, nx2, nx3, nv1, nv2, nv3].

§ranks: Vec<usize>

TT ranks: [r_0, r_1, r_2, r_3, r_4, r_5, r_6] with r_0 = r_6 = 1.

§domain: Domain

Computational domain (extents, BCs).

§tolerance: f64

Approximation tolerance for TT-SVD and recompression.

§max_rank: usize

Maximum allowed TT rank.

Implementations§

Source§

impl TensorTrain

Source

pub fn new(domain: Domain, max_rank: usize) -> Self

Create a minimal-rank (all ranks 1) TT representing the zero tensor.

Source

pub fn from_snapshot( snap: &PhaseSpaceSnapshot, max_rank: usize, tolerance: f64, domain: &Domain, ) -> Self

TT-SVD decomposition of a full 6D snapshot.

Algorithm (Oseledets 2011, Algorithm 1):

  1. Reshape the full tensor as C = reshape(data, [n_0, n_1*…*n_5]).
  2. For k = 0..4:
    • C has shape (r_{k} * n_k, remaining)
    • Compute truncated SVD: C ≈ U_k * S_k * V_k^T
    • Core k = reshape(U_k, [r_k, n_k, r_{k+1}])
    • C = diag(S_k) * V_k^T for the next step
  3. Core 5 = C (the residual, with r_right = 1).
Source

pub fn evaluate(&self, indices: [usize; 6]) -> f64

Evaluate f at a single 6D index by left-to-right contraction of all cores.

f(i0, i1, i2, i3, i4, i5) = G0[:,i0,:] * G1[:,i1,:] * … * G5[:,i5,:]

Source

pub fn to_full(&self) -> Vec<f64>

Expand the TT back to a full 6D array. Only practical for small grids.

Source

pub fn recompress(&mut self, tolerance: f64)

Recompress the TT to reduce ranks while keeping error below tolerance.

Two-sweep rounding (Oseledets 2011):

  1. Left-to-right QR sweep (left-orthogonalize).
  2. Right-to-left SVD sweep with truncation.
Source

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

Add two TT tensors via rank concatenation (direct sum of cores).

Result has ranks r_self + r_other (before recompression).

Source

pub fn scale(&mut self, factor: f64)

Scale all entries by a constant factor.

Source

pub fn inner_product(&self, other: &TensorTrain) -> f64

TT inner product: <self, other> = sum_{all indices} self(i) * other(i).

Computed by sequential contraction from left to right. O(d * n * r^4).

Source

pub fn norm(&self) -> f64

Frobenius norm: ||self||_F = sqrt(<self, self>).

Trait Implementations§

Source§

impl PhaseSpaceRepr for TensorTrain

Source§

fn compute_density(&self) -> DensityField

Integrate f over all velocities: ρ(x) = ∫f dv³. This is the coupling moment to the Poisson equation.
Source§

fn advect_x(&mut self, _displacement: &DisplacementField, dt: f64)

Drift sub-step: advect f in spatial coordinates by displacement Δx = v·dt. Pure translation in x at constant v.
Source§

fn advect_v(&mut self, acceleration: &AccelerationField, dt: f64)

Kick sub-step: advect f in velocity coordinates by Δv = g·dt. Pure translation in v at constant x.
Source§

fn moment(&self, position: &[f64; 3], order: usize) -> Tensor

Compute velocity moment of order n at given spatial position. Order 0 = density, 1 = mean velocity, 2 = dispersion tensor.
Source§

fn total_mass(&self) -> f64

Total mass M = ∫f dx³dv³. Should be conserved to machine precision.
Source§

fn casimir_c2(&self) -> f64

Casimir invariant C₂ = ∫f² dx³dv³. Increase over time indicates numerical diffusion.
Source§

fn entropy(&self) -> f64

Boltzmann entropy S = −∫f ln f dx³dv³. Should be exactly conserved; growth = numerical error.
Source§

fn stream_count(&self) -> StreamCountField

Number of distinct velocity streams at each spatial point. Detects caustic surfaces (sheet folds).
Source§

fn velocity_distribution(&self, position: &[f64; 3]) -> Vec<f64>

Extract the local velocity distribution f(v|x) at a given spatial position. Used for dark matter detection predictions.
Source§

fn total_kinetic_energy(&self) -> f64

Total kinetic energy T = ½∫fv² dx³dv³.
Source§

fn to_snapshot(&self, time: f64) -> PhaseSpaceSnapshot

Extract a full 6D snapshot of the current state.
Source§

fn as_any(&self) -> &dyn Any

Downcast to concrete type for implementation-specific queries (e.g. HT rank data).
Source§

fn load_snapshot(&mut self, snap: PhaseSpaceSnapshot)

Replace the current state with data from a dense 6D snapshot. 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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,