TimeStampedFieldHermiteInterpolator.java

  1. /* Copyright 2002-2025 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.time;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.analysis.interpolation.FieldHermiteInterpolator;
  21. import org.hipparchus.util.MathArrays;

  22. import java.util.List;

  23. /**
  24.  * Hermite interpolator of time stamped field value.
  25.  * <p>
  26.  * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation points
  27.  * (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
  28.  * and numerical problems (including NaN appearing).
  29.  *
  30.  * @author Vincent Cucchietti
  31.  * @see FieldHermiteInterpolator
  32.  * @see FieldTimeInterpolator
  33.  * @param <KK> type of the field elements
  34.  */
  35. public class TimeStampedFieldHermiteInterpolator<KK extends CalculusFieldElement<KK>>
  36.         extends AbstractFieldTimeInterpolator<TimeStampedField<KK>, KK> {

  37.     /**
  38.      * Constructor with :
  39.      * <ul>
  40.      *     <li>Default number of interpolation points of {@code DEFAULT_INTERPOLATION_POINTS}</li>
  41.      *     <li>Default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s)</li>
  42.      * </ul>
  43.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  44.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  45.      * phenomenon</a> and numerical problems (including NaN appearing).
  46.      */
  47.     public TimeStampedFieldHermiteInterpolator() {
  48.         this(DEFAULT_INTERPOLATION_POINTS);
  49.     }

  50.     /**
  51.      * Constructor with :
  52.      * <ul>
  53.      *     <li>Default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s)</li>
  54.      * </ul>
  55.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  56.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  57.      * phenomenon</a> and numerical problems (including NaN appearing).
  58.      *
  59.      * @param interpolationPoints number of interpolation points
  60.      */
  61.     public TimeStampedFieldHermiteInterpolator(final int interpolationPoints) {
  62.         this(interpolationPoints, DEFAULT_EXTRAPOLATION_THRESHOLD_SEC);
  63.     }

  64.     /**
  65.      * Constructor.
  66.      * <p>
  67.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  68.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  69.      * phenomenon</a> and numerical problems (including NaN appearing).
  70.      *
  71.      * @param interpolationPoints number of interpolation points
  72.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  73.      */
  74.     public TimeStampedFieldHermiteInterpolator(final int interpolationPoints, final double extrapolationThreshold) {
  75.         super(interpolationPoints, extrapolationThreshold);
  76.     }

  77.     /**
  78.      * {@inheritDoc}
  79.      * <p>
  80.      * As this implementation of interpolation is polynomial, it should be used only with small samples (about 10-20 points)
  81.      * in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a> and numerical
  82.      * problems (including NaN appearing).
  83.      */
  84.     @Override
  85.     protected TimeStampedField<KK> interpolate(final InterpolationData interpolationData) {
  86.         final FieldHermiteInterpolator<KK> interpolator = new FieldHermiteInterpolator<>();

  87.         // Fill interpolator with sample
  88.         final Field<KK>                  field             = interpolationData.getField();
  89.         final KK                         zero              = interpolationData.getZero();
  90.         final FieldAbsoluteDate<KK>      interpolationDate = interpolationData.getInterpolationDate();
  91.         final List<TimeStampedField<KK>> neighborList      = interpolationData.getNeighborList();
  92.         for (TimeStampedField<KK> value : neighborList) {
  93.             final KK   deltaT    = value.getDate().durationFrom(interpolationDate);
  94.             final KK[] tempArray = MathArrays.buildArray(field, 1);
  95.             tempArray[0] = value.getValue();
  96.             interpolator.addSamplePoint(deltaT, tempArray);
  97.         }

  98.         return new TimeStampedField<>(interpolator.value(zero)[0], interpolationDate);
  99.     }
  100. }