SolarRadiationPressure.java

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

  18. import java.lang.reflect.Array;
  19. import java.util.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.hipparchus.util.FastMath;
  24. import org.hipparchus.util.Precision;
  25. import org.orekit.bodies.OneAxisEllipsoid;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.utils.Constants;
  32. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  33. import org.orekit.utils.FrameAdapter;
  34. import org.orekit.utils.OccultationEngine;
  35. import org.orekit.utils.ParameterDriver;

  36. /** Solar radiation pressure force model.
  37.  * <p>
  38.  * Since Orekit 11.0, it is possible to take into account
  39.  * the eclipses generated by Moon in the solar radiation
  40.  * pressure force model using the
  41.  * {@link #addOccultingBody(ExtendedPVCoordinatesProvider, double)}
  42.  * method.
  43.  * <p>
  44.  * Example:<br>
  45.  * <code> SolarRadiationPressure srp = </code>
  46.  * <code>                      new SolarRadiationPressure(CelestialBodyFactory.getSun(), Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS,</code>
  47.  * <code>                                     new IsotropicRadiationClassicalConvention(50.0, 0.5, 0.5));</code><br>
  48.  * <code> srp.addOccultingBody(CelestialBodyFactory.getMoon(), Constants.MOON_EQUATORIAL_RADIUS);</code><br>
  49.  *
  50.  * @author Fabien Maussion
  51.  * @author &Eacute;douard Delente
  52.  * @author V&eacute;ronique Pommier-Maurussane
  53.  * @author Pascal Parraud
  54.  */
  55. public class SolarRadiationPressure extends AbstractRadiationForceModel {

  56.     /** Reference distance for the solar radiation pressure (m). */
  57.     private static final double D_REF = 149597870000.0;

  58.     /** Reference solar radiation pressure at D_REF (N/m²). */
  59.     private static final double P_REF = 4.56e-6;

  60.     /** Margin to force recompute lighting ratio derivatives when we are really inside penumbra. */
  61.     private static final double ANGULAR_MARGIN = 1.0e-10;

  62.     /** Threshold to decide whether the S/C frame is Sun-centered. */
  63.     private static final double SUN_CENTERED_FRAME_THRESHOLD = 2. * Constants.SUN_RADIUS;

  64.     /** Reference flux normalized for a 1m distance (N). */
  65.     private final double kRef;

  66.     /** Sun model. */
  67.     private final ExtendedPVCoordinatesProvider sun;

  68.     /** Spacecraft. */
  69.     private final RadiationSensitive spacecraft;

  70.     /** Simple constructor with default reference values.
  71.      * <p>When this constructor is used, the reference values are:</p>
  72.      * <ul>
  73.      *   <li>d<sub>ref</sub> = 149597870000.0 m</li>
  74.      *   <li>p<sub>ref</sub> = 4.56 10<sup>-6</sup> N/m²</li>
  75.      * </ul>
  76.      * @param sun Sun model
  77.      * @param centralBody central body shape model (for umbra/penumbra computation)
  78.      * @param spacecraft the object physical and geometrical information
  79.      * @since 12.0
  80.      */
  81.     public SolarRadiationPressure(final ExtendedPVCoordinatesProvider sun,
  82.                                   final OneAxisEllipsoid centralBody,
  83.                                   final RadiationSensitive spacecraft) {
  84.         this(D_REF, P_REF, sun, centralBody, spacecraft);
  85.     }

  86.     /** Complete constructor.
  87.      * <p>Note that reference solar radiation pressure <code>pRef</code> in
  88.      * N/m² is linked to solar flux SF in W/m² using
  89.      * formula pRef = SF/c where c is the speed of light (299792458 m/s). So
  90.      * at 1UA a 1367 W/m² solar flux is a 4.56 10<sup>-6</sup>
  91.      * N/m² solar radiation pressure.</p>
  92.      * @param dRef reference distance for the solar radiation pressure (m)
  93.      * @param pRef reference solar radiation pressure at dRef (N/m²)
  94.      * @param sun Sun model
  95.      * @param centralBody central body shape model (for umbra/penumbra computation)
  96.      * @param spacecraft the object physical and geometrical information
  97.      * @since 12.0
  98.      */
  99.     public SolarRadiationPressure(final double dRef, final double pRef,
  100.                                   final ExtendedPVCoordinatesProvider sun,
  101.                                   final OneAxisEllipsoid centralBody,
  102.                                   final RadiationSensitive spacecraft) {
  103.         super(sun, centralBody);
  104.         this.kRef = pRef * dRef * dRef;
  105.         this.sun  = sun;
  106.         this.spacecraft = spacecraft;
  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  111.         final AbsoluteDate date         = s.getDate();
  112.         final Frame        frame        = s.getFrame();
  113.         final Vector3D     position     = s.getPosition();
  114.         final Vector3D     sunPosition  = sun.getPosition(date, frame);
  115.         final Vector3D     sunSatVector = position.subtract(sunPosition);
  116.         final double       r2           = sunSatVector.getNormSq();

  117.         // compute flux
  118.         final double   ratio = getLightingRatio(s, sunPosition);
  119.         final double   rawP  = ratio  * kRef / r2;
  120.         final Vector3D flux  = new Vector3D(rawP / FastMath.sqrt(r2), sunSatVector);

  121.         return spacecraft.radiationPressureAcceleration(s, flux, parameters);

  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  126.                                                                              final T[] parameters) {

  127.         final FieldAbsoluteDate<T> date         = s.getDate();
  128.         final Frame                frame        = s.getFrame();
  129.         final FieldVector3D<T>     position     = s.getPosition();
  130.         final FieldVector3D<T>     sunPosition  = sun.getPosition(date, frame);
  131.         final FieldVector3D<T>     sunSatVector = position.subtract(sunPosition);
  132.         final T                    r2           = sunSatVector.getNormSq();

  133.         // compute flux
  134.         final T                ratio = getLightingRatio(s, sunPosition);
  135.         final T                rawP  = ratio.multiply(kRef).divide(r2);
  136.         final FieldVector3D<T> flux  = new FieldVector3D<>(rawP.divide(r2.sqrt()), sunSatVector);

  137.         return spacecraft.radiationPressureAcceleration(s, flux, parameters);

  138.     }

  139.     /** Check whether the frame is considerer Sun-centered.
  140.      *
  141.      * @param sunPositionInFrame Sun position in frame to test
  142.      * @return true if frame is considered Sun-centered
  143.      * @since 12.0
  144.      */
  145.     private boolean isSunCenteredFrame(final Vector3D sunPositionInFrame) {
  146.         // Frame is considered Sun-centered if Sun (or Solar System barycenter) position
  147.         // in that frame is smaller than SUN_CENTERED_FRAME_THRESHOLD
  148.         return sunPositionInFrame.getNorm() < SUN_CENTERED_FRAME_THRESHOLD;
  149.     }


  150.     /** Get the lighting ratio ([0-1]).
  151.      * @param state spacecraft state
  152.      * @param sunPosition Sun position in S/C frame at S/C date
  153.      * @return lighting ratio
  154.      * @since 12.0 added to avoid numerous call to sun.getPosition(...)
  155.      */
  156.     private double getLightingRatio(final SpacecraftState state, final Vector3D sunPosition) {

  157.         // Check if S/C frame is Sun-centered
  158.         if (isSunCenteredFrame(sunPosition)) {
  159.             // We are in fact computing a trajectory around Sun (or solar system barycenter),
  160.             // not around a planet, we consider lighting ratio will always be 1
  161.             return 1.0;
  162.         }

  163.         final List<OccultationEngine> occultingBodies = getOccultingBodies();
  164.         final int n = occultingBodies.size();

  165.         final OccultationEngine.OccultationAngles[] angles = new OccultationEngine.OccultationAngles[n];
  166.         for (int i = 0; i < n; ++i) {
  167.             angles[i] = occultingBodies.get(i).angles(state);
  168.         }
  169.         final double alphaSunSq = angles[0].getOccultedApparentRadius() * angles[0].getOccultedApparentRadius();

  170.         double result = 0.0;
  171.         for (int i = 0; i < n; ++i) {

  172.             // compute lighting ratio considering one occulting body only
  173.             final OccultationEngine oi  = occultingBodies.get(i);
  174.             final double lightingRatioI = maskingRatio(angles[i]);
  175.             if (lightingRatioI == 0.0) {
  176.                 // body totally occults Sun, total eclipse is occurring.
  177.                 return 0.0;
  178.             }
  179.             result += lightingRatioI;

  180.             // Mutual occulting body eclipse ratio computations between first and secondary bodies
  181.             for (int j = i + 1; j < n; ++j) {

  182.                 final OccultationEngine oj = occultingBodies.get(j);
  183.                 final double lightingRatioJ = maskingRatio(angles[j]);
  184.                 if (lightingRatioJ == 0.0) {
  185.                     // Secondary body totally occults Sun, no more computations are required, total eclipse is occurring.
  186.                     return 0.0;
  187.                 } else if (lightingRatioJ != 1) {
  188.                     // Secondary body partially occults Sun

  189.                     final OccultationEngine oij = new OccultationEngine(new FrameAdapter(oi.getOcculting().getBodyFrame()),
  190.                                                                         oi.getOcculting().getEquatorialRadius(),
  191.                                                                         oj.getOcculting());
  192.                     final OccultationEngine.OccultationAngles aij = oij.angles(state);
  193.                     final double maskingRatioIJ = maskingRatio(aij);
  194.                     final double alphaJSq       = aij.getOccultedApparentRadius() * aij.getOccultedApparentRadius();

  195.                     final double mutualEclipseCorrection = (1 - maskingRatioIJ) * alphaJSq / alphaSunSq;
  196.                     result -= mutualEclipseCorrection;

  197.                 }

  198.             }
  199.         }

  200.         // Final term
  201.         result -= n - 1;

  202.         return result;
  203.     }

  204.     /** Get the lighting ratio ([0-1]).
  205.      * @param state spacecraft state
  206.      * @return lighting ratio
  207.      * @since 7.1
  208.      */
  209.     public double getLightingRatio(final SpacecraftState state) {
  210.         return getLightingRatio(state, sun.getPosition(state.getDate(), state.getFrame()));
  211.     }

  212.     /** Get the masking ratio ([0-1]) considering one pair of bodies.
  213.      * @param angles occultation angles
  214.      * @return masking ratio: 0.0 body fully masked, 1.0 body fully visible
  215.      * @since 12.0
  216.      */
  217.     private double maskingRatio(final OccultationEngine.OccultationAngles angles) {

  218.         // Sat-Occulted/ Sat-Occulting angle
  219.         final double sunSatCentralBodyAngle = angles.getSeparation();

  220.         // Occulting apparent radius
  221.         final double alphaCentral = angles.getLimbRadius();

  222.         // Occulted apparent radius
  223.         final double alphaSun = angles.getOccultedApparentRadius();

  224.         // Is the satellite in complete umbra ?
  225.         if (sunSatCentralBodyAngle - alphaCentral + alphaSun <= ANGULAR_MARGIN) {
  226.             return 0.0;
  227.         } else if (sunSatCentralBodyAngle - alphaCentral - alphaSun < -ANGULAR_MARGIN) {
  228.             // Compute a masking ratio in penumbra
  229.             final double sEA2    = sunSatCentralBodyAngle * sunSatCentralBodyAngle;
  230.             final double oo2sEA  = 1.0 / (2. * sunSatCentralBodyAngle);
  231.             final double aS2     = alphaSun * alphaSun;
  232.             final double aE2     = alphaCentral * alphaCentral;
  233.             final double aE2maS2 = aE2 - aS2;

  234.             final double alpha1  = (sEA2 - aE2maS2) * oo2sEA;
  235.             final double alpha2  = (sEA2 + aE2maS2) * oo2sEA;

  236.             // Protection against numerical inaccuracy at boundaries
  237.             final double almost0 = Precision.SAFE_MIN;
  238.             final double almost1 = FastMath.nextDown(1.0);
  239.             final double a1oaS   = FastMath.min(almost1, FastMath.max(-almost1, alpha1 / alphaSun));
  240.             final double aS2ma12 = FastMath.max(almost0, aS2 - alpha1 * alpha1);
  241.             final double a2oaE   = FastMath.min(almost1, FastMath.max(-almost1, alpha2 / alphaCentral));
  242.             final double aE2ma22 = FastMath.max(almost0, aE2 - alpha2 * alpha2);

  243.             final double P1 = aS2 * FastMath.acos(a1oaS) - alpha1 * FastMath.sqrt(aS2ma12);
  244.             final double P2 = aE2 * FastMath.acos(a2oaE) - alpha2 * FastMath.sqrt(aE2ma22);

  245.             return 1. - (P1 + P2) / (FastMath.PI * aS2);
  246.         } else {
  247.             return 1.0;
  248.         }

  249.     }

  250.     /** Get the lighting ratio ([0-1]).
  251.      * @param state spacecraft state
  252.      * @param sunPosition Sun position in S/C frame at S/C date
  253.      * @param <T> extends CalculusFieldElement
  254.      * @return lighting ratio
  255.      * @since 12.0 added to avoid numerous call to sun.getPosition(...)
  256.      */
  257.     private <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldSpacecraftState<T> state, final FieldVector3D<T> sunPosition) {

  258.         final T one  = state.getDate().getField().getOne();
  259.         if (isSunCenteredFrame(sunPosition.toVector3D())) {
  260.             // We are in fact computing a trajectory around Sun (or solar system barycenter),
  261.             // not around a planet, we consider lighting ratio will always be 1
  262.             return one;
  263.         }
  264.         final T zero = state.getDate().getField().getZero();
  265.         final List<OccultationEngine> occultingBodies = getOccultingBodies();
  266.         final int n = occultingBodies.size();

  267.         @SuppressWarnings("unchecked")
  268.         final OccultationEngine.FieldOccultationAngles<T>[] angles =
  269.         (OccultationEngine.FieldOccultationAngles<T>[]) Array.newInstance(OccultationEngine.FieldOccultationAngles.class, n);
  270.         for (int i = 0; i < n; ++i) {
  271.             angles[i] = occultingBodies.get(i).angles(state);
  272.         }
  273.         final T alphaSunSq = angles[0].getOccultedApparentRadius().multiply(angles[0].getOccultedApparentRadius());

  274.         T result = state.getDate().getField().getZero();
  275.         for (int i = 0; i < n; ++i) {

  276.             // compute lighting ratio considering one occulting body only
  277.             final OccultationEngine oi  = occultingBodies.get(i);
  278.             final T lightingRatioI = maskingRatio(angles[i]);
  279.             if (lightingRatioI.isZero()) {
  280.                 // body totally occults Sun, total eclipse is occurring.
  281.                 return zero;
  282.             }
  283.             result = result.add(lightingRatioI);

  284.             // Mutual occulting body eclipse ratio computations between first and secondary bodies
  285.             for (int j = i + 1; j < n; ++j) {

  286.                 final OccultationEngine oj = occultingBodies.get(j);
  287.                 final T lightingRatioJ = maskingRatio(angles[j]);
  288.                 if (lightingRatioJ.isZero()) {
  289.                     // Secondary body totally occults Sun, no more computations are required, total eclipse is occurring.
  290.                     return zero;
  291.                 } else if (lightingRatioJ.getReal() != 1) {
  292.                     // Secondary body partially occults Sun

  293.                     final OccultationEngine oij = new OccultationEngine(new FrameAdapter(oi.getOcculting().getBodyFrame()),
  294.                                                                         oi.getOcculting().getEquatorialRadius(),
  295.                                                                         oj.getOcculting());
  296.                     final OccultationEngine.FieldOccultationAngles<T> aij = oij.angles(state);
  297.                     final T maskingRatioIJ = maskingRatio(aij);
  298.                     final T alphaJSq       = aij.getOccultedApparentRadius().multiply(aij.getOccultedApparentRadius());

  299.                     final T mutualEclipseCorrection = one.subtract(maskingRatioIJ).multiply(alphaJSq).divide(alphaSunSq);
  300.                     result = result.subtract(mutualEclipseCorrection);

  301.                 }

  302.             }
  303.         }

  304.         // Final term
  305.         result = result.subtract(n - 1);

  306.         return result;
  307.     }

  308.     /** Get the lighting ratio ([0-1]).
  309.      * @param state spacecraft state
  310.      * @param <T> extends CalculusFieldElement
  311.      * @return lighting ratio
  312.      * @since 7.1
  313.      */
  314.     public <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldSpacecraftState<T> state) {
  315.         return getLightingRatio(state, sun.getPosition(state.getDate(), state.getFrame()));
  316.     }

  317.     /** Get the masking ratio ([0-1]) considering one pair of bodies.
  318.      * @param angles occultation angles
  319.      * @param <T> type of the field elements
  320.      * @return masking ratio: 0.0 body fully masked, 1.0 body fully visible
  321.      * @since 12.0
  322.      */
  323.     private <T extends CalculusFieldElement<T>> T maskingRatio(final OccultationEngine.FieldOccultationAngles<T> angles) {


  324.         // Sat-Occulted/ Sat-Occulting angle
  325.         final T occultedSatOcculting = angles.getSeparation();

  326.         // Occulting apparent radius
  327.         final T alphaOcculting = angles.getLimbRadius();

  328.         // Occulted apparent radius
  329.         final T alphaOcculted = angles.getOccultedApparentRadius();

  330.         // Is the satellite in complete umbra ?
  331.         if (occultedSatOcculting.getReal() - alphaOcculting.getReal() + alphaOcculted.getReal() <= ANGULAR_MARGIN) {
  332.             return occultedSatOcculting.getField().getZero();
  333.         } else if (occultedSatOcculting.getReal() - alphaOcculting.getReal() - alphaOcculted.getReal() < -ANGULAR_MARGIN) {
  334.             // Compute a masking ratio in penumbra
  335.             final T sEA2    = occultedSatOcculting.multiply(occultedSatOcculting);
  336.             final T oo2sEA  = occultedSatOcculting.multiply(2).reciprocal();
  337.             final T aS2     = alphaOcculted.multiply(alphaOcculted);
  338.             final T aE2     = alphaOcculting.multiply(alphaOcculting);
  339.             final T aE2maS2 = aE2.subtract(aS2);

  340.             final T alpha1  = sEA2.subtract(aE2maS2).multiply(oo2sEA);
  341.             final T alpha2  = sEA2.add(aE2maS2).multiply(oo2sEA);

  342.             // Protection against numerical inaccuracy at boundaries
  343.             final double almost0 = Precision.SAFE_MIN;
  344.             final double almost1 = FastMath.nextDown(1.0);
  345.             final T a1oaS   = min(almost1, max(-almost1, alpha1.divide(alphaOcculted)));
  346.             final T aS2ma12 = max(almost0, aS2.subtract(alpha1.multiply(alpha1)));
  347.             final T a2oaE   = min(almost1, max(-almost1, alpha2.divide(alphaOcculting)));
  348.             final T aE2ma22 = max(almost0, aE2.subtract(alpha2.multiply(alpha2)));

  349.             final T P1 = aS2.multiply(a1oaS.acos()).subtract(alpha1.multiply(aS2ma12.sqrt()));
  350.             final T P2 = aE2.multiply(a2oaE.acos()).subtract(alpha2.multiply(aE2ma22.sqrt()));

  351.             return occultedSatOcculting.getField().getOne().subtract(P1.add(P2).divide(aS2.multiply(occultedSatOcculting.getPi())));
  352.         } else {
  353.             return occultedSatOcculting.getField().getOne();
  354.         }

  355.     }

  356.     /** {@inheritDoc} */
  357.     @Override
  358.     public List<ParameterDriver> getParametersDrivers() {
  359.         return spacecraft.getRadiationParametersDrivers();
  360.     }

  361.     /** Compute min of two values, one double and one field element.
  362.      * @param d double value
  363.      * @param f field element
  364.      * @param <T> type of the field elements
  365.      * @return min value
  366.      */
  367.     private <T extends CalculusFieldElement<T>> T min(final double d, final T f) {
  368.         return (f.getReal() > d) ? f.getField().getZero().newInstance(d) : f;
  369.     }

  370.     /** Compute max of two values, one double and one field element.
  371.      * @param d double value
  372.      * @param f field element
  373.      * @param <T> type of the field elements
  374.      * @return max value
  375.      */
  376.     private <T extends CalculusFieldElement<T>> T max(final double d, final T f) {
  377.         return (f.getReal() <= d) ? f.getField().getZero().newInstance(d) : f;
  378.     }

  379. }