1   /* Copyright 2022-2025 Romain Serra
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.numerical;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.junit.jupiter.api.Test;
21  import org.junit.jupiter.params.ParameterizedTest;
22  import org.junit.jupiter.params.provider.EnumSource;
23  import org.orekit.TestUtils;
24  import org.orekit.forces.ForceModel;
25  import org.orekit.forces.gravity.NewtonianAttraction;
26  import org.orekit.orbits.Orbit;
27  import org.orekit.orbits.OrbitType;
28  import org.orekit.orbits.PositionAngleType;
29  import org.orekit.propagation.SpacecraftState;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.utils.Constants;
32  
33  import java.util.ArrayList;
34  import java.util.List;
35  
36  import static org.junit.jupiter.api.Assertions.*;
37  
38  class NumericalTimeDerivativesEquationsTest {
39  
40      @ParameterizedTest
41      @EnumSource(value = OrbitType.class, names = {"EQUINOCTIAL", "KEPLERIAN", "CIRCULAR"})
42      void testComputeTimeDerivatives(final OrbitType orbitType) {
43          // GIVEN
44          final Orbit orbit = TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH);
45          final SpacecraftState state = new SpacecraftState(orbit);
46          final List<ForceModel> forceModelList = new ArrayList<>();
47          final ForceModel forceModel = new NewtonianAttraction(Constants.EGM96_EARTH_MU);
48          forceModelList.add(forceModel);
49          final NumericalTimeDerivativesEquations equations = new NumericalTimeDerivativesEquations(orbitType,
50                  PositionAngleType.MEAN, forceModelList);
51          // WHEN
52          final double[] derivatives = equations.computeTimeDerivatives(state);
53          // THEN
54          assertEquals(7, derivatives.length);
55          for (int i = 0; i < 7; i++) {
56              if (i == 5) {
57                  assertNotEquals(0., derivatives[i]);
58              } else {
59                  assertEquals(0., derivatives[i]);
60              }
61          }
62      }
63  
64      @Test
65      void testComputeTimeDerivativesCartesian() {
66          // GIVEN
67          final Orbit orbit = TestUtils.getDefaultOrbit(AbsoluteDate.ARBITRARY_EPOCH);
68          final SpacecraftState state = new SpacecraftState(orbit);
69          final List<ForceModel> forceModelList = new ArrayList<>();
70          final NewtonianAttraction forceModel = new NewtonianAttraction(Constants.EGM96_EARTH_MU);
71          forceModelList.add(forceModel);
72          final NumericalTimeDerivativesEquations equations = new NumericalTimeDerivativesEquations(OrbitType.CARTESIAN,
73                  PositionAngleType.MEAN, forceModelList);
74          // WHEN
75          final double[] derivatives = equations.computeTimeDerivatives(state);
76          // THEN
77          assertEquals(state.getVelocity().getX(), derivatives[0]);
78          assertEquals(state.getVelocity().getY(), derivatives[1]);
79          assertEquals(state.getVelocity().getZ(), derivatives[2]);
80          final Vector3D acceleration = forceModel.acceleration(state, new double[] {forceModel.getMu(orbit.getDate())});
81          final double tolerance = 1e-10;
82          assertEquals(acceleration.getX(), derivatives[3], tolerance);
83          assertEquals(acceleration.getY(), derivatives[4], tolerance);
84          assertEquals(acceleration.getZ(), derivatives[5], tolerance);
85          assertEquals(0, derivatives[6]);
86      }
87  }