ConstantSphericalHarmonics.java

  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. import org.hipparchus.util.FastMath;
  19. import org.orekit.time.AbsoluteDate;

  20. /** Simple implementation of {@link RawSphericalHarmonicsProvider} for constant gravity fields.
  21.  * @author Luc Maisonobe
  22.  * @since 6.0
  23.  */
  24. class ConstantSphericalHarmonics implements RawSphericalHarmonicsProvider {

  25.     /** Central body reference radius. */
  26.     private final double ae;

  27.     /** Central body attraction coefficient. */
  28.     private final double mu;

  29.     /** Tide system. */
  30.     private final TideSystem tideSystem;

  31.     /** Converter from triangular to flatten array.
  32.      * @since 11.1
  33.      */
  34.     private final Flattener flattener;

  35.     /** Raw tesseral-sectorial coefficients matrix. */
  36.     private final double[] rawC;

  37.     /** Raw tesseral-sectorial coefficients matrix. */
  38.     private final double[] rawS;

  39.     /** Simple constructor.
  40.      * @param ae central body reference radius
  41.      * @param mu central body attraction coefficient
  42.      * @param tideSystem tide system
  43.      * @param rawC raw tesseral-sectorial coefficients
  44.      * @param rawS raw tesseral-sectorial coefficients
  45.      * @deprecated as of 11.1, replaced by {@link #ConstantSphericalHarmonics(double,
  46.      * double, TideSystem, Flattener, double[], double[])}
  47.      */
  48.     @Deprecated
  49.     ConstantSphericalHarmonics(final double ae, final double mu,
  50.                                final TideSystem tideSystem,
  51.                                final double[][] rawC, final double[][] rawS) {
  52.         this(ae, mu, tideSystem, buildFlattener(rawC),
  53.              buildFlattener(rawC).flatten(rawC), buildFlattener(rawS).flatten(rawS));
  54.     }

  55.     /** Simple constructor.
  56.      * @param ae central body reference radius
  57.      * @param mu central body attraction coefficient
  58.      * @param tideSystem tide system
  59.      * @param flattener flattener from triangular to flatten array
  60.      * @param rawC raw tesseral-sectorial coefficients
  61.      * @param rawS raw tesseral-sectorial coefficients
  62.      * @since 11.1
  63.      */
  64.     ConstantSphericalHarmonics(final double ae, final double mu, final TideSystem tideSystem,
  65.                                final Flattener flattener, final double[] rawC, final double[] rawS) {
  66.         this.ae         = ae;
  67.         this.mu         = mu;
  68.         this.tideSystem = tideSystem;
  69.         this.flattener  = flattener;
  70.         this.rawC       = rawC;
  71.         this.rawS       = rawS;
  72.     }

  73.     /** Create a constant provider by freezing a regular provider.
  74.      * @param freezingDate freezing date
  75.      * @param raw raw provider to freeze
  76.      * @since 11.1
  77.      */
  78.     ConstantSphericalHarmonics(final AbsoluteDate freezingDate, final RawSphericalHarmonicsProvider raw) {

  79.         this.ae         = raw.getAe();
  80.         this.mu         = raw.getMu();
  81.         this.tideSystem = raw.getTideSystem();
  82.         this.flattener  = new Flattener(raw.getMaxDegree(), raw.getMaxOrder());
  83.         this.rawC       = new double[flattener.arraySize()];
  84.         this.rawS       = new double[flattener.arraySize()];

  85.         // freeze the raw provider
  86.         final RawSphericalHarmonics frozen = raw.onDate(freezingDate);
  87.         for (int n = 0; n <= flattener.getDegree(); ++n) {
  88.             for (int m = 0; m <= FastMath.min(n, flattener.getOrder()); ++m) {
  89.                 final int index = flattener.index(n, m);
  90.                 rawC[index] = frozen.getRawCnm(n, m);
  91.                 rawS[index] = frozen.getRawSnm(n, m);
  92.             }
  93.         }

  94.     }

  95.     /** Get a flattener for a triangular array.
  96.      * @param triangular triangular array to flatten
  97.      * @return flattener suited for triangular array dimensions
  98.      * @since 11.1
  99.      */
  100.     private static Flattener buildFlattener(final double[][] triangular) {
  101.         return new Flattener(triangular.length - 1, triangular[triangular.length - 1].length - 1);
  102.     }

  103.     /** {@inheritDoc} */
  104.     public int getMaxDegree() {
  105.         return flattener.getDegree();
  106.     }

  107.     /** {@inheritDoc} */
  108.     public int getMaxOrder() {
  109.         return flattener.getOrder();
  110.     }

  111.     /** {@inheritDoc} */
  112.     public double getMu() {
  113.         return mu;
  114.     }

  115.     /** {@inheritDoc} */
  116.     public double getAe() {
  117.         return ae;
  118.     }

  119.     /** {@inheritDoc}
  120.      * <p>
  121.      * For a constant field, null is always returned.
  122.      * </p>
  123.      */
  124.     public AbsoluteDate getReferenceDate() {
  125.         return null;
  126.     }

  127.     /** {@inheritDoc} */
  128.     @Deprecated
  129.     public double getOffset(final AbsoluteDate date) {
  130.         return 0.0;
  131.     }

  132.     /** {@inheritDoc} */
  133.     public TideSystem getTideSystem() {
  134.         return tideSystem;
  135.     }

  136.     @Override
  137.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  138.         return new RawSphericalHarmonics() {

  139.             @Override
  140.             public AbsoluteDate getDate() {
  141.                 return date;
  142.             }

  143.             /** {@inheritDoc} */
  144.             public double getRawCnm(final int n, final int m) {
  145.                 return rawC[flattener.index(n, m)];
  146.             }

  147.             /** {@inheritDoc} */
  148.             public double getRawSnm(final int n, final int m) {
  149.                 return rawS[flattener.index(n, m)];
  150.             }

  151.         };
  152.     }

  153. }