Skip to content

Commit

Permalink
Prototype exposing two-body states
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Jan 17, 2024
1 parent 2a34f4e commit e8be9dc
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 157 deletions.
6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/lox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ num = "0.4.0"
thiserror.workspace = true
nom = "7.1.3"
fast_polynomial = "0.1.0"
dyn-clone = "1.0.16"

[dev-dependencies]
proptest = "1.1.0"
Expand Down
14 changes: 10 additions & 4 deletions crates/lox_core/src/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*/

use dyn_clone::{clone_trait_object, DynClone};
use std::f64::consts::PI;
use std::fmt::{Display, Formatter};

Expand Down Expand Up @@ -103,7 +104,8 @@ macro_rules! body {
body! { Sun, 10 }

// Planets.
pub trait Planet: PointMass + Spheroid {}
pub trait Planet: PointMass + Spheroid + DynClone {}
clone_trait_object!(Planet);

body! { Mercury, Planet, 199 }
body! { Venus, Planet, 299 }
Expand Down Expand Up @@ -134,7 +136,8 @@ impl PointMass for SolarSystemBarycenter {
}

// Satellites.
pub trait Satellite: PointMass + TriAxial {}
pub trait Satellite: PointMass + TriAxial + DynClone {}
clone_trait_object!(Satellite);

body! { Moon, Satellite, 301 }
body! { Phobos, Satellite, 401 }
Expand Down Expand Up @@ -290,7 +293,8 @@ body! { Kerberos, 904 }
body! { Styx, 905 }

// Minor bodies.
pub trait MinorBody: PointMass + TriAxial {}
pub trait MinorBody: PointMass + TriAxial + DynClone {}
clone_trait_object!(MinorBody);

body! {Gaspra, 9511010 }
body! {Ida, 2431010 }
Expand Down Expand Up @@ -541,10 +545,12 @@ pub trait TriAxial: Ellipsoid {
fn along_orbit_radius(&self) -> f64;
}

pub trait PointMass: Body {
pub trait PointMass: Body + DynClone {
fn gravitational_parameter(&self) -> f64;
}

clone_trait_object!(PointMass);

pub type PolynomialCoefficients = (f64, f64, f64, &'static [f64]);

pub type NutationPrecessionCoefficients = (&'static [f64], &'static [f64]);
Expand Down
34 changes: 21 additions & 13 deletions crates/lox_core/src/two_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ use crate::two_body::elements::{cartesian_to_keplerian, keplerian_to_cartesian};

pub mod elements;

type Elements = (f64, f64, f64, f64, f64, f64);
pub type Elements = (f64, f64, f64, f64, f64, f64);

pub trait TwoBody {
pub trait Center {
type Center;
fn epoch(&self) -> Epoch;

fn center(&self) -> Self::Center;
}

pub trait TwoBody {
fn epoch(&self) -> Epoch;
fn position(&self) -> DVec3;
fn velocity(&self) -> DVec3;
fn cartesian(&self) -> (DVec3, DVec3);
Expand Down Expand Up @@ -51,16 +55,18 @@ impl<T: PointMass + Copy> Cartesian<T> {
}
}

impl<T: PointMass + Copy> TwoBody for Cartesian<T> {
impl<T: PointMass + Copy> Center for Cartesian<T> {
type Center = T;

fn epoch(&self) -> Epoch {
self.epoch
}

fn center(&self) -> Self::Center {
self.center
}
}

impl<T: PointMass + Copy> TwoBody for Cartesian<T> {
fn epoch(&self) -> Epoch {
self.epoch
}

fn position(&self) -> DVec3 {
self.position
Expand Down Expand Up @@ -142,16 +148,18 @@ impl<T: PointMass + Copy> Keplerian<T> {
}
}

impl<T: PointMass + Copy> TwoBody for Keplerian<T> {
impl<T: PointMass + Copy> Center for Keplerian<T> {
type Center = T;

fn epoch(&self) -> Epoch {
self.epoch
}

fn center(&self) -> Self::Center {
self.center
}
}

impl<T: PointMass + Copy> TwoBody for Keplerian<T> {
fn epoch(&self) -> Epoch {
self.epoch
}

fn position(&self) -> DVec3 {
self.cartesian().0
Expand Down
1 change: 1 addition & 0 deletions crates/lox_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.20.0"
numpy = "0.20.0"
lox_core.workspace = true
thiserror.workspace = true
3 changes: 3 additions & 0 deletions crates/lox_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
dependencies = [
"numpy~=1.26"
]

[tool.maturin]
features = ["pyo3/extension-module"]
Loading

0 comments on commit e8be9dc

Please sign in to comment.