JacobiPolynomials.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.propagation.semianalytical.dsst.utilities;

  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;

  22. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  23. import org.hipparchus.analysis.polynomials.PolynomialFunction;
  24. import org.hipparchus.analysis.polynomials.PolynomialsUtils;

  25. /** Provider of the Jacobi polynomials P<sub>l</sub><sup>v,w</sup>.
  26.  * <p>
  27.  * This class is used for {@link
  28.  * org.orekit.propagation.semianalytical.dsst.forces.DSSTTesseral
  29.  * tesseral contribution} computation.
  30.  * </p>
  31.  *
  32.  * @author Nicolas Bernard
  33.  * @since 6.1
  34.  */
  35. public class JacobiPolynomials {

  36.     /** Storage map. */
  37.     private static final Map<JacobiKey, List<PolynomialFunction>> MAP =
  38.             new HashMap<JacobiPolynomials.JacobiKey, List<PolynomialFunction>>();

  39.     /** Private constructor as class is a utility. */
  40.     private JacobiPolynomials() {
  41.     }

  42.     /** Returns the value and derivatives of the Jacobi polynomial P<sub>l</sub><sup>v,w</sup> evaluated at γ.
  43.      * <p>
  44.      * This method is guaranteed to be thread-safe
  45.      * </p>
  46.      * @param l degree of the polynomial
  47.      * @param v v value
  48.      * @param w w value
  49.      * @param gamma γ value
  50.      * @return value and derivatives of the Jacobi polynomial P<sub>l</sub><sup>v,w</sup>(γ)
  51.      */
  52.     public static DerivativeStructure getValue(final int l, final int v, final int w, final DerivativeStructure gamma) {

  53.         final List<PolynomialFunction> polyList;
  54.         synchronized (MAP) {

  55.             final JacobiKey key = new JacobiKey(v, w);

  56.             // Check the existence of the corresponding key in the map.
  57.             if (!MAP.containsKey(key)) {
  58.                 MAP.put(key, new ArrayList<PolynomialFunction>());
  59.             }

  60.             polyList = MAP.get(key);

  61.         }

  62.         final PolynomialFunction polynomial;
  63.         synchronized (polyList) {
  64.             // If the l-th degree polynomial has not been computed yet, the polynomials
  65.             // up to this degree are computed.
  66.             for (int degree = polyList.size(); degree <= l; degree++) {
  67.                 polyList.add(degree, PolynomialsUtils.createJacobiPolynomial(degree, v, w));
  68.             }
  69.             polynomial = polyList.get(l);
  70.         }

  71.         // compute value and derivative
  72.         return polynomial.value(gamma);

  73.     }


  74.     /** Inner class for Jacobi polynomials keys.
  75.      * <p>
  76.      * Please note that this class is not original content but is a copy from the
  77.      * Hipparchus library. This library is published under the
  78.      * Apache License, version 2.0.
  79.      * </p>
  80.      *
  81.      * @see org.hipparchus.analysis.polynomials.PolynomialsUtils
  82.      */
  83.     private static class JacobiKey {

  84.         /** First exponent. */
  85.         private final int v;

  86.         /** Second exponent. */
  87.         private final int w;

  88.         /** Simple constructor.
  89.          * @param v first exponent
  90.          * @param w second exponent
  91.          */
  92.         JacobiKey(final int v, final int w) {
  93.             this.v = v;
  94.             this.w = w;
  95.         }

  96.         /** Get hash code.
  97.          * @return hash code
  98.          */
  99.         @Override
  100.         public int hashCode() {
  101.             return (v << 16) ^ w;
  102.         }

  103.         /** Check if the instance represent the same key as another instance.
  104.          * @param key other key
  105.          * @return true if the instance and the other key refer to the same polynomial
  106.          */
  107.         @Override
  108.         public boolean equals(final Object key) {

  109.             if ((key == null) || !(key instanceof JacobiKey)) {
  110.                 return false;
  111.             }

  112.             final JacobiKey otherK = (JacobiKey) key;
  113.             return (v == otherK.v) && (w == otherK.w);

  114.         }
  115.     }

  116. }