Skip to main content

Spacetime

Struct Spacetime 

Source
pub struct Spacetime {
    pub alpha: Real,
    pub beta: Real,
    pub kretschmann: Real,
}
Expand description

Snapshot of the local quantities that set a clock’s rate (d\tau/dt).

Think of this as “how gravity and motion look right here, right now” for a clock:

  • α — gravitational redshift factor (deeper in a well → smaller α → slower clocks).
  • β — speed as a fraction of light speed ((v/c)).
  • kretschmann — a curvature measure; leave at 0.0 for almost all Earth/solar-system work.

Trajectory APIs either take Spacetime samples directly, or build them from velocity and potential via Spacetime::from_potential_velocity_and_scale.

Instantaneous rate: Spacetime::proper_time_rate.

Fields§

§alpha: Real

Gravitational lapse (redshift) factor α.

Clocks run slower where gravity is stronger: α < 1 in a potential well. In the weak field, α ≈ √(1 + 2Φ/c²) with Φ < 0.

§beta: Real

Local three-velocity β = v/c in the coordinate rest frame used for the analysis.

§kretschmann: Real

Kretschmann scalar (curvature invariant), in geometric units of the model.

For solar-system, GNSS, and similar work leave this 0.0 — the curvature correction is negligible. Non-zero values matter only in extreme gravity (near compact objects), where you may estimate K from potential and a length scale (see Spacetime::kretschmann_from_potential_and_scale) or supply K from a metric.

Implementations§

Source§

impl Spacetime

Source

pub const fn new(alpha: Real, beta: Real, kretschmann: Real) -> Spacetime

Source

pub const fn proper_time_rate(&self) -> Real

Instantaneous proper-time rate (d\tau/dt) for this snapshot.

Dimensionless: 1.0 means the clock tracks coordinate time; values a little below 1.0 are typical when moving or sitting in a gravitational well. Same calculation as Drift::proper_time_rate after Drift::from_spacetime.

Source

pub const fn from_gravitic_and_velocity( alpha: Real, velocity: Velocity, kretschmann: Real, ) -> Spacetime

Build from lapse α, a velocity vector, and Kretschmann K.

Sets β from Velocity::beta. Pass kretschmann = 0.0 for ordinary weak-field work.

Source

pub const fn alpha_from_weak_field_potential( grav_potential_over_c2: Real, ) -> Real

Weak-field lapse from dimensionless potential: α = √(1 + 2Φ/c²).

Given how deep you are in a gravity well (as Φ/c²), return the factor by which clocks run slow. Φ is negative for bound gravity, so α < 1.

§Validity

Good when |Φ|/c² ≪ 1 (Earth, solar system, most spacecraft). Not sufficient alone near neutron stars or black holes (|Φ|/c² ≳ 0.1); then you need a strong-field metric treatment and usually a non-zero Kretschmann on Spacetime.

§Note on units

Argument is Φ/c² (dimensionless), not Φ in m²/s². Trajectory *_from_states APIs take SI Φ and divide by (c^2) for you.

Source

pub const fn kretschmann_from_potential_and_scale( grav_potential_over_c2: Real, characteristic_length_scale: Real, ) -> Real

Estimate Kretschmann scalar (\mathcal{K} \approx 48,\phi^2 / L^4).

Optional helper to guess curvature from potential strength and a length scale. For normal flight timing you do not need this: pass characteristic_length_scale = 0.0 and get K = 0.

§Parameters
  • grav_potential_over_c2 — Φ/c² (typically negative). The estimate uses φ², so the sign of φ does not matter for K.
  • characteristic_length_scale — meters. Use 0.0 to disable (recommended default). A positive L is a curvature scale; for a single spherical mass the Schwarzschild match is L = r with |φ| = GM/(c² r). L cannot be recovered from φ alone in general.

Background: relativity model.

Source

pub const fn from_potential_velocity_and_scale( grav_potential_over_c2: Real, velocity: Velocity, characteristic_length_scale: Real, ) -> Spacetime

Build Spacetime from dimensionless potential Φ/c², velocity, and length scale.

Turn “how deep in the well” and “how fast I’m moving” into the α, β, K snapshot used for clock rates.

§Parameters
  • grav_potential_over_c2Φ/c² (dimensionless), not SI Φ.
  • velocity — m/s; only speed enters (via β).
  • characteristic_length_scale — pass 0.0 for solar-system / GNSS work (K = 0). Positive L only if you want the optional K estimate.

For SI potential (m²/s²), divide by (c^2) first, or use trajectory proper_time_*_from_states which does that conversion.

Weak-field α is valid for |Φ|/c² ≪ 1. Strong gravity needs more than this constructor alone.

Source

pub const fn grav_potential_from_alpha(alpha: Real) -> Real

Recovers the Newtonian gravitational potential Φ (m²/s²) from the gravitational lapse factor α using the weak-field relation.

