DSSTThirdBodyStaticContext.java

  1. /* Copyright 2002-2023 CS GROUP
  2.  * Licensed to CS GROUP (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.forces;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
  20. import org.orekit.propagation.semianalytical.dsst.utilities.UpperBounds;

  21. /**
  22.  * This class is a container for the common parameters used in
  23.  * {@link DSSTThirdBody}.
  24.  * <p>
  25.  * It performs parameters initialization at each integration step for the third
  26.  * body attraction perturbation. These parameters are initialize as soon as
  27.  * possible. In fact, they are initialized once with short period terms and
  28.  * don't evolve during propagation.
  29.  * </p>
  30.  * @author Bryan Cazabonne
  31.  * @since 11.3.3
  32.  */
  33. public class DSSTThirdBodyStaticContext extends ForceModelContext {

  34.     /** Max power for a/R3 in the serie expansion. */
  35.     private int maxAR3Pow;

  36.     /** Max power for e in the serie expansion. */
  37.     private int maxEccPow;

  38.     /** Max frequency of F. */
  39.     private int maxFreqF;

  40.     /**
  41.      * Constructor.
  42.      *
  43.      * @param aux auxiliary elements
  44.      * @param x DSST Chi element
  45.      * @param r3 distance from center of mass of the central body to the 3rd body
  46.      * @param parameters force model parameters
  47.      */
  48.     public DSSTThirdBodyStaticContext(final AuxiliaryElements aux,
  49.                                       final double x, final double r3,
  50.                                       final double[] parameters) {
  51.         super(aux);

  52.         // Factorials computation
  53.         final int dim = 2 * DSSTThirdBody.MAX_POWER;
  54.         final double[] fact = new double[dim];
  55.         fact[0] = 1.;
  56.         for (int i = 1; i < dim; i++) {
  57.             fact[i] = i * fact[i - 1];
  58.         }

  59.         // Truncation tolerance.
  60.         final double aor = aux.getSma() / r3;
  61.         final double tol = (aor > .3 || aor > .15 && aux.getEcc() > .25) ? DSSTThirdBody.BIG_TRUNCATION_TOLERANCE : DSSTThirdBody.SMALL_TRUNCATION_TOLERANCE;

  62.         // Utilities for truncation
  63.         // Set a lower bound for eccentricity
  64.         final double eo2 = FastMath.max(0.0025, 0.5 * aux.getEcc());
  65.         final double x2o2 = 0.5 * x * x;
  66.         final double[] eccPwr = new double[DSSTThirdBody.MAX_POWER];
  67.         final double[] chiPwr = new double[DSSTThirdBody.MAX_POWER];
  68.         eccPwr[0] = 1.;
  69.         chiPwr[0] = x;
  70.         for (int i = 1; i < DSSTThirdBody.MAX_POWER; i++) {
  71.             eccPwr[i] = eccPwr[i - 1] * eo2;
  72.             chiPwr[i] = chiPwr[i - 1] * x2o2;
  73.         }

  74.         // Auxiliary quantities.
  75.         final double ao2rxx = aor / (2. * x * x);
  76.         double xmuarn = ao2rxx * ao2rxx * parameters[0] / (x * r3);
  77.         double term = 0.;

  78.         // Compute max power for a/R3 and e.
  79.         maxAR3Pow = 2;
  80.         maxEccPow = 0;
  81.         int n = 2;
  82.         int m = 2;
  83.         int nsmd2 = 0;

  84.         do {
  85.             // Upper bound for Tnm.
  86.             term =
  87.                 xmuarn *
  88.                    (fact[n + m] / (fact[nsmd2] * fact[nsmd2 + m])) *
  89.                    (fact[n + m + 1] / (fact[m] * fact[n + 1])) *
  90.                    (fact[n - m + 1] / fact[n + 1]) * eccPwr[m] *
  91.                    UpperBounds.getDnl(x * x, chiPwr[m], n + 2, m);

  92.             if (term < tol) {
  93.                 if (m == 0) {
  94.                     break;
  95.                 } else if (m < 2) {
  96.                     xmuarn *= ao2rxx;
  97.                     m = 0;
  98.                     n++;
  99.                     nsmd2++;
  100.                 } else {
  101.                     m -= 2;
  102.                     nsmd2++;
  103.                 }
  104.             } else {
  105.                 maxAR3Pow = n;
  106.                 maxEccPow = FastMath.max(m, maxEccPow);
  107.                 xmuarn *= ao2rxx;
  108.                 m++;
  109.                 n++;
  110.             }
  111.         } while (n < DSSTThirdBody.MAX_POWER);

  112.         maxEccPow = FastMath.min(maxAR3Pow, maxEccPow);
  113.         maxFreqF = maxAR3Pow + 1;

  114.     }

  115.     /**
  116.      * Get the value of max power for a/R3 in the serie expansion.
  117.      *
  118.      * @return maxAR3Pow
  119.      */
  120.     public int getMaxAR3Pow() {
  121.         return maxAR3Pow;
  122.     }

  123.     /**
  124.      * Get the value of max power for e in the serie expansion.
  125.      *
  126.      * @return maxEccPow
  127.      */
  128.     public int getMaxEccPow() {
  129.         return maxEccPow;
  130.     }

  131.     /**
  132.      * Get the value of max frequency of F.
  133.      *
  134.      * @return maxFreqF
  135.      */
  136.     public int getMaxFreqF() {
  137.         return maxFreqF;
  138.     }

  139. }