1   /* Copyright 2002-2013 CS Systèmes d'Information
2    * Licensed to CS Systèmes d'Information (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 org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
20  import org.apache.commons.math3.util.FastMath;
21  import org.orekit.errors.OrekitException;
22  import org.orekit.forces.drag.Atmosphere;
23  import org.orekit.frames.Frame;
24  import org.orekit.propagation.SpacecraftState;
25  import org.orekit.propagation.events.EventDetector;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.utils.Constants;
28  
29  /** Atmospheric drag contribution to the
30   *  {@link org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSSTPropagator}.
31   *  <p>
32   *  The drag acceleration is computed as follows:<br>
33   *  &gamma; = (1/2 &rho; C<sub>D</sub> A<sub>Ref</sub> / m) * |v<sub>atm</sub> - v<sub>sat</sub>| *
34   *  (v<sub>atm</sub> - v<sub>sat</sub>)
35   *  </p>
36   *
37   * @author Pascal Parraud
38   */
39  public class DSSTAtmosphericDrag extends AbstractGaussianContribution {
40  
41      /** Threshold for the choice of the Gauss quadrature order. */
42      private static final double GAUSS_THRESHOLD = 6.0e-10;
43  
44      /** Upper limit for atmospheric drag (m) . */
45      private static final double ATMOSPHERE_ALTITUDE_MAX = 1000000.;
46  
47      /** Atmospheric model. */
48      private final Atmosphere atmosphere;
49  
50      /** Cross sectionnal area of satellite. */
51      private final double     area;
52  
53      /** Coefficient 1/2 * C<sub>D</sub> * A<sub>Ref</sub>. */
54      private final double     kRef;
55  
56      /** Critical distance from the center of the central body for entering/leaving the atmosphere. */
57      private final double     rbar;
58  
59      /** Simple constructor.
60       * @param atmosphere atmospheric model
61       * @param cd drag coefficient
62       * @param area cross sectionnal area of satellite
63       */
64      public DSSTAtmosphericDrag(final Atmosphere atmosphere, final double cd, final double area) {
65          super(GAUSS_THRESHOLD);
66          this.atmosphere = atmosphere;
67          this.area = area;
68          this.kRef = 0.5 * cd * area;
69          this.rbar = ATMOSPHERE_ALTITUDE_MAX + Constants.WGS84_EARTH_EQUATORIAL_RADIUS;
70      }
71  
72      /** Get the atmospheric model.
73       * @return atmosphere model
74       */
75      public Atmosphere getAtmosphere() {
76          return atmosphere;
77      }
78  
79      /** Get the cross sectional area of satellite.
80       * @return cross sectional area (m<sup>2</sup>)
81       */
82      public double getArea() {
83          return area;
84      }
85  
86      /** Get the drag coefficient.
87       *  @return drag coefficient
88       */
89      public double getCd() {
90          return 2 * kRef / area;
91      }
92  
93      /** Get the critical distance.
94       *  <p>
95       *  The critical distance from the center of the central body aims at
96       *  defining the atmosphere entry/exit.
97       *  </p>
98       *  @return the critical distance from the center of the central body (m)
99       */
100     public double getRbar() {
101         return rbar;
102     }
103 
104     /** {@inheritDoc} */
105     public double[] getShortPeriodicVariations(final AbsoluteDate date, final double[] meanElements)
106         throws OrekitException {
107         // TODO: not implemented yet, Short Periodic Variations are set to null
108         return new double[] {0., 0., 0., 0., 0., 0.};
109     }
110 
111     /** {@inheritDoc} */
112     public EventDetector[] getEventsDetectors() {
113         return null;
114     }
115 
116     /** {@inheritDoc} */
117     protected Vector3D getAcceleration(final SpacecraftState state,
118                                        final Vector3D position, final Vector3D velocity)
119         throws OrekitException {
120         final AbsoluteDate date = state.getDate();
121         final Frame frame = state.getFrame();
122         // compute atmospheric density (assuming it doesn't depend on the date)
123         final double rho = atmosphere.getDensity(date, position, frame);
124         // compute atmospheric velocity (assuming it doesn't depend on the date)
125         final Vector3D vAtm = atmosphere.getVelocity(date, position, frame);
126         // compute relative velocity
127         final Vector3D vRel = vAtm.subtract(velocity);
128         // compute compound drag coefficient
129         final double bc = kRef / state.getMass();
130         // compute drag acceleration
131         return new Vector3D(bc * rho * vRel.getNorm(), vRel);
132     }
133 
134     /** {@inheritDoc} */
135     protected double[] getLLimits(final SpacecraftState state) throws OrekitException {
136         final double perigee = a * (1. - ecc);
137         // Trajectory entirely out of the atmosphere
138         if (perigee > rbar) {
139             return new double[2];
140         }
141         final double apogee  = a * (1. + ecc);
142         // Trajectory entirely within of the atmosphere
143         if (apogee < rbar) {
144             return new double[] {-FastMath.PI, FastMath.PI};
145         }
146         // Else, trajectory partialy within of the atmosphere
147         final double fb = FastMath.acos(((a * (1. - ecc * ecc) / rbar) - 1.) / ecc);
148         final double wW = FastMath.atan2(h, k);
149         return new double[] {wW - fb, wW + fb};
150     }
151 
152 }