FieldGHmsjPolynomials.java

  1. /* Copyright 2002-2024 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.  * @param <T> type of the field elements
  30.  */
  31. public class FieldGHmsjPolynomials <T extends CalculusFieldElement<T>> {
  32.     /** C<sub>j</sub>(k, h), S<sub>j</sub>(k, h) coefficient.
  33.      * (k, h) are the (x, y) component of the eccentricity vector in equinoctial elements
  34.      */
  35.     private final FieldCjSjCoefficient<T> cjsjKH;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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