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  
19  import org.hipparchus.analysis.interpolation.HermiteInterpolator;
20  
21  import java.util.List;
22  
23  /**bHermite interpolator of time stamped clock offsets.
24   * @author Luc Maisonobe
25   * @see HermiteInterpolator
26   * @see TimeInterpolator
27   * @since 12.1
28   */
29  public class ClockOffsetHermiteInterpolator extends AbstractTimeInterpolator<ClockOffset> {
30  
31      /**
32       * Constructor with default extrapolation threshold value ({@code DEFAULT_EXTRAPOLATION_THRESHOLD_SEC} s).
33       * <p>
34       * As this implementation of interpolation is polynomial, it should be used only with small number of interpolation
35       * points (about 10-20 points) in order to avoid <a href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's
36       * phenomenon</a> and numerical problems (including NaN appearing).
37       * </p>
38       * <p>
39       * If the number of interpolation points or derivatives availability is not sufficient,
40       * the rate and acceleration of interpolated offset will be silently set to 0 (i.e.
41       * model will be constant or linear only).
42       * </p>
43       * @param interpolationPoints number of interpolation points
44       */
45      public ClockOffsetHermiteInterpolator(final int interpolationPoints) {
46          this(interpolationPoints, DEFAULT_EXTRAPOLATION_THRESHOLD_SEC);
47      }
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 ClockOffsetHermiteInterpolator(final int interpolationPoints, final double extrapolationThreshold) {
65          super(interpolationPoints, extrapolationThreshold);
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      protected ClockOffset interpolate(final InterpolationData interpolationData) {
71          final HermiteInterpolator interpolator = new HermiteInterpolator();
72  
73          // Fill interpolator with sample
74          final AbsoluteDate                         interpolationDate = interpolationData.getInterpolationDate();
75          final List<ClockOffset> neighborList      = interpolationData.getNeighborList();
76          for (ClockOffset value : neighborList) {
77              final double deltaT = value.getDate().durationFrom(interpolationDate);
78              final double[] offset = new double[] { value.getOffset() };
79              if (Double.isNaN(value.getRate())) {
80                  // no clock rate for this entry
81                  interpolator.addSamplePoint(deltaT, offset);
82              } else {
83                  // clock rate is available
84                  final double[] rate = new double[] { value.getRate() };
85                  if (Double.isNaN(value.getAcceleration())) {
86                      // no clock acceleration for this entry
87                      interpolator.addSamplePoint(deltaT, offset, rate);
88                  } else {
89                      // clock acceleration is available
90                      final double[] acceleration = new double[] { value.getAcceleration() };
91                      interpolator.addSamplePoint(deltaT, offset, rate, acceleration);
92                  }
93              }
94          }
95  
96          final double[][] y = interpolator.derivatives(0, 2);
97          return new ClockOffset(interpolationDate, y[0][0], y[1][0], y[2][0]);
98  
99      }
100 
101 }