ConstantSphericalHarmonics.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 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 flattener flattener from triangular to flatten array
  44.      * @param rawC raw tesseral-sectorial coefficients
  45.      * @param rawS raw tesseral-sectorial coefficients
  46.      * @since 11.1
  47.      */
  48.     ConstantSphericalHarmonics(final double ae, final double mu, final TideSystem tideSystem,
  49.                                final Flattener flattener, final double[] rawC, final double[] rawS) {
  50.         this.ae         = ae;
  51.         this.mu         = mu;
  52.         this.tideSystem = tideSystem;
  53.         this.flattener  = flattener;
  54.         this.rawC       = rawC;
  55.         this.rawS       = rawS;
  56.     }

  57.     /** Create a constant provider by freezing a regular provider.
  58.      * @param freezingDate freezing date
  59.      * @param raw raw provider to freeze
  60.      * @since 11.1
  61.      */
  62.     ConstantSphericalHarmonics(final AbsoluteDate freezingDate, final RawSphericalHarmonicsProvider raw) {

  63.         this.ae         = raw.getAe();
  64.         this.mu         = raw.getMu();
  65.         this.tideSystem = raw.getTideSystem();
  66.         this.flattener  = new Flattener(raw.getMaxDegree(), raw.getMaxOrder());
  67.         this.rawC       = new double[flattener.arraySize()];
  68.         this.rawS       = new double[flattener.arraySize()];

  69.         // freeze the raw provider
  70.         final RawSphericalHarmonics frozen = raw.onDate(freezingDate);
  71.         for (int n = 0; n <= flattener.getDegree(); ++n) {
  72.             for (int m = 0; m <= FastMath.min(n, flattener.getOrder()); ++m) {
  73.                 final int index = flattener.index(n, m);
  74.                 rawC[index] = frozen.getRawCnm(n, m);
  75.                 rawS[index] = frozen.getRawSnm(n, m);
  76.             }
  77.         }

  78.     }

  79.     /** {@inheritDoc} */
  80.     public int getMaxDegree() {
  81.         return flattener.getDegree();
  82.     }

  83.     /** {@inheritDoc} */
  84.     public int getMaxOrder() {
  85.         return flattener.getOrder();
  86.     }

  87.     /** {@inheritDoc} */
  88.     public double getMu() {
  89.         return mu;
  90.     }

  91.     /** {@inheritDoc} */
  92.     public double getAe() {
  93.         return ae;
  94.     }

  95.     /** {@inheritDoc}
  96.      * <p>
  97.      * For a constant field, null is always returned.
  98.      * </p>
  99.      */
  100.     public AbsoluteDate getReferenceDate() {
  101.         return null;
  102.     }

  103.     /** {@inheritDoc} */
  104.     public TideSystem getTideSystem() {
  105.         return tideSystem;
  106.     }

  107.     @Override
  108.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  109.         return new RawSphericalHarmonics() {

  110.             @Override
  111.             public AbsoluteDate getDate() {
  112.                 return date;
  113.             }

  114.             /** {@inheritDoc} */
  115.             public double getRawCnm(final int n, final int m) {
  116.                 return rawC[flattener.index(n, m)];
  117.             }

  118.             /** {@inheritDoc} */
  119.             public double getRawSnm(final int n, final int m) {
  120.                 return rawS[flattener.index(n, m)];
  121.             }

  122.         };
  123.     }

  124. }