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.control.indirect.shooting;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.ode.FieldOrdinaryDifferentialEquation;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.Test;
24  import org.mockito.Mockito;
25  import org.orekit.control.indirect.shooting.propagation.AdjointDynamicsProvider;
26  import org.orekit.control.indirect.shooting.propagation.ShootingIntegrationSettingsFactory;
27  import org.orekit.control.indirect.shooting.propagation.ShootingPropagationSettings;
28  import org.orekit.forces.ForceModel;
29  import org.orekit.frames.FramesFactory;
30  import org.orekit.orbits.CartesianOrbit;
31  import org.orekit.orbits.OrbitType;
32  import org.orekit.propagation.SpacecraftState;
33  import org.orekit.propagation.integration.AdditionalDerivativesProvider;
34  import org.orekit.propagation.numerical.NumericalPropagator;
35  import org.orekit.time.AbsoluteDate;
36  import org.orekit.time.FieldAbsoluteDate;
37  import org.orekit.utils.AbsolutePVCoordinates;
38  import org.orekit.utils.Constants;
39  import org.orekit.utils.PVCoordinates;
40  import org.orekit.utils.TimeStampedPVCoordinates;
41  
42  import java.util.ArrayList;
43  import java.util.List;
44  
45  class AbstractIndirectShootingTest {
46  
47      @Test
48      void testBuildPropagatorOrbit() {
49          // GIVEN
50          final TestShooting testShooting = new TestShooting(createSettings());
51          final SpacecraftState state = new SpacecraftState(createOrbit());
52          // WHEN
53          final NumericalPropagator propagator = testShooting.buildPropagator(state);
54          // THEN
55          Assertions.assertEquals(OrbitType.CARTESIAN, propagator.getOrbitType());
56          Assertions.assertEquals(state.getDate(), propagator.getInitialState().getDate());
57          Assertions.assertEquals(state.getPosition(propagator.getFrame()), propagator.getInitialState().getPosition());
58      }
59  
60      @Test
61      void testBuildPropagator() {
62          // GIVEN
63          final TestShooting testShooting = new TestShooting(createSettings());
64          final CartesianOrbit orbit = createOrbit();
65          final SpacecraftState state = new SpacecraftState(new AbsolutePVCoordinates(orbit.getFrame(),
66                  orbit.getDate(), orbit.getPVCoordinates()));
67          // WHEN
68          final NumericalPropagator propagator = testShooting.buildPropagator(state);
69          // THEN
70          Assertions.assertEquals(state.getDate(), propagator.getInitialState().getDate());
71          Assertions.assertEquals(state.getPosition(propagator.getFrame()), propagator.getInitialState().getPosition());
72      }
73  
74      private ShootingPropagationSettings createSettings() {
75          final List<ForceModel> forceModelList = new ArrayList<>();
76          final ForceModel mockedForceModel = Mockito.mock(ForceModel.class);
77          forceModelList.add(mockedForceModel);
78          final AdjointDynamicsProvider adjointDynamicsProvider = Mockito.mock(AdjointDynamicsProvider.class);
79          Mockito.when(adjointDynamicsProvider.buildAdditionalDerivativesProvider())
80                  .thenReturn(Mockito.mock(AdditionalDerivativesProvider.class));
81          return new ShootingPropagationSettings(forceModelList, adjointDynamicsProvider,
82                  ShootingIntegrationSettingsFactory.getClassicalRungeKuttaIntegratorSettings(1.));
83      }
84  
85      private static CartesianOrbit createOrbit() {
86          return new CartesianOrbit(new TimeStampedPVCoordinates(AbsoluteDate.ARBITRARY_EPOCH,
87                  new PVCoordinates(Vector3D.MINUS_J.scalarMultiply(1e6), Vector3D.MINUS_K.scalarMultiply(10))),
88                  FramesFactory.getGCRF(), Constants.EGM96_EARTH_MU);
89      }
90  
91      private static class TestShooting extends AbstractIndirectShooting {
92  
93          public TestShooting(ShootingPropagationSettings propagationSettings) {
94              super(propagationSettings);
95          }
96  
97          @Override
98          public ShootingBoundaryOutput solve(double initialMass, double[] initialGuess) {
99              return null;
100         }
101     }
102 
103 }