PolynomialAccelerationModel.java

  1. /* Copyright 2002-2020 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.empirical;

  18. import org.hipparchus.RealFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.propagation.FieldSpacecraftState;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.utils.ParameterDriver;

  24. /** Polynomial acceleration model.
  25.  * @since 10.3
  26.  * @author Luc Maisonobe
  27.  * @author Bryan Cazabonne
  28.  */
  29. public class PolynomialAccelerationModel implements AccelerationModel {

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

  40.     /** Drivers for the polynomial coefficients. */
  41.     private final ParameterDriver[] drivers;

  42.     /** Reference date for computing polynomials. */
  43.     private AbsoluteDate referenceDate;

  44.     /** Simple constructor.
  45.      * @param prefix prefix to use for parameter drivers
  46.      * @param referenceDate reference date for computing polynomials, if null
  47.      * the reference date will be automatically set at propagation start
  48.      * @param degree polynomial degree (i.e. a value of 0 corresponds to a constant acceleration)
  49.      */
  50.     public PolynomialAccelerationModel(final String prefix,
  51.                                         final AbsoluteDate referenceDate,
  52.                                         final int degree) {
  53.         // Reference date
  54.         this.referenceDate = referenceDate;
  55.         // Parameter drivers
  56.         this.drivers       = new ParameterDriver[degree + 1];
  57.         for (int i = 0; i < drivers.length; ++i) {
  58.             drivers[i] = new ParameterDriver(prefix + "[" + i + "]", 0.0, ACCELERATION_SCALE,
  59.                                              Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
  60.         }
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public void init(final SpacecraftState initialState, final AbsoluteDate target) {
  65.         if (referenceDate == null) {
  66.             referenceDate = initialState.getDate();
  67.         }
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public double signedAmplitude(final SpacecraftState state,
  72.                                   final double[] parameters) {
  73.         final double dt = state.getDate().durationFrom(referenceDate);
  74.         double amplitude = 0;
  75.         for (int i = parameters.length - 1; i >= 0; --i) {
  76.             amplitude += amplitude * dt + parameters[i];
  77.         }
  78.         return amplitude;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public <T extends RealFieldElement<T>> T signedAmplitude(final FieldSpacecraftState<T> state,
  83.                                                              final T[] parameters) {
  84.         final T dt = state.getDate().durationFrom(referenceDate);
  85.         T amplitude = dt.getField().getZero();
  86.         for (int i = parameters.length - 1; i >= 0; --i) {
  87.             amplitude = amplitude.add(amplitude.multiply(dt).add(parameters[i]));
  88.         }
  89.         return amplitude;
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public ParameterDriver[] getParametersDrivers() {
  94.         return drivers.clone();
  95.     }

  96. }