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.BeforeEach;
27  import org.junit.jupiter.api.Test;
28  import org.orekit.Utils;
29  import org.orekit.bodies.FieldGeodeticPoint;
30  import org.orekit.bodies.GeodeticPoint;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.time.FieldAbsoluteDate;
33  
34  public class FixedTroposphericModelTest {
35  
36      private static double epsilon = 1e-6;
37  
38      private DiscreteTroposphericModel model;
39  
40      @Test
41      public void testModel() {
42          // check with (artificial) test values from tropospheric-delay.txt
43          Assertions.assertEquals(2.5d, model.pathDelay(FastMath.toRadians(90d), new GeodeticPoint(0., 0., 0.), null, AbsoluteDate.J2000_EPOCH), epsilon);
44          Assertions.assertEquals(20.8d, model.pathDelay(FastMath.toRadians(0d), new GeodeticPoint(0., 0., 0.), null, AbsoluteDate.J2000_EPOCH), epsilon);
45  
46          Assertions.assertEquals(12.1d, model.pathDelay(FastMath.toRadians(0d), new GeodeticPoint(0., 0., 5000.), null, AbsoluteDate.J2000_EPOCH), epsilon);
47          Assertions.assertEquals(2.5d, model.pathDelay(FastMath.toRadians(90d), new GeodeticPoint(0., 0., 5000.), null, AbsoluteDate.J2000_EPOCH), epsilon);
48  
49          // interpolation between two elevation angles in the table
50          final double delay = model.pathDelay(FastMath.toRadians(35d), new GeodeticPoint(0., 0., 1200.), null, AbsoluteDate.J2000_EPOCH);
51          Assertions.assertTrue(Precision.compareTo(delay, 6.4d, epsilon) < 0);
52          Assertions.assertTrue(Precision.compareTo(delay, 3.2d, epsilon) > 0);
53  
54          // sanity checks
55          Assertions.assertEquals(12.1d, model.pathDelay(FastMath.toRadians(-20d), new GeodeticPoint(0., 0., 5000.), null, AbsoluteDate.J2000_EPOCH), epsilon);
56          Assertions.assertEquals(2.5d, model.pathDelay(FastMath.toRadians(90d), new GeodeticPoint(0., 0., 100000.), null, AbsoluteDate.J2000_EPOCH), epsilon);
57      }
58  
59      @Test
60      public void testFieldModel() {
61          doTestFieldModel(Binary64Field.getInstance());
62      }
63  
64      private <T extends CalculusFieldElement<T>> void doTestFieldModel(final Field<T> field) {
65          final T zero = field.getZero();
66          // check with (artificial) test values from tropospheric-delay.txt
67          Assertions.assertEquals(2.5d, model.pathDelay(zero.add(FastMath.toRadians(90d)), new FieldGeodeticPoint<T>(zero, zero, zero), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
68          Assertions.assertEquals(20.8d, model.pathDelay(zero.add(FastMath.toRadians(0d)), new FieldGeodeticPoint<T>(zero, zero, zero), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
69  
70          Assertions.assertEquals(12.1d, model.pathDelay(zero.add(FastMath.toRadians(0d)), new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
71          Assertions.assertEquals(2.5d, model.pathDelay(zero.add(FastMath.toRadians(90d)), new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
72  
73          // interpolation between two elevation angles in the table
74          final double delay = model.pathDelay(zero.add(FastMath.toRadians(35d)), new FieldGeodeticPoint<T>(zero, zero, zero.add(1200.0)), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal();
75          Assertions.assertTrue(Precision.compareTo(delay, 6.4d, epsilon) < 0);
76          Assertions.assertTrue(Precision.compareTo(delay, 3.2d, epsilon) > 0);
77  
78          // sanity checks
79          Assertions.assertEquals(12.1d, model.pathDelay(zero.add(FastMath.toRadians(-20d)), new FieldGeodeticPoint<T>(zero, zero, zero.add(5000.0)), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
80          Assertions.assertEquals(2.5d, model.pathDelay(zero.add(FastMath.toRadians(90d)), new FieldGeodeticPoint<T>(zero, zero, zero.add(100000.0)), null, FieldAbsoluteDate.getJ2000Epoch(field)).getReal(), epsilon);
81      }
82  
83      @Test
84      public void testSymmetry() {
85          for (int elevation = 0; elevation < 90; elevation += 10) {
86              final double delay1 = model.pathDelay(FastMath.toRadians(elevation), new GeodeticPoint(0., 0., 100.), null, AbsoluteDate.J2000_EPOCH);
87              final double delay2 = model.pathDelay(FastMath.toRadians(180 - elevation), new GeodeticPoint(0., 0., 100.), null, AbsoluteDate.J2000_EPOCH);
88  
89              Assertions.assertEquals(delay1, delay2, epsilon);
90          }
91      }
92  
93      @Test
94      public void testFieldSymmetry() {
95          doTestFieldSymmetry(Binary64Field.getInstance());
96      }
97  
98      private <T extends CalculusFieldElement<T>> void doTestFieldSymmetry(final Field<T> field) {
99          final T zero = field.getZero();
100         for (int elevation = 0; elevation < 90; elevation += 10) {
101             final T delay1 = model.pathDelay(zero.add(FastMath.toRadians(elevation)),
102                                              new FieldGeodeticPoint<T>(zero, zero, zero.add(100.)),
103                                              null,
104                                              FieldAbsoluteDate.getJ2000Epoch(field));
105             final T delay2 = model.pathDelay(zero.add(FastMath.toRadians(180 - elevation)),
106                                              new FieldGeodeticPoint<T>(zero, zero, zero.add(100.)),
107                                              null,
108                                              FieldAbsoluteDate.getJ2000Epoch(field));
109 
110             Assertions.assertEquals(delay1.getReal(), delay2.getReal(), epsilon);
111         }
112     }
113 
114     @BeforeAll
115     public static void setUpGlobal() {
116         Utils.setDataRoot("atmosphere");
117     }
118 
119     @BeforeEach
120     public void setUp() throws Exception {
121         model = FixedTroposphericDelay.getDefaultModel();
122     }
123 }