FieldLnsCoefficients.java

  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.semianalytical.dsst.utilities;

  18. import java.util.SortedMap;

  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.Field;
  21. import org.hipparchus.util.MathArrays;
  22. import org.orekit.propagation.semianalytical.dsst.utilities.CoefficientsFactory.NSKey;

  23. /** Compute the L<sub>n</sub><sup>s</sup>(γ).
  24.  *  <p>
  25.  *  The fomula used is: <br>
  26.  *  L<sub>n</sub><sup>s</sup>(γ) = ( R / a )<sup>n</sup>V<sub>ns</sub>Q<sup>ns</sup>(γ)
  27.  *  </p>
  28.  *  @author Lucian Barbulescu
  29.  * @param <T> type of the field elements
  30.  */
  31. public class FieldLnsCoefficients <T extends CalculusFieldElement<T>> {

  32.     /** The coefficients L<sub>n</sub><sup>s</sup>(γ). */
  33.     private final T[][] lns;

  34.     /** The coefficients dL<sub>n</sub><sup>s</sup>(γ) / dγ. */
  35.     private final T[][] dlns;

  36.     /** Create a set of L<sub>n</sub><sup>s</sup>(γ) coefficients.
  37.     *
  38.     * @param nMax maximum value for n
  39.     * @param sMax maximum value for s
  40.     * @param Qns the Q<sup>ns</sup>(γ) coefficients
  41.     * @param Vns the V<sub>ns</sub> coefficients
  42.     * @param roa (R / a)
  43.     * @param field field used by default
  44.     */
  45.     public FieldLnsCoefficients(final int nMax, final int sMax,
  46.                                 final T[][] Qns, final SortedMap<NSKey, Double> Vns, final T roa,
  47.                                 final Field<T> field) {
  48.         final T zero      = field.getZero();
  49.         final int rows    = nMax + 1;
  50.         final int columns = sMax + 1;
  51.         this.lns          = MathArrays.buildArray(field, rows, columns);
  52.         this.dlns         = MathArrays.buildArray(field, rows, columns);

  53.         final T[] roaPow = MathArrays.buildArray(field, rows);
  54.         roaPow[0] = zero.newInstance(1.);
  55.         for (int i = 1; i <= nMax; i++) {
  56.             roaPow[i] = roa.multiply(roaPow[i - 1]);
  57.         }
  58.         for (int s = 0; s <= sMax; s++) {
  59.             for (int n = s; n <= nMax; n++) {
  60.                 // if (n - s) is not even L<sub>n</sub><sup>s</sup>(γ) is 0
  61.                 if ((n - s) % 2 == 0) {
  62.                     final T coef = roaPow[n].multiply(Vns.get(new NSKey(n, s)));
  63.                     lns[n][s] = coef.multiply(Qns[n][s]);
  64.                     if ( n == s) {
  65.                         // if n == s the derivative is 0 because Q[n][s+1] == Q[n][n+1] is 0
  66.                         dlns[n][s] = zero;
  67.                     } else {
  68.                         dlns[n][s] = coef.multiply(Qns[n][s + 1]);
  69.                     }
  70.                 } else {
  71.                     lns[n][s]  = zero;
  72.                     dlns[n][s] = zero;
  73.                 }
  74.             }
  75.         }

  76.     }

  77.    /**Get the value of L<sub>n</sub><sup>s</sup>(γ).
  78.     *
  79.     * @param n n index
  80.     * @param s s index
  81.     * @return L<sub>n</sub><sup>s</sup>(γ)
  82.     */
  83.     public T getLns(final int n, final int s) {
  84.         return lns[n][s];
  85.     }

  86.    /**Get the value of dL<sub>n</sub><sup>s</sup> / dγ (γ).
  87.     *
  88.     * @param n n index
  89.     * @param s s index
  90.     * @return L<sub>n</sub><sup>s</sup>(γ)
  91.     */
  92.     public T getdLnsdGamma(final int n, final int s) {
  93.         return dlns[n][s];
  94.     }
  95. }