InertialForces.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.inertia;

  18. import java.util.Collections;
  19. import java.util.List;
  20. import java.util.stream.Stream;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.CalculusFieldElement;
  23. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  24. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  25. import org.hipparchus.geometry.euclidean.threed.Rotation;
  26. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitIllegalArgumentException;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.forces.AbstractForceModel;
  31. import org.orekit.frames.FieldTransform;
  32. import org.orekit.frames.Frame;
  33. import org.orekit.frames.Transform;
  34. import org.orekit.propagation.FieldSpacecraftState;
  35. import org.orekit.propagation.SpacecraftState;
  36. import org.orekit.propagation.events.EventDetector;
  37. import org.orekit.propagation.events.FieldEventDetector;
  38. import org.orekit.utils.AbsolutePVCoordinates;
  39. import org.orekit.utils.ParameterDriver;

  40. /** Inertial force model.
  41.  * <p>
  42.  * This force model adds the pseudo-forces due to inertia between the
  43.  * integrating frame and a reference inertial frame from which
  44.  * this force model is built.
  45.  * </p>
  46.  * <p>
  47.  * Two typical use-cases are propagating {@link AbsolutePVCoordinates} in either:
  48.  * </p>
  49.  * <ul>
  50.  *   <li>a non-inertial frame (for example propagating in the rotating {@link
  51.  *       org.orekit.frames.FramesFactory#getITRF(org.orekit.utils.IERSConventions, boolean) ITRF}
  52.  *       frame),</li>
  53.  *   <li>an inertial frame that is not related to the main attracting body (for example
  54.  *       propagating in {@link org.orekit.frames.FramesFactory#getEME2000() EME2000} frame a
  55.  *       trajectory about the Sun and Jupiter).</li>
  56.  * </ul>
  57.  * <p>
  58.  * In the second used case above, the attraction from the two main bodies, i.e. the Sun and
  59.  * Jupiter, should be represented by {@link org.orekit.forces.gravity.SingleBodyAbsoluteAttraction}
  60.  * instances.
  61.  * </p>
  62.  * @see org.orekit.forces.gravity.SingleBodyAbsoluteAttraction
  63.  * @author Guillaume Obrecht
  64.  * @author Luc Maisonobe
  65.  */
  66. public class InertialForces extends AbstractForceModel  {

  67.     /** Reference inertial frame to use to compute inertial forces. */
  68.     private Frame referenceInertialFrame;

  69.     /** Simple constructor.
  70.      * @param referenceInertialFrame the pseudo-inertial frame to use as reference for the inertial forces
  71.      * @exception OrekitIllegalArgumentException if frame is not a {@link
  72.      * Frame#isPseudoInertial pseudo-inertial frame}
  73.      */
  74.     public InertialForces(final Frame referenceInertialFrame)
  75.         throws OrekitIllegalArgumentException {
  76.         if (!referenceInertialFrame.isPseudoInertial()) {
  77.             throw new OrekitIllegalArgumentException(OrekitMessages.NON_PSEUDO_INERTIAL_FRAME_NOT_SUITABLE_AS_REFERENCE_FOR_INERTIAL_FORCES,
  78.                                                      referenceInertialFrame.getName());
  79.         }
  80.         this.referenceInertialFrame = referenceInertialFrame;
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     public boolean dependsOnPositionOnly() {
  85.         return false;
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {

  90.         final Transform inertToStateFrame = referenceInertialFrame.getTransformTo(s.getFrame(), s.getDate());
  91.         final Vector3D  a1                = inertToStateFrame.getCartesian().getAcceleration();
  92.         final Rotation  r1                = inertToStateFrame.getAngular().getRotation();
  93.         final Vector3D  o1                = inertToStateFrame.getAngular().getRotationRate();
  94.         final Vector3D  oDot1             = inertToStateFrame.getAngular().getRotationAcceleration();

  95.         final Vector3D  p2                = s.getPVCoordinates().getPosition();
  96.         final Vector3D  v2                = s.getPVCoordinates().getVelocity();

  97.         final Vector3D crossCrossP        = Vector3D.crossProduct(o1,    Vector3D.crossProduct(o1, p2));
  98.         final Vector3D crossV             = Vector3D.crossProduct(o1,    v2);
  99.         final Vector3D crossDotP          = Vector3D.crossProduct(oDot1, p2);

  100.         // we intentionally DON'T include s.getPVCoordinates().getAcceleration()
  101.         // because we want only the coupling effect of the frames transforms
  102.         return r1.applyTo(a1).subtract(new Vector3D(2, crossV, 1, crossCrossP, 1, crossDotP));

  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  107.                                                                          final T[] parameters) {

  108.         final FieldTransform<T> inertToStateFrame = referenceInertialFrame.getTransformTo(s.getFrame(), s.getDate());
  109.         final FieldVector3D<T>  a1                = inertToStateFrame.getCartesian().getAcceleration();
  110.         final FieldRotation<T>  r1                = inertToStateFrame.getAngular().getRotation();
  111.         final FieldVector3D<T>  o1                = inertToStateFrame.getAngular().getRotationRate();
  112.         final FieldVector3D<T>  oDot1             = inertToStateFrame.getAngular().getRotationAcceleration();

  113.         final FieldVector3D<T>  p2                = s.getPVCoordinates().getPosition();
  114.         final FieldVector3D<T>  v2                = s.getPVCoordinates().getVelocity();

  115.         final FieldVector3D<T> crossCrossP        = FieldVector3D.crossProduct(o1,    FieldVector3D.crossProduct(o1, p2));
  116.         final FieldVector3D<T> crossV             = FieldVector3D.crossProduct(o1,    v2);
  117.         final FieldVector3D<T> crossDotP          = FieldVector3D.crossProduct(oDot1, p2);

  118.         // we intentionally DON'T include s.getPVCoordinates().getAcceleration()
  119.         // because we want only the coupling effect of the frames transforms
  120.         return r1.applyTo(a1).subtract(new FieldVector3D<>(2, crossV, 1, crossCrossP, 1, crossDotP));

  121.     }

  122.     /** {@inheritDoc} */
  123.     @Override
  124.     public Stream<EventDetector> getEventsDetectors() {
  125.         return Stream.empty();
  126.     }

  127.     /** {@inheritDoc} */
  128.     @Override
  129.     public <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>>
  130.         getFieldEventsDetectors(final Field<T> field) {
  131.         return Stream.empty();
  132.     }

  133.     /** {@inheritDoc} */
  134.     @Override
  135.     public List<ParameterDriver> getParametersDrivers() {
  136.         return Collections.emptyList();
  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     public ParameterDriver getParameterDriver(final String name) {
  141.         throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, "<none>");
  142.     }

  143. }