FieldAuxiliaryElements.java

  1. /* Copyright 2002-2020 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.RealFieldElement;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.hipparchus.util.MathUtils;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.orbits.FieldOrbit;
  25. import org.orekit.time.FieldAbsoluteDate;

  26. /** Container class for common parameters used by all DSST forces.
  27.  *  <p>
  28.  *  Most of them are defined in Danielson paper at § 2.1.
  29.  *  </p>
  30.  */
  31. public class FieldAuxiliaryElements<T extends RealFieldElement<T>> {

  32.     /** \(2\pi\) . */
  33.     public static final double TWO_PI = 2 * FastMath.PI;

  34.     /** Orbit date. */
  35.     private final FieldAbsoluteDate<T> date;

  36.     /** Orbit frame. */
  37.     private final Frame frame;

  38.     /** Eccentricity. */
  39.     private final T ecc;

  40.     /** Keplerian mean motion. */
  41.     private final T n;

  42.     /** Keplerian period. */
  43.     private final T period;

  44.     /** Semi-major axis. */
  45.     private final T sma;

  46.     /** x component of eccentricity vector. */
  47.     private final T k;

  48.     /** y component of eccentricity vector. */
  49.     private final T h;

  50.     /** x component of inclination vector. */
  51.     private final T q;

  52.     /** y component of inclination vector. */
  53.     private final T p;

  54.     /** Mean longitude. */
  55.     private final T lm;

  56.     /** True longitude. */
  57.     private final T lv;

  58.     /** Eccentric longitude. */
  59.     private final T le;

  60.     /** Retrograde factor I.
  61.      *  <p>
  62.      *  DSST model needs equinoctial orbit as internal representation.
  63.      *  Classical equinoctial elements have discontinuities when inclination
  64.      *  is close to zero. In this representation, I = +1. <br>
  65.      *  To avoid this discontinuity, another representation exists and equinoctial
  66.      *  elements can be expressed in a different way, called "retrograde" orbit.
  67.      *  This implies I = -1. <br>
  68.      *  As Orekit doesn't implement the retrograde orbit, I is always set to +1.
  69.      *  But for the sake of consistency with the theory, the retrograde factor
  70.      *  has been kept in the formulas.
  71.      *  </p>
  72.      */
  73.     private final int    I;

  74.     /** B = sqrt(1 - h² - k²). */
  75.     private final T B;

  76.     /** C = 1 + p² + q². */
  77.     private final T C;

  78.     /** Equinoctial frame f vector. */
  79.     private final FieldVector3D<T> f;

  80.     /** Equinoctial frame g vector. */
  81.     private final FieldVector3D<T> g;

  82.     /** Equinoctial frame w vector. */
  83.     private final FieldVector3D<T> w;

  84.     /** Direction cosine α. */
  85.     private final T alpha;

  86.     /** Direction cosine β. */
  87.     private final T beta;

  88.     /** Direction cosine γ. */
  89.     private final T gamma;

  90.     /** Simple constructor.
  91.      * @param orbit related mean orbit for auxiliary elements
  92.      * @param retrogradeFactor retrograde factor I [Eq. 2.1.2-(2)]
  93.      */
  94.     public FieldAuxiliaryElements(final FieldOrbit<T> orbit, final int retrogradeFactor) {

  95.         final Field<T> field = orbit.getDate().getField();
  96.         final T zero = field.getZero();
  97.         final T pi = zero.add(FastMath.PI);

  98.         // Date of the orbit
  99.         date = orbit.getDate();

  100.         // Orbit definition frame
  101.         frame = orbit.getFrame();

  102.         // Eccentricity
  103.         ecc = orbit.getE();

  104.         // Keplerian mean motion
  105.         n = orbit.getKeplerianMeanMotion();

  106.         // Keplerian period
  107.         period = orbit.getKeplerianPeriod();

  108.         // Equinoctial elements [Eq. 2.1.2-(1)]
  109.         sma = orbit.getA();
  110.         k   = orbit.getEquinoctialEx();
  111.         h   = orbit.getEquinoctialEy();
  112.         q   = orbit.getHx();
  113.         p   = orbit.getHy();
  114.         lm  = MathUtils.normalizeAngle(orbit.getLM(), pi);
  115.         lv  = MathUtils.normalizeAngle(orbit.getLv(), pi);
  116.         le  = MathUtils.normalizeAngle(orbit.getLE(), pi);

  117.         // Retrograde factor [Eq. 2.1.2-(2)]
  118.         I = retrogradeFactor;

  119.         final T k2 = k.multiply(k);
  120.         final T h2 = h.multiply(h);
  121.         final T q2 = q.multiply(q);
  122.         final T p2 = p.multiply(p);

  123.         // A, B, C parameters [Eq. 2.1.6-(1)]
  124.         B = FastMath.sqrt(k2.add(h2).negate().add(1.));
  125.         C = q2.add(p2).add(1);

  126.         // Equinoctial reference frame [Eq. 2.1.4-(1)]
  127.         final T ooC = C.reciprocal();
  128.         final T px2 = p.multiply(2.);
  129.         final T qx2 = q.multiply(2.);
  130.         final T pq2 = px2.multiply(q);
  131.         f = new FieldVector3D<>(ooC, new FieldVector3D<>(p2.negate().add(1.).add(q2), pq2, px2.multiply(I).negate()));
  132.         g = new FieldVector3D<>(ooC, new FieldVector3D<>(pq2.multiply(I), (p2.add(1.).subtract(q2)).multiply(I), qx2));
  133.         w = new FieldVector3D<>(ooC, new FieldVector3D<>(px2, qx2.negate(), (p2.add(q2).negate().add(1.)).multiply(I)));

  134.         // Direction cosines for central body [Eq. 2.1.9-(1)]
  135.         alpha = (T) f.getZ();
  136.         beta  = (T) g.getZ();
  137.         gamma = (T) w.getZ();
  138.     }

  139.     /**
  140.      * Normalize an angle in a 2&pi; wide interval around a center value.
  141.      * <p>This method has three main uses:</p>
  142.      * <ul>
  143.      *   <li>normalize an angle between 0 and 2&pi;:<br>
  144.      *       {@code a = MathUtils.normalizeAngle(a, FastMath.PI);}</li>
  145.      *   <li>normalize an angle between -&pi; and +&pi;<br>
  146.      *       {@code a = MathUtils.normalizeAngle(a, 0.0);}</li>
  147.      *   <li>compute the angle between two defining angular positions:<br>
  148.      *       {@code angle = MathUtils.normalizeAngle(end, start) - start;}</li>
  149.      * </ul>
  150.      * <p>Note that due to numerical accuracy and since &pi; cannot be represented
  151.      * exactly, the result interval is <em>closed</em>, it cannot be half-closed
  152.      * as would be more satisfactory in a purely mathematical view.</p>
  153.      * @param a angle to normalize
  154.      * @param center center of the desired 2&pi; interval for the result
  155.      * @return a-2k&pi; with integer k and center-&pi; &lt;= a-2k&pi; &lt;= center+&pi;
  156.      * @deprecated replaced by {@link MathUtils#normalizeAngle(RealFieldElement, RealFieldElement)}
  157.      */
  158.     @Deprecated
  159.     public T normalizeAngle(final T a, final T center) {
  160.         return a.subtract(FastMath.floor((a.add(FastMath.PI).subtract(center)).divide(TWO_PI)).multiply(TWO_PI));
  161.     }

  162.     /** Get the date of the orbit.
  163.      * @return the date
  164.      */
  165.     public FieldAbsoluteDate<T> getDate() {
  166.         return date;
  167.     }

  168.     /** Get the definition frame of the orbit.
  169.      * @return the definition frame
  170.      */
  171.     public Frame getFrame() {
  172.         return frame;
  173.     }

  174.     /** Get the eccentricity.
  175.      * @return ecc
  176.      */
  177.     public T getEcc() {
  178.         return ecc;
  179.     }

  180.     /** Get the Keplerian mean motion.
  181.      * @return n
  182.      */
  183.     public T getMeanMotion() {
  184.         return n;
  185.     }

  186.     /** Get the Keplerian period.
  187.      * @return period
  188.      */
  189.     public T getKeplerianPeriod() {
  190.         return period;
  191.     }

  192.     /** Get the semi-major axis.
  193.      * @return the semi-major axis a
  194.      */
  195.     public T getSma() {
  196.         return sma;
  197.     }

  198.     /** Get the x component of eccentricity vector.
  199.      * <p>
  200.      * This element called k in DSST corresponds to ex
  201.      * for the {@link org.orekit.orbits.EquinoctialOrbit}
  202.      * </p>
  203.      * @return k
  204.      */
  205.     public T getK() {
  206.         return k;
  207.     }

  208.     /** Get the y component of eccentricity vector.
  209.      * <p>
  210.      * This element called h in DSST corresponds to ey
  211.      * for the {@link org.orekit.orbits.EquinoctialOrbit}
  212.      * </p>
  213.      * @return h
  214.      */
  215.     public T getH() {
  216.         return h;
  217.     }

  218.     /** Get the x component of inclination vector.
  219.      * <p>
  220.      * This element called q in DSST corresponds to hx
  221.      * for the {@link org.orekit.orbits.EquinoctialOrbit}
  222.      * </p>
  223.      * @return q
  224.      */
  225.     public T getQ() {
  226.         return q;
  227.     }

  228.     /** Get the y component of inclination vector.
  229.      * <p>
  230.      * This element called p in DSST corresponds to hy
  231.      * for the {@link org.orekit.orbits.EquinoctialOrbit}
  232.      * </p>
  233.      * @return p
  234.      */
  235.     public T getP() {
  236.         return p;
  237.     }

  238.     /** Get the mean longitude.
  239.      * @return lm
  240.      */
  241.     public T getLM() {
  242.         return lm;
  243.     }

  244.     /** Get the true longitude.
  245.      * @return lv
  246.      */
  247.     public T getLv() {
  248.         return lv;
  249.     }

  250.     /** Get the eccentric longitude.
  251.      * @return le
  252.      */
  253.     public T getLe() {
  254.         return le;
  255.     }

  256.     /** Get the retrograde factor.
  257.      * @return the retrograde factor I
  258.      */
  259.     public int getRetrogradeFactor() {
  260.         return I;
  261.     }

  262.     /** Get B = sqrt(1 - e²).
  263.      * @return B
  264.      */
  265.     public T getB() {
  266.         return B;
  267.     }

  268.     /** Get C = 1 + p² + q².
  269.      * @return C
  270.      */
  271.     public T getC() {
  272.         return C;
  273.     }

  274.     /** Get equinoctial frame vector f.
  275.      * @return f vector
  276.      */
  277.     public FieldVector3D<T> getVectorF() {
  278.         return f;
  279.     }

  280.     /** Get equinoctial frame vector g.
  281.      * @return g vector
  282.      */
  283.     public FieldVector3D<T> getVectorG() {
  284.         return g;
  285.     }

  286.     /** Get equinoctial frame vector w.
  287.      * @return w vector
  288.      */
  289.     public FieldVector3D<T> getVectorW() {
  290.         return w;
  291.     }

  292.     /** Get direction cosine α for central body.
  293.      * @return α
  294.      */
  295.     public T getAlpha() {
  296.         return alpha;
  297.     }

  298.     /** Get direction cosine β for central body.
  299.      * @return β
  300.      */
  301.     public T getBeta() {
  302.         return beta;
  303.     }

  304.     /** Get direction cosine γ for central body.
  305.      * @return γ
  306.      */
  307.     public T getGamma() {
  308.         return gamma;
  309.     }

  310. }