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.hipparchus.ode.nonstiff.AdaptiveStepsizeIntegrator;
20  import org.hipparchus.ode.nonstiff.DormandPrince853Integrator;
21  import org.hipparchus.util.FastMath;
22  import org.hipparchus.util.MathUtils;
23  import org.junit.Assert;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.orekit.Utils;
27  import org.orekit.frames.FramesFactory;
28  import org.orekit.orbits.CircularOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.orbits.PositionAngle;
31  import org.orekit.propagation.SpacecraftState;
32  import org.orekit.propagation.numerical.NumericalPropagator;
33  import org.orekit.time.AbsoluteDate;
34  import org.orekit.time.TimeScalesFactory;
35  import org.orekit.utils.Constants;
36  
37  
38  public class OsculatingToMeanElementsConverterTest {
39  
40      @Test
41      public void testTrivial() throws Exception {
42          final AbsoluteDate date = new AbsoluteDate("2011-12-12T11:57:20.000", TimeScalesFactory.getUTC());
43          final Orbit orbit1 = new CircularOrbit(7204535.848109436, -4.484755873986251E-4, 0.0011562979012178316,
44                                                 FastMath.toRadians(98.74341600466741), FastMath.toRadians(43.32990110790338),
45                                                 FastMath.toRadians(180.0), PositionAngle.MEAN, FramesFactory.getGCRF(),
46                                                 date, Constants.WGS84_EARTH_MU);
47          final SpacecraftState initialState = new SpacecraftState(orbit1);
48          // Set up the numerical propagator
49          final double[][] tol = NumericalPropagator.tolerances(1.0, initialState.getOrbit(), initialState.getOrbit().getType());
50          final double minStep = 1.;
51          final double maxStep = 200.;
52          AdaptiveStepsizeIntegrator integrator = new DormandPrince853Integrator(minStep, maxStep, tol[0], tol[1]);
53          integrator.setInitialStepSize(100.);
54          final NumericalPropagator prop = new NumericalPropagator(integrator);
55          prop.setInitialState(initialState);
56  
57          final OsculatingToMeanElementsConverter converter = new OsculatingToMeanElementsConverter(initialState, 2, prop, 1.0);
58          final SpacecraftState meanOrbit = converter.convert();
59  
60          final double eps  = 1.e-15;
61  
62          Assert.assertEquals(orbit1.getA(), meanOrbit.getA(), eps * orbit1.getA());
63          Assert.assertEquals(orbit1.getEquinoctialEx(), meanOrbit.getEquinoctialEx(), eps);
64          Assert.assertEquals(orbit1.getEquinoctialEy(), meanOrbit.getEquinoctialEy(), eps);
65          Assert.assertEquals(orbit1.getHx(), meanOrbit.getHx(), eps);
66          Assert.assertEquals(orbit1.getHy(), meanOrbit.getHy(), eps);
67          Assert.assertEquals(MathUtils.normalizeAngle(orbit1.getLM(), FastMath.PI),
68                              MathUtils.normalizeAngle(meanOrbit.getLM(), FastMath.PI), eps);
69      }
70  
71      @Before
72      public void setUp() throws Exception {
73          Utils.setDataRoot("regular-data:potential/shm-format");
74      }
75  
76  }