Skip to main content

Spacetime

Struct Spacetime 

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

The three local spacetime quantities that fully determine how fast an observer’s proper time advances relative to coordinate time.

This structure holds the gravitational lapse factor, the observer’s local velocity, and the curvature information needed for the library’s unified proper-time model. It is the low-level input that Drift uses internally.

Fields§

§alpha: Real

Gravitational lapse (redshift) factor α.
This is the factor by which clocks run slower in a gravitational potential.

§beta: Real

Local three-velocity β = v/c measured in the coordinate rest frame.

§kretschmann: Real

Kretschmann scalar (a scalar measure of spacetime curvature).
In the weak-field regime — where |Φ|/c² ≪ 1 and the gravitational field varies over macroscopic distances — this value is effectively zero and can safely be left at its default. It only becomes numerically relevant in strong-field environments such as:

  • the surface or immediate vicinity of neutron stars (where |Φ|/c² ≈ 0.15–0.25);
  • regions near a black-hole event horizon (e.g. the photon rings imaged by the Event Horizon Telescope around M87* or Sgr A*);
  • the final inspiral and merger phases of binary neutron-star or black-hole systems (as observed by LIGO/Virgo in events such as GW170817 or GW150914).

In these regimes a realistic non-zero value (estimated from the local potential and a characteristic length scale) activates the library’s intrinsic Planck-scale saturation term.

Implementations§

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.

Source§

impl Spacetime

Source

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

Source

pub const fn proper_time_rate(&self) -> Real

Returns the instantaneous proper-time rate dτ/dt from this snapshot.

Convenience method that internally uses the same unified calculation as Drift::proper_time_rate.

Source

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

Convenience for direct gravimeter / sensor paths.

Source

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

Converts the Newtonian gravitational potential Φ/c² (where Φ < 0 for bound orbits) into the relativistic lapse factor α = √(1 + 2Φ/c²).

This function implements the standard weak-field approximation used in general relativity. It is valid when the dimensionless gravitational potential satisfies |Φ|/c² ≪ 1. In this regime spacetime is nearly flat, gravitational time dilation is a small perturbation, and higher-order curvature effects can safely be neglected. The resulting α gives the factor by which clocks tick more slowly in a gravitational well relative to a distant reference clock.

This approximation is excellent for solar-system navigation, GNSS satellites, most spacecraft operations, and any environment where |Φ|/c² remains much smaller than ~0.01. It is exported from deep_time::alpha_from_weak_field_potential and is the recommended way to obtain the lapse factor when you have the local Newtonian potential.

The weak-field regime breaks down in strong-gravity environments where |Φ|/c² approaches or exceeds ~0.1. Such conditions occur near:

  • the surface or immediate vicinity of neutron stars (where |Φ|/c² ≈ 0.15–0.25);
  • regions near a black-hole event horizon (e.g. the photon rings imaged by the Event Horizon Telescope around M87* or Sgr A*);
  • the final inspiral and merger phases of binary neutron-star or black-hole systems (as observed by LIGO/Virgo in events such as GW170817 or GW150914).

In those extreme regimes this function alone is no longer sufficient; a full strong-field treatment (including curvature information passed to Spacetime) is required.

Source

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

Kretschmann scalar from total relativity Computes the Kretschmann scalar (\mathcal{K}) from the total gravitational relativity experienced by a local observer at the observer’s spacetime point.

This is the canonical, physics-true convenience function for the master Lagrangian. It uses:

  • phi = Φ/c² — the total local gravitational potential (redshift/gravity effect) felt by the observer from all masses.
  • characteristic_length_scale — the typical length scale (in meters) over which the gravitational field varies at the observer’s location.

For existing weak-field users (Earth orbit, GNSS, solar-system navigation): Supply your existing phi value and set characteristic_length_scale = 0.0. The function safely returns 0.0 (the correct value in double precision).

For strong-field / future users (black-hole flybys, neutron stars, direct gravimeters, or full metric evaluation): Supply the measured or computed (\phi) and the real local length scale (or the value from your metric). The function returns a physically accurate non-zero curvature.

Source

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

Recommended constructor for most users.

Computes both the gravitational lapse factor α and an estimate of the Kretschmann scalar from the dimensionless gravitational potential Φ/c² and a characteristic length scale.

The lapse factor α is computed using alpha_from_weak_field_potential, which is the standard weak-field expression α = √(1 + 2Φ/c²). It is valid when the dimensionless gravitational potential satisfies |Φ|/c² ≪ 1. In this regime spacetime is nearly flat, gravitational time dilation is a small perturbation, and higher-order curvature effects can safely be neglected. The resulting α gives the factor by which clocks tick more slowly in a gravitational well relative to a distant reference clock.

