1   /* Copyright 2011-2012 Space Applications Services
2    * Licensed to CS Communication & Systèmes (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.models.earth.troposphere;
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.hipparchus.util.Precision;
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.BeforeAll;
26  import org.junit.jupiter.api.Test;
27  import org.orekit.Utils;
28  import org.orekit.bodies.FieldGeodeticPoint;
29  import org.orekit.bodies.GeodeticPoint;
30  import org.orekit.models.earth.weather.PressureTemperatureHumidityProvider;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.time.FieldAbsoluteDate;
33  import org.orekit.utils.FieldTrackingCoordinates;
34  import org.orekit.utils.TrackingCoordinates;
35  
36  public class FixedTroposphericModelTest extends AbstractPathDelayTest<FixedTroposphericDelay> {
37  
38      private static final double epsilon = 1e-6;
39  
40      @Override
41      protected FixedTroposphericDelay buildTroposphericModel(final PressureTemperatureHumidityProvider provider) {
42          return FixedTroposphericDelay.getDefaultModel();
43      }
44  
45      @Test
46      @Override
47      public void testDelay() {
48          doTestDelay(defaultDate, defaultPoint, defaultTrackingCoordinates, null,
49                      2.1298, 0.0, 3.4346, 0.0, 3.4346);
50      }
51  
52      @Test
53      @Override
54      public void testFieldDelay() {
55          doTestDelay(Binary64Field.getInstance(),
56                      defaultDate, defaultPoint, defaultTrackingCoordinates, null,
57                      2.1298, 0.0, 3.4346, 0.0, 3.4346);
58      }
59  
60      @Override
61      @Test
62      public void testFixedHeight() {
63          doTestFixedHeight(null);
64      }
65  
66      @Override
67      @Test
68      public void testFieldFixedHeight() {
69          doTestFieldFixedHeight(Binary64Field.getInstance(), null);
70      }
71  
72      @Override
73      @Test
74      public void testFixedElevation() {
75          doTestFixedElevation(null);
76      }
77  
78      @Override
79      @Test
80      public void testFieldFixedElevation() {
81          doTestFieldFixedElevation(Binary64Field.getInstance(), null);
82      }
83  
84      @Test
85      public void testModel() {
86          final FixedTroposphericDelay model = buildTroposphericModel(null);
87          // check with (artificial) test values from tropospheric-delay.txt
88          Assertions.assertEquals(2.4,
89                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90.0), 0.0),
90                                                  new GeodeticPoint(0., 0., 0.),
91                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
92                                  epsilon);
93          Assertions.assertEquals(27.4,
94                                  model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(0.0), 0.0),
95                                                  new GeodeticPoint(0., 0., 0.),
96                                                  null, AbsoluteDate.J2000_EPOCH).getDelay(),
97                                  epsilon);
98  
99          Assertions.assertEquals(14.3,
100                                 model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(0.0), 0.0),
101                                                 new GeodeticPoint(0., 0., 5000.),
102                                                 null, AbsoluteDate.J2000_EPOCH).getDelay(),
103                                 epsilon);
104         Assertions.assertEquals(1.2,
105                                 model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90.0), 0.0),
106                                                 new GeodeticPoint(0., 0., 5000.),
107                                                 null, AbsoluteDate.J2000_EPOCH).getDelay(),
108                                 epsilon);
109 
110         // interpolation between two elevation angles in the table
111         final double delay = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(35.0), 0.0),
112                                              new GeodeticPoint(0., 0., 1200.),
113                                              null, AbsoluteDate.J2000_EPOCH).getDelay();
114         Assertions.assertTrue(Precision.compareTo(delay, 6.4, epsilon) < 0);
115         Assertions.assertTrue(Precision.compareTo(delay, 3.2, epsilon) > 0);
116 
117         // sanity checks
118         Assertions.assertEquals(14.3,
119                                 model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(-20.0), 0.0),
120                                                 new GeodeticPoint(0., 0., 5000.),
121                                                 null, AbsoluteDate.J2000_EPOCH).getDelay(),
122                                 epsilon);
123         Assertions.assertEquals(1.2,
124                                 model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(90.0),0.0),
125                                                 new GeodeticPoint(0., 0., 100000.),
126                                                 null, AbsoluteDate.J2000_EPOCH).getDelay(),
127                                 epsilon);
128     }
129 
130     @Test
131     public void testFieldModel() {
132         doTestFieldModel(Binary64Field.getInstance());
133     }
134 
135     private <T extends CalculusFieldElement<T>> void doTestFieldModel(final Field<T> field) {
136         final FixedTroposphericDelay model = buildTroposphericModel(null);
137         final T zero = field.getZero();
138         // check with (artificial) test values from tropospheric-delay.txt
139         Assertions.assertEquals(2.4,
140                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90.0)), zero),
141                                                 new FieldGeodeticPoint<>(zero, zero, zero),
142                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
143                                 epsilon);
144         Assertions.assertEquals(27.4,
145                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(0.0)), zero),
146                                                 new FieldGeodeticPoint<>(zero, zero, zero),
147                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
148                                 epsilon);
149 
150         Assertions.assertEquals(14.3,
151                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(0.0)), zero),
152                                                 new FieldGeodeticPoint<>(zero, zero, zero.add(5000.0)),
153                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
154                                 epsilon);
155         Assertions.assertEquals(1.2,
156                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90.0)), zero),
157                                                 new FieldGeodeticPoint<>(zero, zero, zero.add(5000.0)),
158                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
159                                 epsilon);
160 
161         // interpolation between two elevation angles in the table
162         final double delay = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(35.0)), zero),
163                                              new FieldGeodeticPoint<>(zero, zero, zero.add(1200.0)),
164                                              null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal();
165         Assertions.assertTrue(Precision.compareTo(delay, 6.4, epsilon) < 0);
166         Assertions.assertTrue(Precision.compareTo(delay, 3.2, epsilon) > 0);
167 
168         // sanity checks
169         Assertions.assertEquals(14.3,
170                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(-20.0)), zero),
171                                                 new FieldGeodeticPoint<>(zero, zero, zero.add(5000.0)),
172                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
173                                 epsilon);
174         Assertions.assertEquals(1.2,
175                                 model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(90.0)), zero),
176                                                 new FieldGeodeticPoint<>(zero, zero, zero.add(100000.0)),
177                                                 null, FieldAbsoluteDate.getJ2000Epoch(field)).getDelay().getReal(),
178                                 epsilon);
179     }
180 
181     @Test
182     public void testSymmetry() {
183         final FixedTroposphericDelay model = buildTroposphericModel(null);
184         for (int elevation = 0; elevation < 90; elevation += 10) {
185             final double delay1 = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(elevation), 0.0),
186                                                   new GeodeticPoint(0., 0., 100.),
187                                                   null, AbsoluteDate.J2000_EPOCH).getDelay();
188             final double delay2 = model.pathDelay(new TrackingCoordinates(0.0, FastMath.toRadians(180 - elevation), 0.0),
189                                                   new GeodeticPoint(0., 0., 100.),
190                                                   null, AbsoluteDate.J2000_EPOCH).getDelay();
191 
192             Assertions.assertEquals(delay1, delay2, epsilon);
193         }
194     }
195 
196     @Test
197     public void testFieldSymmetry() {
198         doTestFieldSymmetry(Binary64Field.getInstance());
199     }
200 
201     private <T extends CalculusFieldElement<T>> void doTestFieldSymmetry(final Field<T> field) {
202         final FixedTroposphericDelay model = buildTroposphericModel(null);
203         final T zero = field.getZero();
204         for (int elevation = 0; elevation < 90; elevation += 10) {
205             final T delay1 = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(elevation)), zero),
206                                              new FieldGeodeticPoint<>(zero, zero, zero.add(100.)),
207                                              null,
208                                              FieldAbsoluteDate.getJ2000Epoch(field)).getDelay();
209             final T delay2 = model.pathDelay(new FieldTrackingCoordinates<>(zero, zero.newInstance(FastMath.toRadians(180 - elevation)), zero),
210                                              new FieldGeodeticPoint<>(zero, zero, zero.add(100.)),
211                                              null,
212                                              FieldAbsoluteDate.getJ2000Epoch(field)).getDelay();
213 
214             Assertions.assertEquals(delay1.getReal(), delay2.getReal(), epsilon);
215         }
216     }
217 
218     @BeforeAll
219     public static void setUpGlobal() {
220         Utils.setDataRoot("atmosphere");
221     }
222 
223 }