ThrustPropulsionModel.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.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.orekit.attitudes.Attitude;
  22. import org.orekit.attitudes.FieldAttitude;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.utils.Constants;

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

  31.     /** Get the specific impulse (s).
  32.      * @param s current spacecraft state
  33.      * @return specific impulse (s).
  34.      */
  35.     default double getIsp(SpacecraftState s) {
  36.         final double thrust   = getThrust(s);
  37.         final double flowRate = getFlowRate(s);
  38.         return -thrust / (Constants.G0_STANDARD_GRAVITY * flowRate);
  39.     }

  40.     /** Get the thrust direction in spacecraft frame.
  41.      * @param s current spacecraft state
  42.      * @return thrust direction in spacecraft frame
  43.      */
  44.     default Vector3D getDirection(SpacecraftState s) {
  45.         return getThrustVector(s).normalize();
  46.     }

  47.     /** Get the thrust norm (N).
  48.      * @param s current spacecraft state
  49.      * @return thrust norm (N)
  50.      */
  51.     default double getThrust(SpacecraftState s) {
  52.         return getThrustVector(s).getNorm();
  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.         final Vector3D direction = thrustVector.normalize();

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

  107.     /** {@inheritDoc}
  108.      * Acceleration is computed here using the thrust vector in S/C frame.
  109.      */
  110.     @Override
  111.     default <T extends CalculusFieldElement<T>> FieldVector3D<T> getAcceleration(FieldSpacecraftState<T> s,
  112.                                                                             final FieldAttitude<T> maneuverAttitude,
  113.                                                                             T[] parameters) {
  114.         // Extract thrust & direction from thrust vector
  115.         final FieldVector3D<T> thrustVector = getThrustVector(s, parameters);
  116.         final T thrust = thrustVector.getNorm();
  117.         final FieldVector3D<T> direction = thrustVector.normalize();

  118.         // Compute thrust acceleration in inertial frame
  119.         // It seems under-efficient to rotate direction and apply thrust
  120.         // instead of just rotating the whole thrust vector itself.
  121.         // However it has to be done that way to avoid numerical discrepancies with legacy tests.
  122.         return new FieldVector3D<>(s.getMass().reciprocal().multiply(thrust),
  123.                         maneuverAttitude.getRotation().applyInverseTo(direction));
  124.     }

  125.     /** {@inheritDoc}
  126.      * Mass derivatives are directly extracted here from the flow rate value.
  127.      */
  128.     @Override
  129.     default double getMassDerivatives(SpacecraftState s, double[] parameters) {
  130.         return getFlowRate(s, parameters);
  131.     }

  132.     /** {@inheritDoc}
  133.      * Mass derivatives are directly extracted here from the flow rate value.
  134.      */
  135.     @Override
  136.     default <T extends CalculusFieldElement<T>> T getMassDerivatives(FieldSpacecraftState<T> s, T[] parameters) {
  137.         return getFlowRate(s, parameters);
  138.     }

  139. }