PulsatingSphericalHarmonics.java

  1. /* Copyright 2002-2015 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.apache.commons.math3.util.FastMath;
  19. import org.apache.commons.math3.util.MathUtils;
  20. import org.orekit.errors.OrekitException;
  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.  */
  26. class PulsatingSphericalHarmonics implements RawSphericalHarmonicsProvider {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  100.             /** {@inheritDoc} */
  101.             public double getRawCnm(final int n, final int m)
  102.                 throws OrekitException {

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

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

  109.                 return cnm;
  110.             }

  111.             /** {@inheritDoc} */
  112.             public double getRawSnm(final int n, final int m)
  113.                 throws OrekitException {

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

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

  120.                 return snm;
  121.             }

  122.         };
  123.     }

  124. }