1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.models.earth;
18
19 import org.junit.jupiter.api.Assertions;
20 import org.junit.jupiter.api.Test;
21 import org.orekit.forces.gravity.potential.GravityFieldFactory;
22 import org.orekit.frames.Frame;
23 import org.orekit.frames.FramesFactory;
24 import org.orekit.utils.Constants;
25
26 import static org.hamcrest.CoreMatchers.is;
27 import static org.hamcrest.MatcherAssert.assertThat;
28 import static org.hipparchus.util.FastMath.PI;
29 import static org.hipparchus.util.FastMath.abs;
30 import static org.orekit.OrekitMatchers.relativelyCloseTo;
31
32
33
34
35
36
37
38 public class ReferenceEllipsoidTest {
39
40
41
42 @Test
43 public void testReferenceEllipsoid() {
44 double a = 1, f = 0.5, gm = 2, omega = 3;
45 ReferenceEllipsoid ellipsoid = new ReferenceEllipsoid(a, f,
46 FramesFactory.getGCRF(), gm, omega);
47 assertThat(ellipsoid.getEquatorialRadius(), is(a));
48 assertThat(ellipsoid.getFlattening(), is(f));
49 assertThat(ellipsoid.getGM(), is(gm));
50 assertThat(ellipsoid.getSpin(), is(omega));
51 }
52
53
54
55
56
57
58
59
60 private ReferenceEllipsoid getComponent() {
61
62
63
64
65 double a = 6378137.00, f = 1 / 298.257223563, GM = 3.986004418e14, spin = 7292115e-11;
66 return new ReferenceEllipsoid(a, f, FramesFactory.getGCRF(), GM, spin);
67 }
68
69
70
71
72
73 @Test
74 public void testGetNormalGravity() {
75 ReferenceEllipsoid ellipsoid = getComponent();
76
77
78 double[] lat = {-90, -45, 0, 45, 90};
79
80 double[] expected = {9.833276738917813685281,
81 9.8064684244573317502963, 9.779777598918278489352,
82 9.8064684244573317502963, 9.833276738917813685281};
83
84
85 Assertions.assertEquals(lat.length, expected.length);
86 for (int i = 0; i < expected.length; i++) {
87 assertThat(ellipsoid.getNormalGravity(lat[i] * PI / 180.),
88 relativelyCloseTo(expected[i], 1));
89 }
90 }
91
92
93 @Test
94 public void testGetC2n0() {
95 ReferenceEllipsoid ellipsoid = getComponent();
96
97
98
99
100 double expected = -0.484166774985e-3;
101
102
103 Assertions.assertEquals(
104 ellipsoid.getC2n0(1), expected, 1.31e-9,"J2 term\n");
105
106
107
108
109 double[] expecteds = {7.90304054e-7, -1.687251e-9, 3.461e-12};
110 for (int i = 0; i < expecteds.length; i++) {
111 double C2n = ellipsoid.getC2n0(2 + i);
112 expected = expecteds[i];
113
114 Assertions.assertEquals(C2n, expected, abs(2e-4 * expected), "C" + (4 + 2 * i) + ",0" + "\n");
115 }
116 }
117
118
119 @Test
120 public void testGetC2n0Bad() {
121 Assertions.assertThrows(IllegalArgumentException.class, () -> {
122 getComponent().getC2n0(0);
123 });
124 }
125
126
127 @Test
128 public void testGetPolarRadius() {
129 assertThat(getComponent().getPolarRadius(), is(6356752.314245179));
130 }
131
132
133
134
135 @Test
136 public void testGetWgs84() {
137
138 double c20factor = GravityFieldFactory.getUnnormalizationFactors(2, 0)[2][0];
139 Frame frame = FramesFactory.getGCRF();
140
141
142 ReferenceEllipsoid wgs84 = ReferenceEllipsoid.getWgs84(frame);
143
144
145 Assertions.assertEquals(
146 wgs84.getC2n0(1), Constants.WGS84_EARTH_C20 / c20factor, 3e-9);
147 assertThat(wgs84.getBodyFrame(), is(frame));
148 }
149
150
151
152
153 @Test
154 public void testGetGrs80() {
155
156 double c20factor = GravityFieldFactory.getUnnormalizationFactors(2, 0)[2][0];
157 Frame frame = FramesFactory.getGCRF();
158
159
160 ReferenceEllipsoid grs80 = ReferenceEllipsoid.getGrs80(frame);
161
162
163 Assertions.assertEquals(
164 grs80.getC2n0(1), Constants.GRS80_EARTH_C20 / c20factor, 3e-9);
165 assertThat(grs80.getBodyFrame(), is(frame));
166 }
167
168
169
170
171 @Test
172 public void testGetIers96() {
173
174 double c20factor = GravityFieldFactory.getUnnormalizationFactors(2, 0)[2][0];
175 Frame frame = FramesFactory.getGCRF();
176
177
178 ReferenceEllipsoid iers96 = ReferenceEllipsoid.getIers96(frame);
179
180
181 Assertions.assertEquals(
182 iers96.getC2n0(1), Constants.IERS96_EARTH_C20 / c20factor, 3e-9);
183 assertThat(iers96.getBodyFrame(), is(frame));
184 }
185
186
187
188
189 @Test
190 public void testGetIers2003() {
191
192 double c20factor = GravityFieldFactory.getUnnormalizationFactors(2, 0)[2][0];
193 Frame frame = FramesFactory.getGCRF();
194
195
196 ReferenceEllipsoid iers2003 = ReferenceEllipsoid.getIers2003(frame);
197
198
199 Assertions.assertEquals(
200 iers2003.getC2n0(1), Constants.IERS2003_EARTH_C20 / c20factor, 3e-9);
201 assertThat(iers2003.getBodyFrame(), is(frame));
202 }
203
204
205
206
207 @Test
208 public void testGetIers2010() {
209
210 double c20factor = GravityFieldFactory.getUnnormalizationFactors(2, 0)[2][0];
211 Frame frame = FramesFactory.getGCRF();
212
213
214 ReferenceEllipsoid iers2010 = ReferenceEllipsoid.getIers2010(frame);
215
216
217 Assertions.assertEquals(
218 iers2010.getC2n0(1), Constants.IERS2010_EARTH_C20 / c20factor, 3e-9);
219 assertThat(iers2010.getBodyFrame(), is(frame));
220 }
221
222
223 @Test
224 public void testGetEllipsoid() {
225
226 ReferenceEllipsoid ellipsoid = getComponent();
227
228
229 assertThat(ellipsoid.getEllipsoid(), is(ellipsoid));
230 }
231 }