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.estimation.measurements;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.util.Binary64Field;
22  import org.hipparchus.util.FastMath;
23  import org.junit.jupiter.api.Assertions;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  
29  public class QuadraticFieldClockModelTest {
30  
31      @Test
32      public void testValueField() {
33          doTestValueField(Binary64Field.getInstance());
34      }
35  
36      @Test
37      public void testRateField() {
38          doTestRateField(Binary64Field.getInstance());
39      }
40  
41      private <T extends CalculusFieldElement<T>> void doTestValueField(final Field<T> field) {
42          final FieldAbsoluteDate<T> t0 = new FieldAbsoluteDate<>(field, AbsoluteDate.GALILEO_EPOCH);
43          final QuadraticFieldClockModel<T> clock =
44                          new QuadraticFieldClockModel<>(t0,
45                                                         field.getZero().newInstance(FastMath.scalb(1.0,  -8)),
46                                                         field.getZero().newInstance(FastMath.scalb(1.0,  -9)),
47                                                         field.getZero().newInstance(FastMath.scalb(1.0, -10)));
48          Assertions.assertEquals(1.00 / 256.0, clock.getOffset(t0).getOffset().getReal(),                1.0e-15);
49          Assertions.assertEquals(1.75 / 256.0, clock.getOffset(t0.shiftedBy(1.0)).getOffset().getReal(), 1.0e-15);
50          Assertions.assertEquals(3.00 / 256.0, clock.getOffset(t0.shiftedBy(2.0)).getOffset().getReal(), 1.0e-15);
51      }
52  
53      private <T extends CalculusFieldElement<T>> void doTestRateField(final Field<T> field) {
54          final FieldAbsoluteDate<T> t0 = new FieldAbsoluteDate<>(field, AbsoluteDate.GALILEO_EPOCH);
55          final QuadraticFieldClockModel<T> clock =
56                          new QuadraticFieldClockModel<>(t0,
57                                                         field.getZero().newInstance(FastMath.scalb(1.0,  -8)),
58                                                         field.getZero().newInstance(FastMath.scalb(1.0,  -9)),
59                                                         field.getZero().newInstance(FastMath.scalb(1.0, -10)));
60          Assertions.assertEquals(1.00 / 512, clock.getOffset(t0).getRate().getReal(),                1.0e-15);
61          Assertions.assertEquals(2.00 / 512, clock.getOffset(t0.shiftedBy(1.0)).getRate().getReal(), 1.0e-15);
62          Assertions.assertEquals(3.00 / 512, clock.getOffset(t0.shiftedBy(2.0)).getRate().getReal(), 1.0e-15);
63      }
64  
65  }