GammaMnsFunction.java

  1. /* Copyright 2002-2013 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.propagation.semianalytical.dsst.utilities;

  18. import java.util.Map;
  19. import java.util.TreeMap;

  20. import org.apache.commons.math3.util.FastMath;
  21. import org.orekit.propagation.semianalytical.dsst.utilities.CoefficientsFactory.MNSKey;

  22. /** Compute the &Gamma;<sup>m</sup><sub>n,s</sub>(&gamma;) function from equation 2.7.1-(13).
  23.  *
  24.  *  @author Romain Di Costanzo
  25.  */
  26. public class GammaMnsFunction {

  27.     /** Storage map. */
  28.     private final Map<MNSKey, Double> map;

  29.     /** Factorial. */
  30.     private final double[] fact;

  31.     /** 1 + I * &gamma;. */
  32.     private final double opIg;

  33.     /** I = +1 for a prograde orbit, -1 otherwise. */
  34.     private final int    I;

  35.     /** Simple constructor.
  36.      *  @param fact factorial array
  37.      *  @param gamma &gamma;
  38.      *  @param I retrograde factor
  39.      */
  40.     public GammaMnsFunction(final double[] fact, final double gamma, final int I) {
  41.         this.fact = fact.clone();
  42.         this.opIg = 1. + I * gamma;
  43.         this.I    = I;
  44.         this.map  = new TreeMap<MNSKey, Double>();
  45.     }

  46.     /** Get &Gamma; function value.
  47.      *  @param m m
  48.      *  @param n n
  49.      *  @param s s
  50.      *  @return &Gamma;<sup>m</sup><sub>n, s</sub>(&gamma;)
  51.      */
  52.     public double getValue(final int m, final int n, final int s) {
  53.         double res = 0.;
  54.         final MNSKey key = new MNSKey(m, n, s);
  55.         if (map.containsKey(key)) {
  56.             res = map.get(key);
  57.         } else {
  58.             if (s <= -m) {
  59.                 res = FastMath.pow(-1, m - s) * FastMath.pow(2, s) * FastMath.pow(opIg, -I * m);
  60.             } else if (s >= m) {
  61.                 res = FastMath.pow(2, -s) * FastMath.pow(opIg, I * m);
  62.             } else {
  63.                 res = FastMath.pow(-1, m - s) * FastMath.pow(2, -m) * FastMath.pow(opIg, I * s);
  64.                 res *= fact[n + m] * fact[n - m];
  65.                 res /= fact[n + s] * fact[n - s];
  66.             }
  67.             map.put(key, res);
  68.         }
  69.         return res;
  70.     }

  71.     /** Get &Gamma; function derivative.
  72.      * @param m m
  73.      * @param n n
  74.      * @param s s
  75.      * @return d&Gamma;<sup>m</sup><sub>n,s</sub>(&gamma;)/d&gamma;
  76.      */
  77.     public double getDerivative(final int m, final int n, final int s) {
  78.         double res = 0.;
  79.         if (s <= -m) {
  80.             res = -m * I * getValue(m, n, s) / opIg;
  81.         } else if (s >= m) {
  82.             res =  m * I * getValue(m, n, s) / opIg;
  83.         } else {
  84.             res =  s * I * getValue(m, n, s) / opIg;
  85.         }
  86.         return res;
  87.     }

  88. }