FieldGHmsjPolynomials.java

  1. /* Copyright 2002-2022 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 org.hipparchus.Field;
  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.util.FastMath;

  21. /** Compute the G<sub>ms</sub><sup>j</sup> and the H<sub>ms</sub><sup>j</sup>
  22.  *  polynomials in the equinoctial elements h, k and the direction cosines α and β
  23.  *  and their partial derivatives with respect to k, h, α and β.
  24.  *  <p>
  25.  *  The expressions used are equations 2.7.5-(1)(2) from the Danielson paper.
  26.  *  </p>
  27.  *  @author Romain Di Costanzo
  28.  *  @author Bryan Cazabonne (field translation)
  29.  */
  30. public class FieldGHmsjPolynomials <T extends CalculusFieldElement<T>> {
  31.     /** C<sub>j</sub>(k, h), S<sub>j</sub>(k, h) coefficient.
  32.      * (k, h) are the (x, y) component of the eccentricity vector in equinoctial elements
  33.      */
  34.     private final FieldCjSjCoefficient<T> cjsjKH;

  35.     /** C<sub>j</sub>(α, β), S<sub>j</sub>(α, β) coefficient.
  36.      * (α, β) are the direction cosines
  37.      */
  38.     private final FieldCjSjCoefficient<T> cjsjAB;

  39.     /** Is the orbit represented as a retrograde orbit.
  40.      *  I = -1 if yes, +1 otherwise.
  41.      */
  42.     private int                   I;

  43.     /** Zero for initialization. */
  44.     private final T zero;

  45.     /** Create a set of G<sub>ms</sub><sup>j</sup> and H<sub>ms</sub><sup>j</sup> polynomials.
  46.      *  @param k X component of the eccentricity vector
  47.      *  @param h Y component of the eccentricity vector
  48.      *  @param alpha direction cosine α
  49.      *  @param beta direction cosine β
  50.      *  @param retroFactor -1 if the orbit is represented as retrograde, +1 otherwise
  51.      *  @param field field element
  52.      **/
  53.     public FieldGHmsjPolynomials(final T k, final T h,
  54.                             final T alpha, final T beta,
  55.                             final int retroFactor,
  56.                             final Field<T> field) {
  57.         zero = field.getZero();
  58.         this.cjsjKH = new FieldCjSjCoefficient<>(k, h, field);
  59.         this.cjsjAB = new FieldCjSjCoefficient<>(alpha, beta, field);
  60.         this.I = retroFactor;
  61.     }

  62.     /** Get the G<sub>ms</sub><sup>j</sup> coefficient.
  63.      * @param m m subscript
  64.      * @param s s subscript
  65.      * @param j order
  66.      * @return the G<sub>ms</sub><sup>j</sup>
  67.      */
  68.     public T getGmsj(final int m, final int s, final int j) {
  69.         final int sMj = FastMath.abs(s - j);
  70.         T gms = zero;
  71.         if (FastMath.abs(s) <= m) {
  72.             final int mMis = m - I * s;
  73.             gms = cjsjKH.getCj(sMj).multiply(cjsjAB.getCj(mMis)).
  74.                   subtract(cjsjKH.getSj(sMj).multiply(cjsjAB.getSj(mMis)).multiply(sgn(s - j)).multiply(I));
  75.         } else {
  76.             final int sMim = FastMath.abs(s - I * m);
  77.             gms = cjsjKH.getCj(sMj).multiply(cjsjAB.getCj(sMim)).
  78.                   add(cjsjKH.getSj(sMj).multiply(cjsjAB.getSj(sMim)).multiply(sgn(s - j)).multiply(sgn(s - m)));
  79.         }
  80.         return gms;
  81.     }

  82.     /** Get the H<sub>ms</sub><sup>j</sup> coefficient.
  83.      * @param m m subscript
  84.      * @param s s subscript
  85.      * @param j order
  86.      * @return the H<sub>ms</sub><sup>j</sup>
  87.      */
  88.     public T getHmsj(final int m, final int s, final int j) {
  89.         final int sMj = FastMath.abs(s - j);
  90.         T hms = zero;
  91.         if (FastMath.abs(s) <= m) {
  92.             final int mMis = m - I * s;
  93.             hms = cjsjKH.getCj(sMj).multiply(cjsjAB.getSj(mMis)).multiply(I).
  94.                             add(cjsjKH.getSj(sMj).multiply(cjsjAB.getCj(mMis)).multiply(sgn(s - j)));
  95.         } else {
  96.             final int sMim = FastMath.abs(s - I * m);
  97.             hms = cjsjKH.getCj(sMj).multiply(cjsjAB.getSj(sMim)).multiply(-sgn(s - m)).
  98.                   add(cjsjKH.getSj(sMj).multiply(cjsjAB.getCj(sMim)).multiply(sgn(s - j)));
  99.         }
  100.         return hms;
  101.     }

  102.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>k</sub> coefficient.
  103.      * @param m m subscript
  104.      * @param s s subscript
  105.      * @param j order
  106.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>k</sub>
  107.      */
  108.     public T getdGmsdk(final int m, final int s, final int j) {
  109.         final int sMj = FastMath.abs(s - j);
  110.         T dGmsdk = zero;
  111.         if (FastMath.abs(s) <= m) {
  112.             final int mMis = m - I * s;
  113.             dGmsdk = cjsjKH.getDcjDk(sMj).multiply(cjsjAB.getCj(mMis)).
  114.                      subtract(cjsjKH.getDsjDk(sMj).multiply(cjsjAB.getSj(mMis)).multiply(I).multiply(sgn(s - j)));
  115.         } else {
  116.             final int sMim = FastMath.abs(s - I * m);
  117.             dGmsdk = cjsjKH.getDcjDk(sMj).multiply(cjsjAB.getCj(sMim)).
  118.                      add(cjsjKH.getDsjDk(sMj).multiply(cjsjAB.getSj(sMim)).multiply(sgn(s - m)).multiply(sgn(s - j)));
  119.         }
  120.         return dGmsdk;
  121.     }

  122.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>h</sub> coefficient.
  123.      * @param m m subscript
  124.      * @param s s subscript
  125.      * @param j order
  126.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>h</sub>
  127.      */
  128.     public T getdGmsdh(final int m, final int s, final int j) {
  129.         final int sMj = FastMath.abs(s - j);
  130.         T dGmsdh = zero;
  131.         if (FastMath.abs(s) <= m) {
  132.             final int mMis = m - I * s;
  133.             dGmsdh = cjsjKH.getDcjDh(sMj).multiply(cjsjAB.getCj(mMis)).
  134.                      subtract(cjsjKH.getDsjDh(sMj).multiply(cjsjAB.getSj(mMis)).multiply(I).multiply(sgn(s - j)));
  135.         } else {
  136.             final int sMim = FastMath.abs(s - I * m);
  137.             dGmsdh = cjsjKH.getDcjDh(sMj).multiply(cjsjAB.getCj(sMim)).
  138.                      add(cjsjKH.getDsjDh(sMj).multiply(cjsjAB.getSj(sMim)).multiply(sgn(s - m)).multiply(sgn(s - j)));
  139.         }
  140.         return dGmsdh;
  141.     }

  142.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>α</sub> coefficient.
  143.      * @param m m subscript
  144.      * @param s s subscript
  145.      * @param j order
  146.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>α</sub>
  147.      */
  148.     public T getdGmsdAlpha(final int m, final int s, final int j) {
  149.         final int sMj  = FastMath.abs(s - j);
  150.         T dGmsdAl = zero;
  151.         if (FastMath.abs(s) <= m) {
  152.             final int mMis = m - I * s;
  153.             dGmsdAl = cjsjKH.getCj(sMj).multiply(cjsjAB.getDcjDk(mMis)).
  154.                       subtract(cjsjKH.getSj(sMj).multiply(cjsjAB.getDsjDk(mMis)).multiply(I).multiply(sgn(s - j)));
  155.         } else {
  156.             final int sMim = FastMath.abs(s - I * m);
  157.             dGmsdAl = cjsjKH.getCj(sMj).multiply(cjsjAB.getDcjDk(sMim)).
  158.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDsjDk(sMim)).multiply(sgn(s - j)).multiply(sgn(s - m)));
  159.         }
  160.         return dGmsdAl;
  161.     }

  162.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>β</sub> coefficient.
  163.      * @param m m subscript
  164.      * @param s s subscript
  165.      * @param j order
  166.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>β</sub>
  167.      */
  168.     public T getdGmsdBeta(final int m, final int s, final int j) {
  169.         final int sMj = FastMath.abs(s - j);
  170.         T dGmsdBe = zero;
  171.         if (FastMath.abs(s) <= m) {
  172.             final int mMis = m - I * s;
  173.             dGmsdBe = cjsjKH.getCj(sMj).multiply(cjsjAB.getDcjDh(mMis)).
  174.                       subtract(cjsjKH.getSj(sMj).multiply(cjsjAB.getDsjDh(mMis)).multiply(I).multiply(sgn(s - j)));
  175.         } else {
  176.             final int sMim = FastMath.abs(s - I * m);
  177.             dGmsdBe = cjsjKH.getCj(sMj).multiply(cjsjAB.getDcjDh(sMim)).
  178.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDsjDh(sMim)).multiply(sgn(s - j)).multiply(sgn(s - m)));
  179.         }
  180.         return dGmsdBe;
  181.     }

  182.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>k</sub> coefficient.
  183.      * @param m m subscript
  184.      * @param s s subscript
  185.      * @param j order
  186.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>k</sub>
  187.      */
  188.     public T getdHmsdk(final int m, final int s, final int j) {
  189.         final int sMj = FastMath.abs(s - j);
  190.         T dHmsdk = zero;
  191.         if (FastMath.abs(s) <= m) {
  192.             final int mMis = m - I * s;
  193.             dHmsdk = cjsjKH.getDcjDk(sMj).multiply(cjsjAB.getSj(mMis)).multiply(I).
  194.                      add(cjsjKH.getDsjDk(sMj).multiply(cjsjAB.getCj(mMis)).multiply(sgn(s - j)));
  195.         } else {
  196.             final int sMim = FastMath.abs(s - I * m);
  197.             dHmsdk = cjsjKH.getDcjDk(sMj).multiply(cjsjAB.getSj(sMim)).multiply(-sgn(s - m)).
  198.                      add(cjsjKH.getDsjDk(sMj).multiply(cjsjAB.getCj(sMim)).multiply(sgn(s - j)));
  199.         }
  200.         return dHmsdk;
  201.     }

  202.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>h</sub> coefficient.
  203.      * @param m m subscript
  204.      * @param s s subscript
  205.      * @param j order
  206.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>h</sub>
  207.      */
  208.     public T getdHmsdh(final int m,  final int s, final int j) {
  209.         final int sMj = FastMath.abs(s - j);
  210.         T dHmsdh = zero;
  211.         if (FastMath.abs(s) <= m) {
  212.             final int mMis = m - I * s;
  213.             dHmsdh = cjsjKH.getDcjDh(sMj).multiply(cjsjAB.getSj(mMis)).multiply(I).
  214.                      add(cjsjKH.getDsjDh(sMj).multiply(cjsjAB.getCj(mMis)).multiply(sgn(s - j)));
  215.         } else {
  216.             final int sMim = FastMath.abs(s - I * m);
  217.             dHmsdh = cjsjKH.getDcjDh(sMj).multiply(cjsjAB.getSj(sMim)).multiply(-sgn(s - m)).
  218.                      add(cjsjKH.getDsjDh(sMj).multiply(cjsjAB.getCj(sMim)).multiply(sgn(s - j)));
  219.         }
  220.         return dHmsdh;
  221.     }

  222.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>α</sub> coefficient.
  223.      * @param m m subscript
  224.      * @param s s subscript
  225.      * @param j order
  226.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>α</sub>
  227.      */
  228.     public T getdHmsdAlpha(final int m, final int s, final int j) {
  229.         final int sMj  = FastMath.abs(s - j);
  230.         T dHmsdAl = zero;
  231.         if (FastMath.abs(s) <= m) {
  232.             final int mMis = m - I * s;
  233.             dHmsdAl = cjsjKH.getCj(sMj).multiply(cjsjAB.getDsjDk(mMis)).multiply(I).
  234.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDcjDk(mMis)).multiply(sgn(s - j)));
  235.         } else {
  236.             final int sMim = FastMath.abs(s - I * m);
  237.             dHmsdAl = cjsjKH.getCj(sMj).multiply(cjsjAB.getDsjDk(sMim)).multiply(-sgn(s - m)).
  238.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDcjDk(sMim)).multiply(sgn(s - j)));
  239.         }
  240.         return dHmsdAl;
  241.     }

  242.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>β</sub> coefficient.
  243.      * @param m m subscript
  244.      * @param s s subscript
  245.      * @param j order
  246.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>β</sub>
  247.      */
  248.     public T getdHmsdBeta(final int m, final int s, final int j) {
  249.         final int sMj = FastMath.abs(s - j);
  250.         T dHmsdBe = zero;
  251.         if (FastMath.abs(s) <= m) {
  252.             final int mMis = m - I * s;
  253.             dHmsdBe = cjsjKH.getCj(sMj).multiply(cjsjAB.getDsjDh(mMis)).multiply(I).
  254.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDcjDh(mMis)).multiply(sgn(s - j)));
  255.         } else {
  256.             final int sMim = FastMath.abs(s - I * m);
  257.             dHmsdBe = cjsjKH.getCj(sMj).multiply(cjsjAB.getDsjDh(sMim)).multiply(-sgn(s - m)).
  258.                       add(cjsjKH.getSj(sMj).multiply(cjsjAB.getDcjDh(sMim)).multiply(sgn(s - j)));
  259.         }
  260.         return dHmsdBe;
  261.     }

  262.     /** Get the sign of an integer.
  263.      *  @param i number on which evaluation is done
  264.      *  @return -1 or +1 depending on sign of i
  265.      */
  266.     private int sgn(final int i) {
  267.         return (i < 0) ? -1 : 1;
  268.     }
  269. }