CjSjCoefficient.java

  1. /* Copyright 2002-2018 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. import java.util.ArrayList;
  19. import java.util.List;

  20. import org.hipparchus.complex.Complex;

  21. /** Compute the S<sub>j</sub>(k, h) and the C<sub>j</sub>(k, h) series
  22.  *  and their partial derivatives with respect to k and h.
  23.  *  <p>
  24.  *  Those series are given in Danielson paper by expression 2.5.3-(5):
  25.  *
  26.  *  <p> C<sub>j</sub>(k, h) + i S<sub>j</sub>(k, h) = (k+ih)<sup>j</sup>
  27.  *
  28.  *  <p>
  29.  *  The C<sub>j</sub>(k, h) and the S<sub>j</sub>(k, h) elements are store as an
  30.  *  {@link ArrayList} of {@link Complex} number, the C<sub>j</sub>(k, h) being
  31.  *  represented by the real and the S<sub>j</sub>(k, h) by the imaginary part.
  32.  */
  33. public class CjSjCoefficient {

  34.     /** Last computed order j. */
  35.     private int jLast;

  36.     /** Complex base (k + ih) of the C<sub>j</sub>, S<sub>j</sub> series. */
  37.     private final Complex kih;

  38.     /** List of computed elements. */
  39.     private final List<Complex> cjsj;

  40.     /** C<sub>j</sub>(k, h) and S<sub>j</sub>(k, h) constructor.
  41.      * @param k k value
  42.      * @param h h value
  43.      */
  44.     public CjSjCoefficient(final double k, final double h) {
  45.         kih  = new Complex(k, h);
  46.         cjsj = new ArrayList<Complex>();
  47.         cjsj.add(new Complex(1, 0));
  48.         cjsj.add(kih);
  49.         jLast = 1;
  50.     }

  51.     /** Get the C<sub>j</sub> coefficient.
  52.      * @param j order
  53.      * @return C<sub>j</sub>
  54.      */
  55.     public double getCj(final int j) {
  56.         if (j > jLast) {
  57.             // Update to order j
  58.             updateCjSj(j);
  59.         }
  60.         return cjsj.get(j).getReal();
  61.     }

  62.     /** Get the S<sub>j</sub> coefficient.
  63.      * @param j order
  64.      * @return S<sub>j</sub>
  65.      */
  66.     public double getSj(final int j) {
  67.         if (j > jLast) {
  68.             // Update to order j
  69.             updateCjSj(j);
  70.         }
  71.         return cjsj.get(j).getImaginary();
  72.     }

  73.     /** Get the dC<sub>j</sub> / dk coefficient.
  74.      * @param j order
  75.      * @return dC<sub>j</sub> / d<sub>k</sub>
  76.      */
  77.     public double getDcjDk(final int j) {
  78.         return j == 0 ? 0 : j * getCj(j - 1);
  79.     }

  80.     /** Get the dS<sub>j</sub> / dk coefficient.
  81.      * @param j order
  82.      * @return dS<sub>j</sub> / d<sub>k</sub>
  83.      */
  84.     public double getDsjDk(final int j) {
  85.         return j == 0 ? 0 : j * getSj(j - 1);
  86.     }

  87.     /** Get the dC<sub>j</sub> / dh coefficient.
  88.      * @param j order
  89.      * @return dC<sub>i</sub> / d<sub>k</sub>
  90.      */
  91.     public double getDcjDh(final int j) {
  92.         return j == 0 ? 0 : -j * getSj(j - 1);
  93.     }

  94.     /** Get the dS<sub>j</sub> / dh coefficient.
  95.      * @param j order
  96.      * @return dS<sub>j</sub> / d<sub>h</sub>
  97.      */
  98.     public double getDsjDh(final int j) {
  99.         return j == 0 ? 0 : j * getCj(j - 1);
  100.     }

  101.     /** Update the cjsj up to order j.
  102.      * @param j order
  103.      */
  104.     private void updateCjSj(final int j) {
  105.         Complex last = cjsj.get(cjsj.size() - 1);
  106.         for (int i = jLast; i < j; i++) {
  107.             final Complex next = last.multiply(kih);
  108.             cjsj.add(next);
  109.             last = next;
  110.         }
  111.         jLast = j;
  112.     }
  113. }