1 /* Copyright 2002-2022 CS GROUP
2 * Licensed to CS GROUP (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.forces.gravity.potential;
18
19 import org.hipparchus.util.FastMath;
20 import org.orekit.time.AbsoluteDate;
21
22 /** Simple implementation of {@link RawSphericalHarmonicsProvider} for constant gravity fields.
23 * @author Luc Maisonobe
24 * @since 6.0
25 */
26 class ConstantSphericalHarmonics implements RawSphericalHarmonicsProvider {
27
28 /** Central body reference radius. */
29 private final double ae;
30
31 /** Central body attraction coefficient. */
32 private final double mu;
33
34 /** Tide system. */
35 private final TideSystem tideSystem;
36
37 /** Converter from triangular to flatten array.
38 * @since 11.1
39 */
40 private final Flattener flattener;
41
42 /** Raw tesseral-sectorial coefficients matrix. */
43 private final double[] rawC;
44
45 /** Raw tesseral-sectorial coefficients matrix. */
46 private final double[] rawS;
47
48 /** Simple constructor.
49 * @param ae central body reference radius
50 * @param mu central body attraction coefficient
51 * @param tideSystem tide system
52 * @param rawC raw tesseral-sectorial coefficients
53 * @param rawS raw tesseral-sectorial coefficients
54 * @deprecated as of 11.1, replaced by {@link #ConstantSphericalHarmonics(double,
55 * double, TideSystem, Flattener, double[], double[])}
56 */
57 @Deprecated
58 ConstantSphericalHarmonics(final double ae, final double mu,
59 final TideSystem tideSystem,
60 final double[][] rawC, final double[][] rawS) {
61 this(ae, mu, tideSystem, buildFlattener(rawC),
62 buildFlattener(rawC).flatten(rawC), buildFlattener(rawS).flatten(rawS));
63 }
64
65 /** Simple constructor.
66 * @param ae central body reference radius
67 * @param mu central body attraction coefficient
68 * @param tideSystem tide system
69 * @param flattener flattener from triangular to flatten array
70 * @param rawC raw tesseral-sectorial coefficients
71 * @param rawS raw tesseral-sectorial coefficients
72 * @since 11.1
73 */
74 ConstantSphericalHarmonics(final double ae, final double mu, final TideSystem tideSystem,
75 final Flattener flattener, final double[] rawC, final double[] rawS) {
76 this.ae = ae;
77 this.mu = mu;
78 this.tideSystem = tideSystem;
79 this.flattener = flattener;
80 this.rawC = rawC;
81 this.rawS = rawS;
82 }
83
84 /** Create a constant provider by freezing a regular provider.
85 * @param freezingDate freezing date
86 * @param raw raw provider to freeze
87 * @since 11.1
88 */
89 ConstantSphericalHarmonics(final AbsoluteDate freezingDate, final RawSphericalHarmonicsProvider raw) {
90
91 this.ae = raw.getAe();
92 this.mu = raw.getMu();
93 this.tideSystem = raw.getTideSystem();
94 this.flattener = new Flattener(raw.getMaxDegree(), raw.getMaxOrder());
95 this.rawC = new double[flattener.arraySize()];
96 this.rawS = new double[flattener.arraySize()];
97
98 // freeze the raw provider
99 final RawSphericalHarmonics frozen = raw.onDate(freezingDate);
100 for (int n = 0; n <= flattener.getDegree(); ++n) {
101 for (int m = 0; m <= FastMath.min(n, flattener.getOrder()); ++m) {
102 final int index = flattener.index(n, m);
103 rawC[index] = frozen.getRawCnm(n, m);
104 rawS[index] = frozen.getRawSnm(n, m);
105 }
106 }
107
108 }
109
110 /** Get a flattener for a triangular array.
111 * @param triangular triangular array to flatten
112 * @return flattener suited for triangular array dimensions
113 * @since 11.1
114 */
115 private static Flattener buildFlattener(final double[][] triangular) {
116 return new Flattener(triangular.length - 1, triangular[triangular.length - 1].length - 1);
117 }
118
119 /** {@inheritDoc} */
120 public int getMaxDegree() {
121 return flattener.getDegree();
122 }
123
124 /** {@inheritDoc} */
125 public int getMaxOrder() {
126 return flattener.getOrder();
127 }
128
129 /** {@inheritDoc} */
130 public double getMu() {
131 return mu;
132 }
133
134 /** {@inheritDoc} */
135 public double getAe() {
136 return ae;
137 }
138
139 /** {@inheritDoc}
140 * <p>
141 * For a constant field, null is always returned.
142 * </p>
143 */
144 public AbsoluteDate getReferenceDate() {
145 return null;
146 }
147
148 /** {@inheritDoc} */
149 @Deprecated
150 public double getOffset(final AbsoluteDate date) {
151 return 0.0;
152 }
153
154 /** {@inheritDoc} */
155 public TideSystem getTideSystem() {
156 return tideSystem;
157 }
158
159 @Override
160 public RawSphericalHarmonics onDate(final AbsoluteDate date) {
161 return new RawSphericalHarmonics() {
162
163 @Override
164 public AbsoluteDate getDate() {
165 return date;
166 }
167
168 /** {@inheritDoc} */
169 public double getRawCnm(final int n, final int m) {
170 return rawC[flattener.index(n, m)];
171 }
172
173 /** {@inheritDoc} */
174 public double getRawSnm(final int n, final int m) {
175 return rawS[flattener.index(n, m)];
176 }
177
178 };
179 }
180
181 }
182