Commit 8ccd498e authored by Luc Maisonobe's avatar Luc Maisonobe

Added adapter for event detectors.

This adaptor allows wrapping an existing detector while changing its
behaviour.
parent d682a842
/* Copyright 2002-2018 CS Systèmes d'Information
* Licensed to CS Systèmes d'Information (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.propagation.events;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.EventHandler.Action;
import org.orekit.time.AbsoluteDate;
/** Base class for adapting an existing detector.
* <p>
* This class is intended to be a base class for changing behaviour
* of a wrapped existing detector. This base class delegates all
* its methods to the wrapped detector. Classes extending it can
* therefore override only the methods they want to change.
* </p>
* @author Luc Maisonobe
* @since 9.3
*/
public class AdapterDetector implements EventDetector {
/** Serializable UID. */
private static final long serialVersionUID = 20181206L;
/** Wrapped detector. */
private final EventDetector detector;
/** Build an adaptor wrapping an existing detector.
* @param detector detector to wrap
*/
public AdapterDetector(final EventDetector detector) {
this.detector = detector;
}
/** Get the wrapped detector.
* @return wrapped detector
*/
public EventDetector getDetector() {
return detector;
}
/** {@inheritDoc} */
@Override
public void init(final SpacecraftState s0, final AbsoluteDate t) {
detector.init(s0, t);
}
/** {@inheritDoc} */
@Override
public double g(final SpacecraftState s) {
return detector.g(s);
}
/** {@inheritDoc} */
@Override
public double getThreshold() {
return detector.getThreshold();
}
/** {@inheritDoc} */
@Override
public double getMaxCheckInterval() {
return detector.getMaxCheckInterval();
}
/** {@inheritDoc} */
@Override
public int getMaxIterationCount() {
return detector.getMaxIterationCount();
}
/** {@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);
}
}
......@@ -21,6 +21,10 @@
</properties>
<body>
<release version="TBD" date="TBD" description="TBD">
<action dev="luc" type="add">
Added adapter for event detectors, allowing to wrap existing detector
while changing their behaviour.
</action>
<action dev="luc" type="add">
Added ground at night detector.
</action>
......
/* Copyright 2002-2018 CS Systèmes d'Information
* Licensed to CS Systèmes d'Information (CS) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* CS licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.orekit.propagation.events;
import java.util.concurrent.atomic.AtomicInteger;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator;
import org.hipparchus.ode.nonstiff.DormandPrince853Integrator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.orekit.Utils;
import org.orekit.errors.OrekitException;
import org.orekit.frames.FramesFactory;
import org.orekit.orbits.EquinoctialOrbit;
import org.orekit.orbits.Orbit;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.EventHandler.Action;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.PVCoordinates;
public class AdapterDetectorTest {
private double maxCheck;
private double threshold;
private double dt;
private Orbit iniOrbit;
private AbsoluteDate iniDate;
private NumericalPropagator propagator;
@Test
public void testSimpleTimer() {
DateDetector dateDetector = new DateDetector(maxCheck, threshold, iniDate.shiftedBy(2.0*dt));
AdapterDetector adapter = new AdapterDetector(dateDetector);
Assert.assertSame(dateDetector, adapter.getDetector());
Assert.assertEquals(2 * dt, dateDetector.getDate().durationFrom(iniDate), 1.0e-10);
propagator.addEventDetector(adapter);
final SpacecraftState finalState = propagator.propagate(iniDate.shiftedBy(100.*dt));
Assert.assertEquals(2.0*dt, finalState.getDate().durationFrom(iniDate), threshold);
}
@Test
public void testOverrideAction() {
AtomicInteger count = new AtomicInteger(0);
DateDetector dateDetector = new DateDetector(maxCheck, threshold, iniDate.shiftedBy(2.0*dt));
AdapterDetector adapter = new AdapterDetector(dateDetector) {
/** Serializable UID. */
private static final long serialVersionUID = 20181206L;
/** {@inheritDoc} */
@Override
public Action eventOccurred(final SpacecraftState s, final boolean increasing) {
count.incrementAndGet();
return Action.RESET_STATE;
}
};
Assert.assertSame(dateDetector, adapter.getDetector());
Assert.assertEquals(2 * dt, dateDetector.getDate().durationFrom(iniDate), 1.0e-10);
propagator.addEventDetector(adapter);
Assert.assertEquals(0, count.get());
final SpacecraftState finalState = propagator.propagate(iniDate.shiftedBy(100.*dt));
Assert.assertEquals(1, count.get());
Assert.assertEquals(100.0*dt, finalState.getDate().durationFrom(iniDate), threshold);
}
@Before
public void setUp() {
try {
Utils.setDataRoot("regular-data");
final double mu = 3.9860047e14;
final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680);
final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231);
iniDate = new AbsoluteDate(1969, 7, 28, 4, 0, 0.0, TimeScalesFactory.getTT());
iniOrbit = new EquinoctialOrbit(new PVCoordinates(position, velocity),
FramesFactory.getEME2000(), iniDate, mu);
SpacecraftState initialState = new SpacecraftState(iniOrbit);
double[] absTolerance = {
0.001, 1.0e-9, 1.0e-9, 1.0e-6, 1.0e-6, 1.0e-6, 0.001
};
double[] relTolerance = {
1.0e-7, 1.0e-4, 1.0e-4, 1.0e-7, 1.0e-7, 1.0e-7, 1.0e-7
};
AdaptiveStepsizeIntegrator integrator =
new DormandPrince853Integrator(0.001, 1000, absTolerance, relTolerance);
integrator.setInitialStepSize(60);
propagator = new NumericalPropagator(integrator);
propagator.setInitialState(initialState);
dt = 60.;
maxCheck = 10.;
threshold = 10.e-10;
} catch (OrekitException oe) {
Assert.fail(oe.getLocalizedMessage());
}
}
@After
public void tearDown() {
iniDate = null;
propagator = null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment