SolarRadiationPressure.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.forces.radiation;

  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.orekit.bodies.OneAxisEllipsoid;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.utils.Constants;
  30. import org.orekit.utils.ExtendedPVCoordinatesProvider;
  31. import org.orekit.utils.FrameAdapter;
  32. import org.orekit.utils.OccultationEngine;
  33. import org.orekit.utils.ParameterDriver;

  34. import java.lang.reflect.Array;
  35. import java.util.List;

  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.     /**
  109.      * Getter for radiation-sensitive spacecraft.
  110.      * @return radiation-sensitive model
  111.      * @since 12.1
  112.      */
  113.     public RadiationSensitive getRadiationSensitiveSpacecraft() {
  114.         return spacecraft;
  115.     }

  116.     /** {@inheritDoc} */
  117.     @Override
  118.     public boolean dependsOnPositionOnly() {
  119.         return spacecraft instanceof IsotropicRadiationClassicalConvention || spacecraft instanceof IsotropicRadiationCNES95Convention || spacecraft instanceof IsotropicRadiationSingleCoefficient;
  120.     }

  121.     /** {@inheritDoc} */
  122.     @Override
  123.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  124.         final AbsoluteDate date         = s.getDate();
  125.         final Frame        frame        = s.getFrame();
  126.         final Vector3D     position     = s.getPosition();
  127.         final Vector3D     sunPosition  = sun.getPosition(date, frame);
  128.         final Vector3D     sunSatVector = position.subtract(sunPosition);
  129.         final double       r2           = sunSatVector.getNormSq();

  130.         // compute flux
  131.         final double   ratio = getLightingRatio(s, sunPosition);
  132.         final double   rawP  = ratio  * kRef / r2;
  133.         final Vector3D flux  = new Vector3D(rawP / FastMath.sqrt(r2), sunSatVector);

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

  135.     }

  136.     /** {@inheritDoc} */
  137.     @Override
  138.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  139.                                                                              final T[] parameters) {

  140.         final FieldAbsoluteDate<T> date         = s.getDate();
  141.         final Frame                frame        = s.getFrame();
  142.         final FieldVector3D<T>     position     = s.getPosition();
  143.         final FieldVector3D<T>     sunPosition  = sun.getPosition(date, frame);
  144.         final FieldVector3D<T>     sunSatVector = position.subtract(sunPosition);
  145.         final T                    r2           = sunSatVector.getNormSq();

  146.         // compute flux
  147.         final T                ratio = getLightingRatio(s, sunPosition);
  148.         final T                rawP  = ratio.multiply(kRef).divide(r2);
  149.         final FieldVector3D<T> flux  = new FieldVector3D<>(rawP.divide(r2.sqrt()), sunSatVector);

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

  151.     }

  152.     /** Check whether the frame is considerer Sun-centered.
  153.      *
  154.      * @param sunPositionInFrame Sun position in frame to test
  155.      * @return true if frame is considered Sun-centered
  156.      * @since 12.0
  157.      */
  158.     private boolean isSunCenteredFrame(final Vector3D sunPositionInFrame) {
  159.         // Frame is considered Sun-centered if Sun (or Solar System barycenter) position
  160.         // in that frame is smaller than SUN_CENTERED_FRAME_THRESHOLD
  161.         return sunPositionInFrame.getNorm() < SUN_CENTERED_FRAME_THRESHOLD;
  162.     }


  163.     /** Get the lighting ratio ([0-1]).
  164.      * @param state spacecraft state
  165.      * @param sunPosition Sun position in S/C frame at S/C date
  166.      * @return lighting ratio
  167.      * @since 12.0 added to avoid numerous call to sun.getPosition(...)
  168.      */
  169.     private double getLightingRatio(final SpacecraftState state, final Vector3D sunPosition) {

  170.         // Check if S/C frame is Sun-centered
  171.         if (isSunCenteredFrame(sunPosition)) {
  172.             // We are in fact computing a trajectory around Sun (or solar system barycenter),
  173.             // not around a planet, we consider lighting ratio will always be 1
  174.             return 1.0;
  175.         }

  176.         final List<OccultationEngine> occultingBodies = getOccultingBodies();
  177.         final int n = occultingBodies.size();

  178.         final OccultationEngine.OccultationAngles[] angles = new OccultationEngine.OccultationAngles[n];
  179.         for (int i = 0; i < n; ++i) {
  180.             angles[i] = occultingBodies.get(i).angles(state);
  181.         }
  182.         final double alphaSunSq = angles[0].getOccultedApparentRadius() * angles[0].getOccultedApparentRadius();

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

  185.             // compute lighting ratio considering one occulting body only
  186.             final OccultationEngine oi  = occultingBodies.get(i);
  187.             final double lightingRatioI = maskingRatio(angles[i]);
  188.             if (lightingRatioI == 0.0) {
  189.                 // body totally occults Sun, total eclipse is occurring.
  190.                 return 0.0;
  191.             }
  192.             result += lightingRatioI;

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

  195.                 final OccultationEngine oj = occultingBodies.get(j);
  196.                 final double lightingRatioJ = maskingRatio(angles[j]);
  197.                 if (lightingRatioJ == 0.0) {
  198.                     // Secondary body totally occults Sun, no more computations are required, total eclipse is occurring.
  199.                     return 0.0;
  200.                 } else if (lightingRatioJ != 1) {
  201.                     // Secondary body partially occults Sun

  202.                     final OccultationEngine oij = new OccultationEngine(new FrameAdapter(oi.getOcculting().getBodyFrame()),
  203.                                                                         oi.getOcculting().getEquatorialRadius(),
  204.                                                                         oj.getOcculting());
  205.                     final OccultationEngine.OccultationAngles aij = oij.angles(state);
  206.                     final double maskingRatioIJ = maskingRatio(aij);
  207.                     final double alphaJSq       = aij.getOccultedApparentRadius() * aij.getOccultedApparentRadius();

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

  210.                 }

  211.             }
  212.         }

  213.         // Final term
  214.         result -= n - 1;

  215.         return result;
  216.     }

  217.     /** Get the lighting ratio ([0-1]).
  218.      * @param state spacecraft state
  219.      * @return lighting ratio
  220.      * @since 7.1
  221.      */
  222.     public double getLightingRatio(final SpacecraftState state) {
  223.         return getLightingRatio(state, sun.getPosition(state.getDate(), state.getFrame()));
  224.     }

  225.     /** Get the masking ratio ([0-1]) considering one pair of bodies.
  226.      * @param angles occultation angles
  227.      * @return masking ratio: 0.0 body fully masked, 1.0 body fully visible
  228.      * @since 12.0
  229.      */
  230.     private double maskingRatio(final OccultationEngine.OccultationAngles angles) {

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

  233.         // Occulting apparent radius
  234.         final double alphaCentral = angles.getLimbRadius();

  235.         // Occulted apparent radius
  236.         final double alphaSun = angles.getOccultedApparentRadius();

  237.         // Is the satellite in complete umbra ?
  238.         if (sunSatCentralBodyAngle - alphaCentral + alphaSun <= ANGULAR_MARGIN) {
  239.             return 0.0;
  240.         } else if (sunSatCentralBodyAngle - alphaCentral - alphaSun < -ANGULAR_MARGIN) {
  241.             // Compute a masking ratio in penumbra
  242.             final double sEA2    = sunSatCentralBodyAngle * sunSatCentralBodyAngle;
  243.             final double oo2sEA  = 1.0 / (2. * sunSatCentralBodyAngle);
  244.             final double aS2     = alphaSun * alphaSun;
  245.             final double aE2     = alphaCentral * alphaCentral;
  246.             final double aE2maS2 = aE2 - aS2;

  247.             final double alpha1  = (sEA2 - aE2maS2) * oo2sEA;
  248.             final double alpha2  = (sEA2 + aE2maS2) * oo2sEA;

  249.             // Protection against numerical inaccuracy at boundaries
  250.             final double almost0 = Precision.SAFE_MIN;
  251.             final double almost1 = FastMath.nextDown(1.0);
  252.             final double a1oaS   = FastMath.min(almost1, FastMath.max(-almost1, alpha1 / alphaSun));
  253.             final double aS2ma12 = FastMath.max(almost0, aS2 - alpha1 * alpha1);
  254.             final double a2oaE   = FastMath.min(almost1, FastMath.max(-almost1, alpha2 / alphaCentral));
  255.             final double aE2ma22 = FastMath.max(almost0, aE2 - alpha2 * alpha2);

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

  258.             return 1. - (P1 + P2) / (FastMath.PI * aS2);
  259.         } else {
  260.             return 1.0;
  261.         }

  262.     }

  263.     /** Get the lighting ratio ([0-1]).
  264.      * @param state spacecraft state
  265.      * @param sunPosition Sun position in S/C frame at S/C date
  266.      * @param <T> extends CalculusFieldElement
  267.      * @return lighting ratio
  268.      * @since 12.0 added to avoid numerous call to sun.getPosition(...)
  269.      */
  270.     private <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldSpacecraftState<T> state, final FieldVector3D<T> sunPosition) {

  271.         final T one  = state.getDate().getField().getOne();
  272.         if (isSunCenteredFrame(sunPosition.toVector3D())) {
  273.             // We are in fact computing a trajectory around Sun (or solar system barycenter),
  274.             // not around a planet, we consider lighting ratio will always be 1
  275.             return one;
  276.         }
  277.         final T zero = state.getDate().getField().getZero();
  278.         final List<OccultationEngine> occultingBodies = getOccultingBodies();
  279.         final int n = occultingBodies.size();

  280.         @SuppressWarnings("unchecked")
  281.         final OccultationEngine.FieldOccultationAngles<T>[] angles =
  282.         (OccultationEngine.FieldOccultationAngles<T>[]) Array.newInstance(OccultationEngine.FieldOccultationAngles.class, n);
  283.         for (int i = 0; i < n; ++i) {
  284.             angles[i] = occultingBodies.get(i).angles(state);
  285.         }
  286.         final T alphaSunSq = angles[0].getOccultedApparentRadius().multiply(angles[0].getOccultedApparentRadius());

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

  289.             // compute lighting ratio considering one occulting body only
  290.             final OccultationEngine oi  = occultingBodies.get(i);
  291.             final T lightingRatioI = maskingRatio(angles[i]);
  292.             if (lightingRatioI.isZero()) {
  293.                 // body totally occults Sun, total eclipse is occurring.
  294.                 return zero;
  295.             }
  296.             result = result.add(lightingRatioI);

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

  299.                 final OccultationEngine oj = occultingBodies.get(j);
  300.                 final T lightingRatioJ = maskingRatio(angles[j]);
  301.                 if (lightingRatioJ.isZero()) {
  302.                     // Secondary body totally occults Sun, no more computations are required, total eclipse is occurring.
  303.                     return zero;
  304.                 } else if (lightingRatioJ.getReal() != 1) {
  305.                     // Secondary body partially occults Sun

  306.                     final OccultationEngine oij = new OccultationEngine(new FrameAdapter(oi.getOcculting().getBodyFrame()),
  307.                                                                         oi.getOcculting().getEquatorialRadius(),
  308.                                                                         oj.getOcculting());
  309.                     final OccultationEngine.FieldOccultationAngles<T> aij = oij.angles(state);
  310.                     final T maskingRatioIJ = maskingRatio(aij);
  311.                     final T alphaJSq       = aij.getOccultedApparentRadius().multiply(aij.getOccultedApparentRadius());

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

  314.                 }

  315.             }
  316.         }

  317.         // Final term
  318.         result = result.subtract(n - 1);

  319.         return result;
  320.     }

  321.     /** Get the lighting ratio ([0-1]).
  322.      * @param state spacecraft state
  323.      * @param <T> extends CalculusFieldElement
  324.      * @return lighting ratio
  325.      * @since 7.1
  326.      */
  327.     public <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldSpacecraftState<T> state) {
  328.         return getLightingRatio(state, sun.getPosition(state.getDate(), state.getFrame()));
  329.     }

  330.     /** Get the masking ratio ([0-1]) considering one pair of bodies.
  331.      * @param angles occultation angles
  332.      * @param <T> type of the field elements
  333.      * @return masking ratio: 0.0 body fully masked, 1.0 body fully visible
  334.      * @since 12.0
  335.      */
  336.     private <T extends CalculusFieldElement<T>> T maskingRatio(final OccultationEngine.FieldOccultationAngles<T> angles) {


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

  339.         // Occulting apparent radius
  340.         final T alphaOcculting = angles.getLimbRadius();

  341.         // Occulted apparent radius
  342.         final T alphaOcculted = angles.getOccultedApparentRadius();

  343.         // Is the satellite in complete umbra ?
  344.         if (occultedSatOcculting.getReal() - alphaOcculting.getReal() + alphaOcculted.getReal() <= ANGULAR_MARGIN) {
  345.             return occultedSatOcculting.getField().getZero();
  346.         } else if (occultedSatOcculting.getReal() - alphaOcculting.getReal() - alphaOcculted.getReal() < -ANGULAR_MARGIN) {
  347.             // Compute a masking ratio in penumbra
  348.             final T sEA2    = occultedSatOcculting.multiply(occultedSatOcculting);
  349.             final T oo2sEA  = occultedSatOcculting.multiply(2).reciprocal();
  350.             final T aS2     = alphaOcculted.multiply(alphaOcculted);
  351.             final T aE2     = alphaOcculting.multiply(alphaOcculting);
  352.             final T aE2maS2 = aE2.subtract(aS2);

  353.             final T alpha1  = sEA2.subtract(aE2maS2).multiply(oo2sEA);
  354.             final T alpha2  = sEA2.add(aE2maS2).multiply(oo2sEA);

  355.             // Protection against numerical inaccuracy at boundaries
  356.             final double almost0 = Precision.SAFE_MIN;
  357.             final double almost1 = FastMath.nextDown(1.0);
  358.             final T a1oaS   = min(almost1, max(-almost1, alpha1.divide(alphaOcculted)));
  359.             final T aS2ma12 = max(almost0, aS2.subtract(alpha1.multiply(alpha1)));
  360.             final T a2oaE   = min(almost1, max(-almost1, alpha2.divide(alphaOcculting)));
  361.             final T aE2ma22 = max(almost0, aE2.subtract(alpha2.multiply(alpha2)));

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

  364.             return occultedSatOcculting.getField().getOne().subtract(P1.add(P2).divide(aS2.multiply(occultedSatOcculting.getPi())));
  365.         } else {
  366.             return occultedSatOcculting.getField().getOne();
  367.         }

  368.     }

  369.     /** {@inheritDoc} */
  370.     @Override
  371.     public List<ParameterDriver> getParametersDrivers() {
  372.         return spacecraft.getRadiationParametersDrivers();
  373.     }

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

  383.     /** Compute max of two values, one double and one field element.
  384.      * @param d double value
  385.      * @param f field element
  386.      * @param <T> type of the field elements
  387.      * @return max value
  388.      */
  389.     private <T extends CalculusFieldElement<T>> T max(final double d, final T f) {
  390.         return (f.getReal() <= d) ? f.getField().getZero().newInstance(d) : f;
  391.     }

  392. }