AbstractLightFluxModel.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.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.FieldAbsoluteDate;
  26. import org.orekit.utils.ExtendedPositionProvider;

  27. /**
  28.  * Abstract class for light flux models.
  29.  * Via the definition of the lighting ratio and the unocculted flux vector, derives the final value.
  30.  *
  31.  * @author Romain Serra
  32.  * @see LightFluxModel
  33.  * @since 12.1
  34.  */
  35. public abstract class AbstractLightFluxModel implements LightFluxModel {

  36.     /** Direction provider for the occulted body e.g. the Sun. */
  37.     private final ExtendedPositionProvider occultedBody;

  38.     /**
  39.      * Constructor.
  40.      * @param occultedBody position provider for light source
  41.      */
  42.     protected AbstractLightFluxModel(final ExtendedPositionProvider occultedBody) {
  43.         this.occultedBody = occultedBody;
  44.     }

  45.     /**
  46.      * Getter for the occulted body's position provider.
  47.      * @return occulted body
  48.      */
  49.     public ExtendedPositionProvider getOccultedBody() {
  50.         return occultedBody;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public Vector3D getLightFluxVector(final SpacecraftState state) {
  55.         final Vector3D position = state.getPosition();
  56.         final Vector3D lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
  57.         final double lightingRatio = getLightingRatio(position, lightSourcePosition);
  58.         if (lightingRatio != 0.) {
  59.             final Vector3D relativePosition = position.subtract(lightSourcePosition);
  60.             final Vector3D unoccultedFlux = getUnoccultedFluxVector(relativePosition);
  61.             return unoccultedFlux.scalarMultiply(lightingRatio);
  62.         } else {
  63.             return Vector3D.ZERO;
  64.         }
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getLightFluxVector(final FieldSpacecraftState<T> state) {
  69.         final FieldVector3D<T> position = state.getPosition();
  70.         final FieldVector3D<T> lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
  71.         final T lightingRatio = getLightingRatio(position, lightSourcePosition);
  72.         final FieldVector3D<T> relativePosition = position.subtract(lightSourcePosition);
  73.         final FieldVector3D<T> unoccultedFlux = getUnoccultedFluxVector(relativePosition);
  74.         return unoccultedFlux.scalarMultiply(lightingRatio);
  75.     }

  76.     /**
  77.      * Method computing the occulted body's position at a given date and frame.
  78.      * @param date date
  79.      * @param frame frame
  80.      * @return position
  81.      */
  82.     protected Vector3D getOccultedBodyPosition(final AbsoluteDate date, final Frame frame) {
  83.         return occultedBody.getPosition(date, frame);
  84.     }

  85.     /**
  86.      * Method computing the occulted body's position at a given date and frame. Field version.
  87.      * @param date date
  88.      * @param frame frame
  89.      * @param <T> field type
  90.      * @return position
  91.      */
  92.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getOccultedBodyPosition(final FieldAbsoluteDate<T> date,
  93.                                                                                            final Frame frame) {
  94.         return occultedBody.getPosition(date, frame);
  95.     }

  96.     /** Get the light flux vector, not considering any shadowing effect.
  97.      * @param relativePosition relative position w.r.t. light source
  98.      * @return unocculted flux
  99.      */
  100.     protected abstract Vector3D getUnoccultedFluxVector(Vector3D relativePosition);

  101.     /** Get the light flux vector, not considering any shadowing effect. Field version.
  102.      * @param relativePosition relative position w.r.t. light source
  103.      * @param <T> field type
  104.      * @return unocculted flux
  105.      */
  106.     protected abstract <T extends CalculusFieldElement<T>> FieldVector3D<T> getUnoccultedFluxVector(FieldVector3D<T> relativePosition);

  107.     /** Get the lighting ratio ([0-1]).
  108.      * @param position object's position
  109.      * @param occultedBodyPosition occulted body position in same frame
  110.      * @return lighting ratio
  111.      */
  112.     protected abstract double getLightingRatio(Vector3D position, Vector3D occultedBodyPosition);

  113.     /** Get the lighting ratio ([0-1]). Field version.
  114.      * @param position object's position
  115.      * @param occultedBodyPosition occulted body position in same frame
  116.      * @param <T> field type
  117.      * @return lighting ratio
  118.      */
  119.     protected abstract <T extends CalculusFieldElement<T>> T getLightingRatio(FieldVector3D<T> position,
  120.                                                                               FieldVector3D<T> occultedBodyPosition);

  121. }