HarrisPriester.java

  1. /* Copyright 2002-2013 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.forces.drag;

  18. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  19. import org.apache.commons.math3.util.FastMath;
  20. import org.apache.commons.math3.util.Precision;
  21. import org.orekit.bodies.OneAxisEllipsoid;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.frames.Transform;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.PVCoordinates;
  28. import org.orekit.utils.PVCoordinatesProvider;


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

  44.     /** Serializable UID.*/
  45.     private static final long serialVersionUID = 2772347498196369601L;

  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 cosine. */
  54.     private static final double COSLAG = FastMath.cos(LAG);
  55.     /** Lag angle sine. */
  56.     private static final double SINLAG = FastMath.sin(LAG);

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

  113.     /** Cosine exponent from 2 to 6 according to inclination. */
  114.     private double n;

  115.     /** Sun position. */
  116.     private PVCoordinatesProvider sun;

  117.     /** Earth body shape. */
  118.     private OneAxisEllipsoid earth;

  119.     /** Density table. */
  120.     private double[][] tabAltRho;

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

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

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

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

  194.     /** {@inheritDoc} */
  195.     public Frame getFrame() {
  196.         return earth.getBodyFrame();
  197.     }

  198.     /** Set parameter N, the cosine exponent.
  199.      *  @param n the cosine exponent
  200.      */
  201.     private void setN(final double n) {
  202.         this.n = n;
  203.     }

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

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

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

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

  248.     /** Get the local density.
  249.      * @param sunInEarth position of the Sun in Earth frame (m)
  250.      * @param posInEarth target position in Earth frame (m)
  251.      * @return the local density (kg/m<sup>3</sup>)
  252.      * @exception OrekitException if altitude is below the model minimal altitude
  253.      */
  254.     public double getDensity(final Vector3D sunInEarth, final Vector3D posInEarth)
  255.         throws OrekitException {

  256.         final double posAlt = getHeight(posInEarth);
  257.         // Check for height boundaries
  258.         if (posAlt < getMinAlt()) {
  259.             throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, posAlt, getMinAlt());
  260.         }
  261.         if (posAlt > getMaxAlt()) {
  262.             return 0.;
  263.         }

  264.         // Diurnal bulge apex direction
  265.         final Vector3D sunDir = sunInEarth.normalize();
  266.         final Vector3D bulDir = new Vector3D(sunDir.getX() * COSLAG - sunDir.getY() * SINLAG,
  267.                                              sunDir.getX() * SINLAG + sunDir.getY() * COSLAG,
  268.                                              sunDir.getZ());

  269.         // Cosine of angle Psi between the diurnal bulge apex and the satellite
  270.         final double cosPsi = bulDir.normalize().dotProduct(posInEarth.normalize());
  271.         // (1 + cos(Psi))/2 = cos²(Psi/2)
  272.         final double c2Psi2 = (1. + cosPsi) / 2.;
  273.         final double cPsi2  = FastMath.sqrt(c2Psi2);
  274.         final double cosPow = (cPsi2 > MIN_COS) ? c2Psi2 * FastMath.pow(cPsi2, n - 2) : 0.;

  275.         // Search altitude index in density table
  276.         int ia = 0;
  277.         while (ia < tabAltRho.length - 2 && posAlt > tabAltRho[ia + 1][0]) {
  278.             ia++;
  279.         }

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

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

  284.         if (Precision.equals(cosPow, 0.)) {
  285.             return rhoMin;
  286.         } else {
  287.             // Max exponential density interpolation
  288.             final double rhoMax = tabAltRho[ia][2] * FastMath.pow(tabAltRho[ia + 1][2] / tabAltRho[ia][2], dH);
  289.             return rhoMin + (rhoMax - rhoMin) * cosPow;
  290.         }

  291.     }

  292.     /** Get the local density at some position.
  293.      * @param date current date
  294.      * @param position current position
  295.      * @param frame the frame in which is defined the position
  296.      * @return local density (kg/m<sup>3</sup>)
  297.      * @exception OrekitException if some frame conversion cannot be performed
  298.      *            or if altitude is below the model minimal altitude
  299.      */
  300.     public double getDensity(final AbsoluteDate date, final Vector3D position, final Frame frame)
  301.         throws OrekitException {

  302.         // Sun position in earth frame
  303.         final Vector3D sunInEarth = sun.getPVCoordinates(date, earth.getBodyFrame()).getPosition();

  304.         // Target position in earth frame
  305.         final Vector3D posInEarth = frame.getTransformTo(earth.getBodyFrame(), date).transformPosition(position);

  306.         return getDensity(sunInEarth, posInEarth);
  307.     }

  308.     /** Get the inertial velocity of atmosphere molecules.
  309.      * <p>
  310.      * Here the case is simplified : atmosphere is supposed to have a null velocity
  311.      * in earth frame.
  312.      * </p>
  313.      * @param date current date
  314.      * @param position current position
  315.      * @param frame the frame in which is defined the position
  316.      * @return velocity (m/s) (defined in the same frame as the position)
  317.      * @exception OrekitException if some frame conversion cannot be performed
  318.      */
  319.     public Vector3D getVelocity(final AbsoluteDate date, final Vector3D position, final Frame frame)
  320.         throws OrekitException {
  321.         final Transform bodyToFrame = earth.getBodyFrame().getTransformTo(frame, date);
  322.         final Vector3D posInBody    = bodyToFrame.getInverse().transformPosition(position);
  323.         final PVCoordinates pvBody  = new PVCoordinates(posInBody, Vector3D.ZERO);
  324.         final PVCoordinates pvFrame = bodyToFrame.transformPVCoordinates(pvBody);
  325.         return pvFrame.getVelocity();
  326.     }

  327.     /** Get the height above the Earth for the given position.
  328.      *  <p>
  329.      *  The height computation is an approximation valid for the considered atmosphere.
  330.      *  </p>
  331.      *  @param position current position in Earth frame
  332.      *  @return height (m)
  333.      */
  334.     private double getHeight(final Vector3D position) {
  335.         final double a    = earth.getEquatorialRadius();
  336.         final double f    = earth.getFlattening();
  337.         final double e2   = f * (2. - f);
  338.         final double r    = position.getNorm();
  339.         final double sl   = position.getZ() / r;
  340.         final double cl2  = 1. - sl * sl;
  341.         final double coef = FastMath.sqrt((1. - e2) / (1. - e2 * cl2));

  342.         return r - a * coef;
  343.     }

  344. }