1   /* Copyright 2002-2021 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.propagation.semianalytical.dsst.forces;
18  
19  import java.util.List;
20  
21  import org.hipparchus.Field;
22  import org.hipparchus.CalculusFieldElement;
23  import org.hipparchus.util.FastMath;
24  import org.hipparchus.util.MathArrays;
25  import org.hipparchus.util.MathUtils;
26  import org.orekit.forces.drag.DragForce;
27  import org.orekit.forces.drag.DragSensitive;
28  import org.orekit.forces.drag.IsotropicDrag;
29  import org.orekit.models.earth.atmosphere.Atmosphere;
30  import org.orekit.propagation.FieldSpacecraftState;
31  import org.orekit.propagation.SpacecraftState;
32  import org.orekit.propagation.events.EventDetector;
33  import org.orekit.propagation.events.FieldEventDetector;
34  import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
35  import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
36  import org.orekit.utils.Constants;
37  import org.orekit.utils.ParameterDriver;
38  
39  /** Atmospheric drag contribution to the
40   *  {@link org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSSTPropagator}.
41   *  <p>
42   *  The drag acceleration is computed through the acceleration model of
43   *  {@link org.orekit.forces.drag.DragForce DragForce}.
44   *  </p>
45   *
46   * @author Pascal Parraud
47   */
48  public class DSSTAtmosphericDrag extends AbstractGaussianContribution {
49  
50      /** Threshold for the choice of the Gauss quadrature order. */
51      private static final double GAUSS_THRESHOLD = 6.0e-10;
52  
53      /** Upper limit for atmospheric drag (m) . */
54      private static final double ATMOSPHERE_ALTITUDE_MAX = 1000000.;
55  
56      /** Atmospheric drag force model. */
57      private final DragForce drag;
58  
59      /** Critical distance from the center of the central body for entering/leaving the atmosphere. */
60      private final double     rbar;
61  
62      /** Simple constructor with custom force.
63       * @param force atmospheric drag force model
64       * @param mu central attraction coefficient
65       */
66      public DSSTAtmosphericDrag(final DragForce force, final double mu) {
67          //Call to the constructor from superclass using the numerical drag model as ForceModel
68          super("DSST-drag-", GAUSS_THRESHOLD, force, mu);
69          this.drag = force;
70          this.rbar = ATMOSPHERE_ALTITUDE_MAX + Constants.WGS84_EARTH_EQUATORIAL_RADIUS;
71      }
72  
73      /** Simple constructor assuming spherical spacecraft.
74       * @param atmosphere atmospheric model
75       * @param cd drag coefficient
76       * @param area cross sectionnal area of satellite
77       * @param mu central attraction coefficient
78       */
79      public DSSTAtmosphericDrag(final Atmosphere atmosphere, final double cd,
80                                 final double area, final double mu) {
81          this(atmosphere, new IsotropicDrag(area, cd), mu);
82      }
83  
84      /** Simple constructor with custom spacecraft.
85       * @param atmosphere atmospheric model
86       * @param spacecraft spacecraft model
87       * @param mu central attraction coefficient
88       */
89      public DSSTAtmosphericDrag(final Atmosphere atmosphere, final DragSensitive spacecraft, final double mu) {
90  
91          //Call to the constructor from superclass using the numerical drag model as ForceModel
92          this(new DragForce(atmosphere, spacecraft), mu);
93      }
94  
95      /** Get the atmospheric model.
96       * @return atmosphere model
97       */
98      public Atmosphere getAtmosphere() {
99          return drag.getAtmosphere();
100     }
101 
102     /** Get the critical distance.
103      *  <p>
104      *  The critical distance from the center of the central body aims at
105      *  defining the atmosphere entry/exit.
106      *  </p>
107      *  @return the critical distance from the center of the central body (m)
108      */
109     public double getRbar() {
110         return rbar;
111     }
112 
113     /** {@inheritDoc} */
114     public EventDetector[] getEventsDetectors() {
115         return null;
116     }
117 
118     /** {@inheritDoc} */
119     @Override
120     public <T extends CalculusFieldElement<T>> FieldEventDetector<T>[] getFieldEventsDetectors(final Field<T> field) {
121         return null;
122     }
123 
124     /** {@inheritDoc} */
125     protected double[] getLLimits(final SpacecraftState state, final AuxiliaryElements auxiliaryElements) {
126 
127         final double perigee = auxiliaryElements.getSma() * (1. - auxiliaryElements.getEcc());
128 
129         // Trajectory entirely out of the atmosphere
130         if (perigee > rbar) {
131             return new double[2];
132         }
133         final double apogee  = auxiliaryElements.getSma() * (1. + auxiliaryElements.getEcc());
134         // Trajectory entirely within of the atmosphere
135         if (apogee < rbar) {
136             return new double[] { -FastMath.PI + MathUtils.normalizeAngle(state.getLv(), 0),
137                                   FastMath.PI + MathUtils.normalizeAngle(state.getLv(), 0) };
138         }
139         // Else, trajectory partialy within of the atmosphere
140         final double fb = FastMath.acos(((auxiliaryElements.getSma() * (1. - auxiliaryElements.getEcc() * auxiliaryElements.getEcc()) / rbar) - 1.) / auxiliaryElements.getEcc());
141         final double wW = FastMath.atan2(auxiliaryElements.getH(), auxiliaryElements.getK());
142         return new double[] {wW - fb, wW + fb};
143     }
144 
145     /** {@inheritDoc} */
146     protected <T extends CalculusFieldElement<T>> T[] getLLimits(final FieldSpacecraftState<T> state,
147                                                              final FieldAuxiliaryElements<T> auxiliaryElements) {
148 
149         final Field<T> field = state.getDate().getField();
150 
151         final T[] tab = MathArrays.buildArray(field, 2);
152 
153         final T perigee = auxiliaryElements.getSma().multiply(auxiliaryElements.getEcc().negate().add(1.));
154         // Trajectory entirely out of the atmosphere
155         if (perigee.getReal() > rbar) {
156             return tab;
157         }
158         final T apogee  = auxiliaryElements.getSma().multiply(auxiliaryElements.getEcc().add(1.));
159         // Trajectory entirely within of the atmosphere
160         if (apogee.getReal() < rbar) {
161             final T zero = field.getZero();
162             final T pi   = zero.getPi();
163             tab[0] = MathUtils.normalizeAngle(state.getLv(), zero).subtract(pi);
164             tab[1] = MathUtils.normalizeAngle(state.getLv(), zero).add(pi);
165             return tab;
166         }
167         // Else, trajectory partialy within of the atmosphere
168         final T fb = FastMath.acos(((auxiliaryElements.getSma().multiply(auxiliaryElements.getEcc().multiply(auxiliaryElements.getEcc()).negate().add(1.)).divide(rbar)).subtract(1.)).divide(auxiliaryElements.getEcc()));
169         final T wW = FastMath.atan2(auxiliaryElements.getH(), auxiliaryElements.getK());
170 
171         tab[0] = wW.subtract(fb);
172         tab[1] = wW.add(fb);
173         return tab;
174     }
175 
176     /** {@inheritDoc} */
177     @Override
178     protected List<ParameterDriver> getParametersDriversWithoutMu() {
179         return drag.getParametersDrivers();
180     }
181 
182     /** Get spacecraft shape.
183      *
184      * @return spacecraft shape
185      */
186     public DragSensitive getSpacecraft() {
187         return drag.getSpacecraft();
188     }
189 
190     /** Get drag force.
191      *
192      * @return drag force
193      */
194     public DragForce getDrag() {
195         return drag;
196     }
197 }