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.hipparchus.util.FastMath;
27  import org.orekit.time.AbsoluteDate;
28  import org.orekit.time.TimeInterval;
29  import org.orekit.utils.drivers.ParameterDriver;
30  
31  /**
32   * Clock model for a clock with constant offset.
33   *
34   * @author Luc Maisonobe
35   * @since 14.0
36   */
37  public class ConstantClockModel implements ClockModel {
38  
39      /** Constant offset. */
40      private final ParameterDriver offset;
41  
42      /**
43       * Simple constructor.
44       *
45       * @param offset constant offset
46       */
47      public ConstantClockModel(final double offset) {
48          this.offset = new ParameterDriver("a0", 0.0, FastMath.scalb(1.0, -10),
49                                            Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
50                                            TimeInterval.UNLIMITED);
51          this.offset.setValue(offset);
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public AbsoluteDate getValidityStart() {
57          return offset.getValidity().getStartDate();
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public AbsoluteDate getValidityEnd() {
63          return offset.getValidity().getEndDate();
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public List<ParameterDriver> getParametersDrivers() {
69          return Collections.singletonList(offset);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public ClockOffset getOffset(final AbsoluteDate date) {
75          return new ClockOffset(date, offset.getValue(), 0, 0);
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public <T extends CalculusFieldElement<T>> ConstantFieldClockModel<T> toField(final DoubleFunction<T> converter) {
81          return new ConstantFieldClockModel<>(converter.apply(offset.getValue()));
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public ConstantFieldClockModel<Gradient> toGradient(final int freeParameters, final Map<String, Integer> indices) {
87          return toField(v -> Gradient.constant(freeParameters, v));
88      }
89  
90  }