This approximation is excellent for solar-system navigation, GNSS satellites, most spacecraft operations, and any environment where |Φ|/c² remains much smaller than ~0.01. It is exported from deep_time::alpha_from_weak_field_potential and is the recommended way to obtain the lapse factor when you have the local Newtonian potential.

The weak-field regime breaks down in strong-gravity environments where |Φ|/c² approaches or exceeds ~0.1. Such conditions occur near:

  • the surface or immediate vicinity of neutron stars (where |Φ|/c² ≈ 0.15–0.25);
  • regions near a black-hole event horizon (e.g. the photon rings imaged by the Event Horizon Telescope around M87* or Sgr A*);
  • the final inspiral and merger phases of binary neutron-star or black-hole systems (as observed by LIGO/Virgo in events such as GW170817 or GW150914).

In those extreme regimes this function alone is no longer sufficient; a full strong-field treatment (including curvature information passed to Spacetime) is required.

For the characteristic_length_scale parameter:

  • In weak-field conditions, pass 0.0. This returns exactly the same clock rate as the classic relativistic formulation and sets the Kretschmann scalar to zero (its default value for all ordinary navigation, GNSS, or solar-system work).
  • In strong-field conditions, supply the typical length scale (in meters) over which the gravitational field varies significantly at the observer’s location. This allows the library to estimate the Kretschmann scalar and activate the intrinsic Planck-scale saturation term when curvature becomes extreme.
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)>,

Computes the total Newtonian gravitational potential Φ at a given position from an arbitrary collection of point-mass bodies (Sun, Earth, Moon, planets, asteroids, etc.).

This is the standard method used by real mission planners (Apollo, Artemis, Mars orbiters, lunar landers) and in open-source astrodynamics libraries (SPICE/NAIF, Orekit, GMAT, poliastro). It evaluates

[ \Phi = -\sum_i \frac{GM_i}{r_i} ]

§Example (realistic cislunar trajectory)
use deep_time::{Position, Spacetime};

let bodies = [
    (Position::from_au(0.0, 0.0, 0.0), 1.3271244e20),     // Sun
    (Position::from_au(1.0, 0.0, 0.0), 3.9860044e14),     // Earth
    (Position::from_au(1.00257, 0.0, 0.0), 4.9048695e12), // Moon
];

let position = Position::from_au(1.001, 0.001, 0.0); // e.g. spacecraft, asteroid, etc.

let phi = Spacetime::grav_potential_from_point_masses(
    position,
    bodies.iter().copied(),
);

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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 Tsify for Spacetime

Source§

const DECL: &'static str = "/**\n * The three local spacetime quantities that fully determine how fast an observer\u{2019}s\n * proper time advances relative to coordinate time.\n *\n * This structure holds the gravitational lapse factor, the observer\u{2019}s local velocity,\n * and the curvature information needed for the library\u{2019}s unified proper-time model.\n * It is the low-level input that `Drift` uses internally.\n */\nexport interface Spacetime {\n /**\n * Gravitational lapse (redshift) factor \u{3b1}. \n * This is the factor by which clocks run slower in a gravitational potential.\n */\n alpha: Real;\n /**\n * Local three-velocity \u{3b2} = v/c measured in the coordinate rest frame.\n */\n beta: Real;\n /**\n * Kretschmann scalar (a scalar measure of spacetime curvature). \n * In the weak-field regime \u{2014} where |\u{3a6}|/c\u{b2} \u{226a} 1 and the gravitational field varies\n * over macroscopic distances \u{2014} this value is effectively zero and can safely be\n * left at its default. It only becomes numerically relevant in strong-field\n * environments such as:\n *\n * - the surface or immediate vicinity of neutron stars (where |\u{3a6}|/c\u{b2} \u{2248} 0.15\u{2013}0.25);\n * - regions near a black-hole event horizon (e.g. the photon rings imaged by the\n * Event Horizon Telescope around M87* or Sgr A*);\n * - the final inspiral and merger phases of binary neutron-star or black-hole\n * systems (as observed by LIGO/Virgo in events such as GW170817 or GW150914).\n *\n * In these regimes a realistic non-zero value (estimated from the local potential\n * and a characteristic length scale) activates the library\u{2019}s intrinsic Planck-scale\n * saturation term.\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,

Source§

impl Copy for Spacetime

Source§

impl StructuralPartialEq for Spacetime

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> 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: 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: ErasableGeneric<Repr = Self::Repr>,

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,