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