TemporaryCoefficientsContainer.java

  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. import org.hipparchus.util.FastMath;

  19. import java.util.Arrays;

  20. /**
  21.  * Temporary container for reading gravity field coefficients.
  22.  * @since 12.2
  23.  * @author Fabien Maussion
  24.  */
  25. class TemporaryCoefficientsContainer {

  26.     /** Converter from triangular to flat form. */
  27.     private final Flattener flattener;

  28.     /** Cosine coefficients. */
  29.     private final double[] c;

  30.     /** Sine coefficients. */
  31.     private final double[] s;

  32.     /** Initial value for coefficients. */
  33.     private final double initialValue;

  34.     /** Build a container with given degree and order.
  35.      * @param degree degree of the container
  36.      * @param order order of the container
  37.      * @param initialValue initial value for coefficients
  38.      */
  39.     TemporaryCoefficientsContainer(final int degree, final int order, final double initialValue) {
  40.         this.flattener    = new Flattener(degree, order);
  41.         this.c            = new double[flattener.arraySize()];
  42.         this.s            = new double[flattener.arraySize()];
  43.         this.initialValue = initialValue;
  44.         Arrays.fill(c, initialValue);
  45.         Arrays.fill(s, initialValue);
  46.     }

  47.     /** Build a resized container.
  48.      * @param degree degree of the resized container
  49.      * @param order order of the resized container
  50.      * @return resized container
  51.      */
  52.     TemporaryCoefficientsContainer resize(final int degree, final int order) {
  53.         final TemporaryCoefficientsContainer resized = new TemporaryCoefficientsContainer(degree, order, initialValue);
  54.         for (int n = 0; n <= degree; ++n) {
  55.             for (int m = 0; m <= FastMath.min(n, order); ++m) {
  56.                 if (flattener.withinRange(n, m)) {
  57.                     final int rIndex = resized.flattener.index(n, m);
  58.                     final int index  = flattener.index(n, m);
  59.                     resized.c[rIndex] = c[index];
  60.                     resized.s[rIndex] = s[index];
  61.                 }
  62.             }
  63.         }
  64.         return resized;
  65.     }

  66.     /**
  67.      * Get the converter from triangular to flat form.
  68.      * @return the converter from triangular to flat form
  69.      */
  70.     Flattener getFlattener() {
  71.         return flattener;
  72.     }

  73.     /**
  74.      * Get the cosine coefficients.
  75.      * @return the cosine coefficients
  76.      */
  77.     public double[] getC() {
  78.         return c;
  79.     }

  80.     /**
  81.      * Get the sine coefficients.
  82.      * @return the cosine coefficients
  83.      */
  84.     public double[] getS() {
  85.         return s;
  86.     }
  87. }