ClockOffsetHermiteInterpolator.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.analysis.interpolation.HermiteInterpolator;

  19. import java.util.List;

  20. /**bHermite interpolator of time stamped clock offsets.
  21.  * @author Luc Maisonobe
  22.  * @see HermiteInterpolator
  23.  * @see TimeInterpolator
  24.  * @since 12.1
  25.  */
  26. public class ClockOffsetHermiteInterpolator extends AbstractTimeInterpolator<ClockOffset> {

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

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

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     protected ClockOffset interpolate(final InterpolationData interpolationData) {
  65.         final HermiteInterpolator interpolator = new HermiteInterpolator();

  66.         // Fill interpolator with sample
  67.         final AbsoluteDate                         interpolationDate = interpolationData.getInterpolationDate();
  68.         final List<ClockOffset> neighborList      = interpolationData.getNeighborList();
  69.         for (ClockOffset value : neighborList) {
  70.             final double deltaT = value.getDate().durationFrom(interpolationDate);
  71.             final double[] offset = new double[] { value.getOffset() };
  72.             if (Double.isNaN(value.getRate())) {
  73.                 // no clock rate for this entry
  74.                 interpolator.addSamplePoint(deltaT, offset);
  75.             } else {
  76.                 // clock rate is available
  77.                 final double[] rate = new double[] { value.getRate() };
  78.                 if (Double.isNaN(value.getAcceleration())) {
  79.                     // no clock acceleration for this entry
  80.                     interpolator.addSamplePoint(deltaT, offset, rate);
  81.                 } else {
  82.                     // clock acceleration is available
  83.                     final double[] acceleration = new double[] { value.getAcceleration() };
  84.                     interpolator.addSamplePoint(deltaT, offset, rate, acceleration);
  85.                 }
  86.             }
  87.         }

  88.         final double[][] y = interpolator.derivatives(0, 2);
  89.         return new ClockOffset(interpolationDate, y[0][0], y[1][0], y[2][0]);

  90.     }

  91. }