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  
20  import org.hipparchus.Field;
21  import org.hipparchus.CalculusFieldElement;
22  import org.hipparchus.util.Decimal64Field;
23  import org.hipparchus.util.FastMath;
24  import org.hipparchus.util.Precision;
25  import org.junit.Assert;
26  import org.junit.Before;
27  import org.junit.BeforeClass;
28  import org.junit.Test;
29  import org.orekit.Utils;
30  import org.orekit.bodies.FieldGeodeticPoint;
31  import org.orekit.bodies.GeodeticPoint;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.FieldAbsoluteDate;
34  
35  public class MariniMurrayModelTest {
36  
37      private static double epsilon = 1e-6;
38  
39      private DiscreteTroposphericModel model;
40  
41      private double latitude;
42  
43      private double longitude;
44  
45      @BeforeClass
46      public static void setUpGlobal() {
47          Utils.setDataRoot("atmosphere");
48      }
49  
50      @Before
51      public void setUp() throws Exception {
52          // ruby laser with wavelength 694.3 nm
53          model = MariniMurrayModel.getStandardModel(694.3);
54          latitude = FastMath.toRadians(45.0);
55          longitude = FastMath.toRadians(45.0);
56      }
57  
58      @Test
59      public void testDelay() {
60          final double elevation = 10d;
61          final double height = 100d;
62  
63          final double path = model.pathDelay(FastMath.toRadians(elevation), new GeodeticPoint(latitude, longitude, height), null, AbsoluteDate.J2000_EPOCH);
64  
65          Assert.assertTrue(Precision.compareTo(path, 20d, epsilon) < 0);
66          Assert.assertTrue(Precision.compareTo(path, 0d, epsilon) > 0);
67      }
68  
69      @Test
70      public void testFieldDelay() {
71          doTestFieldDelay(Decimal64Field.getInstance());
72      }
73  
74      private <T extends CalculusFieldElement<T>> void doTestFieldDelay(final Field<T> field) {
75          final T zero = field.getZero();
76          final T elevation = zero.add(FastMath.toRadians(10d));
77          final T height = zero.add(100d);
78  
79          final T path = model.pathDelay(elevation, new FieldGeodeticPoint<>(zero.add(latitude), zero.add(longitude), height), null, FieldAbsoluteDate.getJ2000Epoch(field));
80  
81          Assert.assertTrue(Precision.compareTo(path.getReal(), 20d, epsilon) < 0);
82          Assert.assertTrue(Precision.compareTo(path.getReal(), 0d, epsilon) > 0);
83      }
84  
85      @Test
86      public void testFixedHeight() {
87          double lastDelay = Double.MAX_VALUE;
88          // delay shall decline with increasing elevation angle
89          for (double elev = 10d; elev < 90d; elev += 8d) {
90              final double delay = model.pathDelay(FastMath.toRadians(elev), new GeodeticPoint(latitude, longitude, 350.0), null, AbsoluteDate.J2000_EPOCH);
91              Assert.assertTrue(Precision.compareTo(delay, lastDelay, epsilon) < 0);
92              lastDelay = delay;
93          }
94      }
95  
96      @Test
97      public void testFieldFixedHeight() {
98          doTestFieldFixedHeight(Decimal64Field.getInstance());
99      }
100 
101     private <T extends CalculusFieldElement<T>> void doTestFieldFixedHeight(final Field<T> field) {
102         final T zero = field.getZero();
103         T lastDelay  = zero.add(Double.MAX_VALUE);
104         // delay shall decline with increasing elevation angle
105         for (double elev = 10d; elev < 90d; elev += 8d) {
106             final T delay = model.pathDelay(zero.add(FastMath.toRadians(elev)), new FieldGeodeticPoint<>(zero.add(latitude), zero.add(longitude), zero.add(350.0)), null, FieldAbsoluteDate.getJ2000Epoch(field));
107             Assert.assertTrue(Precision.compareTo(delay.getReal(), lastDelay.getReal(), epsilon) < 0);
108             lastDelay = delay;
109         }
110     }
111 
112     @Test
113     public void compareExpectedValues() {
114 
115         double height = 0;
116         double elevation = 10;
117         double expectedValue = 13.26069;
118         double actualValue = model.pathDelay(FastMath.toRadians(elevation), new GeodeticPoint(latitude, longitude, height), null, AbsoluteDate.J2000_EPOCH);
119 
120         Assert.assertEquals(expectedValue, actualValue, 1.0e-5);
121     }
122 
123     @Test
124     public void compareFieldExpectedValue() {
125         doCompareFieldExpectedValues(Decimal64Field.getInstance());
126     }
127 
128     private <T extends CalculusFieldElement<T>> void doCompareFieldExpectedValues(final Field<T> field) {
129 
130         T zero = field.getZero();
131         T height = zero;
132         T elevation = zero.add(FastMath.toRadians(10));
133         double expectedValue = 13.26069;
134         T actualValue = model.pathDelay(elevation, new FieldGeodeticPoint<>(zero.add(latitude), zero.add(longitude), height), null, FieldAbsoluteDate.getJ2000Epoch(field));
135 
136         Assert.assertEquals(expectedValue, actualValue.getReal(), 1.0e-5);
137     }
138 
139 }