Commit 992ce1d1 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Improved test coverage.

parent 79e1ddd8
......@@ -86,7 +86,7 @@ public interface OrekitStepInterpolator {
* @param newPreviousState start of the restricted step
* @param newCurrentState end of the restricted step
* @return restricted version of the instance
* @see #getPreviousState()
* @see #getPreviousState()
* @see #getCurrentState()
* @since 9.0
*/
......
/* Copyright 2002-2021 CS GROUP
* Licensed to CS GROUP (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.forces.maneuvers.triggers;
import java.util.stream.Stream;
import org.hipparchus.CalculusFieldElement;
import org.hipparchus.Field;
import org.hipparchus.util.Decimal64Field;
import org.junit.Assert;
import org.junit.Test;
import org.orekit.forces.maneuvers.trigger.ManeuverTriggers;
import org.orekit.frames.FramesFactory;
import org.orekit.orbits.KeplerianOrbit;
import org.orekit.orbits.PositionAngle;
import org.orekit.propagation.FieldSpacecraftState;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.EventDetector;
import org.orekit.propagation.events.FieldEventDetector;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.FieldAbsoluteDate;
import org.orekit.utils.Constants;
public class ManeuverTriggersTest {
@Test
public void testNoOpDefault() {
// just test the default no-op implementation can be called without side effects
ManeuverTriggers dummy = new ManeuverTriggers() {
public <T extends CalculusFieldElement<T>> boolean isFiring(FieldAbsoluteDate<T> date, T[] parameters) {
return false;
}
public boolean isFiring(AbsoluteDate date, double[] parameters) {
return false;
}
public <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(Field<T> field) {
return null;
}
public Stream<EventDetector> getEventsDetectors() {
return null;
}
};
SpacecraftState state = new SpacecraftState(new KeplerianOrbit(7e6, 0.1, 0.2, 0.3, 0.4, 0.5,
PositionAngle.MEAN, FramesFactory.getGCRF(),
AbsoluteDate.J2000_EPOCH,
Constants.EIGEN5C_EARTH_MU));
dummy.init(state, state.getDate().shiftedBy(60));
dummy.init(new FieldSpacecraftState<>(Decimal64Field.getInstance(), state),
new FieldAbsoluteDate<>(Decimal64Field.getInstance(), state.getDate().shiftedBy(60)));
Assert.assertEquals("", dummy.getName());
}
}
......@@ -29,10 +29,13 @@ import org.orekit.errors.OrekitException;
import org.orekit.frames.FramesFactory;
import org.orekit.orbits.EquinoctialOrbit;
import org.orekit.orbits.Orbit;
import org.orekit.orbits.OrbitType;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.events.handlers.ContinueOnEvent;
import org.orekit.propagation.events.handlers.EventHandler;
import org.orekit.propagation.integration.AdditionalDerivativesProvider;
import org.orekit.propagation.numerical.NumericalPropagator;
import org.orekit.propagation.sampling.OrekitStepInterpolator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.PVCoordinates;
......@@ -53,6 +56,25 @@ public class DateDetectorTest {
public void testSimpleTimer() {
DateDetector dateDetector = new DateDetector(maxCheck, threshold, iniDate.shiftedBy(2.0*dt));
Assert.assertEquals(2 * dt, dateDetector.getDate().durationFrom(iniDate), 1.0e-10);
propagator.addAdditionalDerivativesProvider(new AdditionalDerivativesProvider() {
public String getName() { return "dummy"; }
public int getDimension() { return 1; }
public double[] derivatives(SpacecraftState s) { return new double[1]; }
});
propagator.setInitialState(propagator.getInitialState().addAdditionalState("dummy", new double[1]));
propagator.getMultiplexer().add(interpolator -> {
SpacecraftState prev = interpolator.getPreviousState();
SpacecraftState curr = interpolator.getCurrentState();
double dt = curr.getDate().durationFrom(prev.getDate());
OrekitStepInterpolator restricted =
interpolator.restrictStep(prev.shiftedBy(dt * +0.25),
curr.shiftedBy(dt * -0.25));
SpacecraftState restrictedPrev = restricted.getPreviousState();
SpacecraftState restrictedCurr = restricted.getCurrentState();
double restrictedDt = restrictedCurr.getDate().durationFrom(restrictedPrev.getDate());
Assert.assertEquals(dt * 0.5, restrictedDt, 1.0e-10);
});
propagator.setOrbitType(OrbitType.EQUINOCTIAL);
propagator.addEventDetector(dateDetector);
final SpacecraftState finalState = propagator.propagate(iniDate.shiftedBy(100.*dt));
......
......@@ -18,13 +18,14 @@ package org.orekit.propagation.events;
import java.lang.reflect.Array;
import org.hipparchus.Field;
import org.hipparchus.CalculusFieldElement;
import org.hipparchus.Field;
import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
import org.hipparchus.ode.events.Action;
import org.hipparchus.ode.nonstiff.AdaptiveStepsizeFieldIntegrator;
import org.hipparchus.ode.nonstiff.DormandPrince853FieldIntegrator;
import org.hipparchus.util.Decimal64Field;
import org.hipparchus.util.MathArrays;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
......@@ -36,7 +37,9 @@ import org.orekit.orbits.OrbitType;
import org.orekit.propagation.FieldSpacecraftState;
import org.orekit.propagation.events.handlers.FieldContinueOnEvent;
import org.orekit.propagation.events.handlers.FieldEventHandler;
import org.orekit.propagation.integration.FieldAdditionalDerivativesProvider;
import org.orekit.propagation.numerical.FieldNumericalPropagator;
import org.orekit.propagation.sampling.FieldOrekitStepInterpolator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.FieldAbsoluteDate;
import org.orekit.time.FieldTimeStamped;
......@@ -73,7 +76,7 @@ public class FieldDateDetectorTest {
doTestGenericHandler(Decimal64Field.getInstance());
}
private <T extends CalculusFieldElement<T>> void doTestSimpleTimer(Field<T> field) {
private <T extends CalculusFieldElement<T>> void doTestSimpleTimer(final Field<T> field) {
T zero = field.getZero();
final FieldVector3D<T> position = new FieldVector3D<>(zero.add(-6142438.668), zero.add( 3492467.560), zero.add( -25767.25680));
final FieldVector3D<T> velocity = new FieldVector3D<>(zero.add(505.8479685), zero.add(942.7809215), zero.add(7435.922231));
......@@ -91,8 +94,25 @@ public class FieldDateDetectorTest {
new DormandPrince853FieldIntegrator<>(field, 0.001, 1000, absTolerance, relTolerance);
integrator.setInitialStepSize(60);
FieldNumericalPropagator<T> propagator = new FieldNumericalPropagator<>(field, integrator);
propagator.addAdditionalDerivativesProvider(new FieldAdditionalDerivativesProvider<T>() {
public String getName() { return "dummy"; }
public int getDimension() { return 1; }
public T[] derivatives(FieldSpacecraftState<T> s) { return MathArrays.buildArray(field, 1); }
});
propagator.getMultiplexer().add(interpolator -> {
FieldSpacecraftState<T> prev = interpolator.getPreviousState();
FieldSpacecraftState<T> curr = interpolator.getCurrentState();
T dt = curr.getDate().durationFrom(prev.getDate());
FieldOrekitStepInterpolator<T> restricted =
interpolator.restrictStep(prev.shiftedBy(dt.multiply(+0.25)),
curr.shiftedBy(dt.multiply(-0.25)));
FieldSpacecraftState<T> restrictedPrev = restricted.getPreviousState();
FieldSpacecraftState<T> restrictedCurr = restricted.getCurrentState();
T restrictedDt = restrictedCurr.getDate().durationFrom(restrictedPrev.getDate());
Assert.assertEquals(dt.multiply(0.5).getReal(), restrictedDt.getReal(), 1.0e-10);
});
propagator.setOrbitType(OrbitType.EQUINOCTIAL);
propagator.setInitialState(initialState);
propagator.setInitialState(initialState.addAdditionalState("dummy", MathArrays.buildArray(field, 1)));
FieldDateDetector<T> dateDetector = new FieldDateDetector<>(zero.add(maxCheck), zero.add(threshold),
toArray(iniDate.shiftedBy(2.0*dt)));
......
......@@ -154,8 +154,7 @@ public class FieldNumericalPropagatorTest {
doTestEventAtBeginningOfEphemeris(Decimal64Field.getInstance());
}
private <T extends CalculusFieldElement<T>, D extends FieldEventDetector<T>> void doTestEventAtBeginningOfEphemeris(Field<T> field)
{
private <T extends CalculusFieldElement<T>, D extends FieldEventDetector<T>> void doTestEventAtBeginningOfEphemeris(Field<T> field) {
T zero = field.getZero();
FieldNumericalPropagator<T> propagator = createPropagator(field);
......@@ -283,6 +282,9 @@ public class FieldNumericalPropagatorTest {
FieldAbsoluteDate<T> date = endDate.shiftedBy(-0.11);
Assert.assertEquals(
ephemeris.propagate(date).getDate().durationFrom(date).getReal(), 0, 0);
Assert.assertTrue(prop.getAdditionalDerivativesProviders().isEmpty());
}
@Test
......
Supports Markdown
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