PolynomialAccelerationModel.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.empirical;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.hipparchus.CalculusFieldElement;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.utils.ParameterDriver;

  27. /** Polynomial acceleration model.
  28.  * @since 10.3
  29.  * @author Luc Maisonobe
  30.  * @author Bryan Cazabonne
  31.  */
  32. public class PolynomialAccelerationModel implements AccelerationModel {

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

  43.     /** Drivers for the polynomial coefficients. */
  44.     private final List<ParameterDriver> drivers;

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

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

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

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

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

  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public List<ParameterDriver> getParametersDrivers() {
  97.         return Collections.unmodifiableList(drivers);
  98.     }

  99. }