1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation;
18
19 import java.util.List;
20
21 import org.hipparchus.linear.MatrixUtils;
22 import org.hipparchus.linear.RealMatrix;
23 import org.orekit.orbits.PositionAngleType;
24 import org.orekit.utils.DoubleArrayDictionary;
25
26
27
28
29
30
31 public abstract class AbstractMatricesHarvester implements MatricesHarvester {
32
33
34 public static final int STATE_DIMENSION = 6;
35
36
37 private static final double[][] IDENTITY = {
38 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
39 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
40 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
41 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
42 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
43 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
44 };
45
46
47 private final RealMatrix initialStm;
48
49
50 private final DoubleArrayDictionary initialJacobianColumns;
51
52
53 private final String stmName;
54
55
56
57
58
59
60
61
62
63
64
65
66
67 protected AbstractMatricesHarvester(final String stmName, final RealMatrix initialStm, final DoubleArrayDictionary initialJacobianColumns) {
68 this.stmName = stmName;
69 this.initialStm = initialStm == null ? MatrixUtils.createRealIdentityMatrix(STATE_DIMENSION) : initialStm;
70 this.initialJacobianColumns = initialJacobianColumns == null ? new DoubleArrayDictionary() : initialJacobianColumns;
71 }
72
73
74
75
76 public String getStmName() {
77 return stmName;
78 }
79
80
81
82
83 public RealMatrix getInitialStateTransitionMatrix() {
84 return initialStm;
85 }
86
87
88
89
90
91 public double[] getInitialJacobianColumn(final String columnName) {
92 final DoubleArrayDictionary.Entry entry = initialJacobianColumns.getEntry(columnName);
93 return entry == null ? new double[STATE_DIMENSION] : entry.getValue();
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 protected double[][] getConversionJacobian(final SpacecraftState state) {
110 return IDENTITY;
111 }
112
113
114 @Override
115 public void setReferenceState(final SpacecraftState reference) {
116
117 }
118
119
120 @Override
121 public RealMatrix getStateTransitionMatrix(final SpacecraftState state) {
122
123 if (!state.hasAdditionalState(stmName)) {
124 return null;
125 }
126
127
128 final double[][] dYdC = getConversionJacobian(state);
129
130
131 final double[] p = state.getAdditionalState(stmName);
132
133
134 final RealMatrix dYdY0 = MatrixUtils.createRealMatrix(STATE_DIMENSION, STATE_DIMENSION);
135 for (int i = 0; i < STATE_DIMENSION; i++) {
136 final double[] rowC = dYdC[i];
137 for (int j = 0; j < STATE_DIMENSION; ++j) {
138 double sum = 0;
139 int pIndex = j;
140 for (int k = 0; k < STATE_DIMENSION; ++k) {
141 sum += rowC[k] * p[pIndex];
142 pIndex += STATE_DIMENSION;
143 }
144 dYdY0.setEntry(i, j, sum);
145 }
146 }
147
148 return dYdY0;
149
150 }
151
152
153 @Override
154 public RealMatrix getParametersJacobian(final SpacecraftState state) {
155
156 final List<String> columnsNames = getJacobiansColumnsNames();
157
158 if (columnsNames == null || columnsNames.isEmpty()) {
159 return null;
160 }
161
162
163 final double[][] dYdC = getConversionJacobian(state);
164
165
166 final RealMatrix dYdP = MatrixUtils.createRealMatrix(STATE_DIMENSION, columnsNames.size());
167 for (int j = 0; j < columnsNames.size(); j++) {
168 final double[] p = state.getAdditionalState(columnsNames.get(j));
169 for (int i = 0; i < STATE_DIMENSION; ++i) {
170 final double[] dYdCi = dYdC[i];
171 double sum = 0;
172 for (int k = 0; k < STATE_DIMENSION; ++k) {
173 sum += dYdCi[k] * p[k];
174 }
175 dYdP.setEntry(i, j, sum);
176 }
177 }
178
179 return dYdP;
180
181 }
182
183
184
185
186
187
188 public abstract void freezeColumnsNames();
189
190 }