ConstantSphericalHarmonics.java

  1. /* Copyright 2002-2017 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.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.time.AbsoluteDate;

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

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

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

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

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

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

  36.     /** Simple constructor.
  37.      * @param ae central body reference radius
  38.      * @param mu central body attraction coefficient
  39.      * @param tideSystem tide system
  40.      * @param rawC raw tesseral-sectorial coefficients
  41.      * @param rawS raw tesseral-sectorial coefficients
  42.      */
  43.     ConstantSphericalHarmonics(final double ae, final double mu,
  44.                                       final TideSystem tideSystem,
  45.                                       final double[][] rawC, final double[][] rawS) {
  46.         this.ae         = ae;
  47.         this.mu         = mu;
  48.         this.tideSystem = tideSystem;
  49.         this.rawC       = rawC;
  50.         this.rawS       = rawS;
  51.     }

  52.     /** {@inheritDoc} */
  53.     public int getMaxDegree() {
  54.         return rawC.length - 1;
  55.     }

  56.     /** {@inheritDoc} */
  57.     public int getMaxOrder() {
  58.         return rawC[rawC.length - 1].length - 1;
  59.     }

  60.     /** {@inheritDoc} */
  61.     public double getMu() {
  62.         return mu;
  63.     }

  64.     /** {@inheritDoc} */
  65.     public double getAe() {
  66.         return ae;
  67.     }

  68.     /** {@inheritDoc}
  69.      * <p>
  70.      * For a constant field, null is always returned.
  71.      * </p>
  72.      */
  73.     public AbsoluteDate getReferenceDate() {
  74.         return null;
  75.     }

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

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

  84.     @Override
  85.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  86.         return new RawSphericalHarmonics() {

  87.             @Override
  88.             public AbsoluteDate getDate() {
  89.                 return date;
  90.             }

  91.             /** {@inheritDoc} */
  92.             public double getRawCnm(final int n, final int m)
  93.                 throws OrekitException {
  94.                 checkLimits(n, m);
  95.                 return rawC[n][m];
  96.             }

  97.             /** {@inheritDoc} */
  98.             public double getRawSnm(final int n, final int m)
  99.                 throws OrekitException {
  100.                 checkLimits(n, m);
  101.                 return rawS[n][m];
  102.             }

  103.         };
  104.     }

  105.     /** Check limits.
  106.      * @param degree degree
  107.      * @param order order
  108.      * @exception OrekitException if indices are out of bound
  109.      */
  110.     private void checkLimits(final int degree, final int order)
  111.         throws OrekitException {

  112.         if (degree >= rawC.length) {
  113.             throw new OrekitException(OrekitMessages.TOO_LARGE_DEGREE_FOR_GRAVITY_FIELD,
  114.                                       degree, rawC.length - 1);
  115.         }

  116.         if (order >= rawC[degree].length) {
  117.             throw new OrekitException(OrekitMessages.TOO_LARGE_ORDER_FOR_GRAVITY_FIELD,
  118.                                       order, rawC[degree].length - 1);
  119.         }

  120.     }

  121. }