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 java.util.Collections;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.function.DoubleFunction;
23  
24  import org.hipparchus.CalculusFieldElement;
25  import org.hipparchus.analysis.differentiation.Gradient;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.utils.ImmutableTimeStampedCache;
28  import org.orekit.utils.drivers.ParameterDriver;
29  
30  /** Offset clock model backed up by a sample.
31   *
32   * @author Luc Maisonobe
33   * @since 12.1
34   */
35  public class SampledClockModel implements ClockModel {
36  
37      /** sample. */
38      private final ImmutableTimeStampedCache<ClockOffset> sample;
39  
40      /** Simple constructor.
41       * @param sample                clock offsets sample
42       * @param nbInterpolationPoints number of points to use in interpolation
43       */
44      public SampledClockModel(final List<ClockOffset> sample, final int nbInterpolationPoints) {
45          this.sample = new ImmutableTimeStampedCache<>(nbInterpolationPoints, sample);
46      }
47  
48      /** Get the clock offsets cache.
49       * @return clock offsets cache
50       */
51      public ImmutableTimeStampedCache<ClockOffset> getCache() {
52          return sample;
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public AbsoluteDate getValidityStart() {
58          return sample.getEarliest().getDate();
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public AbsoluteDate getValidityEnd() {
64          return sample.getLatest().getDate();
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public ClockOffset getOffset(final AbsoluteDate date) {
70          return new ClockOffsetHermiteInterpolator(sample.getMaxNeighborsSize()).
71              interpolate(date, sample.getNeighbors(date));
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public <T extends CalculusFieldElement<T>> SampledFieldClockModel<T> toField(final DoubleFunction<T> converter) {
77          return new SampledFieldClockModel<>(sample.toField(c -> c.toField(converter)).getAll(),
78                                              sample.getMaxNeighborsSize());
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public SampledFieldClockModel<Gradient> toGradient(final int freeParameters, final Map<String, Integer> indices) {
84          return toField(v -> Gradient.constant(freeParameters, v));
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public List<ParameterDriver> getParametersDrivers() {
90          return Collections.emptyList();
91      }
92  
93  }