1 /* Copyright 2002-2025 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
21 import java.util.Arrays;
22
23 /**
24 * Temporary container for reading gravity field coefficients.
25 * @since 12.2
26 * @author Fabien Maussion
27 */
28 class TemporaryCoefficientsContainer {
29
30 /** Converter from triangular to flat form. */
31 private final Flattener flattener;
32
33 /** Cosine coefficients. */
34 private final double[] c;
35
36 /** Sine coefficients. */
37 private final double[] s;
38
39 /** Initial value for coefficients. */
40 private final double initialValue;
41
42 /** Build a container with given degree and order.
43 * @param degree degree of the container
44 * @param order order of the container
45 * @param initialValue initial value for coefficients
46 */
47 TemporaryCoefficientsContainer(final int degree, final int order, final double initialValue) {
48 this.flattener = new Flattener(degree, order);
49 this.c = new double[flattener.arraySize()];
50 this.s = new double[flattener.arraySize()];
51 this.initialValue = initialValue;
52 Arrays.fill(c, initialValue);
53 Arrays.fill(s, initialValue);
54 }
55
56 /** Build a resized container.
57 * @param degree degree of the resized container
58 * @param order order of the resized container
59 * @return resized container
60 */
61 TemporaryCoefficientsContainer resize(final int degree, final int order) {
62 final TemporaryCoefficientsContainer resized = new TemporaryCoefficientsContainer(degree, order, initialValue);
63 for (int n = 0; n <= degree; ++n) {
64 for (int m = 0; m <= FastMath.min(n, order); ++m) {
65 if (flattener.withinRange(n, m)) {
66 final int rIndex = resized.flattener.index(n, m);
67 final int index = flattener.index(n, m);
68 resized.c[rIndex] = c[index];
69 resized.s[rIndex] = s[index];
70 }
71 }
72 }
73 return resized;
74 }
75
76 /**
77 * Get the converter from triangular to flat form.
78 * @return the converter from triangular to flat form
79 */
80 Flattener getFlattener() {
81 return flattener;
82 }
83
84 /**
85 * Get the cosine coefficients.
86 * @return the cosine coefficients
87 */
88 public double[] getC() {
89 return c;
90 }
91
92 /**
93 * Get the sine coefficients.
94 * @return the cosine coefficients
95 */
96 public double[] getS() {
97 return s;
98 }
99 }