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 package org.orekit.propagation.numerical;
18
19 import java.util.List;
20
21 import org.hipparchus.linear.MatrixUtils;
22 import org.hipparchus.linear.RealMatrix;
23 import org.orekit.orbits.Orbit;
24 import org.orekit.orbits.OrbitType;
25 import org.orekit.orbits.PositionAngleType;
26 import org.orekit.propagation.AbstractMatricesHarvester;
27 import org.orekit.propagation.SpacecraftState;
28 import org.orekit.utils.DoubleArrayDictionary;
29
30 /** Harvester between two-dimensional Jacobian matrices and one-dimensional {@link
31 * SpacecraftState#getAdditionalState(String) additional state arrays}.
32 * @author Luc Maisonobe
33 * @since 11.1
34 */
35 class NumericalPropagationHarvester extends AbstractMatricesHarvester {
36
37 /** Propagator bound to this harvester. */
38 private final NumericalPropagator propagator;
39
40 /** Columns names for parameters. */
41 private List<String> columnsNames;
42
43 /** Simple constructor.
44 * <p>
45 * The arguments for initial matrices <em>must</em> be compatible with the {@link org.orekit.orbits.OrbitType orbit type}
46 * and {@link PositionAngleType position angle} that will be used by propagator
47 * </p>
48 * <p>
49 * If the initial matrix is 7x7, it means that the mass is considered as being a state variable.
50 * </p>
51 * @param propagator propagator bound to this harvester
52 * @param stmName State Transition Matrix state name
53 * @param initialStm initial State Transition Matrix ∂Y/∂Y₀,
54 * if null (which is the most frequent case), assumed to be 6x6 identity
55 * @param initialJacobianColumns initial columns of the Jacobians matrix with respect to parameters,
56 * if null or if some selected parameters are missing from the dictionary, the corresponding
57 * initial column is assumed to be 0
58 */
59 NumericalPropagationHarvester(final NumericalPropagator propagator, final String stmName,
60 final RealMatrix initialStm, final DoubleArrayDictionary initialJacobianColumns) {
61 super(stmName, initialStm, initialJacobianColumns);
62 this.propagator = propagator;
63 this.columnsNames = null;
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 protected double[][] getConversionJacobian(final SpacecraftState state) {
69
70 final double[][] identity = super.getConversionJacobian(state);
71
72 if (state.isOrbitDefined() && state.getOrbit().getType() != OrbitType.CARTESIAN) {
73 // make sure the state is in the desired orbit type
74 final Orbit orbit = propagator.getOrbitType().convertType(state.getOrbit());
75
76 // compute the Jacobian, taking the position angle type into account
77 final double[][] dYdC = new double[identity.length][identity[0].length];
78 orbit.getJacobianWrtCartesian(propagator.getPositionAngleType(), dYdC);
79 return dYdC;
80 } else {
81 return identity;
82 }
83
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public void freezeColumnsNames() {
89 columnsNames = getJacobiansColumnsNames();
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public List<String> getJacobiansColumnsNames() {
95 return columnsNames == null ? propagator.getJacobiansColumnsNames() : columnsNames;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public OrbitType getOrbitType() {
101 return propagator.getOrbitType();
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 public PositionAngleType getPositionAngleType() {
107 return propagator.getPositionAngleType();
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 public RealMatrix getStateTransitionMatrix(final SpacecraftState state) {
113
114 if (!state.hasAdditionalData(getStmName())) {
115 return null;
116 }
117
118 // extract the additional state
119 final double[] p = state.getAdditionalState(getStmName());
120 final RealMatrix dCdY0 = toSquareMatrix(p);
121
122 final RealMatrix dYdY0;
123 if (!state.isOrbitDefined() || state.getOrbit().getType() == OrbitType.CARTESIAN) {
124 dYdY0 = dCdY0;
125 } else {
126 // get the conversion Jacobian
127 final RealMatrix dYdC = MatrixUtils.createRealIdentityMatrix(getStateDimension());
128 dYdC.setSubMatrix(getConversionJacobian(state), 0, 0);
129
130 // compute dYdC * dCdY0
131 dYdY0 = dYdC.multiply(dCdY0);
132 }
133
134 return dYdY0;
135
136 }
137
138 }