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

  18. import java.util.stream.Stream;

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

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

  65.     /** Reference inertial frame to use to compute inertial forces. */
  66.     private Frame referenceInertialFrame;

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

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

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

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

  93.         final Vector3D  p2                = s.getPVCoordinates().getPosition();
  94.         final Vector3D  v2                = s.getPVCoordinates().getVelocity();

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

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

  101.     }

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

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

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

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

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

  119.     }

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

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

  131.     /** {@inheritDoc} */
  132.     @Override
  133.     public ParameterDriver[] getParametersDrivers() {
  134.         return new ParameterDriver[0];
  135.     }

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

  141. }