Skip to content

Commit 450e821

Browse files
Error Control struct is now an enum instead of a trait
1 parent f59f8b2 commit 450e821

35 files changed

+410
-482
lines changed

examples/03_geo_analysis/raise.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use nyx::{
1919
},
2020
io::{gravity::HarmonicsMem, ExportCfg},
2121
md::{prelude::Objective, StateParameter},
22-
propagators::{PropOpts, Propagator, RSSCartesianStep},
22+
propagators::{ErrorControl, IntegratorOptions, Propagator},
2323
Spacecraft,
2424
};
2525
use std::{error::Error, sync::Arc};
@@ -117,9 +117,9 @@ fn main() -> Result<(), Box<dyn Error>> {
117117
// We specify a minimum step in the propagator because the Ruggiero control would otherwise drive this step very low.
118118
let (final_state, traj) = Propagator::rk89(
119119
sc_dynamics.clone(),
120-
PropOpts::builder()
120+
IntegratorOptions::builder()
121121
.min_step(10.0_f64.seconds())
122-
.error_ctrl(RSSCartesianStep {})
122+
.error_ctrl(ErrorControl::RSSCartesianStep)
123123
.build(),
124124
)
125125
.with(sc, almanac.clone())

examples/03_geo_analysis/stationkeeping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use nyx::{
2020
io::{gravity::HarmonicsMem, ExportCfg},
2121
mc::{MonteCarlo, MultivariateNormal, StateDispersion},
2222
md::{prelude::Objective, StateParameter},
23-
propagators::{PropOpts, Propagator, RSSCartesianStep},
23+
propagators::{ErrorControl, IntegratorOptions, Propagator},
2424
Spacecraft, State,
2525
};
2626
use std::{error::Error, sync::Arc};
@@ -103,9 +103,9 @@ fn main() -> Result<(), Box<dyn Error>> {
103103
// Build the propagator setup.
104104
let setup = Propagator::rk89(
105105
sc_dynamics.clone(),
106-
PropOpts::builder()
106+
IntegratorOptions::builder()
107107
.min_step(10.0_f64.seconds())
108-
.error_ctrl(RSSCartesianStep {})
108+
.error_ctrl(ErrorControl::RSSCartesianStep)
109109
.build(),
110110
);
111111

src/mc/montecarlo.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::mc::results::{PropResult, Results, Run};
2424
use crate::mc::DispersedState;
2525
use crate::md::trajectory::Interpolatable;
2626
use crate::md::EventEvaluator;
27-
use crate::propagators::{ErrorCtrl, Propagator};
27+
use crate::propagators::Propagator;
2828
#[cfg(not(target_arch = "wasm32"))]
2929
use crate::time::Unit;
3030
use crate::time::{Duration, Epoch};
@@ -89,9 +89,9 @@ where
8989

9090
/// Generate states and propagate each independently until a specific event is found `trigger` times.
9191
#[allow(clippy::needless_lifetimes)]
92-
pub fn run_until_nth_event<D, E, F>(
92+
pub fn run_until_nth_event<D, F>(
9393
self,
94-
prop: Propagator<D, E>,
94+
prop: Propagator<D>,
9595
almanac: Arc<Almanac>,
9696
max_duration: Duration,
9797
event: &F,
@@ -100,7 +100,7 @@ where
100100
) -> Results<S, PropResult<S>>
101101
where
102102
D: Dynamics<StateType = S>,
103-
E: ErrorCtrl,
103+
104104
F: EventEvaluator<S>,
105105
DefaultAllocator: Allocator<<D::StateType as State>::Size>
106106
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
@@ -113,9 +113,9 @@ where
113113
/// Generate states and propagate each independently until a specific event is found `trigger` times.
114114
#[must_use = "Monte Carlo result must be used"]
115115
#[allow(clippy::needless_lifetimes)]
116-
pub fn resume_run_until_nth_event<D, E, F>(
116+
pub fn resume_run_until_nth_event<D, F>(
117117
&self,
118-
prop: Propagator<D, E>,
118+
prop: Propagator<D>,
119119
almanac: Arc<Almanac>,
120120
skip: usize,
121121
max_duration: Duration,
@@ -125,7 +125,7 @@ where
125125
) -> Results<S, PropResult<S>>
126126
where
127127
D: Dynamics<StateType = S>,
128-
E: ErrorCtrl,
128+
129129
F: EventEvaluator<S>,
130130
DefaultAllocator: Allocator<<D::StateType as State>::Size>
131131
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
@@ -188,16 +188,16 @@ where
188188
/// Generate states and propagate each independently until a specific event is found `trigger` times.
189189
#[must_use = "Monte Carlo result must be used"]
190190
#[allow(clippy::needless_lifetimes)]
191-
pub fn run_until_epoch<D, E>(
191+
pub fn run_until_epoch<D>(
192192
self,
193-
prop: Propagator<D, E>,
193+
prop: Propagator<D>,
194194
almanac: Arc<Almanac>,
195195
end_epoch: Epoch,
196196
num_runs: usize,
197197
) -> Results<S, PropResult<S>>
198198
where
199199
D: Dynamics<StateType = S>,
200-
E: ErrorCtrl,
200+
201201
DefaultAllocator: Allocator<<D::StateType as State>::Size>
202202
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
203203
+ Allocator<<D::StateType as State>::VecLength>,
@@ -209,17 +209,17 @@ where
209209
/// Resumes a Monte Carlo run by skipping the first `skip` items, generating states only after that, and propagate each independently until the specified epoch.
210210
#[must_use = "Monte Carlo result must be used"]
211211
#[allow(clippy::needless_lifetimes)]
212-
pub fn resume_run_until_epoch<D, E>(
212+
pub fn resume_run_until_epoch<D>(
213213
&self,
214-
prop: Propagator<D, E>,
214+
prop: Propagator<D>,
215215
almanac: Arc<Almanac>,
216216
skip: usize,
217217
end_epoch: Epoch,
218218
num_runs: usize,
219219
) -> Results<S, PropResult<S>>
220220
where
221221
D: Dynamics<StateType = S>,
222-
E: ErrorCtrl,
222+
223223
DefaultAllocator: Allocator<<D::StateType as State>::Size>
224224
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
225225
+ Allocator<<D::StateType as State>::VecLength>,

src/md/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod prelude {
3636
pub use crate::dynamics::{Dynamics, NyxError};
3737
pub use crate::io::gravity::HarmonicsMem;
3838
pub use crate::md::objective::Objective;
39-
pub use crate::propagators::{PropOpts, Propagator};
39+
pub use crate::propagators::{IntegratorOptions, Propagator};
4040
pub use crate::time::{Duration, Epoch, TimeUnits, Unit};
4141
pub use crate::Spacecraft;
4242
pub use crate::{State, TimeTagged};

src/md/opti/multipleshooting/altitude_heuristic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ use super::{
2727
};
2828
use crate::errors::TargetingError;
2929
use crate::md::{prelude::*, PropSnafu};
30-
use crate::propagators::error_ctrl::ErrorCtrl;
3130
use crate::{Orbit, Spacecraft};
3231

33-
impl<'a, E: ErrorCtrl> MultipleShooting<'a, E, Node, 3, 3> {
32+
impl<'a> MultipleShooting<'a, Node, 3, 3> {
3433
/// Builds a multiple shooting structure assuming that the optimal trajectory is near a linear
3534
/// heuristic in geodetic altitude and direction.
3635
/// For example, if x0 has an altitude of 100 km and xf has an altitude
@@ -42,7 +41,7 @@ impl<'a, E: ErrorCtrl> MultipleShooting<'a, E, Node, 3, 3> {
4241
node_count: usize,
4342
angular_velocity_deg_s: f64,
4443
body_frame: Frame,
45-
prop: &'a Propagator<SpacecraftDynamics, E>,
44+
prop: &'a Propagator<SpacecraftDynamics>,
4645
almanac: Arc<Almanac>,
4746
) -> Result<Self, MultipleShootingError> {
4847
if node_count < 3 {

src/md/opti/multipleshooting/equidistant_heuristic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ use super::multishoot::MultipleShooting;
2121
pub use super::CostFunction;
2222
use crate::errors::TargetingError;
2323
use crate::md::prelude::*;
24-
use crate::propagators::error_ctrl::ErrorCtrl;
2524
use crate::{Orbit, Spacecraft};
2625

27-
impl<'a, E: ErrorCtrl> MultipleShooting<'a, E, Node, 3, 3> {
26+
impl<'a> MultipleShooting<'a, Node, 3, 3> {
2827
/// Builds a multiple shooting structure assuming that the optimal trajectory is a straight line
2928
/// between the start and end points. The position of the nodes will be update at each iteration
3029
/// of the outer loop.
@@ -33,7 +32,7 @@ impl<'a, E: ErrorCtrl> MultipleShooting<'a, E, Node, 3, 3> {
3332
x0: Spacecraft,
3433
xf: Orbit,
3534
node_count: usize,
36-
prop: &'a Propagator<SpacecraftDynamics, E>,
35+
prop: &'a Propagator<SpacecraftDynamics>,
3736
) -> Result<Self, TargetingError> {
3837
if node_count < 3 {
3938
error!("At least three nodes are needed for a multiple shooting optimization");

src/md/opti/multipleshooting/multishoot.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::linalg::{DMatrix, DVector, SVector};
2424
use crate::md::opti::solution::TargeterSolution;
2525
use crate::md::optimizer::Optimizer;
2626
use crate::md::{prelude::*, TargetingError};
27-
use crate::propagators::error_ctrl::ErrorCtrl;
2827
use crate::pseudo_inverse;
2928
use crate::{Orbit, Spacecraft};
3029

@@ -39,15 +38,9 @@ pub trait MultishootNode<const O: usize>: Copy + Into<[Objective; O]> {
3938
/// Source of implementation: "Low Thrust Optimization in Cislunar and Translunar space", 2018 Nathan Re (Parrish)
4039
/// OT: size of the objectives for each node (e.g. 3 if the objectives are X, Y, Z).
4140
/// VT: size of the variables for targeter node (e.g. 4 if the objectives are thrust direction (x,y,z) and thrust level).
42-
pub struct MultipleShooting<
43-
'a,
44-
E: ErrorCtrl,
45-
T: MultishootNode<OT>,
46-
const VT: usize,
47-
const OT: usize,
48-
> {
41+
pub struct MultipleShooting<'a, T: MultishootNode<OT>, const VT: usize, const OT: usize> {
4942
/// The propagator setup (kind, stages, etc.)
50-
pub prop: &'a Propagator<SpacecraftDynamics, E>,
43+
pub prop: &'a Propagator<SpacecraftDynamics>,
5144
/// List of nodes of the optimal trajectory
5245
pub targets: Vec<T>,
5346
/// Starting point, must be a spacecraft equipped with a thruster
@@ -66,9 +59,7 @@ pub struct MultipleShooting<
6659
pub all_dvs: Vec<SVector<f64, VT>>,
6760
}
6861

69-
impl<'a, E: ErrorCtrl, T: MultishootNode<OT>, const VT: usize, const OT: usize>
70-
MultipleShooting<'a, E, T, VT, OT>
71-
{
62+
impl<'a, T: MultishootNode<OT>, const VT: usize, const OT: usize> MultipleShooting<'a, T, VT, OT> {
7263
/// Solve the multiple shooting problem by finding the arrangement of nodes to minimize the cost function.
7364
pub fn solve(
7465
&mut self,
@@ -287,8 +278,8 @@ impl<'a, E: ErrorCtrl, T: MultishootNode<OT>, const VT: usize, const OT: usize>
287278
}
288279
}
289280

290-
impl<'a, E: ErrorCtrl, T: MultishootNode<OT>, const VT: usize, const OT: usize> fmt::Display
291-
for MultipleShooting<'a, E, T, VT, OT>
281+
impl<'a, T: MultishootNode<OT>, const VT: usize, const OT: usize> fmt::Display
282+
for MultipleShooting<'a, T, VT, OT>
292283
{
293284
#[allow(clippy::or_fun_call, clippy::clone_on_copy)]
294285
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -357,9 +348,9 @@ impl<T: MultishootNode<O>, const O: usize> fmt::Display for MultipleShootingSolu
357348
impl<T: MultishootNode<O>, const O: usize> MultipleShootingSolution<T, O> {
358349
/// Allows building the trajectories between different nodes
359350
/// This will rebuild the targeters and apply the solutions sequentially
360-
pub fn build_trajectories<E: ErrorCtrl>(
351+
pub fn build_trajectories(
361352
&self,
362-
prop: &Propagator<SpacecraftDynamics, E>,
353+
prop: &Propagator<SpacecraftDynamics>,
363354
almanac: Arc<Almanac>,
364355
) -> Result<Vec<ScTraj>, MultipleShootingError> {
365356
let mut trajz = Vec::with_capacity(self.nodes.len());

src/md/opti/optimizer.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ use crate::md::AstroSnafu;
2626
use crate::md::PropSnafu;
2727
use crate::md::StateParameter;
2828
pub use crate::md::{Variable, Vary};
29-
use crate::propagators::error_ctrl::ErrorCtrl;
3029
use std::fmt;
3130

3231
use super::solution::TargeterSolution;
3332

33+
// TODO(now): rename to Differential Controller
34+
3435
/// An optimizer structure with V control variables and O objectives.
3536
#[derive(Clone)]
36-
pub struct Optimizer<'a, E: ErrorCtrl, const V: usize, const O: usize> {
37+
pub struct Optimizer<'a, const V: usize, const O: usize> {
3738
/// The propagator setup (kind, stages, etc.)
38-
pub prop: &'a Propagator<SpacecraftDynamics, E>,
39+
pub prop: &'a Propagator<SpacecraftDynamics>,
3940
/// The list of objectives of this targeter
4041
pub objectives: [Objective; O],
4142
/// An optional frame (and Cosm) to compute the objectives in.
@@ -49,7 +50,7 @@ pub struct Optimizer<'a, E: ErrorCtrl, const V: usize, const O: usize> {
4950
pub iterations: usize,
5051
}
5152

52-
impl<'a, E: ErrorCtrl, const V: usize, const O: usize> fmt::Display for Optimizer<'a, E, V, O> {
53+
impl<'a, const V: usize, const O: usize> fmt::Display for Optimizer<'a, V, O> {
5354
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5455
let mut objmsg = String::from("");
5556
for obj in &self.objectives {
@@ -65,12 +66,9 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> fmt::Display for Optimize
6566
}
6667
}
6768

68-
impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 3, O> {
69+
impl<'a, const O: usize> Optimizer<'a, 3, O> {
6970
/// Create a new Targeter which will apply an impulsive delta-v correction.
70-
pub fn delta_v(
71-
prop: &'a Propagator<SpacecraftDynamics, E>,
72-
objectives: [Objective; O],
73-
) -> Self {
71+
pub fn delta_v(prop: &'a Propagator<SpacecraftDynamics>, objectives: [Objective; O]) -> Self {
7472
Self {
7573
prop,
7674
objectives,
@@ -86,10 +84,7 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 3, O> {
8684
}
8785

8886
/// Create a new Targeter which will MOVE the position of the spacecraft at the correction epoch
89-
pub fn delta_r(
90-
prop: &'a Propagator<SpacecraftDynamics, E>,
91-
objectives: [Objective; O],
92-
) -> Self {
87+
pub fn delta_r(prop: &'a Propagator<SpacecraftDynamics>, objectives: [Objective; O]) -> Self {
9388
Self {
9489
prop,
9590
objectives,
@@ -105,7 +100,7 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 3, O> {
105100
}
106101

107102
/// Create a new Targeter which will apply an impulsive delta-v correction on all components of the VNC frame. By default, max step is 0.5 km/s.
108-
pub fn vnc(prop: &'a Propagator<SpacecraftDynamics, E>, objectives: [Objective; O]) -> Self {
103+
pub fn vnc(prop: &'a Propagator<SpacecraftDynamics>, objectives: [Objective; O]) -> Self {
109104
Self {
110105
prop,
111106
objectives,
@@ -121,10 +116,10 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 3, O> {
121116
}
122117
}
123118

124-
impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 4, O> {
119+
impl<'a, const O: usize> Optimizer<'a, 4, O> {
125120
/// Create a new Targeter which will apply a continuous thrust for the whole duration of the segment
126121
pub fn thrust_dir(
127-
prop: &'a Propagator<SpacecraftDynamics, E>,
122+
prop: &'a Propagator<SpacecraftDynamics>,
128123
objectives: [Objective; O],
129124
) -> Self {
130125
Self {
@@ -143,10 +138,10 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 4, O> {
143138
}
144139
}
145140

146-
impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 7, O> {
141+
impl<'a, const O: usize> Optimizer<'a, 7, O> {
147142
/// Create a new Targeter which will apply a continuous thrust for the whole duration of the segment
148143
pub fn thrust_dir_rate(
149-
prop: &'a Propagator<SpacecraftDynamics, E>,
144+
prop: &'a Propagator<SpacecraftDynamics>,
150145
objectives: [Objective; O],
151146
) -> Self {
152147
Self {
@@ -168,10 +163,10 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 7, O> {
168163
}
169164
}
170165

171-
impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 10, O> {
166+
impl<'a, const O: usize> Optimizer<'a, 10, O> {
172167
/// Create a new Targeter which will apply a continuous thrust for the whole duration of the segment
173168
pub fn thrust_profile(
174-
prop: &'a Propagator<SpacecraftDynamics, E>,
169+
prop: &'a Propagator<SpacecraftDynamics>,
175170
objectives: [Objective; O],
176171
) -> Self {
177172
Self {
@@ -196,10 +191,10 @@ impl<'a, E: ErrorCtrl, const O: usize> Optimizer<'a, E, 10, O> {
196191
}
197192
}
198193

199-
impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> {
194+
impl<'a, const V: usize, const O: usize> Optimizer<'a, V, O> {
200195
/// Create a new Targeter which will apply an impulsive delta-v correction.
201196
pub fn new(
202-
prop: &'a Propagator<SpacecraftDynamics, E>,
197+
prop: &'a Propagator<SpacecraftDynamics>,
203198
variables: [Variable; V],
204199
objectives: [Objective; O],
205200
) -> Self {
@@ -215,7 +210,7 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> {
215210

216211
/// Create a new Targeter which will apply an impulsive delta-v correction.
217212
pub fn in_frame(
218-
prop: &'a Propagator<SpacecraftDynamics, E>,
213+
prop: &'a Propagator<SpacecraftDynamics>,
219214
variables: [Variable; V],
220215
objectives: [Objective; O],
221216
objective_frame: Frame,
@@ -232,7 +227,7 @@ impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> {
232227

233228
/// Create a new Targeter which will apply an impulsive delta-v correction on the specified components of the VNC frame.
234229
pub fn vnc_with_components(
235-
prop: &'a Propagator<SpacecraftDynamics, E>,
230+
prop: &'a Propagator<SpacecraftDynamics>,
236231
variables: [Variable; V],
237232
objectives: [Objective; O],
238233
) -> Self {

src/md/opti/raphson_finite_diff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ use crate::md::{prelude::*, AstroSnafu, GuidanceSnafu, UnderdeterminedProblemSna
2626
use crate::md::{PropSnafu, StateParameter};
2727
pub use crate::md::{Variable, Vary};
2828
use crate::polyfit::CommonPolynomial;
29-
use crate::propagators::error_ctrl::ErrorCtrl;
3029
use crate::pseudo_inverse;
3130
use hifitime::TimeUnits;
3231
use rayon::prelude::*;
3332
use snafu::{ensure, ResultExt};
3433
#[cfg(not(target_arch = "wasm32"))]
3534
use std::time::Instant;
3635

37-
impl<'a, E: ErrorCtrl, const V: usize, const O: usize> Optimizer<'a, E, V, O> {
36+
impl<'a, const V: usize, const O: usize> Optimizer<'a, V, O> {
3837
/// Differential correction using finite differencing
3938
#[allow(clippy::comparison_chain)]
4039
pub fn try_achieve_fd(

0 commit comments

Comments
 (0)