1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.forces.gravity.potential;
18
19 import org.junit.Assert;
20 import org.hipparchus.util.Precision;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider.NormalizedSphericalHarmonics;
24 import org.orekit.time.AbsoluteDate;
25 import org.orekit.utils.Constants;
26
27
28 public class CachedNormalizedSphericalHarmonicsProviderTest {
29
30
31 private static final AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
32 private NormalizedSphericalHarmonicsProvider raw;
33 private static final double step = 60 * 60, slotSpan = Constants.JULIAN_DAY, newSlotInterval = Constants.JULIAN_DAY;
34 private static final int interpolationPoints = 3, maxSlots = 100;
35 private CachedNormalizedSphericalHarmonicsProvider cache;
36
37 @Before
38 public void setUp() {
39 raw = new QuadraticProvider(date);
40 cache = new CachedNormalizedSphericalHarmonicsProvider(raw, step, interpolationPoints, maxSlots, slotSpan, newSlotInterval);
41 }
42
43 @Deprecated
44 @Test
45 public void testGetReferenceDate() {
46 AbsoluteDate actualDate = cache.getReferenceDate();
47 Assert.assertEquals(actualDate, date);
48 }
49
50 @Test
51 public void testLimits() {
52 Assert.assertEquals(2, cache.getMaxDegree());
53 Assert.assertEquals(2, cache.getMaxOrder());
54 }
55
56 @Test
57 public void testBody() {
58 Assert.assertEquals(1, cache.getMu(), 1.0e-15);
59 Assert.assertEquals(1, cache.getAe(), 1.0e-15);
60 }
61
62 @Test
63 public void testGetTideSystem() {
64 TideSystem actualSystem = cache.getTideSystem();
65 Assert.assertEquals(actualSystem, TideSystem.UNKNOWN);
66 }
67
68 @Deprecated
69 @Test
70 public void testGetOffset() {
71 final double epsilon = 1e-12;
72 AbsoluteDate offsetDate = AbsoluteDate.GALILEO_EPOCH;
73 double targetOffset = offsetDate.durationFrom(date);
74 double actualOffset = cache.getOffset(offsetDate);
75
76 Assert.assertEquals(targetOffset, actualOffset, epsilon);
77 }
78
79 @Test
80 public void testInterpolation() {
81
82
83 cache.onDate(date);
84
85 AbsoluteDate sampleDate = date.shiftedBy(step / 2.0);
86
87 NormalizedSphericalHarmonics expected = raw.onDate(sampleDate);
88
89
90 NormalizedSphericalHarmonics actual = cache.onDate(sampleDate);
91
92
93 double tol = Precision.EPSILON;
94 for (int n = 0; n < raw.getMaxDegree(); n++) {
95 for (int m = 0; m < n; m++) {
96 Assert.assertEquals(expected.getNormalizedCnm(n, m), actual.getNormalizedCnm(n, m), tol);
97 Assert.assertEquals(expected.getNormalizedSnm(n, m), actual.getNormalizedSnm(n, m), tol);
98 }
99 }
100 }
101
102 @Test
103 public void testReverseEntryGeneration() {
104
105
106 cache.onDate(date);
107
108 AbsoluteDate sampleDate = date.shiftedBy(-step * 3);
109 NormalizedSphericalHarmonics expected = raw.onDate(sampleDate);
110
111
112 NormalizedSphericalHarmonics actual = cache.onDate(sampleDate);
113
114
115 double tol = Precision.EPSILON;
116 for (int n = 0; n < raw.getMaxDegree(); n++) {
117 for (int m = 0; m < n; m++) {
118 Assert.assertEquals(expected.getNormalizedCnm(n, m), actual.getNormalizedCnm(n, m), tol);
119 Assert.assertEquals(expected.getNormalizedSnm(n, m), actual.getNormalizedSnm(n, m), tol);
120 }
121 }
122 }
123
124 private static class QuadraticProvider implements NormalizedSphericalHarmonicsProvider {
125
126 private final AbsoluteDate date;
127
128 private QuadraticProvider(AbsoluteDate date) {
129 this.date = date;
130 }
131
132 @Override
133 public NormalizedSphericalHarmonics onDate(final AbsoluteDate date) {
134 final double t = date.durationFrom(this.date);
135 return new NormalizedSphericalHarmonics() {
136 @Override
137 public double getNormalizedCnm(int n, int m) {
138 return n + m + t * t;
139 }
140
141 @Override
142 public double getNormalizedSnm(int n, int m) {
143 return n + m + t * t + 1;
144 }
145
146 @Override
147 public AbsoluteDate getDate() {
148 return date;
149 }
150 };
151 }
152
153 @Override
154 public int getMaxDegree() {
155 return 2;
156 }
157
158 @Override
159 public int getMaxOrder() {
160 return 2;
161 }
162
163 @Override
164 public double getMu() {
165 return 1;
166 }
167
168 @Override
169 public double getAe() {
170 return 1;
171 }
172
173 @Override
174 public AbsoluteDate getReferenceDate() {
175 return date;
176 }
177
178 @Override
179 public double getOffset(AbsoluteDate date) {
180 return date.durationFrom(this.date);
181 }
182
183 @Override
184 public TideSystem getTideSystem() {
185 return TideSystem.UNKNOWN;
186 }
187
188 }
189 }