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.propagation.integration;
18
19 import java.util.List;
20 import java.util.stream.Collectors;
21
22 import org.hipparchus.linear.Array2DRowRealMatrix;
23 import org.hipparchus.linear.RealMatrix;
24 import org.orekit.propagation.MatricesHarvester;
25 import org.orekit.propagation.SpacecraftState;
26 import org.orekit.utils.ParameterDriversList;
27
28 /** Base class for jacobian mapper.
29 * @author Bryan Cazabonne
30 * @since 10.0
31 */
32 public abstract class AbstractJacobiansMapper implements MatricesHarvester {
33
34 /** State dimension, fixed to 6.
35 * @since 9.0
36 */
37 public static final int STATE_DIMENSION = 6;
38
39 /** Name. */
40 private String name;
41
42 /** Selected parameters for Jacobian computation. */
43 private final ParameterDriversList parameters;
44
45 /** Simple constructor.
46 * @param name name of the Jacobians
47 * @param parameters selected parameters for Jacobian computation
48 */
49 protected AbstractJacobiansMapper(final String name, final ParameterDriversList parameters) {
50 this.name = name;
51 this.parameters = parameters;
52 }
53
54 /** Get the name of the partial Jacobians.
55 * @return name of the Jacobians
56 */
57 public String getName() {
58 return name;
59 }
60
61 /** Get the number of parameters.
62 * @return number of parameters
63 */
64 public int getParameters() {
65 return parameters.getNbParams();
66 }
67
68 /** Compute the length of the one-dimensional additional state array needed.
69 * @return length of the one-dimensional additional state array
70 */
71 public int getAdditionalStateDimension() {
72 return STATE_DIMENSION * (STATE_DIMENSION + parameters.getNbParams());
73 }
74
75 /** Not used anymore.
76 * @param s spacecraft state
77 * @deprecated as of 11.1, not used anymore
78 */
79 @Deprecated
80 public void analyticalDerivatives(final SpacecraftState s) {
81 // nothing by default
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public void setReferenceState(final SpacecraftState reference) {
87 // nothing by default
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 public RealMatrix getStateTransitionMatrix(final SpacecraftState s) {
93 final double[][] dYdY0 = new double[STATE_DIMENSION][STATE_DIMENSION];
94 getStateJacobian(s, dYdY0);
95 return new Array2DRowRealMatrix(dYdY0, false);
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public RealMatrix getParametersJacobian(final SpacecraftState s) {
101 if (getParameters() == 0) {
102 return null;
103 } else {
104 final double[][] dYdP = new double[STATE_DIMENSION][getParameters()];
105 getParametersJacobian(s, dYdP);
106 return new Array2DRowRealMatrix(dYdP, false);
107 }
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public List<String> getJacobiansColumnsNames() {
113 return parameters.getDrivers().stream().map(d -> d.getName()).collect(Collectors.toList());
114 }
115
116 /** Set the Jacobian with respect to state into a one-dimensional additional state array.
117 * @param state spacecraft state
118 * @param dY1dY0 Jacobian of current state at time t₁
119 * with respect to state at some previous time t₀
120 * @param dY1dP Jacobian of current state at time t₁
121 * with respect to parameters (may be null if there are no parameters)
122 * @param p placeholder where to put the one-dimensional additional state
123 * @see #getStateJacobian(SpacecraftState, double[][])
124 */
125 public abstract void setInitialJacobians(SpacecraftState state, double[][] dY1dY0, double[][] dY1dP, double[] p);
126
127 /** Get the Jacobian with respect to state from a one-dimensional additional state array.
128 * <p>
129 * This method extract the data from the {@code state} and put it in the
130 * {@code dYdY0} array.
131 * <p>
132 * @param state spacecraft state
133 * @param dYdY0 placeholder where to put the Jacobian with respect to state
134 * @see #getParametersJacobian(SpacecraftState, double[][])
135 */
136 public abstract void getStateJacobian(SpacecraftState state, double[][] dYdY0);
137
138 /** Get the Jacobian with respect to parameters from a one-dimensional additional state array.
139 * <p>
140 * This method extract the data from the {@code state} and put it in the
141 * {@code dYdP} array.
142 * </p>
143 * <p>
144 * If no parameters have been set in the constructor, the method returns immediately and
145 * does not reference {@code dYdP} which can safely be null in this case.
146 * </p>
147 * @param state spacecraft state
148 * @param dYdP placeholder where to put the Jacobian with respect to parameters
149 * @see #getStateJacobian(SpacecraftState, double[][])
150 */
151 public abstract void getParametersJacobian(SpacecraftState state, double[][] dYdP);
152
153 }