ScaledConstantThrustPropulsionModel.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 java.util.Arrays;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.utils.ParameterDriver;

  27. /** Thrust propulsion model with parameters (for estimation) represented by scale factors
  28.  *  on the X, Y and Z axis of the spacecraft frame.
  29.  * @author Maxime Journot
  30.  * @since 10.2
  31.  */
  32. public class ScaledConstantThrustPropulsionModel extends AbstractConstantThrustPropulsionModel {

  33.     /** Parameter name for the scale factor on the X component of the thrust in S/C frame. */
  34.     public static final String THRUSTX_SCALE_FACTOR = "TX scale factor";
  35.     /** Parameter name for the scale factor on the Y component of the thrust in S/C frame. */
  36.     public static final String THRUSTY_SCALE_FACTOR = "TY scale factor";
  37.     /** Parameter name for the scale factor on the Z component of the thrust in S/C frame. */
  38.     public static final String THRUSTZ_SCALE_FACTOR = "TZ scale factor";

  39.     /** Thrust scaling factor.
  40.      * <p>
  41.      * We use a power of 2 to avoid numeric noise introduction
  42.      * in the multiplications/divisions sequences.
  43.      * </p>
  44.      */
  45.     private static final double THRUST_SCALE = FastMath.scalb(1.0, -5);

  46.     /** Parameter driver for the scale factor on the X component of the thrust in S/C frame. */
  47.     private final ParameterDriver scaleFactorThrustXDriver;
  48.     /** Parameter driver for the scale factor on the Y component of the thrust in S/C frame. */
  49.     private final ParameterDriver scaleFactorThrustYDriver;
  50.     /** Parameter driver for the scale factor on the Z component of the thrust in S/C frame. */
  51.     private final ParameterDriver scaleFactorThrustZDriver;

  52.     /** Constructor with min/max deviation for the scale factors.
  53.      * Typical usage is, for example, if you know that your propulsion system
  54.      * usually has an error of less than 10% then set the min/max to respectively 0.9 and 1.1.
  55.      * @param thrust the thrust (N)
  56.      * @param isp the isp (s)
  57.      * @param direction in spacecraft frame
  58.      * @param name the name of the maneuver
  59.      */
  60.     public ScaledConstantThrustPropulsionModel(final double thrust,
  61.                                                final double isp,
  62.                                                final Vector3D direction,
  63.                                                final String name) {
  64.         super(thrust, isp, direction, name);

  65.         // Build the parameter drivers, using maneuver name as prefix
  66.         this.scaleFactorThrustXDriver   = new ParameterDriver(name + THRUSTX_SCALE_FACTOR, 1., THRUST_SCALE,
  67.                                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  68.         this.scaleFactorThrustYDriver   = new ParameterDriver(name + THRUSTY_SCALE_FACTOR, 1., THRUST_SCALE,
  69.                                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  70.         this.scaleFactorThrustZDriver   = new ParameterDriver(name + THRUSTZ_SCALE_FACTOR, 1., THRUST_SCALE,
  71.                                                               Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  72.     }

  73.     /** Get the thrust vector in S/C frame from scale factors (N).
  74.      * @param scaleFactorX thrust vector scale factor on X axis of S/C frame
  75.      * @param scaleFactorY thrust vector scale factor on Y axis of S/C frame
  76.      * @param scaleFactorZ thrust vector scale factor on Z axis of S/C frame
  77.      * @return thrust vector in S/C frame
  78.      */
  79.     private Vector3D getThrustVector(final double scaleFactorX,
  80.                                      final double scaleFactorY,
  81.                                      final double scaleFactorZ) {
  82.         return new Vector3D(getInitialThrustVector().getX() * scaleFactorX,
  83.                             getInitialThrustVector().getY() * scaleFactorY,
  84.                             getInitialThrustVector().getZ() * scaleFactorZ);
  85.     }

  86.     /** {@inheritDoc} */
  87.     @Override
  88.     public Vector3D getThrustVector() {
  89.         // scaleFactorThruster must be drivers with only 1 one value driven
  90.         return getThrustVector(scaleFactorThrustXDriver.getValue(),
  91.                                scaleFactorThrustYDriver.getValue(),
  92.                                scaleFactorThrustZDriver.getValue());
  93.     }

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public Vector3D getThrustVector(final AbsoluteDate date) {
  97.         return getThrustVector(scaleFactorThrustXDriver.getValue(date),
  98.                                scaleFactorThrustYDriver.getValue(date),
  99.                                scaleFactorThrustZDriver.getValue(date));
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public double getFlowRate() {
  104.         return getInitialFlowRate();
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public double getFlowRate(final AbsoluteDate date) {
  109.         return getInitialFlowRate();
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public List<ParameterDriver> getParametersDrivers() {
  114.         return Collections.unmodifiableList(Arrays.asList(scaleFactorThrustXDriver,
  115.                                                           scaleFactorThrustYDriver,
  116.                                                           scaleFactorThrustZDriver));
  117.     }

  118.     /** {@inheritDoc} */
  119.     @Override
  120.     public Vector3D getThrustVector(final double[] parameters) {
  121.         return getThrustVector(parameters[0], parameters[1], parameters[2]);
  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     public double getFlowRate(final double[] parameters) {
  126.         return getInitialFlowRate();
  127.     }

  128.     /** {@inheritDoc} */
  129.     @Override
  130.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(final T[] parameters) {
  131.         return new FieldVector3D<>(parameters[0].multiply(getInitialThrustVector().getX()),
  132.                         parameters[1].multiply(getInitialThrustVector().getY()),
  133.                         parameters[2].multiply(getInitialThrustVector().getZ()));
  134.     }

  135.     /** {@inheritDoc} */
  136.     @Override
  137.     public <T extends CalculusFieldElement<T>> T getFlowRate(final T[] parameters) {
  138.         return parameters[0].getField().getZero().newInstance(getInitialFlowRate());
  139.     }
  140. }