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.hipparchus.util.FastMath;
20 import org.hipparchus.util.SinCos;
21 import org.orekit.time.AbsoluteDate;
22 import org.orekit.utils.TimeSpanMap;
23
24
25
26
27
28 class PiecewiseSphericalHarmonics implements RawSphericalHarmonicsProvider {
29
30
31 private final ConstantSphericalHarmonics constant;
32
33
34 private final AbsoluteDate[] references;
35
36
37 private final double[] pulsations;
38
39
40 private final TimeSpanMap<PiecewisePart> pieces;
41
42
43 private final int maxDegree;
44
45
46 private final int maxOrder;
47
48
49
50
51
52
53
54 PiecewiseSphericalHarmonics(final ConstantSphericalHarmonics constant,
55 final AbsoluteDate[] references, final double[] pulsations,
56 final TimeSpanMap<PiecewisePart> pieces) {
57 this.constant = constant;
58 this.references = references.clone();
59 this.pulsations = pulsations.clone();
60 this.pieces = pieces;
61
62
63 int d = constant.getMaxDegree();
64 int o = constant.getMaxOrder();
65 for (TimeSpanMap.Span<PiecewisePart> span = pieces.getFirstSpan(); span != null; span = span.next()) {
66 final PiecewisePart piece = span.getData();
67 if (piece != null) {
68 d = FastMath.max(d, piece.getMaxDegree());
69 o = FastMath.max(o, piece.getMaxOrder());
70 }
71 }
72 this.maxDegree = d;
73 this.maxOrder = o;
74
75 }
76
77
78
79
80 public ConstantSphericalHarmonics getConstant() {
81 return constant;
82 }
83
84
85 public int getMaxDegree() {
86 return maxDegree;
87 }
88
89
90 public int getMaxOrder() {
91 return maxOrder;
92 }
93
94
95 public double getMu() {
96 return constant.getMu();
97 }
98
99
100 public double getAe() {
101 return constant.getAe();
102 }
103
104
105 public AbsoluteDate getReferenceDate() {
106 AbsoluteDate last = AbsoluteDate.PAST_INFINITY;
107 for (final AbsoluteDate date : references) {
108 if (date.isAfter(last)) {
109 last = date;
110 }
111 }
112 return last;
113 }
114
115
116 public TideSystem getTideSystem() {
117 return constant.getTideSystem();
118 }
119
120
121
122
123
124 public RawSphericalHarmonics onDate(final AbsoluteDate date) {
125
126
127 final RawSphericalHarmonics raw = constant.onDate(date);
128
129
130 final PiecewisePart piece = pieces.get(date);
131
132
133 final double[] offsets = new double[references.length];
134 final SinCos[][] sinCos = new SinCos[references.length][pulsations.length];
135 for (int i = 0; i < references.length; ++i) {
136 final double offset = date.durationFrom(references[i]);
137 offsets[i] = offset;
138 for (int j = 0; j < pulsations.length; ++j) {
139 sinCos[i][j] = FastMath.sinCos(offset * pulsations[j]);
140 }
141 }
142
143 return new RawSphericalHarmonics() {
144
145 @Override
146 public AbsoluteDate getDate() {
147 return date;
148 }
149
150
151 public double getRawCnm(final int n, final int m) {
152 return raw.getRawCnm(n, m) + piece.computeCnm(n, m, offsets, sinCos);
153 }
154
155
156 public double getRawSnm(final int n, final int m) {
157 return raw.getRawSnm(n, m) + piece.computeSnm(n, m, offsets, sinCos);
158 }
159
160 };
161
162 }
163
164 }