ThrustPropulsionModel.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.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.     /** Get the specific impulse (s).
  33.      * @param s current spacecraft state
  34.      * @return specific impulse (s).
  35.      */
  36.     default double getIsp(SpacecraftState s) {
  37.         final double flowRate = getFlowRate(s);
  38.         return -getControl3DVectorCostType().evaluate(getThrustVector(s)) / (Constants.G0_STANDARD_GRAVITY * flowRate);
  39.     }

  40.     /** Get the thrust direction in spacecraft frame.
  41.      * <p>
  42.      * Return a zero vector if there is no thrust for given spacecraft state.
  43.      * @param s current spacecraft state
  44.      * @return thrust direction in spacecraft frame
  45.      */
  46.     default Vector3D getDirection(SpacecraftState s) {
  47.         final Vector3D thrustVector = getThrustVector(s);
  48.         final double   norm         = thrustVector.getNorm();
  49.         if (norm <= Precision.EPSILON) {
  50.             return Vector3D.ZERO;
  51.         }
  52.         return thrustVector.scalarMultiply(1. / norm);
  53.     }

  54.     /** Get the thrust vector in spacecraft frame (N).
  55.      * @param s current spacecraft state
  56.      * @return thrust vector in spacecraft frame (N)
  57.      */
  58.     Vector3D getThrustVector(SpacecraftState s);

  59.     /** Get the flow rate (kg/s).
  60.      * @param s current spacecraft state
  61.      * @return flow rate (kg/s)
  62.      */
  63.     double getFlowRate(SpacecraftState s);

  64.     /** Get the thrust vector in spacecraft frame (N).
  65.      * @param s current spacecraft state
  66.      * @param parameters propulsion model parameters
  67.      * @return thrust vector in spacecraft frame (N)
  68.      */
  69.     Vector3D getThrustVector(SpacecraftState s, double[] parameters);

  70.     /** Get the flow rate (kg/s).
  71.      * @param s current spacecraft state
  72.      * @param parameters propulsion model parameters
  73.      * @return flow rate (kg/s)
  74.      */
  75.     double getFlowRate(SpacecraftState s, double[] parameters);

  76.     /** Get the thrust vector in spacecraft frame (N).
  77.      * @param s current spacecraft state
  78.      * @param parameters propulsion model parameters
  79.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  80.      * @return thrust vector in spacecraft frame (N)
  81.      */
  82.     <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(FieldSpacecraftState<T> s, T[] parameters);

  83.     /** Get the flow rate (kg/s).
  84.      * @param s current spacecraft state
  85.      * @param parameters propulsion model parameters
  86.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  87.      * @return flow rate (kg/s)
  88.      */
  89.     <T extends CalculusFieldElement<T>> T getFlowRate(FieldSpacecraftState<T> s, T[] parameters);

  90.     /** {@inheritDoc}
  91.      * Acceleration is computed here using the thrust vector in S/C frame.
  92.      */
  93.     @Override
  94.     default Vector3D getAcceleration(SpacecraftState s,
  95.                                     final Attitude maneuverAttitude,
  96.                                     double[] parameters) {

  97.         final Vector3D thrustVector = getThrustVector(s, parameters);
  98.         final double thrust = thrustVector.getNorm();
  99.         if (thrust == 0) {
  100.             return Vector3D.ZERO;
  101.         }
  102.         final Vector3D direction = thrustVector.normalize();

  103.         // Compute thrust acceleration in inertial frame
  104.         // It seems under-efficient to rotate direction and apply thrust
  105.         // instead of just rotating the whole thrust vector itself.
  106.         // However it has to be done that way to avoid numerical discrepancies with legacy tests.
  107.         return new Vector3D(thrust / s.getMass(),
  108.                             maneuverAttitude.getRotation().applyInverseTo(direction));
  109.     }

  110.     /** {@inheritDoc}
  111.      * Acceleration is computed here using the thrust vector in S/C frame.
  112.      */
  113.     @Override
  114.     default <T extends CalculusFieldElement<T>> FieldVector3D<T> getAcceleration(FieldSpacecraftState<T> s,
  115.                                                                             final FieldAttitude<T> maneuverAttitude,
  116.                                                                             T[] parameters) {
  117.         // Extract thrust & direction from thrust vector
  118.         final FieldVector3D<T> thrustVector = getThrustVector(s, parameters);
  119.         final T thrust = thrustVector.getNorm();
  120.         if (thrust.isZero()) {
  121.             return FieldVector3D.getZero(s.getDate().getField());
  122.         }
  123.         final FieldVector3D<T> direction = thrustVector.normalize();

  124.         // Compute thrust acceleration in inertial frame
  125.         // It seems under-efficient to rotate direction and apply thrust
  126.         // instead of just rotating the whole thrust vector itself.
  127.         // However it has to be done that way to avoid numerical discrepancies with legacy tests.
  128.         return new FieldVector3D<>(thrust.divide(s.getMass()),
  129.                         maneuverAttitude.getRotation().applyInverseTo(direction));
  130.     }

  131.     /** {@inheritDoc}
  132.      * Mass derivatives are directly extracted here from the flow rate value.
  133.      */
  134.     @Override
  135.     default double getMassDerivatives(SpacecraftState s, double[] parameters) {
  136.         return getFlowRate(s, parameters);
  137.     }

  138.     /** {@inheritDoc}
  139.      * Mass derivatives are directly extracted here from the flow rate value.
  140.      */
  141.     @Override
  142.     default <T extends CalculusFieldElement<T>> T getMassDerivatives(FieldSpacecraftState<T> s, T[] parameters) {
  143.         return getFlowRate(s, parameters);
  144.     }

  145. }