1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//! Gauss-Jackson configuration.
//!
//! Port of JEOD's `GaussJacksonConfig` (`gauss_jackson_config.hh/cc`).
/// Configuration for the Gauss-Jackson integrator.
///
/// JEOD: `GaussJacksonConfig` in `gauss_jackson_config.hh`.
/// All fields are public — this is essentially a struct.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GaussJacksonConfig {
/// Order immediately after priming. Must be even, ≤ 14.
/// JEOD default: 4.
pub initial_order: usize,
/// Operational order. Must be even, ≥ initial_order, ≤ 14.
/// JEOD default: 12.
pub final_order: usize,
/// Number of step-doubling stages between priming and operational.
/// JEOD default: `(final_order - initial_order) / 2`.
pub ndoubling_steps: usize,
/// Maximum correction iterations during bootstrap editing.
/// 0 = predict-only, 1 = one correction, ≥2 = iterative correction.
/// JEOD default: 10.
pub max_correction_iterations: usize,
/// Relative convergence tolerance.
/// JEOD default: 1e-14.
pub relative_tolerance: f64,
/// Absolute convergence tolerance.
/// JEOD default: 1e-10.
pub absolute_tolerance: f64,
/// Continue when the corrector or a bootstrap edit fails to converge.
///
/// JEOD's `GaussJacksonIntegrationGroup` logs a warning and continues
/// when the predictor-corrector fails to converge within
/// [`max_correction_iterations`](Self::max_correction_iterations), or
/// when a bootstrap edit accepts a non-converged correction. We diverge
/// from JEOD by default — non-convergence panics — because a degraded
/// position silently propagating into the rest of a mission trajectory
/// is the silent-wrong-physics class of failure the fail-loudly rule
/// exists to prevent (#485 C1).
///
/// Set this to `true` to restore JEOD-faithful behavior: a `log::warn!`
/// is emitted and integration continues. Use only when matching a JEOD
/// reference run exactly is worth the silent-degradation risk (typically
/// short reproduction runs of JEOD verif sims), and document the choice
/// at the call site.
pub allow_non_convergence: bool,
}
impl Default for GaussJacksonConfig {
/// JEOD constructor default: initial=4, final=12, ndoubling=4. The
/// `allow_non_convergence` flag defaults to `false` — see the field's
/// rustdoc for the JEOD-faithful opt-in.
fn default() -> Self {
Self {
initial_order: 4,
final_order: 12,
ndoubling_steps: 4, // (12 - 4) / 2
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: 1e-10,
allow_non_convergence: false,
}
}
}
impl GaussJacksonConfig {
/// Create a config with fixed order, no step-doubling.
/// `initial_order = final_order = order`, `ndoubling_steps = 0`.
/// Bootstrap editing still runs (controlled by `max_correction_iterations`)
/// to refine primed data — only step-doubling is skipped.
pub fn with_order(order: usize) -> Self {
Self {
initial_order: order,
final_order: order,
ndoubling_steps: 0,
..Default::default()
}
}
/// JEOD standard configuration.
/// JEOD: `GaussJacksonConfig::standard_configuration()`.
/// initial=8, final=12, ndoubling=2, tolerances=1e-14.
///
/// `allow_non_convergence` defaults to `false` — see the field's
/// rustdoc for the JEOD-faithful opt-in semantics.
pub fn standard() -> Self {
Self {
initial_order: 8,
final_order: 12,
ndoubling_steps: 2,
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: 1e-14,
allow_non_convergence: false,
}
}
/// Non-panicking validation. Returns a list of error descriptions.
///
/// Used by `Simulation::validate()` to report all issues at once.
/// JEOD: `validate_config()` in `gauss_jackson_config.cc`.
pub fn check(&self) -> Vec<String> {
let mut errors = Vec::new();
let is_valid_order = |o: usize| (2..=14).contains(&o) && o.is_multiple_of(2);
// JEOD_INV: IG.04 — initial_order must be even integer in [2, 14]
if !is_valid_order(self.initial_order) {
errors.push(format!(
"initial_order {} must be even, ≥ 2, ≤ 14",
self.initial_order
));
}
// JEOD_INV: IG.05 — final_order must be even integer in [initial_order, 14]
if !is_valid_order(self.final_order) {
errors.push(format!(
"final_order {} must be even, ≥ 2, ≤ 14",
self.final_order
));
} else if self.final_order < self.initial_order {
errors.push(format!(
"final_order {} < initial_order {}",
self.final_order, self.initial_order
));
}
// JEOD_INV: IG.06 — ndoubling_steps ≤ 20
if self.ndoubling_steps > 20 {
errors.push(format!(
"ndoubling_steps {} must be ≤ 20",
self.ndoubling_steps
));
}
// JEOD_INV: IG.07 — relative_tolerance finite and in [0, 1]
if !self.relative_tolerance.is_finite() || !(0.0..=1.0).contains(&self.relative_tolerance) {
errors.push(format!(
"relative_tolerance {} must be finite and in [0, 1]",
self.relative_tolerance
));
}
// JEOD_INV: IG.08 — absolute_tolerance finite and ≥ 0.
// (JEOD's message mentions relative_tolerance here — that's a known
// message-string bug in `gauss_jackson_config.cc`; the actual variable
// checked is absolute_tolerance, which is what we validate.)
if !self.absolute_tolerance.is_finite() || self.absolute_tolerance < 0.0 {
errors.push(format!(
"absolute_tolerance {} must be finite and ≥ 0",
self.absolute_tolerance
));
}
// JEOD doesn't validate max_correction_iterations, but cap it to
// prevent overflow in stage-cap arithmetic (order * iterations).
if self.max_correction_iterations > 1000 {
errors.push(format!(
"max_correction_iterations {} must be ≤ 1000",
self.max_correction_iterations
));
}
errors
}
/// Validate the configuration, panicking on invalid values.
///
/// JEOD: `GaussJacksonConfig::validate_configuration()`.
pub fn validate(&self) {
let errors = self.check();
assert!(
errors.is_empty(),
"Invalid GaussJacksonConfig: {}",
errors.join("; ")
);
}
}
#[cfg(test)]
mod tests {
use super::*;
/// IG.04: `initial_order` must be an even integer in [2, 14]. Odd
/// orders are rejected because Gauss-Jackson's symmetric corrector
/// coefficients are tabulated only for even orders.
#[test]
#[should_panic(expected = "initial_order 3 must be even")]
fn ig_04_panics_on_odd_initial_order() {
// JEOD_INV: IG.04 — initial_order must be even integer in [2, 14]
GaussJacksonConfig {
initial_order: 3,
final_order: 4,
ndoubling_steps: 0,
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: 1e-10,
allow_non_convergence: false,
}
.validate();
}
/// IG.05: `final_order` must be ≥ `initial_order`. A final order
/// below the initial order would require shrinking the corrector
/// stencil mid-flight, which Gauss-Jackson is not formulated for.
#[test]
#[should_panic(expected = "final_order 2 < initial_order 8")]
fn ig_05_panics_on_final_below_initial() {
// JEOD_INV: IG.05 — final_order must be even integer in [initial_order, 14]
GaussJacksonConfig {
initial_order: 8,
final_order: 2,
ndoubling_steps: 0,
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: 1e-10,
allow_non_convergence: false,
}
.validate();
}
/// IG.06: `ndoubling_steps` must be ≤ 20. The doubling cap bounds
/// the tour count `1 << ndoubling_steps`, which otherwise overflows
/// the stage-cap arithmetic in the integration kernel.
#[test]
#[should_panic(expected = "ndoubling_steps 21 must be ≤ 20")]
fn ig_06_panics_on_excessive_doubling() {
// JEOD_INV: IG.06 — ndoubling_steps ≤ 20
GaussJacksonConfig {
initial_order: 4,
final_order: 4,
ndoubling_steps: 21,
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: 1e-10,
allow_non_convergence: false,
}
.validate();
}
/// IG.07: `relative_tolerance` must be finite and in [0, 1]. A
/// tolerance > 1 is meaningless (the corrector would accept any
/// finite error), and a non-finite tolerance corrupts convergence
/// arithmetic.
#[test]
#[should_panic(expected = "relative_tolerance")]
fn ig_07_panics_on_relative_tolerance_above_one() {
// JEOD_INV: IG.07 — relative_tolerance finite and in [0, 1]
GaussJacksonConfig {
initial_order: 4,
final_order: 4,
ndoubling_steps: 0,
max_correction_iterations: 10,
relative_tolerance: 2.0,
absolute_tolerance: 1e-10,
allow_non_convergence: false,
}
.validate();
}
/// IG.08: `absolute_tolerance` must be finite and ≥ 0. A negative
/// tolerance flips the convergence comparison and lets the corrector
/// accept arbitrary errors. (JEOD's diagnostic message names the
/// `relative_tolerance` field at this site — a known bug in
/// `gauss_jackson_config.cc` — but the variable actually validated
/// is `absolute_tolerance`; our diagnostic names the right field.)
#[test]
#[should_panic(expected = "absolute_tolerance -1 must be finite and ≥ 0")]
fn ig_08_panics_on_negative_absolute_tolerance() {
// JEOD_INV: IG.08 — absolute_tolerance finite and ≥ 0
GaussJacksonConfig {
initial_order: 4,
final_order: 4,
ndoubling_steps: 0,
max_correction_iterations: 10,
relative_tolerance: 1e-14,
absolute_tolerance: -1.0,
allow_non_convergence: false,
}
.validate();
}
}