1   package org.orekit.propagation.conversion;
2   
3   import org.hipparchus.geometry.euclidean.threed.Vector3D;
4   import org.hipparchus.ode.nonstiff.DormandPrince54Integrator;
5   import org.junit.jupiter.api.Assertions;
6   import org.junit.jupiter.api.Test;
7   import org.orekit.frames.FramesFactory;
8   import org.orekit.orbits.KeplerianOrbit;
9   import org.orekit.orbits.Orbit;
10  import org.orekit.orbits.PositionAngleType;
11  import org.orekit.propagation.ToleranceProvider;
12  import org.orekit.time.AbsoluteDate;
13  import org.orekit.utils.AbsolutePVCoordinates;
14  import org.orekit.utils.Constants;
15  
16  import java.util.Arrays;
17  
18  class AbstractVariableStepIntegratorBuilderTest {
19  
20      @Test
21      void testGetTolerancesOrbit() {
22          // GIVEN
23          final Orbit orbit = new KeplerianOrbit(7e6, 0.1, 1, 2, 3, 4, PositionAngleType.ECCENTRIC, FramesFactory.getGCRF(),
24                  AbsoluteDate.ARBITRARY_EPOCH, Constants.EGM96_EARTH_MU);
25          final double expectedAbsoluteTolerance = 1.;
26          final double expectedRelativeTolerance = 0.001;
27          final TestIntegratorBuilder integratorBuilder = new TestIntegratorBuilder(0., 1.,
28                  ToleranceProvider.of(expectedAbsoluteTolerance, expectedRelativeTolerance));
29          // WHEN
30          final double[][] actualTolerances = integratorBuilder.getTolerances(orbit, orbit.getType());
31          // THEN
32          final double[] expectedAbsolute = new double[7];
33          Arrays.fill(expectedAbsolute, expectedAbsoluteTolerance);
34          final double[] expectedRelative = new double[7];
35          Arrays.fill(expectedRelative, expectedRelativeTolerance);
36          final double [][] expectedTolerances = new double[][] {expectedAbsolute, expectedRelative};
37          Assertions.assertArrayEquals(expectedTolerances[0], actualTolerances[0]);
38          Assertions.assertArrayEquals(expectedTolerances[1], actualTolerances[1]);
39      }
40  
41      @Test
42      void testGetTolerances() {
43          // GIVEN
44          final AbsolutePVCoordinates absolutePVCoordinates = new AbsolutePVCoordinates(FramesFactory.getGCRF(),
45                  AbsoluteDate.ARBITRARY_EPOCH, Vector3D.MINUS_J, Vector3D.MINUS_K);
46          final double expectedAbsoluteTolerance = 1.;
47          final double expectedRelativeTolerance = 0.001;
48          final TestIntegratorBuilder integratorBuilder = new TestIntegratorBuilder(0., 1.,
49                  ToleranceProvider.of(expectedAbsoluteTolerance, expectedRelativeTolerance));
50          // WHEN
51          final double[][] actualTolerances = integratorBuilder.getTolerances(absolutePVCoordinates);
52          // THEN
53          final double[] expectedAbsolute = new double[7];
54          Arrays.fill(expectedAbsolute, expectedAbsoluteTolerance);
55          final double[] expectedRelative = new double[7];
56          Arrays.fill(expectedRelative, expectedRelativeTolerance);
57          final double [][] expectedTolerances = new double[][] {expectedAbsolute, expectedRelative};
58          Assertions.assertArrayEquals(expectedTolerances[0], actualTolerances[0]);
59          Assertions.assertArrayEquals(expectedTolerances[1], actualTolerances[1]);
60      }
61  
62      private static class TestIntegratorBuilder extends AbstractVariableStepIntegratorBuilder<DormandPrince54Integrator> {
63  
64          protected TestIntegratorBuilder(double minStep, double maxStep, ToleranceProvider toleranceProvider) {
65              super(minStep, maxStep, toleranceProvider);
66          }
67  
68          @Override
69          protected DormandPrince54Integrator buildIntegrator(double[][] tolerances) {
70              return null;
71          }
72      }
73  }