PulsatingSphericalHarmonics.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.hipparchus.util.MathUtils;
  20. import org.hipparchus.util.SinCos;
  21. import org.orekit.time.AbsoluteDate;

  22. /** Simple implementation of {@link RawSphericalHarmonicsProvider} for pulsating gravity fields.
  23.  * @author Luc Maisonobe
  24.  * @since 6.0
  25.  * @deprecated as of 11.1, replaced by {@link PiecewiseSphericalHarmonics}
  26.  */
  27. @Deprecated
  28. class PulsatingSphericalHarmonics implements RawSphericalHarmonicsProvider {

  29.     /** Underlying part of the field. */
  30.     private final RawSphericalHarmonicsProvider provider;

  31.     /** Pulsation (rad/s). */
  32.     private final double pulsation;

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

  37.     /** Cosine component of the cosine coefficients. */
  38.     private final double[] cosC;

  39.     /** Sine component of the cosine coefficients. */
  40.     private final double[] sinC;

  41.     /** Cosine component of the sine coefficients. */
  42.     private final double[] cosS;

  43.     /** Sine component of the sine coefficients. */
  44.     private final double[] sinS;

  45.     /** Simple constructor.
  46.      * @param provider underlying part of the field
  47.      * @param period period of the pulsation (s)
  48.      * @param cosC cosine component of the cosine coefficients
  49.      * @param sinC sine component of the cosine coefficients
  50.      * @param cosS cosine component of the sine coefficients
  51.      * @param sinS sine component of the sine coefficients
  52.      * @deprecated as of 11.1, replaced by {@link #PulsatingSphericalHarmonics(RawSphericalHarmonicsProvider,
  53.      * double, Flattener, double[], double[], double[], double[])}
  54.      */
  55.     @Deprecated
  56.     PulsatingSphericalHarmonics(final RawSphericalHarmonicsProvider provider,
  57.                                 final double period,
  58.                                 final double[][] cosC, final double[][] sinC,
  59.                                 final double[][] cosS, final double[][] sinS) {
  60.         this(provider, period, buildFlattener(cosC),
  61.              buildFlattener(cosC).flatten(cosC), buildFlattener(sinC).flatten(sinC),
  62.              buildFlattener(cosS).flatten(cosS), buildFlattener(sinS).flatten(sinS));
  63.     }

  64.     /** Simple constructor.
  65.      * @param provider underlying part of the field
  66.      * @param period period of the pulsation (s)
  67.      * @param flattener flattener from triangular to flatten array
  68.      * @param cosC cosine component of the cosine coefficients
  69.      * @param sinC sine component of the cosine coefficients
  70.      * @param cosS cosine component of the sine coefficients
  71.      * @param sinS sine component of the sine coefficients
  72.      * @since 11.1
  73.      */
  74.     PulsatingSphericalHarmonics(final RawSphericalHarmonicsProvider provider,
  75.                                 final double period, final Flattener flattener,
  76.                                 final double[] cosC, final double[] sinC,
  77.                                 final double[] cosS, final double[] sinS) {
  78.         this.provider  = provider;
  79.         this.pulsation = MathUtils.TWO_PI / period;
  80.         this.flattener = flattener;
  81.         this.cosC      = cosC.clone();
  82.         this.sinC      = sinC.clone();
  83.         this.cosS      = cosS.clone();
  84.         this.sinS      = sinS.clone();
  85.     }

  86.     /** Get a flattener for a triangular array.
  87.      * @param triangular triangular array to flatten
  88.      * @return flattener suited for triangular array dimensions
  89.      * @since 11.1
  90.      */
  91.     private static Flattener buildFlattener(final double[][] triangular) {
  92.         return new Flattener(triangular.length - 1, triangular[triangular.length - 1].length - 1);
  93.     }

  94.     /** {@inheritDoc} */
  95.     public int getMaxDegree() {
  96.         return FastMath.max(flattener.getDegree(), provider.getMaxDegree());
  97.     }

  98.     /** {@inheritDoc} */
  99.     public int getMaxOrder() {
  100.         return FastMath.max(flattener.getOrder(), provider.getMaxOrder());
  101.     }

  102.     /** {@inheritDoc} */
  103.     public double getMu() {
  104.         return provider.getMu();
  105.     }

  106.     /** {@inheritDoc} */
  107.     public double getAe() {
  108.         return provider.getAe();
  109.     }

  110.     /** {@inheritDoc} */
  111.     public AbsoluteDate getReferenceDate() {
  112.         return provider.getReferenceDate();
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Deprecated
  116.     public double getOffset(final AbsoluteDate date) {
  117.         return provider.getOffset(date);
  118.     }

  119.     /** {@inheritDoc} */
  120.     public TideSystem getTideSystem() {
  121.         return provider.getTideSystem();
  122.     }

  123.     @Override
  124.     @Deprecated
  125.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  126.         //raw (constant) harmonics
  127.         final RawSphericalHarmonics raw = provider.onDate(date);
  128.         //phase angle, will loose precision for large offsets
  129.         final double alpha = pulsation * provider.getOffset(date);
  130.         //pre-compute transcendental functions
  131.         final SinCos scAlpha = FastMath.sinCos(alpha);
  132.         return new RawSphericalHarmonics() {

  133.             @Override
  134.             public AbsoluteDate getDate() {
  135.                 return date;
  136.             }

  137.             /** {@inheritDoc} */
  138.             public double getRawCnm(final int n, final int m) {

  139.                 // retrieve the underlying part of the coefficient
  140.                 double cnm = raw.getRawCnm(n, m);

  141.                 if (flattener.withinRange(n, m)) {
  142.                     // add pulsation
  143.                     cnm += cosC[flattener.index(n, m)] * scAlpha.cos() + sinC[flattener.index(n, m)] * scAlpha.sin();
  144.                 }

  145.                 return cnm;
  146.             }

  147.             /** {@inheritDoc} */
  148.             public double getRawSnm(final int n, final int m) {

  149.                 // retrieve the constant part of the coefficient
  150.                 double snm = raw.getRawSnm(n, m);

  151.                 if (flattener.withinRange(n, m)) {
  152.                     // add pulsation
  153.                     snm += cosS[flattener.index(n, m)] * scAlpha.cos() + sinS[flattener.index(n, m)] * scAlpha.sin();
  154.                 }

  155.                 return snm;
  156.             }

  157.         };
  158.     }

  159. }