ScaledConstantThrustPropulsionModel.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 java.util.ArrayList;
  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.utils.ParameterDriver;

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

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

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

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

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

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

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

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public Vector3D getThrustVector() {
  88.         return getThrustVector(scaleFactorThrustXDriver.getValue(),
  89.                                scaleFactorThrustYDriver.getValue(),
  90.                                scaleFactorThrustZDriver.getValue());
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public double getFlowRate() {
  95.         return getInitialFlowrate();
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public List<ParameterDriver> getParametersDrivers() {
  100.         final List<ParameterDriver> drivers = new ArrayList<>(3);
  101.         drivers.add(scaleFactorThrustXDriver);
  102.         drivers.add(scaleFactorThrustYDriver);
  103.         drivers.add(scaleFactorThrustZDriver);
  104.         return Collections.unmodifiableList(drivers);
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public Vector3D getThrustVector(final double parameters[]) {
  109.         return getThrustVector(parameters[0], parameters[1], parameters[2]);
  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public double getFlowRate(final double[] parameters) {
  114.         return getInitialFlowrate();
  115.     }

  116.     /** {@inheritDoc} */
  117.     @Override
  118.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(final T parameters[]) {
  119.         return new FieldVector3D<T>(parameters[0].multiply(getInitialThrustVector().getX()),
  120.                         parameters[1].multiply(getInitialThrustVector().getY()),
  121.                         parameters[2].multiply(getInitialThrustVector().getZ()));
  122.     }

  123.     /** {@inheritDoc} */
  124.     @Override
  125.     public <T extends CalculusFieldElement<T>> T getFlowRate(final T[] parameters) {
  126.         return parameters[0].getField().getZero().add(getInitialFlowrate());
  127.     }
  128. }