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