1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.propagation.semianalytical.dsst.utilities;
18
19 import java.util.TreeMap;
20
21 import org.apache.commons.math3.util.FastMath;
22 import org.orekit.errors.OrekitException;
23 import org.orekit.errors.OrekitMessages;
24
25
26
27
28
29
30 public class CoefficientsFactory {
31
32
33 private static TreeMap<NSKey, Double> VNS = new TreeMap<NSKey, Double>();
34
35
36 private static int LAST_VNS_ORDER = 2;
37
38
39 static {
40
41 VNS.put(new NSKey(0, 0), 1.);
42 VNS.put(new NSKey(1, 0), 0.);
43 VNS.put(new NSKey(1, 1), 0.5);
44 }
45
46
47
48 private CoefficientsFactory() {
49 }
50
51
52
53
54
55
56
57
58
59
60
61 public static double[][] computeQns(final double gamma, final int nMax, final int sMax) {
62
63
64 final int sDim = FastMath.min(sMax + 1, nMax) + 1;
65 final double[][] Qns = new double[nMax + 1][];
66 for (int i = 0; i <= nMax; i++) {
67 final int snDim = FastMath.min(i + 1, sDim);
68 Qns[i] = new double[snDim];
69 }
70
71
72 Qns[0][0] = 1;
73
74 for (int n = 1; n <= nMax; n++) {
75 final int snDim = FastMath.min(n + 1, sDim);
76 for (int s = 0; s < snDim; s++) {
77 if (n == s) {
78 Qns[n][s] = (2. * s - 1.) * Qns[s - 1][s - 1];
79 } else if (n == (s + 1)) {
80 Qns[n][s] = (2. * s + 1.) * gamma * Qns[s][s];
81 } else {
82 Qns[n][s] = (2. * n - 1.) * gamma * Qns[n - 1][s] - (n + s - 1.) * Qns[n - 2][s];
83 Qns[n][s] /= n - s;
84 }
85 }
86 }
87
88 return Qns;
89 }
90
91
92
93
94
95
96
97
98
99
100
101 public static double[][] computeGsHs(final double k, final double h,
102 final double alpha, final double beta,
103 final int order) {
104
105 final double hamkb = h * alpha - k * beta;
106 final double kaphb = k * alpha + h * beta;
107
108 final double[][] GsHs = new double[2][order + 1];
109 GsHs[0][0] = 1.;
110 GsHs[1][0] = 0.;
111
112 for (int s = 1; s <= order; s++) {
113
114 GsHs[0][s] = kaphb * GsHs[0][s - 1] - hamkb * GsHs[1][s - 1];
115
116 GsHs[1][s] = hamkb * GsHs[0][s - 1] + kaphb * GsHs[1][s - 1];
117 }
118
119 return GsHs;
120 }
121
122
123
124
125
126 public static TreeMap<NSKey, Double> computeVns(final int order) {
127
128 if (order > LAST_VNS_ORDER) {
129
130
131 final int min = (LAST_VNS_ORDER - 2 < 0) ? 0 : (LAST_VNS_ORDER - 2);
132 for (int n = min; n < order; n++) {
133 for (int s = 0; s < n + 1; s++) {
134 if ((n - s) % 2 != 0) {
135 VNS.put(new NSKey(n, s), 0.);
136 } else {
137
138 if (n == s && (s + 1) < order) {
139 VNS.put(new NSKey(s + 1, s + 1), VNS.get(new NSKey(s, s)) / (2 * s + 2.));
140 }
141
142 if ((n + 2) < order) {
143 VNS.put(new NSKey(n + 2, s), VNS.get(new NSKey(n, s)) * (-n + s - 1.) / (n + s + 2.));
144 }
145 }
146 }
147 }
148 LAST_VNS_ORDER = order;
149 }
150 return VNS;
151 }
152
153
154
155
156
157
158
159
160
161
162
163 public static double getVmns(final int m, final int n, final int s,
164 final double fns, final double fnm)
165 throws OrekitException {
166 if (m > n) {
167 throw new OrekitException(OrekitMessages.DSST_VMNS_COEFFICIENT_ERROR_MS, m, n);
168 }
169
170 double result = 0;
171
172 if ((n - s) % 2 == 0) {
173
174 if ((n + 1) > LAST_VNS_ORDER) {
175 computeVns(n + 1);
176 }
177 if (s >= 0) {
178 result = fns * VNS.get(new NSKey(n, s)) / fnm;
179 } else {
180
181 final int mops = (s % 2 == 0) ? 1 : -1;
182 result = mops * fns * VNS.get(new NSKey(n, -s)) / fnm;
183 }
184 }
185 return result;
186 }
187
188
189 public static class NSKey implements Comparable<NSKey> {
190
191
192 private final int n;
193
194
195 private final int s;
196
197
198
199
200
201 public NSKey(final int n, final int s) {
202 this.n = n;
203 this.s = s;
204 }
205
206
207
208
209 public int getN() {
210 return n;
211 }
212
213
214
215
216 public int getS() {
217 return s;
218 }
219
220
221 public int compareTo(final NSKey key) {
222 int result = 1;
223 if (n == key.n) {
224 if (s < key.s) {
225 result = -1;
226 } else if (s == key.s) {
227 result = 0;
228 }
229 } else if (n < key.n) {
230 result = -1;
231 }
232 return result;
233 }
234
235
236 public boolean equals(final Object key) {
237
238 if (key == this) {
239
240 return true;
241 }
242
243 if ((key != null) && (key instanceof NSKey)) {
244 return (n == ((NSKey) key).n) && (s == ((NSKey) key).s);
245 }
246
247 return false;
248
249 }
250
251
252 public int hashCode() {
253 return 0x998493a6 ^ (n << 8) ^ s;
254 }
255
256 }
257
258
259 public static class MNSKey implements Comparable<MNSKey> {
260
261
262 private final int m;
263
264
265 private final int n;
266
267
268 private final int s;
269
270
271
272
273
274
275 public MNSKey(final int m, final int n, final int s) {
276 this.m = m;
277 this.n = n;
278 this.s = s;
279 }
280
281
282 public int compareTo(final MNSKey key) {
283 int result = 1;
284 if (m == key.m) {
285 if (n == key.n) {
286 if (s < key.s) {
287 result = -1;
288 } else if (s == key.s) {
289 result = 0;
290 } else {
291 result = 1;
292 }
293 } else if (n < key.n) {
294 result = -1;
295 } else {
296 result = 1;
297 }
298 } else if (m < key.m) {
299 result = -1;
300 }
301 return result;
302 }
303
304
305 public boolean equals(final Object key) {
306
307 if (key == this) {
308
309 return true;
310 }
311
312 if ((key != null) && (key instanceof MNSKey)) {
313 return (m == ((MNSKey) key).m) &&
314 (n == ((MNSKey) key).n) &&
315 (s == ((MNSKey) key).s);
316 }
317
318 return false;
319
320 }
321
322
323 public int hashCode() {
324 return 0x25baa451 ^ (m << 16) ^ (n << 8) ^ s;
325 }
326
327 }
328
329 }