AbstractGaussianContribution.java

  1. /* Copyright 2002-2022 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.CalculusFieldElement;
  27. import org.hipparchus.analysis.CalculusFieldUnivariateVectorFunction;
  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.FieldSinCos;
  33. import org.hipparchus.util.MathArrays;
  34. import org.hipparchus.util.SinCos;
  35. import org.orekit.attitudes.Attitude;
  36. import org.orekit.attitudes.AttitudeProvider;
  37. import org.orekit.attitudes.FieldAttitude;
  38. import org.orekit.forces.ForceModel;
  39. import org.orekit.orbits.EquinoctialOrbit;
  40. import org.orekit.orbits.FieldEquinoctialOrbit;
  41. import org.orekit.orbits.FieldOrbit;
  42. import org.orekit.orbits.Orbit;
  43. import org.orekit.orbits.OrbitType;
  44. import org.orekit.orbits.PositionAngle;
  45. import org.orekit.propagation.FieldSpacecraftState;
  46. import org.orekit.propagation.PropagationType;
  47. import org.orekit.propagation.SpacecraftState;
  48. import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
  49. import org.orekit.propagation.semianalytical.dsst.utilities.CjSjCoefficient;
  50. import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
  51. import org.orekit.propagation.semianalytical.dsst.utilities.FieldCjSjCoefficient;
  52. import org.orekit.propagation.semianalytical.dsst.utilities.FieldShortPeriodicsInterpolatedCoefficient;
  53. import org.orekit.propagation.semianalytical.dsst.utilities.ShortPeriodicsInterpolatedCoefficient;
  54. import org.orekit.time.AbsoluteDate;
  55. import org.orekit.time.FieldAbsoluteDate;
  56. import org.orekit.utils.FieldTimeSpanMap;
  57. import org.orekit.utils.ParameterDriver;
  58. import org.orekit.utils.TimeSpanMap;

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

  96.     /**
  97.      * Retrograde factor I.
  98.      * <p>
  99.      * DSST model needs equinoctial orbit as internal representation. Classical
  100.      * equinoctial elements have discontinuities when inclination is close to zero.
  101.      * In this representation, I = +1. <br>
  102.      * To avoid this discontinuity, another representation exists and equinoctial
  103.      * elements can be expressed in a different way, called "retrograde" orbit. This
  104.      * implies I = -1. <br>
  105.      * As Orekit doesn't implement the retrograde orbit, I is always set to +1. But
  106.      * for the sake of consistency with the theory, the retrograde factor has been
  107.      * kept in the formulas.
  108.      * </p>
  109.      */
  110.     private static final int I = 1;

  111.     /**
  112.      * Central attraction scaling factor.
  113.      * <p>
  114.      * We use a power of 2 to avoid numeric noise introduction in the
  115.      * multiplications/divisions sequences.
  116.      * </p>
  117.      */
  118.     private static final double MU_SCALE = FastMath.scalb(1.0, 32);

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

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

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

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

  127.     /** Contribution to be numerically averaged. */
  128.     private final ForceModel contribution;

  129.     /** Gauss integrator. */
  130.     private final double threshold;

  131.     /** Gauss integrator. */
  132.     private GaussQuadrature integrator;

  133.     /** Flag for Gauss order computation. */
  134.     private boolean isDirty;

  135.     /** Attitude provider. */
  136.     private AttitudeProvider attitudeProvider;

  137.     /** Prefix for coefficients keys. */
  138.     private final String coefficientsKeyPrefix;

  139.     /** Short period terms. */
  140.     private GaussianShortPeriodicCoefficients gaussianSPCoefs;

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

  143.     /** Driver for gravitational parameter. */
  144.     private final ParameterDriver gmParameterDriver;

  145.     /**
  146.      * Build a new instance.
  147.      * @param coefficientsKeyPrefix prefix for coefficients keys
  148.      * @param threshold             tolerance for the choice of the Gauss quadrature
  149.      *                              order
  150.      * @param contribution          the {@link ForceModel} to be numerically
  151.      *                              averaged
  152.      * @param mu                    central attraction coefficient
  153.      */
  154.     protected AbstractGaussianContribution(final String coefficientsKeyPrefix, final double threshold,
  155.             final ForceModel contribution, final double mu) {

  156.         gmParameterDriver = new ParameterDriver(DSSTNewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT, mu, MU_SCALE,
  157.                 0.0, Double.POSITIVE_INFINITY);

  158.         this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  159.         this.contribution = contribution;
  160.         this.threshold = threshold;
  161.         this.integrator = new GaussQuadrature(GAUSS_ORDER[MAX_ORDER_RANK]);
  162.         this.isDirty = true;

  163.         gaussianFieldSPCoefs = new HashMap<>();
  164.     }

  165.     /** {@inheritDoc} */
  166.     @Override
  167.     public void init(final SpacecraftState initialState, final AbsoluteDate target) {
  168.         // Initialize the numerical force model
  169.         contribution.init(initialState, target);
  170.     }

  171.     /** {@inheritDoc} */
  172.     @Override
  173.     public <T extends CalculusFieldElement<T>> void init(final FieldSpacecraftState<T> initialState, final FieldAbsoluteDate<T> target) {
  174.         // Initialize the numerical force model
  175.         contribution.init(initialState, target);
  176.     }

  177.     /** {@inheritDoc} */
  178.     @Override
  179.     public List<ParameterDriver> getParametersDrivers() {

  180.         // Parameter drivers
  181.         final List<ParameterDriver> drivers = new ArrayList<>();

  182.         // Loop on drivers (without central attraction coefficient driver)
  183.         for (final ParameterDriver driver : getParametersDriversWithoutMu()) {
  184.             drivers.add(driver);
  185.         }

  186.         // We put central attraction coefficient driver at the end of the array
  187.         drivers.add(gmParameterDriver);
  188.         return drivers;

  189.     }

  190.     /**
  191.      * Get the drivers for force model parameters except the one for the central
  192.      * attraction coefficient.
  193.      * <p>
  194.      * The driver for central attraction coefficient is automatically added at the
  195.      * last element of the {@link ParameterDriver} array into
  196.      * {@link #getParametersDrivers()} method.
  197.      * </p>
  198.      * @return drivers for force model parameters
  199.      */
  200.     protected abstract List<ParameterDriver> getParametersDriversWithoutMu();

  201.     /** {@inheritDoc} */
  202.     @Override
  203.     public List<ShortPeriodTerms> initializeShortPeriodTerms(final AuxiliaryElements auxiliaryElements, final PropagationType type,
  204.             final double[] parameters) {

  205.         final List<ShortPeriodTerms> list = new ArrayList<ShortPeriodTerms>();
  206.         gaussianSPCoefs = new GaussianShortPeriodicCoefficients(coefficientsKeyPrefix, JMAX, INTERPOLATION_POINTS,
  207.                 new TimeSpanMap<Slot>(new Slot(JMAX, INTERPOLATION_POINTS)));
  208.         list.add(gaussianSPCoefs);
  209.         return list;

  210.     }

  211.     /** {@inheritDoc} */
  212.     @Override
  213.     public <T extends CalculusFieldElement<T>> List<FieldShortPeriodTerms<T>> initializeShortPeriodTerms(
  214.             final FieldAuxiliaryElements<T> auxiliaryElements, final PropagationType type, final T[] parameters) {

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

  216.         final FieldGaussianShortPeriodicCoefficients<T> fgspc = new FieldGaussianShortPeriodicCoefficients<>(
  217.                 coefficientsKeyPrefix, JMAX, INTERPOLATION_POINTS,
  218.                 new FieldTimeSpanMap<>(new FieldSlot<>(JMAX, INTERPOLATION_POINTS), field));
  219.         gaussianFieldSPCoefs.put(field, fgspc);
  220.         return Collections.singletonList(fgspc);
  221.     }

  222.     /**
  223.      * Performs initialization at each integration step for the current force model.
  224.      * <p>
  225.      * This method aims at being called before mean elements rates computation.
  226.      * </p>
  227.      * @param auxiliaryElements auxiliary elements related to the current orbit
  228.      * @param parameters        parameters values of the force model parameters
  229.      * @return new force model context
  230.      */
  231.     private AbstractGaussianContributionContext initializeStep(final AuxiliaryElements auxiliaryElements,
  232.             final double[] parameters) {
  233.         return new AbstractGaussianContributionContext(auxiliaryElements, parameters);
  234.     }

  235.     /**
  236.      * Performs initialization at each integration step for the current force model.
  237.      * <p>
  238.      * This method aims at being called before mean elements rates computation.
  239.      * </p>
  240.      * @param <T>               type of the elements
  241.      * @param auxiliaryElements auxiliary elements related to the current orbit
  242.      * @param parameters        parameters values of the force model parameters
  243.      * @return new force model context
  244.      */
  245.     private <T extends CalculusFieldElement<T>> FieldAbstractGaussianContributionContext<T> initializeStep(
  246.             final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters) {
  247.         return new FieldAbstractGaussianContributionContext<>(auxiliaryElements, parameters);
  248.     }

  249.     /** {@inheritDoc} */
  250.     @Override
  251.     public double[] getMeanElementRate(final SpacecraftState state, final AuxiliaryElements auxiliaryElements,
  252.             final double[] parameters) {

  253.         // Container for attributes
  254.         final AbstractGaussianContributionContext context = initializeStep(auxiliaryElements, parameters);
  255.         double[] meanElementRate = new double[6];
  256.         // Computes the limits for the integral
  257.         final double[] ll = getLLimits(state, auxiliaryElements);
  258.         // Computes integrated mean element rates if Llow < Lhigh
  259.         if (ll[0] < ll[1]) {
  260.             meanElementRate = getMeanElementRate(state, integrator, ll[0], ll[1], context, parameters);
  261.             if (isDirty) {
  262.                 boolean next = true;
  263.                 for (int i = 0; i < MAX_ORDER_RANK && next; i++) {
  264.                     final double[] meanRates = getMeanElementRate(state, new GaussQuadrature(GAUSS_ORDER[i]), ll[0],
  265.                             ll[1], context, parameters);
  266.                     if (getRatesDiff(meanElementRate, meanRates, context) < threshold) {
  267.                         integrator = new GaussQuadrature(GAUSS_ORDER[i]);
  268.                         next = false;
  269.                     }
  270.                 }
  271.                 isDirty = false;
  272.             }
  273.         }
  274.         return meanElementRate;
  275.     }

  276.     /** {@inheritDoc} */
  277.     @Override
  278.     public <T extends CalculusFieldElement<T>> T[] getMeanElementRate(final FieldSpacecraftState<T> state,
  279.             final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters) {

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

  283.         T[] meanElementRate = MathArrays.buildArray(field, 6);
  284.         // Computes the limits for the integral
  285.         final T[] ll = getLLimits(state, auxiliaryElements);
  286.         // Computes integrated mean element rates if Llow < Lhigh
  287.         if (ll[0].getReal() < ll[1].getReal()) {
  288.             meanElementRate = getMeanElementRate(state, integrator, ll[0], ll[1], context, parameters);
  289.             if (isDirty) {
  290.                 boolean next = true;
  291.                 for (int i = 0; i < MAX_ORDER_RANK && next; i++) {
  292.                     final T[] meanRates = getMeanElementRate(state, new GaussQuadrature(GAUSS_ORDER[i]), ll[0], ll[1],
  293.                             context, parameters);
  294.                     if (getRatesDiff(meanElementRate, meanRates, context).getReal() < threshold) {
  295.                         integrator = new GaussQuadrature(GAUSS_ORDER[i]);
  296.                         next = false;
  297.                     }
  298.                 }
  299.                 isDirty = false;
  300.             }
  301.         }

  302.         return meanElementRate;
  303.     }

  304.     /**
  305.      * Compute the limits in L, the true longitude, for integration.
  306.      *
  307.      * @param state             current state information: date, kinematics,
  308.      *                          attitude
  309.      * @param auxiliaryElements auxiliary elements related to the current orbit
  310.      * @return the integration limits in L
  311.      */
  312.     protected abstract double[] getLLimits(SpacecraftState state, AuxiliaryElements auxiliaryElements);

  313.     /**
  314.      * Compute the limits in L, the true longitude, for integration.
  315.      *
  316.      * @param <T>               type of the elements
  317.      * @param state             current state information: date, kinematics,
  318.      *                          attitude
  319.      * @param auxiliaryElements auxiliary elements related to the current orbit
  320.      * @return the integration limits in L
  321.      */
  322.     protected abstract <T extends CalculusFieldElement<T>> T[] getLLimits(FieldSpacecraftState<T> state,
  323.             FieldAuxiliaryElements<T> auxiliaryElements);

  324.     /**
  325.      * Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  326.      *
  327.      * @param state      current state
  328.      * @param gauss      Gauss quadrature
  329.      * @param low        lower bound of the integral interval
  330.      * @param high       upper bound of the integral interval
  331.      * @param context    container for attributes
  332.      * @param parameters values of the force model parameters
  333.      * @return the mean element rates
  334.      */
  335.     protected double[] getMeanElementRate(final SpacecraftState state, final GaussQuadrature gauss, final double low,
  336.             final double high, final AbstractGaussianContributionContext context, final double[] parameters) {

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

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

  340.         // Constant multiplier for integral
  341.         final double coef = 1. / (2. * FastMath.PI * auxiliaryElements.getB());
  342.         // Corrects mean element rates
  343.         for (int i = 0; i < 6; i++) {
  344.             meanElementRate[i] *= coef;
  345.         }
  346.         return meanElementRate;
  347.     }

  348.     /**
  349.      * Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  350.      *
  351.      * @param <T>        type of the elements
  352.      * @param state      current state
  353.      * @param gauss      Gauss quadrature
  354.      * @param low        lower bound of the integral interval
  355.      * @param high       upper bound of the integral interval
  356.      * @param context    container for attributes
  357.      * @param parameters values of the force model parameters
  358.      * @return the mean element rates
  359.      */
  360.     protected <T extends CalculusFieldElement<T>> T[] getMeanElementRate(final FieldSpacecraftState<T> state,
  361.             final GaussQuadrature gauss, final T low, final T high,
  362.             final FieldAbstractGaussianContributionContext<T> context, final T[] parameters) {

  363.         // Field
  364.         final Field<T> field = context.getA().getField();

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

  367.         final T[] meanElementRate = gauss.integrate(new FieldIntegrableFunction<>(state, true, 0, parameters, field),
  368.                 low, high, field);
  369.         // Constant multiplier for integral
  370.         final T coef = auxiliaryElements.getB().multiply(low.getPi()).multiply(2.).reciprocal();
  371.         // Corrects mean element rates
  372.         for (int i = 0; i < 6; i++) {
  373.             meanElementRate[i] = meanElementRate[i].multiply(coef);
  374.         }
  375.         return meanElementRate;
  376.     }

  377.     /**
  378.      * Estimates the weighted magnitude of the difference between 2 sets of
  379.      * equinoctial elements rates.
  380.      *
  381.      * @param meanRef reference rates
  382.      * @param meanCur current rates
  383.      * @param context container for attributes
  384.      * @return estimated magnitude of weighted differences
  385.      */
  386.     private double getRatesDiff(final double[] meanRef, final double[] meanCur,
  387.             final AbstractGaussianContributionContext context) {

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

  390.         double maxDiff = FastMath.abs(meanRef[0] - meanCur[0]) / auxiliaryElements.getSma();
  391.         // Corrects mean element rates
  392.         for (int i = 1; i < meanRef.length; i++) {
  393.             maxDiff = FastMath.max(maxDiff, FastMath.abs(meanRef[i] - meanCur[i]));
  394.         }
  395.         return maxDiff;
  396.     }

  397.     /**
  398.      * Estimates the weighted magnitude of the difference between 2 sets of
  399.      * equinoctial elements rates.
  400.      *
  401.      * @param <T>     type of the elements
  402.      * @param meanRef reference rates
  403.      * @param meanCur current rates
  404.      * @param context container for attributes
  405.      * @return estimated magnitude of weighted differences
  406.      */
  407.     private <T extends CalculusFieldElement<T>> T getRatesDiff(final T[] meanRef, final T[] meanCur,
  408.             final FieldAbstractGaussianContributionContext<T> context) {

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

  411.         T maxDiff = FastMath.abs(meanRef[0].subtract(meanCur[0])).divide(auxiliaryElements.getSma());
  412.         ;
  413.         // Corrects mean element rates
  414.         for (int i = 1; i < meanRef.length; i++) {
  415.             maxDiff = FastMath.max(maxDiff, FastMath.abs(meanRef[i].subtract(meanCur[i])));
  416.         }
  417.         return maxDiff;
  418.     }

  419.     /** {@inheritDoc} */
  420.     @Override
  421.     public void registerAttitudeProvider(final AttitudeProvider provider) {
  422.         this.attitudeProvider = provider;
  423.     }

  424.     /** {@inheritDoc} */
  425.     @Override
  426.     public void updateShortPeriodTerms(final double[] parameters, final SpacecraftState... meanStates) {

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

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

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

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

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

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

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

  442.         }

  443.     }

  444.     /** {@inheritDoc} */
  445.     @Override
  446.     @SuppressWarnings("unchecked")
  447.     public <T extends CalculusFieldElement<T>> void updateShortPeriodTerms(final T[] parameters,
  448.             final FieldSpacecraftState<T>... meanStates) {

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

  451.         final FieldGaussianShortPeriodicCoefficients<T> fgspc = (FieldGaussianShortPeriodicCoefficients<T>) gaussianFieldSPCoefs
  452.                 .get(field);
  453.         final FieldSlot<T> slot = fgspc.createSlot(meanStates);
  454.         for (final FieldSpacecraftState<T> meanState : meanStates) {

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

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

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

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

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

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

  469.         }

  470.     }

  471.     /**
  472.      * Compute the auxiliary quantities ρ<sub>j</sub> and σ<sub>j</sub>.
  473.      * <p>
  474.      * The expressions used are equations 2.5.3-(4) from the Danielson paper. <br/>
  475.      * ρ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>C<sub>j</sub>(k, h) <br/>
  476.      * σ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>S<sub>j</sub>(k, h) <br/>
  477.      * </p>
  478.      * @param date              current date
  479.      * @param auxiliaryElements auxiliary elements related to the current orbit
  480.      * @return computed coefficients
  481.      */
  482.     private double[][] computeRhoSigmaCoefficients(final AbsoluteDate date, final AuxiliaryElements auxiliaryElements) {
  483.         final double[][] currentRhoSigmaj = new double[2][3 * JMAX + 1];
  484.         final CjSjCoefficient cjsjKH = new CjSjCoefficient(auxiliaryElements.getK(), auxiliaryElements.getH());
  485.         final double b = 1. / (1 + auxiliaryElements.getB());

  486.         // (-b)<sup>j</sup>
  487.         double mbtj = 1;

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

  489.             // Compute current rho and sigma;
  490.             mbtj *= -b;
  491.             final double coef = (1 + j * auxiliaryElements.getB()) * mbtj;
  492.             currentRhoSigmaj[0][j] = coef * cjsjKH.getCj(j);
  493.             currentRhoSigmaj[1][j] = coef * cjsjKH.getSj(j);
  494.         }
  495.         return currentRhoSigmaj;
  496.     }

  497.     /**
  498.      * Compute the auxiliary quantities ρ<sub>j</sub> and σ<sub>j</sub>.
  499.      * <p>
  500.      * The expressions used are equations 2.5.3-(4) from the Danielson paper. <br/>
  501.      * ρ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>C<sub>j</sub>(k, h) <br/>
  502.      * σ<sub>j</sub> = (1+jB)(-b)<sup>j</sup>S<sub>j</sub>(k, h) <br/>
  503.      * </p>
  504.      * @param <T>     type of the elements
  505.      * @param date    current date
  506.      * @param context container for attributes
  507.      * @param field   field used by default
  508.      * @return computed coefficients
  509.      */
  510.     private <T extends CalculusFieldElement<T>> T[][] computeRhoSigmaCoefficients(final FieldAbsoluteDate<T> date,
  511.             final FieldAbstractGaussianContributionContext<T> context, final Field<T> field) {
  512.         // zero
  513.         final T zero = field.getZero();

  514.         final FieldAuxiliaryElements<T> auxiliaryElements = context.getFieldAuxiliaryElements();
  515.         final T[][] currentRhoSigmaj = MathArrays.buildArray(field, 2, 3 * JMAX + 1);
  516.         final FieldCjSjCoefficient<T> cjsjKH = new FieldCjSjCoefficient<>(auxiliaryElements.getK(),
  517.                 auxiliaryElements.getH(), field);
  518.         final T b = auxiliaryElements.getB().add(1.).reciprocal();

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

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

  522.             // Compute current rho and sigma;
  523.             mbtj = mbtj.multiply(b.negate());
  524.             final T coef = mbtj.multiply(auxiliaryElements.getB().multiply(j).add(1.));
  525.             currentRhoSigmaj[0][j] = coef.multiply(cjsjKH.getCj(j));
  526.             currentRhoSigmaj[1][j] = coef.multiply(cjsjKH.getSj(j));
  527.         }
  528.         return currentRhoSigmaj;
  529.     }

  530.     /**
  531.      * Internal class for numerical quadrature.
  532.      * <p>
  533.      * This class is a rewrite of {@link IntegrableFunction} for field elements
  534.      * </p>
  535.      */
  536.     protected class FieldIntegrableFunction<T extends CalculusFieldElement<T>>
  537.             implements CalculusFieldUnivariateVectorFunction<T> {

  538.         /** Current state. */
  539.         private final FieldSpacecraftState<T> state;

  540.         /**
  541.          * Signal that this class is used to compute the values required by the mean
  542.          * element variations or by the short periodic element variations.
  543.          */
  544.         private final boolean meanMode;

  545.         /**
  546.          * The j index.
  547.          * <p>
  548.          * Used only for short periodic variation. Ignored for mean elements variation.
  549.          * </p>
  550.          */
  551.         private final int j;

  552.         /** Container for attributes. */
  553.         private final FieldAbstractGaussianContributionContext<T> context;

  554.         /** Auxiliary Elements. */
  555.         private final FieldAuxiliaryElements<T> auxiliaryElements;

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

  558.         /**
  559.          * Build a new instance with a new field.
  560.          * @param state      current state information: date, kinematics, attitude
  561.          * @param meanMode   if true return the value associated to the mean elements
  562.          *                   variation, if false return the values associated to the
  563.          *                   short periodic elements variation
  564.          * @param j          the j index. used only for short periodic variation.
  565.          *                   Ignored for mean elements variation.
  566.          * @param parameters values of the force model parameters
  567.          * @param field      field utilized by default
  568.          */
  569.         public FieldIntegrableFunction(final FieldSpacecraftState<T> state, final boolean meanMode, final int j,
  570.                 final T[] parameters, final Field<T> field) {

  571.             this.meanMode = meanMode;
  572.             this.j = j;
  573.             this.parameters = parameters.clone();
  574.             this.auxiliaryElements = new FieldAuxiliaryElements<>(state.getOrbit(), I);
  575.             this.context = new FieldAbstractGaussianContributionContext<>(auxiliaryElements, this.parameters);
  576.             // remove derivatives from state
  577.             final T[] stateVector = MathArrays.buildArray(field, 6);
  578.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), PositionAngle.TRUE, stateVector, null);
  579.             final FieldOrbit<T> fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null,
  580.                     PositionAngle.TRUE, state.getDate(), context.getMu(), state.getFrame());
  581.             this.state = new FieldSpacecraftState<>(fixedOrbit, state.getAttitude(), state.getMass());
  582.         }

  583.         /** {@inheritDoc} */
  584.         @Override
  585.         public T[] value(final T x) {

  586.             // Parameters for array building
  587.             final Field<T> field = auxiliaryElements.getDate().getField();
  588.             final int dimension = 6;

  589.             // Compute the time difference from the true longitude difference
  590.             final T shiftedLm = trueToMean(x);
  591.             final T dLm = shiftedLm.subtract(auxiliaryElements.getLM());
  592.             final T dt = dLm.divide(context.getMeanMotion());

  593.             final FieldSinCos<T> scL = FastMath.sinCos(x);
  594.             final T cosL = scL.cos();
  595.             final T sinL = scL.sin();
  596.             final T roa  = auxiliaryElements.getB().multiply(auxiliaryElements.getB()).divide(auxiliaryElements.getH().multiply(sinL).add(auxiliaryElements.getK().multiply(cosL)).add(1.));
  597.             final T roa2 = roa.multiply(roa);
  598.             final T r = auxiliaryElements.getSma().multiply(roa);
  599.             final T X = r.multiply(cosL);
  600.             final T Y = r.multiply(sinL);
  601.             final T naob = context.getMeanMotion().multiply(auxiliaryElements.getSma())
  602.                     .divide(auxiliaryElements.getB());
  603.             final T Xdot = naob.multiply(auxiliaryElements.getH().add(sinL)).negate();
  604.             final T Ydot = naob.multiply(auxiliaryElements.getK().add(cosL));
  605.             final FieldVector3D<T> vel = new FieldVector3D<>(Xdot, auxiliaryElements.getVectorF(), Ydot,
  606.                     auxiliaryElements.getVectorG());

  607.             // Compute acceleration
  608.             FieldVector3D<T> acc = FieldVector3D.getZero(field);

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

  611.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  612.             final FieldOrbit<T> recomposedOrbit = new FieldEquinoctialOrbit<>(shiftedOrbit.getA(),
  613.                     shiftedOrbit.getEquinoctialEx(), shiftedOrbit.getEquinoctialEy(), shiftedOrbit.getHx(),
  614.                     shiftedOrbit.getHy(), shiftedOrbit.getLv(), PositionAngle.TRUE, shiftedOrbit.getFrame(),
  615.                     state.getDate(), context.getMu());

  616.             // Get the corresponding attitude
  617.             final FieldAttitude<T> recomposedAttitude = attitudeProvider.getAttitude(recomposedOrbit,
  618.                     recomposedOrbit.getDate(), recomposedOrbit.getFrame());

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

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

  623.             // Compute the derivatives of the elements by the speed
  624.             final T[] deriv = MathArrays.buildArray(field, dimension);
  625.             // da/dv
  626.             deriv[0] = getAoV(vel).dotProduct(acc);
  627.             // dex/dv
  628.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  629.             // dey/dv
  630.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  631.             // dhx/dv
  632.             deriv[3] = getQoV(X).dotProduct(acc);
  633.             // dhy/dv
  634.             deriv[4] = getPoV(Y).dotProduct(acc);
  635.             // dλ/dv
  636.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  637.             // Compute mean elements rates
  638.             T[] val = null;
  639.             if (meanMode) {
  640.                 val = MathArrays.buildArray(field, dimension);
  641.                 for (int i = 0; i < 6; i++) {
  642.                     // da<sub>i</sub>/dt
  643.                     val[i] = deriv[i].multiply(roa2);
  644.                 }
  645.             } else {
  646.                 val = MathArrays.buildArray(field, dimension * 2);
  647.                 //Compute cos(j*L) and sin(j*L);
  648.                 final FieldSinCos<T> scjL = FastMath.sinCos(x.multiply(j));
  649.                 final T cosjL = j == 1 ? cosL : scjL.cos();
  650.                 final T sinjL = j == 1 ? sinL : scjL.sin();

  651.                 for (int i = 0; i < 6; i++) {
  652.                     // da<sub>i</sub>/dv * cos(jL)
  653.                     val[i] = deriv[i].multiply(cosjL);
  654.                     // da<sub>i</sub>/dv * sin(jL)
  655.                     val[i + 6] = deriv[i].multiply(sinjL);
  656.                 }
  657.             }

  658.             return val;
  659.         }

  660.         /**
  661.          * Converts true longitude to mean longitude.
  662.          * @param x True longitude
  663.          * @return Eccentric longitude
  664.          */
  665.         private T trueToMean(final T x) {
  666.             return eccentricToMean(trueToEccentric(x));
  667.         }

  668.         /**
  669.          * Converts true longitude to eccentric longitude.
  670.          * @param lv True longitude
  671.          * @return Eccentric longitude
  672.          */
  673.         private T trueToEccentric (final T lv) {
  674.             final FieldSinCos<T> sclV = FastMath.sinCos(lv);
  675.             final T cosLv   = sclV.cos();
  676.             final T sinLv   = sclV.sin();
  677.             final T num     = auxiliaryElements.getH().multiply(cosLv).subtract(auxiliaryElements.getK().multiply(sinLv));
  678.             final T den     = auxiliaryElements.getB().add(auxiliaryElements.getK().multiply(cosLv)).add(auxiliaryElements.getH().multiply(sinLv)).add(1.);
  679.             return FastMath.atan(num.divide(den)).multiply(2.).add(lv);
  680.         }

  681.         /**
  682.          * Converts eccentric longitude to mean longitude.
  683.          * @param le Eccentric longitude
  684.          * @return Mean longitude
  685.          */
  686.         private T eccentricToMean (final T le) {
  687.             final FieldSinCos<T> scle = FastMath.sinCos(le);
  688.             return le.subtract(auxiliaryElements.getK().multiply(scle.sin())).add(auxiliaryElements.getH().multiply(scle.cos()));
  689.         }

  690.         /**
  691.          * Compute δa/δv.
  692.          * @param vel satellite velocity
  693.          * @return δa/δv
  694.          */
  695.         private FieldVector3D<T> getAoV(final FieldVector3D<T> vel) {
  696.             return new FieldVector3D<>(context.getTon2a(), vel);
  697.         }

  698.         /**
  699.          * Compute δh/δv.
  700.          * @param X    satellite position component along f, equinoctial reference frame
  701.          *             1st vector
  702.          * @param Y    satellite position component along g, equinoctial reference frame
  703.          *             2nd vector
  704.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  705.          *             1st vector
  706.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  707.          *             2nd vector
  708.          * @return δh/δv
  709.          */
  710.         private FieldVector3D<T> getHoV(final T X, final T Y, final T Xdot, final T Ydot) {
  711.             final T kf = (Xdot.multiply(Y).multiply(2.).subtract(X.multiply(Ydot))).multiply(context.getOoMU());
  712.             final T kg = X.multiply(Xdot).multiply(context.getOoMU());
  713.             final T kw = auxiliaryElements.getK().multiply(
  714.                     auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X)))
  715.                     .multiply(context.getOOAB());
  716.             return new FieldVector3D<>(kf, auxiliaryElements.getVectorF(), kg.negate(), auxiliaryElements.getVectorG(),
  717.                     kw, auxiliaryElements.getVectorW());
  718.         }

  719.         /**
  720.          * Compute δk/δv.
  721.          * @param X    satellite position component along f, equinoctial reference frame
  722.          *             1st vector
  723.          * @param Y    satellite position component along g, equinoctial reference frame
  724.          *             2nd vector
  725.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  726.          *             1st vector
  727.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  728.          *             2nd vector
  729.          * @return δk/δv
  730.          */
  731.         private FieldVector3D<T> getKoV(final T X, final T Y, final T Xdot, final T Ydot) {
  732.             final T kf = Y.multiply(Ydot).multiply(context.getOoMU());
  733.             final T kg = (X.multiply(Ydot).multiply(2.).subtract(Xdot.multiply(Y))).multiply(context.getOoMU());
  734.             final T kw = auxiliaryElements.getH().multiply(
  735.                     auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X)))
  736.                     .multiply(context.getOOAB());
  737.             return new FieldVector3D<>(kf.negate(), auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(),
  738.                     kw.negate(), auxiliaryElements.getVectorW());
  739.         }

  740.         /**
  741.          * Compute δp/δv.
  742.          * @param Y satellite position component along g, equinoctial reference frame
  743.          *          2nd vector
  744.          * @return δp/δv
  745.          */
  746.         private FieldVector3D<T> getPoV(final T Y) {
  747.             return new FieldVector3D<>(context.getCo2AB().multiply(Y), auxiliaryElements.getVectorW());
  748.         }

  749.         /**
  750.          * Compute δq/δv.
  751.          * @param X satellite position component along f, equinoctial reference frame
  752.          *          1st vector
  753.          * @return δq/δv
  754.          */
  755.         private FieldVector3D<T> getQoV(final T X) {
  756.             return new FieldVector3D<>(context.getCo2AB().multiply(X).multiply(I), auxiliaryElements.getVectorW());
  757.         }

  758.         /**
  759.          * Compute δλ/δv.
  760.          * @param X    satellite position component along f, equinoctial reference frame
  761.          *             1st vector
  762.          * @param Y    satellite position component along g, equinoctial reference frame
  763.          *             2nd vector
  764.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  765.          *             1st vector
  766.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  767.          *             2nd vector
  768.          * @return δλ/δv
  769.          */
  770.         private FieldVector3D<T> getLoV(final T X, final T Y, final T Xdot, final T Ydot) {
  771.             final FieldVector3D<T> pos = new FieldVector3D<>(X, auxiliaryElements.getVectorF(), Y,
  772.                     auxiliaryElements.getVectorG());
  773.             final FieldVector3D<T> v2 = new FieldVector3D<>(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot),
  774.                     auxiliaryElements.getH().negate(), getKoV(X, Y, Xdot, Ydot));
  775.             return new FieldVector3D<>(context.getOOA().multiply(-2.), pos, context.getOoBpo(), v2,
  776.                     context.getOOA().multiply(auxiliaryElements.getQ().multiply(Y).multiply(I)
  777.                             .subtract(auxiliaryElements.getP().multiply(X))),
  778.                     auxiliaryElements.getVectorW());
  779.         }

  780.     }

  781.     /** Internal class for numerical quadrature. */
  782.     protected class IntegrableFunction implements UnivariateVectorFunction {

  783.         /** Current state. */
  784.         private final SpacecraftState state;

  785.         /**
  786.          * Signal that this class is used to compute the values required by the mean
  787.          * element variations or by the short periodic element variations.
  788.          */
  789.         private final boolean meanMode;

  790.         /**
  791.          * The j index.
  792.          * <p>
  793.          * Used only for short periodic variation. Ignored for mean elements variation.
  794.          * </p>
  795.          */
  796.         private final int j;

  797.         /** Container for attributes. */
  798.         private final AbstractGaussianContributionContext context;

  799.         /** Auxiliary Elements. */
  800.         private final AuxiliaryElements auxiliaryElements;

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

  803.         /**
  804.          * Build a new instance.
  805.          * @param state      current state information: date, kinematics, attitude
  806.          * @param meanMode   if true return the value associated to the mean elements
  807.          *                   variation, if false return the values associated to the
  808.          *                   short periodic elements variation
  809.          * @param j          the j index. used only for short periodic variation.
  810.          *                   Ignored for mean elements variation.
  811.          * @param parameters values of the force model parameters
  812.          */
  813.         IntegrableFunction(final SpacecraftState state, final boolean meanMode, final int j,
  814.                 final double[] parameters) {

  815.             this.meanMode = meanMode;
  816.             this.j = j;
  817.             this.parameters = parameters.clone();
  818.             this.auxiliaryElements = new AuxiliaryElements(state.getOrbit(), I);
  819.             this.context = new AbstractGaussianContributionContext(auxiliaryElements, this.parameters);
  820.             // remove derivatives from state
  821.             final double[] stateVector = new double[6];
  822.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), PositionAngle.TRUE, stateVector, null);
  823.             final Orbit fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null, PositionAngle.TRUE,
  824.                     state.getDate(), context.getMu(), state.getFrame());
  825.             this.state = new SpacecraftState(fixedOrbit, state.getAttitude(), state.getMass());
  826.         }

  827.         /** {@inheritDoc} */
  828.         @Override
  829.         public double[] value(final double x) {

  830.             // Compute the time difference from the true longitude difference
  831.             final double shiftedLm = trueToMean(x);
  832.             final double dLm = shiftedLm - auxiliaryElements.getLM();
  833.             final double dt = dLm / context.getMeanMotion();

  834.             final SinCos scL  = FastMath.sinCos(x);
  835.             final double cosL = scL.cos();
  836.             final double sinL = scL.sin();
  837.             final double roa  = auxiliaryElements.getB() * auxiliaryElements.getB() / (1. + auxiliaryElements.getH() * sinL + auxiliaryElements.getK() * cosL);
  838.             final double roa2 = roa * roa;
  839.             final double r = auxiliaryElements.getSma() * roa;
  840.             final double X = r * cosL;
  841.             final double Y = r * sinL;
  842.             final double naob = context.getMeanMotion() * auxiliaryElements.getSma() / auxiliaryElements.getB();
  843.             final double Xdot = -naob * (auxiliaryElements.getH() + sinL);
  844.             final double Ydot = naob * (auxiliaryElements.getK() + cosL);
  845.             final Vector3D vel = new Vector3D(Xdot, auxiliaryElements.getVectorF(), Ydot,
  846.                     auxiliaryElements.getVectorG());

  847.             // Compute acceleration
  848.             Vector3D acc = Vector3D.ZERO;

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

  851.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  852.             final Orbit recomposedOrbit = new EquinoctialOrbit(shiftedOrbit.getA(), shiftedOrbit.getEquinoctialEx(),
  853.                     shiftedOrbit.getEquinoctialEy(), shiftedOrbit.getHx(), shiftedOrbit.getHy(), shiftedOrbit.getLv(),
  854.                     PositionAngle.TRUE, shiftedOrbit.getFrame(), state.getDate(), context.getMu());

  855.             // Get the corresponding attitude
  856.             final Attitude recomposedAttitude = attitudeProvider.getAttitude(recomposedOrbit, recomposedOrbit.getDate(),
  857.                     recomposedOrbit.getFrame());

  858.             // create shifted SpacecraftState with attitude at specified time
  859.             final SpacecraftState shiftedState = new SpacecraftState(recomposedOrbit, recomposedAttitude,
  860.                     state.getMass());

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

  862.             // Compute the derivatives of the elements by the speed
  863.             final double[] deriv = new double[6];
  864.             // da/dv
  865.             deriv[0] = getAoV(vel).dotProduct(acc);
  866.             // dex/dv
  867.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  868.             // dey/dv
  869.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  870.             // dhx/dv
  871.             deriv[3] = getQoV(X).dotProduct(acc);
  872.             // dhy/dv
  873.             deriv[4] = getPoV(Y).dotProduct(acc);
  874.             // dλ/dv
  875.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  876.             // Compute mean elements rates
  877.             double[] val = null;
  878.             if (meanMode) {
  879.                 val = new double[6];
  880.                 for (int i = 0; i < 6; i++) {
  881.                     // da<sub>i</sub>/dt
  882.                     val[i] = roa2 * deriv[i];
  883.                 }
  884.             } else {
  885.                 val = new double[12];
  886.                 //Compute cos(j*L) and sin(j*L);
  887.                 final SinCos scjL  = FastMath.sinCos(j * x);
  888.                 final double cosjL = j == 1 ? cosL : scjL.cos();
  889.                 final double sinjL = j == 1 ? sinL : scjL.sin();

  890.                 for (int i = 0; i < 6; i++) {
  891.                     // da<sub>i</sub>/dv * cos(jL)
  892.                     val[i] = cosjL * deriv[i];
  893.                     // da<sub>i</sub>/dv * sin(jL)
  894.                     val[i + 6] = sinjL * deriv[i];
  895.                 }
  896.             }
  897.             return val;
  898.         }

  899.         /**
  900.          * Converts true longitude to eccentric longitude.
  901.          * @param lv True longitude
  902.          * @return Eccentric longitude
  903.          */
  904.         private double trueToEccentric (final double lv) {
  905.             final SinCos scLv    = FastMath.sinCos(lv);
  906.             final double num     = auxiliaryElements.getH() * scLv.cos() - auxiliaryElements.getK() * scLv.sin();
  907.             final double den     = auxiliaryElements.getB() + 1. + auxiliaryElements.getK() * scLv.cos() + auxiliaryElements.getH() * scLv.sin();
  908.             return lv + 2. * FastMath.atan(num / den);
  909.         }

  910.         /**
  911.          * Converts eccentric longitude to mean longitude.
  912.          * @param le Eccentric longitude
  913.          * @return Mean longitude
  914.          */
  915.         private double eccentricToMean (final double le) {
  916.             final SinCos scLe = FastMath.sinCos(le);
  917.             return le - auxiliaryElements.getK() * scLe.sin() + auxiliaryElements.getH() * scLe.cos();
  918.         }

  919.         /**
  920.          * Converts true longitude to mean longitude.
  921.          * @param lv True longitude
  922.          * @return Eccentric longitude
  923.          */
  924.         private double trueToMean(final double lv) {
  925.             return eccentricToMean(trueToEccentric(lv));
  926.         }

  927.         /**
  928.          * Compute δa/δv.
  929.          * @param vel satellite velocity
  930.          * @return δa/δv
  931.          */
  932.         private Vector3D getAoV(final Vector3D vel) {
  933.             return new Vector3D(context.getTon2a(), vel);
  934.         }

  935.         /**
  936.          * Compute δh/δv.
  937.          * @param X    satellite position component along f, equinoctial reference frame
  938.          *             1st vector
  939.          * @param Y    satellite position component along g, equinoctial reference frame
  940.          *             2nd vector
  941.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  942.          *             1st vector
  943.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  944.          *             2nd vector
  945.          * @return δh/δv
  946.          */
  947.         private Vector3D getHoV(final double X, final double Y, final double Xdot, final double Ydot) {
  948.             final double kf = (2. * Xdot * Y - X * Ydot) * context.getOoMU();
  949.             final double kg = X * Xdot * context.getOoMU();
  950.             final double kw = auxiliaryElements.getK() *
  951.                     (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOAB();
  952.             return new Vector3D(kf, auxiliaryElements.getVectorF(), -kg, auxiliaryElements.getVectorG(), kw,
  953.                     auxiliaryElements.getVectorW());
  954.         }

  955.         /**
  956.          * Compute δk/δv.
  957.          * @param X    satellite position component along f, equinoctial reference frame
  958.          *             1st vector
  959.          * @param Y    satellite position component along g, equinoctial reference frame
  960.          *             2nd vector
  961.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  962.          *             1st vector
  963.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  964.          *             2nd vector
  965.          * @return δk/δv
  966.          */
  967.         private Vector3D getKoV(final double X, final double Y, final double Xdot, final double Ydot) {
  968.             final double kf = Y * Ydot * context.getOoMU();
  969.             final double kg = (2. * X * Ydot - Xdot * Y) * context.getOoMU();
  970.             final double kw = auxiliaryElements.getH() *
  971.                     (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOAB();
  972.             return new Vector3D(-kf, auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(), -kw,
  973.                     auxiliaryElements.getVectorW());
  974.         }

  975.         /**
  976.          * Compute δp/δv.
  977.          * @param Y satellite position component along g, equinoctial reference frame
  978.          *          2nd vector
  979.          * @return δp/δv
  980.          */
  981.         private Vector3D getPoV(final double Y) {
  982.             return new Vector3D(context.getCo2AB() * Y, auxiliaryElements.getVectorW());
  983.         }

  984.         /**
  985.          * Compute δq/δv.
  986.          * @param X satellite position component along f, equinoctial reference frame
  987.          *          1st vector
  988.          * @return δq/δv
  989.          */
  990.         private Vector3D getQoV(final double X) {
  991.             return new Vector3D(I * context.getCo2AB() * X, auxiliaryElements.getVectorW());
  992.         }

  993.         /**
  994.          * Compute δλ/δv.
  995.          * @param X    satellite position component along f, equinoctial reference frame
  996.          *             1st vector
  997.          * @param Y    satellite position component along g, equinoctial reference frame
  998.          *             2nd vector
  999.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  1000.          *             1st vector
  1001.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  1002.          *             2nd vector
  1003.          * @return δλ/δv
  1004.          */
  1005.         private Vector3D getLoV(final double X, final double Y, final double Xdot, final double Ydot) {
  1006.             final Vector3D pos = new Vector3D(X, auxiliaryElements.getVectorF(), Y, auxiliaryElements.getVectorG());
  1007.             final Vector3D v2 = new Vector3D(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot),
  1008.                     -auxiliaryElements.getH(), getKoV(X, Y, Xdot, Ydot));
  1009.             return new Vector3D(-2. * context.getOOA(), pos, context.getOoBpo(), v2,
  1010.                     (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOA(),
  1011.                     auxiliaryElements.getVectorW());
  1012.         }

  1013.     }

  1014.     /**
  1015.      * Class used to {@link #integrate(UnivariateVectorFunction, double, double)
  1016.      * integrate} a {@link org.hipparchus.analysis.UnivariateVectorFunction
  1017.      * function} of the orbital elements using the Gaussian quadrature rule to get
  1018.      * the acceleration.
  1019.      */
  1020.     protected static class GaussQuadrature {

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

  1022.         /** Points for quadrature of order 12. */
  1023.         private static final double[] P_12 = { -0.98156063424671910000, -0.90411725637047490000,
  1024.             -0.76990267419430470000, -0.58731795428661740000, -0.36783149899818024000, -0.12523340851146890000,
  1025.             0.12523340851146890000, 0.36783149899818024000, 0.58731795428661740000, 0.76990267419430470000,
  1026.             0.90411725637047490000, 0.98156063424671910000 };

  1027.         /** Weights for quadrature of order 12. */
  1028.         private static final double[] W_12 = { 0.04717533638651220000, 0.10693932599531830000, 0.16007832854334633000,
  1029.             0.20316742672306584000, 0.23349253653835478000, 0.24914704581340286000, 0.24914704581340286000,
  1030.             0.23349253653835478000, 0.20316742672306584000, 0.16007832854334633000, 0.10693932599531830000,
  1031.             0.04717533638651220000 };

  1032.         /** Points for quadrature of order 16. */
  1033.         private static final double[] P_16 = { -0.98940093499164990000, -0.94457502307323260000,
  1034.             -0.86563120238783160000, -0.75540440835500310000, -0.61787624440264380000, -0.45801677765722737000,
  1035.             -0.28160355077925890000, -0.09501250983763745000, 0.09501250983763745000, 0.28160355077925890000,
  1036.             0.45801677765722737000, 0.61787624440264380000, 0.75540440835500310000, 0.86563120238783160000,
  1037.             0.94457502307323260000, 0.98940093499164990000 };

  1038.         /** Weights for quadrature of order 16. */
  1039.         private static final double[] W_16 = { 0.02715245941175405800, 0.06225352393864777000, 0.09515851168249283000,
  1040.             0.12462897125553388000, 0.14959598881657685000, 0.16915651939500256000, 0.18260341504492360000,
  1041.             0.18945061045506847000, 0.18945061045506847000, 0.18260341504492360000, 0.16915651939500256000,
  1042.             0.14959598881657685000, 0.12462897125553388000, 0.09515851168249283000, 0.06225352393864777000,
  1043.             0.02715245941175405800 };

  1044.         /** Points for quadrature of order 20. */
  1045.         private static final double[] P_20 = { -0.99312859918509490000, -0.96397192727791390000,
  1046.             -0.91223442825132600000, -0.83911697182221890000, -0.74633190646015080000, -0.63605368072651510000,
  1047.             -0.51086700195082700000, -0.37370608871541955000, -0.22778585114164507000, -0.07652652113349734000,
  1048.             0.07652652113349734000, 0.22778585114164507000, 0.37370608871541955000, 0.51086700195082700000,
  1049.             0.63605368072651510000, 0.74633190646015080000, 0.83911697182221890000, 0.91223442825132600000,
  1050.             0.96397192727791390000, 0.99312859918509490000 };

  1051.         /** Weights for quadrature of order 20. */
  1052.         private static final double[] W_20 = { 0.01761400713915226400, 0.04060142980038684000, 0.06267204833410904000,
  1053.             0.08327674157670477000, 0.10193011981724048000, 0.11819453196151844000, 0.13168863844917678000,
  1054.             0.14209610931838212000, 0.14917298647260380000, 0.15275338713072600000, 0.15275338713072600000,
  1055.             0.14917298647260380000, 0.14209610931838212000, 0.13168863844917678000, 0.11819453196151844000,
  1056.             0.10193011981724048000, 0.08327674157670477000, 0.06267204833410904000, 0.04060142980038684000,
  1057.             0.01761400713915226400 };

  1058.         /** Points for quadrature of order 24. */
  1059.         private static final double[] P_24 = { -0.99518721999702130000, -0.97472855597130950000,
  1060.             -0.93827455200273270000, -0.88641552700440100000, -0.82000198597390300000, -0.74012419157855440000,
  1061.             -0.64809365193697550000, -0.54542147138883950000, -0.43379350762604520000, -0.31504267969616340000,
  1062.             -0.19111886747361634000, -0.06405689286260563000, 0.06405689286260563000, 0.19111886747361634000,
  1063.             0.31504267969616340000, 0.43379350762604520000, 0.54542147138883950000, 0.64809365193697550000,
  1064.             0.74012419157855440000, 0.82000198597390300000, 0.88641552700440100000, 0.93827455200273270000,
  1065.             0.97472855597130950000, 0.99518721999702130000 };

  1066.         /** Weights for quadrature of order 24. */
  1067.         private static final double[] W_24 = { 0.01234122979998733500, 0.02853138862893380600, 0.04427743881741981000,
  1068.             0.05929858491543691500, 0.07334648141108027000, 0.08619016153195320000, 0.09761865210411391000,
  1069.             0.10744427011596558000, 0.11550566805372553000, 0.12167047292780335000, 0.12583745634682825000,
  1070.             0.12793819534675221000, 0.12793819534675221000, 0.12583745634682825000, 0.12167047292780335000,
  1071.             0.11550566805372553000, 0.10744427011596558000, 0.09761865210411391000, 0.08619016153195320000,
  1072.             0.07334648141108027000, 0.05929858491543691500, 0.04427743881741981000, 0.02853138862893380600,
  1073.             0.01234122979998733500 };

  1074.         /** Points for quadrature of order 32. */
  1075.         private static final double[] P_32 = { -0.99726386184948160000, -0.98561151154526840000,
  1076.             -0.96476225558750640000, -0.93490607593773970000, -0.89632115576605220000, -0.84936761373256990000,
  1077.             -0.79448379596794250000, -0.73218211874028970000, -0.66304426693021520000, -0.58771575724076230000,
  1078.             -0.50689990893222950000, -0.42135127613063540000, -0.33186860228212767000, -0.23928736225213710000,
  1079.             -0.14447196158279646000, -0.04830766568773831000, 0.04830766568773831000, 0.14447196158279646000,
  1080.             0.23928736225213710000, 0.33186860228212767000, 0.42135127613063540000, 0.50689990893222950000,
  1081.             0.58771575724076230000, 0.66304426693021520000, 0.73218211874028970000, 0.79448379596794250000,
  1082.             0.84936761373256990000, 0.89632115576605220000, 0.93490607593773970000, 0.96476225558750640000,
  1083.             0.98561151154526840000, 0.99726386184948160000 };

  1084.         /** Weights for quadrature of order 32. */
  1085.         private static final double[] W_32 = { 0.00701861000947013600, 0.01627439473090571200, 0.02539206530926214200,
  1086.             0.03427386291302141000, 0.04283589802222658600, 0.05099805926237621600, 0.05868409347853559000,
  1087.             0.06582222277636193000, 0.07234579410884862000, 0.07819389578707042000, 0.08331192422694673000,
  1088.             0.08765209300440380000, 0.09117387869576390000, 0.09384439908080441000, 0.09563872007927487000,
  1089.             0.09654008851472784000, 0.09654008851472784000, 0.09563872007927487000, 0.09384439908080441000,
  1090.             0.09117387869576390000, 0.08765209300440380000, 0.08331192422694673000, 0.07819389578707042000,
  1091.             0.07234579410884862000, 0.06582222277636193000, 0.05868409347853559000, 0.05099805926237621600,
  1092.             0.04283589802222658600, 0.03427386291302141000, 0.02539206530926214200, 0.01627439473090571200,
  1093.             0.00701861000947013600 };

  1094.         /** Points for quadrature of order 40. */
  1095.         private static final double[] P_40 = { -0.99823770971055930000, -0.99072623869945710000,
  1096.             -0.97725994998377420000, -0.95791681921379170000, -0.93281280827867660000, -0.90209880696887420000,
  1097.             -0.86595950321225960000, -0.82461223083331170000, -0.77830565142651940000, -0.72731825518992710000,
  1098.             -0.67195668461417960000, -0.61255388966798030000, -0.54946712509512820000, -0.48307580168617870000,
  1099.             -0.41377920437160500000, -0.34199409082575850000, -0.26815218500725370000, -0.19269758070137110000,
  1100.             -0.11608407067525522000, -0.03877241750605081600, 0.03877241750605081600, 0.11608407067525522000,
  1101.             0.19269758070137110000, 0.26815218500725370000, 0.34199409082575850000, 0.41377920437160500000,
  1102.             0.48307580168617870000, 0.54946712509512820000, 0.61255388966798030000, 0.67195668461417960000,
  1103.             0.72731825518992710000, 0.77830565142651940000, 0.82461223083331170000, 0.86595950321225960000,
  1104.             0.90209880696887420000, 0.93281280827867660000, 0.95791681921379170000, 0.97725994998377420000,
  1105.             0.99072623869945710000, 0.99823770971055930000 };

  1106.         /** Weights for quadrature of order 40. */
  1107.         private static final double[] W_40 = { 0.00452127709853309800, 0.01049828453115270400, 0.01642105838190797300,
  1108.             0.02224584919416689000, 0.02793700698002338000, 0.03346019528254786500, 0.03878216797447199000,
  1109.             0.04387090818567333000, 0.04869580763507221000, 0.05322784698393679000, 0.05743976909939157000,
  1110.             0.06130624249292891000, 0.06480401345660108000, 0.06791204581523394000, 0.07061164739128681000,
  1111.             0.07288658239580408000, 0.07472316905796833000, 0.07611036190062619000, 0.07703981816424793000,
  1112.             0.07750594797842482000, 0.07750594797842482000, 0.07703981816424793000, 0.07611036190062619000,
  1113.             0.07472316905796833000, 0.07288658239580408000, 0.07061164739128681000, 0.06791204581523394000,
  1114.             0.06480401345660108000, 0.06130624249292891000, 0.05743976909939157000, 0.05322784698393679000,
  1115.             0.04869580763507221000, 0.04387090818567333000, 0.03878216797447199000, 0.03346019528254786500,
  1116.             0.02793700698002338000, 0.02224584919416689000, 0.01642105838190797300, 0.01049828453115270400,
  1117.             0.00452127709853309800 };

  1118.         /** Points for quadrature of order 48. */
  1119.         private static final double[] P_48 = { -0.99877100725242610000, -0.99353017226635080000,
  1120.             -0.98412458372282700000, -0.97059159254624720000, -0.95298770316043080000, -0.93138669070655440000,
  1121.             -0.90587913671556960000, -0.87657202027424800000, -0.84358826162439350000, -0.80706620402944250000,
  1122.             -0.76715903251574020000, -0.72403413092381470000, -0.67787237963266400000, -0.62886739677651370000,
  1123.             -0.57722472608397270000, -0.52316097472223300000, -0.46690290475095840000, -0.40868648199071680000,
  1124.             -0.34875588629216070000, -0.28736248735545555000, -0.22476379039468908000, -0.16122235606889174000,
  1125.             -0.09700469920946270000, -0.03238017096286937000, 0.03238017096286937000, 0.09700469920946270000,
  1126.             0.16122235606889174000, 0.22476379039468908000, 0.28736248735545555000, 0.34875588629216070000,
  1127.             0.40868648199071680000, 0.46690290475095840000, 0.52316097472223300000, 0.57722472608397270000,
  1128.             0.62886739677651370000, 0.67787237963266400000, 0.72403413092381470000, 0.76715903251574020000,
  1129.             0.80706620402944250000, 0.84358826162439350000, 0.87657202027424800000, 0.90587913671556960000,
  1130.             0.93138669070655440000, 0.95298770316043080000, 0.97059159254624720000, 0.98412458372282700000,
  1131.             0.99353017226635080000, 0.99877100725242610000 };

  1132.         /** Weights for quadrature of order 48. */
  1133.         private static final double[] W_48 = { 0.00315334605230596250, 0.00732755390127620800, 0.01147723457923446900,
  1134.             0.01557931572294386600, 0.01961616045735556700, 0.02357076083932435600, 0.02742650970835688000,
  1135.             0.03116722783279807000, 0.03477722256477045000, 0.03824135106583080600, 0.04154508294346483000,
  1136.             0.04467456085669424000, 0.04761665849249054000, 0.05035903555385448000, 0.05289018948519365000,
  1137.             0.05519950369998416500, 0.05727729210040315000, 0.05911483969839566000, 0.06070443916589384000,
  1138.             0.06203942315989268000, 0.06311419228625403000, 0.06392423858464817000, 0.06446616443595010000,
  1139.             0.06473769681268386000, 0.06473769681268386000, 0.06446616443595010000, 0.06392423858464817000,
  1140.             0.06311419228625403000, 0.06203942315989268000, 0.06070443916589384000, 0.05911483969839566000,
  1141.             0.05727729210040315000, 0.05519950369998416500, 0.05289018948519365000, 0.05035903555385448000,
  1142.             0.04761665849249054000, 0.04467456085669424000, 0.04154508294346483000, 0.03824135106583080600,
  1143.             0.03477722256477045000, 0.03116722783279807000, 0.02742650970835688000, 0.02357076083932435600,
  1144.             0.01961616045735556700, 0.01557931572294386600, 0.01147723457923446900, 0.00732755390127620800,
  1145.             0.00315334605230596250 };

  1146.         /** Node points. */
  1147.         private final double[] nodePoints;

  1148.         /** Node weights. */
  1149.         private final double[] nodeWeights;

  1150.         /** Number of points. */
  1151.         private final int numberOfPoints;

  1152.         /**
  1153.          * Creates a Gauss integrator of the given order.
  1154.          *
  1155.          * @param numberOfPoints Order of the integration rule.
  1156.          */
  1157.         GaussQuadrature(final int numberOfPoints) {

  1158.             this.numberOfPoints = numberOfPoints;

  1159.             switch (numberOfPoints) {
  1160.                 case 12:
  1161.                     this.nodePoints = P_12.clone();
  1162.                     this.nodeWeights = W_12.clone();
  1163.                     break;
  1164.                 case 16:
  1165.                     this.nodePoints = P_16.clone();
  1166.                     this.nodeWeights = W_16.clone();
  1167.                     break;
  1168.                 case 20:
  1169.                     this.nodePoints = P_20.clone();
  1170.                     this.nodeWeights = W_20.clone();
  1171.                     break;
  1172.                 case 24:
  1173.                     this.nodePoints = P_24.clone();
  1174.                     this.nodeWeights = W_24.clone();
  1175.                     break;
  1176.                 case 32:
  1177.                     this.nodePoints = P_32.clone();
  1178.                     this.nodeWeights = W_32.clone();
  1179.                     break;
  1180.                 case 40:
  1181.                     this.nodePoints = P_40.clone();
  1182.                     this.nodeWeights = W_40.clone();
  1183.                     break;
  1184.                 case 48:
  1185.                 default:
  1186.                     this.nodePoints = P_48.clone();
  1187.                     this.nodeWeights = W_48.clone();
  1188.                     break;
  1189.             }

  1190.         }

  1191.         /**
  1192.          * Integrates a given function on the given interval.
  1193.          *
  1194.          * @param f          Function to integrate.
  1195.          * @param lowerBound Lower bound of the integration interval.
  1196.          * @param upperBound Upper bound of the integration interval.
  1197.          * @return the integral of the weighted function.
  1198.          */
  1199.         public double[] integrate(final UnivariateVectorFunction f, final double lowerBound, final double upperBound) {

  1200.             final double[] adaptedPoints = nodePoints.clone();
  1201.             final double[] adaptedWeights = nodeWeights.clone();
  1202.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1203.             return basicIntegrate(f, adaptedPoints, adaptedWeights);
  1204.         }

  1205.         /**
  1206.          * Integrates a given function on the given interval.
  1207.          *
  1208.          * @param <T>        the type of the field elements
  1209.          * @param f          Function to integrate.
  1210.          * @param lowerBound Lower bound of the integration interval.
  1211.          * @param upperBound Upper bound of the integration interval.
  1212.          * @param field      field utilized by default
  1213.          * @return the integral of the weighted function.
  1214.          */
  1215.         public <T extends CalculusFieldElement<T>> T[] integrate(final CalculusFieldUnivariateVectorFunction<T> f,
  1216.                 final T lowerBound, final T upperBound, final Field<T> field) {

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

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

  1220.             for (int i = 0; i < numberOfPoints; i++) {
  1221.                 adaptedPoints[i] = zero.add(nodePoints[i]);
  1222.                 adaptedWeights[i] = zero.add(nodeWeights[i]);
  1223.             }

  1224.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1225.             return basicIntegrate(f, adaptedPoints, adaptedWeights, field);
  1226.         }

  1227.         /**
  1228.          * Performs a change of variable so that the integration can be performed on an
  1229.          * arbitrary interval {@code [a, b]}.
  1230.          * <p>
  1231.          * It is assumed that the natural interval is {@code [-1, 1]}.
  1232.          * </p>
  1233.          *
  1234.          * @param points  Points to adapt to the new interval.
  1235.          * @param weights Weights to adapt to the new interval.
  1236.          * @param a       Lower bound of the integration interval.
  1237.          * @param b       Lower bound of the integration interval.
  1238.          */
  1239.         private void transform(final double[] points, final double[] weights, final double a, final double b) {
  1240.             // Scaling
  1241.             final double scale = (b - a) / 2;
  1242.             final double shift = a + scale;
  1243.             for (int i = 0; i < points.length; i++) {
  1244.                 points[i] = points[i] * scale + shift;
  1245.                 weights[i] *= scale;
  1246.             }
  1247.         }

  1248.         /**
  1249.          * Performs a change of variable so that the integration can be performed on an
  1250.          * arbitrary interval {@code [a, b]}.
  1251.          * <p>
  1252.          * It is assumed that the natural interval is {@code [-1, 1]}.
  1253.          * </p>
  1254.          * @param <T>     the type of the field elements
  1255.          * @param points  Points to adapt to the new interval.
  1256.          * @param weights Weights to adapt to the new interval.
  1257.          * @param a       Lower bound of the integration interval.
  1258.          * @param b       Lower bound of the integration interval
  1259.          */
  1260.         private <T extends CalculusFieldElement<T>> void transform(final T[] points, final T[] weights, final T a,
  1261.                 final T b) {
  1262.             // Scaling
  1263.             final T scale = (b.subtract(a)).divide(2.);
  1264.             final T shift = a.add(scale);
  1265.             for (int i = 0; i < points.length; i++) {
  1266.                 points[i] = scale.multiply(points[i]).add(shift);
  1267.                 weights[i] = scale.multiply(weights[i]);
  1268.             }
  1269.         }

  1270.         /**
  1271.          * Returns an estimate of the integral of {@code f(x) * w(x)}, where {@code w}
  1272.          * is a weight function that depends on the actual flavor of the Gauss
  1273.          * integration scheme.
  1274.          *
  1275.          * @param f       Function to integrate.
  1276.          * @param points  Nodes.
  1277.          * @param weights Nodes weights.
  1278.          * @return the integral of the weighted function.
  1279.          */
  1280.         private double[] basicIntegrate(final UnivariateVectorFunction f, final double[] points,
  1281.                 final double[] weights) {
  1282.             double x = points[0];
  1283.             double w = weights[0];
  1284.             double[] v = f.value(x);
  1285.             final double[] y = new double[v.length];
  1286.             for (int j = 0; j < v.length; j++) {
  1287.                 y[j] = w * v[j];
  1288.             }
  1289.             final double[] t = y.clone();
  1290.             final double[] c = new double[v.length];
  1291.             final double[] s = t.clone();
  1292.             for (int i = 1; i < points.length; i++) {
  1293.                 x = points[i];
  1294.                 w = weights[i];
  1295.                 v = f.value(x);
  1296.                 for (int j = 0; j < v.length; j++) {
  1297.                     y[j] = w * v[j] - c[j];
  1298.                     t[j] = s[j] + y[j];
  1299.                     c[j] = (t[j] - s[j]) - y[j];
  1300.                     s[j] = t[j];
  1301.                 }
  1302.             }
  1303.             return s;
  1304.         }

  1305.         /**
  1306.          * Returns an estimate of the integral of {@code f(x) * w(x)}, where {@code w}
  1307.          * is a weight function that depends on the actual flavor of the Gauss
  1308.          * integration scheme.
  1309.          *
  1310.          * @param <T>     the type of the field elements.
  1311.          * @param f       Function to integrate.
  1312.          * @param points  Nodes.
  1313.          * @param weights Nodes weight
  1314.          * @param field   field utilized by default
  1315.          * @return the integral of the weighted function.
  1316.          */
  1317.         private <T extends CalculusFieldElement<T>> T[] basicIntegrate(final CalculusFieldUnivariateVectorFunction<T> f,
  1318.                 final T[] points, final T[] weights, final Field<T> field) {

  1319.             T x = points[0];
  1320.             T w = weights[0];
  1321.             T[] v = f.value(x);

  1322.             final T[] y = MathArrays.buildArray(field, v.length);
  1323.             for (int j = 0; j < v.length; j++) {
  1324.                 y[j] = v[j].multiply(w);
  1325.             }
  1326.             final T[] t = y.clone();
  1327.             final T[] c = MathArrays.buildArray(field, v.length);
  1328.             ;
  1329.             final T[] s = t.clone();
  1330.             for (int i = 1; i < points.length; i++) {
  1331.                 x = points[i];
  1332.                 w = weights[i];
  1333.                 v = f.value(x);
  1334.                 for (int j = 0; j < v.length; j++) {
  1335.                     y[j] = v[j].multiply(w).subtract(c[j]);
  1336.                     t[j] = y[j].add(s[j]);
  1337.                     c[j] = (t[j].subtract(s[j])).subtract(y[j]);
  1338.                     s[j] = t[j];
  1339.                 }
  1340.             }
  1341.             return s;
  1342.         }

  1343.     }

  1344.     /**
  1345.      * Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  1346.      * coefficients.
  1347.      * <p>
  1348.      * Those coefficients are given in Danielson paper by expression 4.4-(6)
  1349.      * </p>
  1350.      * @author Petre Bazavan
  1351.      * @author Lucian Barbulescu
  1352.      */
  1353.     protected class FourierCjSjCoefficients {

  1354.         /** Maximum possible value for j. */
  1355.         private final int jMax;

  1356.         /**
  1357.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1358.          * <p>
  1359.          * the index i corresponds to the following elements: <br/>
  1360.          * - 0 for a <br>
  1361.          * - 1 for k <br>
  1362.          * - 2 for h <br>
  1363.          * - 3 for q <br>
  1364.          * - 4 for p <br>
  1365.          * - 5 for λ <br>
  1366.          * </p>
  1367.          */
  1368.         private final double[][] cCoef;

  1369.         /**
  1370.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1371.          * <p>
  1372.          * the index i corresponds to the following elements: <br/>
  1373.          * - 0 for a <br>
  1374.          * - 1 for k <br>
  1375.          * - 2 for h <br>
  1376.          * - 3 for q <br>
  1377.          * - 4 for p <br>
  1378.          * - 5 for λ <br>
  1379.          * </p>
  1380.          */
  1381.         private final double[][] sCoef;

  1382.         /**
  1383.          * Standard constructor.
  1384.          * @param state             the current state
  1385.          * @param jMax              maximum value for j
  1386.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1387.          * @param parameters        values of the force model parameters
  1388.          */
  1389.         FourierCjSjCoefficients(final SpacecraftState state, final int jMax, final AuxiliaryElements auxiliaryElements,
  1390.                 final double[] parameters) {

  1391.             // Initialise the fields
  1392.             this.jMax = jMax;

  1393.             // Allocate the arrays
  1394.             final int rows = jMax + 1;
  1395.             cCoef = new double[rows][6];
  1396.             sCoef = new double[rows][6];

  1397.             // Compute the coefficients
  1398.             computeCoefficients(state, auxiliaryElements, parameters);
  1399.         }

  1400.         /**
  1401.          * Compute the Fourrier coefficients.
  1402.          * <p>
  1403.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients
  1404.          * need to be computed as D<sub>i</sub><sup>m</sup> is always 0.
  1405.          * </p>
  1406.          * @param state             the current state
  1407.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1408.          * @param parameters        values of the force model parameters
  1409.          */
  1410.         private void computeCoefficients(final SpacecraftState state, final AuxiliaryElements auxiliaryElements,
  1411.                 final double[] parameters) {

  1412.             // Computes the limits for the integral
  1413.             final double[] ll = getLLimits(state, auxiliaryElements);
  1414.             // Computes integrated mean element rates if Llow < Lhigh
  1415.             if (ll[0] < ll[1]) {
  1416.                 // Compute 1 / PI
  1417.                 final double ooPI = 1 / FastMath.PI;

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

  1422.                     // divide by PI and set the values for the coefficients
  1423.                     for (int i = 0; i < 6; i++) {
  1424.                         cCoef[j][i] = ooPI * curentCoefficients[i];
  1425.                         sCoef[j][i] = ooPI * curentCoefficients[i + 6];
  1426.                     }
  1427.                 }
  1428.             }
  1429.         }

  1430.         /**
  1431.          * Get the coefficient C<sub>i</sub><sup>j</sup>.
  1432.          * @param i i index - corresponds to the required variation
  1433.          * @param j j index
  1434.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1435.          */
  1436.         public double getCij(final int i, final int j) {
  1437.             return cCoef[j][i];
  1438.         }

  1439.         /**
  1440.          * Get the coefficient S<sub>i</sub><sup>j</sup>.
  1441.          * @param i i index - corresponds to the required variation
  1442.          * @param j j index
  1443.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1444.          */
  1445.         public double getSij(final int i, final int j) {
  1446.             return sCoef[j][i];
  1447.         }
  1448.     }

  1449.     /**
  1450.      * Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  1451.      * coefficients with field elements.
  1452.      * <p>
  1453.      * Those coefficients are given in Danielson paper by expression 4.4-(6)
  1454.      * </p>
  1455.      * @author Petre Bazavan
  1456.      * @author Lucian Barbulescu
  1457.      */
  1458.     protected class FieldFourierCjSjCoefficients<T extends CalculusFieldElement<T>> {

  1459.         /** Maximum possible value for j. */
  1460.         private final int jMax;

  1461.         /**
  1462.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1463.          * <p>
  1464.          * the index i corresponds to the following elements: <br/>
  1465.          * - 0 for a <br>
  1466.          * - 1 for k <br>
  1467.          * - 2 for h <br>
  1468.          * - 3 for q <br>
  1469.          * - 4 for p <br>
  1470.          * - 5 for λ <br>
  1471.          * </p>
  1472.          */
  1473.         private final T[][] cCoef;

  1474.         /**
  1475.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1476.          * <p>
  1477.          * the index i corresponds to the following elements: <br/>
  1478.          * - 0 for a <br>
  1479.          * - 1 for k <br>
  1480.          * - 2 for h <br>
  1481.          * - 3 for q <br>
  1482.          * - 4 for p <br>
  1483.          * - 5 for λ <br>
  1484.          * </p>
  1485.          */
  1486.         private final T[][] sCoef;

  1487.         /**
  1488.          * Standard constructor.
  1489.          * @param state             the current state
  1490.          * @param jMax              maximum value for j
  1491.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1492.          * @param parameters        values of the force model parameters
  1493.          * @param field             field used by default
  1494.          */
  1495.         FieldFourierCjSjCoefficients(final FieldSpacecraftState<T> state, final int jMax,
  1496.                 final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters, final Field<T> field) {
  1497.             // Initialise the fields
  1498.             this.jMax = jMax;

  1499.             // Allocate the arrays
  1500.             final int rows = jMax + 1;
  1501.             cCoef = MathArrays.buildArray(field, rows, 6);
  1502.             sCoef = MathArrays.buildArray(field, rows, 6);

  1503.             // Compute the coefficients
  1504.             computeCoefficients(state, auxiliaryElements, parameters, field);
  1505.         }

  1506.         /**
  1507.          * Compute the Fourrier coefficients.
  1508.          * <p>
  1509.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients
  1510.          * need to be computed as D<sub>i</sub><sup>m</sup> is always 0.
  1511.          * </p>
  1512.          * @param state             the current state
  1513.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1514.          * @param parameters        values of the force model parameters
  1515.          * @param field             field used by default
  1516.          */
  1517.         private void computeCoefficients(final FieldSpacecraftState<T> state,
  1518.                 final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters, final Field<T> field) {
  1519.             // Zero
  1520.             final T zero = field.getZero();
  1521.             // Computes the limits for the integral
  1522.             final T[] ll = getLLimits(state, auxiliaryElements);
  1523.             // Computes integrated mean element rates if Llow < Lhigh
  1524.             if (ll[0].getReal() < ll[1].getReal()) {
  1525.                 // Compute 1 / PI
  1526.                 final T ooPI = zero.getPi().reciprocal();

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

  1531.                     // divide by PI and set the values for the coefficients
  1532.                     for (int i = 0; i < 6; i++) {
  1533.                         cCoef[j][i] = curentCoefficients[i].multiply(ooPI);
  1534.                         sCoef[j][i] = curentCoefficients[i + 6].multiply(ooPI);
  1535.                     }
  1536.                 }
  1537.             }
  1538.         }

  1539.         /**
  1540.          * Get the coefficient C<sub>i</sub><sup>j</sup>.
  1541.          * @param i i index - corresponds to the required variation
  1542.          * @param j j index
  1543.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1544.          */
  1545.         public T getCij(final int i, final int j) {
  1546.             return cCoef[j][i];
  1547.         }

  1548.         /**
  1549.          * Get the coefficient S<sub>i</sub><sup>j</sup>.
  1550.          * @param i i index - corresponds to the required variation
  1551.          * @param j j index
  1552.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1553.          */
  1554.         public T getSij(final int i, final int j) {
  1555.             return sCoef[j][i];
  1556.         }
  1557.     }

  1558.     /**
  1559.      * This class handles the short periodic coefficients described in Danielson
  1560.      * 2.5.3-26.
  1561.      *
  1562.      * <p>
  1563.      * The value of M is 0. Also, since the values of the Fourier coefficient
  1564.      * D<sub>i</sub><sup>m</sup> is 0 then the values of the coefficients
  1565.      * D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1566.      * </p>
  1567.      * @author Petre Bazavan
  1568.      * @author Lucian Barbulescu
  1569.      *
  1570.      */
  1571.     protected static class GaussianShortPeriodicCoefficients implements ShortPeriodTerms {

  1572.         /** Maximum value for j index. */
  1573.         private final int jMax;

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

  1576.         /** Prefix for coefficients keys. */
  1577.         private final String coefficientsKeyPrefix;

  1578.         /** All coefficients slots. */
  1579.         private final transient TimeSpanMap<Slot> slots;

  1580.         /**
  1581.          * Constructor.
  1582.          * @param coefficientsKeyPrefix prefix for coefficients keys
  1583.          * @param jMax                  maximum value for j index
  1584.          * @param interpolationPoints   number of points used in the interpolation
  1585.          *                              process
  1586.          * @param slots                 all coefficients slots
  1587.          */
  1588.         GaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix, final int jMax,
  1589.                 final int interpolationPoints, final TimeSpanMap<Slot> slots) {
  1590.             // Initialize fields
  1591.             this.jMax = jMax;
  1592.             this.interpolationPoints = interpolationPoints;
  1593.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1594.             this.slots = slots;
  1595.         }

  1596.         /**
  1597.          * Get the slot valid for some date.
  1598.          * @param meanStates mean states defining the slot
  1599.          * @return slot valid at the specified date
  1600.          */
  1601.         public Slot createSlot(final SpacecraftState... meanStates) {
  1602.             final Slot slot = new Slot(jMax, interpolationPoints);
  1603.             final AbsoluteDate first = meanStates[0].getDate();
  1604.             final AbsoluteDate last = meanStates[meanStates.length - 1].getDate();
  1605.             final int compare = first.compareTo(last);
  1606.             if (compare < 0) {
  1607.                 slots.addValidAfter(slot, first, false);
  1608.             } else if (compare > 0) {
  1609.                 slots.addValidBefore(slot, first, false);
  1610.             } else {
  1611.                 // single date, valid for all time
  1612.                 slots.addValidAfter(slot, AbsoluteDate.PAST_INFINITY, false);
  1613.             }
  1614.             return slot;
  1615.         }

  1616.         /**
  1617.          * Compute the short periodic coefficients.
  1618.          *
  1619.          * @param state       current state information: date, kinematics, attitude
  1620.          * @param slot        coefficients slot
  1621.          * @param fourierCjSj Fourier coefficients
  1622.          * @param uijvij      U and V coefficients
  1623.          * @param n           Keplerian mean motion
  1624.          * @param a           semi major axis
  1625.          */
  1626.         private void computeCoefficients(final SpacecraftState state, final Slot slot,
  1627.                 final FourierCjSjCoefficients fourierCjSj, final UijVijCoefficients uijvij, final double n,
  1628.                 final double a) {

  1629.             // get the current date
  1630.             final AbsoluteDate date = state.getDate();

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

  1633.             // 1. / n
  1634.             final double oon = 1. / n;
  1635.             // 3. / (2 * a * n)
  1636.             final double to2an = 1.5 * oon / a;
  1637.             // 3. / (4 * a * n)
  1638.             final double to4an = to2an / 2;

  1639.             // Compute the coefficients for each element
  1640.             final int size = jMax + 1;
  1641.             final double[] di1 = new double[6];
  1642.             final double[] di2 = new double[6];
  1643.             final double[][] currentCij = new double[size][6];
  1644.             final double[][] currentSij = new double[size][6];
  1645.             for (int i = 0; i < 6; i++) {

  1646.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  1647.                 di1[i] = -oon * fourierCjSj.getCij(i, 0);
  1648.                 if (i == 5) {
  1649.                     di1[i] += to2an * uijvij.getU1(0, 0);
  1650.                 }
  1651.                 di2[i] = 0.;
  1652.                 if (i == 5) {
  1653.                     di2[i] += -to4an * fourierCjSj.getCij(0, 0);
  1654.                 }

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

  1657.                 for (int j = 1; j <= jMax; j++) {
  1658.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  1659.                     currentCij[j][i] = oon * uijvij.getU1(j, i);
  1660.                     if (i == 5) {
  1661.                         currentCij[j][i] += -to2an * uijvij.getU2(j);
  1662.                     }
  1663.                     currentSij[j][i] = oon * uijvij.getV1(j, i);
  1664.                     if (i == 5) {
  1665.                         currentSij[j][i] += -to2an * uijvij.getV2(j);
  1666.                     }

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

  1671.             }

  1672.             // add the values to the interpolators
  1673.             slot.cij[0].addGridPoint(date, currentCij[0]);
  1674.             slot.dij[1].addGridPoint(date, di1);
  1675.             slot.dij[2].addGridPoint(date, di2);
  1676.             for (int j = 1; j <= jMax; j++) {
  1677.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  1678.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  1679.             }

  1680.         }

  1681.         /**
  1682.          * Compute the coefficient k₂⁰ by using the equation 2.5.3-(9a) from Danielson.
  1683.          * <p>
  1684.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  1685.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² +
  1686.          * ρ<sub>k</sub>²)]
  1687.          * </p>
  1688.          * @param kMax             max value fot k index
  1689.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  1690.          *                         σ<sub>j</sub> coefficients
  1691.          * @return the coefficient k₂⁰
  1692.          */
  1693.         private double computeK20(final int kMax, final double[][] currentRhoSigmaj) {
  1694.             double k20 = 0.;

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

  1701.                 // multiply by 2 / k²
  1702.                 currentTerm *= 2. / (kIndex * kIndex);

  1703.                 // add the term to the result
  1704.                 k20 += currentTerm;
  1705.             }

  1706.             return k20;
  1707.         }

  1708.         /** {@inheritDoc} */
  1709.         @Override
  1710.         public double[] value(final Orbit meanOrbit) {

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

  1713.             // Get the True longitude L
  1714.             final double L = meanOrbit.getLv();

  1715.             // Compute the center (l - λ)
  1716.             final double center = L - meanOrbit.getLM();
  1717.             // Compute (l - λ)²
  1718.             final double center2 = center * center;

  1719.             // Initialize short periodic variations
  1720.             final double[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  1721.             final double[] d1 = slot.dij[1].value(meanOrbit.getDate());
  1722.             final double[] d2 = slot.dij[2].value(meanOrbit.getDate());
  1723.             for (int i = 0; i < 6; i++) {
  1724.                 shortPeriodicVariation[i] += center * d1[i] + center2 * d2[i];
  1725.             }

  1726.             for (int j = 1; j <= JMAX; j++) {
  1727.                 final double[] c = slot.cij[j].value(meanOrbit.getDate());
  1728.                 final double[] s = slot.sij[j].value(meanOrbit.getDate());
  1729.                 final SinCos sc  = FastMath.sinCos(j * L);
  1730.                 final double cos = sc.cos();
  1731.                 final double sin = sc.sin();
  1732.                 for (int i = 0; i < 6; i++) {
  1733.                     // add corresponding term to the short periodic variation
  1734.                     shortPeriodicVariation[i] += c[i] * cos;
  1735.                     shortPeriodicVariation[i] += s[i] * sin;
  1736.                 }
  1737.             }

  1738.             return shortPeriodicVariation;

  1739.         }

  1740.         /** {@inheritDoc} */
  1741.         public String getCoefficientsKeyPrefix() {
  1742.             return coefficientsKeyPrefix;
  1743.         }

  1744.         /**
  1745.          * {@inheritDoc}
  1746.          * <p>
  1747.          * For Gaussian forces, there are JMAX cj coefficients, JMAX sj coefficients and
  1748.          * 3 dj coefficients. As JMAX = 12, this sums up to 27 coefficients. The j index
  1749.          * is the integer multiplier for the true longitude argument in the cj and sj
  1750.          * coefficients and to the degree in the polynomial dj coefficients.
  1751.          * </p>
  1752.          */
  1753.         @Override
  1754.         public Map<String, double[]> getCoefficients(final AbsoluteDate date, final Set<String> selected) {

  1755.             // select the coefficients slot
  1756.             final Slot slot = slots.get(date);

  1757.             final Map<String, double[]> coefficients = new HashMap<String, double[]>(2 * JMAX + 3);
  1758.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  1759.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  1760.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  1761.             for (int j = 1; j <= JMAX; j++) {
  1762.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  1763.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  1764.             }

  1765.             return coefficients;

  1766.         }

  1767.         /**
  1768.          * Put a coefficient in a map if selected.
  1769.          * @param map      map to populate
  1770.          * @param selected set of coefficients that should be put in the map (empty set
  1771.          *                 means all coefficients are selected)
  1772.          * @param value    coefficient value
  1773.          * @param id       coefficient identifier
  1774.          * @param indices  list of coefficient indices
  1775.          */
  1776.         private void storeIfSelected(final Map<String, double[]> map, final Set<String> selected, final double[] value,
  1777.                 final String id, final int... indices) {
  1778.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  1779.             keyBuilder.append(id);
  1780.             for (int index : indices) {
  1781.                 keyBuilder.append('[').append(index).append(']');
  1782.             }
  1783.             final String key = keyBuilder.toString();
  1784.             if (selected.isEmpty() || selected.contains(key)) {
  1785.                 map.put(key, value);
  1786.             }
  1787.         }

  1788.     }

  1789.     /**
  1790.      * This class handles the short periodic coefficients described in Danielson
  1791.      * 2.5.3-26.
  1792.      *
  1793.      * <p>
  1794.      * The value of M is 0. Also, since the values of the Fourier coefficient
  1795.      * D<sub>i</sub><sup>m</sup> is 0 then the values of the coefficients
  1796.      * D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1797.      * </p>
  1798.      * @author Petre Bazavan
  1799.      * @author Lucian Barbulescu
  1800.      *
  1801.      */
  1802.     protected static class FieldGaussianShortPeriodicCoefficients<T extends CalculusFieldElement<T>>
  1803.             implements FieldShortPeriodTerms<T> {

  1804.         /** Maximum value for j index. */
  1805.         private final int jMax;

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

  1808.         /** Prefix for coefficients keys. */
  1809.         private final String coefficientsKeyPrefix;

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

  1812.         /**
  1813.          * Constructor.
  1814.          * @param coefficientsKeyPrefix prefix for coefficients keys
  1815.          * @param jMax                  maximum value for j index
  1816.          * @param interpolationPoints   number of points used in the interpolation
  1817.          *                              process
  1818.          * @param slots                 all coefficients slots
  1819.          */
  1820.         FieldGaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix, final int jMax,
  1821.                 final int interpolationPoints, final FieldTimeSpanMap<FieldSlot<T>, T> slots) {
  1822.             // Initialize fields
  1823.             this.jMax = jMax;
  1824.             this.interpolationPoints = interpolationPoints;
  1825.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1826.             this.slots = slots;
  1827.         }

  1828.         /**
  1829.          * Get the slot valid for some date.
  1830.          * @param meanStates mean states defining the slot
  1831.          * @return slot valid at the specified date
  1832.          */
  1833.         @SuppressWarnings("unchecked")
  1834.         public FieldSlot<T> createSlot(final FieldSpacecraftState<T>... meanStates) {
  1835.             final FieldSlot<T> slot = new FieldSlot<>(jMax, interpolationPoints);
  1836.             final FieldAbsoluteDate<T> first = meanStates[0].getDate();
  1837.             final FieldAbsoluteDate<T> last = meanStates[meanStates.length - 1].getDate();
  1838.             if (first.compareTo(last) <= 0) {
  1839.                 slots.addValidAfter(slot, first);
  1840.             } else {
  1841.                 slots.addValidBefore(slot, first);
  1842.             }
  1843.             return slot;
  1844.         }

  1845.         /**
  1846.          * Compute the short periodic coefficients.
  1847.          *
  1848.          * @param state       current state information: date, kinematics, attitude
  1849.          * @param slot        coefficients slot
  1850.          * @param fourierCjSj Fourier coefficients
  1851.          * @param uijvij      U and V coefficients
  1852.          * @param n           Keplerian mean motion
  1853.          * @param a           semi major axis
  1854.          * @param field       field used by default
  1855.          */
  1856.         private void computeCoefficients(final FieldSpacecraftState<T> state, final FieldSlot<T> slot,
  1857.                 final FieldFourierCjSjCoefficients<T> fourierCjSj, final FieldUijVijCoefficients<T> uijvij, final T n,
  1858.                 final T a, final Field<T> field) {

  1859.             // Zero
  1860.             final T zero = field.getZero();

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

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

  1865.             // 1. / n
  1866.             final T oon = n.reciprocal();
  1867.             // 3. / (2 * a * n)
  1868.             final T to2an = oon.multiply(1.5).divide(a);
  1869.             // 3. / (4 * a * n)
  1870.             final T to4an = to2an.divide(2.);

  1871.             // Compute the coefficients for each element
  1872.             final int size = jMax + 1;
  1873.             final T[] di1 = MathArrays.buildArray(field, 6);
  1874.             final T[] di2 = MathArrays.buildArray(field, 6);
  1875.             final T[][] currentCij = MathArrays.buildArray(field, size, 6);
  1876.             final T[][] currentSij = MathArrays.buildArray(field, size, 6);
  1877.             for (int i = 0; i < 6; i++) {

  1878.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  1879.                 di1[i] = oon.negate().multiply(fourierCjSj.getCij(i, 0));
  1880.                 if (i == 5) {
  1881.                     di1[i] = di1[i].add(to2an.multiply(uijvij.getU1(0, 0)));
  1882.                 }
  1883.                 di2[i] = zero;
  1884.                 if (i == 5) {
  1885.                     di2[i] = di2[i].add(to4an.negate().multiply(fourierCjSj.getCij(0, 0)));
  1886.                 }

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

  1889.                 for (int j = 1; j <= jMax; j++) {
  1890.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  1891.                     currentCij[j][i] = oon.multiply(uijvij.getU1(j, i));
  1892.                     if (i == 5) {
  1893.                         currentCij[j][i] = currentCij[j][i].add(to2an.negate().multiply(uijvij.getU2(j)));
  1894.                     }
  1895.                     currentSij[j][i] = oon.multiply(uijvij.getV1(j, i));
  1896.                     if (i == 5) {
  1897.                         currentSij[j][i] = currentSij[j][i].add(to2an.negate().multiply(uijvij.getV2(j)));
  1898.                     }

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

  1903.             }

  1904.             // add the values to the interpolators
  1905.             slot.cij[0].addGridPoint(date, currentCij[0]);
  1906.             slot.dij[1].addGridPoint(date, di1);
  1907.             slot.dij[2].addGridPoint(date, di2);
  1908.             for (int j = 1; j <= jMax; j++) {
  1909.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  1910.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  1911.             }

  1912.         }

  1913.         /**
  1914.          * Compute the coefficient k₂⁰ by using the equation 2.5.3-(9a) from Danielson.
  1915.          * <p>
  1916.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  1917.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² +
  1918.          * ρ<sub>k</sub>²)]
  1919.          * </p>
  1920.          * @param kMax             max value fot k index
  1921.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  1922.          *                         σ<sub>j</sub> coefficients
  1923.          * @param field            field used by default
  1924.          * @return the coefficient k₂⁰
  1925.          */
  1926.         private T computeK20(final int kMax, final T[][] currentRhoSigmaj, final Field<T> field) {
  1927.             final T zero = field.getZero();
  1928.             T k20 = zero;

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

  1935.                 // multiply by 2 / k²
  1936.                 currentTerm = currentTerm.multiply(2. / (kIndex * kIndex));

  1937.                 // add the term to the result
  1938.                 k20 = k20.add(currentTerm);
  1939.             }

  1940.             return k20;
  1941.         }

  1942.         /** {@inheritDoc} */
  1943.         @Override
  1944.         public T[] value(final FieldOrbit<T> meanOrbit) {

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

  1947.             // Get the True longitude L
  1948.             final T L = meanOrbit.getLv();

  1949.             // Compute the center (l - λ)
  1950.             final T center = L.subtract(meanOrbit.getLM());
  1951.             // Compute (l - λ)²
  1952.             final T center2 = center.multiply(center);

  1953.             // Initialize short periodic variations
  1954.             final T[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  1955.             final T[] d1 = slot.dij[1].value(meanOrbit.getDate());
  1956.             final T[] d2 = slot.dij[2].value(meanOrbit.getDate());
  1957.             for (int i = 0; i < 6; i++) {
  1958.                 shortPeriodicVariation[i] = shortPeriodicVariation[i]
  1959.                         .add(center.multiply(d1[i]).add(center2.multiply(d2[i])));
  1960.             }

  1961.             for (int j = 1; j <= JMAX; j++) {
  1962.                 final T[] c = slot.cij[j].value(meanOrbit.getDate());
  1963.                 final T[] s = slot.sij[j].value(meanOrbit.getDate());
  1964.                 final FieldSinCos<T> sc = FastMath.sinCos(L.multiply(j));
  1965.                 final T cos = sc.cos();
  1966.                 final T sin = sc.sin();
  1967.                 for (int i = 0; i < 6; i++) {
  1968.                     // add corresponding term to the short periodic variation
  1969.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(c[i].multiply(cos));
  1970.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(s[i].multiply(sin));
  1971.                 }
  1972.             }

  1973.             return shortPeriodicVariation;

  1974.         }

  1975.         /** {@inheritDoc} */
  1976.         public String getCoefficientsKeyPrefix() {
  1977.             return coefficientsKeyPrefix;
  1978.         }

  1979.         /**
  1980.          * {@inheritDoc}
  1981.          * <p>
  1982.          * For Gaussian forces, there are JMAX cj coefficients, JMAX sj coefficients and
  1983.          * 3 dj coefficients. As JMAX = 12, this sums up to 27 coefficients. The j index
  1984.          * is the integer multiplier for the true longitude argument in the cj and sj
  1985.          * coefficients and to the degree in the polynomial dj coefficients.
  1986.          * </p>
  1987.          */
  1988.         @Override
  1989.         public Map<String, T[]> getCoefficients(final FieldAbsoluteDate<T> date, final Set<String> selected) {

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

  1992.             final Map<String, T[]> coefficients = new HashMap<String, T[]>(2 * JMAX + 3);
  1993.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  1994.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  1995.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  1996.             for (int j = 1; j <= JMAX; j++) {
  1997.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  1998.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  1999.             }

  2000.             return coefficients;

  2001.         }

  2002.         /**
  2003.          * Put a coefficient in a map if selected.
  2004.          * @param map      map to populate
  2005.          * @param selected set of coefficients that should be put in the map (empty set
  2006.          *                 means all coefficients are selected)
  2007.          * @param value    coefficient value
  2008.          * @param id       coefficient identifier
  2009.          * @param indices  list of coefficient indices
  2010.          */
  2011.         private void storeIfSelected(final Map<String, T[]> map, final Set<String> selected, final T[] value,
  2012.                 final String id, final int... indices) {
  2013.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  2014.             keyBuilder.append(id);
  2015.             for (int index : indices) {
  2016.                 keyBuilder.append('[').append(index).append(']');
  2017.             }
  2018.             final String key = keyBuilder.toString();
  2019.             if (selected.isEmpty() || selected.contains(key)) {
  2020.                 map.put(key, value);
  2021.             }
  2022.         }

  2023.     }

  2024.     /**
  2025.      * The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients
  2026.      * described by equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2027.      * <p>
  2028.      * The index i takes only the values 1 and 2<br>
  2029.      * For U only the index 0 for j is used.
  2030.      * </p>
  2031.      *
  2032.      * @author Petre Bazavan
  2033.      * @author Lucian Barbulescu
  2034.      */
  2035.     protected static class UijVijCoefficients {

  2036.         /**
  2037.          * The U₁<sup>j</sup> coefficients.
  2038.          * <p>
  2039.          * The first index identifies the Fourier coefficients used<br>
  2040.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2041.          * S<sub>i</sub><sup>j</sup><br>
  2042.          * The only exception is when j = 0 when only the coefficient for fourier index
  2043.          * = 1 (i == 0) is needed.<br>
  2044.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are
  2045.          * computed, because are required to compute the coefficients U₂<sup>j</sup>
  2046.          * </p>
  2047.          */
  2048.         private final double[][] u1ij;

  2049.         /**
  2050.          * The V₁<sup>j</sup> coefficients.
  2051.          * <p>
  2052.          * The first index identifies the Fourier coefficients used<br>
  2053.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2054.          * S<sub>i</sub><sup>j</sup><br>
  2055.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed,
  2056.          * because are required to compute the coefficients V₂<sup>j</sup>
  2057.          * </p>
  2058.          */
  2059.         private final double[][] v1ij;

  2060.         /**
  2061.          * The U₂<sup>j</sup> coefficients.
  2062.          * <p>
  2063.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2064.          * they are the only ones required.
  2065.          * </p>
  2066.          */
  2067.         private final double[] u2ij;

  2068.         /**
  2069.          * The V₂<sup>j</sup> coefficients.
  2070.          * <p>
  2071.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2072.          * they are the only ones required.
  2073.          * </p>
  2074.          */
  2075.         private final double[] v2ij;

  2076.         /**
  2077.          * The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub>
  2078.          * coefficients.
  2079.          */
  2080.         private final double[][] currentRhoSigmaj;

  2081.         /**
  2082.          * The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier
  2083.          * coefficients.
  2084.          */
  2085.         private final FourierCjSjCoefficients fourierCjSj;

  2086.         /** The maximum value for j index. */
  2087.         private final int jMax;

  2088.         /**
  2089.          * Constructor.
  2090.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  2091.          *                         σ<sub>j</sub> coefficients
  2092.          * @param fourierCjSj      the fourier coefficients C<sub>i</sub><sup>j</sup>
  2093.          *                         and the S<sub>i</sub><sup>j</sup>
  2094.          * @param jMax             maximum value for j index
  2095.          */
  2096.         UijVijCoefficients(final double[][] currentRhoSigmaj, final FourierCjSjCoefficients fourierCjSj,
  2097.                 final int jMax) {
  2098.             this.currentRhoSigmaj = currentRhoSigmaj;
  2099.             this.fourierCjSj = fourierCjSj;
  2100.             this.jMax = jMax;

  2101.             // initialize the internal arrays.
  2102.             this.u1ij = new double[6][2 * jMax + 1];
  2103.             this.v1ij = new double[6][2 * jMax + 1];
  2104.             this.u2ij = new double[jMax + 1];
  2105.             this.v2ij = new double[jMax + 1];

  2106.             // compute the coefficients
  2107.             computeU1V1Coefficients();
  2108.             computeU2V2Coefficients();
  2109.         }

  2110.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients. */
  2111.         private void computeU1V1Coefficients() {
  2112.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2113.             // for j >= 1
  2114.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2115.             u1ij[0][0] = 0;
  2116.             for (int j = 1; j <= jMax; j++) {
  2117.                 // compute 1 / j
  2118.                 final double ooj = 1. / j;

  2119.                 for (int i = 0; i < 6; i++) {
  2120.                     // j is aready between 1 and J
  2121.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2122.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2123.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2124.                     if (j > 1) {
  2125.                         // k starts with 1 because j-J is less than or equal to 0
  2126.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2127.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2128.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2129.                             u1ij[i][j] += fourierCjSj.getCij(i, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2130.                                     fourierCjSj.getSij(i, j - kIndex) * currentRhoSigmaj[0][kIndex];

  2131.                             // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2132.                             // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2133.                             v1ij[i][j] += fourierCjSj.getCij(i, j - kIndex) * currentRhoSigmaj[0][kIndex] -
  2134.                                     fourierCjSj.getSij(i, j - kIndex) * currentRhoSigmaj[1][kIndex];
  2135.                         }
  2136.                     }

  2137.                     // since j must be between 1 and J-1 and is already between 1 and J
  2138.                     // the following sum is skiped only for j = jMax
  2139.                     if (j != jMax) {
  2140.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2141.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2142.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2143.                             u1ij[i][j] += -fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[1][kIndex] +
  2144.                                     fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[0][kIndex];

  2145.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2146.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2147.                             v1ij[i][j] += fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[0][kIndex] +
  2148.                                     fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[1][kIndex];
  2149.                         }
  2150.                     }

  2151.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2152.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2153.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2154.                         u1ij[i][j] += -fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2155.                                 fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2156.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2157.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2158.                         v1ij[i][j] += fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2159.                                 fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2160.                     }

  2161.                     // divide by 1 / j
  2162.                     u1ij[i][j] *= -ooj;
  2163.                     v1ij[i][j] *= ooj;

  2164.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2165.                     if (i == 0) {
  2166.                         // - (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2167.                         u1ij[0][0] += -u1ij[0][j] * currentRhoSigmaj[0][j] - v1ij[0][j] * currentRhoSigmaj[1][j];
  2168.                     }
  2169.                 }
  2170.             }

  2171.             // Terms with j > jMax are required only when computing the coefficients
  2172.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2173.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2174.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2175.                 // compute 1 / j
  2176.                 final double ooj = 1. / j;
  2177.                 // the value of i is 0
  2178.                 u1ij[0][j] = 0.;
  2179.                 v1ij[0][j] = 0.;

  2180.                 // k starts from j-J as it is always greater than or equal to 1
  2181.                 for (int kIndex = j - jMax; kIndex <= j - 1; kIndex++) {
  2182.                     // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2183.                     // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2184.                     u1ij[0][j] += fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2185.                             fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[0][kIndex];

  2186.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2187.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2188.                     v1ij[0][j] += fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[0][kIndex] -
  2189.                             fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[1][kIndex];
  2190.                 }
  2191.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2192.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2193.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2194.                     u1ij[0][j] += -fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2195.                             fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2196.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2197.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2198.                     v1ij[0][j] += fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2199.                             fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2200.                 }

  2201.                 // divide by 1 / j
  2202.                 u1ij[0][j] *= -ooj;
  2203.                 v1ij[0][j] *= ooj;
  2204.             }
  2205.         }

  2206.         /**
  2207.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2208.          * <p>
  2209.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2210.          * </p>
  2211.          */
  2212.         private void computeU2V2Coefficients() {
  2213.             for (int j = 1; j <= jMax; j++) {
  2214.                 // compute 1 / j
  2215.                 final double ooj = 1. / j;

  2216.                 // only the values for i == 0 are computed
  2217.                 u2ij[j] = v1ij[0][j];
  2218.                 v2ij[j] = u1ij[0][j];

  2219.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2220.                 if (j > 1) {
  2221.                     for (int l = 1; l <= j - 1; l++) {
  2222.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2223.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2224.                         u2ij[j] += u1ij[0][j - l] * currentRhoSigmaj[1][l] + v1ij[0][j - l] * currentRhoSigmaj[0][l];

  2225.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2226.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2227.                         v2ij[j] += u1ij[0][j - l] * currentRhoSigmaj[0][l] - v1ij[0][j - l] * currentRhoSigmaj[1][l];
  2228.                     }
  2229.                 }

  2230.                 for (int l = 1; l <= jMax; l++) {
  2231.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2232.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2233.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2234.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2235.                     u2ij[j] += -u1ij[0][j + l] * currentRhoSigmaj[1][l] + u1ij[0][l] * currentRhoSigmaj[1][j + l] +
  2236.                             v1ij[0][j + l] * currentRhoSigmaj[0][l] - v1ij[0][l] * currentRhoSigmaj[0][j + l];

  2237.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2238.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2239.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2240.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2241.                     u2ij[j] += u1ij[0][j + l] * currentRhoSigmaj[0][l] + u1ij[0][l] * currentRhoSigmaj[0][j + l] +
  2242.                             v1ij[0][j + l] * currentRhoSigmaj[1][l] + v1ij[0][l] * currentRhoSigmaj[1][j + l];
  2243.                 }

  2244.                 // divide by 1 / j
  2245.                 u2ij[j] *= -ooj;
  2246.                 v2ij[j] *= ooj;
  2247.             }
  2248.         }

  2249.         /**
  2250.          * Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2251.          *
  2252.          * @param j j index
  2253.          * @param i Fourier index (starts at 0)
  2254.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2255.          */
  2256.         public double getU1(final int j, final int i) {
  2257.             return u1ij[i][j];
  2258.         }

  2259.         /**
  2260.          * Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2261.          *
  2262.          * @param j j index
  2263.          * @param i Fourier index (starts at 0)
  2264.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2265.          */
  2266.         public double getV1(final int j, final int i) {
  2267.             return v1ij[i][j];
  2268.         }

  2269.         /**
  2270.          * Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2271.          *
  2272.          * @param j j index
  2273.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2274.          */
  2275.         public double getU2(final int j) {
  2276.             return u2ij[j];
  2277.         }

  2278.         /**
  2279.          * Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2280.          *
  2281.          * @param j j index
  2282.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2283.          */
  2284.         public double getV2(final int j) {
  2285.             return v2ij[j];
  2286.         }
  2287.     }

  2288.     /**
  2289.      * The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients
  2290.      * described by equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2291.      * <p>
  2292.      * The index i takes only the values 1 and 2<br>
  2293.      * For U only the index 0 for j is used.
  2294.      * </p>
  2295.      *
  2296.      * @author Petre Bazavan
  2297.      * @author Lucian Barbulescu
  2298.      */
  2299.     protected static class FieldUijVijCoefficients<T extends CalculusFieldElement<T>> {

  2300.         /**
  2301.          * The U₁<sup>j</sup> coefficients.
  2302.          * <p>
  2303.          * The first index identifies the Fourier coefficients used<br>
  2304.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2305.          * S<sub>i</sub><sup>j</sup><br>
  2306.          * The only exception is when j = 0 when only the coefficient for fourier index
  2307.          * = 1 (i == 0) is needed.<br>
  2308.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are
  2309.          * computed, because are required to compute the coefficients U₂<sup>j</sup>
  2310.          * </p>
  2311.          */
  2312.         private final T[][] u1ij;

  2313.         /**
  2314.          * The V₁<sup>j</sup> coefficients.
  2315.          * <p>
  2316.          * The first index identifies the Fourier coefficients used<br>
  2317.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2318.          * S<sub>i</sub><sup>j</sup><br>
  2319.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed,
  2320.          * because are required to compute the coefficients V₂<sup>j</sup>
  2321.          * </p>
  2322.          */
  2323.         private final T[][] v1ij;

  2324.         /**
  2325.          * The U₂<sup>j</sup> coefficients.
  2326.          * <p>
  2327.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2328.          * they are the only ones required.
  2329.          * </p>
  2330.          */
  2331.         private final T[] u2ij;

  2332.         /**
  2333.          * The V₂<sup>j</sup> coefficients.
  2334.          * <p>
  2335.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2336.          * they are the only ones required.
  2337.          * </p>
  2338.          */
  2339.         private final T[] v2ij;

  2340.         /**
  2341.          * The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub>
  2342.          * coefficients.
  2343.          */
  2344.         private final T[][] currentRhoSigmaj;

  2345.         /**
  2346.          * The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier
  2347.          * coefficients.
  2348.          */
  2349.         private final FieldFourierCjSjCoefficients<T> fourierCjSj;

  2350.         /** The maximum value for j index. */
  2351.         private final int jMax;

  2352.         /**
  2353.          * Constructor.
  2354.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  2355.          *                         σ<sub>j</sub> coefficients
  2356.          * @param fourierCjSj      the fourier coefficients C<sub>i</sub><sup>j</sup>
  2357.          *                         and the S<sub>i</sub><sup>j</sup>
  2358.          * @param jMax             maximum value for j index
  2359.          * @param field            field used by default
  2360.          */
  2361.         FieldUijVijCoefficients(final T[][] currentRhoSigmaj, final FieldFourierCjSjCoefficients<T> fourierCjSj,
  2362.                 final int jMax, final Field<T> field) {
  2363.             this.currentRhoSigmaj = currentRhoSigmaj;
  2364.             this.fourierCjSj = fourierCjSj;
  2365.             this.jMax = jMax;

  2366.             // initialize the internal arrays.
  2367.             this.u1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2368.             this.v1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2369.             this.u2ij = MathArrays.buildArray(field, jMax + 1);
  2370.             this.v2ij = MathArrays.buildArray(field, jMax + 1);

  2371.             // compute the coefficients
  2372.             computeU1V1Coefficients(field);
  2373.             computeU2V2Coefficients(field);
  2374.         }

  2375.         /**
  2376.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2377.          * @param field field used by default
  2378.          */
  2379.         private void computeU1V1Coefficients(final Field<T> field) {
  2380.             // Zero
  2381.             final T zero = field.getZero();

  2382.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2383.             // for j >= 1
  2384.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2385.             u1ij[0][0] = zero;
  2386.             for (int j = 1; j <= jMax; j++) {
  2387.                 // compute 1 / j
  2388.                 final double ooj = 1. / j;

  2389.                 for (int i = 0; i < 6; i++) {
  2390.                     // j is aready between 1 and J
  2391.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2392.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2393.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2394.                     if (j > 1) {
  2395.                         // k starts with 1 because j-J is less than or equal to 0
  2396.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2397.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2398.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2399.                             u1ij[i][j] = u1ij[i][j]
  2400.                                     .add(fourierCjSj.getCij(i, j - kIndex).multiply(currentRhoSigmaj[1][kIndex]).add(
  2401.                                             fourierCjSj.getSij(i, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2402.                             // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2403.                             // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2404.                             v1ij[i][j] = v1ij[i][j].add(
  2405.                                     fourierCjSj.getCij(i, j - kIndex).multiply(currentRhoSigmaj[0][kIndex]).subtract(
  2406.                                             fourierCjSj.getSij(i, j - kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2407.                         }
  2408.                     }

  2409.                     // since j must be between 1 and J-1 and is already between 1 and J
  2410.                     // the following sum is skiped only for j = jMax
  2411.                     if (j != jMax) {
  2412.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2413.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2414.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2415.                             u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, j + kIndex).negate()
  2416.                                     .multiply(currentRhoSigmaj[1][kIndex])
  2417.                                     .add(fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2418.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2419.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2420.                             v1ij[i][j] = v1ij[i][j]
  2421.                                     .add(fourierCjSj.getCij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex]).add(
  2422.                                             fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2423.                         }
  2424.                     }

  2425.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2426.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2427.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2428.                         u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, kIndex).negate()
  2429.                                 .multiply(currentRhoSigmaj[1][j + kIndex])
  2430.                                 .subtract(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2431.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2432.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2433.                         v1ij[i][j] = v1ij[i][j]
  2434.                                 .add(fourierCjSj.getCij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])
  2435.                                         .add(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2436.                     }

  2437.                     // divide by 1 / j
  2438.                     u1ij[i][j] = u1ij[i][j].multiply(-ooj);
  2439.                     v1ij[i][j] = v1ij[i][j].multiply(ooj);

  2440.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2441.                     if (i == 0) {
  2442.                         // - (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2443.                         u1ij[0][0] = u1ij[0][0].add(u1ij[0][j].negate().multiply(currentRhoSigmaj[0][j])
  2444.                                 .subtract(v1ij[0][j].multiply(currentRhoSigmaj[1][j])));
  2445.                     }
  2446.                 }
  2447.             }

  2448.             // Terms with j > jMax are required only when computing the coefficients
  2449.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2450.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2451.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2452.                 // compute 1 / j
  2453.                 final double ooj = 1. / j;
  2454.                 // the value of i is 0
  2455.                 u1ij[0][j] = zero;
  2456.                 v1ij[0][j] = zero;

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

  2463.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2464.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2465.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])
  2466.                             .subtract(fourierCjSj.getSij(0, j - kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2467.                 }
  2468.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2469.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2470.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2471.                     u1ij[0][j] = u1ij[0][j]
  2472.                             .add(fourierCjSj.getCij(0, kIndex).negate().multiply(currentRhoSigmaj[1][j + kIndex])
  2473.                                     .subtract(fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2474.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2475.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2476.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])
  2477.                             .add(fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2478.                 }

  2479.                 // divide by 1 / j
  2480.                 u1ij[0][j] = u1ij[0][j].multiply(-ooj);
  2481.                 v1ij[0][j] = v1ij[0][j].multiply(ooj);
  2482.             }
  2483.         }

  2484.         /**
  2485.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2486.          * <p>
  2487.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2488.          * </p>
  2489.          * @param field field used by default
  2490.          */
  2491.         private void computeU2V2Coefficients(final Field<T> field) {
  2492.             for (int j = 1; j <= jMax; j++) {
  2493.                 // compute 1 / j
  2494.                 final double ooj = 1. / j;

  2495.                 // only the values for i == 0 are computed
  2496.                 u2ij[j] = v1ij[0][j];
  2497.                 v2ij[j] = u1ij[0][j];

  2498.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2499.                 if (j > 1) {
  2500.                     for (int l = 1; l <= j - 1; l++) {
  2501.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2502.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2503.                         u2ij[j] = u2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[1][l])
  2504.                                 .add(v1ij[0][j - l].multiply(currentRhoSigmaj[0][l])));

  2505.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2506.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2507.                         v2ij[j] = v2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[0][l])
  2508.                                 .subtract(v1ij[0][j - l].multiply(currentRhoSigmaj[1][l])));
  2509.                     }
  2510.                 }

  2511.                 for (int l = 1; l <= jMax; l++) {
  2512.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2513.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2514.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2515.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2516.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].negate().multiply(currentRhoSigmaj[1][l])
  2517.                             .add(u1ij[0][l].multiply(currentRhoSigmaj[1][j + l]))
  2518.                             .add(v1ij[0][j + l].multiply(currentRhoSigmaj[0][l]))
  2519.                             .subtract(v1ij[0][l].multiply(currentRhoSigmaj[0][j + l])));

  2520.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2521.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2522.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2523.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2524.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].multiply(currentRhoSigmaj[0][l])
  2525.                             .add(u1ij[0][l].multiply(currentRhoSigmaj[0][j + l]))
  2526.                             .add(v1ij[0][j + l].multiply(currentRhoSigmaj[1][l]))
  2527.                             .add(v1ij[0][l].multiply(currentRhoSigmaj[1][j + l])));
  2528.                 }

  2529.                 // divide by 1 / j
  2530.                 u2ij[j] = u2ij[j].multiply(-ooj);
  2531.                 v2ij[j] = v2ij[j].multiply(ooj);
  2532.             }
  2533.         }

  2534.         /**
  2535.          * Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2536.          *
  2537.          * @param j j index
  2538.          * @param i Fourier index (starts at 0)
  2539.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2540.          */
  2541.         public T getU1(final int j, final int i) {
  2542.             return u1ij[i][j];
  2543.         }

  2544.         /**
  2545.          * Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2546.          *
  2547.          * @param j j index
  2548.          * @param i Fourier index (starts at 0)
  2549.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2550.          */
  2551.         public T getV1(final int j, final int i) {
  2552.             return v1ij[i][j];
  2553.         }

  2554.         /**
  2555.          * Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2556.          *
  2557.          * @param j j index
  2558.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2559.          */
  2560.         public T getU2(final int j) {
  2561.             return u2ij[j];
  2562.         }

  2563.         /**
  2564.          * Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2565.          *
  2566.          * @param j j index
  2567.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2568.          */
  2569.         public T getV2(final int j) {
  2570.             return v2ij[j];
  2571.         }
  2572.     }

  2573.     /** Coefficients valid for one time slot. */
  2574.     protected static class Slot {

  2575.         /**
  2576.          * The coefficients D<sub>i</sub><sup>j</sup>.
  2577.          * <p>
  2578.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2579.          * i corresponds to the equinoctial element, as follows: - i=0 for a <br/>
  2580.          * - i=1 for k <br/>
  2581.          * - i=2 for h <br/>
  2582.          * - i=3 for q <br/>
  2583.          * - i=4 for p <br/>
  2584.          * - i=5 for λ <br/>
  2585.          * </p>
  2586.          */
  2587.         private final ShortPeriodicsInterpolatedCoefficient[] dij;

  2588.         /**
  2589.          * The coefficients C<sub>i</sub><sup>j</sup>.
  2590.          * <p>
  2591.          * The index order is cij[j][i] <br/>
  2592.          * i corresponds to the equinoctial element, as follows: <br/>
  2593.          * - i=0 for a <br/>
  2594.          * - i=1 for k <br/>
  2595.          * - i=2 for h <br/>
  2596.          * - i=3 for q <br/>
  2597.          * - i=4 for p <br/>
  2598.          * - i=5 for λ <br/>
  2599.          * </p>
  2600.          */
  2601.         private final ShortPeriodicsInterpolatedCoefficient[] cij;

  2602.         /**
  2603.          * The coefficients S<sub>i</sub><sup>j</sup>.
  2604.          * <p>
  2605.          * The index order is sij[j][i] <br/>
  2606.          * i corresponds to the equinoctial element, as follows: <br/>
  2607.          * - i=0 for a <br/>
  2608.          * - i=1 for k <br/>
  2609.          * - i=2 for h <br/>
  2610.          * - i=3 for q <br/>
  2611.          * - i=4 for p <br/>
  2612.          * - i=5 for λ <br/>
  2613.          * </p>
  2614.          */
  2615.         private final ShortPeriodicsInterpolatedCoefficient[] sij;

  2616.         /**
  2617.          * Simple constructor.
  2618.          * @param jMax                maximum value for j index
  2619.          * @param interpolationPoints number of points used in the interpolation process
  2620.          */
  2621.         Slot(final int jMax, final int interpolationPoints) {

  2622.             dij = new ShortPeriodicsInterpolatedCoefficient[3];
  2623.             cij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];
  2624.             sij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];

  2625.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and
  2626.             // D<sub>i</sub><sup>j</sup> coefficients
  2627.             for (int j = 0; j <= jMax; j++) {
  2628.                 cij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2629.                 if (j > 0) {
  2630.                     sij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2631.                 }
  2632.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2633.                 if (j == 1 || j == 2) {
  2634.                     dij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2635.                 }
  2636.             }

  2637.         }

  2638.     }

  2639.     /** Coefficients valid for one time slot. */
  2640.     protected static class FieldSlot<T extends CalculusFieldElement<T>> {

  2641.         /**
  2642.          * The coefficients D<sub>i</sub><sup>j</sup>.
  2643.          * <p>
  2644.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2645.          * i corresponds to the equinoctial element, as follows: - i=0 for a <br/>
  2646.          * - i=1 for k <br/>
  2647.          * - i=2 for h <br/>
  2648.          * - i=3 for q <br/>
  2649.          * - i=4 for p <br/>
  2650.          * - i=5 for λ <br/>
  2651.          * </p>
  2652.          */
  2653.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] dij;

  2654.         /**
  2655.          * The coefficients C<sub>i</sub><sup>j</sup>.
  2656.          * <p>
  2657.          * The index order is cij[j][i] <br/>
  2658.          * i corresponds to the equinoctial element, as follows: <br/>
  2659.          * - i=0 for a <br/>
  2660.          * - i=1 for k <br/>
  2661.          * - i=2 for h <br/>
  2662.          * - i=3 for q <br/>
  2663.          * - i=4 for p <br/>
  2664.          * - i=5 for λ <br/>
  2665.          * </p>
  2666.          */
  2667.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] cij;

  2668.         /**
  2669.          * The coefficients S<sub>i</sub><sup>j</sup>.
  2670.          * <p>
  2671.          * The index order is sij[j][i] <br/>
  2672.          * i corresponds to the equinoctial element, as follows: <br/>
  2673.          * - i=0 for a <br/>
  2674.          * - i=1 for k <br/>
  2675.          * - i=2 for h <br/>
  2676.          * - i=3 for q <br/>
  2677.          * - i=4 for p <br/>
  2678.          * - i=5 for λ <br/>
  2679.          * </p>
  2680.          */
  2681.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] sij;

  2682.         /**
  2683.          * Simple constructor.
  2684.          * @param jMax                maximum value for j index
  2685.          * @param interpolationPoints number of points used in the interpolation process
  2686.          */
  2687.         @SuppressWarnings("unchecked")
  2688.         FieldSlot(final int jMax, final int interpolationPoints) {

  2689.             dij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2690.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, 3);
  2691.             cij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2692.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);
  2693.             sij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2694.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);

  2695.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and
  2696.             // D<sub>i</sub><sup>j</sup> coefficients
  2697.             for (int j = 0; j <= jMax; j++) {
  2698.                 cij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2699.                 if (j > 0) {
  2700.                     sij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2701.                 }
  2702.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2703.                 if (j == 1 || j == 2) {
  2704.                     dij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2705.                 }
  2706.             }

  2707.         }

  2708.     }

  2709. }