[ \alpha = \sqrt{1 + \frac{2\Phi}{c^2}} \quad\implies\quad \Phi = \frac{c^2}{2}(\alpha^2 - 1) ]

This is the inverse of Spacetime::alpha_from_weak_field_potential.

Source

pub fn grav_potential_from_point_masses<I>( position: &Position, bodies: I, ) -> Real
where I: IntoIterator<Item = (Position, Real)>,

Newtonian point-mass potential Φ = −Σ GMᵢ / rᵢ at a position (m²/s²).

Sums “how much gravity well” you feel from a list of bodies treated as point masses. The result is negative near masses. Use it to build samples for trajectory proper-time APIs, or convert to α via Φ/c² and Spacetime::alpha_from_weak_field_potential.

§Limits

Point masses only — no Earth (J_2), no tides, no extended bodies. Fine for rough multi-body Φ or cislunar order-of-magnitude work; LEO-grade timing usually needs multipoles from a full gravity model.

Body positions and the evaluation point must share the same coordinate frame.

§Example
use deep_time::{Position, Spacetime};

let bodies = [
    (Position::from_au(0.0, 0.0, 0.0), 1.3271244e20),     // Sun GM
    (Position::from_au(1.0, 0.0, 0.0), 3.9860044e14),     // Earth GM
    (Position::from_au(1.00257, 0.0, 0.0), 4.9048695e12), // Moon GM
];
let position = Position::from_au(1.001, 0.001, 0.0);
let phi = Spacetime::grav_potential_from_point_masses(
    &position,
    bodies.iter().cloned(),
);
assert!(phi < 0.0);
Source§

impl Spacetime

Source

pub const WIRE_SIZE: usize = 24

Size of the canonical wire representation in bytes (24 bytes).

Source

pub fn to_wire_bytes(&self) -> [u8; 24]

Serializes this Spacetime snapshot into a fixed 24-byte buffer.

All fields are stored as little-endian IEEE 754 f64.

Source

pub fn from_wire_bytes(bytes: &[u8]) -> Option<Self>

Deserializes a Spacetime from exactly 24 bytes.

§Security

Accepts any f64 bit pattern (including NaN/Inf) to match the type’s own invariants. Fixed size makes it immune to length-based attacks. Safe for untrusted input.

Trait Implementations§

Source§

impl Clone for Spacetime

Source§

fn clone(&self) -> Spacetime

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 Debug for Spacetime

Source§

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

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

impl<'de> Deserialize<'de> for Spacetime

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Spacetime

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Spacetime

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Spacetime

Source§

impl Tsify for Spacetime

Source§

const DECL: &'static str = "/**\n * Snapshot of the local quantities that set a clock\u{2019}s rate \\\\(d\\\\tau/dt\\\\).\n *\n * Think of this as \u{201c}how gravity and motion look right here, right now\u{201d} for a\n * clock:\n *\n * - **\u{3b1}** \u{2014} gravitational redshift factor (deeper in a well \u{2192} smaller \u{3b1} \u{2192}\n * slower clocks).\n * - **\u{3b2}** \u{2014} speed as a fraction of light speed (\\\\(v/c\\\\)).\n * - **kretschmann** \u{2014} a curvature measure; leave at `0.0` for almost all\n * Earth/solar-system work.\n *\n * Trajectory APIs either take [`Spacetime`] samples directly, or build them\n * from velocity and potential via\n * [`Spacetime::from_potential_velocity_and_scale`].\n *\n * Instantaneous rate: [`Spacetime::proper_time_rate`].\n */\nexport interface Spacetime {\n /**\n * Gravitational lapse (redshift) factor \u{3b1}.\n *\n * Clocks run slower where gravity is stronger: \u{3b1} &lt; 1 in a potential well.\n * In the weak field, \u{3b1} \u{2248} \u{221a}(1 + 2\u{3a6}/c\u{b2}) with \u{3a6} &lt; 0.\n */\n alpha: Real;\n /**\n * Local three-velocity \u{3b2} = v/c in the coordinate rest frame used for the analysis.\n */\n beta: Real;\n /**\n * Kretschmann scalar (curvature invariant), in geometric units of the model.\n *\n * For solar-system, GNSS, and similar work leave this **0.0** \u{2014} the\n * curvature correction is negligible. Non-zero values matter only in\n * extreme gravity (near compact objects), where you may estimate K from\n * potential and a length scale (see\n * [`Spacetime::kretschmann_from_potential_and_scale`]) or supply K from a\n * metric.\n */\n kretschmann: Real;\n}"

Source§

const SERIALIZATION_CONFIG: SerializationConfig

Source§

type JsType = JsType

Source§

fn into_js(&self) -> Result<Self::JsType, Error>
where Self: Serialize,

Source§

fn from_js<T>(js: T) -> Result<Self, Error>
where T: Into<JsValue>, Self: DeserializeOwned,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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 = 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more