DragForce.java

  1. /* Copyright 2002-2024 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 org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.analysis.differentiation.Gradient;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.models.earth.atmosphere.Atmosphere;
  26. import org.orekit.propagation.FieldSpacecraftState;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.utils.ParameterDriver;


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

  46. public class DragForce extends AbstractDragForceModel {

  47.     /** Atmospheric model. */
  48.     private final Atmosphere atmosphere;

  49.     /** Spacecraft. */
  50.     private final DragSensitive spacecraft;

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

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

  63.         final AbsoluteDate date     = s.getDate();
  64.         final Frame        frame    = s.getFrame();
  65.         final Vector3D     position = s.getPosition();

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

  69.         return spacecraft.dragAcceleration(s, rho, relativeVelocity, parameters);

  70.     }

  71.     /** {@inheritDoc} */
  72.     @SuppressWarnings("unchecked")
  73.     @Override
  74.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  75.                                                                          final T[] parameters) {

  76.         final FieldAbsoluteDate<T> date     = s.getDate();
  77.         final Frame                frame    = s.getFrame();
  78.         final FieldVector3D<T>     position = s.getPosition();

  79.         // Density and its derivatives
  80.         final T rho;

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

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

  94.         // Drag acceleration along with its derivatives
  95.         return spacecraft.dragAcceleration(s, rho, relativeVelocity, parameters);

  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public List<ParameterDriver> getParametersDrivers() {
  100.         return spacecraft.getDragParametersDrivers();
  101.     }

  102.     /** Get the atmospheric model.
  103.      * @return atmosphere model
  104.      */
  105.     public Atmosphere getAtmosphere() {
  106.         return atmosphere;
  107.     }

  108.     /** Get spacecraft that are sensitive to atmospheric drag forces.
  109.      * @return drag sensitive spacecraft model
  110.      */
  111.     public DragSensitive getSpacecraft() {
  112.         return spacecraft;
  113.     }

  114. }