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: DomainComputational domain (extents, BCs).
tolerance: f64Approximation tolerance for TT-SVD and recompression.
max_rank: usizeMaximum allowed TT rank.
Implementations§
Source§impl TensorTrain
impl TensorTrain
Sourcepub fn new(domain: Domain, max_rank: usize) -> Self
pub fn new(domain: Domain, max_rank: usize) -> Self
Create a minimal-rank (all ranks 1) TT representing the zero tensor.
Sourcepub fn from_snapshot(
snap: &PhaseSpaceSnapshot,
max_rank: usize,
tolerance: f64,
domain: &Domain,
) -> Self
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):
- Reshape the full tensor as C = reshape(data, [n_0, n_1*…*n_5]).
- 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
- Core 5 = C (the residual, with r_right = 1).
Sourcepub fn evaluate(&self, indices: [usize; 6]) -> f64
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,:]
Sourcepub fn to_full(&self) -> Vec<f64>
pub fn to_full(&self) -> Vec<f64>
Expand the TT back to a full 6D array. Only practical for small grids.
Sourcepub fn recompress(&mut self, tolerance: f64)
pub fn recompress(&mut self, tolerance: f64)
Recompress the TT to reduce ranks while keeping error below tolerance.
Two-sweep rounding (Oseledets 2011):
- Left-to-right QR sweep (left-orthogonalize).
- Right-to-left SVD sweep with truncation.
Sourcepub fn add(&self, other: &TensorTrain) -> TensorTrain
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).
Sourcepub fn inner_product(&self, other: &TensorTrain) -> f64
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).
Trait Implementations§
Source§impl PhaseSpaceRepr for TensorTrain
impl PhaseSpaceRepr for TensorTrain
Source§fn compute_density(&self) -> DensityField
fn compute_density(&self) -> DensityField
Source§fn advect_x(&mut self, _displacement: &DisplacementField, dt: f64)
fn advect_x(&mut self, _displacement: &DisplacementField, dt: f64)
Source§fn advect_v(&mut self, acceleration: &AccelerationField, dt: f64)
fn advect_v(&mut self, acceleration: &AccelerationField, dt: f64)
Source§fn moment(&self, position: &[f64; 3], order: usize) -> Tensor
fn moment(&self, position: &[f64; 3], order: usize) -> Tensor
Source§fn total_mass(&self) -> f64
fn total_mass(&self) -> f64
Source§fn casimir_c2(&self) -> f64
fn casimir_c2(&self) -> f64
Source§fn entropy(&self) -> f64
fn entropy(&self) -> f64
Source§fn stream_count(&self) -> StreamCountField
fn stream_count(&self) -> StreamCountField
Source§fn velocity_distribution(&self, position: &[f64; 3]) -> Vec<f64>
fn velocity_distribution(&self, position: &[f64; 3]) -> Vec<f64>
Source§fn total_kinetic_energy(&self) -> f64
fn total_kinetic_energy(&self) -> f64
Source§fn to_snapshot(&self, time: f64) -> PhaseSpaceSnapshot
fn to_snapshot(&self, time: f64) -> PhaseSpaceSnapshot
Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Source§fn load_snapshot(&mut self, snap: PhaseSpaceSnapshot)
fn load_snapshot(&mut self, snap: PhaseSpaceSnapshot)
Auto Trait Implementations§
impl Freeze for TensorTrain
impl RefUnwindSafe for TensorTrain
impl Send for TensorTrain
impl Sync for TensorTrain
impl Unpin for TensorTrain
impl UnsafeUnpin for TensorTrain
impl UnwindSafe for TensorTrain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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