FieldClockOffsetHermiteInterpolator.java

  1. /* Copyright 2022-2025 Thales Alenia Space
  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.analysis.interpolation.FieldHermiteInterpolator;
  20. import org.hipparchus.analysis.interpolation.HermiteInterpolator;
  21. import org.hipparchus.util.MathArrays;

  22. import java.util.List;

  23. /**bHermite interpolator of time stamped clock offsets.
  24.  * @param <T> type of the field elements
  25.  * @author Luc Maisonobe
  26.  * @see HermiteInterpolator
  27.  * @see TimeInterpolator
  28.  * @since 12.1
  29.  */
  30. public class FieldClockOffsetHermiteInterpolator<T extends CalculusFieldElement<T>>
  31.     extends AbstractFieldTimeInterpolator<FieldClockOffset<T>, T> {

  32.     /**
  33.      * Constructor with default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s).
  34.      * <p>
  35.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  36.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  37.      * phenomenon</a> and numerical problems (including NaN appearing).
  38.      * </p>
  39.      * <p>
  40.      * If the number of interpolation points or derivatives availability is not sufficient,
  41.      * the rate and acceleration of interpolated offset will be silently set to 0 (i.e.
  42.      * model will be constant or linear only).
  43.      * </p>
  44.      * @param interpolationPoints number of interpolation points
  45.      */
  46.     public FieldClockOffsetHermiteInterpolator(final int interpolationPoints) {
  47.         this(interpolationPoints, DEFAULT_EXTRAPOLATION_THRESHOLD_SEC);
  48.     }

  49.     /**
  50.      * Constructor.
  51.      * <p>
  52.      * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
  53.      * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
  54.      * phenomenon</a> and numerical problems (including NaN appearing).
  55.      * </p>
  56.      * <p>
  57.      * If the number of interpolation points or derivatives availability is not sufficient,
  58.      * the rate and acceleration of interpolated offset will be silently set to 0 (i.e.
  59.      * model will be constant or linear only).
  60.      * </p>
  61.      * @param interpolationPoints number of interpolation points
  62.      * @param extrapolationThreshold extrapolation threshold beyond which the propagation will fail
  63.      */
  64.     public FieldClockOffsetHermiteInterpolator(final int interpolationPoints, final double extrapolationThreshold) {
  65.         super(interpolationPoints, extrapolationThreshold);
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     protected FieldClockOffset<T> interpolate(final InterpolationData interpolationData) {
  70.         final FieldHermiteInterpolator<T> interpolator = new FieldHermiteInterpolator<>();

  71.         // Fill interpolator with sample
  72.         final FieldAbsoluteDate<T>      interpolationDate = interpolationData.getInterpolationDate();
  73.         final List<FieldClockOffset<T>> neighborList      = interpolationData.getNeighborList();
  74.         for (FieldClockOffset<T> value : neighborList) {
  75.             final T   deltaT = value.getDate().durationFrom(interpolationDate);
  76.             final T[] offset = MathArrays.buildArray(interpolationDate.getField(), 1);
  77.             offset[0] = value.getOffset();
  78.             if (value.getRate() == null || value.getRate().isNaN()) {
  79.                 // no clock rate for this entry
  80.                 interpolator.addSamplePoint(deltaT, offset);
  81.             } else {
  82.                 // clock rate is available
  83.                 final T[] rate = MathArrays.buildArray(interpolationDate.getField(), 1);
  84.                 rate[0] = value.getRate();
  85.                 if (value.getAcceleration() == null || value.getAcceleration().isNaN()) {
  86.                     // no clock acceleration for this entry
  87.                     interpolator.addSamplePoint(deltaT, offset, rate);
  88.                 } else {
  89.                     // clock acceleration is available
  90.                     final T[] acceleration = MathArrays.buildArray(interpolationDate.getField(), 1);
  91.                     acceleration[0] = value.getAcceleration();
  92.                     interpolator.addSamplePoint(deltaT, offset, rate, acceleration);
  93.                 }
  94.             }
  95.         }

  96.         final T[][] y = interpolator.derivatives(interpolationDate.getField().getZero(), 2);
  97.         return new FieldClockOffset<>(interpolationDate, y[0][0], y[1][0], y[2][0]);

  98.     }

  99. }