1   /* Copyright 2022-2025 Luc Maisonobe
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.propagation.analytical.gnss.data;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.time.FieldAbsoluteDate;
23  
24  import java.util.function.Function;
25  
26  /**
27   * Base class for GNSS navigation messages.
28   * @param <T> type of the field elements
29   * @param <O> type of the orbital elements (non-field version)
30   * @author Luc Maisonobe
31   * @since 13.0
32   *
33   * @see FieldGPSLegacyNavigationMessage
34   * @see FieldGalileoNavigationMessage
35   * @see FieldBeidouLegacyNavigationMessage
36   * @see FieldQZSSLegacyNavigationMessage
37   * @see FieldNavicLegacyNavigationMessage
38   */
39  public abstract class FieldAbstractNavigationMessage<T extends CalculusFieldElement<T>,
40                                                       O extends AbstractNavigationMessage<O>>
41      extends FieldAbstractAlmanac<T, O> {
42  
43      /** Mean Motion Difference from Computed Value. */
44      private T deltaN0;
45  
46      /** Time of clock epoch. */
47      private FieldAbsoluteDate<T> epochToc;
48  
49      /** Transmission time. */
50      private T transmissionTime;
51  
52      /** Constructor from non-field instance.
53       * @param field    field to which elements belong
54       * @param original regular non-field instance
55       */
56      protected FieldAbstractNavigationMessage(final Field<T> field, final O original) {
57          super(field, original);
58          setDeltaN0(field.getZero().newInstance(original.getDeltaN0()));
59          setEpochToc(new FieldAbsoluteDate<>(field, original.getEpochToc()));
60          setTransmissionTime(field.getZero().newInstance(original.getTransmissionTime()));
61      }
62  
63      /** Constructor from different field instance.
64       * @param <V> type of the old field elements
65       * @param original regular non-field instance
66       * @param converter for field elements
67       */
68      protected <V extends CalculusFieldElement<V>> FieldAbstractNavigationMessage(final Function<V, T> converter,
69                                                                                   final FieldAbstractNavigationMessage<V, O> original) {
70          super(converter, original);
71          setDeltaN0(converter.apply(original.getDeltaN0()));
72          setEpochToc(new FieldAbsoluteDate<>(getMu().getField(), original.getEpochToc().toAbsoluteDate()));
73          setTransmissionTime(converter.apply(original.getTransmissionTime()));
74      }
75  
76      /**
77       * Getter for Square Root of Semi-Major Axis (√m).
78       * @return Square Root of Semi-Major Axis (√m)
79       */
80      public T getSqrtA() {
81          return FastMath.sqrt(getSma());
82      }
83  
84      /**
85       * Setter for the Square Root of Semi-Major Axis (√m).
86       * <p>
87       * In addition, this method set the value of the Semi-Major Axis.
88       * </p>
89       * @param sqrtA the Square Root of Semi-Major Axis (√m)
90       */
91      public void setSqrtA(final T sqrtA) {
92          setSma(sqrtA.square());
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public T getDeltaN0() {
98          return deltaN0;
99      }
100 
101     /**
102      * Setter for the delta of satellite mean motion.
103      * @param deltaN0 the value to set
104      */
105     public void setDeltaN0(final T deltaN0) {
106         this.deltaN0 = deltaN0;
107     }
108 
109     /**
110      * Getter for the time of clock epoch.
111      * @return the time of clock epoch
112      */
113     public FieldAbsoluteDate<T> getEpochToc() {
114         return epochToc;
115     }
116 
117     /**
118      * Setter for the time of clock epoch.
119      * @param epochToc the epoch to set
120      */
121     public void setEpochToc(final FieldAbsoluteDate<T> epochToc) {
122         this.epochToc = epochToc;
123     }
124 
125     /**
126      * Getter for transmission time.
127      * @return transmission time
128      */
129     public T getTransmissionTime() {
130         return transmissionTime;
131     }
132 
133     /**
134      * Setter for transmission time.
135      * @param transmissionTime transmission time
136      */
137     public void setTransmissionTime(final T transmissionTime) {
138         this.transmissionTime = transmissionTime;
139     }
140 
141 }