1 /* Copyright 2002-2021 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.orekit.errors.OrekitException;
20 import org.orekit.errors.OrekitMessages;
21 import org.orekit.time.AbsoluteDate;
22
23 /** Simple implementation of {@link RawSphericalHarmonicsProvider} for constant gravity fields.
24 * @author Luc Maisonobe
25 * @since 6.0
26 */
27 class ConstantSphericalHarmonics implements RawSphericalHarmonicsProvider {
28
29 /** Central body reference radius. */
30 private final double ae;
31
32 /** Central body attraction coefficient. */
33 private final double mu;
34
35 /** Tide system. */
36 private final TideSystem tideSystem;
37
38 /** Raw tesseral-sectorial coefficients matrix. */
39 private final double[][] rawC;
40
41 /** Raw tesseral-sectorial coefficients matrix. */
42 private final double[][] rawS;
43
44 /** Simple constructor.
45 * @param ae central body reference radius
46 * @param mu central body attraction coefficient
47 * @param tideSystem tide system
48 * @param rawC raw tesseral-sectorial coefficients
49 * @param rawS raw tesseral-sectorial coefficients
50 */
51 ConstantSphericalHarmonics(final double ae, final double mu,
52 final TideSystem tideSystem,
53 final double[][] rawC, final double[][] rawS) {
54 this.ae = ae;
55 this.mu = mu;
56 this.tideSystem = tideSystem;
57 this.rawC = rawC;
58 this.rawS = rawS;
59 }
60
61 /** {@inheritDoc} */
62 public int getMaxDegree() {
63 return rawC.length - 1;
64 }
65
66 /** {@inheritDoc} */
67 public int getMaxOrder() {
68 return rawC[rawC.length - 1].length - 1;
69 }
70
71 /** {@inheritDoc} */
72 public double getMu() {
73 return mu;
74 }
75
76 /** {@inheritDoc} */
77 public double getAe() {
78 return ae;
79 }
80
81 /** {@inheritDoc}
82 * <p>
83 * For a constant field, null is always returned.
84 * </p>
85 */
86 public AbsoluteDate getReferenceDate() {
87 return null;
88 }
89
90 /** {@inheritDoc} */
91 public double getOffset(final AbsoluteDate date) {
92 return 0.0;
93 }
94
95 /** {@inheritDoc} */
96 public TideSystem getTideSystem() {
97 return tideSystem;
98 }
99
100 @Override
101 public RawSphericalHarmonics onDate(final AbsoluteDate date) {
102 return new RawSphericalHarmonics() {
103
104 @Override
105 public AbsoluteDate getDate() {
106 return date;
107 }
108
109 /** {@inheritDoc} */
110 public double getRawCnm(final int n, final int m) {
111 checkLimits(n, m);
112 return rawC[n][m];
113 }
114
115 /** {@inheritDoc} */
116 public double getRawSnm(final int n, final int m) {
117 checkLimits(n, m);
118 return rawS[n][m];
119 }
120
121 };
122 }
123
124 /** Check limits.
125 * @param degree degree
126 * @param order order
127 */
128 private void checkLimits(final int degree, final int order) {
129
130 if (degree >= rawC.length) {
131 throw new OrekitException(OrekitMessages.TOO_LARGE_DEGREE_FOR_GRAVITY_FIELD,
132 degree, rawC.length - 1);
133 }
134
135 if (order >= rawC[degree].length) {
136 throw new OrekitException(OrekitMessages.TOO_LARGE_ORDER_FOR_GRAVITY_FIELD,
137 order, rawC[degree].length - 1);
138 }
139
140 }
141
142 }
143