PulsatingSphericalHarmonics.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.orekit.time.AbsoluteDate;

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

  26.     /** Underlying part of the field. */
  27.     private final RawSphericalHarmonicsProvider provider;

  28.     /** Pulsation (rad/s). */
  29.     private final double pulsation;

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

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

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

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

  38.     /** Simple constructor.
  39.      * @param provider underlying part of the field
  40.      * @param period period of the pulsation (s)
  41.      * @param cosC cosine component of the cosine coefficients
  42.      * @param sinC sine component of the cosine coefficients
  43.      * @param cosS cosine component of the sine coefficients
  44.      * @param sinS sine component of the sine coefficients
  45.      */
  46.     PulsatingSphericalHarmonics(final RawSphericalHarmonicsProvider provider,
  47.                                      final double period,
  48.                                      final double[][] cosC, final double[][] sinC,
  49.                                      final double[][] cosS, final double[][] sinS) {
  50.         this.provider  = provider;
  51.         this.pulsation = MathUtils.TWO_PI / period;
  52.         this.cosC      = cosC;
  53.         this.sinC      = sinC;
  54.         this.cosS      = cosS;
  55.         this.sinS      = sinS;
  56.     }

  57.     /** {@inheritDoc} */
  58.     public int getMaxDegree() {
  59.         return provider.getMaxDegree();
  60.     }

  61.     /** {@inheritDoc} */
  62.     public int getMaxOrder() {
  63.         return provider.getMaxOrder();
  64.     }

  65.     /** {@inheritDoc} */
  66.     public double getMu() {
  67.         return provider.getMu();
  68.     }

  69.     /** {@inheritDoc} */
  70.     public double getAe() {
  71.         return provider.getAe();
  72.     }

  73.     /** {@inheritDoc} */
  74.     public AbsoluteDate getReferenceDate() {
  75.         return provider.getReferenceDate();
  76.     }

  77.     /** {@inheritDoc} */
  78.     public double getOffset(final AbsoluteDate date) {
  79.         return provider.getOffset(date);
  80.     }

  81.     /** {@inheritDoc} */
  82.     public TideSystem getTideSystem() {
  83.         return provider.getTideSystem();
  84.     }

  85.     @Override
  86.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  87.         //raw (constant) harmonics
  88.         final RawSphericalHarmonics raw = provider.onDate(date);
  89.         //phase angle, will loose precision for large offsets
  90.         final double alpha = pulsation * getOffset(date);
  91.         //pre-compute transcendental functions
  92.         final double cAlpha = FastMath.cos(alpha);
  93.         final double sAlpha = FastMath.sin(alpha);
  94.         return new RawSphericalHarmonics() {

  95.             @Override
  96.             public AbsoluteDate getDate() {
  97.                 return date;
  98.             }

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

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

  103.                 if (n < cosC.length && m < cosC[n].length) {
  104.                     // add pulsation
  105.                     cnm += cosC[n][m] * cAlpha + sinC[n][m] * sAlpha;
  106.                 }

  107.                 return cnm;
  108.             }

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

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

  113.                 if (n < cosS.length && m < cosS[n].length) {
  114.                     // add pulsation
  115.                     snm += cosS[n][m] * cAlpha + sinS[n][m] * sAlpha;
  116.                 }

  117.                 return snm;
  118.             }

  119.         };
  120.     }

  121. }