ThrustPropulsionModel.java

  1. /* Copyright 2002-2025 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.maneuvers.propulsion;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.Precision;
  22. import org.orekit.attitudes.Attitude;
  23. import org.orekit.attitudes.FieldAttitude;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.utils.Constants;

  27. /** Interface for a thrust-based propulsion model.
  28.  * @author Maxime Journot
  29.  * @since 10.2
  30.  */
  31. public interface ThrustPropulsionModel extends PropulsionModel {

  32.     /**
  33.      * Method computing the effective exhaust velocity from the specific impulse.
  34.      * @param isp specific impulse (s)
  35.      * @return effective exhaust velocity (m/s)
  36.      * @since 13.0
  37.      */
  38.     static double getExhaustVelocity(final double isp) {
  39.         return Constants.G0_STANDARD_GRAVITY * isp;
  40.     }

  41.     /** Get the specific impulse (s).
  42.      * @param s current spacecraft state
  43.      * @return specific impulse (s).
  44.      */
  45.     default double getIsp(SpacecraftState s) {
  46.         final double flowRate = getFlowRate(s);
  47.         return -getControl3DVectorCostType().evaluate(getThrustVector(s)) / (Constants.G0_STANDARD_GRAVITY * flowRate);
  48.     }

  49.     /** Get the thrust direction in spacecraft frame.
  50.      * <p>
  51.      * Return a zero vector if there is no thrust for given spacecraft state.
  52.      * @param s current spacecraft state
  53.      * @return thrust direction in spacecraft frame
  54.      */
  55.     default Vector3D getDirection(SpacecraftState s) {
  56.         final Vector3D thrustVector = getThrustVector(s);
  57.         final double   norm         = thrustVector.getNorm();
  58.         if (norm <= Precision.EPSILON) {
  59.             return Vector3D.ZERO;
  60.         }
  61.         return thrustVector.scalarMultiply(1. / norm);
  62.     }

  63.     /** Get the thrust vector in spacecraft frame (N).
  64.      * @param s current spacecraft state
  65.      * @return thrust vector in spacecraft frame (N)
  66.      */
  67.     Vector3D getThrustVector(SpacecraftState s);

  68.     /** Get the flow rate (kg/s).
  69.      * @param s current spacecraft state
  70.      * @return flow rate (kg/s)
  71.      */
  72.     double getFlowRate(SpacecraftState s);

  73.     /** Get the thrust vector in spacecraft frame (N).
  74.      * @param s current spacecraft state
  75.      * @param parameters propulsion model parameters
  76.      * @return thrust vector in spacecraft frame (N)
  77.      */
  78.     Vector3D getThrustVector(SpacecraftState s, double[] parameters);

  79.     /** Get the flow rate (kg/s).
  80.      * @param s current spacecraft state
  81.      * @param parameters propulsion model parameters
  82.      * @return flow rate (kg/s)
  83.      */
  84.     double getFlowRate(SpacecraftState s, double[] parameters);

  85.     /** Get the thrust vector in spacecraft frame (N).
  86.      * @param s current spacecraft state
  87.      * @param parameters propulsion model parameters
  88.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  89.      * @return thrust vector in spacecraft frame (N)
  90.      */
  91.     <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(FieldSpacecraftState<T> s, T[] parameters);

  92.     /** Get the flow rate (kg/s).
  93.      * @param s current spacecraft state
  94.      * @param parameters propulsion model parameters
  95.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  96.      * @return flow rate (kg/s)
  97.      */
  98.     <T extends CalculusFieldElement<T>> T getFlowRate(FieldSpacecraftState<T> s, T[] parameters);

  99.     /** {@inheritDoc}
  100.      * Acceleration is computed here using the thrust vector in S/C frame.
  101.      */
  102.     @Override
  103.     default Vector3D getAcceleration(final SpacecraftState s, final Attitude maneuverAttitude,
  104.                                      final double[] parameters) {

  105.         final Vector3D thrustVector = getThrustVector(s, parameters);
  106.         final double thrustNorm = thrustVector.getNorm();
  107.         if (thrustNorm == 0) {
  108.             return Vector3D.ZERO;
  109.         }
  110.         final Vector3D direction = thrustVector.normalize();

  111.         // Compute thrust acceleration in inertial frame
  112.         // It seems under-efficient to rotate direction and apply thrust
  113.         // instead of just rotating the whole thrust vector itself.
  114.         // However it has to be done that way to avoid numerical discrepancies with legacy tests.
  115.         return new Vector3D(thrustNorm / s.getMass(),
  116.                             maneuverAttitude.getRotation().applyInverseTo(direction));
  117.     }

  118.     /** {@inheritDoc}
  119.      * Acceleration is computed here using the thrust vector in S/C frame.
  120.      */
  121.     @Override
  122.     default <T extends CalculusFieldElement<T>> FieldVector3D<T> getAcceleration(final FieldSpacecraftState<T> s,
  123.                                                                                  final FieldAttitude<T> maneuverAttitude,
  124.                                                                                  final T[] parameters) {
  125.         // Extract thrust & direction from thrust vector
  126.         final FieldVector3D<T> thrustVector = getThrustVector(s, parameters);
  127.         final T thrustNorm = thrustVector.getNorm();
  128.         if (thrustNorm.getReal() == 0) {
  129.             return maneuverAttitude.getRotation().applyInverseTo(thrustVector.scalarMultiply(s.getMass().reciprocal()));
  130.         }
  131.         final FieldVector3D<T> direction = thrustVector.normalize();

  132.         // Compute thrust acceleration in inertial frame
  133.         // It seems under-efficient to rotate direction and apply thrust
  134.         // instead of just rotating the whole thrust vector itself.
  135.         // However it has to be done that way to avoid numerical discrepancies with legacy tests.
  136.         return new FieldVector3D<>(thrustNorm.divide(s.getMass()),
  137.                         maneuverAttitude.getRotation().applyInverseTo(direction));
  138.     }

  139.     /** {@inheritDoc}
  140.      * Mass derivatives are directly extracted here from the flow rate value.
  141.      */
  142.     @Override
  143.     default double getMassDerivatives(SpacecraftState s, double[] parameters) {
  144.         return getFlowRate(s, parameters);
  145.     }

  146.     /** {@inheritDoc}
  147.      * Mass derivatives are directly extracted here from the flow rate value.
  148.      */
  149.     @Override
  150.     default <T extends CalculusFieldElement<T>> T getMassDerivatives(FieldSpacecraftState<T> s, T[] parameters) {
  151.         return getFlowRate(s, parameters);
  152.     }

  153. }