Commit 02165794 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Merge branch 'hipparchus-issue-223-change' into develop

parents 0e329630 316ac5f5
......@@ -33,6 +33,8 @@ import org.orekit.propagation.Propagator;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.EventDetector;
import org.orekit.propagation.events.FieldEventDetector;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.propagation.events.handlers.FieldEventHandler;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.FieldAbsoluteDate;
import org.orekit.utils.AngularDerivativesFilter;
......@@ -170,14 +172,23 @@ public class AttitudesSequence implements AttitudeProvider {
/** {@inheritDoc} */
@Override
public Action eventOccurred(final FieldSpacecraftState<T> s, final boolean increasing) {
return sw.eventOccurred(s.toSpacecraftState(), increasing);
}
/** {@inheritDoc} */
@Override
public FieldSpacecraftState<T> resetState(final FieldSpacecraftState<T> oldState) {
return new FieldSpacecraftState<>(field, sw.resetState(oldState.toSpacecraftState()));
public FieldEventHandler<T> getHandler() {
return new FieldEventHandler<T>() {
/** {@inheritDoc} */
@Override
public Action eventOccurred(final FieldSpacecraftState<T> s,
final FieldEventDetector<T> detector,
final boolean increasing) {
return sw.eventOccurred(s.toSpacecraftState(), sw, increasing);
}
/** {@inheritDoc} */
@Override
public FieldSpacecraftState<T> resetState(final FieldEventDetector<T> detector,
final FieldSpacecraftState<T> oldState) {
return new FieldSpacecraftState<>(field, sw.resetState(sw, oldState.toSpacecraftState()));
}
};
}
});
......@@ -302,7 +313,7 @@ public class AttitudesSequence implements AttitudeProvider {
/** Switch specification.
* @param <T> class type for the generic version
*/
private class Switch<T extends EventDetector> implements EventDetector {
private class Switch<T extends EventDetector> implements EventDetector, EventHandler {
/** Event. */
private final T event;
......@@ -403,7 +414,12 @@ public class AttitudesSequence implements AttitudeProvider {
}
/** {@inheritDoc} */
public Action eventOccurred(final SpacecraftState s, final boolean increasing) {
public EventHandler getHandler() {
return this;
}
/** {@inheritDoc} */
public Action eventOccurred(final SpacecraftState s, final EventDetector detector, final boolean increasing) {
final AbsoluteDate date = s.getDate();
if (activated.get(date) == (forward ? past : future) &&
......@@ -423,7 +439,7 @@ public class AttitudesSequence implements AttitudeProvider {
switchHandler.switchOccurred(past, future, s);
}
return event.eventOccurred(s, increasing);
return event.getHandler().eventOccurred(s, event, increasing);
} else {
......@@ -446,22 +462,22 @@ public class AttitudesSequence implements AttitudeProvider {
switchHandler.switchOccurred(future, past, sState);
}
return event.eventOccurred(sState, increasing);
return event.getHandler().eventOccurred(sState, event, increasing);
}
} else {
// trigger the underlying event despite no attitude switch occurred
return event.eventOccurred(s, increasing);
return event.getHandler().eventOccurred(s, event, increasing);
}
}
/** {@inheritDoc} */
@Override
public SpacecraftState resetState(final SpacecraftState oldState) {
public SpacecraftState resetState(final EventDetector detector, final SpacecraftState oldState) {
// delegate to underlying event
return event.resetState(oldState);
return event.getHandler().resetState(detector, oldState);
}
/** Provider for transition phases.
......
......@@ -20,12 +20,12 @@ import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import org.hipparchus.ode.events.Action;
import org.orekit.estimation.measurements.ObservedMeasurement;
import org.orekit.propagation.Propagator;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.AdapterDetector;
import org.orekit.propagation.events.EventDetector;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.propagation.sampling.OrekitStepInterpolator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.DatesSelector;
......@@ -150,22 +150,29 @@ public class EventBasedScheduler<T extends ObservedMeasurement<T>> extends Abstr
/** {@inheritDoc} */
@Override
public Action eventOccurred(final SpacecraftState s, final boolean increasing) {
// find the feasibility status AFTER the current date
final boolean statusAfter = signSemantic.measurementIsFeasible(increasing ? +1 : -1);
// store either status or its opposite according to propagation direction
if (forward) {
// forward propagation
feasibility.addValidAfter(statusAfter, s.getDate(), false);
} else {
// backward propagation
feasibility.addValidBefore(!statusAfter, s.getDate(), false);
}
public EventHandler getHandler() {
final EventDetector rawDetector = getDetector();
final EventHandler rawHandler = rawDetector.getHandler();
return (state, detector, increasing) -> {
// find the feasibility status AFTER the current date
final boolean statusAfter = signSemantic.measurementIsFeasible(increasing ? +1 : -1);
// store either status or its opposite according to propagation direction
if (forward) {
// forward propagation
feasibility.addValidAfter(statusAfter, state.getDate(), false);
} else {
// backward propagation
feasibility.addValidBefore(!statusAfter, state.getDate(), false);
}
// delegate to wrapped detector
return rawHandler.eventOccurred(state, rawDetector, increasing);
// delegate to wrapped detector
return super.eventOccurred(s, increasing);
};
}
......
......@@ -196,7 +196,7 @@ public class ImpulseManeuver extends AbstractDetector<ImpulseManeuver> {
// filter underlying event
final ImpulseManeuver im = (ImpulseManeuver) detector;
final Action underlyingAction = im.trigger.eventOccurred(s, increasing);
final Action underlyingAction = im.trigger.getHandler().eventOccurred(s, detector, increasing);
return (underlyingAction == Action.STOP) ? Action.RESET_STATE : Action.CONTINUE;
......
......@@ -16,7 +16,6 @@
*/
package org.orekit.propagation.events;
import org.hipparchus.ode.events.Action;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.propagation.SpacecraftState;
......@@ -165,27 +164,12 @@ public abstract class AbstractDetector<T extends AbstractDetector<T>> implements
return create(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), newHandler);
}
/** Get the handler.
* @return event handler to call at event occurrences
*/
/** {@inheritDoc} */
@Override
public EventHandler getHandler() {
return handler;
}
/** {@inheritDoc} */
public Action eventOccurred(final SpacecraftState s, final boolean increasing) {
@SuppressWarnings("unchecked")
final Action whatNext = getHandler().eventOccurred(s, (T) this, increasing);
return whatNext;
}
/** {@inheritDoc} */
public SpacecraftState resetState(final SpacecraftState oldState) {
@SuppressWarnings("unchecked")
final SpacecraftState newState = getHandler().resetState((T) this, oldState);
return newState;
}
/** Build a new instance.
* @param newMaxCheck maximum checking interval (s)
* @param newThreshold convergence threshold (s)
......
......@@ -16,8 +16,8 @@
*/
package org.orekit.propagation.events;
import org.hipparchus.ode.events.Action;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.time.AbsoluteDate;
/** Base class for adapting an existing detector.
......@@ -81,14 +81,8 @@ public class AdapterDetector implements EventDetector {
/** {@inheritDoc} */
@Override
public Action eventOccurred(final SpacecraftState s, final boolean increasing) {
return detector.eventOccurred(s, increasing);
}
/** {@inheritDoc} */
@Override
public SpacecraftState resetState(final SpacecraftState oldState) {
return detector.resetState(oldState);
public EventHandler getHandler() {
return detector.getHandler();
}
}
......@@ -16,8 +16,8 @@
*/
package org.orekit.propagation.events;
import org.hipparchus.ode.events.Action;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.time.AbsoluteDate;
/** This interface represents space-dynamics aware events detectors.
......@@ -85,31 +85,10 @@ public interface EventDetector {
*/
int getMaxIterationCount();
/** Handle the event.
* @param s SpaceCraft state to be used in the evaluation
* @param increasing with the event occurred in an "increasing" or "decreasing" slope direction
* @return the Action that the calling detector should pass back to the evaluation system
* @since 7.0
/** Get the handler.
* @return event handler to call at event occurrences
* @since 12.0
*/
Action eventOccurred(SpacecraftState s, boolean increasing);
/** Reset the state prior to continue propagation.
* <p>This method is called after the step handler has returned and
* before the next step is started, but only when {@link
* #eventOccurred} has itself returned the {@link Action#RESET_STATE}
* indicator. It allows the user to reset the state for the next step,
* without perturbing the step handler of the finishing step. If the
* {@link #eventOccurred} never returns the {@link Action#RESET_STATE}
* indicator, this function will never be called, and it is safe to simply return null.</p>
* <p>
* The default implementation simply returns its argument.
* </p>
* @param oldState old state
* @return new state
* @since 7.0
*/
default SpacecraftState resetState(SpacecraftState oldState) {
return oldState;
}
EventHandler getHandler();
}
......@@ -291,14 +291,14 @@ public class EventEnablingPredicateFilter
public Action eventOccurred(final SpacecraftState s, final EventDetector detector, final boolean increasing) {
final EventEnablingPredicateFilter ef = (EventEnablingPredicateFilter) detector;
final Transformer transformer = ef.forward ? ef.transformers[ef.transformers.length - 1] : ef.transformers[0];
return ef.rawDetector.eventOccurred(s, transformer == Transformer.PLUS ? increasing : !increasing);
return ef.rawDetector.getHandler().eventOccurred(s, ef, transformer == Transformer.PLUS ? increasing : !increasing);
}
/** {@inheritDoc} */
@Override
public SpacecraftState resetState(final EventDetector detector, final SpacecraftState oldState) {
final EventEnablingPredicateFilter ef = (EventEnablingPredicateFilter) detector;
return ef.rawDetector.resetState(oldState);
return ef.rawDetector.getHandler().resetState(ef, oldState);
}
}
......
......@@ -169,7 +169,7 @@ public class EventShifter extends AbstractDetector<EventShifter> {
shiftedState = s.shiftedBy(offset);
}
return shifter.detector.eventOccurred(shiftedState, increasing);
return shifter.detector.getHandler().eventOccurred(shiftedState, shifter.detector, increasing);
}
......@@ -177,7 +177,7 @@ public class EventShifter extends AbstractDetector<EventShifter> {
@Override
public SpacecraftState resetState(final EventDetector detector, final SpacecraftState oldState) {
final EventShifter shifter = (EventShifter) detector;
return shifter.detector.resetState(shiftedState);
return shifter.detector.getHandler().resetState(shifter.detector, shiftedState);
}
}
......
......@@ -246,7 +246,7 @@ public class EventSlopeFilter<T extends EventDetector> extends AbstractDetector<
public Action eventOccurred(final SpacecraftState s, final EventDetector detector, final boolean increasing) {
@SuppressWarnings("unchecked")
final EventSlopeFilter<T> esf = (EventSlopeFilter<T>) detector;
return esf.rawDetector.eventOccurred(s, esf.filter.getTriggeredIncreasing());
return esf.rawDetector.getHandler().eventOccurred(s, esf, esf.filter.getTriggeredIncreasing());
}
/** {@inheritDoc} */
......@@ -254,7 +254,7 @@ public class EventSlopeFilter<T extends EventDetector> extends AbstractDetector<
public SpacecraftState resetState(final EventDetector detector, final SpacecraftState oldState) {
@SuppressWarnings("unchecked")
final EventSlopeFilter<T> esf = (EventSlopeFilter<T>) detector;
return esf.rawDetector.resetState(oldState);
return esf.rawDetector.getHandler().resetState(esf, oldState);
}
}
......
......@@ -30,6 +30,7 @@ import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitInternalError;
import org.orekit.errors.OrekitMessages;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.propagation.sampling.OrekitStepInterpolator;
import org.orekit.time.AbsoluteDate;
......@@ -55,6 +56,9 @@ public class EventState<T extends EventDetector> {
/** Event detector. */
private T detector;
/** Event handler. */
private EventHandler handler;
/** Time of the previous call to g. */
private AbsoluteDate lastT;
......@@ -104,6 +108,7 @@ public class EventState<T extends EventDetector> {
*/
public EventState(final T detector) {
this.detector = detector;
this.handler = detector.getHandler();
// some dummy values ...
lastT = AbsoluteDate.PAST_INFINITY;
......@@ -501,10 +506,10 @@ public class EventState<T extends EventDetector> {
check(pendingEvent);
check(state.getDate().equals(this.pendingEventTime));
final Action action = detector.eventOccurred(state, increasing == forward);
final Action action = handler.eventOccurred(state, detector, increasing == forward);
final SpacecraftState newState;
if (action == Action.RESET_STATE) {
newState = detector.resetState(state);
newState = handler.resetState(detector, state);
} else {
newState = state;
}
......
......@@ -168,7 +168,7 @@ public class EventsLogger {
*/
LoggingWrapper(final EventDetector detector) {
this(detector.getMaxCheckInterval(), detector.getThreshold(),
detector.getMaxIterationCount(), new LocalHandler(),
detector.getMaxIterationCount(), null,
detector);
}
......@@ -219,23 +219,26 @@ public class EventsLogger {
return detector.g(s);
}
}
/** {@inheritDoc} */
public EventHandler getHandler() {
/** Local class for handling events. */
private static class LocalHandler implements EventHandler {
final EventHandler handler = detector.getHandler();
/** {@inheritDoc} */
public Action eventOccurred(final SpacecraftState s, final EventDetector detector, final boolean increasing) {
final LoggingWrapper wrapper = (LoggingWrapper) detector;
wrapper.logEvent(s, increasing);
return wrapper.detector.eventOccurred(s, increasing);
}
return new EventHandler() {
/** {@inheritDoc} */
@Override
public SpacecraftState resetState(final EventDetector detector, final SpacecraftState oldState) {
final LoggingWrapper wrapper = (LoggingWrapper) detector;
return wrapper.detector.resetState(oldState);
/** {@inheritDoc} */
public Action eventOccurred(final SpacecraftState s, final EventDetector d, final boolean increasing) {
logEvent(s, increasing);
return handler.eventOccurred(s, detector, increasing);
}
/** {@inheritDoc} */
@Override
public SpacecraftState resetState(final EventDetector d, final SpacecraftState oldState) {
return handler.resetState(detector, oldState);
}
};
}
}
......
......@@ -162,9 +162,7 @@ public abstract class FieldAbstractDetector<D extends FieldAbstractDetector<D, T
return create(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), newHandler);
}
/** Get the handler.
* @return event handler to call at event occurrences
*/
/** {@inheritDoc} */
public FieldEventHandler<T> getHandler() {
return handler;
}
......
......@@ -17,8 +17,8 @@
package org.orekit.propagation.events;
import org.hipparchus.CalculusFieldElement;
import org.hipparchus.ode.events.Action;
import org.orekit.propagation.FieldSpacecraftState;
import org.orekit.propagation.events.handlers.FieldEventHandler;
import org.orekit.time.FieldAbsoluteDate;
/** This interface represents space-dynamics aware events detectors.
......@@ -88,31 +88,10 @@ public interface FieldEventDetector <T extends CalculusFieldElement<T>> {
*/
int getMaxIterationCount();
/** Handle the event.
* @param s SpaceCraft state to be used in the evaluation
* @param increasing with the event occurred in an "increasing" or "decreasing" slope direction
* @return the Action that the calling detector should pass back to the evaluation system
* @since 7.0
/** Get the handler.
* @return event handler to call at event occurrences
* @since 12.0
*/
Action eventOccurred(FieldSpacecraftState<T> s, boolean increasing);
/** Reset the state prior to continue propagation.
* <p>This method is called after the step handler has returned and
* before the next step is started, but only when {@link
* #eventOccurred} has itself returned the {@link Action#RESET_STATE}
* indicator. It allows the user to reset the state for the next step,
* without perturbing the step handler of the finishing step. If the
* {@link #eventOccurred} never returns the {@link Action#RESET_STATE}
* indicator, this function will never be called, and it is safe to simply return null.</p>
* <p>
* The default implementation simply returns its argument.
* </p>
* @param oldState old state
* @return new state
* @since 7.0
*/
default FieldSpacecraftState<T> resetState(FieldSpacecraftState<T> oldState) {
return oldState;
}
FieldEventHandler<T> getHandler();
}
......@@ -32,6 +32,7 @@ import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitInternalError;
import org.orekit.errors.OrekitMessages;
import org.orekit.propagation.FieldSpacecraftState;
import org.orekit.propagation.events.handlers.FieldEventHandler;
import org.orekit.propagation.sampling.FieldOrekitStepInterpolator;
import org.orekit.time.FieldAbsoluteDate;
......@@ -57,6 +58,9 @@ public class FieldEventState<D extends FieldEventDetector<T>, T extends Calculus
/** Event detector. */
private D detector;
/** Event handler. */
private FieldEventHandler<T> handler;
/** Time of the previous call to g. */
private FieldAbsoluteDate<T> lastT;
......@@ -107,6 +111,7 @@ public class FieldEventState<D extends FieldEventDetector<T>, T extends Calculus
public FieldEventState(final D detector) {
this.detector = detector;
this.handler = detector.getHandler();
// some dummy values ...
final Field<T> field = detector.getMaxCheckInterval().getField();
......@@ -508,10 +513,10 @@ public class FieldEventState<D extends FieldEventDetector<T>, T extends Calculus
check(pendingEvent);
check(state.getDate().equals(this.pendingEventTime));
final Action action = detector.eventOccurred(state, increasing == forward);
final Action action = handler.eventOccurred(state, detector, increasing == forward);
final FieldSpacecraftState<T> newState;
if (action == Action.RESET_STATE) {
newState = detector.resetState(state);
newState = handler.resetState(detector, state);
} else {
newState = state;
}
......
......@@ -164,7 +164,7 @@ public class FieldEventsLogger<T extends CalculusFieldElement<T>> {
*/
FieldLoggingWrapper(final FieldEventDetector<T> detector) {
this(detector.getMaxCheckInterval(), detector.getThreshold(),
detector.getMaxIterationCount(), new FieldLocalHandler(),
detector.getMaxIterationCount(), null,
detector);
}
......@@ -215,25 +215,29 @@ public class FieldEventsLogger<T extends CalculusFieldElement<T>> {
return detector.g(s);
}
}
/** {@inheritDoc} */
public FieldEventHandler<T> getHandler() {
/** Local class for handling events.
* @param <D> class type for the generic version
*/
private class FieldLocalHandler implements FieldEventHandler<T> {
final FieldEventHandler<T> handler = detector.getHandler();
/** {@inheritDoc} */
public Action eventOccurred(final FieldSpacecraftState<T> s, final FieldEventDetector<T> detector, final boolean increasing) {
final FieldLoggingWrapper wrapper = (FieldLoggingWrapper) detector;
wrapper.logEvent(s, increasing);
return wrapper.detector.eventOccurred(s, increasing);
}
return new FieldEventHandler<T>() {
/** {@inheritDoc} */
@Override
public FieldSpacecraftState<T> resetState(final FieldEventDetector<T> detector, final FieldSpacecraftState<T> oldState) {
final FieldLoggingWrapper wrapper = (FieldLoggingWrapper) detector;
return wrapper.detector.resetState(oldState);
/** {@inheritDoc} */
public Action eventOccurred(final FieldSpacecraftState<T> s,
final FieldEventDetector<T> d,
final boolean increasing) {
logEvent(s, increasing);
return handler.eventOccurred(s, detector, increasing);
}
/** {@inheritDoc} */
@Override
public FieldSpacecraftState<T> resetState(final FieldEventDetector<T> d,
final FieldSpacecraftState<T> oldState) {
return handler.resetState(detector, oldState);
}
};
}
}
......
......@@ -35,7 +35,7 @@ import org.hipparchus.ode.ODEStateAndDerivative;
import org.hipparchus.ode.OrdinaryDifferentialEquation;
import org.hipparchus.ode.SecondaryODE;
import org.hipparchus.ode.events.Action;
import org.hipparchus.ode.events.EventHandlerConfiguration;
import org.hipparchus.ode.events.ODEEventDetector;