DragForce.java

  1. /* Copyright 2002-2020 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.forces.drag;

  18. import java.util.stream.Stream;

  19. import org.hipparchus.Field;
  20. import org.hipparchus.RealFieldElement;
  21. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  22. import org.hipparchus.analysis.differentiation.Gradient;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.models.earth.atmosphere.Atmosphere;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.propagation.events.EventDetector;
  30. import org.orekit.propagation.events.FieldEventDetector;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.ParameterDriver;


  34. /** Atmospheric drag force model.
  35.  *
  36.  * The drag acceleration is computed as follows :
  37.  *
  38.  * γ = (1/2 * ρ * V² * S / Mass) * DragCoefVector
  39.  *
  40.  * With DragCoefVector = {C<sub>x</sub>, C<sub>y</sub>, C<sub>z</sub>} and S given by the user through the interface
  41.  * {@link DragSensitive}
  42.  *
  43.  * @author &Eacute;douard Delente
  44.  * @author Fabien Maussion
  45.  * @author V&eacute;ronique Pommier-Maurussane
  46.  * @author Pascal Parraud
  47.  */

  48. public class DragForce extends AbstractDragForceModel {

  49.     /** Atmospheric model. */
  50.     private final Atmosphere atmosphere;

  51.     /** Spacecraft. */
  52.     private final DragSensitive spacecraft;

  53.     /** Simple constructor.
  54.      * @param atmosphere atmospheric model
  55.      * @param spacecraft the object physical and geometrical information
  56.      */
  57.     public DragForce(final Atmosphere atmosphere, final DragSensitive spacecraft) {
  58.         super(atmosphere);
  59.         this.atmosphere = atmosphere;
  60.         this.spacecraft = spacecraft;
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  65.         final AbsoluteDate date     = s.getDate();
  66.         final Frame        frame    = s.getFrame();
  67.         final Vector3D     position = s.getPVCoordinates().getPosition();

  68.         final double rho    = atmosphere.getDensity(date, position, frame);
  69.         final Vector3D vAtm = atmosphere.getVelocity(date, position, frame);
  70.         final Vector3D relativeVelocity = vAtm.subtract(s.getPVCoordinates().getVelocity());

  71.         return spacecraft.dragAcceleration(date, frame, position, s.getAttitude().getRotation(),
  72.                                            s.getMass(), rho, relativeVelocity, parameters);

  73.     }

  74.     /** {@inheritDoc} */
  75.     @SuppressWarnings("unchecked")
  76.     @Override
  77.     public <T extends RealFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  78.                                                                          final T[] parameters) {

  79.         final FieldAbsoluteDate<T> date     = s.getDate();
  80.         final Frame                frame    = s.getFrame();
  81.         final FieldVector3D<T>     position = s.getPVCoordinates().getPosition();

  82.         // Density and its derivatives
  83.         final T rho;

  84.         // Check for faster computation dedicated to derivatives with respect to state
  85.         // Using finite differences instead of automatic differentiation as it seems to be much
  86.         // faster for the drag's derivatives' computation
  87.         if (isGradientStateDerivative(s)) {
  88.             rho =  (T) this.getGradientDensityWrtStateUsingFiniteDifferences(date.toAbsoluteDate(), frame, (FieldVector3D<Gradient>) position);
  89.         } else if (isDSStateDerivative(s)) {
  90.             rho = (T) this.getDSDensityWrtStateUsingFiniteDifferences(date.toAbsoluteDate(), frame, (FieldVector3D<DerivativeStructure>) position);
  91.         } else {
  92.             rho = atmosphere.getDensity(date, position, frame);
  93.         }

  94.         // Spacecraft relative velocity with respect to the atmosphere
  95.         final FieldVector3D<T> vAtm = atmosphere.getVelocity(date, position, frame);
  96.         final FieldVector3D<T> relativeVelocity = vAtm.subtract(s.getPVCoordinates().getVelocity());

  97.         // Drag acceleration along with its derivatives
  98.         return spacecraft.dragAcceleration(date, frame, position, s.getAttitude().getRotation(),
  99.                                            s.getMass(), rho, relativeVelocity, parameters);

  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public ParameterDriver[] getParametersDrivers() {
  104.         return spacecraft.getDragParametersDrivers();
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public Stream<EventDetector> getEventsDetectors() {
  109.         return Stream.empty();
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
  114.         return Stream.empty();
  115.     }

  116.     /** Get the atmospheric model.
  117.      * @return atmosphere model
  118.      */
  119.     public Atmosphere getAtmosphere() {
  120.         return atmosphere;
  121.     }

  122.     /** Get spacecraft that are sensitive to atmospheric drag forces.
  123.      * @return drag sensitive spacecraft model
  124.      */
  125.     public DragSensitive getSpacecraft() {
  126.         return spacecraft;
  127.     }
  128. }