DragForce.java

  1. /* Copyright 2002-2022 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.List;
  19. import java.util.stream.Stream;

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


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

  49. public class DragForce extends AbstractDragForceModel {

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

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

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

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

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

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

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

  74.     }

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

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

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

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

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

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

  101.     }

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     public List<ParameterDriver> getParametersDrivers() {
  105.         return spacecraft.getDragParametersDrivers();
  106.     }

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

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

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

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