1 /* Copyright 2002-2015 CS Systèmes d'Information
2 * Licensed to CS Systèmes d'Information (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.semianalytical.dsst.utilities;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.math3.complex.Complex;
23
24 /** Compute the S<sub>j</sub>(k, h) and the C<sub>j</sub>(k, h) series
25 * and their partial derivatives with respect to k and h.
26 * <p>
27 * Those series are given in Danielson paper by expression 2.5.3-(5):
28 * <pre>C<sub>j</sub>(k, h) + i S<sub>j</sub>(k, h) = (k+ih)<sup>j</sup> </pre>
29 * </p>
30 * The C<sub>j</sub>(k, h) and the S<sub>j</sub>(k, h) elements are store as an
31 * {@link ArrayList} of {@link Complex} number, the C<sub>j</sub>(k, h) being
32 * represented by the real and the S<sub>j</sub>(k, h) by the imaginary part.
33 */
34 public class CjSjCoefficient {
35
36 /** Last computed order j. */
37 private int jLast;
38
39 /** Complex base (k + ih) of the C<sub>j</sub>, S<sub>j</sub> series. */
40 private final Complex kih;
41
42 /** List of computed elements. */
43 private final List<Complex> cjsj;
44
45 /** C<sub>j</sub>(k, h) and S<sub>j</sub>(k, h) constructor.
46 * @param k k value
47 * @param h h value
48 */
49 public CjSjCoefficient(final double k, final double h) {
50 kih = new Complex(k, h);
51 cjsj = new ArrayList<Complex>();
52 cjsj.add(new Complex(1, 0));
53 cjsj.add(kih);
54 jLast = 1;
55 }
56
57 /** Get the C<sub>j</sub> coefficient.
58 * @param j order
59 * @return C<sub>j</sub>
60 */
61 public double getCj(final int j) {
62 if (j > jLast) {
63 // Update to order j
64 updateCjSj(j);
65 }
66 return cjsj.get(j).getReal();
67 }
68
69 /** Get the S<sub>j</sub> coefficient.
70 * @param j order
71 * @return S<sub>j</sub>
72 */
73 public double getSj(final int j) {
74 if (j > jLast) {
75 // Update to order j
76 updateCjSj(j);
77 }
78 return cjsj.get(j).getImaginary();
79 }
80
81 /** Get the dC<sub>j</sub> / dk coefficient.
82 * @param j order
83 * @return dC<sub>j</sub> / d<sub>k</sub>
84 */
85 public double getDcjDk(final int j) {
86 return j == 0 ? 0 : j * getCj(j - 1);
87 }
88
89 /** Get the dS<sub>j</sub> / dk coefficient.
90 * @param j order
91 * @return dS<sub>j</sub> / d<sub>k</sub>
92 */
93 public double getDsjDk(final int j) {
94 return j == 0 ? 0 : j * getSj(j - 1);
95 }
96
97 /** Get the dC<sub>j</sub> / dh coefficient.
98 * @param j order
99 * @return dC<sub>i</sub> / d<sub>k</sub>
100 */
101 public double getDcjDh(final int j) {
102 return j == 0 ? 0 : -j * getSj(j - 1);
103 }
104
105 /** Get the dS<sub>j</sub> / dh coefficient.
106 * @param j order
107 * @return dS<sub>j</sub> / d<sub>h</sub>
108 */
109 public double getDsjDh(final int j) {
110 return j == 0 ? 0 : j * getCj(j - 1);
111 }
112
113 /** Update the cjsj up to order j.
114 * @param j order
115 */
116 private void updateCjSj(final int j) {
117 Complex last = cjsj.get(cjsj.size() - 1);
118 for (int i = jLast; i < j; i++) {
119 final Complex next = last.multiply(kih);
120 cjsj.add(next);
121 last = next;
122 }
123 jLast = j;
124 }
125 }