1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.conversion;
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  import org.orekit.estimation.Context;
22  import org.orekit.estimation.EstimationTestUtils;
23  import org.orekit.orbits.CartesianOrbit;
24  import org.orekit.orbits.Orbit;
25  import org.orekit.orbits.PositionAngle;
26  import org.orekit.propagation.Propagator;
27  import org.orekit.propagation.analytical.KeplerianPropagator;
28  import org.orekit.utils.ParameterDriversList.DelegatingDriver;
29  
30  public class AbstractPropagatorBuilderTest {
31  
32      /** Test method restOrbit. */
33      @Test
34      public void testResetOrbit() {
35          // Load a context
36          Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
37          
38          // Use a Cartesian orbit so the parameters are changed sufficiently when shifting the orbit of a minute
39          final Orbit initialOrbit = new CartesianOrbit(context.initialOrbit);
40          
41          final AbstractPropagatorBuilder propagatorBuilder = new AbstractPropagatorBuilder(initialOrbit, PositionAngle.TRUE, 10., true) {
42              
43              @Override
44              public Propagator buildPropagator(double[] normalizedParameters) {
45                  // Dummy function "buildPropagator", copied from KeplerianPropagatorBuilder
46                  setParameters(normalizedParameters);
47                  return new KeplerianPropagator(createInitialOrbit());
48              }
49          };
50          
51          // Shift the orbit of a minute
52          // Reset the builder and check the orbits value
53          final Orbit newOrbit = initialOrbit.shiftedBy(60.);
54          propagatorBuilder.resetOrbit(newOrbit);
55          
56          // Check that the new orbit was properly set in the builder and 
57          Assert.assertEquals(0., propagatorBuilder.getInitialOrbitDate().durationFrom(newOrbit.getDate()), 0.);
58          final double[] stateVector = new double[6];
59          propagatorBuilder.getOrbitType().mapOrbitToArray(newOrbit, PositionAngle.TRUE, stateVector, null);
60          int i = 0;
61          for (DelegatingDriver driver : propagatorBuilder.getOrbitalParametersDrivers().getDrivers()) {
62              final double expectedValue = stateVector[i++];
63              Assert.assertEquals(expectedValue, driver.getValue(), 0.);
64              Assert.assertEquals(expectedValue, driver.getReferenceValue(), 0.);
65          }
66      }
67  }
68