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  
18  package org.orekit.propagation.conversion;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.Utils;
25  import org.orekit.forces.gravity.potential.GravityFieldFactory;
26  import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider;
27  import org.orekit.frames.FramesFactory;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.orbits.PositionAngleType;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.utils.Constants;
33  import org.orekit.utils.PVCoordinates;
34  import org.orekit.utils.TimeStampedPVCoordinates;
35  
36  import static org.orekit.propagation.conversion.AbstractPropagatorBuilderTest.assertPropagatorBuilderIsACopy;
37  
38  public class EcksteinHechlerPropagatorBuilderTest {
39  
40      @BeforeEach
41      public void initialize() {
42          Utils.setDataRoot("potential");
43      }
44  
45      @Test
46      void testClone() {
47  
48          // Given
49          final Orbit orbit = new CartesianOrbit(new PVCoordinates(
50                  new Vector3D(Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS + 400000, 0, 0),
51                  new Vector3D(10, 7668.6, 3)), FramesFactory.getGCRF(),
52                  new AbsoluteDate(), Constants.EIGEN5C_EARTH_MU);
53  
54          final UnnormalizedSphericalHarmonicsProvider harmonicsProvider = GravityFieldFactory.getUnnormalizedProvider(6, 0);
55  
56          final EcksteinHechlerPropagatorBuilder builder = new EcksteinHechlerPropagatorBuilder(orbit, harmonicsProvider,
57                  PositionAngleType.MEAN, 10.0);
58  
59          // When
60          final EcksteinHechlerPropagatorBuilder copyBuilder = builder.clone();
61  
62          // Then
63          assertPropagatorBuilderIsACopy(builder, copyBuilder);
64          Assertions.assertEquals(builder.getImpulseManeuvers().size(), copyBuilder.getImpulseManeuvers().size());
65      }
66  
67      /** Test for issue #1741.
68       * <p>This test checks that orbital drivers in cloned propagator builders
69       * ain't at the same physical address, i.e. that they're not linked anymore.</p>
70       */
71      @Test
72      void testIssue1741() {
73  
74          // Given
75          final Orbit orbit = new CartesianOrbit(new PVCoordinates(
76                          new Vector3D(Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS + 400000, 0, 0),
77                          new Vector3D(10, 7668.6, 3)), FramesFactory.getGCRF(),
78                                                 new AbsoluteDate(), Constants.EIGEN5C_EARTH_MU);
79  
80          final UnnormalizedSphericalHarmonicsProvider harmonicsProvider = GravityFieldFactory.getUnnormalizedProvider(6, 0);
81  
82          final EcksteinHechlerPropagatorBuilder builder = new EcksteinHechlerPropagatorBuilder(orbit, harmonicsProvider,
83                                                                                                PositionAngleType.MEAN, 10.0);
84  
85          // When
86          final EcksteinHechlerPropagatorBuilder copyBuilder = builder.clone();
87  
88          // Change orbit of the copied builder
89          final TimeStampedPVCoordinates modifiedPv = orbit.shiftedBy(3600.).getPVCoordinates();
90          copyBuilder.resetOrbit(new CartesianOrbit(modifiedPv, orbit.getFrame(), orbit.getDate(), orbit.getMu()));
91  
92          // Then
93          // Original builder should still have original orbit
94          final PVCoordinates originalPv = orbit.getPVCoordinates();
95          final PVCoordinates initialPv = builder.createInitialOrbit().getPVCoordinates();
96          final double dP = originalPv.getPosition().distance(initialPv.getPosition());
97          final double dV = originalPv.getVelocity().distance(initialPv.getVelocity());
98          final double dA = originalPv.getAcceleration().distance(initialPv.getAcceleration());
99          Assertions.assertEquals(0., dP, 0.);
100         Assertions.assertEquals(0., dV, 0.);
101         Assertions.assertEquals(0., dA, 0.);
102     }
103 }