AbstractConstantThrustPropulsionModel.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.orekit.forces.maneuvers.Control3DVectorCostType;
  22. import org.orekit.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.utils.Constants;

  26. /** This abstract class simply serve as a container for a constant thrust maneuver.
  27.  * It re-writes all spacecraft dependent methods from {@link ThrustPropulsionModel}
  28.  * and removes their dependencies to current spacecraft state.
  29.  * Indeed since the thrust is constant (i.e. not variable during the maneuver), most of the
  30.  * calculated parameters (thrust vector, flow rate etc.) do not depend on current spacecraft state.
  31.  * @author Maxime Journot
  32.  * @since 10.2
  33.  */
  34. public abstract class AbstractConstantThrustPropulsionModel implements ThrustPropulsionModel {

  35.     /** Default control vector cost type. */
  36.     static final Control3DVectorCostType DEFAULT_CONTROL_3D_VECTOR_COST_TYPE = Control3DVectorCostType.TWO_NORM;

  37.     /** Initial thrust vector (N) in S/C frame, when building the object. */
  38.     private final Vector3D initialThrustVector;

  39.     /** Initial flow rate (kg/s), when building the object. */
  40.     private final double initialFlowRate;

  41.     /** Type of norm linking thrust vector to mass flow rate. */
  42.     private final Control3DVectorCostType control3DVectorCostType;

  43.     /** User-defined name of the maneuver.
  44.      * This String attribute is empty by default.
  45.      * It is added as a prefix to the parameter drivers of the maneuver.
  46.      * The purpose is to differentiate between drivers in the case where several maneuvers
  47.      * were added to a propagator force model.
  48.      * Additionally, the user can retrieve the whole maneuver by looping on the force models of a propagator,
  49.      * scanning for its name.
  50.      * @since 9.2
  51.      */
  52.     private final String name;

  53.     /** Generic constructor.
  54.      * @param thrust initial thrust value (N)
  55.      * @param isp initial isp value (s)
  56.      * @param direction initial thrust direction in S/C frame
  57.      * @param control3DVectorCostType control cost type
  58.      * @param name name of the maneuver
  59.      * @since 12.0
  60.      */
  61.     public AbstractConstantThrustPropulsionModel(final double thrust,
  62.                                                  final double isp,
  63.                                                  final Vector3D direction,
  64.                                                  final Control3DVectorCostType control3DVectorCostType,
  65.                                                  final String name) {
  66.         this.name = name;
  67.         this.initialThrustVector = direction.normalize().scalarMultiply(thrust);
  68.         this.control3DVectorCostType = control3DVectorCostType;
  69.         this.initialFlowRate = -control3DVectorCostType.evaluate(initialThrustVector) / (Constants.G0_STANDARD_GRAVITY * isp);
  70.     }

  71.     /** Constructor with default control cost type.
  72.      * @param thrust initial thrust value (N)
  73.      * @param isp initial isp value (s)
  74.      * @param direction initial thrust direction in S/C frame
  75.      * @param name name of the maneuver
  76.      */
  77.     public AbstractConstantThrustPropulsionModel(final double thrust,
  78.                                                  final double isp,
  79.                                                  final Vector3D direction,
  80.                                                  final String name) {
  81.         this(thrust, isp, direction, DEFAULT_CONTROL_3D_VECTOR_COST_TYPE, name);
  82.     }

  83.     /** Get the initial thrust vector.
  84.      * @return the initial thrust vector
  85.      */
  86.     protected Vector3D getInitialThrustVector() {
  87.         return initialThrustVector;
  88.     }

  89.     /** Get the initial flow rate.
  90.      * @return the initial flow rate
  91.      */
  92.     protected double getInitialFlowRate() {
  93.         return initialFlowRate;
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     public String getName() {
  98.         return name;
  99.     }

  100.     /** {@inheritDoc} */
  101.     @Override
  102.     public Control3DVectorCostType getControl3DVectorCostType() {
  103.         return control3DVectorCostType;
  104.     }

  105.     /** Get the specific impulse.
  106.      * @return specific impulse (s), will throw exception if
  107.      * used on PDriver having several driven values, because
  108.      * in this case a date is needed.
  109.      */
  110.     public double getIsp() {
  111.         final double flowRate = getFlowRate();
  112.         return -control3DVectorCostType.evaluate(getThrustVector()) / (Constants.G0_STANDARD_GRAVITY * flowRate);
  113.     }

  114.     /** Get the specific impulse at given date.
  115.      * @param date date at which the Isp wants to be known
  116.      * @return specific impulse (s).
  117.      */
  118.     public double getIsp(final AbsoluteDate date) {
  119.         final double flowRate = getFlowRate(date);
  120.         return -control3DVectorCostType.evaluate(getThrustVector(date)) / (Constants.G0_STANDARD_GRAVITY * flowRate);
  121.     }

  122.     /** Get the thrust direction in S/C frame.
  123.      * @param date date at which the direction wants to be known
  124.      * @return the thrust direction in S/C frame
  125.      */
  126.     public Vector3D getDirection(final AbsoluteDate date) {
  127.         return getThrustVector(date).normalize();
  128.     }

  129.     /** Get the thrust direction in S/C frame.
  130.      * @return the thrust direction in S/C frame,  will throw exception if
  131.      * used on PDriver having several driven values, because
  132.      * in this case a date is needed.
  133.      */
  134.     public Vector3D getDirection() {
  135.         return getThrustVector().normalize();
  136.     }

  137.     /** Get the thrust magnitude (N).
  138.      * @return the thrust value (N), will throw
  139.      * an exception if called of a driver having several
  140.      * values driven
  141.      */
  142.     public double getThrustMagnitude() {
  143.         return getThrustVector().getNorm();
  144.     }

  145.     /** Get the thrust magnitude (N) at given date.
  146.      * @param date date at which the thrust vector wants to be known,
  147.      * often the date parameter will not be important and can be whatever
  148.      * if the thrust parameter driver as only value estimated over the all
  149.      * orbit determination interval
  150.      * @return the thrust value (N)
  151.      */
  152.     public double getThrustMagnitude(final AbsoluteDate date) {
  153.         return getThrustVector(date).getNorm();
  154.     }

  155.     /** {@inheritDoc}
  156.      * Here the thrust vector do not depend on current S/C state.
  157.      */
  158.     @Override
  159.     public Vector3D getThrustVector(final SpacecraftState s) {
  160.         // Call the abstract function that do not depend on current S/C state
  161.         return getThrustVector(s.getDate());
  162.     }

  163.     /** {@inheritDoc}
  164.      * Here the flow rate do not depend on current S/C state
  165.      */
  166.     @Override
  167.     public double getFlowRate(final SpacecraftState s) {
  168.         // Call the abstract function that do not depend on current S/C state
  169.         return getFlowRate(s.getDate());
  170.     }

  171.     /** {@inheritDoc}
  172.      * Here the thrust vector do not depend on current S/C state.
  173.      */
  174.     @Override
  175.     public Vector3D getThrustVector(final SpacecraftState s, final double[] parameters) {
  176.         // Call the abstract function that do not depend on current S/C state
  177.         return getThrustVector(parameters);
  178.     }

  179.     /** {@inheritDoc}
  180.      * Here the flow rate do not depend on current S/C state
  181.      */
  182.     public double getFlowRate(final SpacecraftState s, final double[] parameters) {
  183.         // Call the abstract function that do not depend on current S/C state
  184.         return getFlowRate(parameters);
  185.     }

  186.     /** {@inheritDoc}
  187.      * Here the thrust vector do not depend on current S/C state.
  188.      */
  189.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(final FieldSpacecraftState<T> s,
  190.                                                                             final T[] parameters) {
  191.         // Call the abstract function that do not depend on current S/C state
  192.         return getThrustVector(parameters);
  193.     }

  194.     /** {@inheritDoc}
  195.      * Here the flow rate do not depend on current S/C state
  196.      */
  197.     public <T extends CalculusFieldElement<T>> T getFlowRate(final FieldSpacecraftState<T> s, final T[] parameters) {
  198.         // Call the abstract function that do not depend on current S/C state
  199.         return getFlowRate(parameters);
  200.     }

  201.     /** Get the thrust vector in spacecraft frame (N).
  202.      * Here it does not depend on current S/C state.
  203.      * @return thrust vector in spacecraft frame (N),
  204.      * will throw an exception if used on driver
  205.      * containing several value spans
  206.      */
  207.     public abstract Vector3D getThrustVector();

  208.     /** Get the thrust vector in spacecraft frame (N).
  209.      * Here it does not depend on current S/C state.
  210.      * @param date date at which the thrust vector wants to be known,
  211.      * often the date parameter will not be important and can be whatever
  212.      * if the thrust parameter driver as only value estimated over the all
  213.      * orbit determination interval
  214.      * @return thrust vector in spacecraft frame (N)
  215.      */
  216.     public abstract Vector3D getThrustVector(AbsoluteDate date);

  217.     /** Get the flow rate (kg/s).
  218.      * Here it does not depend on current S/C.
  219.      * @return flow rate (kg/s)
  220.      * will throw an exception if used on driver
  221.      * containing several value spans
  222.      */
  223.     public abstract double getFlowRate();

  224.     /** Get the flow rate (kg/s).
  225.      * Here it does not depend on current S/C.
  226.      * @param date date at which the thrust vector wants to be known,
  227.      * often the date parameter will not be important and can be whatever
  228.      * if the thrust parameter driver as only value estimated over the all
  229.      * orbit determination interval
  230.      * @return flow rate (kg/s)
  231.      */
  232.     public abstract double getFlowRate(AbsoluteDate date);

  233.     /** Get the thrust vector in spacecraft frame (N).
  234.      * Here it does not depend on current S/C state.
  235.      * @param parameters propulsion model parameters
  236.      * @return thrust vector in spacecraft frame (N)
  237.      */
  238.     public abstract Vector3D getThrustVector(double[] parameters);

  239.     /** Get the flow rate (kg/s).
  240.      * Here it does not depend on current S/C state.
  241.      * @param parameters propulsion model parameters
  242.      * @return flow rate (kg/s)
  243.      */
  244.     public abstract double getFlowRate(double[] parameters);

  245.     /** Get the thrust vector in spacecraft frame (N).
  246.      * Here it does not depend on current S/C state.
  247.      * @param parameters propulsion model parameters
  248.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  249.      * @return thrust vector in spacecraft frame (N)
  250.      */
  251.     public abstract <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(T[] parameters);

  252.     /** Get the flow rate (kg/s).
  253.      * Here it does not depend on current S/C state.
  254.      * @param parameters propulsion model parameters
  255.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  256.      * @return flow rate (kg/s)
  257.      */
  258.     public abstract <T extends CalculusFieldElement<T>> T getFlowRate(T[] parameters);
  259. }