HarrisPriester.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.models.earth.atmosphere;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.hipparchus.util.Precision;
  23. import org.hipparchus.util.SinCos;
  24. import org.orekit.bodies.OneAxisEllipsoid;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitMessages;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.ExtendedPositionProvider;


  31. /** This atmosphere model is the realization of the Modified Harris-Priester model.
  32.  * <p>
  33.  * This model is a static one that takes into account the diurnal density bulge.
  34.  * It doesn't need any space weather data but a density vs. altitude table, which
  35.  * depends on solar activity.
  36.  * </p>
  37.  * <p>
  38.  * The implementation relies on the book:<br>
  39.  * <b>Satellite Orbits</b><br>
  40.  * <i>Oliver Montenbruck, Eberhard Gill</i><br>
  41.  * Springer 2005
  42.  * </p>
  43.  * @author Pascal Parraud
  44.  */
  45. public class HarrisPriester extends AbstractSunInfluencedAtmosphere {

  46.     // Constants :

  47.     /** Default cosine exponent value. */
  48.     private static final int N_DEFAULT = 4;

  49.     /** Minimal value for calculating poxer of cosine. */
  50.     private static final double MIN_COS = 1.e-12;

  51.     /** Lag angle for diurnal bulge. */
  52.     private static final double LAG = FastMath.toRadians(30.0);

  53.     /** Lag angle sine and cosine. */
  54.     private static final SinCos SCLAG = FastMath.sinCos(LAG);

  55.     // CHECKSTYLE: stop NoWhitespaceAfter check
  56.     /** Harris-Priester min-max density (kg/m3) vs. altitude (m) table.
  57.      *  These data are valid for a mean solar activity. */
  58.     private static final double[][] ALT_RHO = {
  59.         {  100000.0, 4.974e-07, 4.974e-07 },
  60.         {  120000.0, 2.490e-08, 2.490e-08 },
  61.         {  130000.0, 8.377e-09, 8.710e-09 },
  62.         {  140000.0, 3.899e-09, 4.059e-09 },
  63.         {  150000.0, 2.122e-09, 2.215e-09 },
  64.         {  160000.0, 1.263e-09, 1.344e-09 },
  65.         {  170000.0, 8.008e-10, 8.758e-10 },
  66.         {  180000.0, 5.283e-10, 6.010e-10 },
  67.         {  190000.0, 3.617e-10, 4.297e-10 },
  68.         {  200000.0, 2.557e-10, 3.162e-10 },
  69.         {  210000.0, 1.839e-10, 2.396e-10 },
  70.         {  220000.0, 1.341e-10, 1.853e-10 },
  71.         {  230000.0, 9.949e-11, 1.455e-10 },
  72.         {  240000.0, 7.488e-11, 1.157e-10 },
  73.         {  250000.0, 5.709e-11, 9.308e-11 },
  74.         {  260000.0, 4.403e-11, 7.555e-11 },
  75.         {  270000.0, 3.430e-11, 6.182e-11 },
  76.         {  280000.0, 2.697e-11, 5.095e-11 },
  77.         {  290000.0, 2.139e-11, 4.226e-11 },
  78.         {  300000.0, 1.708e-11, 3.526e-11 },
  79.         {  320000.0, 1.099e-11, 2.511e-11 },
  80.         {  340000.0, 7.214e-12, 1.819e-11 },
  81.         {  360000.0, 4.824e-12, 1.337e-11 },
  82.         {  380000.0, 3.274e-12, 9.955e-12 },
  83.         {  400000.0, 2.249e-12, 7.492e-12 },
  84.         {  420000.0, 1.558e-12, 5.684e-12 },
  85.         {  440000.0, 1.091e-12, 4.355e-12 },
  86.         {  460000.0, 7.701e-13, 3.362e-12 },
  87.         {  480000.0, 5.474e-13, 2.612e-12 },
  88.         {  500000.0, 3.916e-13, 2.042e-12 },
  89.         {  520000.0, 2.819e-13, 1.605e-12 },
  90.         {  540000.0, 2.042e-13, 1.267e-12 },
  91.         {  560000.0, 1.488e-13, 1.005e-12 },
  92.         {  580000.0, 1.092e-13, 7.997e-13 },
  93.         {  600000.0, 8.070e-14, 6.390e-13 },
  94.         {  620000.0, 6.012e-14, 5.123e-13 },
  95.         {  640000.0, 4.519e-14, 4.121e-13 },
  96.         {  660000.0, 3.430e-14, 3.325e-13 },
  97.         {  680000.0, 2.632e-14, 2.691e-13 },
  98.         {  700000.0, 2.043e-14, 2.185e-13 },
  99.         {  720000.0, 1.607e-14, 1.779e-13 },
  100.         {  740000.0, 1.281e-14, 1.452e-13 },
  101.         {  760000.0, 1.036e-14, 1.190e-13 },
  102.         {  780000.0, 8.496e-15, 9.776e-14 },
  103.         {  800000.0, 7.069e-15, 8.059e-14 },
  104.         {  840000.0, 4.680e-15, 5.741e-14 },
  105.         {  880000.0, 3.200e-15, 4.210e-14 },
  106.         {  920000.0, 2.210e-15, 3.130e-14 },
  107.         {  960000.0, 1.560e-15, 2.360e-14 },
  108.         { 1000000.0, 1.150e-15, 1.810e-14 }
  109.     };
  110.     // CHECKSTYLE: resume NoWhitespaceAfter check

  111.     /** Cosine exponent from 2 to 6 according to inclination. */
  112.     private double n;

  113.     /** Earth body shape. */
  114.     private OneAxisEllipsoid earth;

  115.     /** Density table. */
  116.     private double[][] tabAltRho;

  117.     /** Simple constructor for Modified Harris-Priester atmosphere model.
  118.      *  <p>The cosine exponent value is set to 4 by default.</p>
  119.      *  <p>The default embedded density table is the one given in the referenced
  120.      *  book from Montenbruck &amp; Gill. It is given for mean solar activity and
  121.      *  spreads over 100 to 1000 km.</p>
  122.      * @param sun the sun position
  123.      * @param earth the earth body shape
  124.      */
  125.     public HarrisPriester(final ExtendedPositionProvider sun,
  126.                           final OneAxisEllipsoid earth) {
  127.         this(sun, earth, ALT_RHO, N_DEFAULT);
  128.     }

  129.     /** Constructor for Modified Harris-Priester atmosphere model.
  130.      *  <p>Recommanded values for the cosine exponent spread over the range
  131.      *  2, for low inclination orbits, to 6, for polar orbits.</p>
  132.      *  <p> The default embedded density table is the one given in the referenced
  133.      *  book from Montenbruck &amp; Gill. It is given for mean solar activity and
  134.      *  spreads over 100 to 1000 km. </p>
  135.      *  @param sun the sun position
  136.      * @param earth the earth body shape
  137.      * @param n the cosine exponent
  138.      */
  139.     public HarrisPriester(final ExtendedPositionProvider sun,
  140.                           final OneAxisEllipsoid earth,
  141.                           final double n) {
  142.         this(sun, earth, ALT_RHO, n);
  143.     }

  144.     /** Constructor for Modified Harris-Priester atmosphere model.
  145.      *  <p>The provided density table must be an array such as:
  146.      *  <ul>
  147.      *   <li>tabAltRho[][0] = altitude (m)</li>
  148.      *   <li>tabAltRho[][1] = min density (kg/m³)</li>
  149.      *   <li>tabAltRho[][2] = max density (kg/m³)</li>
  150.      *  </ul>
  151.      *  <p> The altitude must be increasing without limitation in range. The
  152.      *  internal density table is a copy of the provided one.
  153.      *
  154.      *  <p>The cosine exponent value is set to 4 by default.</p>
  155.      * @param sun the sun position
  156.      * @param earth the earth body shape
  157.      * @param tabAltRho the density table
  158.      */
  159.     public HarrisPriester(final ExtendedPositionProvider sun,
  160.                           final OneAxisEllipsoid earth,
  161.                           final double[][] tabAltRho) {
  162.         this(sun, earth, tabAltRho, N_DEFAULT);
  163.     }

  164.     /** Constructor for Modified Harris-Priester atmosphere model.
  165.      *  <p>Recommanded values for the cosine exponent spread over the range
  166.      *  2, for low inclination orbits, to 6, for polar orbits.</p>
  167.      *  <p>The provided density table must be an array such as:
  168.      *  <ul>
  169.      *   <li>tabAltRho[][0] = altitude (m)</li>
  170.      *   <li>tabAltRho[][1] = min density (kg/m³)</li>
  171.      *   <li>tabAltRho[][2] = max density (kg/m³)</li>
  172.      *  </ul>
  173.      *  <p> The altitude must be increasing without limitation in range. The
  174.      *  internal density table is a copy of the provided one.
  175.      *
  176.      *  @param sun the sun position
  177.      * @param earth the earth body shape
  178.      * @param tabAltRho the density table
  179.      * @param n the cosine exponent
  180.      */
  181.     public HarrisPriester(final ExtendedPositionProvider sun,
  182.                           final OneAxisEllipsoid earth,
  183.                           final double[][] tabAltRho,
  184.                           final double n) {
  185.         super(sun);
  186.         this.earth = earth;
  187.         setTabDensity(tabAltRho);
  188.         setN(n);
  189.     }

  190.     /** {@inheritDoc} */
  191.     public Frame getFrame() {
  192.         return earth.getBodyFrame();
  193.     }

  194.     /** Set parameter N, the cosine exponent.
  195.      *  @param n the cosine exponent
  196.      */
  197.     private void setN(final double n) {
  198.         this.n = n;
  199.     }

  200.     /** Set a user define density table to deal with different solar activities.
  201.      *  @param tab density vs. altitude table
  202.      */
  203.     private void setTabDensity(final double[][] tab) {
  204.         this.tabAltRho = new double[tab.length][];
  205.         for (int i = 0; i < tab.length; i++) {
  206.             this.tabAltRho[i] = tab[i].clone();
  207.         }
  208.     }

  209.     /** Get the current density table.
  210.      *  <p>The density table is an array such as:
  211.      *  <ul>
  212.      *   <li>tabAltRho[][0] = altitude (m)</li>
  213.      *   <li>tabAltRho[][1] = min density (kg/m³)</li>
  214.      *   <li>tabAltRho[][2] = max density (kg/m³)</li>
  215.      *  </ul>
  216.      *  <p> The altitude must be increasing without limitation in range.
  217.      *
  218.      *  <p>
  219.      *  The returned density table is a copy of the current one.
  220.      *  </p>
  221.      *  @return density vs. altitude table
  222.      */
  223.     public double[][] getTabDensity() {
  224.         final double[][] copy = new double[tabAltRho.length][];
  225.         for (int i = 0; i < tabAltRho.length; i++) {
  226.             copy[i] = tabAltRho[i].clone();
  227.         }
  228.         return copy;
  229.     }

  230.     /** Get the minimal altitude for the model.
  231.      * <p>No computation is possible below this altitude.</p>
  232.      *  @return the minimal altitude (m)
  233.      */
  234.     public double getMinAlt() {
  235.         return tabAltRho[0][0];
  236.     }

  237.     /** Get the maximal altitude for the model.
  238.      * <p>Above this altitude, density is assumed to be zero.</p>
  239.      *  @return the maximal altitude (m)
  240.      */
  241.     public double getMaxAlt() {
  242.         return tabAltRho[tabAltRho.length - 1][0];
  243.     }

  244.     /** Get the local density.
  245.      * @param sunInEarth position of the Sun in Earth frame (m)
  246.      * @param posInEarth target position in Earth frame (m)
  247.      * @return the local density (kg/m³)
  248.      */
  249.     public double getDensity(final Vector3D sunInEarth, final Vector3D posInEarth) {

  250.         final double posAlt = getHeight(posInEarth);
  251.         // Check for height boundaries
  252.         if (posAlt < getMinAlt()) {
  253.             throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, posAlt, getMinAlt());
  254.         }
  255.         if (posAlt > getMaxAlt()) {
  256.             return 0.;
  257.         }

  258.         // Diurnal bulge apex direction
  259.         final Vector3D sunDir = sunInEarth.normalize();
  260.         final Vector3D bulDir = new Vector3D(sunDir.getX() * SCLAG.cos() - sunDir.getY() * SCLAG.sin(),
  261.                                              sunDir.getX() * SCLAG.sin() + sunDir.getY() * SCLAG.cos(),
  262.                                              sunDir.getZ());

  263.         // Cosine of angle Psi between the diurnal bulge apex and the satellite
  264.         final double cosPsi = bulDir.normalize().dotProduct(posInEarth.normalize());
  265.         // (1 + cos(Psi))/2 = cos²(Psi/2)
  266.         final double c2Psi2 = (1. + cosPsi) / 2.;
  267.         final double cPsi2  = FastMath.sqrt(c2Psi2);
  268.         final double cosPow = (cPsi2 > MIN_COS) ? c2Psi2 * FastMath.pow(cPsi2, n - 2) : 0.;

  269.         // Search altitude index in density table
  270.         int ia = 0;
  271.         while (ia < tabAltRho.length - 2 && posAlt > tabAltRho[ia + 1][0]) {
  272.             ia++;
  273.         }

  274.         // Fractional satellite height
  275.         final double dH = (tabAltRho[ia][0] - posAlt) / (tabAltRho[ia][0] - tabAltRho[ia + 1][0]);

  276.         // Min exponential density interpolation
  277.         final double rhoMin = tabAltRho[ia][1] * FastMath.pow(tabAltRho[ia + 1][1] / tabAltRho[ia][1], dH);

  278.         if (Precision.equals(cosPow, 0.)) {
  279.             return rhoMin;
  280.         } else {
  281.             // Max exponential density interpolation
  282.             final double rhoMax = tabAltRho[ia][2] * FastMath.pow(tabAltRho[ia + 1][2] / tabAltRho[ia][2], dH);
  283.             return rhoMin + (rhoMax - rhoMin) * cosPow;
  284.         }

  285.     }

  286.     /** Get the local density.
  287.      * @param sunInEarth position of the Sun in Earth frame (m)
  288.      * @param posInEarth target position in Earth frame (m)
  289.      * @return the local density (kg/m³)
  290.      * @param <T> instance of CalculusFieldElement&lt;T&gt;
  291.      */
  292.     public <T extends CalculusFieldElement<T>> T getDensity(final FieldVector3D<T> sunInEarth, final FieldVector3D<T> posInEarth) {
  293.         final T zero = posInEarth.getX().getField().getZero();
  294.         final T posAlt = getHeight(posInEarth);
  295.         // Check for height boundaries
  296.         if (posAlt.getReal() < getMinAlt()) {
  297.             throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, posAlt, getMinAlt());
  298.         }
  299.         if (posAlt.getReal() > getMaxAlt()) {
  300.             return zero;
  301.         }

  302.         // Diurnal bulge apex direction
  303.         final FieldVector3D<T> sunDir = sunInEarth.normalize();
  304.         final FieldVector3D<T> bulDir = new FieldVector3D<>(sunDir.getX().multiply(SCLAG.cos()).subtract(sunDir.getY().multiply(SCLAG.sin())),
  305.                                              sunDir.getX().multiply(SCLAG.sin()).add(sunDir.getY().multiply(SCLAG.cos())),
  306.                                              sunDir.getZ());

  307.         // Cosine of angle Psi between the diurnal bulge apex and the satellite
  308.         final T cosPsi = posInEarth.normalize().dotProduct(bulDir.normalize());
  309.         // (1 + cos(Psi))/2 = cos²(Psi/2)
  310.         final T c2Psi2 = cosPsi.add(1.).divide(2);
  311.         final T cPsi2  = c2Psi2.sqrt();
  312.         final T cosPow = (cPsi2.getReal() > MIN_COS) ? c2Psi2.multiply(cPsi2.pow(n - 2)) : zero;

  313.         // Search altitude index in density table
  314.         int ia = 0;
  315.         while (ia < tabAltRho.length - 2 && posAlt.getReal() > tabAltRho[ia + 1][0]) {
  316.             ia++;
  317.         }

  318.         // Fractional satellite height
  319.         final T dH = posAlt.negate().add(tabAltRho[ia][0]).divide(tabAltRho[ia][0] - tabAltRho[ia + 1][0]);

  320.         // Min exponential density interpolation
  321.         final T rhoMin = zero.newInstance(tabAltRho[ia + 1][1] / tabAltRho[ia][1]).pow(dH).multiply(tabAltRho[ia][1]);

  322.         if (Precision.equals(cosPow.getReal(), 0.)) {
  323.             return rhoMin;
  324.         } else {
  325.             // Max exponential density interpolation
  326.             final T rhoMax = zero.newInstance(tabAltRho[ia + 1][2] / tabAltRho[ia][2]).pow(dH).multiply(tabAltRho[ia][2]);
  327.             return rhoMin.add(rhoMax.subtract(rhoMin).multiply(cosPow));
  328.         }

  329.     }

  330.     /** Get the local density at some position.
  331.      * @param date current date
  332.      * @param position current position
  333.      * @param frame the frame in which is defined the position
  334.      * @return local density (kg/m³)
  335.           *            or if altitude is below the model minimal altitude
  336.      */
  337.     public double getDensity(final AbsoluteDate date, final Vector3D position, final Frame frame) {

  338.         // Sun position in earth frame
  339.         final Vector3D sunInEarth = getSunPosition(date, earth.getBodyFrame());

  340.         // Target position in earth frame
  341.         final Vector3D posInEarth = frame
  342.                 .getStaticTransformTo(earth.getBodyFrame(), date)
  343.                 .transformPosition(position);

  344.         return getDensity(sunInEarth, posInEarth);
  345.     }

  346.     /** Get the local density at some position.
  347.      * @param date current date
  348.      * @param position current position
  349.      * @param <T> implements a CalculusFieldElement
  350.      * @param frame the frame in which is defined the position
  351.      * @return local density (kg/m³)
  352.           *            or if altitude is below the model minimal altitude
  353.      */
  354.     public <T extends CalculusFieldElement<T>> T getDensity(final FieldAbsoluteDate<T> date,
  355.                                                             final FieldVector3D<T> position, final Frame frame) {
  356.         // Sun position in earth frame
  357.         final FieldVector3D<T> sunInEarth = getSunPosition(date, earth.getBodyFrame());

  358.         // Target position in earth frame
  359.         final FieldVector3D<T> posInEarth = frame
  360.                 .getStaticTransformTo(earth.getBodyFrame(), date.toAbsoluteDate())
  361.                 .transformPosition(position);

  362.         return getDensity(sunInEarth, posInEarth);
  363.     }

  364.     /** Get the height above the Earth for the given position.
  365.      *  <p>
  366.      *  The height computation is an approximation valid for the considered atmosphere.
  367.      *  </p>
  368.      *  @param position current position in Earth frame
  369.      *  @return height (m)
  370.      */
  371.     private double getHeight(final Vector3D position) {
  372.         final double a    = earth.getEquatorialRadius();
  373.         final double f    = earth.getFlattening();
  374.         final double e2   = f * (2. - f);
  375.         final double r    = position.getNorm();
  376.         final double sl   = position.getZ() / r;
  377.         final double cl2  = 1. - sl * sl;
  378.         final double coef = FastMath.sqrt((1. - e2) / (1. - e2 * cl2));

  379.         return r - a * coef;
  380.     }

  381.     /** Get the height above the Earth for the given position.
  382.      *  <p>
  383.      *  The height computation is an approximation valid for the considered atmosphere.
  384.      *  </p>
  385.      *  @param position current position in Earth frame
  386.      *  @param <T> instance of CalculusFieldElement<T>
  387.      *  @return height (m)
  388.      */
  389.     private <T extends CalculusFieldElement<T>> T getHeight(final FieldVector3D<T> position) {
  390.         final double a    = earth.getEquatorialRadius();
  391.         final double f    = earth.getFlattening();
  392.         final double e2   = f * (2. - f);
  393.         final T r    = position.getNorm();
  394.         final T sl   = position.getZ().divide(r);
  395.         final T cl2  = sl.square().negate().add(1.);
  396.         final T coef = cl2.multiply(-e2).add(1.).reciprocal().multiply(1. - e2).sqrt();

  397.         return r.subtract(coef.multiply(a));
  398.     }

  399. }