use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class JacobianPropagatorConverter method getObjectiveFunction.
/**
* {@inheritDoc}
*/
protected MultivariateVectorFunction getObjectiveFunction() {
return new MultivariateVectorFunction() {
/**
* {@inheritDoc}
*/
public double[] value(final double[] arg) throws IllegalArgumentException, OrekitExceptionWrapper {
try {
final double[] value = new double[getTargetSize()];
final NumericalPropagator prop = builder.buildPropagator(arg);
final int stateSize = isOnlyPosition() ? 3 : 6;
final List<SpacecraftState> sample = getSample();
for (int i = 0; i < sample.size(); ++i) {
final int row = i * stateSize;
if (prop.getInitialState().getDate().equals(sample.get(i).getDate())) {
// use initial state
fillRows(value, row, prop.getInitialState());
} else {
// use a date detector to pick up states
prop.addEventDetector(new DateDetector(sample.get(i).getDate()).withHandler(new EventHandler<DateDetector>() {
/**
* {@inheritDoc}
*/
@Override
public Action eventOccurred(final SpacecraftState state, final DateDetector detector, final boolean increasing) throws OrekitException {
fillRows(value, row, state);
return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
}
}));
}
}
prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
return value;
} catch (OrekitException ex) {
throw new OrekitExceptionWrapper(ex);
}
}
};
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class JacobianPropagatorConverter method getModel.
/**
* {@inheritDoc}
*/
protected MultivariateJacobianFunction getModel() {
return new MultivariateJacobianFunction() {
/**
* {@inheritDoc}
*/
public Pair<RealVector, RealMatrix> value(final RealVector point) throws IllegalArgumentException, OrekitExceptionWrapper {
try {
final RealVector value = new ArrayRealVector(getTargetSize());
final RealMatrix jacobian = MatrixUtils.createRealMatrix(getTargetSize(), point.getDimension());
final NumericalPropagator prop = builder.buildPropagator(point.toArray());
final int stateSize = isOnlyPosition() ? 3 : 6;
final ParameterDriversList orbitalParameters = builder.getOrbitalParametersDrivers();
final PartialDerivativesEquations pde = new PartialDerivativesEquations("pde", prop);
final ParameterDriversList propagationParameters = pde.getSelectedParameters();
prop.setInitialState(pde.setInitialJacobians(prop.getInitialState()));
final JacobiansMapper mapper = pde.getMapper();
final List<SpacecraftState> sample = getSample();
for (int i = 0; i < sample.size(); ++i) {
final int row = i * stateSize;
if (prop.getInitialState().getDate().equals(sample.get(i).getDate())) {
// use initial state and Jacobians
fillRows(value, jacobian, row, prop.getInitialState(), stateSize, orbitalParameters, propagationParameters, mapper);
} else {
// use a date detector to pick up state and Jacobians
prop.addEventDetector(new DateDetector(sample.get(i).getDate()).withHandler(new EventHandler<DateDetector>() {
/**
* {@inheritDoc}
*/
@Override
public Action eventOccurred(final SpacecraftState state, final DateDetector detector, final boolean increasing) throws OrekitException {
fillRows(value, jacobian, row, state, stateSize, orbitalParameters, propagationParameters, mapper);
return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
}
}));
}
}
prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
return new Pair<RealVector, RealMatrix>(value, jacobian);
} catch (OrekitException ex) {
throw new OrekitExceptionWrapper(ex);
}
}
};
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testShortBracketingIntervalReverse.
/**
* The root finder requires the start point to be in the interval (a, b) which is hard
* when there aren't many numbers between a and b. This test uses a second event
* detector to force a very small window for the first event detector.
*/
@Test
public void testShortBracketingIntervalReverse() throws OrekitException {
// setup
double maxCheck = 10;
double tolerance = 1e-6;
final double t1 = FastMath.nextDown(-10.0), t2 = -10.5;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
// never zero so there is no easy way out
EventDetector detectorA = new AbstractDetector<EventDetector>(maxCheck, tolerance, 100, new RecordAndContinue<>(events)) {
private static final long serialVersionUID = 1L;
@Override
public double g(SpacecraftState state) {
final AbsoluteDate t = state.getDate();
if (t.compareTo(epoch.shiftedBy(t1)) > 0) {
return -1;
} else if (t.compareTo(epoch.shiftedBy(t2)) > 0) {
return 1;
} else {
return -1;
}
}
@Override
protected EventDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler<? super EventDetector> newHandler) {
return null;
}
};
TimeDetector detectorB = new TimeDetector(t1).withHandler(new RecordAndContinue<>(events)).withMaxCheck(maxCheck).withThreshold(tolerance);
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorB);
// action
propagator.propagate(epoch.shiftedBy(-30.0));
// verify
Assert.assertEquals(3, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(false, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
Assert.assertEquals(t1, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertSame(detectorB, events.get(1).getDetector());
Assert.assertEquals(t2, events.get(2).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(2).isIncreasing());
Assert.assertSame(detectorA, events.get(2).getDetector());
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testEventChangesGFunctionDefinition.
/**
* test when one event detector changes the definition of another's g function before
* the end of the step as a result of a continue action. Not sure if this should be
* officially supported, but it is used in Orekit's DateDetector, it's useful, and not
* too hard to implement.
*/
@Test
public void testEventChangesGFunctionDefinition() throws OrekitException {
// setup
double maxCheck = 5;
double tolerance = 1e-6;
double t1 = 11, t2 = 19;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
// mutable boolean
boolean[] swap = new boolean[1];
final ContinuousDetector detectorA = new ContinuousDetector(t1).withThreshold(maxCheck).withThreshold(tolerance).withHandler(new RecordAndContinue<EventDetector>(events) {
@Override
public Action eventOccurred(SpacecraftState s, EventDetector detector, boolean increasing) {
swap[0] = true;
return super.eventOccurred(s, detector, increasing);
}
});
ContinuousDetector detectorB = new ContinuousDetector(t2);
EventDetector detectorC = new AbstractDetector<EventDetector>(maxCheck, tolerance, 100, new RecordAndContinue<>(events)) {
private static final long serialVersionUID = 1L;
@Override
public double g(SpacecraftState s) throws OrekitException {
if (swap[0]) {
return detectorB.g(s);
} else {
return -1;
}
}
@Override
protected EventDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler<? super EventDetector> newHandler) {
return null;
}
};
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorC);
// action
propagator.propagate(epoch.shiftedBy(30));
// verify
Assert.assertEquals(2, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertSame(detectorC, events.get(1).getDetector());
}
use of org.orekit.propagation.events.handlers.EventHandler in project Orekit by CS-SI.
the class CloseEventsAbstractTest method testEventChangesGFunctionDefinitionReverse.
/**
* test when one event detector changes the definition of another's g function before
* the end of the step as a result of a continue action. Not sure if this should be
* officially supported, but it is used in Orekit's DateDetector, it's useful, and not
* too hard to implement.
*/
@Test
public void testEventChangesGFunctionDefinitionReverse() throws OrekitException {
// setup
double maxCheck = 5;
double tolerance = 1e-6;
double t1 = -11, t2 = -19;
// shared event list so we know the order in which they occurred
List<Event<EventDetector>> events = new ArrayList<>();
// mutable boolean
boolean[] swap = new boolean[1];
ContinuousDetector detectorA = new ContinuousDetector(t1).withMaxCheck(maxCheck).withThreshold(tolerance).withHandler(new RecordAndContinue<EventDetector>(events) {
@Override
public Action eventOccurred(SpacecraftState s, EventDetector detector, boolean increasing) {
swap[0] = true;
return super.eventOccurred(s, detector, increasing);
}
});
ContinuousDetector detectorB = new ContinuousDetector(t2);
EventDetector detectorC = new AbstractDetector<EventDetector>(maxCheck, tolerance, 100, new RecordAndContinue<>(events)) {
private static final long serialVersionUID = 1L;
@Override
public double g(SpacecraftState state) throws OrekitException {
if (swap[0]) {
return detectorB.g(state);
} else {
return 1;
}
}
@Override
protected EventDetector create(double newMaxCheck, double newThreshold, int newMaxIter, EventHandler<? super EventDetector> newHandler) {
return null;
}
};
Propagator propagator = getPropagator(10);
propagator.addEventDetector(detectorA);
propagator.addEventDetector(detectorC);
// action
propagator.propagate(epoch.shiftedBy(-30.0));
// verify
Assert.assertEquals(2, events.size());
Assert.assertEquals(t1, events.get(0).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(0).isIncreasing());
Assert.assertSame(detectorA, events.get(0).getDetector());
Assert.assertEquals(t2, events.get(1).getState().getDate().durationFrom(epoch), tolerance);
Assert.assertEquals(true, events.get(1).isIncreasing());
Assert.assertSame(detectorC, events.get(1).getDetector());
}
Aggregations