1   /* Copyright 2002-2022 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.utils;
18  
19  import java.util.List;
20  import java.util.Map;
21  import java.util.stream.Collectors;
22  
23  import org.orekit.propagation.SpacecraftState;
24  import org.orekit.propagation.numerical.EpochDerivativesEquations;
25  import org.orekit.propagation.numerical.NumericalPropagator;
26  
27  /**
28   * Multiple shooting method applicable for trajectories, in an ephemeris model.
29   * Not suited for closed orbits.
30   * @see "TRAJECTORY DESIGN AND ORBIT MAINTENANCE STRATEGIES IN MULTI-BODY DYNAMICAL REGIMES by Thomas A. Pavlak, Purdue University"
31   * @author William Desprats
32   * @since 10.2
33   */
34  public class MultipleShooter extends AbstractMultipleShooting {
35  
36      /** Name of the additional derivatives. */
37      private static final String DERIVATIVES = "derivatives";
38  
39      /** Derivatives linked to the Propagators.
40       * @since 11.1
41       */
42      private final List<EpochDerivativesEquations> epochEquations;
43  
44      /** Simple Constructor.
45       * <p> Standard constructor for multiple shooting which can be used with the CR3BP model.</p>
46       * @param initialGuessList initial patch points to be corrected.
47       * @param propagatorList list of propagators associated to each patch point.
48       * @param additionalEquations list of additional equations linked to propagatorList.
49       * @param arcDuration initial guess of the duration of each arc.
50       * @param tolerance convergence tolerance on the constraint vector
51       * @deprecated as of 11.1, replaced by {@link #MultipleShooter(List, List, List, double, double, int)}
52       */
53      @Deprecated
54      public MultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
55                             final List<org.orekit.propagation.integration.AdditionalEquations> additionalEquations,
56                             final double arcDuration, final double tolerance) {
57          super(initialGuessList, propagatorList, additionalEquations, arcDuration, tolerance, DERIVATIVES);
58          epochEquations = additionalEquations.stream().map(ae -> (EpochDerivativesEquations) ae).collect(Collectors.toList());
59      }
60  
61      /** Simple Constructor.
62       * <p> Standard constructor for multiple shooting which can be used with the CR3BP model.</p>
63       * @param initialGuessList initial patch points to be corrected.
64       * @param propagatorList list of propagators associated to each patch point.
65       * @param epochEquations list of additional derivatives providers linked to propagatorList.
66       * @param arcDuration initial guess of the duration of each arc.
67       * @param tolerance convergence tolerance on the constraint vector
68       * @param maxIter maximum number of iterations
69       */
70      public MultipleShooter(final List<SpacecraftState> initialGuessList, final List<NumericalPropagator> propagatorList,
71                             final List<EpochDerivativesEquations> epochEquations, final double arcDuration,
72                             final double tolerance, final int maxIter) {
73          super(initialGuessList, propagatorList, arcDuration, tolerance, maxIter, DERIVATIVES);
74          this.epochEquations = epochEquations;
75      }
76  
77      /** {@inheritDoc} */
78      protected SpacecraftState getAugmentedInitialState(final int i) {
79          return epochEquations.get(i).setInitialJacobians(getPatchPoint(i));
80      }
81  
82      /** {@inheritDoc} */
83      protected double[][] computeAdditionalJacobianMatrix(final List<SpacecraftState> propagatedSP) {
84          final Map<Integer, Double> mapConstraints = getConstraintsMap();
85  
86          final int n = mapConstraints.size();
87          final int ncolumns = getNumberOfFreeVariables() - 1;
88  
89          final double[][] M = new double[n][ncolumns];
90  
91          int k = 0;
92          for (int index : mapConstraints.keySet()) {
93              M[k][index] = 1;
94              k++;
95          }
96          return M;
97      }
98  
99      /** {@inheritDoc} */
100     protected double[] computeAdditionalConstraints(final List<SpacecraftState> propagatedSP) {
101         // The additional constraint vector has the following form :
102 
103         //           [ y1i - y1d ]---- other constraints (component of
104         // Fadd(X) = [    ...    ]    | a patch point equals to a
105         //           [vz2i - vz2d]----  desired value)
106 
107         // Number of additional constraints
108         final int      n             = getConstraintsMap().size();
109         final double[] fxAdditionnal = new double[n];
110 
111         // Update additional constraints
112         updateAdditionalConstraints(0, fxAdditionnal);
113         return fxAdditionnal;
114     }
115 
116 }