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;
18  
19  import org.hipparchus.linear.MatrixUtils;
20  import org.hipparchus.linear.RealMatrix;
21  import org.junit.jupiter.params.ParameterizedTest;
22  import org.junit.jupiter.params.provider.EnumSource;
23  import org.junit.jupiter.params.provider.ValueSource;
24  import org.orekit.frames.FramesFactory;
25  import org.orekit.frames.LOFType;
26  import org.orekit.orbits.EquinoctialOrbit;
27  import org.orekit.orbits.Orbit;
28  import org.orekit.orbits.OrbitType;
29  import org.orekit.orbits.PositionAngleType;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.utils.Constants;
32  
33  import static org.junit.jupiter.api.Assertions.*;
34  
35  class LinearKeplerianCovarianceMapperTest {
36  
37      @ParameterizedTest
38      @EnumSource(OrbitType.class)
39      void testMapIdentity(final OrbitType orbitType) {
40          // GIVEN
41          final Orbit equinoctialOrbit = new EquinoctialOrbit(7e6, 0.01, 0.001, 1, 2, 3, PositionAngleType.TRUE, FramesFactory.getGCRF(),
42                  AbsoluteDate.ARBITRARY_EPOCH, Constants.EGM96_EARTH_MU);
43          final Orbit orbit = orbitType.convertType(equinoctialOrbit);
44          final RealMatrix covarianceMatrix = MatrixUtils.createRealIdentityMatrix(6);
45          final LOFType lofType = LOFType.QSW;
46          final StateCovariance covariance = new StateCovariance(covarianceMatrix, orbit.getDate(), lofType);
47          final LinearKeplerianCovarianceMapper mapper = new LinearKeplerianCovarianceMapper(orbit, covariance);
48          // WHEN
49          final StateCovariance mappedCovariance = mapper.map(orbit);
50          // THEN
51          assertEquals(lofType, mappedCovariance.getLOF());
52          for (int i = 0; i < covarianceMatrix.getRowDimension(); i++) {
53              assertArrayEquals(covarianceMatrix.getRow(i), mappedCovariance.getMatrix().getRow(i), 1e-5);
54          }
55      }
56  
57      @ParameterizedTest
58      @ValueSource(doubles = {1e2, 1e3, 1e4, 1e5})
59      void testMapEquinoctial() {
60          // GIVEN
61          final double dt = 1e2;
62          final PositionAngleType positionAngleType = PositionAngleType.MEAN;
63          final EquinoctialOrbit orbit = new EquinoctialOrbit(7e6, 0.01, 0.001, 1, 2, 3, positionAngleType, FramesFactory.getGCRF(),
64                  AbsoluteDate.ARBITRARY_EPOCH, Constants.EGM96_EARTH_MU);
65          final RealMatrix covarianceMatrix = MatrixUtils.createRealIdentityMatrix(6).scalarMultiply(1e-2);
66          covarianceMatrix.setEntry(0, 0, 10);
67          final StateCovariance covariance = new StateCovariance(covarianceMatrix, orbit.getDate(), orbit.getFrame(),
68                  orbit.getType(), orbit.getCachedPositionAngleType());
69          final LinearKeplerianCovarianceMapper mapper = new LinearKeplerianCovarianceMapper(orbit, covariance);
70          final Orbit shitedOrbit = orbit.shiftedBy(dt);
71          // WHEN
72          final StateCovariance mappedCovariance = mapper.map(shitedOrbit);
73          // THEN
74          final RealMatrix stm = MatrixUtils.createRealIdentityMatrix(6);
75          final double contribution = orbit.getMeanAnomalyDotWrtA() * dt;
76          stm.setEntry(5, 0, contribution);
77          final RealMatrix expectedCovarianceMatrix = stm.multiply(covarianceMatrix.multiplyTransposed(stm));
78          assertEquals(shitedOrbit.getDate(), mappedCovariance.getDate());
79          assertEquals(shitedOrbit.getFrame(), mappedCovariance.getFrame());
80          assertEquals(OrbitType.EQUINOCTIAL, mappedCovariance.getOrbitType());
81  
82          assertArrayEquals(expectedCovarianceMatrix.getRow(0), mappedCovariance.getMatrix().getRow(0), 1e-2);
83          for (int i = 1; i < covarianceMatrix.getRowDimension(); i++) {
84              assertArrayEquals(expectedCovarianceMatrix.getRow(i), mappedCovariance.getMatrix().getRow(i), 1e-7);
85          }
86      }
87  }