AbstractGaussianContribution.java

  1. /* Copyright 2002-2020 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 java.lang.reflect.Array;
  19. import java.util.ArrayList;
  20. import java.util.Collections;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Set;

  25. import org.hipparchus.Field;
  26. import org.hipparchus.RealFieldElement;
  27. import org.hipparchus.analysis.RealFieldUnivariateVectorFunction;
  28. import org.hipparchus.analysis.UnivariateVectorFunction;
  29. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  30. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  31. import org.hipparchus.util.FastMath;
  32. import org.hipparchus.util.MathArrays;
  33. import org.orekit.attitudes.Attitude;
  34. import org.orekit.attitudes.AttitudeProvider;
  35. import org.orekit.attitudes.FieldAttitude;
  36. import org.orekit.forces.ForceModel;
  37. import org.orekit.orbits.EquinoctialOrbit;
  38. import org.orekit.orbits.FieldEquinoctialOrbit;
  39. import org.orekit.orbits.FieldOrbit;
  40. import org.orekit.orbits.Orbit;
  41. import org.orekit.orbits.OrbitType;
  42. import org.orekit.orbits.PositionAngle;
  43. import org.orekit.propagation.FieldSpacecraftState;
  44. import org.orekit.propagation.PropagationType;
  45. import org.orekit.propagation.SpacecraftState;
  46. import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
  47. import org.orekit.propagation.semianalytical.dsst.utilities.CjSjCoefficient;
  48. import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
  49. import org.orekit.propagation.semianalytical.dsst.utilities.FieldCjSjCoefficient;
  50. import org.orekit.propagation.semianalytical.dsst.utilities.FieldShortPeriodicsInterpolatedCoefficient;
  51. import org.orekit.propagation.semianalytical.dsst.utilities.ShortPeriodicsInterpolatedCoefficient;
  52. import org.orekit.time.AbsoluteDate;
  53. import org.orekit.time.FieldAbsoluteDate;
  54. import org.orekit.utils.FieldTimeSpanMap;
  55. import org.orekit.utils.ParameterDriver;
  56. import org.orekit.utils.TimeSpanMap;

  57. /** Common handling of {@link DSSTForceModel} methods for Gaussian contributions to DSST propagation.
  58.  * <p>
  59.  * This abstract class allows to provide easily a subset of {@link DSSTForceModel} methods
  60.  * for specific Gaussian contributions.
  61.  * </p><p>
  62.  * This class implements the notion of numerical averaging of the DSST theory.
  63.  * Numerical averaging is mainly used for non-conservative disturbing forces such as
  64.  * atmospheric drag and solar radiation pressure.
  65.  * </p><p>
  66.  * Gaussian contributions can be expressed as: da<sub>i</sub>/dt = δa<sub>i</sub>/δv . q<br>
  67.  * where:
  68.  * <ul>
  69.  * <li>a<sub>i</sub> are the six equinoctial elements</li>
  70.  * <li>v is the velocity vector</li>
  71.  * <li>q is the perturbing acceleration due to the considered force</li>
  72.  * </ul>
  73.  *
  74.  * <p> The averaging process and other considerations lead to integrate this contribution
  75.  * over the true longitude L possibly taking into account some limits.
  76.  *
  77.  * <p> To create a numerically averaged contribution, one needs only to provide a
  78.  * {@link ForceModel} and to implement in the derived class the methods:
  79.  * {@link #getLLimits(SpacecraftState, AuxiliaryElements)}
  80.  * and {@link #getParametersDriversWithoutMu()}.
  81.  * </p>
  82.  * @author Pascal Parraud
  83.  * @author Bryan Cazabonne (field translation)
  84.  */
  85. public abstract class AbstractGaussianContribution implements DSSTForceModel {

  86.     /** Retrograde factor I.
  87.      *  <p>
  88.      *  DSST model needs equinoctial orbit as internal representation.
  89.      *  Classical equinoctial elements have discontinuities when inclination
  90.      *  is close to zero. In this representation, I = +1. <br>
  91.      *  To avoid this discontinuity, another representation exists and equinoctial
  92.      *  elements can be expressed in a different way, called "retrograde" orbit.
  93.      *  This implies I = -1. <br>
  94.      *  As Orekit doesn't implement the retrograde orbit, I is always set to +1.
  95.      *  But for the sake of consistency with the theory, the retrograde factor
  96.      *  has been kept in the formulas.
  97.      *  </p>
  98.      */
  99.     private static final int I = 1;

  100.     /** Central attraction scaling factor.
  101.      * <p>
  102.      * We use a power of 2 to avoid numeric noise introduction
  103.      * in the multiplications/divisions sequences.
  104.      * </p>
  105.      */
  106.     private static final double MU_SCALE = FastMath.scalb(1.0, 32);

  107.     /** Available orders for Gauss quadrature. */
  108.     private static final int[] GAUSS_ORDER = {12, 16, 20, 24, 32, 40, 48};

  109.     /** Max rank in Gauss quadrature orders array. */
  110.     private static final int MAX_ORDER_RANK = GAUSS_ORDER.length - 1;

  111.     /** Number of points for interpolation. */
  112.     private static final int INTERPOLATION_POINTS = 3;

  113.     /** Maximum value for j index. */
  114.     private static final int JMAX = 12;

  115.     /** Contribution to be numerically averaged. */
  116.     private final ForceModel contribution;

  117.     /** Gauss integrator. */
  118.     private final double threshold;

  119.     /** Gauss integrator. */
  120.     private GaussQuadrature integrator;

  121.     /** Flag for Gauss order computation. */
  122.     private boolean isDirty;

  123.     /** Attitude provider. */
  124.     private AttitudeProvider attitudeProvider;

  125.     /** Prefix for coefficients keys. */
  126.     private final String coefficientsKeyPrefix;

  127.     /** Short period terms. */
  128.     private GaussianShortPeriodicCoefficients gaussianSPCoefs;

  129.     /** Short period terms. */
  130.     private Map<Field<?>, FieldGaussianShortPeriodicCoefficients<?>> gaussianFieldSPCoefs;

  131.     /** Driver for gravitational parameter. */
  132.     private final ParameterDriver gmParameterDriver;

  133.     /** Build a new instance.
  134.      *  @param coefficientsKeyPrefix prefix for coefficients keys
  135.      *  @param threshold tolerance for the choice of the Gauss quadrature order
  136.      *  @param contribution the {@link ForceModel} to be numerically averaged
  137.      *  @param mu central attraction coefficient
  138.      */
  139.     protected AbstractGaussianContribution(final String coefficientsKeyPrefix,
  140.                                            final double threshold,
  141.                                            final ForceModel contribution,
  142.                                            final double mu) {

  143.         gmParameterDriver = new ParameterDriver(DSSTNewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT,
  144.                                                 mu, MU_SCALE,
  145.                                                 0.0, Double.POSITIVE_INFINITY);

  146.         this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  147.         this.contribution          = contribution;
  148.         this.threshold             = threshold;
  149.         this.integrator            = new GaussQuadrature(GAUSS_ORDER[MAX_ORDER_RANK]);
  150.         this.isDirty               = true;

  151.         gaussianFieldSPCoefs       = new HashMap<>();
  152.     }

  153.     /** {@inheritDoc} */
  154.     @Override
  155.     public ParameterDriver[] getParametersDrivers() {

  156.         final ParameterDriver[] driversWithoutMu = getParametersDriversWithoutMu();

  157.         // + 1 for central attraction coefficient driver
  158.         final ParameterDriver[] drivers = new ParameterDriver[driversWithoutMu.length + 1];

  159.         int index = 0;
  160.         for (final ParameterDriver driver : driversWithoutMu) {
  161.             drivers[index] = driver;
  162.             index++;
  163.         }

  164.         // We put central attraction coefficient driver at the end of the array
  165.         drivers[driversWithoutMu.length] = gmParameterDriver;
  166.         return drivers;

  167.     }

  168.     /** Get the drivers for force model parameters except the one for the central attraction coefficient.
  169.      * <p>
  170.      * The driver for central attraction coefficient is automatically
  171.      * added at the last element of the {@link ParameterDriver} array
  172.      * into {@link #getParametersDrivers()} method.
  173.      * </p>
  174.      * @return drivers for force model parameters
  175.      */
  176.     protected abstract ParameterDriver[] getParametersDriversWithoutMu();

  177.     /** {@inheritDoc} */
  178.     @Override
  179.     public List<ShortPeriodTerms> initialize(final AuxiliaryElements auxiliaryElements,
  180.                                              final PropagationType type,
  181.                                              final double[] parameters) {

  182.         final List<ShortPeriodTerms> list = new ArrayList<ShortPeriodTerms>();
  183.         gaussianSPCoefs = new GaussianShortPeriodicCoefficients(coefficientsKeyPrefix,
  184.                                                                 JMAX, INTERPOLATION_POINTS,
  185.                                                                 new TimeSpanMap<Slot>(new Slot(JMAX, INTERPOLATION_POINTS)));
  186.         list.add(gaussianSPCoefs);
  187.         return list;

  188.     }

  189.     /** {@inheritDoc} */
  190.     @Override
  191.     public <T extends RealFieldElement<T>> List<FieldShortPeriodTerms<T>> initialize(final FieldAuxiliaryElements<T> auxiliaryElements,
  192.                                                                                      final PropagationType type,
  193.                                                                                      final T[] parameters) {

  194.         final Field<T> field = auxiliaryElements.getDate().getField();

  195.         final FieldGaussianShortPeriodicCoefficients<T> fgspc =
  196.                         new FieldGaussianShortPeriodicCoefficients<>(coefficientsKeyPrefix,
  197.                                                                      JMAX, INTERPOLATION_POINTS,
  198.                                                                      new FieldTimeSpanMap<>(new FieldSlot<>(JMAX,
  199.                                                                                                             INTERPOLATION_POINTS),
  200.                                                                                             field));
  201.         gaussianFieldSPCoefs.put(field, fgspc);
  202.         return Collections.singletonList(fgspc);
  203.     }

  204.     /** Performs initialization at each integration step for the current force model.
  205.      *  <p>
  206.      *  This method aims at being called before mean elements rates computation.
  207.      *  </p>
  208.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  209.      *  @param parameters parameters values of the force model parameters
  210.      *  @return new force model context
  211.      */
  212.     private AbstractGaussianContributionContext initializeStep(final AuxiliaryElements auxiliaryElements, final double[] parameters) {
  213.         return new AbstractGaussianContributionContext(auxiliaryElements, parameters);
  214.     }

  215.     /** Performs initialization at each integration step for the current force model.
  216.      *  <p>
  217.      *  This method aims at being called before mean elements rates computation.
  218.      *  </p>
  219.      *  @param <T> type of the elements
  220.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  221.      *  @param parameters parameters values of the force model parameters
  222.      *  @return new force model context
  223.      */
  224.     private <T extends RealFieldElement<T>> FieldAbstractGaussianContributionContext<T> initializeStep(final FieldAuxiliaryElements<T> auxiliaryElements,
  225.                                                                                                        final T[] parameters) {
  226.         return new FieldAbstractGaussianContributionContext<>(auxiliaryElements, parameters);
  227.     }

  228.     /** {@inheritDoc} */
  229.     @Override
  230.     public double[] getMeanElementRate(final SpacecraftState state,
  231.                                        final AuxiliaryElements auxiliaryElements, final double[] parameters) {

  232.         // Container for attributes
  233.         final AbstractGaussianContributionContext context = initializeStep(auxiliaryElements, parameters);
  234.         double[] meanElementRate = new double[6];
  235.         // Computes the limits for the integral
  236.         final double[] ll = getLLimits(state, auxiliaryElements);
  237.         // Computes integrated mean element rates if Llow < Lhigh
  238.         if (ll[0] < ll[1]) {
  239.             meanElementRate = getMeanElementRate(state, integrator, ll[0], ll[1], context, parameters);
  240.             if (isDirty) {
  241.                 boolean next = true;
  242.                 for (int i = 0; i < MAX_ORDER_RANK && next; i++) {
  243.                     final double[] meanRates = getMeanElementRate(state, new GaussQuadrature(GAUSS_ORDER[i]), ll[0], ll[1], context, parameters);
  244.                     if (getRatesDiff(meanElementRate, meanRates, context) < threshold) {
  245.                         integrator = new GaussQuadrature(GAUSS_ORDER[i]);
  246.                         next = false;
  247.                     }
  248.                 }
  249.                 isDirty = false;
  250.             }
  251.         }
  252.         return meanElementRate;
  253.     }

  254.     /** {@inheritDoc} */
  255.     @Override
  256.     public <T extends RealFieldElement<T>> T[] getMeanElementRate(final FieldSpacecraftState<T> state,
  257.                                                                   final FieldAuxiliaryElements<T> auxiliaryElements,
  258.                                                                   final T[] parameters) {

  259.         // Container for attributes
  260.         final FieldAbstractGaussianContributionContext<T> context = initializeStep(auxiliaryElements, parameters);
  261.         final Field<T> field = state.getDate().getField();

  262.         T[] meanElementRate = MathArrays.buildArray(field, 6);
  263.         // Computes the limits for the integral
  264.         final T[] ll = getLLimits(state, auxiliaryElements);
  265.         // Computes integrated mean element rates if Llow < Lhigh
  266.         if (ll[0].getReal() < ll[1].getReal()) {
  267.             meanElementRate = getMeanElementRate(state, integrator, ll[0], ll[1], context, parameters);
  268.             if (isDirty) {
  269.                 boolean next = true;
  270.                 for (int i = 0; i < MAX_ORDER_RANK && next; i++) {
  271.                     final T[] meanRates = getMeanElementRate(state, new GaussQuadrature(GAUSS_ORDER[i]), ll[0], ll[1], context, parameters);
  272.                     if (getRatesDiff(meanElementRate, meanRates, context).getReal() < threshold) {
  273.                         integrator = new GaussQuadrature(GAUSS_ORDER[i]);
  274.                         next = false;
  275.                     }
  276.                 }
  277.                 isDirty = false;
  278.             }
  279.         }

  280.         return meanElementRate;
  281.     }

  282.     /** Compute the limits in L, the true longitude, for integration.
  283.      *
  284.      *  @param  state current state information: date, kinematics, attitude
  285.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  286.      *  @return the integration limits in L
  287.      */
  288.     protected abstract double[] getLLimits(SpacecraftState state, AuxiliaryElements auxiliaryElements);

  289.     /** Compute the limits in L, the true longitude, for integration.
  290.      *
  291.      *  @param <T> type of the elements
  292.      *  @param state current state information: date, kinematics, attitude
  293.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  294.      *  @return the integration limits in L
  295.      */
  296.     protected abstract <T extends RealFieldElement<T>> T[] getLLimits(FieldSpacecraftState<T> state,
  297.                                                                       FieldAuxiliaryElements<T> auxiliaryElements);

  298.     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  299.     *
  300.     *  @param state current state
  301.     *  @param gauss Gauss quadrature
  302.     *  @param low lower bound of the integral interval
  303.     *  @param high upper bound of the integral interval
  304.     *  @param context container for attributes
  305.     *  @param parameters values of the force model parameters
  306.     *  @return the mean element rates
  307.     */
  308.     private double[] getMeanElementRate(final SpacecraftState state,
  309.                                         final GaussQuadrature gauss,
  310.                                         final double low,
  311.                                         final double high,
  312.                                         final AbstractGaussianContributionContext context,
  313.                                         final double[] parameters) {

  314.         // Auxiliary elements related to the current orbit
  315.         final AuxiliaryElements auxiliaryElements = context.getAuxiliaryElements();

  316.         final double[] meanElementRate = gauss.integrate(new IntegrableFunction(state, true, 0, parameters), low, high);

  317.         // Constant multiplier for integral
  318.         final double coef = 1. / (2. * FastMath.PI * auxiliaryElements.getB());
  319.         // Corrects mean element rates
  320.         for (int i = 0; i < 6; i++) {
  321.             meanElementRate[i] *= coef;
  322.         }
  323.         return meanElementRate;
  324.     }

  325.     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  326.     *
  327.     *  @param <T> type of the elements
  328.     *  @param state current state
  329.     *  @param gauss Gauss quadrature
  330.     *  @param low lower bound of the integral interval
  331.     *  @param high upper bound of the integral interval
  332.     *  @param context container for attributes
  333.     *  @param parameters values of the force model parameters
  334.     *  @return the mean element rates
  335.     */
  336.     private <T extends RealFieldElement<T>> T[] getMeanElementRate(final FieldSpacecraftState<T> state,
  337.                                                                    final GaussQuadrature gauss,
  338.                                                                    final T low,
  339.                                                                    final T high,
  340.                                                                    final FieldAbstractGaussianContributionContext<T> context,
  341.                                                                    final T[] parameters) {

  342.         // Field
  343.         final Field<T> field = context.getA().getField();

  344.         // Auxiliary elements related to the current orbit
  345.         final FieldAuxiliaryElements<T> auxiliaryElements = context.getFieldAuxiliaryElements();

  346.         final T[] meanElementRate = gauss.integrate(new FieldIntegrableFunction<>(state, true, 0, parameters, field), low, high, field);
  347.         // Constant multiplier for integral
  348.         final T coef = auxiliaryElements.getB().multiply(FastMath.PI).multiply(2.).reciprocal();
  349.         // Corrects mean element rates
  350.         for (int i = 0; i < 6; i++) {
  351.             meanElementRate[i] = meanElementRate[i].multiply(coef);
  352.         }
  353.         return meanElementRate;
  354.     }

  355.     /** Estimates the weighted magnitude of the difference between 2 sets of equinoctial elements rates.
  356.      *
  357.      *  @param meanRef reference rates
  358.      *  @param meanCur current rates
  359.      *  @param context container for attributes
  360.      *  @return estimated magnitude of weighted differences
  361.      */
  362.     private double getRatesDiff(final double[] meanRef, final double[] meanCur, final AbstractGaussianContributionContext context) {

  363.         // Auxiliary elements related to the current orbit
  364.         final AuxiliaryElements auxiliaryElements = context.getAuxiliaryElements();

  365.         double maxDiff = FastMath.abs(meanRef[0] - meanCur[0]) / auxiliaryElements.getSma();
  366.         // Corrects mean element rates
  367.         for (int i = 1; i < meanRef.length; i++) {
  368.             maxDiff = FastMath.max(maxDiff, FastMath.abs(meanRef[i] - meanCur[i]));
  369.         }
  370.         return maxDiff;
  371.     }

  372.     /** Estimates the weighted magnitude of the difference between 2 sets of equinoctial elements rates.
  373.     *
  374.     *  @param <T> type of the elements
  375.     *  @param meanRef reference rates
  376.     *  @param meanCur current rates
  377.     *  @param context container for attributes
  378.     *  @return estimated magnitude of weighted differences
  379.     */
  380.     private <T extends RealFieldElement<T>> T getRatesDiff(final T[] meanRef, final T[] meanCur, final FieldAbstractGaussianContributionContext<T> context) {

  381.         // Auxiliary elements related to the current orbit
  382.         final FieldAuxiliaryElements<T> auxiliaryElements = context.getFieldAuxiliaryElements();

  383.         T maxDiff = FastMath.abs(meanRef[0].subtract(meanCur[0])).divide(auxiliaryElements.getSma());;
  384.         // Corrects mean element rates
  385.         for (int i = 1; i < meanRef.length; i++) {
  386.             maxDiff = FastMath.max(maxDiff, FastMath.abs(meanRef[i].subtract(meanCur[i])));
  387.         }
  388.         return maxDiff;
  389.     }

  390.     /** {@inheritDoc} */
  391.     @Override
  392.     public void registerAttitudeProvider(final AttitudeProvider provider) {
  393.         this.attitudeProvider = provider;
  394.     }

  395.     /** {@inheritDoc} */
  396.     @Override
  397.     public void updateShortPeriodTerms(final double[] parameters, final SpacecraftState... meanStates) {

  398.         final Slot slot = gaussianSPCoefs.createSlot(meanStates);
  399.         for (final SpacecraftState meanState : meanStates) {

  400.             // Auxiliary elements related to the current orbit
  401.             final AuxiliaryElements auxiliaryElements = new AuxiliaryElements(meanState.getOrbit(), I);

  402.             // Container of attributes
  403.             final AbstractGaussianContributionContext context = initializeStep(auxiliaryElements, parameters);

  404.             // Compute rhoj and sigmaj
  405.             final double[][] currentRhoSigmaj = computeRhoSigmaCoefficients(meanState.getDate(), auxiliaryElements);

  406.             // Generate the Cij and Sij coefficients
  407.             final FourierCjSjCoefficients fourierCjSj = new FourierCjSjCoefficients(meanState, JMAX, auxiliaryElements, parameters);

  408.             // Generate the Uij and Vij coefficients
  409.             final UijVijCoefficients uijvij = new UijVijCoefficients(currentRhoSigmaj, fourierCjSj, JMAX);

  410.             gaussianSPCoefs.computeCoefficients(meanState, slot, fourierCjSj, uijvij, context.getMeanMotion(), auxiliaryElements.getSma());

  411.         }

  412.     }

  413.     /** {@inheritDoc} */
  414.     @Override
  415.     @SuppressWarnings("unchecked")
  416.     public <T extends RealFieldElement<T>> void updateShortPeriodTerms(final T[] parameters,
  417.                                                                        final FieldSpacecraftState<T>... meanStates) {

  418.         // Field used by default
  419.         final Field<T> field = meanStates[0].getDate().getField();

  420.         final FieldGaussianShortPeriodicCoefficients<T> fgspc = (FieldGaussianShortPeriodicCoefficients<T>) gaussianFieldSPCoefs.get(field);
  421.         final FieldSlot<T> slot = fgspc.createSlot(meanStates);
  422.         for (final FieldSpacecraftState<T> meanState : meanStates) {

  423.             // Auxiliary elements related to the current orbit
  424.             final FieldAuxiliaryElements<T> auxiliaryElements = new FieldAuxiliaryElements<>(meanState.getOrbit(), I);

  425.             // Container of attributes
  426.             final FieldAbstractGaussianContributionContext<T> context = initializeStep(auxiliaryElements, parameters);

  427.             // Compute rhoj and sigmaj
  428.             final T[][] currentRhoSigmaj = computeRhoSigmaCoefficients(meanState.getDate(), context, field);

  429.             // Generate the Cij and Sij coefficients
  430.             final FieldFourierCjSjCoefficients<T> fourierCjSj = new FieldFourierCjSjCoefficients<>(meanState, JMAX, auxiliaryElements, parameters, field);

  431.             // Generate the Uij and Vij coefficients
  432.             final FieldUijVijCoefficients<T> uijvij = new FieldUijVijCoefficients<>(currentRhoSigmaj, fourierCjSj, JMAX, field);

  433.             fgspc.computeCoefficients(meanState, slot, fourierCjSj, uijvij, context.getMeanMotion(), auxiliaryElements.getSma(), field);

  434.         }

  435.     }

  436.     /**
  437.      * Compute the auxiliary quantities ρ<sub>j</sub> and σ<sub>j</sub>.
  438.      * <p>
  439.      * The expressions used are equations 2.5.3-(4) from the Danielson paper. <br/>
  440.      *  ρ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>C<sub>j</sub>(k, h) <br/>
  441.      *  σ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>S<sub>j</sub>(k, h) <br/>
  442.      * </p>
  443.      * @param date current date
  444.      * @param auxiliaryElements auxiliary elements related to the current orbit
  445.      * @return computed coefficients
  446.      */
  447.     private double[][] computeRhoSigmaCoefficients(final AbsoluteDate date, final AuxiliaryElements auxiliaryElements) {
  448.         final double[][] currentRhoSigmaj = new double[2][3 * JMAX + 1];
  449.         final CjSjCoefficient cjsjKH = new CjSjCoefficient(auxiliaryElements.getK(), auxiliaryElements.getH());
  450.         final double b = 1. / (1 + auxiliaryElements.getB());

  451.         // (-b)<sup>j</sup>
  452.         double mbtj = 1;

  453.         for (int j = 1; j <= 3 * JMAX; j++) {

  454.             //Compute current rho and sigma;
  455.             mbtj *= -b;
  456.             final double coef = (1 + j * auxiliaryElements.getB()) * mbtj;
  457.             currentRhoSigmaj[0][j] = coef * cjsjKH.getCj(j);
  458.             currentRhoSigmaj[1][j] = coef * cjsjKH.getSj(j);
  459.         }
  460.         return currentRhoSigmaj;
  461.     }

  462.     /**
  463.      * Compute the auxiliary quantities ρ<sub>j</sub> and σ<sub>j</sub>.
  464.      * <p>
  465.      * The expressions used are equations 2.5.3-(4) from the Danielson paper. <br/>
  466.      *  ρ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>C<sub>j</sub>(k, h) <br/>
  467.      *  σ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>S<sub>j</sub>(k, h) <br/>
  468.      * </p>
  469.      * @param <T> type of the elements
  470.      * @param date current date
  471.      * @param context container for attributes
  472.      * @param field field used by default
  473.      * @return computed coefficients
  474.      */
  475.     private <T extends RealFieldElement<T>> T[][] computeRhoSigmaCoefficients(final FieldAbsoluteDate<T> date,
  476.                                                                               final FieldAbstractGaussianContributionContext<T> context,
  477.                                                                               final Field<T> field) {
  478.         // zero
  479.         final T zero = field.getZero();

  480.         final FieldAuxiliaryElements<T> auxiliaryElements = context.getFieldAuxiliaryElements();
  481.         final T[][] currentRhoSigmaj = MathArrays.buildArray(field, 2, 3 * JMAX + 1);
  482.         final FieldCjSjCoefficient<T> cjsjKH = new FieldCjSjCoefficient<>(auxiliaryElements.getK(), auxiliaryElements.getH(), field);
  483.         final T b = auxiliaryElements.getB().add(1.).reciprocal();

  484.         // (-b)<sup>j</sup>
  485.         T mbtj = zero.add(1.);

  486.         for (int j = 1; j <= 3 * JMAX; j++) {

  487.             //Compute current rho and sigma;
  488.             mbtj = mbtj.multiply(b.negate());
  489.             final T coef = mbtj.multiply(auxiliaryElements.getB().multiply(j).add(1.));
  490.             currentRhoSigmaj[0][j] = coef.multiply(cjsjKH.getCj(j));
  491.             currentRhoSigmaj[1][j] = coef.multiply(cjsjKH.getSj(j));
  492.         }
  493.         return currentRhoSigmaj;
  494.     }

  495.     /** Internal class for numerical quadrature.
  496.      *  <p>
  497.      *  This class is a rewrite of {@link IntegrableFunction} for field elements
  498.      *  </p>
  499.      */
  500.     private class FieldIntegrableFunction <T extends RealFieldElement<T>> implements RealFieldUnivariateVectorFunction<T> {

  501.         /** Current state. */
  502.         private final FieldSpacecraftState<T> state;

  503.         /** Signal that this class is used to compute the values required by the mean element variations
  504.          * or by the short periodic element variations. */
  505.         private final boolean meanMode;

  506.         /** The j index.
  507.          * <p>
  508.          * Used only for short periodic variation. Ignored for mean elements variation.
  509.          * </p> */
  510.         private final int j;

  511.         /** Container for attributes. */
  512.         private final FieldAbstractGaussianContributionContext<T> context;

  513.         /** Auxiliary Elements. */
  514.         private final FieldAuxiliaryElements<T> auxiliaryElements;

  515.         /** Drivers for solar radiation and atmospheric drag forces. */
  516.         private final T[] parameters;

  517.         /** Build a new instance with a new field.
  518.          *  @param  state current state information: date, kinematics, attitude
  519.          *  @param meanMode if true return the value associated to the mean elements variation,
  520.          *                  if false return the values associated to the short periodic elements variation
  521.          *  @param j the j index. used only for short periodic variation. Ignored for mean elements variation.
  522.          *  @param parameters values of the force model parameters
  523.          *  @param field field utilized by default
  524.          */
  525.         FieldIntegrableFunction(final FieldSpacecraftState<T> state,
  526.                                 final boolean meanMode,
  527.                                 final int j,
  528.                                 final T[] parameters,
  529.                                 final Field<T> field) {

  530.             this.meanMode = meanMode;
  531.             this.j = j;
  532.             this.parameters = parameters;
  533.             this.auxiliaryElements = new FieldAuxiliaryElements<>(state.getOrbit(), I);
  534.             this.context = new FieldAbstractGaussianContributionContext<>(auxiliaryElements, parameters);
  535.             // remove derivatives from state
  536.             final T[] stateVector = MathArrays.buildArray(field, 6);
  537.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), PositionAngle.TRUE, stateVector, null);
  538.             final FieldOrbit<T> fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE,
  539.                                                                            state.getDate(),
  540.                                                                            context.getMu(),
  541.                                                                            state.getFrame());
  542.             this.state = new FieldSpacecraftState<>(fixedOrbit, state.getAttitude(), state.getMass());
  543.         }

  544.         /** {@inheritDoc} */
  545.         @Override
  546.         public T[] value(final T x) {

  547.             // Parameters for array building
  548.             final Field<T> field = auxiliaryElements.getDate().getField();
  549.             final int dimension = 6;

  550.             //Compute the time difference from the true longitude difference
  551.             final T shiftedLm = trueToMean(x);
  552.             final T dLm = shiftedLm.subtract(auxiliaryElements.getLM());
  553.             final T dt = dLm.divide(context.getMeanMotion());

  554.             final T cosL = FastMath.cos(x);
  555.             final T sinL = FastMath.sin(x);
  556.             final T roa  = auxiliaryElements.getB().multiply(auxiliaryElements.getB()).divide(auxiliaryElements.getH().multiply(sinL).add(auxiliaryElements.getK().multiply(cosL)).add(1.));
  557.             final T roa2 = roa.multiply(roa);
  558.             final T r    = auxiliaryElements.getSma().multiply(roa);
  559.             final T X    = r.multiply(cosL);
  560.             final T Y    = r.multiply(sinL);
  561.             final T naob = context.getMeanMotion().multiply(auxiliaryElements.getSma()).divide(auxiliaryElements.getB());
  562.             final T Xdot = naob.multiply(auxiliaryElements.getH().add(sinL)).negate();
  563.             final T Ydot = naob.multiply(auxiliaryElements.getK().add(cosL));
  564.             final FieldVector3D<T> vel = new FieldVector3D<>(Xdot, auxiliaryElements.getVectorF(), Ydot, auxiliaryElements.getVectorG());

  565.             // Compute acceleration
  566.             FieldVector3D<T> acc = FieldVector3D.getZero(field);

  567.             // shift the orbit to dt
  568.             final FieldOrbit<T> shiftedOrbit = state.getOrbit().shiftedBy(dt);

  569.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  570.             final FieldOrbit<T> recomposedOrbit =
  571.                             new FieldEquinoctialOrbit<>(shiftedOrbit.getA(),
  572.                                             shiftedOrbit.getEquinoctialEx(),
  573.                                             shiftedOrbit.getEquinoctialEy(),
  574.                                             shiftedOrbit.getHx(),
  575.                                             shiftedOrbit.getHy(),
  576.                                             shiftedOrbit.getLv(),
  577.                                             PositionAngle.TRUE,
  578.                                             shiftedOrbit.getFrame(),
  579.                                             state.getDate(),
  580.                                             context.getMu());

  581.             // Get the corresponding attitude
  582.             final FieldAttitude<T> recomposedAttitude =
  583.                             attitudeProvider.getAttitude(recomposedOrbit,
  584.                                                          recomposedOrbit.getDate(),
  585.                                                          recomposedOrbit.getFrame());

  586.             // create shifted SpacecraftState with attitude at specified time
  587.             final FieldSpacecraftState<T> shiftedState =
  588.                             new FieldSpacecraftState<>(recomposedOrbit, recomposedAttitude, state.getMass());

  589.             acc = contribution.acceleration(shiftedState, parameters);

  590.             //Compute the derivatives of the elements by the speed
  591.             final T[] deriv = MathArrays.buildArray(field, dimension);
  592.             // da/dv
  593.             deriv[0] = getAoV(vel).dotProduct(acc);
  594.             // dex/dv
  595.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  596.             // dey/dv
  597.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  598.             // dhx/dv
  599.             deriv[3] = getQoV(X).dotProduct(acc);
  600.             // dhy/dv
  601.             deriv[4] = getPoV(Y).dotProduct(acc);
  602.             // dλ/dv
  603.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  604.             // Compute mean elements rates
  605.             T[] val = null;
  606.             if (meanMode) {
  607.                 val = MathArrays.buildArray(field, dimension);
  608.                 for (int i = 0; i < 6; i++) {
  609.                     // da<sub>i</sub>/dt
  610.                     val[i] = deriv[i].multiply(roa2);
  611.                 }
  612.             } else {
  613.                 val = MathArrays.buildArray(field, dimension * 2);
  614.                 //Compute cos(j*L) and sin(j*L);
  615.                 final T cosjL = j == 1 ? cosL : FastMath.cos(x.multiply(j));
  616.                 final T sinjL = j == 1 ? sinL : FastMath.sin(x.multiply(j));

  617.                 for (int i = 0; i < 6; i++) {
  618.                     // da<sub>i</sub>/dv * cos(jL)
  619.                     val[i] = deriv[i].multiply(cosjL);
  620.                     // da<sub>i</sub>/dv * sin(jL)
  621.                     val[i + 6] = deriv[i].multiply(sinjL);
  622.                 }
  623.             }

  624.             return val;
  625.         }

  626.         /** Converts true longitude to mean longitude.
  627.          * @param x True longitude
  628.          * @return Eccentric longitude
  629.          */
  630.         private T trueToMean (final T x) {
  631.             return eccentricToMean(trueToEccentric(x));
  632.         }

  633.         /** Converts true longitude to eccentric longitude.
  634.          * @param lv True longitude
  635.          * @return Eccentric longitude
  636.          */
  637.         private T trueToEccentric (final T lv) {
  638.             final T cosLv   = FastMath.cos(lv);
  639.             final T sinLv   = FastMath.sin(lv);
  640.             final T num     = auxiliaryElements.getH().multiply(cosLv).subtract(auxiliaryElements.getK().multiply(sinLv));
  641.             final T den     = auxiliaryElements.getB().add(auxiliaryElements.getK().multiply(cosLv)).add(auxiliaryElements.getH().multiply(sinLv)).add(1.);
  642.             return FastMath.atan(num.divide(den)).multiply(2.).add(lv);
  643.         }

  644.         /** Converts eccentric longitude to mean longitude.
  645.          * @param le Eccentric longitude
  646.          * @return Mean longitude
  647.          */
  648.         private T eccentricToMean (final T le) {
  649.             return le.subtract(auxiliaryElements.getK().multiply(FastMath.sin(le))).add(auxiliaryElements.getH().multiply(FastMath.cos(le)));
  650.         }

  651.         /** Compute δa/δv.
  652.          *  @param vel satellite velocity
  653.          *  @return δa/δv
  654.          */
  655.         private FieldVector3D<T> getAoV(final FieldVector3D<T> vel) {
  656.             return new FieldVector3D<>(context.getTon2a(), vel);
  657.         }

  658.         /** Compute δh/δv.
  659.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  660.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  661.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  662.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  663.          *  @return δh/δv
  664.          */
  665.         private FieldVector3D<T> getHoV(final T X, final T Y, final T Xdot, final T Ydot) {
  666.             final T kf = (Xdot.multiply(Y).multiply(2.).subtract(X.multiply(Ydot))).multiply(context.getOoMU());
  667.             final T kg = X.multiply(Xdot).multiply(context.getOoMU());
  668.             final T kw = auxiliaryElements.getK().multiply(auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X))).multiply(context.getOOAB());
  669.             return new FieldVector3D<>(kf, auxiliaryElements.getVectorF(), kg.negate(), auxiliaryElements.getVectorG(), kw, auxiliaryElements.getVectorW());
  670.         }

  671.         /** Compute δk/δv.
  672.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  673.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  674.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  675.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  676.          *  @return δk/δv
  677.          */
  678.         private FieldVector3D<T> getKoV(final T X, final T Y, final T Xdot, final T Ydot) {
  679.             final T kf = Y.multiply(Ydot).multiply(context.getOoMU());
  680.             final T kg = (X.multiply(Ydot).multiply(2.).subtract(Xdot.multiply(Y))).multiply(context.getOoMU());
  681.             final T kw = auxiliaryElements.getH().multiply(auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X))).multiply(context.getOOAB());
  682.             return new FieldVector3D<>(kf.negate(), auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(), kw.negate(), auxiliaryElements.getVectorW());
  683.         }

  684.         /** Compute δp/δv.
  685.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  686.          *  @return δp/δv
  687.          */
  688.         private FieldVector3D<T> getPoV(final T Y) {
  689.             return new FieldVector3D<>(context.getCo2AB().multiply(Y), auxiliaryElements.getVectorW());
  690.         }

  691.         /** Compute δq/δv.
  692.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  693.          *  @return δq/δv
  694.          */
  695.         private FieldVector3D<T> getQoV(final T X) {
  696.             return new FieldVector3D<>(context.getCo2AB().multiply(X).multiply(I), auxiliaryElements.getVectorW());
  697.         }

  698.         /** Compute δλ/δv.
  699.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  700.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  701.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  702.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  703.          *  @return δλ/δv
  704.          */
  705.         private FieldVector3D<T> getLoV(final T X, final T Y, final T Xdot, final T Ydot) {
  706.             final FieldVector3D<T> pos = new FieldVector3D<>(X, auxiliaryElements.getVectorF(), Y, auxiliaryElements.getVectorG());
  707.             final FieldVector3D<T> v2  = new FieldVector3D<>(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot), auxiliaryElements.getH().negate(), getKoV(X, Y, Xdot, Ydot));
  708.             return new FieldVector3D<>(context.getOOA().multiply(-2.), pos, context.getOoBpo(), v2, context.getOOA().multiply(auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X))), auxiliaryElements.getVectorW());
  709.         }

  710.     }

  711.     /** Internal class for numerical quadrature. */
  712.     private class IntegrableFunction implements UnivariateVectorFunction {

  713.         /** Current state. */
  714.         private final SpacecraftState state;

  715.         /** Signal that this class is used to compute the values required by the mean element variations
  716.          * or by the short periodic element variations. */
  717.         private final boolean meanMode;

  718.         /** The j index.
  719.          * <p>
  720.          * Used only for short periodic variation. Ignored for mean elements variation.
  721.          * </p> */
  722.         private final int j;

  723.         /** Container for attributes. */
  724.         private final AbstractGaussianContributionContext context;

  725.         /** Auxiliary Elements. */
  726.         private final AuxiliaryElements auxiliaryElements;

  727.         /** Drivers for solar radiation and atmospheric drag forces. */
  728.         private final double[] parameters;

  729.         /** Build a new instance.
  730.          *  @param  state current state information: date, kinematics, attitude
  731.          *  @param meanMode if true return the value associated to the mean elements variation,
  732.          *                  if false return the values associated to the short periodic elements variation
  733.          *  @param j the j index. used only for short periodic variation. Ignored for mean elements variation.
  734.          *  @param parameters values of the force model parameters
  735.          */
  736.         IntegrableFunction(final SpacecraftState state,
  737.                            final boolean meanMode,
  738.                            final int j,
  739.                            final double[] parameters) {

  740.             this.meanMode = meanMode;
  741.             this.j = j;
  742.             this.parameters = parameters;
  743.             this.auxiliaryElements = new AuxiliaryElements(state.getOrbit(), I);
  744.             this.context = new AbstractGaussianContributionContext(auxiliaryElements, parameters);
  745.             // remove derivatives from state
  746.             final double[] stateVector = new double[6];
  747.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), PositionAngle.TRUE, stateVector, null);
  748.             final Orbit fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE,
  749.                                                                            state.getDate(),
  750.                                                                            context.getMu(),
  751.                                                                            state.getFrame());
  752.             this.state = new SpacecraftState(fixedOrbit, state.getAttitude(), state.getMass());
  753.         }

  754.         /** {@inheritDoc} */
  755.         @Override
  756.         public double[] value(final double x) {

  757.             //Compute the time difference from the true longitude difference
  758.             final double shiftedLm = trueToMean(x);
  759.             final double dLm = shiftedLm - auxiliaryElements.getLM();
  760.             final double dt = dLm / context.getMeanMotion();

  761.             final double cosL = FastMath.cos(x);
  762.             final double sinL = FastMath.sin(x);
  763.             final double roa  = auxiliaryElements.getB() * auxiliaryElements.getB() / (1. + auxiliaryElements.getH() * sinL + auxiliaryElements.getK() * cosL);
  764.             final double roa2 = roa * roa;
  765.             final double r    = auxiliaryElements.getSma() * roa;
  766.             final double X    = r * cosL;
  767.             final double Y    = r * sinL;
  768.             final double naob = context.getMeanMotion() * auxiliaryElements.getSma() / auxiliaryElements.getB();
  769.             final double Xdot = -naob * (auxiliaryElements.getH() + sinL);
  770.             final double Ydot =  naob * (auxiliaryElements.getK() + cosL);
  771.             final Vector3D vel = new Vector3D(Xdot, auxiliaryElements.getVectorF(), Ydot, auxiliaryElements.getVectorG());

  772.             // Compute acceleration
  773.             Vector3D acc = Vector3D.ZERO;

  774.             // shift the orbit to dt
  775.             final Orbit shiftedOrbit = state.getOrbit().shiftedBy(dt);

  776.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  777.             final Orbit recomposedOrbit =
  778.                             new EquinoctialOrbit(shiftedOrbit.getA(),
  779.                                                  shiftedOrbit.getEquinoctialEx(),
  780.                                                  shiftedOrbit.getEquinoctialEy(),
  781.                                                  shiftedOrbit.getHx(),
  782.                                                  shiftedOrbit.getHy(),
  783.                                                  shiftedOrbit.getLv(),
  784.                                                  PositionAngle.TRUE,
  785.                                                  shiftedOrbit.getFrame(),
  786.                                                  state.getDate(),
  787.                                                  context.getMu());

  788.             // Get the corresponding attitude
  789.             final Attitude recomposedAttitude =
  790.                     attitudeProvider.getAttitude(recomposedOrbit,
  791.                                                  recomposedOrbit.getDate(),
  792.                                                  recomposedOrbit.getFrame());

  793.             // create shifted SpacecraftState with attitude at specified time
  794.             final SpacecraftState shiftedState =
  795.                     new SpacecraftState(recomposedOrbit, recomposedAttitude, state.getMass());

  796.             acc = contribution.acceleration(shiftedState, parameters);

  797.             //Compute the derivatives of the elements by the speed
  798.             final double[] deriv = new double[6];
  799.             // da/dv
  800.             deriv[0] = getAoV(vel).dotProduct(acc);
  801.             // dex/dv
  802.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  803.             // dey/dv
  804.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  805.             // dhx/dv
  806.             deriv[3] = getQoV(X).dotProduct(acc);
  807.             // dhy/dv
  808.             deriv[4] = getPoV(Y).dotProduct(acc);
  809.             // dλ/dv
  810.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  811.             // Compute mean elements rates
  812.             double[] val = null;
  813.             if (meanMode) {
  814.                 val = new double[6];
  815.                 for (int i = 0; i < 6; i++) {
  816.                     // da<sub>i</sub>/dt
  817.                     val[i] = roa2 * deriv[i];
  818.                 }
  819.             } else {
  820.                 val = new double[12];
  821.                 //Compute cos(j*L) and sin(j*L);
  822.                 final double cosjL = j == 1 ? cosL : FastMath.cos(j * x);
  823.                 final double sinjL = j == 1 ? sinL : FastMath.sin(j * x);

  824.                 for (int i = 0; i < 6; i++) {
  825.                     // da<sub>i</sub>/dv * cos(jL)
  826.                     val[i] = cosjL * deriv[i];
  827.                     // da<sub>i</sub>/dv * sin(jL)
  828.                     val[i + 6] = sinjL * deriv[i];
  829.                 }
  830.             }
  831.             return val;
  832.         }

  833.         /** Converts true longitude to eccentric longitude.
  834.          * @param lv True longitude
  835.          * @return Eccentric longitude
  836.          */
  837.         private double trueToEccentric (final double lv) {
  838.             final double cosLv   = FastMath.cos(lv);
  839.             final double sinLv   = FastMath.sin(lv);
  840.             final double num     = auxiliaryElements.getH() * cosLv - auxiliaryElements.getK() * sinLv;
  841.             final double den     = auxiliaryElements.getB() + 1. + auxiliaryElements.getK() * cosLv + auxiliaryElements.getH() * sinLv;
  842.             return lv + 2. * FastMath.atan(num / den);
  843.         }

  844.         /** Converts eccentric longitude to mean longitude.
  845.          * @param le Eccentric longitude
  846.          * @return Mean longitude
  847.          */
  848.         private double eccentricToMean (final double le) {
  849.             return le - auxiliaryElements.getK() * FastMath.sin(le) + auxiliaryElements.getH() * FastMath.cos(le);
  850.         }

  851.         /** Converts true longitude to mean longitude.
  852.          * @param lv True longitude
  853.          * @return Eccentric longitude
  854.          */
  855.         private double trueToMean (final double lv) {
  856.             return eccentricToMean(trueToEccentric(lv));
  857.         }

  858.         /** Compute δa/δv.
  859.          *  @param vel satellite velocity
  860.          *  @return δa/δv
  861.          */
  862.         private Vector3D getAoV(final Vector3D vel) {
  863.             return new Vector3D(context.getTon2a(), vel);
  864.         }

  865.         /** Compute δh/δv.
  866.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  867.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  868.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  869.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  870.          *  @return δh/δv
  871.          */
  872.         private Vector3D getHoV(final double X, final double Y, final double Xdot, final double Ydot) {
  873.             final double kf = (2. * Xdot * Y - X * Ydot) * context.getOoMU();
  874.             final double kg = X * Xdot * context.getOoMU();
  875.             final double kw = auxiliaryElements.getK() * (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOAB();
  876.             return new Vector3D(kf, auxiliaryElements.getVectorF(), -kg, auxiliaryElements.getVectorG(), kw, auxiliaryElements.getVectorW());
  877.         }

  878.         /** Compute δk/δv.
  879.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  880.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  881.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  882.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  883.          *  @return δk/δv
  884.          */
  885.         private Vector3D getKoV(final double X, final double Y, final double Xdot, final double Ydot) {
  886.             final double kf = Y * Ydot * context.getOoMU();
  887.             final double kg = (2. * X * Ydot - Xdot * Y) * context.getOoMU();
  888.             final double kw = auxiliaryElements.getH() * (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOAB();
  889.             return new Vector3D(-kf, auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(), -kw, auxiliaryElements.getVectorW());
  890.         }

  891.         /** Compute δp/δv.
  892.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  893.          *  @return δp/δv
  894.          */
  895.         private Vector3D getPoV(final double Y) {
  896.             return new Vector3D(context.getCo2AB() * Y, auxiliaryElements.getVectorW());
  897.         }

  898.         /** Compute δq/δv.
  899.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  900.          *  @return δq/δv
  901.          */
  902.         private Vector3D getQoV(final double X) {
  903.             return new Vector3D(I * context.getCo2AB() * X, auxiliaryElements.getVectorW());
  904.         }

  905.         /** Compute δλ/δv.
  906.          *  @param X satellite position component along f, equinoctial reference frame 1st vector
  907.          *  @param Y satellite position component along g, equinoctial reference frame 2nd vector
  908.          *  @param Xdot satellite velocity component along f, equinoctial reference frame 1st vector
  909.          *  @param Ydot satellite velocity component along g, equinoctial reference frame 2nd vector
  910.          *  @return δλ/δv
  911.          */
  912.         private Vector3D getLoV(final double X, final double Y, final double Xdot, final double Ydot) {
  913.             final Vector3D pos = new Vector3D(X, auxiliaryElements.getVectorF(), Y, auxiliaryElements.getVectorG());
  914.             final Vector3D v2  = new Vector3D(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot), -auxiliaryElements.getH(), getKoV(X, Y, Xdot, Ydot));
  915.             return new Vector3D(-2. * context.getOOA(), pos, context.getOoBpo(), v2, (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOA(), auxiliaryElements.getVectorW());
  916.         }

  917.     }

  918.     /** Class used to {@link #integrate(UnivariateVectorFunction, double, double) integrate}
  919.      *  a {@link org.hipparchus.analysis.UnivariateVectorFunction function}
  920.      *  of the orbital elements using the Gaussian quadrature rule to get the acceleration.
  921.      */
  922.     private static class GaussQuadrature {

  923.         // Points and weights for the available quadrature orders

  924.         /** Points for quadrature of order 12. */
  925.         private static final double[] P_12 = {
  926.             -0.98156063424671910000,
  927.             -0.90411725637047490000,
  928.             -0.76990267419430470000,
  929.             -0.58731795428661740000,
  930.             -0.36783149899818024000,
  931.             -0.12523340851146890000,
  932.             0.12523340851146890000,
  933.             0.36783149899818024000,
  934.             0.58731795428661740000,
  935.             0.76990267419430470000,
  936.             0.90411725637047490000,
  937.             0.98156063424671910000
  938.         };

  939.         /** Weights for quadrature of order 12. */
  940.         private static final double[] W_12 = {
  941.             0.04717533638651220000,
  942.             0.10693932599531830000,
  943.             0.16007832854334633000,
  944.             0.20316742672306584000,
  945.             0.23349253653835478000,
  946.             0.24914704581340286000,
  947.             0.24914704581340286000,
  948.             0.23349253653835478000,
  949.             0.20316742672306584000,
  950.             0.16007832854334633000,
  951.             0.10693932599531830000,
  952.             0.04717533638651220000
  953.         };

  954.         /** Points for quadrature of order 16. */
  955.         private static final double[] P_16 = {
  956.             -0.98940093499164990000,
  957.             -0.94457502307323260000,
  958.             -0.86563120238783160000,
  959.             -0.75540440835500310000,
  960.             -0.61787624440264380000,
  961.             -0.45801677765722737000,
  962.             -0.28160355077925890000,
  963.             -0.09501250983763745000,
  964.             0.09501250983763745000,
  965.             0.28160355077925890000,
  966.             0.45801677765722737000,
  967.             0.61787624440264380000,
  968.             0.75540440835500310000,
  969.             0.86563120238783160000,
  970.             0.94457502307323260000,
  971.             0.98940093499164990000
  972.         };

  973.         /** Weights for quadrature of order 16. */
  974.         private static final double[] W_16 = {
  975.             0.02715245941175405800,
  976.             0.06225352393864777000,
  977.             0.09515851168249283000,
  978.             0.12462897125553388000,
  979.             0.14959598881657685000,
  980.             0.16915651939500256000,
  981.             0.18260341504492360000,
  982.             0.18945061045506847000,
  983.             0.18945061045506847000,
  984.             0.18260341504492360000,
  985.             0.16915651939500256000,
  986.             0.14959598881657685000,
  987.             0.12462897125553388000,
  988.             0.09515851168249283000,
  989.             0.06225352393864777000,
  990.             0.02715245941175405800
  991.         };

  992.         /** Points for quadrature of order 20. */
  993.         private static final double[] P_20 = {
  994.             -0.99312859918509490000,
  995.             -0.96397192727791390000,
  996.             -0.91223442825132600000,
  997.             -0.83911697182221890000,
  998.             -0.74633190646015080000,
  999.             -0.63605368072651510000,
  1000.             -0.51086700195082700000,
  1001.             -0.37370608871541955000,
  1002.             -0.22778585114164507000,
  1003.             -0.07652652113349734000,
  1004.             0.07652652113349734000,
  1005.             0.22778585114164507000,
  1006.             0.37370608871541955000,
  1007.             0.51086700195082700000,
  1008.             0.63605368072651510000,
  1009.             0.74633190646015080000,
  1010.             0.83911697182221890000,
  1011.             0.91223442825132600000,
  1012.             0.96397192727791390000,
  1013.             0.99312859918509490000
  1014.         };

  1015.         /** Weights for quadrature of order 20. */
  1016.         private static final double[] W_20 = {
  1017.             0.01761400713915226400,
  1018.             0.04060142980038684000,
  1019.             0.06267204833410904000,
  1020.             0.08327674157670477000,
  1021.             0.10193011981724048000,
  1022.             0.11819453196151844000,
  1023.             0.13168863844917678000,
  1024.             0.14209610931838212000,
  1025.             0.14917298647260380000,
  1026.             0.15275338713072600000,
  1027.             0.15275338713072600000,
  1028.             0.14917298647260380000,
  1029.             0.14209610931838212000,
  1030.             0.13168863844917678000,
  1031.             0.11819453196151844000,
  1032.             0.10193011981724048000,
  1033.             0.08327674157670477000,
  1034.             0.06267204833410904000,
  1035.             0.04060142980038684000,
  1036.             0.01761400713915226400
  1037.         };

  1038.         /** Points for quadrature of order 24. */
  1039.         private static final double[] P_24 = {
  1040.             -0.99518721999702130000,
  1041.             -0.97472855597130950000,
  1042.             -0.93827455200273270000,
  1043.             -0.88641552700440100000,
  1044.             -0.82000198597390300000,
  1045.             -0.74012419157855440000,
  1046.             -0.64809365193697550000,
  1047.             -0.54542147138883950000,
  1048.             -0.43379350762604520000,
  1049.             -0.31504267969616340000,
  1050.             -0.19111886747361634000,
  1051.             -0.06405689286260563000,
  1052.             0.06405689286260563000,
  1053.             0.19111886747361634000,
  1054.             0.31504267969616340000,
  1055.             0.43379350762604520000,
  1056.             0.54542147138883950000,
  1057.             0.64809365193697550000,
  1058.             0.74012419157855440000,
  1059.             0.82000198597390300000,
  1060.             0.88641552700440100000,
  1061.             0.93827455200273270000,
  1062.             0.97472855597130950000,
  1063.             0.99518721999702130000
  1064.         };

  1065.         /** Weights for quadrature of order 24. */
  1066.         private static final double[] W_24 = {
  1067.             0.01234122979998733500,
  1068.             0.02853138862893380600,
  1069.             0.04427743881741981000,
  1070.             0.05929858491543691500,
  1071.             0.07334648141108027000,
  1072.             0.08619016153195320000,
  1073.             0.09761865210411391000,
  1074.             0.10744427011596558000,
  1075.             0.11550566805372553000,
  1076.             0.12167047292780335000,
  1077.             0.12583745634682825000,
  1078.             0.12793819534675221000,
  1079.             0.12793819534675221000,
  1080.             0.12583745634682825000,
  1081.             0.12167047292780335000,
  1082.             0.11550566805372553000,
  1083.             0.10744427011596558000,
  1084.             0.09761865210411391000,
  1085.             0.08619016153195320000,
  1086.             0.07334648141108027000,
  1087.             0.05929858491543691500,
  1088.             0.04427743881741981000,
  1089.             0.02853138862893380600,
  1090.             0.01234122979998733500
  1091.         };

  1092.         /** Points for quadrature of order 32. */
  1093.         private static final double[] P_32 = {
  1094.             -0.99726386184948160000,
  1095.             -0.98561151154526840000,
  1096.             -0.96476225558750640000,
  1097.             -0.93490607593773970000,
  1098.             -0.89632115576605220000,
  1099.             -0.84936761373256990000,
  1100.             -0.79448379596794250000,
  1101.             -0.73218211874028970000,
  1102.             -0.66304426693021520000,
  1103.             -0.58771575724076230000,
  1104.             -0.50689990893222950000,
  1105.             -0.42135127613063540000,
  1106.             -0.33186860228212767000,
  1107.             -0.23928736225213710000,
  1108.             -0.14447196158279646000,
  1109.             -0.04830766568773831000,
  1110.             0.04830766568773831000,
  1111.             0.14447196158279646000,
  1112.             0.23928736225213710000,
  1113.             0.33186860228212767000,
  1114.             0.42135127613063540000,
  1115.             0.50689990893222950000,
  1116.             0.58771575724076230000,
  1117.             0.66304426693021520000,
  1118.             0.73218211874028970000,
  1119.             0.79448379596794250000,
  1120.             0.84936761373256990000,
  1121.             0.89632115576605220000,
  1122.             0.93490607593773970000,
  1123.             0.96476225558750640000,
  1124.             0.98561151154526840000,
  1125.             0.99726386184948160000
  1126.         };

  1127.         /** Weights for quadrature of order 32. */
  1128.         private static final double[] W_32 = {
  1129.             0.00701861000947013600,
  1130.             0.01627439473090571200,
  1131.             0.02539206530926214200,
  1132.             0.03427386291302141000,
  1133.             0.04283589802222658600,
  1134.             0.05099805926237621600,
  1135.             0.05868409347853559000,
  1136.             0.06582222277636193000,
  1137.             0.07234579410884862000,
  1138.             0.07819389578707042000,
  1139.             0.08331192422694673000,
  1140.             0.08765209300440380000,
  1141.             0.09117387869576390000,
  1142.             0.09384439908080441000,
  1143.             0.09563872007927487000,
  1144.             0.09654008851472784000,
  1145.             0.09654008851472784000,
  1146.             0.09563872007927487000,
  1147.             0.09384439908080441000,
  1148.             0.09117387869576390000,
  1149.             0.08765209300440380000,
  1150.             0.08331192422694673000,
  1151.             0.07819389578707042000,
  1152.             0.07234579410884862000,
  1153.             0.06582222277636193000,
  1154.             0.05868409347853559000,
  1155.             0.05099805926237621600,
  1156.             0.04283589802222658600,
  1157.             0.03427386291302141000,
  1158.             0.02539206530926214200,
  1159.             0.01627439473090571200,
  1160.             0.00701861000947013600
  1161.         };

  1162.         /** Points for quadrature of order 40. */
  1163.         private static final double[] P_40 = {
  1164.             -0.99823770971055930000,
  1165.             -0.99072623869945710000,
  1166.             -0.97725994998377420000,
  1167.             -0.95791681921379170000,
  1168.             -0.93281280827867660000,
  1169.             -0.90209880696887420000,
  1170.             -0.86595950321225960000,
  1171.             -0.82461223083331170000,
  1172.             -0.77830565142651940000,
  1173.             -0.72731825518992710000,
  1174.             -0.67195668461417960000,
  1175.             -0.61255388966798030000,
  1176.             -0.54946712509512820000,
  1177.             -0.48307580168617870000,
  1178.             -0.41377920437160500000,
  1179.             -0.34199409082575850000,
  1180.             -0.26815218500725370000,
  1181.             -0.19269758070137110000,
  1182.             -0.11608407067525522000,
  1183.             -0.03877241750605081600,
  1184.             0.03877241750605081600,
  1185.             0.11608407067525522000,
  1186.             0.19269758070137110000,
  1187.             0.26815218500725370000,
  1188.             0.34199409082575850000,
  1189.             0.41377920437160500000,
  1190.             0.48307580168617870000,
  1191.             0.54946712509512820000,
  1192.             0.61255388966798030000,
  1193.             0.67195668461417960000,
  1194.             0.72731825518992710000,
  1195.             0.77830565142651940000,
  1196.             0.82461223083331170000,
  1197.             0.86595950321225960000,
  1198.             0.90209880696887420000,
  1199.             0.93281280827867660000,
  1200.             0.95791681921379170000,
  1201.             0.97725994998377420000,
  1202.             0.99072623869945710000,
  1203.             0.99823770971055930000
  1204.         };

  1205.         /** Weights for quadrature of order 40. */
  1206.         private static final double[] W_40 = {
  1207.             0.00452127709853309800,
  1208.             0.01049828453115270400,
  1209.             0.01642105838190797300,
  1210.             0.02224584919416689000,
  1211.             0.02793700698002338000,
  1212.             0.03346019528254786500,
  1213.             0.03878216797447199000,
  1214.             0.04387090818567333000,
  1215.             0.04869580763507221000,
  1216.             0.05322784698393679000,
  1217.             0.05743976909939157000,
  1218.             0.06130624249292891000,
  1219.             0.06480401345660108000,
  1220.             0.06791204581523394000,
  1221.             0.07061164739128681000,
  1222.             0.07288658239580408000,
  1223.             0.07472316905796833000,
  1224.             0.07611036190062619000,
  1225.             0.07703981816424793000,
  1226.             0.07750594797842482000,
  1227.             0.07750594797842482000,
  1228.             0.07703981816424793000,
  1229.             0.07611036190062619000,
  1230.             0.07472316905796833000,
  1231.             0.07288658239580408000,
  1232.             0.07061164739128681000,
  1233.             0.06791204581523394000,
  1234.             0.06480401345660108000,
  1235.             0.06130624249292891000,
  1236.             0.05743976909939157000,
  1237.             0.05322784698393679000,
  1238.             0.04869580763507221000,
  1239.             0.04387090818567333000,
  1240.             0.03878216797447199000,
  1241.             0.03346019528254786500,
  1242.             0.02793700698002338000,
  1243.             0.02224584919416689000,
  1244.             0.01642105838190797300,
  1245.             0.01049828453115270400,
  1246.             0.00452127709853309800
  1247.         };

  1248.         /** Points for quadrature of order 48. */
  1249.         private static final double[] P_48 = {
  1250.             -0.99877100725242610000,
  1251.             -0.99353017226635080000,
  1252.             -0.98412458372282700000,
  1253.             -0.97059159254624720000,
  1254.             -0.95298770316043080000,
  1255.             -0.93138669070655440000,
  1256.             -0.90587913671556960000,
  1257.             -0.87657202027424800000,
  1258.             -0.84358826162439350000,
  1259.             -0.80706620402944250000,
  1260.             -0.76715903251574020000,
  1261.             -0.72403413092381470000,
  1262.             -0.67787237963266400000,
  1263.             -0.62886739677651370000,
  1264.             -0.57722472608397270000,
  1265.             -0.52316097472223300000,
  1266.             -0.46690290475095840000,
  1267.             -0.40868648199071680000,
  1268.             -0.34875588629216070000,
  1269.             -0.28736248735545555000,
  1270.             -0.22476379039468908000,
  1271.             -0.16122235606889174000,
  1272.             -0.09700469920946270000,
  1273.             -0.03238017096286937000,
  1274.             0.03238017096286937000,
  1275.             0.09700469920946270000,
  1276.             0.16122235606889174000,
  1277.             0.22476379039468908000,
  1278.             0.28736248735545555000,
  1279.             0.34875588629216070000,
  1280.             0.40868648199071680000,
  1281.             0.46690290475095840000,
  1282.             0.52316097472223300000,
  1283.             0.57722472608397270000,
  1284.             0.62886739677651370000,
  1285.             0.67787237963266400000,
  1286.             0.72403413092381470000,
  1287.             0.76715903251574020000,
  1288.             0.80706620402944250000,
  1289.             0.84358826162439350000,
  1290.             0.87657202027424800000,
  1291.             0.90587913671556960000,
  1292.             0.93138669070655440000,
  1293.             0.95298770316043080000,
  1294.             0.97059159254624720000,
  1295.             0.98412458372282700000,
  1296.             0.99353017226635080000,
  1297.             0.99877100725242610000
  1298.         };

  1299.         /** Weights for quadrature of order 48. */
  1300.         private static final double[] W_48 = {
  1301.             0.00315334605230596250,
  1302.             0.00732755390127620800,
  1303.             0.01147723457923446900,
  1304.             0.01557931572294386600,
  1305.             0.01961616045735556700,
  1306.             0.02357076083932435600,
  1307.             0.02742650970835688000,
  1308.             0.03116722783279807000,
  1309.             0.03477722256477045000,
  1310.             0.03824135106583080600,
  1311.             0.04154508294346483000,
  1312.             0.04467456085669424000,
  1313.             0.04761665849249054000,
  1314.             0.05035903555385448000,
  1315.             0.05289018948519365000,
  1316.             0.05519950369998416500,
  1317.             0.05727729210040315000,
  1318.             0.05911483969839566000,
  1319.             0.06070443916589384000,
  1320.             0.06203942315989268000,
  1321.             0.06311419228625403000,
  1322.             0.06392423858464817000,
  1323.             0.06446616443595010000,
  1324.             0.06473769681268386000,
  1325.             0.06473769681268386000,
  1326.             0.06446616443595010000,
  1327.             0.06392423858464817000,
  1328.             0.06311419228625403000,
  1329.             0.06203942315989268000,
  1330.             0.06070443916589384000,
  1331.             0.05911483969839566000,
  1332.             0.05727729210040315000,
  1333.             0.05519950369998416500,
  1334.             0.05289018948519365000,
  1335.             0.05035903555385448000,
  1336.             0.04761665849249054000,
  1337.             0.04467456085669424000,
  1338.             0.04154508294346483000,
  1339.             0.03824135106583080600,
  1340.             0.03477722256477045000,
  1341.             0.03116722783279807000,
  1342.             0.02742650970835688000,
  1343.             0.02357076083932435600,
  1344.             0.01961616045735556700,
  1345.             0.01557931572294386600,
  1346.             0.01147723457923446900,
  1347.             0.00732755390127620800,
  1348.             0.00315334605230596250
  1349.         };

  1350.         /** Node points. */
  1351.         private final double[] nodePoints;

  1352.         /** Node weights. */
  1353.         private final double[] nodeWeights;

  1354.         /** Number of points. */
  1355.         private final int numberOfPoints;

  1356.         /** Creates a Gauss integrator of the given order.
  1357.          *
  1358.          *  @param numberOfPoints Order of the integration rule.
  1359.          */
  1360.         GaussQuadrature(final int numberOfPoints) {

  1361.             this.numberOfPoints = numberOfPoints;

  1362.             switch(numberOfPoints) {
  1363.                 case 12 :
  1364.                     this.nodePoints  = P_12.clone();
  1365.                     this.nodeWeights = W_12.clone();
  1366.                     break;
  1367.                 case 16 :
  1368.                     this.nodePoints  = P_16.clone();
  1369.                     this.nodeWeights = W_16.clone();
  1370.                     break;
  1371.                 case 20 :
  1372.                     this.nodePoints  = P_20.clone();
  1373.                     this.nodeWeights = W_20.clone();
  1374.                     break;
  1375.                 case 24 :
  1376.                     this.nodePoints  = P_24.clone();
  1377.                     this.nodeWeights = W_24.clone();
  1378.                     break;
  1379.                 case 32 :
  1380.                     this.nodePoints  = P_32.clone();
  1381.                     this.nodeWeights = W_32.clone();
  1382.                     break;
  1383.                 case 40 :
  1384.                     this.nodePoints  = P_40.clone();
  1385.                     this.nodeWeights = W_40.clone();
  1386.                     break;
  1387.                 case 48 :
  1388.                 default :
  1389.                     this.nodePoints  = P_48.clone();
  1390.                     this.nodeWeights = W_48.clone();
  1391.                     break;
  1392.             }

  1393.         }

  1394.         /** Integrates a given function on the given interval.
  1395.         *
  1396.         *  @param f Function to integrate.
  1397.         *  @param lowerBound Lower bound of the integration interval.
  1398.         *  @param upperBound Upper bound of the integration interval.
  1399.         *  @return the integral of the weighted function.
  1400.         */
  1401.         public double[] integrate(final UnivariateVectorFunction f,
  1402.                final double lowerBound, final double upperBound) {

  1403.             final double[] adaptedPoints  = nodePoints.clone();
  1404.             final double[] adaptedWeights = nodeWeights.clone();
  1405.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1406.             return basicIntegrate(f, adaptedPoints, adaptedWeights);
  1407.         }

  1408.        /** Integrates a given function on the given interval.
  1409.        *
  1410.        *  @param <T> the type of the field elements
  1411.        *  @param f Function to integrate.
  1412.        *  @param lowerBound Lower bound of the integration interval.
  1413.        *  @param upperBound Upper bound of the integration interval.
  1414.        *  @param field field utilized by default
  1415.        *  @return the integral of the weighted function.
  1416.        */
  1417.         public <T extends RealFieldElement<T>> T[] integrate(final RealFieldUnivariateVectorFunction<T> f,
  1418.                                                              final T lowerBound, final T upperBound,
  1419.                                                              final Field<T> field) {

  1420.             final T zero = field.getZero();

  1421.             final T[] adaptedPoints  = MathArrays.buildArray(field, numberOfPoints);
  1422.             final T[] adaptedWeights = MathArrays.buildArray(field, numberOfPoints);;

  1423.             for (int i = 0; i < numberOfPoints; i++) {
  1424.                 adaptedPoints[i]  = zero.add(nodePoints[i]);
  1425.                 adaptedWeights[i] = zero.add(nodeWeights[i]);
  1426.             }

  1427.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1428.             return basicIntegrate(f, adaptedPoints, adaptedWeights, field);
  1429.         }

  1430.         /** Performs a change of variable so that the integration
  1431.          *  can be performed on an arbitrary interval {@code [a, b]}.
  1432.          *  <p>
  1433.          *  It is assumed that the natural interval is {@code [-1, 1]}.
  1434.          *  </p>
  1435.          *
  1436.          * @param points  Points to adapt to the new interval.
  1437.          * @param weights Weights to adapt to the new interval.
  1438.          * @param a Lower bound of the integration interval.
  1439.          * @param b Lower bound of the integration interval.
  1440.          */
  1441.         private void transform(final double[] points, final double[] weights,
  1442.                 final double a, final double b) {
  1443.             // Scaling
  1444.             final double scale = (b - a) / 2;
  1445.             final double shift = a + scale;
  1446.             for (int i = 0; i < points.length; i++) {
  1447.                 points[i]   = points[i] * scale + shift;
  1448.                 weights[i] *= scale;
  1449.             }
  1450.         }

  1451.         /** Performs a change of variable so that the integration
  1452.          *  can be performed on an arbitrary interval {@code [a, b]}.
  1453.          *  <p>
  1454.          *  It is assumed that the natural interval is {@code [-1, 1]}.
  1455.          *  </p>
  1456.          * @param <T> the type of the field elements
  1457.          * @param points  Points to adapt to the new interval.
  1458.          * @param weights Weights to adapt to the new interval.
  1459.          * @param a Lower bound of the integration interval.
  1460.          * @param b Lower bound of the integration interval
  1461.          */
  1462.         private <T extends RealFieldElement<T>> void transform(final T[] points, final T[] weights,
  1463.                 final T a, final T b) {
  1464.             // Scaling
  1465.             final T scale = (b.subtract(a)).divide(2.);
  1466.             final T shift = a.add(scale);
  1467.             for (int i = 0; i < points.length; i++) {
  1468.                 points[i]   = scale.multiply(points[i]).add(shift);
  1469.                 weights[i]  = scale.multiply(weights[i]);
  1470.             }
  1471.         }

  1472.         /** Returns an estimate of the integral of {@code f(x) * w(x)},
  1473.          *  where {@code w} is a weight function that depends on the actual
  1474.          *  flavor of the Gauss integration scheme.
  1475.          *
  1476.          * @param f Function to integrate.
  1477.          * @param points  Nodes.
  1478.          * @param weights Nodes weights.
  1479.          * @return the integral of the weighted function.
  1480.          */
  1481.         private double[] basicIntegrate(final UnivariateVectorFunction f,
  1482.                 final double[] points,
  1483.                 final double[] weights) {
  1484.             double x = points[0];
  1485.             double w = weights[0];
  1486.             double[] v = f.value(x);
  1487.             final double[] y = new double[v.length];
  1488.             for (int j = 0; j < v.length; j++) {
  1489.                 y[j] = w * v[j];
  1490.             }
  1491.             final double[] t = y.clone();
  1492.             final double[] c = new double[v.length];
  1493.             final double[] s = t.clone();
  1494.             for (int i = 1; i < points.length; i++) {
  1495.                 x = points[i];
  1496.                 w = weights[i];
  1497.                 v = f.value(x);
  1498.                 for (int j = 0; j < v.length; j++) {
  1499.                     y[j] = w * v[j] - c[j];
  1500.                     t[j] =  s[j] + y[j];
  1501.                     c[j] = (t[j] - s[j]) - y[j];
  1502.                     s[j] = t[j];
  1503.                 }
  1504.             }
  1505.             return s;
  1506.         }

  1507.         /** Returns an estimate of the integral of {@code f(x) * w(x)},
  1508.          *  where {@code w} is a weight function that depends on the actual
  1509.          *  flavor of the Gauss integration scheme.
  1510.          *
  1511.          * @param <T> the type of the field elements.
  1512.          * @param f Function to integrate.
  1513.          * @param points  Nodes.
  1514.          * @param weights Nodes weight
  1515.          * @param field field utilized by default
  1516.          * @return the integral of the weighted function.
  1517.          */
  1518.         private <T extends RealFieldElement<T>> T[] basicIntegrate(final RealFieldUnivariateVectorFunction<T> f,
  1519.                 final T[] points,
  1520.                 final T[] weights,
  1521.                 final Field<T> field) {

  1522.             T x = points[0];
  1523.             T w = weights[0];
  1524.             T[] v = f.value(x);

  1525.             final T[] y = MathArrays.buildArray(field, v.length);
  1526.             for (int j = 0; j < v.length; j++) {
  1527.                 y[j] = v[j].multiply(w);
  1528.             }
  1529.             final T[] t = y.clone();
  1530.             final T[] c = MathArrays.buildArray(field, v.length);;
  1531.             final T[] s = t.clone();
  1532.             for (int i = 1; i < points.length; i++) {
  1533.                 x = points[i];
  1534.                 w = weights[i];
  1535.                 v = f.value(x);
  1536.                 for (int j = 0; j < v.length; j++) {
  1537.                     y[j] = v[j].multiply(w).subtract(c[j]);
  1538.                     t[j] = y[j].add(s[j]);
  1539.                     c[j] = (t[j].subtract(s[j])).subtract(y[j]);
  1540.                     s[j] = t[j];
  1541.                 }
  1542.             }
  1543.             return s;
  1544.         }

  1545.     }

  1546.     /** Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> coefficients.
  1547.      *  <p>
  1548.      *  Those coefficients are given in Danielson paper by expression 4.4-(6)
  1549.      *  </p>
  1550.      *  @author Petre Bazavan
  1551.      *  @author Lucian Barbulescu
  1552.      */
  1553.     private class FourierCjSjCoefficients {

  1554.         /** Maximum possible value for j. */
  1555.         private final int jMax;

  1556.         /** The C<sub>i</sub><sup>j</sup> coefficients.
  1557.          * <p>
  1558.          * the index i corresponds to the following elements: <br/>
  1559.          * - 0 for a <br>
  1560.          * - 1 for k <br>
  1561.          * - 2 for h <br>
  1562.          * - 3 for q <br>
  1563.          * - 4 for p <br>
  1564.          * - 5 for λ <br>
  1565.          * </p>
  1566.          */
  1567.         private final double[][] cCoef;

  1568.         /** The C<sub>i</sub><sup>j</sup> coefficients.
  1569.          * <p>
  1570.          * the index i corresponds to the following elements: <br/>
  1571.          * - 0 for a <br>
  1572.          * - 1 for k <br>
  1573.          * - 2 for h <br>
  1574.          * - 3 for q <br>
  1575.          * - 4 for p <br>
  1576.          * - 5 for λ <br>
  1577.          * </p>
  1578.          */
  1579.         private final double[][] sCoef;

  1580.         /** Standard constructor.
  1581.          * @param state the current state
  1582.          * @param jMax maximum value for j
  1583.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1584.          * @param parameters values of the force model parameters
  1585.          */
  1586.         FourierCjSjCoefficients(final SpacecraftState state, final int jMax,
  1587.                                 final AuxiliaryElements auxiliaryElements, final double[] parameters) {

  1588.             //Initialise the fields
  1589.             this.jMax = jMax;

  1590.             //Allocate the arrays
  1591.             final int rows = jMax + 1;
  1592.             cCoef = new double[rows][6];
  1593.             sCoef = new double[rows][6];

  1594.             //Compute the coefficients
  1595.             computeCoefficients(state, auxiliaryElements, parameters);
  1596.         }

  1597.         /**
  1598.          * Compute the Fourrier coefficients.
  1599.          * <p>
  1600.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients need to be computed
  1601.          * as D<sub>i</sub><sup>m</sup> is always 0.
  1602.          * </p>
  1603.          * @param state the current state
  1604.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1605.          * @param parameters values of the force model parameters
  1606.          */
  1607.         private void computeCoefficients(final SpacecraftState state,
  1608.                                          final AuxiliaryElements auxiliaryElements,
  1609.                                          final double[] parameters) {

  1610.             // Computes the limits for the integral
  1611.             final double[] ll = getLLimits(state, auxiliaryElements);
  1612.             // Computes integrated mean element rates if Llow < Lhigh
  1613.             if (ll[0] < ll[1]) {
  1614.                 //Compute 1 / PI
  1615.                 final double ooPI = 1 / FastMath.PI;

  1616.                 // loop through all values of j
  1617.                 for (int j = 0; j <= jMax; j++) {
  1618.                     final double[] curentCoefficients =
  1619.                             integrator.integrate(new IntegrableFunction(state, false, j, parameters), ll[0], ll[1]);

  1620.                     //divide by PI and set the values for the coefficients
  1621.                     for (int i = 0; i < 6; i++) {
  1622.                         cCoef[j][i] = ooPI * curentCoefficients[i];
  1623.                         sCoef[j][i] = ooPI * curentCoefficients[i + 6];
  1624.                     }
  1625.                 }
  1626.             }
  1627.         }

  1628.         /** Get the coefficient C<sub>i</sub><sup>j</sup>.
  1629.          * @param i i index - corresponds to the required variation
  1630.          * @param j j index
  1631.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1632.          */
  1633.         public double getCij(final int i, final int j) {
  1634.             return cCoef[j][i];
  1635.         }

  1636.         /** Get the coefficient S<sub>i</sub><sup>j</sup>.
  1637.          * @param i i index - corresponds to the required variation
  1638.          * @param j j index
  1639.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1640.          */
  1641.         public double getSij(final int i, final int j) {
  1642.             return sCoef[j][i];
  1643.         }
  1644.     }

  1645.     /** Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> coefficients with field elements.
  1646.      *  <p>
  1647.      *  Those coefficients are given in Danielson paper by expression 4.4-(6)
  1648.      *  </p>
  1649.      *  @author Petre Bazavan
  1650.      *  @author Lucian Barbulescu
  1651.      */
  1652.     private class FieldFourierCjSjCoefficients <T extends RealFieldElement<T>> {

  1653.         /** Maximum possible value for j. */
  1654.         private final int jMax;

  1655.         /** The C<sub>i</sub><sup>j</sup> coefficients.
  1656.          * <p>
  1657.          * the index i corresponds to the following elements: <br/>
  1658.          * - 0 for a <br>
  1659.          * - 1 for k <br>
  1660.          * - 2 for h <br>
  1661.          * - 3 for q <br>
  1662.          * - 4 for p <br>
  1663.          * - 5 for λ <br>
  1664.          * </p>
  1665.          */
  1666.         private final T[][] cCoef;

  1667.         /** The C<sub>i</sub><sup>j</sup> coefficients.
  1668.          * <p>
  1669.          * the index i corresponds to the following elements: <br/>
  1670.          * - 0 for a <br>
  1671.          * - 1 for k <br>
  1672.          * - 2 for h <br>
  1673.          * - 3 for q <br>
  1674.          * - 4 for p <br>
  1675.          * - 5 for λ <br>
  1676.          * </p>
  1677.          */
  1678.         private final T[][] sCoef;

  1679.         /** Standard constructor.
  1680.          * @param state the current state
  1681.          * @param jMax maximum value for j
  1682.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1683.          * @param parameters values of the force model parameters
  1684.          * @param field field used by default
  1685.          */
  1686.         FieldFourierCjSjCoefficients(final FieldSpacecraftState<T> state, final int jMax,
  1687.                                      final FieldAuxiliaryElements<T> auxiliaryElements,
  1688.                                      final T[] parameters,
  1689.                                      final Field<T> field) {
  1690.             //Initialise the fields
  1691.             this.jMax = jMax;

  1692.             //Allocate the arrays
  1693.             final int rows = jMax + 1;
  1694.             cCoef = MathArrays.buildArray(field, rows, 6);
  1695.             sCoef = MathArrays.buildArray(field, rows, 6);

  1696.             //Compute the coefficients
  1697.             computeCoefficients(state, auxiliaryElements, parameters, field);
  1698.         }

  1699.         /**
  1700.          * Compute the Fourrier coefficients.
  1701.          * <p>
  1702.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients need to be computed
  1703.          * as D<sub>i</sub><sup>m</sup> is always 0.
  1704.          * </p>
  1705.          * @param state the current state
  1706.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1707.          * @param parameters values of the force model parameters
  1708.          * @param field field used by default
  1709.          */
  1710.         private void computeCoefficients(final FieldSpacecraftState<T> state,
  1711.                                          final FieldAuxiliaryElements<T> auxiliaryElements,
  1712.                                          final T[] parameters,
  1713.                                          final Field<T> field) {
  1714.             // Zero
  1715.             final T zero = field.getZero();
  1716.             // Computes the limits for the integral
  1717.             final T[] ll = getLLimits(state, auxiliaryElements);
  1718.             // Computes integrated mean element rates if Llow < Lhigh
  1719.             if (ll[0].getReal() < ll[1].getReal()) {
  1720.                 //Compute 1 / PI
  1721.                 final T ooPI = zero.add(FastMath.PI).reciprocal();

  1722.                 // loop through all values of j
  1723.                 for (int j = 0; j <= jMax; j++) {
  1724.                     final T[] curentCoefficients =
  1725.                             integrator.integrate(new FieldIntegrableFunction<>(state, false, j, parameters, field), ll[0], ll[1], field);

  1726.                     //divide by PI and set the values for the coefficients
  1727.                     for (int i = 0; i < 6; i++) {
  1728.                         cCoef[j][i] = curentCoefficients[i].multiply(ooPI);
  1729.                         sCoef[j][i] = curentCoefficients[i + 6].multiply(ooPI);
  1730.                     }
  1731.                 }
  1732.             }
  1733.         }

  1734.         /** Get the coefficient C<sub>i</sub><sup>j</sup>.
  1735.          * @param i i index - corresponds to the required variation
  1736.          * @param j j index
  1737.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1738.          */
  1739.         public T getCij(final int i, final int j) {
  1740.             return cCoef[j][i];
  1741.         }

  1742.         /** Get the coefficient S<sub>i</sub><sup>j</sup>.
  1743.          * @param i i index - corresponds to the required variation
  1744.          * @param j j index
  1745.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1746.          */
  1747.         public T getSij(final int i, final int j) {
  1748.             return sCoef[j][i];
  1749.         }
  1750.     }

  1751.     /** This class handles the short periodic coefficients described in Danielson 2.5.3-26.
  1752.      *
  1753.      * <p>
  1754.      * The value of M is 0. Also, since the values of the Fourier coefficient D<sub>i</sub><sup>m</sup> is 0
  1755.      * then the values of the coefficients D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1756.      * </p>
  1757.      * @author Petre Bazavan
  1758.      * @author Lucian Barbulescu
  1759.      *
  1760.      */
  1761.     private static class GaussianShortPeriodicCoefficients implements ShortPeriodTerms {

  1762.         /** Maximum value for j index. */
  1763.         private final int jMax;

  1764.         /** Number of points used in the interpolation process. */
  1765.         private final int interpolationPoints;

  1766.         /** Prefix for coefficients keys. */
  1767.         private final String coefficientsKeyPrefix;

  1768.         /** All coefficients slots. */
  1769.         private final transient TimeSpanMap<Slot> slots;

  1770.         /** Constructor.
  1771.          *  @param coefficientsKeyPrefix prefix for coefficients keys
  1772.          *  @param jMax maximum value for j index
  1773.          *  @param interpolationPoints number of points used in the interpolation process
  1774.          *  @param slots all coefficients slots
  1775.          */
  1776.         GaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix,
  1777.                                           final int jMax, final int interpolationPoints,
  1778.                                           final TimeSpanMap<Slot> slots) {
  1779.             //Initialize fields
  1780.             this.jMax                  = jMax;
  1781.             this.interpolationPoints   = interpolationPoints;
  1782.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1783.             this.slots                 = slots;
  1784.         }

  1785.         /** Get the slot valid for some date.
  1786.          * @param meanStates mean states defining the slot
  1787.          * @return slot valid at the specified date
  1788.          */
  1789.         public Slot createSlot(final SpacecraftState... meanStates) {
  1790.             final Slot         slot  = new Slot(jMax, interpolationPoints);
  1791.             final AbsoluteDate first = meanStates[0].getDate();
  1792.             final AbsoluteDate last  = meanStates[meanStates.length - 1].getDate();
  1793.             if (first.compareTo(last) <= 0) {
  1794.                 slots.addValidAfter(slot, first);
  1795.             } else {
  1796.                 slots.addValidBefore(slot, first);
  1797.             }
  1798.             return slot;
  1799.         }

  1800.         /** Compute the short periodic coefficients.
  1801.          *
  1802.          * @param state current state information: date, kinematics, attitude
  1803.          * @param slot coefficients slot
  1804.          * @param fourierCjSj Fourier coefficients
  1805.          * @param uijvij U and V coefficients
  1806.          * @param n Keplerian mean motion
  1807.          * @param a semi major axis
  1808.          */
  1809.         private void computeCoefficients(final SpacecraftState state, final Slot slot,
  1810.                                          final FourierCjSjCoefficients fourierCjSj,
  1811.                                          final UijVijCoefficients uijvij,
  1812.                                          final double n, final double a) {

  1813.             // get the current date
  1814.             final AbsoluteDate date = state.getDate();

  1815.             // compute the k₂⁰ coefficient
  1816.             final double k20 = computeK20(jMax, uijvij.currentRhoSigmaj);

  1817.             // 1. / n
  1818.             final double oon = 1. / n;
  1819.             // 3. / (2 * a * n)
  1820.             final double to2an = 1.5 * oon / a;
  1821.             // 3. / (4 * a * n)
  1822.             final double to4an = to2an / 2;

  1823.             // Compute the coefficients for each element
  1824.             final int size = jMax + 1;
  1825.             final double[]   di1        = new double[6];
  1826.             final double[]   di2        = new double[6];
  1827.             final double[][] currentCij = new double[size][6];
  1828.             final double[][] currentSij = new double[size][6];
  1829.             for (int i = 0; i < 6; i++) {

  1830.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  1831.                 di1[i] = -oon * fourierCjSj.getCij(i, 0);
  1832.                 if (i == 5) {
  1833.                     di1[i] += to2an * uijvij.getU1(0, 0);
  1834.                 }
  1835.                 di2[i] = 0.;
  1836.                 if (i == 5) {
  1837.                     di2[i] += -to4an * fourierCjSj.getCij(0, 0);
  1838.                 }

  1839.                 //the C<sub>i</sub>⁰ is computed based on all others
  1840.                 currentCij[0][i] = -di2[i] * k20;

  1841.                 for (int j = 1; j <= jMax; j++) {
  1842.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  1843.                     currentCij[j][i] = oon * uijvij.getU1(j, i);
  1844.                     if (i == 5) {
  1845.                         currentCij[j][i] += -to2an * uijvij.getU2(j);
  1846.                     }
  1847.                     currentSij[j][i] = oon * uijvij.getV1(j, i);
  1848.                     if (i == 5) {
  1849.                         currentSij[j][i] += -to2an * uijvij.getV2(j);
  1850.                     }

  1851.                     // add the computed coefficients to C<sub>i</sub>⁰
  1852.                     currentCij[0][i] += -(currentCij[j][i] * uijvij.currentRhoSigmaj[0][j] + currentSij[j][i] * uijvij.currentRhoSigmaj[1][j]);
  1853.                 }

  1854.             }

  1855.             // add the values to the interpolators
  1856.             slot.cij[0].addGridPoint(date, currentCij[0]);
  1857.             slot.dij[1].addGridPoint(date, di1);
  1858.             slot.dij[2].addGridPoint(date, di2);
  1859.             for (int j = 1; j <= jMax; j++) {
  1860.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  1861.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  1862.             }

  1863.         }

  1864.         /** Compute the coefficient k₂⁰ by using the equation
  1865.          * 2.5.3-(9a) from Danielson.
  1866.          * <p>
  1867.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  1868.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² + ρ<sub>k</sub>²)]
  1869.          * </p>
  1870.          * @param kMax max value fot k index
  1871.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients
  1872.          * @return the coefficient k₂⁰
  1873.          */
  1874.         private double computeK20(final int kMax, final double[][] currentRhoSigmaj) {
  1875.             double k20 = 0.;

  1876.             for (int kIndex = 1; kIndex <= kMax; kIndex++) {
  1877.                 // After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:
  1878.                 //k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² + ρ<sub>k</sub>²)]
  1879.                 double currentTerm = currentRhoSigmaj[1][kIndex] * currentRhoSigmaj[1][kIndex] +
  1880.                                      currentRhoSigmaj[0][kIndex] * currentRhoSigmaj[0][kIndex];

  1881.                 //multiply by 2 / k²
  1882.                 currentTerm *= 2. / (kIndex * kIndex);

  1883.                 // add the term to the result
  1884.                 k20 += currentTerm;
  1885.             }

  1886.             return k20;
  1887.         }

  1888.         /** {@inheritDoc} */
  1889.         @Override
  1890.         public double[] value(final Orbit meanOrbit) {

  1891.             // select the coefficients slot
  1892.             final Slot slot = slots.get(meanOrbit.getDate());

  1893.             // Get the True longitude L
  1894.             final double L = meanOrbit.getLv();

  1895.             // Compute the center (l - λ)
  1896.             final double center =  L - meanOrbit.getLM();
  1897.             // Compute (l - λ)²
  1898.             final double center2 = center * center;

  1899.             // Initialize short periodic variations
  1900.             final double[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  1901.             final double[] d1 = slot.dij[1].value(meanOrbit.getDate());
  1902.             final double[] d2 = slot.dij[2].value(meanOrbit.getDate());
  1903.             for (int i = 0; i < 6; i++) {
  1904.                 shortPeriodicVariation[i] += center * d1[i] + center2 * d2[i];
  1905.             }

  1906.             for (int j = 1; j <= JMAX; j++) {
  1907.                 final double[] c = slot.cij[j].value(meanOrbit.getDate());
  1908.                 final double[] s = slot.sij[j].value(meanOrbit.getDate());
  1909.                 final double cos = FastMath.cos(j * L);
  1910.                 final double sin = FastMath.sin(j * L);
  1911.                 for (int i = 0; i < 6; i++) {
  1912.                     // add corresponding term to the short periodic variation
  1913.                     shortPeriodicVariation[i] += c[i] * cos;
  1914.                     shortPeriodicVariation[i] += s[i] * sin;
  1915.                 }
  1916.             }

  1917.             return shortPeriodicVariation;

  1918.         }

  1919.         /** {@inheritDoc} */
  1920.         public String getCoefficientsKeyPrefix() {
  1921.             return coefficientsKeyPrefix;
  1922.         }

  1923.         /** {@inheritDoc}
  1924.          * <p>
  1925.          * For Gaussian forces, there are JMAX cj coefficients,
  1926.          * JMAX sj coefficients and 3 dj coefficients. As JMAX = 12,
  1927.          * this sums up to 27 coefficients. The j index is the integer
  1928.          * multiplier for the true longitude argument in the cj and sj
  1929.          * coefficients and to the degree in  the polynomial dj coefficients.
  1930.          * </p>
  1931.          */
  1932.         @Override
  1933.         public Map<String, double[]> getCoefficients(final AbsoluteDate date, final Set<String> selected) {

  1934.             // select the coefficients slot
  1935.             final Slot slot = slots.get(date);

  1936.             final Map<String, double[]> coefficients = new HashMap<String, double[]>(2 * JMAX + 3);
  1937.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  1938.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  1939.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  1940.             for (int j = 1; j <= JMAX; j++) {
  1941.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  1942.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  1943.             }

  1944.             return coefficients;

  1945.         }

  1946.         /** Put a coefficient in a map if selected.
  1947.          * @param map map to populate
  1948.          * @param selected set of coefficients that should be put in the map
  1949.          * (empty set means all coefficients are selected)
  1950.          * @param value coefficient value
  1951.          * @param id coefficient identifier
  1952.          * @param indices list of coefficient indices
  1953.          */
  1954.         private void storeIfSelected(final Map<String, double[]> map, final Set<String> selected,
  1955.                                      final double[] value, final String id, final int... indices) {
  1956.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  1957.             keyBuilder.append(id);
  1958.             for (int index : indices) {
  1959.                 keyBuilder.append('[').append(index).append(']');
  1960.             }
  1961.             final String key = keyBuilder.toString();
  1962.             if (selected.isEmpty() || selected.contains(key)) {
  1963.                 map.put(key, value);
  1964.             }
  1965.         }

  1966.     }

  1967.      /** This class handles the short periodic coefficients described in Danielson 2.5.3-26.
  1968.      *
  1969.      * <p>
  1970.      * The value of M is 0. Also, since the values of the Fourier coefficient D<sub>i</sub><sup>m</sup> is 0
  1971.      * then the values of the coefficients D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1972.      * </p>
  1973.      * @author Petre Bazavan
  1974.      * @author Lucian Barbulescu
  1975.      *
  1976.      */
  1977.     private static class FieldGaussianShortPeriodicCoefficients <T extends RealFieldElement<T>> implements FieldShortPeriodTerms<T> {

  1978.         /** Maximum value for j index. */
  1979.         private final int jMax;

  1980.         /** Number of points used in the interpolation process. */
  1981.         private final int interpolationPoints;

  1982.         /** Prefix for coefficients keys. */
  1983.         private final String coefficientsKeyPrefix;

  1984.         /** All coefficients slots. */
  1985.         private final transient FieldTimeSpanMap<FieldSlot<T>, T> slots;

  1986.         /** Constructor.
  1987.          *  @param coefficientsKeyPrefix prefix for coefficients keys
  1988.          *  @param jMax maximum value for j index
  1989.          *  @param interpolationPoints number of points used in the interpolation process
  1990.          *  @param slots all coefficients slots
  1991.          */
  1992.         FieldGaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix,
  1993.                                                final int jMax, final int interpolationPoints,
  1994.                                                final FieldTimeSpanMap<FieldSlot<T>, T> slots) {
  1995.             //Initialize fields
  1996.             this.jMax                  = jMax;
  1997.             this.interpolationPoints   = interpolationPoints;
  1998.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1999.             this.slots                 = slots;
  2000.         }

  2001.         /** Get the slot valid for some date.
  2002.          * @param meanStates mean states defining the slot
  2003.          * @return slot valid at the specified date
  2004.          */
  2005.         @SuppressWarnings("unchecked")
  2006.         public FieldSlot<T> createSlot(final FieldSpacecraftState<T>... meanStates) {
  2007.             final FieldSlot<T>         slot  = new FieldSlot<>(jMax, interpolationPoints);
  2008.             final FieldAbsoluteDate<T> first = meanStates[0].getDate();
  2009.             final FieldAbsoluteDate<T> last  = meanStates[meanStates.length - 1].getDate();
  2010.             if (first.compareTo(last) <= 0) {
  2011.                 slots.addValidAfter(slot, first);
  2012.             } else {
  2013.                 slots.addValidBefore(slot, first);
  2014.             }
  2015.             return slot;
  2016.         }

  2017.         /** Compute the short periodic coefficients.
  2018.          *
  2019.          * @param state current state information: date, kinematics, attitude
  2020.          * @param slot coefficients slot
  2021.          * @param fourierCjSj Fourier coefficients
  2022.          * @param uijvij U and V coefficients
  2023.          * @param n Keplerian mean motion
  2024.          * @param a semi major axis
  2025.          * @param field field used by default
  2026.          */
  2027.         private void computeCoefficients(final FieldSpacecraftState<T> state, final FieldSlot<T> slot,
  2028.                                          final FieldFourierCjSjCoefficients<T> fourierCjSj,
  2029.                                          final FieldUijVijCoefficients<T> uijvij,
  2030.                                          final T n, final T a,
  2031.                                          final Field<T> field) {

  2032.             // Zero
  2033.             final T zero = field.getZero();

  2034.             // get the current date
  2035.             final FieldAbsoluteDate<T> date = state.getDate();

  2036.             // compute the k₂⁰ coefficient
  2037.             final T k20 = computeK20(jMax, uijvij.currentRhoSigmaj, field);

  2038.             // 1. / n
  2039.             final T oon = n.reciprocal();
  2040.             // 3. / (2 * a * n)
  2041.             final T to2an = oon.multiply(1.5).divide(a);
  2042.             // 3. / (4 * a * n)
  2043.             final T to4an = to2an.divide(2.);

  2044.             // Compute the coefficients for each element
  2045.             final int size = jMax + 1;
  2046.             final T[]   di1        = MathArrays.buildArray(field, 6);
  2047.             final T[]   di2        = MathArrays.buildArray(field, 6);
  2048.             final T[][] currentCij = MathArrays.buildArray(field, size, 6);
  2049.             final T[][] currentSij = MathArrays.buildArray(field, size, 6);
  2050.             for (int i = 0; i < 6; i++) {

  2051.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  2052.                 di1[i] = oon.negate().multiply(fourierCjSj.getCij(i, 0));
  2053.                 if (i == 5) {
  2054.                     di1[i] = di1[i].add(to2an.multiply(uijvij.getU1(0, 0)));
  2055.                 }
  2056.                 di2[i] = zero;
  2057.                 if (i == 5) {
  2058.                     di2[i] = di2[i].add(to4an.negate().multiply(fourierCjSj.getCij(0, 0)));
  2059.                 }

  2060.                 //the C<sub>i</sub>⁰ is computed based on all others
  2061.                 currentCij[0][i] = di2[i].negate().multiply(k20);

  2062.                 for (int j = 1; j <= jMax; j++) {
  2063.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  2064.                     currentCij[j][i] = oon.multiply(uijvij.getU1(j, i));
  2065.                     if (i == 5) {
  2066.                         currentCij[j][i] = currentCij[j][i].add(to2an.negate().multiply(uijvij.getU2(j)));
  2067.                     }
  2068.                     currentSij[j][i] = oon.multiply(uijvij.getV1(j, i));
  2069.                     if (i == 5) {
  2070.                         currentSij[j][i] = currentSij[j][i].add(to2an.negate().multiply(uijvij.getV2(j)));
  2071.                     }

  2072.                     // add the computed coefficients to C<sub>i</sub>⁰
  2073.                     currentCij[0][i] = currentCij[0][i].add(currentCij[j][i].multiply(uijvij.currentRhoSigmaj[0][j]).add(currentSij[j][i].multiply(uijvij.currentRhoSigmaj[1][j])).negate());
  2074.                 }

  2075.             }

  2076.             // add the values to the interpolators
  2077.             slot.cij[0].addGridPoint(date, currentCij[0]);
  2078.             slot.dij[1].addGridPoint(date, di1);
  2079.             slot.dij[2].addGridPoint(date, di2);
  2080.             for (int j = 1; j <= jMax; j++) {
  2081.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  2082.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  2083.             }

  2084.         }

  2085.         /** Compute the coefficient k₂⁰ by using the equation
  2086.          * 2.5.3-(9a) from Danielson.
  2087.          * <p>
  2088.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  2089.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² + ρ<sub>k</sub>²)]
  2090.          * </p>
  2091.          * @param kMax max value fot k index
  2092.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients
  2093.          * @param field field used by default
  2094.          * @return the coefficient k₂⁰
  2095.          */
  2096.         private T computeK20(final int kMax, final T[][] currentRhoSigmaj, final Field<T> field) {
  2097.             final T zero = field.getZero();
  2098.             T k20 = zero;

  2099.             for (int kIndex = 1; kIndex <= kMax; kIndex++) {
  2100.                 // After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:
  2101.                 //k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² + ρ<sub>k</sub>²)]
  2102.                 T currentTerm = currentRhoSigmaj[1][kIndex].multiply(currentRhoSigmaj[1][kIndex]).
  2103.                                 add(currentRhoSigmaj[0][kIndex].multiply(currentRhoSigmaj[0][kIndex]));

  2104.                 //multiply by 2 / k²
  2105.                 currentTerm = currentTerm.multiply(2. / (kIndex * kIndex));

  2106.                 // add the term to the result
  2107.                 k20 = k20.add(currentTerm);
  2108.             }

  2109.             return k20;
  2110.         }

  2111.         /** {@inheritDoc} */
  2112.         @Override
  2113.         public T[] value(final FieldOrbit<T> meanOrbit) {

  2114.             // select the coefficients slot
  2115.             final FieldSlot<T> slot = slots.get(meanOrbit.getDate());

  2116.             // Get the True longitude L
  2117.             final T L = meanOrbit.getLv();

  2118.             // Compute the center (l - λ)
  2119.             final T center =  L.subtract(meanOrbit.getLM());
  2120.             // Compute (l - λ)²
  2121.             final T center2 = center.multiply(center);

  2122.             // Initialize short periodic variations
  2123.             final T[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  2124.             final T[] d1 = slot.dij[1].value(meanOrbit.getDate());
  2125.             final T[] d2 = slot.dij[2].value(meanOrbit.getDate());
  2126.             for (int i = 0; i < 6; i++) {
  2127.                 shortPeriodicVariation[i] = shortPeriodicVariation[i].add(center.multiply(d1[i]).add(center2.multiply(d2[i])));
  2128.             }

  2129.             for (int j = 1; j <= JMAX; j++) {
  2130.                 final T[] c = slot.cij[j].value(meanOrbit.getDate());
  2131.                 final T[] s = slot.sij[j].value(meanOrbit.getDate());
  2132.                 final T cos = FastMath.cos(L.multiply(j));
  2133.                 final T sin = FastMath.sin(L.multiply(j));
  2134.                 for (int i = 0; i < 6; i++) {
  2135.                     // add corresponding term to the short periodic variation
  2136.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(c[i].multiply(cos));
  2137.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(s[i].multiply(sin));
  2138.                 }
  2139.             }

  2140.             return shortPeriodicVariation;

  2141.         }

  2142.         /** {@inheritDoc} */
  2143.         public String getCoefficientsKeyPrefix() {
  2144.             return coefficientsKeyPrefix;
  2145.         }

  2146.         /** {@inheritDoc}
  2147.          * <p>
  2148.          * For Gaussian forces, there are JMAX cj coefficients,
  2149.          * JMAX sj coefficients and 3 dj coefficients. As JMAX = 12,
  2150.          * this sums up to 27 coefficients. The j index is the integer
  2151.          * multiplier for the true longitude argument in the cj and sj
  2152.          * coefficients and to the degree in  the polynomial dj coefficients.
  2153.          * </p>
  2154.          */
  2155.         @Override
  2156.         public Map<String, T[]> getCoefficients(final FieldAbsoluteDate<T> date, final Set<String> selected) {

  2157.             // select the coefficients slot
  2158.             final FieldSlot<T> slot = slots.get(date);

  2159.             final Map<String, T[]> coefficients = new HashMap<String, T[]>(2 * JMAX + 3);
  2160.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  2161.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  2162.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  2163.             for (int j = 1; j <= JMAX; j++) {
  2164.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  2165.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  2166.             }

  2167.             return coefficients;

  2168.         }

  2169.         /** Put a coefficient in a map if selected.
  2170.          * @param map map to populate
  2171.          * @param selected set of coefficients that should be put in the map
  2172.          * (empty set means all coefficients are selected)
  2173.          * @param value coefficient value
  2174.          * @param id coefficient identifier
  2175.          * @param indices list of coefficient indices
  2176.          */
  2177.         private void storeIfSelected(final Map<String, T[]> map, final Set<String> selected,
  2178.                                      final T[] value, final String id, final int... indices) {
  2179.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  2180.             keyBuilder.append(id);
  2181.             for (int index : indices) {
  2182.                 keyBuilder.append('[').append(index).append(']');
  2183.             }
  2184.             final String key = keyBuilder.toString();
  2185.             if (selected.isEmpty() || selected.contains(key)) {
  2186.                 map.put(key, value);
  2187.             }
  2188.         }

  2189.     }


  2190.     /** The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients described by
  2191.      * equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2192.      * <p>
  2193.      * The index i takes only the values 1 and 2<br>
  2194.      * For U only the index 0 for j is used.
  2195.      * </p>
  2196.      *
  2197.      * @author Petre Bazavan
  2198.      * @author Lucian Barbulescu
  2199.      */
  2200.     private static class UijVijCoefficients {

  2201.         /** The U₁<sup>j</sup> coefficients.
  2202.          * <p>
  2203.          * The first index identifies the Fourier coefficients used<br>
  2204.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup><br>
  2205.          * The only exception is when j = 0 when only the coefficient for fourier index = 1 (i == 0) is needed.<br>
  2206.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed, because are required
  2207.          * to compute the coefficients U₂<sup>j</sup>
  2208.          * </p>
  2209.          */
  2210.         private final double[][] u1ij;

  2211.         /** The V₁<sup>j</sup> coefficients.
  2212.          * <p>
  2213.          * The first index identifies the Fourier coefficients used<br>
  2214.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup><br>
  2215.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed, because are required
  2216.          * to compute the coefficients V₂<sup>j</sup>
  2217.          * </p>
  2218.          */
  2219.         private final double[][] v1ij;

  2220.         /** The U₂<sup>j</sup> coefficients.
  2221.          * <p>
  2222.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as they are the only ones required.
  2223.          * </p>
  2224.          */
  2225.         private final double[] u2ij;

  2226.         /** The V₂<sup>j</sup> coefficients.
  2227.          * <p>
  2228.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as they are the only ones required.
  2229.          * </p>
  2230.          */
  2231.         private final double[] v2ij;

  2232.         /** The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients. */
  2233.         private final double[][] currentRhoSigmaj;

  2234.         /** The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier coefficients. */
  2235.         private final FourierCjSjCoefficients fourierCjSj;

  2236.         /** The maximum value for j index. */
  2237.         private final int jMax;

  2238.         /** Constructor.
  2239.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients
  2240.          * @param fourierCjSj the fourier coefficients C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  2241.          * @param jMax maximum value for j index
  2242.          */
  2243.         UijVijCoefficients(final double[][] currentRhoSigmaj, final FourierCjSjCoefficients fourierCjSj, final int jMax) {
  2244.             this.currentRhoSigmaj = currentRhoSigmaj;
  2245.             this.fourierCjSj = fourierCjSj;
  2246.             this.jMax = jMax;

  2247.             // initialize the internal arrays.
  2248.             this.u1ij = new double[6][2 * jMax + 1];
  2249.             this.v1ij = new double[6][2 * jMax + 1];
  2250.             this.u2ij = new double[jMax + 1];
  2251.             this.v2ij = new double[jMax + 1];

  2252.             //compute the coefficients
  2253.             computeU1V1Coefficients();
  2254.             computeU2V2Coefficients();
  2255.         }

  2256.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients. */
  2257.         private void computeU1V1Coefficients() {
  2258.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2259.             // for j >= 1
  2260.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2261.             u1ij[0][0] = 0;
  2262.             for (int j = 1; j <= jMax; j++) {
  2263.                 // compute 1 / j
  2264.                 final double ooj = 1. / j;

  2265.                 for (int i = 0; i < 6; i++) {
  2266.                     //j is aready between 1 and J
  2267.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2268.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2269.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2270.                     if (j > 1) {
  2271.                         // k starts with 1 because j-J is less than or equal to 0
  2272.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2273.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2274.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2275.                             u1ij[i][j] +=   fourierCjSj.getCij(i, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2276.                                             fourierCjSj.getSij(i, j - kIndex) * currentRhoSigmaj[0][kIndex];

  2277.                             // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2278.                             // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2279.                             v1ij[i][j] +=   fourierCjSj.getCij(i, j - kIndex) * currentRhoSigmaj[0][kIndex] -
  2280.                                             fourierCjSj.getSij(i, j - kIndex) * currentRhoSigmaj[1][kIndex];
  2281.                         }
  2282.                     }

  2283.                     // since j must be between 1 and J-1 and is already between 1 and J
  2284.                     // the following sum is skiped only for j = jMax
  2285.                     if (j != jMax) {
  2286.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2287.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2288.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2289.                             u1ij[i][j] +=   -fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[1][kIndex] +
  2290.                                             fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[0][kIndex];

  2291.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2292.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2293.                             v1ij[i][j] +=   fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[0][kIndex] +
  2294.                                             fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[1][kIndex];
  2295.                         }
  2296.                     }

  2297.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2298.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2299.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2300.                         u1ij[i][j] +=   -fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2301.                                         fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2302.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2303.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2304.                         v1ij[i][j] +=   fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2305.                                         fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2306.                     }

  2307.                     // divide by 1 / j
  2308.                     u1ij[i][j] *= -ooj;
  2309.                     v1ij[i][j] *= ooj;

  2310.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2311.                     if (i == 0) {
  2312.                         //- (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2313.                         u1ij[0][0] += -u1ij[0][j] * currentRhoSigmaj[0][j] - v1ij[0][j] * currentRhoSigmaj[1][j];
  2314.                     }
  2315.                 }
  2316.             }

  2317.             // Terms with j > jMax are required only when computing the coefficients
  2318.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2319.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2320.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2321.                 // compute 1 / j
  2322.                 final double ooj = 1. / j;
  2323.                 //the value of i is 0
  2324.                 u1ij[0][j] = 0.;
  2325.                 v1ij[0][j] = 0.;

  2326.                 //k starts from j-J as it is always greater than or equal to 1
  2327.                 for (int kIndex = j - jMax; kIndex <= j - 1; kIndex++) {
  2328.                     // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2329.                     // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2330.                     u1ij[0][j] +=   fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2331.                                     fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[0][kIndex];

  2332.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2333.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2334.                     v1ij[0][j] +=   fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[0][kIndex] -
  2335.                                     fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[1][kIndex];
  2336.                 }
  2337.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2338.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2339.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2340.                     u1ij[0][j] +=   -fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2341.                                     fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2342.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2343.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2344.                     v1ij[0][j] +=   fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2345.                                     fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2346.                 }

  2347.                 // divide by 1 / j
  2348.                 u1ij[0][j] *= -ooj;
  2349.                 v1ij[0][j] *= ooj;
  2350.             }
  2351.         }

  2352.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2353.          * <p>
  2354.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2355.          * </p>
  2356.          */
  2357.         private void computeU2V2Coefficients() {
  2358.             for (int j = 1; j <= jMax; j++) {
  2359.                 // compute 1 / j
  2360.                 final double ooj = 1. / j;

  2361.                 // only the values for i == 0 are computed
  2362.                 u2ij[j] = v1ij[0][j];
  2363.                 v2ij[j] = u1ij[0][j];

  2364.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2365.                 if (j > 1) {
  2366.                     for (int l = 1; l <= j - 1; l++) {
  2367.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2368.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2369.                         u2ij[j] +=   u1ij[0][j - l] * currentRhoSigmaj[1][l] +
  2370.                                      v1ij[0][j - l] * currentRhoSigmaj[0][l];

  2371.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2372.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2373.                         v2ij[j] +=   u1ij[0][j - l] * currentRhoSigmaj[0][l] -
  2374.                                      v1ij[0][j - l] * currentRhoSigmaj[1][l];
  2375.                     }
  2376.                 }

  2377.                 for (int l = 1; l <= jMax; l++) {
  2378.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2379.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2380.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2381.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2382.                     u2ij[j] +=   -u1ij[0][j + l] * currentRhoSigmaj[1][l] +
  2383.                                   u1ij[0][l] * currentRhoSigmaj[1][j + l] +
  2384.                                   v1ij[0][j + l] * currentRhoSigmaj[0][l] -
  2385.                                   v1ij[0][l] * currentRhoSigmaj[0][j + l];

  2386.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2387.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2388.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2389.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2390.                     u2ij[j] +=   u1ij[0][j + l] * currentRhoSigmaj[0][l] +
  2391.                                  u1ij[0][l] * currentRhoSigmaj[0][j + l] +
  2392.                                  v1ij[0][j + l] * currentRhoSigmaj[1][l] +
  2393.                                  v1ij[0][l] * currentRhoSigmaj[1][j + l];
  2394.                 }

  2395.                 // divide by 1 / j
  2396.                 u2ij[j] *= -ooj;
  2397.                 v2ij[j] *= ooj;
  2398.             }
  2399.         }

  2400.         /** Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2401.          *
  2402.          * @param j j index
  2403.          * @param i Fourier index (starts at 0)
  2404.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2405.          */
  2406.         public double getU1(final int j, final int i) {
  2407.             return u1ij[i][j];
  2408.         }

  2409.         /** Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2410.          *
  2411.          * @param j j index
  2412.          * @param i Fourier index (starts at 0)
  2413.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2414.          */
  2415.         public double getV1(final int j, final int i) {
  2416.             return v1ij[i][j];
  2417.         }

  2418.         /** Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2419.          *
  2420.          * @param j j index
  2421.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2422.          */
  2423.         public double getU2(final int j) {
  2424.             return u2ij[j];
  2425.         }

  2426.         /** Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2427.          *
  2428.          * @param j j index
  2429.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2430.          */
  2431.         public double getV2(final int j) {
  2432.             return v2ij[j];
  2433.         }
  2434.     }

  2435.     /** The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients described by
  2436.      * equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2437.      * <p>
  2438.      * The index i takes only the values 1 and 2<br>
  2439.      * For U only the index 0 for j is used.
  2440.      * </p>
  2441.      *
  2442.      * @author Petre Bazavan
  2443.      * @author Lucian Barbulescu
  2444.      */
  2445.     private static class FieldUijVijCoefficients <T extends RealFieldElement<T>> {

  2446.         /** The U₁<sup>j</sup> coefficients.
  2447.          * <p>
  2448.          * The first index identifies the Fourier coefficients used<br>
  2449.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup><br>
  2450.          * The only exception is when j = 0 when only the coefficient for fourier index = 1 (i == 0) is needed.<br>
  2451.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed, because are required
  2452.          * to compute the coefficients U₂<sup>j</sup>
  2453.          * </p>
  2454.          */
  2455.         private final T[][] u1ij;

  2456.         /** The V₁<sup>j</sup> coefficients.
  2457.          * <p>
  2458.          * The first index identifies the Fourier coefficients used<br>
  2459.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup><br>
  2460.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed, because are required
  2461.          * to compute the coefficients V₂<sup>j</sup>
  2462.          * </p>
  2463.          */
  2464.         private final T[][] v1ij;

  2465.         /** The U₂<sup>j</sup> coefficients.
  2466.          * <p>
  2467.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as they are the only ones required.
  2468.          * </p>
  2469.          */
  2470.         private final T[] u2ij;

  2471.         /** The V₂<sup>j</sup> coefficients.
  2472.          * <p>
  2473.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as they are the only ones required.
  2474.          * </p>
  2475.          */
  2476.         private final T[] v2ij;

  2477.         /** The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients. */
  2478.         private final T[][] currentRhoSigmaj;

  2479.         /** The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier coefficients. */
  2480.         private final FieldFourierCjSjCoefficients<T> fourierCjSj;

  2481.         /** The maximum value for j index. */
  2482.         private final int jMax;

  2483.         /** Constructor.
  2484.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and σ<sub>j</sub> coefficients
  2485.          * @param fourierCjSj the fourier coefficients C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  2486.          * @param jMax maximum value for j index
  2487.          * @param field field used by default
  2488.          */
  2489.         FieldUijVijCoefficients(final T[][] currentRhoSigmaj,
  2490.                                 final FieldFourierCjSjCoefficients<T> fourierCjSj,
  2491.                                 final int jMax,
  2492.                                 final Field<T> field) {
  2493.             this.currentRhoSigmaj = currentRhoSigmaj;
  2494.             this.fourierCjSj = fourierCjSj;
  2495.             this.jMax = jMax;

  2496.             // initialize the internal arrays.
  2497.             this.u1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2498.             this.v1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2499.             this.u2ij = MathArrays.buildArray(field, jMax + 1);
  2500.             this.v2ij = MathArrays.buildArray(field, jMax + 1);

  2501.             //compute the coefficients
  2502.             computeU1V1Coefficients(field);
  2503.             computeU2V2Coefficients(field);
  2504.         }

  2505.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2506.          * @param field field used by default
  2507.          */
  2508.         private void computeU1V1Coefficients(final Field<T> field) {
  2509.             // Zero
  2510.             final T zero = field.getZero();

  2511.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2512.             // for j >= 1
  2513.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2514.             u1ij[0][0] = zero;
  2515.             for (int j = 1; j <= jMax; j++) {
  2516.                 // compute 1 / j
  2517.                 final double ooj = 1. / j;

  2518.                 for (int i = 0; i < 6; i++) {
  2519.                     //j is aready between 1 and J
  2520.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2521.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2522.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2523.                     if (j > 1) {
  2524.                         // k starts with 1 because j-J is less than or equal to 0
  2525.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2526.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2527.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2528.                             u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, j - kIndex).multiply(currentRhoSigmaj[1][kIndex]).
  2529.                                          add(fourierCjSj.getSij(i, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2530.                             // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2531.                             // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2532.                             v1ij[i][j] = v1ij[i][j].add(fourierCjSj.getCij(i, j - kIndex).multiply(currentRhoSigmaj[0][kIndex]).
  2533.                                          subtract(fourierCjSj.getSij(i, j - kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2534.                         }
  2535.                     }

  2536.                     // since j must be between 1 and J-1 and is already between 1 and J
  2537.                     // the following sum is skiped only for j = jMax
  2538.                     if (j != jMax) {
  2539.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2540.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2541.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2542.                             u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, j + kIndex).negate().multiply(currentRhoSigmaj[1][kIndex]).
  2543.                                          add(fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2544.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2545.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2546.                             v1ij[i][j] = v1ij[i][j].add(fourierCjSj.getCij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex]).
  2547.                                          add(fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2548.                         }
  2549.                     }

  2550.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2551.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2552.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2553.                         u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, kIndex).negate().multiply(currentRhoSigmaj[1][j + kIndex]).
  2554.                                      subtract(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2555.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2556.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2557.                         v1ij[i][j] = v1ij[i][j].add(fourierCjSj.getCij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex]).
  2558.                                      add(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2559.                     }

  2560.                     // divide by 1 / j
  2561.                     u1ij[i][j] = u1ij[i][j].multiply(-ooj);
  2562.                     v1ij[i][j] = v1ij[i][j].multiply(ooj);

  2563.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2564.                     if (i == 0) {
  2565.                         //- (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2566.                         u1ij[0][0] = u1ij[0][0].add(u1ij[0][j].negate().multiply(currentRhoSigmaj[0][j]).subtract(v1ij[0][j].multiply(currentRhoSigmaj[1][j])));
  2567.                     }
  2568.                 }
  2569.             }

  2570.             // Terms with j > jMax are required only when computing the coefficients
  2571.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2572.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2573.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2574.                 // compute 1 / j
  2575.                 final double ooj = 1. / j;
  2576.                 //the value of i is 0
  2577.                 u1ij[0][j] = zero;
  2578.                 v1ij[0][j] = zero;

  2579.                 //k starts from j-J as it is always greater than or equal to 1
  2580.                 for (int kIndex = j - jMax; kIndex <= j - 1; kIndex++) {
  2581.                     // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2582.                     // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2583.                     u1ij[0][j] = u1ij[0][j].add(fourierCjSj.getCij(0, j - kIndex).multiply(currentRhoSigmaj[1][kIndex]).
  2584.                                  add(fourierCjSj.getSij(0, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2585.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2586.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2587.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, j - kIndex).multiply(currentRhoSigmaj[0][kIndex]).
  2588.                                  subtract(fourierCjSj.getSij(0, j - kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2589.                 }
  2590.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2591.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2592.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2593.                     u1ij[0][j] = u1ij[0][j].add(fourierCjSj.getCij(0, kIndex).negate().multiply(currentRhoSigmaj[1][j + kIndex]).
  2594.                                  subtract(fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2595.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2596.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2597.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex]).add(
  2598.                                  fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2599.                 }

  2600.                 // divide by 1 / j
  2601.                 u1ij[0][j] = u1ij[0][j].multiply(-ooj);
  2602.                 v1ij[0][j] = v1ij[0][j].multiply(ooj);
  2603.             }
  2604.         }

  2605.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2606.          * <p>
  2607.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2608.          * </p>
  2609.          * @param field field used by default
  2610.          */
  2611.         private void computeU2V2Coefficients(final Field<T> field) {
  2612.             for (int j = 1; j <= jMax; j++) {
  2613.                 // compute 1 / j
  2614.                 final double ooj = 1. / j;

  2615.                 // only the values for i == 0 are computed
  2616.                 u2ij[j] = v1ij[0][j];
  2617.                 v2ij[j] = u1ij[0][j];

  2618.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2619.                 if (j > 1) {
  2620.                     for (int l = 1; l <= j - 1; l++) {
  2621.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2622.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2623.                         u2ij[j] = u2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[1][l]).
  2624.                                   add(v1ij[0][j - l].multiply(currentRhoSigmaj[0][l])));

  2625.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2626.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2627.                         v2ij[j] = v2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[0][l]).
  2628.                                   subtract(v1ij[0][j - l].multiply(currentRhoSigmaj[1][l])));
  2629.                     }
  2630.                 }

  2631.                 for (int l = 1; l <= jMax; l++) {
  2632.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2633.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2634.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2635.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2636.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].negate().multiply(currentRhoSigmaj[1][l]).
  2637.                               add(u1ij[0][l].multiply(currentRhoSigmaj[1][j + l])).
  2638.                               add(v1ij[0][j + l].multiply(currentRhoSigmaj[0][l])).
  2639.                               subtract(v1ij[0][l].multiply(currentRhoSigmaj[0][j + l])));

  2640.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2641.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2642.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2643.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2644.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].multiply(currentRhoSigmaj[0][l]).
  2645.                               add(u1ij[0][l].multiply(currentRhoSigmaj[0][j + l])).
  2646.                               add(v1ij[0][j + l].multiply(currentRhoSigmaj[1][l])).
  2647.                               add(v1ij[0][l].multiply(currentRhoSigmaj[1][j + l])));
  2648.                 }

  2649.                 // divide by 1 / j
  2650.                 u2ij[j] = u2ij[j].multiply(-ooj);
  2651.                 v2ij[j] = v2ij[j].multiply(ooj);
  2652.             }
  2653.         }

  2654.         /** Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2655.          *
  2656.          * @param j j index
  2657.          * @param i Fourier index (starts at 0)
  2658.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2659.          */
  2660.         public T getU1(final int j, final int i) {
  2661.             return u1ij[i][j];
  2662.         }

  2663.         /** Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2664.          *
  2665.          * @param j j index
  2666.          * @param i Fourier index (starts at 0)
  2667.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2668.          */
  2669.         public T getV1(final int j, final int i) {
  2670.             return v1ij[i][j];
  2671.         }

  2672.         /** Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2673.          *
  2674.          * @param j j index
  2675.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2676.          */
  2677.         public T getU2(final int j) {
  2678.             return u2ij[j];
  2679.         }

  2680.         /** Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2681.          *
  2682.          * @param j j index
  2683.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2684.          */
  2685.         public T getV2(final int j) {
  2686.             return v2ij[j];
  2687.         }
  2688.     }

  2689.     /** Coefficients valid for one time slot. */
  2690.     private static class Slot {

  2691.         /**The coefficients D<sub>i</sub><sup>j</sup>.
  2692.          * <p>
  2693.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2694.          * i corresponds to the equinoctial element, as follows:
  2695.          * - i=0 for a <br/>
  2696.          * - i=1 for k <br/>
  2697.          * - i=2 for h <br/>
  2698.          * - i=3 for q <br/>
  2699.          * - i=4 for p <br/>
  2700.          * - i=5 for λ <br/>
  2701.          * </p>
  2702.          */
  2703.         private final ShortPeriodicsInterpolatedCoefficient[] dij;

  2704.         /** The coefficients C<sub>i</sub><sup>j</sup>.
  2705.          * <p>
  2706.          * The index order is cij[j][i] <br/>
  2707.          * i corresponds to the equinoctial element, as follows: <br/>
  2708.          * - i=0 for a <br/>
  2709.          * - i=1 for k <br/>
  2710.          * - i=2 for h <br/>
  2711.          * - i=3 for q <br/>
  2712.          * - i=4 for p <br/>
  2713.          * - i=5 for λ <br/>
  2714.          * </p>
  2715.          */
  2716.         private final ShortPeriodicsInterpolatedCoefficient[] cij;

  2717.         /** The coefficients S<sub>i</sub><sup>j</sup>.
  2718.          * <p>
  2719.          * The index order is sij[j][i] <br/>
  2720.          * i corresponds to the equinoctial element, as follows: <br/>
  2721.          * - i=0 for a <br/>
  2722.          * - i=1 for k <br/>
  2723.          * - i=2 for h <br/>
  2724.          * - i=3 for q <br/>
  2725.          * - i=4 for p <br/>
  2726.          * - i=5 for λ <br/>
  2727.          * </p>
  2728.          */
  2729.         private final ShortPeriodicsInterpolatedCoefficient[] sij;

  2730.         /** Simple constructor.
  2731.          *  @param jMax maximum value for j index
  2732.          *  @param interpolationPoints number of points used in the interpolation process
  2733.          */
  2734.         Slot(final int jMax, final int interpolationPoints) {

  2735.             dij = new ShortPeriodicsInterpolatedCoefficient[3];
  2736.             cij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];
  2737.             sij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];

  2738.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and D<sub>i</sub><sup>j</sup> coefficients
  2739.             for (int j = 0; j <= jMax; j++) {
  2740.                 cij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2741.                 if (j > 0) {
  2742.                     sij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2743.                 }
  2744.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2745.                 if (j == 1 || j == 2) {
  2746.                     dij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2747.                 }
  2748.             }

  2749.         }

  2750.     }

  2751.     /** Coefficients valid for one time slot. */
  2752.     private static class FieldSlot <T extends RealFieldElement<T>> {

  2753.         /**The coefficients D<sub>i</sub><sup>j</sup>.
  2754.          * <p>
  2755.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2756.          * i corresponds to the equinoctial element, as follows:
  2757.          * - i=0 for a <br/>
  2758.          * - i=1 for k <br/>
  2759.          * - i=2 for h <br/>
  2760.          * - i=3 for q <br/>
  2761.          * - i=4 for p <br/>
  2762.          * - i=5 for λ <br/>
  2763.          * </p>
  2764.          */
  2765.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] dij;

  2766.         /** The coefficients C<sub>i</sub><sup>j</sup>.
  2767.          * <p>
  2768.          * The index order is cij[j][i] <br/>
  2769.          * i corresponds to the equinoctial element, as follows: <br/>
  2770.          * - i=0 for a <br/>
  2771.          * - i=1 for k <br/>
  2772.          * - i=2 for h <br/>
  2773.          * - i=3 for q <br/>
  2774.          * - i=4 for p <br/>
  2775.          * - i=5 for λ <br/>
  2776.          * </p>
  2777.          */
  2778.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] cij;

  2779.         /** The coefficients S<sub>i</sub><sup>j</sup>.
  2780.          * <p>
  2781.          * The index order is sij[j][i] <br/>
  2782.          * i corresponds to the equinoctial element, as follows: <br/>
  2783.          * - i=0 for a <br/>
  2784.          * - i=1 for k <br/>
  2785.          * - i=2 for h <br/>
  2786.          * - i=3 for q <br/>
  2787.          * - i=4 for p <br/>
  2788.          * - i=5 for λ <br/>
  2789.          * </p>
  2790.          */
  2791.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] sij;

  2792.         /** Simple constructor.
  2793.          *  @param jMax maximum value for j index
  2794.          *  @param interpolationPoints number of points used in the interpolation process
  2795.          */
  2796.         @SuppressWarnings("unchecked")
  2797.         FieldSlot(final int jMax, final int interpolationPoints) {

  2798.             dij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array.newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, 3);
  2799.             cij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array.newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);
  2800.             sij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array.newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);

  2801.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and D<sub>i</sub><sup>j</sup> coefficients
  2802.             for (int j = 0; j <= jMax; j++) {
  2803.                 cij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2804.                 if (j > 0) {
  2805.                     sij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2806.                 }
  2807.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2808.                 if (j == 1 || j == 2) {
  2809.                     dij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2810.                 }
  2811.             }

  2812.         }

  2813.     }

  2814. }