DSST osculating state passed to EventDetector.g(...) inconsistent with states passed to EventHandler and StepHandler
From a broader perspective it seems that there is a flaw where the DSST does not update the short period coefficients before calling event detectors. The short period coefficients are updated by a step handler, which is called after events are detected. That means that the short period coefficients are extrapolated from the last step instead of interpolated. In particular when starting the short period coefficients are extrapolated from a single state set in the beforeIntegration(...)
method.
One of the consequences of the current implementation of short periodic terms in the DSST is that event handlers and step handlers see a different state for the same point in time. This will cause some confusion and potentially larger errors with events that use RESET_STATE
.
Workaround is to run the DSST in ephemeris mode, then add the events to the BoundedPropagator
retrieved from getGeneratedEphemeris()
. The problem here is that Actions other than CONTINUE
are not possible.
For example, this test case:
@Test
public void testEventStateVsStepHandlerState() {
double[][] tol = DSSTPropagator.tolerances(1e-6, initialOrbit);
DormandPrince853Integrator integrator = new DormandPrince853Integrator(3600, 3600, tol[0], tol[1]);
integrator.setInitialStepSize(3600);
DSSTPropagator propagator = new DSSTPropagator(integrator, PropagationType.OSCULATING);
propagator.setInitialState(new SpacecraftState(initialOrbit));
double gm = Constants.EIGEN5C_EARTH_MU;
propagator.addForceModel(new DSSTThirdBody(CelestialBodyFactory.getMoon(), gm));
//EphemerisGenerator ephemerisGenerator = propagator.getEphemerisGenerator();
//propagator.propagate(initialOrbit.getDate().shiftedBy(86400));
//Propagator prop = ephemerisGenerator.getGeneratedEphemeris();
List<SpacecraftState> states = new ArrayList<>();
propagator.addEventDetector(new FunctionalDetector()
.withFunction(s -> {
System.out.println("g: " + s);
states.add(s);
return s.getDate().durationFrom(initialOrbit.getDate().shiftedBy(3600 - 0.816));
})
.withHandler((s, detector, increasing) -> {
System.out.println("Handler: " + s);
return Action.STOP;
}
)
);
propagator.setStepHandler(interpolator -> {
System.out.println("interpolator previous: " + interpolator.getPreviousState());
System.out.println("interpolator current: " + interpolator.getCurrentState());
});
final SpacecraftState finalState = propagator.propagate(initialOrbit.getDate().shiftedBy(86400.0));
System.out.println(finalState);
System.out.println(states.get(states.size()-2).getPVCoordinates().getPosition().subtract(finalState.getPVCoordinates().getPosition()).getNorm());
}
produces this output:
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T11:58:55.816Z; a: 6878137.000000089; ex: -1.2026805393762522E-14; ey: 2.8982684554763733E-15; hx: 3.122922026103705E-16; hy: -2.3830572684917597E-15; lv: -2.8902886340464875E-13; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@30c7da1e, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:08:55.816Z; a: 6878137.534968372; ex: 9.430457850326931E-8; ey: -3.0190952709010325E-8; hx: 9.186654619879427E-9; hy: 3.3333705802309796E-9; lv: 38.04841258728833; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@19dfb72a, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:18:55.816Z; a: 6878137.177462091; ex: 1.246431646683715E-7; ey: -1.1298355342313434E-7; hx: 1.4857455474772088E-8; hy: 1.1927591152811629E-8; lv: 76.09682138468527; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@17c68925, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:28:55.816Z; a: 6878136.459034158; ex: 1.3638366026989008E-7; ey: -2.1890962410741675E-7; hx: 1.4588110221069753E-8; hy: 1.8523213244245744E-8; lv: 114.14522177115917; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@7e0ea639, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:38:55.816Z; a: 6878136.466516326; ex: 1.0346221132486464E-7; ey: -2.4832853582046256E-7; hx: 1.4936959254002136E-8; hy: 1.8809477316511615E-8; lv: 152.1936196655541; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@3d24753a, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:48:55.816Z; a: 6878137.210293077; ex: -5.033989354251364E-9; ey: -2.2780176478097455E-7; hx: 2.186776799806081E-8; hy: 1.8142627222393367E-8; lv: 190.24202674300895; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@59a6e353, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.816Z; a: 6878137.554647031; ex: -8.630781183758184E-8; ey: -1.8733734751653937E-7; hx: 3.1432896018176415E-8; hy: 2.3685078411044097E-8; lv: 228.2904459082263; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@7a0ac6e3, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:48:55.816Z; a: 6878137.210293077; ex: -5.033989354251364E-9; ey: -2.2780176478097455E-7; hx: 2.186776799806081E-8; hy: 1.8142627222393367E-8; lv: 190.24202674300895; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@506e6d5e, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:53:55.816Z; a: 6878137.502089529; ex: -5.5490197101299194E-8; ey: -2.134333873916712E-7; hx: 2.6900243697710334E-8; hy: 2.000637677792735E-8; lv: 209.26623521537837; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@67b64c45, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:48:55.816Z; a: 6878137.210293077; ex: -5.033989354251364E-9; ey: -2.2780176478097455E-7; hx: 2.186776799806081E-8; hy: 1.8142627222393367E-8; lv: 190.24202674300895; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@4411d970, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.816Z; a: 6878137.554647031; ex: -8.630781183758184E-8; ey: -1.8733734751653937E-7; hx: 3.1432896018176415E-8; hy: 2.3685078411044097E-8; lv: 228.2904459082263; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@6442b0a6, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.554877086; ex: -8.625110788575974E-8; ey: -1.8743274476732697E-7; hx: 3.1422293429243904E-8; hy: 2.3673109202129882E-8; lv: 228.2387000535064; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@60f82f98, mass=1000.0, additional={}}
g: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.00000000000065Z; a: 6878137.554877086; ex: -8.625110788575974E-8; ey: -1.8743274476732702E-7; hx: 3.1422293429243904E-8; hy: 2.367310920212988E-8; lv: 228.23870005350636; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@edf4efb, mass=1000.0, additional={}}
interpolator previous: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T11:58:55.816Z; a: 6878137.000000089; ex: -1.2026805393762522E-14; ey: 2.8982684554763733E-15; hx: 3.122922026103705E-16; hy: -2.3830572684917597E-15; lv: -2.8902886340464875E-13; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@2f7a2457, mass=1000.0, additional={}}
interpolator current: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.555734211; ex: -8.495462504671336E-8; ey: -1.8903167214364522E-7; hx: 3.144214035071233E-8; hy: 2.3609200431179313E-8; lv: 228.23869997539154; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@566776ad, mass=1000.0, additional={}}
Handler: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.555734211; ex: -8.495462504671336E-8; ey: -1.8903167214364522E-7; hx: 3.144214035071233E-8; hy: 2.3609200431179313E-8; lv: 228.23869997539154; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@6108b2d7, mass=1000.0, additional={}}
interpolator previous: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.555734211; ex: -8.495462504671336E-8; ey: -1.8903167214364522E-7; hx: 3.144214035071233E-8; hy: 2.3609200431179313E-8; lv: 228.23869997539154; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@6cd8737, mass=1000.0, additional={}}
interpolator current: SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.555734211; ex: -8.495462504671336E-8; ey: -1.8903167214364522E-7; hx: 3.144214035071233E-8; hy: 2.3609200431179313E-8; lv: 228.23869997539154; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@22f71333, mass=1000.0, additional={}}
SpacecraftState{orbit=equinoctial parameters: {date: 2000-01-01T12:58:55.0000000000002Z; a: 6878137.555734211; ex: -8.495462504671336E-8; ey: -1.8903167214364522E-7; hx: 3.144214035071233E-8; hy: 2.3609200431179313E-8; lv: 228.23869997539154; mu: 3.986004415E14; frame: GCRF;}, attitude=org.orekit.attitudes.Attitude@380fb434, mass=1000.0, additional={}}
0.009515143877119577
States are similar but have 1 cm differences between the g function and the other methods of retrieving state.
Discovered during #798 (closed)