1   /* Copyright 2002-2021 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.semianalytical.dsst.utilities;
18  
19  import java.util.TreeMap;
20  
21  import org.hipparchus.Field;
22  import org.hipparchus.CalculusFieldElement;
23  import org.hipparchus.util.MathArrays;
24  import org.orekit.propagation.semianalytical.dsst.utilities.CoefficientsFactory.NSKey;
25  
26  /** Compute the L<sub>n</sub><sup>s</sup>(γ).
27   *  <p>
28   *  The fomula used is: <br>
29   *  L<sub>n</sub><sup>s</sup>(γ) = ( R / a )<sup>n</sup>V<sub>ns</sub>Q<sup>ns</sup>(γ)
30   *  </p>
31   *  @author Lucian Barbulescu
32   */
33  public class FieldLnsCoefficients <T extends CalculusFieldElement<T>> {
34  
35      /** The coefficients L<sub>n</sub><sup>s</sup>(γ). */
36      private final T[][] lns;
37  
38      /** The coefficients dL<sub>n</sub><sup>s</sup>(γ) / dγ. */
39      private final T[][] dlns;
40  
41      /** Create a set of L<sub>n</sub><sup>s</sup>(γ) coefficients.
42      *
43      * @param nMax maximum value for n
44      * @param sMax maximum value for s
45      * @param Qns the Q<sup>ns</sup>(γ) coefficients
46      * @param Vns the V<sub>ns</sub> coefficients
47      * @param roa (R / a)
48      * @param field field used by default
49      */
50      public FieldLnsCoefficients(final int nMax, final int sMax,
51                                  final T[][] Qns, final TreeMap<NSKey, Double> Vns, final T roa,
52                                  final Field<T> field) {
53          final T zero      = field.getZero();
54          final int rows    = nMax + 1;
55          final int columns = sMax + 1;
56          this.lns          = MathArrays.buildArray(field, rows, columns);
57          this.dlns         = MathArrays.buildArray(field, rows, columns);
58  
59          final T[] roaPow = MathArrays.buildArray(field, rows);
60          roaPow[0] = zero.add(1.);
61          for (int i = 1; i <= nMax; i++) {
62              roaPow[i] = roa.multiply(roaPow[i - 1]);
63          }
64          for (int s = 0; s <= sMax; s++) {
65              for (int n = s; n <= nMax; n++) {
66                  // if (n - s) is not even L<sub>n</sub><sup>s</sup>(γ) is 0
67                  if ((n - s) % 2 == 0) {
68                      final T coef = roaPow[n].multiply(Vns.get(new NSKey(n, s)));
69                      lns[n][s] = coef.multiply(Qns[n][s]);
70                      if ( n == s) {
71                          // if n == s the derivative is 0 because Q[n][s+1] == Q[n][n+1] is 0
72                          dlns[n][s] = zero;
73                      } else {
74                          dlns[n][s] = coef.multiply(Qns[n][s + 1]);
75                      }
76                  } else {
77                      lns[n][s]  = zero;
78                      dlns[n][s] = zero;
79                  }
80              }
81          }
82  
83      }
84  
85     /**Get the value of L<sub>n</sub><sup>s</sup>(γ).
86      *
87      * @param n n index
88      * @param s s index
89      * @return L<sub>n</sub><sup>s</sup>(γ)
90      */
91      public T getLns(final int n, final int s) {
92          return lns[n][s];
93      }
94  
95     /**Get the value of dL<sub>n</sub><sup>s</sup> / dγ (γ).
96      *
97      * @param n n index
98      * @param s s index
99      * @return L<sub>n</sub><sup>s</sup>(γ)
100     */
101     public T getdLnsdGamma(final int n, final int s) {
102         return dlns[n][s];
103     }
104 }