CylindricallyShadowedLightFluxModel.java

  1. /* Copyright 2022-2024 Romain Serra
  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.Field;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.ode.events.Action;
  23. import org.hipparchus.util.FastMath;
  24. import org.orekit.propagation.events.CylindricalShadowEclipseDetector;
  25. import org.orekit.propagation.events.EventDetector;
  26. import org.orekit.propagation.events.FieldCylindricalShadowEclipseDetector;
  27. import org.orekit.propagation.events.FieldEventDetector;
  28. import org.orekit.utils.ExtendedPositionProvider;

  29. import java.util.ArrayList;
  30. import java.util.List;

  31. /**
  32.  * Class defining a flux model with a single occulting body, casting a shadow whose shape is a circular cylinder
  33.  * (equivalent to the light source being infinitely distant). It is less accurate but faster to evaluate than a conical
  34.  * model.
  35.  *
  36.  * @author Romain Serra
  37.  * @see AbstractLightFluxModel
  38.  * @see LightFluxModel
  39.  * @since 12.1
  40.  */
  41. public class CylindricallyShadowedLightFluxModel extends AbstractLightFluxModel {

  42.     /**
  43.      * Max. check interval for eclipse detection.
  44.      */
  45.     private static final double CYLINDRICAL_ECLIPSE_MAX_CHECK = 100;

  46.     /**
  47.      * Threshold for eclipse detection.
  48.      */
  49.     private static final double CYLINDRICAL_ECLIPSE_THRESHOLD = 1e-7;

  50.     /** Radius of central, occulting body (approximated as spherical).
  51.      * Its center is assumed to be at the origin of the frame linked to the state. */
  52.     private final double occultingBodyRadius;

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

  55.     /**
  56.      * Constructor.
  57.      * @param kRef reference flux
  58.      * @param occultedBody position provider for light source
  59.      * @param occultingBodyRadius radius of central, occulting body
  60.      */
  61.     public CylindricallyShadowedLightFluxModel(final double kRef, final ExtendedPositionProvider occultedBody,
  62.                                                final double occultingBodyRadius) {
  63.         super(occultedBody);
  64.         this.kRef = kRef;
  65.         this.occultingBodyRadius = occultingBodyRadius;
  66.     }

  67.     /**
  68.      * Constructor with default value for reference flux.
  69.      * @param occultedBody position provider for light source
  70.      * @param occultingBodyRadius radius of central, occulting body
  71.      */
  72.     public CylindricallyShadowedLightFluxModel(final ExtendedPositionProvider occultedBody,
  73.                                                final double occultingBodyRadius) {
  74.         this(4.56e-6 * FastMath.pow(149597870000.0, 2), occultedBody, occultingBodyRadius);
  75.     }

  76.     /**
  77.      * Getter for occulting body radius.
  78.      * @return radius
  79.      */
  80.     public double getOccultingBodyRadius() {
  81.         return occultingBodyRadius;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     protected Vector3D getUnoccultedFluxVector(final Vector3D relativePosition) {
  86.         final double squaredRadius = relativePosition.getNormSq();
  87.         final double factor = kRef / (squaredRadius * FastMath.sqrt(squaredRadius));
  88.         return relativePosition.scalarMultiply(factor);
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getUnoccultedFluxVector(final FieldVector3D<T> relativePosition) {
  93.         final T squaredRadius = relativePosition.getNormSq();
  94.         final T factor = (squaredRadius.multiply(squaredRadius.sqrt())).reciprocal().multiply(kRef);
  95.         return relativePosition.scalarMultiply(factor);
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     protected double getLightingRatio(final Vector3D position, final Vector3D occultedBodyPosition) {
  100.         final Vector3D occultedBodyDirection = occultedBodyPosition.normalize();
  101.         final double dotProduct = position.dotProduct(occultedBodyDirection);
  102.         if (dotProduct < 0.) {
  103.             final double distanceToCylinderAxis = (position.subtract(occultedBodyDirection.scalarMultiply(dotProduct))).getNorm();
  104.             if (distanceToCylinderAxis <= occultingBodyRadius) {
  105.                 return 0.;
  106.             }
  107.         }
  108.         return 1.;
  109.     }

  110.     /** {@inheritDoc} */
  111.     @Override
  112.     protected <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldVector3D<T> position,
  113.                                                                      final FieldVector3D<T> occultedBodyPosition) {
  114.         final Field<T> field = position.getX().getField();
  115.         final FieldVector3D<T> occultedBodyDirection = occultedBodyPosition.normalize();
  116.         final T dotProduct = position.dotProduct(occultedBodyDirection);
  117.         if (dotProduct.getReal() < 0.) {
  118.             final T distanceToCylinderAxis = (position.subtract(occultedBodyDirection.scalarMultiply(dotProduct))).getNorm();
  119.             if (distanceToCylinderAxis.getReal() <= occultingBodyRadius) {
  120.                 return field.getZero();
  121.             }
  122.         }
  123.         return field.getOne();
  124.     }


  125.     /** {@inheritDoc} */
  126.     @Override
  127.     public List<EventDetector> getEclipseConditionsDetector() {
  128.         final List<EventDetector> detectors = new ArrayList<>();
  129.         detectors.add(createCylindricalShadowEclipseDetector()
  130.             .withThreshold(CYLINDRICAL_ECLIPSE_THRESHOLD).withMaxCheck(CYLINDRICAL_ECLIPSE_MAX_CHECK));
  131.         return detectors;
  132.     }

  133.     /**
  134.      * Method to create a new eclipse detector.
  135.      * @return detector
  136.      */
  137.     private CylindricalShadowEclipseDetector createCylindricalShadowEclipseDetector() {
  138.         return new CylindricalShadowEclipseDetector(getOccultedBody(), getOccultingBodyRadius(),
  139.                 (state, detector, increasing) -> Action.RESET_DERIVATIVES);
  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     public <T extends CalculusFieldElement<T>> List<FieldEventDetector<T>> getFieldEclipseConditionsDetector(final Field<T> field) {
  144.         final List<FieldEventDetector<T>> detectors = new ArrayList<>();
  145.         final T threshold = field.getZero().newInstance(CYLINDRICAL_ECLIPSE_THRESHOLD);
  146.         detectors.add(createFieldCylindricalShadowEclipseDetector(field)
  147.             .withThreshold(threshold).withMaxCheck(CYLINDRICAL_ECLIPSE_MAX_CHECK));
  148.         return detectors;
  149.     }

  150.     /**
  151.      * Method to create a new eclipse detector. Field version.
  152.      * @param field field
  153.      * @param <T> field type
  154.      * @return detector
  155.      */
  156.     private <T extends CalculusFieldElement<T>> FieldCylindricalShadowEclipseDetector<T> createFieldCylindricalShadowEclipseDetector(final Field<T> field) {
  157.         final T occultingBodyRadiusAsField = field.getZero().newInstance(getOccultingBodyRadius());
  158.         return new FieldCylindricalShadowEclipseDetector<>(getOccultedBody(), occultingBodyRadiusAsField,
  159.                 (state, detector, increasing) -> Action.RESET_DERIVATIVES);
  160.     }
  161. }