Added full cartesian support with (the beginning of) frames
This commit is contained in:
1 parent
412d96dde0
commit
b089b206f5
11 files changed
+731
-167
No files matched your search
+20
-17
@@ -6,31 +6,36 @@
|
||||
|
||||
use std::hint::black_box;
|
||||
|
||||
use astrokit::body::Body;
|
||||
use astrokit::cartesian::Cartesian;
|
||||
use astrokit::frames::Frame;
|
||||
use astrokit::kepler::{self, Degeneracy, Keplerian};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use nalgebra::Vector3;
|
||||
|
||||
const MU: f64 = 3.986004415e14;
|
||||
const MU: f64 = Body::EARTH.mu;
|
||||
|
||||
/// Inclined, near-circular LEO. Just outside the degeneracy tolerance, so it
|
||||
/// takes the general branch.
|
||||
fn leo() -> (Vector3<f64>, Vector3<f64>) {
|
||||
(
|
||||
fn leo() -> Cartesian<f64> {
|
||||
Cartesian::new(
|
||||
Vector3::new(
|
||||
4.263868426884883e6,
|
||||
5.146189057155391e6,
|
||||
1.1310208421331816e6,
|
||||
),
|
||||
Vector3::new(-5923.454461876975, 4496.802639690076, 1870.3893008991558),
|
||||
Frame::EARTH_J2000,
|
||||
)
|
||||
}
|
||||
|
||||
/// GEO: circular and equatorial, so it takes the doubly-degenerate branch.
|
||||
fn geo() -> (Vector3<f64>, Vector3<f64>) {
|
||||
fn geo() -> Cartesian<f64> {
|
||||
let radius = 4.2164e7;
|
||||
(
|
||||
Cartesian::new(
|
||||
Vector3::new(radius, 0.0, 0.0),
|
||||
Vector3::new(0.0, kepler::circular_speed(radius, MU), 0.0),
|
||||
Frame::EARTH_J2000,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -73,14 +78,14 @@ fn bench_anomalies(c: &mut Criterion) {
|
||||
fn bench_conversions(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("kepler/conversions");
|
||||
|
||||
let (r, v) = leo();
|
||||
let leo = leo();
|
||||
group.bench_function("from_cartesian/leo", |b| {
|
||||
b.iter(|| Keplerian::from_cartesian(black_box(r), black_box(v), black_box(MU)))
|
||||
b.iter(|| Keplerian::from_cartesian(&black_box(leo)))
|
||||
});
|
||||
|
||||
let (r_geo, v_geo) = geo();
|
||||
let geo = geo();
|
||||
group.bench_function("from_cartesian/geo", |b| {
|
||||
b.iter(|| Keplerian::from_cartesian(black_box(r_geo), black_box(v_geo), black_box(MU)))
|
||||
b.iter(|| Keplerian::from_cartesian(&black_box(geo)))
|
||||
});
|
||||
|
||||
let elements = Keplerian {
|
||||
@@ -90,30 +95,28 @@ fn bench_conversions(c: &mut Criterion) {
|
||||
raan: 0.5,
|
||||
aop: 1.0,
|
||||
true_anomaly: 2.0,
|
||||
frame: Frame::EARTH_J2000,
|
||||
degeneracy: Degeneracy::None,
|
||||
};
|
||||
group.bench_function("to_cartesian", |b| {
|
||||
b.iter(|| black_box(elements).to_cartesian(black_box(MU)))
|
||||
b.iter(|| black_box(elements).to_cartesian())
|
||||
});
|
||||
|
||||
group.bench_function("round_trip", |b| {
|
||||
b.iter(|| {
|
||||
let elements = Keplerian::from_cartesian(black_box(r), black_box(v), MU);
|
||||
black_box(elements.to_cartesian(MU))
|
||||
})
|
||||
b.iter(|| Keplerian::from_cartesian(&black_box(leo)).to_cartesian())
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn bench_invariants(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("kepler/invariants");
|
||||
let (r, v) = leo();
|
||||
let leo = leo();
|
||||
|
||||
group.bench_function("specific_energy", |b| {
|
||||
b.iter(|| kepler::specific_energy(black_box(r), black_box(v), black_box(MU)))
|
||||
b.iter(|| black_box(leo).specific_energy())
|
||||
});
|
||||
group.bench_function("specific_angular_momentum", |b| {
|
||||
b.iter(|| kepler::specific_angular_momentum(black_box(r), black_box(v)))
|
||||
b.iter(|| black_box(leo).specific_angular_momentum())
|
||||
});
|
||||
group.finish();
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fn velocity() -> Vector3<f64> {
|
||||
}
|
||||
|
||||
fn two_body() -> Vec<Dynamics> {
|
||||
vec![TwoBody { mu: MU }]
|
||||
vec![TwoBody { body: Body::EARTH }]
|
||||
}
|
||||
|
||||
/// One derivative evaluation, per layout. The layout should cost nothing.
|
||||
@@ -45,7 +45,7 @@ fn bench_derivative(c: &mut Criterion) {
|
||||
|
||||
let assembly = Assembly::new(
|
||||
dynamics::build::<f64, 6, Orbit>(&two_body()),
|
||||
Context::new(epoch()),
|
||||
Context::new(epoch(), Frame::EARTH_J2000),
|
||||
);
|
||||
let y = Orbit.with_position(position()).with_velocity(velocity());
|
||||
group.bench_function("two_body/Orbit", |b| {
|
||||
@@ -54,7 +54,7 @@ fn bench_derivative(c: &mut Criterion) {
|
||||
|
||||
let assembly = Assembly::new(
|
||||
dynamics::build::<f64, 7, OrbitMass>(&two_body()),
|
||||
Context::new(epoch()),
|
||||
Context::new(epoch(), Frame::EARTH_J2000),
|
||||
);
|
||||
let y = OrbitMass
|
||||
.with_position(position())
|
||||
@@ -66,7 +66,7 @@ fn bench_derivative(c: &mut Criterion) {
|
||||
|
||||
let assembly = Assembly::new(
|
||||
dynamics::build::<f64, 14, Full>(&two_body()),
|
||||
Context::new(epoch()),
|
||||
Context::new(epoch(), Frame::EARTH_J2000),
|
||||
);
|
||||
let y = Full
|
||||
.with_position(position())
|
||||
|
||||
Reference in new issue
Block a user