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  
18  package org.orekit.forces.maneuvers.propulsion;
19  
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.hipparchus.CalculusFieldElement;
25  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
26  import org.hipparchus.geometry.euclidean.threed.Vector3D;
27  import org.hipparchus.util.FastMath;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.utils.ParameterDriver;
30  
31  /** Thrust propulsion model with parameters (for estimation) represented by scale factors
32   *  on the X, Y and Z axis of the spacecraft frame.
33   * @author Maxime Journot
34   * @since 10.2
35   */
36  public class ScaledConstantThrustPropulsionModel extends AbstractConstantThrustPropulsionModel {
37  
38      /** Parameter name for the scale factor on the X component of the thrust in S/C frame. */
39      public static final String THRUSTX_SCALE_FACTOR = "TX scale factor";
40      /** Parameter name for the scale factor on the Y component of the thrust in S/C frame. */
41      public static final String THRUSTY_SCALE_FACTOR = "TY scale factor";
42      /** Parameter name for the scale factor on the Z component of the thrust in S/C frame. */
43      public static final String THRUSTZ_SCALE_FACTOR = "TZ scale factor";
44  
45      /** Thrust scaling factor.
46       * <p>
47       * We use a power of 2 to avoid numeric noise introduction
48       * in the multiplications/divisions sequences.
49       * </p>
50       */
51      private static final double THRUST_SCALE = FastMath.scalb(1.0, -5);
52  
53      /** Parameter driver for the scale factor on the X component of the thrust in S/C frame. */
54      private final ParameterDriver scaleFactorThrustXDriver;
55      /** Parameter driver for the scale factor on the Y component of the thrust in S/C frame. */
56      private final ParameterDriver scaleFactorThrustYDriver;
57      /** Parameter driver for the scale factor on the Z component of the thrust in S/C frame. */
58      private final ParameterDriver scaleFactorThrustZDriver;
59  
60      /** Constructor with min/max deviation for the scale factors.
61       * Typical usage is, for example, if you know that your propulsion system
62       * usually has an error of less than 10% then set the min/max to respectively 0.9 and 1.1.
63       * @param thrust the thrust (N)
64       * @param isp the isp (s)
65       * @param direction in spacecraft frame
66       * @param name the name of the maneuver
67       */
68      public ScaledConstantThrustPropulsionModel(final double thrust,
69                                                 final double isp,
70                                                 final Vector3D direction,
71                                                 final String name) {
72          super(thrust, isp, direction, name);
73  
74          // Build the parameter drivers, using maneuver name as prefix
75          this.scaleFactorThrustXDriver   = new ParameterDriver(name + THRUSTX_SCALE_FACTOR, 1., THRUST_SCALE,
76                                                                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
77          this.scaleFactorThrustYDriver   = new ParameterDriver(name + THRUSTY_SCALE_FACTOR, 1., THRUST_SCALE,
78                                                                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
79          this.scaleFactorThrustZDriver   = new ParameterDriver(name + THRUSTZ_SCALE_FACTOR, 1., THRUST_SCALE,
80                                                                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
81      }
82  
83      /** Get the thrust vector in S/C frame from scale factors (N).
84       * @param scaleFactorX thrust vector scale factor on X axis of S/C frame
85       * @param scaleFactorY thrust vector scale factor on Y axis of S/C frame
86       * @param scaleFactorZ thrust vector scale factor on Z axis of S/C frame
87       * @return thrust vector in S/C frame
88       */
89      private Vector3D getThrustVector(final double scaleFactorX,
90                                       final double scaleFactorY,
91                                       final double scaleFactorZ) {
92          return new Vector3D(getInitialThrustVector().getX() * scaleFactorX,
93                              getInitialThrustVector().getY() * scaleFactorY,
94                              getInitialThrustVector().getZ() * scaleFactorZ);
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public Vector3D getThrustVector() {
100         // scaleFactorThruster must be drivers with only 1 one value driven
101         return getThrustVector(scaleFactorThrustXDriver.getValue(),
102                                scaleFactorThrustYDriver.getValue(),
103                                scaleFactorThrustZDriver.getValue());
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public Vector3D getThrustVector(final AbsoluteDate date) {
109         return getThrustVector(scaleFactorThrustXDriver.getValue(date),
110                                scaleFactorThrustYDriver.getValue(date),
111                                scaleFactorThrustZDriver.getValue(date));
112     }
113 
114     /** {@inheritDoc} */
115     @Override
116     public double getFlowRate() {
117         return getInitialFlowRate();
118     }
119 
120     /** {@inheritDoc} */
121     @Override
122     public double getFlowRate(final AbsoluteDate date) {
123         return getInitialFlowRate();
124     }
125 
126     /** {@inheritDoc} */
127     @Override
128     public List<ParameterDriver> getParametersDrivers() {
129         return Collections.unmodifiableList(Arrays.asList(scaleFactorThrustXDriver,
130                                                           scaleFactorThrustYDriver,
131                                                           scaleFactorThrustZDriver));
132     }
133 
134     /** {@inheritDoc} */
135     @Override
136     public Vector3D getThrustVector(final double[] parameters) {
137         return getThrustVector(parameters[0], parameters[1], parameters[2]);
138     }
139 
140     /** {@inheritDoc} */
141     @Override
142     public double getFlowRate(final double[] parameters) {
143         return getInitialFlowRate();
144     }
145 
146     /** {@inheritDoc} */
147     @Override
148     public <T extends CalculusFieldElement<T>> FieldVector3D<T> getThrustVector(final T[] parameters) {
149         return new FieldVector3D<>(parameters[0].multiply(getInitialThrustVector().getX()),
150                         parameters[1].multiply(getInitialThrustVector().getY()),
151                         parameters[2].multiply(getInitialThrustVector().getZ()));
152     }
153 
154     /** {@inheritDoc} */
155     @Override
156     public <T extends CalculusFieldElement<T>> T getFlowRate(final T[] parameters) {
157         return parameters[0].getField().getZero().newInstance(getInitialFlowRate());
158     }
159 }