PolynomialParametricAcceleration.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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;

  18. import org.hipparchus.RealFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.attitudes.AttitudeProvider;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitInternalError;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.ParameterDriver;

  28. /** This class implements a {@link AbstractParametricAcceleration parametric acceleration}
  29.  * with polynomial signed amplitude.
  30.  * @since 9.0
  31.  * @author Luc Maisonobe
  32.  */
  33. public class PolynomialParametricAcceleration extends AbstractParametricAcceleration {

  34.     /** Acceleration scaling factor.
  35.      * <p>
  36.      * 2⁻²⁰ is the order of magnitude of third body perturbing acceleration.
  37.      * </p>
  38.      * <p>
  39.      * We use a power of 2 to avoid numeric noise introduction
  40.      * in the multiplications/divisions sequences.
  41.      * </p>
  42.      */
  43.     private static final double ACCELERATION_SCALE = FastMath.scalb(1.0, -20);

  44.     /** Drivers for the polynomial coefficients. */
  45.     private final ParameterDriver[] drivers;

  46.     /** Reference date for computing polynomials. */
  47.     private AbsoluteDate referenceDate;

  48.     /** Simple constructor.
  49.      * <p>
  50.      * The signed amplitude of the acceleration is ∑pₙ(t-t₀)ⁿ, where
  51.      * pₙ is parameter {@code n}, t is current date and t₀ is reference date.
  52.      * The value t-t₀ is in seconds.
  53.      * </p>
  54.      * <p>
  55.      * The {@code degree + 1} parameters for this model are the polynomial
  56.      * coefficients in increasing degree order. Their reference values (used
  57.      * also as the initial values) are all set to 0. User can change them before
  58.      * starting the propagation (or orbit determination) by calling {@link
  59.      * #getParametersDrivers()} and {@link ParameterDriver#setValue(double)}.
  60.      * </p>
  61.      * @param direction acceleration direction in defining frame
  62.      * @param isInertial if true, direction is defined in the same inertial
  63.      * frame used for propagation (i.e. {@link SpacecraftState#getFrame()}),
  64.      * otherwise direction is defined in spacecraft frame (i.e. using the
  65.      * propagation {@link
  66.      * org.orekit.propagation.Propagator#setAttitudeProvider(AttitudeProvider)
  67.      * attitude law})
  68.      * @param prefix prefix to use for parameter drivers
  69.      * @param referenceDate reference date for computing polynomials, if null
  70.      * the reference date will be automatically set at propagation start
  71.      * @param degree polynomial degree (i.e. a value of 0 corresponds to a constant acceleration)
  72.      */
  73.     public PolynomialParametricAcceleration(final Vector3D direction, final boolean isInertial,
  74.                                             final String prefix, final AbsoluteDate referenceDate,
  75.                                             final int degree) {
  76.         this(direction, isInertial, null, prefix, referenceDate, degree);
  77.     }

  78.     /** Simple constructor.
  79.      * <p>
  80.      * The signed amplitude of the acceleration is ∑pₙ(t-t₀)ⁿ, where
  81.      * pₙ is parameter {@code n}, t is current date and t₀ is reference date.
  82.      * The value t-t₀ is in seconds.
  83.      * </p>
  84.      * <p>
  85.      * The {@code degree + 1} parameters for this model are the polynomial
  86.      * coefficients in increasing degree order. Their reference values (used
  87.      * also as the initial values) are all set to 0. User can change them before
  88.      * starting the propagation (or orbit determination) by calling {@link
  89.      * #getParametersDrivers()} and {@link ParameterDriver#setValue(double)}.
  90.      * </p>
  91.      * @param direction acceleration direction in overridden spacecraft frame
  92.      * @param attitudeOverride provider for attitude used to compute acceleration
  93.      * direction
  94.      * @param prefix prefix to use for parameter drivers
  95.      * @param referenceDate reference date for computing polynomials, if null
  96.      * the reference date will be automatically set at propagation start
  97.      * @param degree polynomial degree (i.e. a value of 0 corresponds to a constant acceleration)
  98.      */
  99.     public PolynomialParametricAcceleration(final Vector3D direction, final AttitudeProvider attitudeOverride,
  100.                                             final String prefix, final AbsoluteDate referenceDate,
  101.                                             final int degree) {
  102.         this(direction, false, attitudeOverride, prefix, referenceDate, degree);
  103.     }

  104.     /** Simple constructor.
  105.      * @param direction acceleration direction in overridden spacecraft frame
  106.      * @param isInertial if true, direction is defined in the same inertial
  107.      * frame used for propagation (i.e. {@link SpacecraftState#getFrame()}),
  108.      * otherwise direction is defined in spacecraft frame (i.e. using the
  109.      * propagation {@link
  110.      * org.orekit.propagation.Propagator#setAttitudeProvider(AttitudeProvider)
  111.      * attitude law})
  112.      * @param attitudeOverride provider for attitude used to compute acceleration
  113.      * direction
  114.      * @param prefix prefix to use for parameter drivers
  115.      * @param referenceDate reference date for computing polynomials, if null
  116.      * the reference date will be automatically set at propagation start
  117.      * @param degree polynomial degree (i.e. a value of 0 corresponds to a constant acceleration)
  118.      */
  119.     private PolynomialParametricAcceleration(final Vector3D direction, final boolean isInertial,
  120.                                              final AttitudeProvider attitudeOverride,
  121.                                              final String prefix, final AbsoluteDate referenceDate,
  122.                                              final int degree) {
  123.         super(direction, isInertial, attitudeOverride);
  124.         this.referenceDate = referenceDate;
  125.         this.drivers       = new ParameterDriver[degree + 1];
  126.         try {
  127.             for (int i = 0; i < drivers.length; ++i) {
  128.                 drivers[i] = new ParameterDriver(prefix + "[" + i + "]", 0.0, ACCELERATION_SCALE,
  129.                                                  Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  130.             }
  131.         } catch (OrekitException oe) {
  132.             // this should never happen as scale is hard-coded
  133.             throw new OrekitInternalError(oe);
  134.         }
  135.     }

  136.     /** {@inheritDoc} */
  137.     @Override
  138.     public boolean dependsOnPositionOnly() {
  139.         return isInertial();
  140.     }

  141.     /** {@inheritDoc} */
  142.     @Override
  143.     public void init(final SpacecraftState initialState, final AbsoluteDate target)
  144.         throws OrekitException {
  145.         if (referenceDate == null) {
  146.             referenceDate = initialState.getDate();
  147.         }
  148.     }

  149.     /** {@inheritDoc} */
  150.     @Override
  151.     protected double signedAmplitude(final SpacecraftState state, final double[] parameters) {
  152.         final double dt = state.getDate().durationFrom(referenceDate);
  153.         double amplitude = 0;
  154.         for (int i = parameters.length - 1; i >= 0; --i) {
  155.             amplitude += amplitude * dt + parameters[i];
  156.         }
  157.         return amplitude;
  158.     }

  159.     /** {@inheritDoc} */
  160.     @Override
  161.     protected <T extends RealFieldElement<T>> T signedAmplitude(final FieldSpacecraftState<T> state, final T[] parameters) {
  162.         final T dt = state.getDate().durationFrom(referenceDate);
  163.         T amplitude = dt.getField().getZero();
  164.         for (int i = parameters.length - 1; i >= 0; --i) {
  165.             amplitude = amplitude.add(amplitude.multiply(dt).add(parameters[i]));
  166.         }
  167.         return amplitude;
  168.     }

  169.     /** {@inheritDoc} */
  170.     @Override
  171.     public ParameterDriver[] getParametersDrivers() {
  172.         return drivers.clone();
  173.     }

  174. }