Search in sources :

Example 1 with GFunction

use of org.orekit.propagation.events.FunctionalDetector.GFunction in project Orekit by CS-SI.

the class FunctionalDetectorTest method testFunctionalDetector.

/**
 * Check {@link FunctionalDetector}.
 *
 * @throws OrekitException on error.
 */
@Test
public void testFunctionalDetector() throws OrekitException {
    // setup
    GFunction g = SpacecraftState::getMass;
    EventHandler<EventDetector> handler = (s, detector, increasing) -> Action.STOP;
    // action
    FunctionalDetector detector = new FunctionalDetector().withMaxIter(1).withThreshold(2).withMaxCheck(3).withGFunction(g).withHandler(handler);
    // verify
    MatcherAssert.assertThat(detector.getMaxIterationCount(), CoreMatchers.is(1));
    MatcherAssert.assertThat(detector.getThreshold(), CoreMatchers.is(2.0));
    MatcherAssert.assertThat(detector.getMaxCheckInterval(), CoreMatchers.is(3.0));
    MatcherAssert.assertThat(detector.getHandler(), CoreMatchers.is(handler));
    MatcherAssert.assertThat(detector.getGFunction(), CoreMatchers.is(g));
    SpacecraftState state = new SpacecraftState(new CartesianOrbit(new PVCoordinates(new Vector3D(1, 2, 3), new Vector3D(4, 5, 6)), FramesFactory.getGCRF(), AbsoluteDate.CCSDS_EPOCH, 4), 5);
    MatcherAssert.assertThat(detector.g(state), CoreMatchers.is(5.0));
    MatcherAssert.assertThat(detector.eventOccurred(null, false), CoreMatchers.is(Action.STOP));
}
Also used : CartesianOrbit(org.orekit.orbits.CartesianOrbit) CoreMatchers(org.hamcrest.CoreMatchers) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FramesFactory(org.orekit.frames.FramesFactory) Test(org.junit.Test) PVCoordinates(org.orekit.utils.PVCoordinates) MatcherAssert(org.hamcrest.MatcherAssert) EventHandler(org.orekit.propagation.events.handlers.EventHandler) OrekitException(org.orekit.errors.OrekitException) SpacecraftState(org.orekit.propagation.SpacecraftState) GFunction(org.orekit.propagation.events.FunctionalDetector.GFunction) Action(org.orekit.propagation.events.handlers.EventHandler.Action) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) CartesianOrbit(org.orekit.orbits.CartesianOrbit) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) PVCoordinates(org.orekit.utils.PVCoordinates) GFunction(org.orekit.propagation.events.FunctionalDetector.GFunction) Test(org.junit.Test)

Aggregations

CoreMatchers (org.hamcrest.CoreMatchers)1 MatcherAssert (org.hamcrest.MatcherAssert)1 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)1 Test (org.junit.Test)1 OrekitException (org.orekit.errors.OrekitException)1 FramesFactory (org.orekit.frames.FramesFactory)1 CartesianOrbit (org.orekit.orbits.CartesianOrbit)1 SpacecraftState (org.orekit.propagation.SpacecraftState)1 GFunction (org.orekit.propagation.events.FunctionalDetector.GFunction)1 EventHandler (org.orekit.propagation.events.handlers.EventHandler)1 Action (org.orekit.propagation.events.handlers.EventHandler.Action)1 AbsoluteDate (org.orekit.time.AbsoluteDate)1 PVCoordinates (org.orekit.utils.PVCoordinates)1