Commit 6a66e172 authored by Luc Maisonobe's avatar Luc Maisonobe

Ensure additional state is available when calling init.

parent 887fb4a9
......@@ -97,7 +97,4 @@
</module>
<module name="FileTabCharacter"/>
<module name="NewlineAtEndOfFile"/>
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}"/>
</module>
</module>
\ No newline at end of file
</module>
......@@ -667,23 +667,6 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>${orekit.jacoco-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<enableRulesSummary>false</enableRulesSummary>
<headerLocation>${basedir}/license-header.txt</headerLocation>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
......
......@@ -640,8 +640,8 @@ public abstract class AbstractIntegratedPropagator extends AbstractPropagator {
* @throws OrekitException if there is an Orekit related error during
* initialization.
*/
default void init(SpacecraftState initialState, AbsoluteDate target)
throws OrekitException {
default void init(final SpacecraftState initialState, final AbsoluteDate target)
throws OrekitException {
}
/** Compute differential equations for main state.
......@@ -741,6 +741,7 @@ public abstract class AbstractIntegratedPropagator extends AbstractPropagator {
// use only ODE elements
SpacecraftState initialState = stateMapper.mapArrayToState(t0, primary0, null, true);
initialState = updateAdditionalStates(initialState);
initialState = initialState.addAdditionalState(equations.getName(), secondary0);
final AbsoluteDate target = stateMapper.mapDoubleToDate(finalTime);
equations.init(initialState, target);
} catch (OrekitException oe) {
......
......@@ -67,10 +67,16 @@ public interface AdditionalEquations {
String getName();
/**
* Initialize the equations at the start of propagation. This method will be
* called before any calls to {@link #computeDerivatives(SpacecraftState)}.
* Initialize the equations at the start of propagation.
*
* <p> The default implementation of this method does nothing.
* <p>
* This method will be called once at propagation start,
* before any calls to {@link #computeDerivatives(SpacecraftState)}.
* </p>
*
* <p>
* The default implementation of this method does nothing.
* </p>
*
* @param initialState initial state information at the start of propagation.
* @param target date of propagation. Not equal to {@code
......@@ -78,9 +84,9 @@ public interface AdditionalEquations {
* @throws OrekitException if there is an Orekit related error during
* initialization.
*/
default void init(SpacecraftState initialState, AbsoluteDate target)
throws OrekitException {
// nothing by default
default void init(final SpacecraftState initialState, final AbsoluteDate target)
throws OrekitException {
// nothing by default
}
/** Compute the derivatives related to the additional state parameters.
......
......@@ -38,54 +38,54 @@ import org.orekit.time.AbsoluteDate;
import org.orekit.utils.PVCoordinates;
public class AdditionalEquationsTest {
private double mu;
private AbsoluteDate initDate;
private SpacecraftState initialState;
private AdaptiveStepsizeIntegrator integrator;
/** Test for issue #401
/** Test for issue #401
* with a numerical propagator */
@Test
public void testInitNumerical() throws OrekitException {
// setup
InitCheckerEquations checker = new InitCheckerEquations();
final double reference = 1.25;
InitCheckerEquations checker = new InitCheckerEquations(reference);
Assert.assertFalse(checker.wasCalled());
// action
NumericalPropagator propagatorNumerical = new NumericalPropagator(integrator);
propagatorNumerical.setInitialState(initialState);
propagatorNumerical.setInitialState(initialState.addAdditionalState(checker.getName(), reference));
propagatorNumerical.addAdditionalEquations(checker);
propagatorNumerical.setInitialState(propagatorNumerical.getInitialState().addAdditionalState("linear", 1.5));
propagatorNumerical.propagate(initDate.shiftedBy(600));
// verify
Assert.assertTrue(checker.wasCalled());
}
/** Test for issue #401
/** Test for issue #401
* with a DSST propagator */
@Test
public void testInitDSST() throws OrekitException {
// setup
InitCheckerEquations checker = new InitCheckerEquations();
final double reference = 3.5;
InitCheckerEquations checker = new InitCheckerEquations(reference);
Assert.assertFalse(checker.wasCalled());
// action
DSSTPropagator propagatorDSST = new DSSTPropagator(integrator);
propagatorDSST.setInitialState(initialState);
propagatorDSST.setInitialState(initialState.addAdditionalState(checker.getName(), reference));
propagatorDSST.addAdditionalEquations(checker);
propagatorDSST.setInitialState(propagatorDSST.getInitialState().addAdditionalState("linear", 1.5));
propagatorDSST.propagate(initDate.shiftedBy(600));
// verify
Assert.assertTrue(checker.wasCalled());
}
@Before
public void setUp() throws OrekitException {
Utils.setDataRoot("regular-data:potential/shm-format");
......@@ -108,19 +108,21 @@ public class AdditionalEquationsTest {
initialState = null;
integrator = null;
}
public static class InitCheckerEquations implements AdditionalEquations {
private double expected;
private boolean called;
/** Simple Constructor */
public InitCheckerEquations() {
this.called = false;
public InitCheckerEquations(final double expected) {
this.expected = expected;
this.called = false;
}
@Override
public void init(SpacecraftState initiaState, AbsoluteDate target)
throws OrekitException {
Assert.assertEquals(expected, initiaState.getAdditionalState(getName())[0], 1.0e-15);
called = true;
}
......@@ -130,7 +132,7 @@ public class AdditionalEquationsTest {
pDot[0] = 1.5;
return new double[7];
}
@Override
public String getName() {
return "linear";
......@@ -141,5 +143,5 @@ public class AdditionalEquationsTest {
}
}
}
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