1   /* Copyright 2022-2025 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  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.frames.Frame;
23  import org.orekit.propagation.FieldSpacecraftState;
24  import org.orekit.propagation.SpacecraftState;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  import org.orekit.utils.ExtendedPositionProvider;
28  
29  /**
30   * Abstract class for light flux models.
31   * Via the definition of the lighting ratio and the unocculted flux vector, derives the final value.
32   *
33   * @author Romain Serra
34   * @see LightFluxModel
35   * @since 12.1
36   */
37  public abstract class AbstractLightFluxModel implements LightFluxModel {
38  
39      /** Direction provider for the occulted body e.g. the Sun. */
40      private final ExtendedPositionProvider occultedBody;
41  
42      /**
43       * Constructor.
44       * @param occultedBody position provider for light source
45       */
46      protected AbstractLightFluxModel(final ExtendedPositionProvider occultedBody) {
47          this.occultedBody = occultedBody;
48      }
49  
50      /**
51       * Getter for the occulted body's position provider.
52       * @return occulted body
53       */
54      public ExtendedPositionProvider getOccultedBody() {
55          return occultedBody;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public Vector3D getLightFluxVector(final SpacecraftState state) {
61          final Vector3D position = state.getPosition();
62          final Vector3D lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
63          final double lightingRatio = getLightingRatio(position, lightSourcePosition);
64          if (lightingRatio != 0.) {
65              final Vector3D relativePosition = position.subtract(lightSourcePosition);
66              final Vector3D unoccultedFlux = getUnoccultedFluxVector(relativePosition);
67              return unoccultedFlux.scalarMultiply(lightingRatio);
68          } else {
69              return Vector3D.ZERO;
70          }
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public <T extends CalculusFieldElement<T>> FieldVector3D<T> getLightFluxVector(final FieldSpacecraftState<T> state) {
76          final FieldVector3D<T> position = state.getPosition();
77          final FieldVector3D<T> lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
78          final T lightingRatio = getLightingRatio(position, lightSourcePosition);
79          final FieldVector3D<T> relativePosition = position.subtract(lightSourcePosition);
80          final FieldVector3D<T> unoccultedFlux = getUnoccultedFluxVector(relativePosition);
81          return unoccultedFlux.scalarMultiply(lightingRatio);
82      }
83  
84      /**
85       * Method computing the occulted body's position at a given date and frame.
86       * @param date date
87       * @param frame frame
88       * @return position
89       */
90      protected Vector3D getOccultedBodyPosition(final AbsoluteDate date, final Frame frame) {
91          return occultedBody.getPosition(date, frame);
92      }
93  
94      /**
95       * Method computing the occulted body's position at a given date and frame. Field version.
96       * @param date date
97       * @param frame frame
98       * @param <T> field type
99       * @return position
100      */
101     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getOccultedBodyPosition(final FieldAbsoluteDate<T> date,
102                                                                                            final Frame frame) {
103         return occultedBody.getPosition(date, frame);
104     }
105 
106     /** Get the light flux vector, not considering any shadowing effect.
107      * @param relativePosition relative position w.r.t. light source
108      * @return unocculted flux
109      */
110     protected abstract Vector3D getUnoccultedFluxVector(Vector3D relativePosition);
111 
112     /** Get the light flux vector, not considering any shadowing effect. Field version.
113      * @param relativePosition relative position w.r.t. light source
114      * @param <T> field type
115      * @return unocculted flux
116      */
117     protected abstract <T extends CalculusFieldElement<T>> FieldVector3D<T> getUnoccultedFluxVector(FieldVector3D<T> relativePosition);
118 
119     /** Get the lighting ratio ([0-1]).
120      * @param state state
121      * @return lighting ratio
122      */
123     public double getLightingRatio(final SpacecraftState state) {
124         final Vector3D position = state.getPosition();
125         final Vector3D lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
126         return getLightingRatio(position, lightSourcePosition);
127     }
128 
129     /** Get the lighting ratio ([0-1]).
130      * @param position object's position
131      * @param occultedBodyPosition occulted body position in same frame
132      * @return lighting ratio
133      */
134     protected abstract double getLightingRatio(Vector3D position, Vector3D occultedBodyPosition);
135 
136     /** Get the lighting ratio ([0-1]).
137      * @param state state
138      * @param <T> field type
139      * @return lighting ratio
140      */
141     public <T extends CalculusFieldElement<T>> T getLightingRatio(final FieldSpacecraftState<T> state) {
142         final FieldVector3D<T> position = state.getPosition();
143         final FieldVector3D<T> lightSourcePosition = getOccultedBodyPosition(state.getDate(), state.getFrame());
144         return getLightingRatio(position, lightSourcePosition);
145     }
146 
147     /** Get the lighting ratio ([0-1]). Field version.
148      * @param position object's position
149      * @param occultedBodyPosition occulted body position in same frame
150      * @param <T> field type
151      * @return lighting ratio
152      */
153     protected abstract <T extends CalculusFieldElement<T>> T getLightingRatio(FieldVector3D<T> position,
154                                                                               FieldVector3D<T> occultedBodyPosition);
155 
156 }