AbstractGaussianContribution.java

  1. /* Copyright 2002-2024 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.semianalytical.dsst.forces;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.analysis.CalculusFieldUnivariateVectorFunction;
  21. import org.hipparchus.analysis.UnivariateVectorFunction;
  22. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Rotation;
  25. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  26. import org.hipparchus.util.FastMath;
  27. import org.hipparchus.util.FieldSinCos;
  28. import org.hipparchus.util.MathArrays;
  29. import org.hipparchus.util.SinCos;
  30. import org.orekit.attitudes.Attitude;
  31. import org.orekit.attitudes.AttitudeProvider;
  32. import org.orekit.attitudes.FieldAttitude;
  33. import org.orekit.forces.ForceModel;
  34. import org.orekit.orbits.EquinoctialOrbit;
  35. import org.orekit.orbits.FieldEquinoctialOrbit;
  36. import org.orekit.orbits.FieldOrbit;
  37. import org.orekit.orbits.Orbit;
  38. import org.orekit.orbits.OrbitType;
  39. import org.orekit.orbits.PositionAngleType;
  40. import org.orekit.propagation.FieldSpacecraftState;
  41. import org.orekit.propagation.PropagationType;
  42. import org.orekit.propagation.SpacecraftState;
  43. import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
  44. import org.orekit.propagation.semianalytical.dsst.utilities.CjSjCoefficient;
  45. import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
  46. import org.orekit.propagation.semianalytical.dsst.utilities.FieldCjSjCoefficient;
  47. import org.orekit.propagation.semianalytical.dsst.utilities.FieldShortPeriodicsInterpolatedCoefficient;
  48. import org.orekit.propagation.semianalytical.dsst.utilities.ShortPeriodicsInterpolatedCoefficient;
  49. import org.orekit.time.AbsoluteDate;
  50. import org.orekit.time.FieldAbsoluteDate;
  51. import org.orekit.utils.FieldTimeSpanMap;
  52. import org.orekit.utils.ParameterDriver;
  53. import org.orekit.utils.TimeSpanMap;

  54. import java.lang.reflect.Array;
  55. import java.util.ArrayList;
  56. import java.util.Collections;
  57. import java.util.HashMap;
  58. import java.util.List;
  59. import java.util.Map;
  60. import java.util.Set;

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

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

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

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

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

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

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

  129.     /** Contribution to be numerically averaged. */
  130.     private final ForceModel contribution;

  131.     /** Gauss integrator. */
  132.     private final double threshold;

  133.     /** Gauss integrator. */
  134.     private GaussQuadrature integrator;

  135.     /** Flag for Gauss order computation. */
  136.     private boolean isDirty;

  137.     /** Attitude provider. */
  138.     private AttitudeProvider attitudeProvider;

  139.     /** Prefix for coefficients keys. */
  140.     private final String coefficientsKeyPrefix;

  141.     /** Short period terms. */
  142.     private GaussianShortPeriodicCoefficients gaussianSPCoefs;

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

  145.     /** Driver for gravitational parameter. */
  146.     private final ParameterDriver gmParameterDriver;

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

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

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

  165.         gaussianFieldSPCoefs = new HashMap<>();
  166.     }

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

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

  179.     /** {@inheritDoc} */
  180.     @Override
  181.     public List<ParameterDriver> getParametersDrivers() {
  182.         // Initialize drivers (without central attraction coefficient driver)
  183.         final List<ParameterDriver> drivers = new ArrayList<>(getParametersDriversWithoutMu());
  184.         // We put central attraction coefficient driver at the end of the array
  185.         drivers.add(gmParameterDriver);
  186.         return drivers;
  187.     }

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

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

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

  208.     }

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

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

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

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

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

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

  254.         // Container for attributes

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

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

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

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

  303.         return meanElementRate;
  304.     }

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

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

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

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

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

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

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

  365.         // Field
  366.         final Field<T> field = context.getA().getField();

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

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

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

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

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

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

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

  413.         T maxDiff = FastMath.abs(meanRef[0].subtract(meanCur[0])).divide(auxiliaryElements.getSma());

  414.         // Corrects mean element rates
  415.         for (int i = 1; i < meanRef.length; i++) {
  416.             maxDiff = FastMath.max(maxDiff, FastMath.abs(meanRef[i].subtract(meanCur[i])));
  417.         }
  418.         return maxDiff;
  419.     }

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

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

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

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

  432.             // Container of attributes
  433.             // Extract the proper parameters valid for the corresponding meanState date from the input array
  434.             final double[] extractedParameters = this.extractParameters(parameters, auxiliaryElements.getDate());
  435.             final AbstractGaussianContributionContext context = initializeStep(auxiliaryElements, extractedParameters);

  436.             // Compute rhoj and sigmaj
  437.             final double[][] currentRhoSigmaj = computeRhoSigmaCoefficients(auxiliaryElements);

  438.             // Generate the Cij and Sij coefficients
  439.             final FourierCjSjCoefficients fourierCjSj = new FourierCjSjCoefficients(meanState, JMAX, auxiliaryElements,
  440.                                                                                     extractedParameters);

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

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

  445.         }

  446.     }

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

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

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

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

  460.             // Container of attributes
  461.             // Extract the proper parameters valid for the corresponding meanState date from the input array
  462.             final T[] extractedParameters = this.extractParameters(parameters, auxiliaryElements.getDate());
  463.             final FieldAbstractGaussianContributionContext<T> context = initializeStep(auxiliaryElements, extractedParameters);

  464.             // Compute rhoj and sigmaj
  465.             final T[][] currentRhoSigmaj = computeRhoSigmaCoefficients(context, field);

  466.             // Generate the Cij and Sij coefficients
  467.             final FieldFourierCjSjCoefficients<T> fourierCjSj = new FieldFourierCjSjCoefficients<>(meanState, JMAX,
  468.                     auxiliaryElements, extractedParameters, field);

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

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

  474.         }

  475.     }

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

  490.         // (-b)<sup>j</sup>
  491.         double mbtj = 1;

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

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

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

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

  521.         // (-b)<sup>j</sup>
  522.         T mbtj = zero.newInstance(1.);

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

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

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

  541.         /** Current state. */
  542.         private final FieldSpacecraftState<T> state;

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

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

  555.         /** Container for attributes. */
  556.         private final FieldAbstractGaussianContributionContext<T> context;

  557.         /** Auxiliary Elements. */
  558.         private final FieldAuxiliaryElements<T> auxiliaryElements;

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

  561.         /**
  562.          * Build a new instance with a new field.
  563.          * @param state      current state information: date, kinematics, attitude
  564.          * @param meanMode   if true return the value associated to the mean elements
  565.          *                   variation, if false return the values associated to the
  566.          *                   short periodic elements variation
  567.          * @param j          the j index. used only for short periodic variation.
  568.          *                   Ignored for mean elements variation.
  569.          * @param parameters values of the force model parameters (only 1 values
  570.          *                   for each parameters corresponding to state date) obtained by
  571.          *                   calling the extract parameter method {@link #extractParameters(double[], AbsoluteDate)}
  572.          *                   to selected the right value for state date or by getting the parameters for a specific date
  573.          * @param field      field utilized by default
  574.          */
  575.         public FieldIntegrableFunction(final FieldSpacecraftState<T> state, final boolean meanMode, final int j,
  576.                 final T[] parameters, final Field<T> field) {

  577.             this.meanMode = meanMode;
  578.             this.j = j;
  579.             this.parameters = parameters.clone();
  580.             this.auxiliaryElements = new FieldAuxiliaryElements<>(state.getOrbit(), I);
  581.             this.context = new FieldAbstractGaussianContributionContext<>(auxiliaryElements, this.parameters);
  582.             // remove derivatives from state
  583.             final T[] stateVector = MathArrays.buildArray(field, 6);
  584.             final PositionAngleType positionAngleType = PositionAngleType.MEAN;
  585.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), positionAngleType, stateVector, null);
  586.             final FieldOrbit<T> fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null,
  587.                     positionAngleType, state.getDate(), context.getMu(), state.getFrame());
  588.             this.state = new FieldSpacecraftState<>(fixedOrbit, state.getAttitude(), state.getMass());
  589.         }

  590.         /** {@inheritDoc} */
  591.         @Override
  592.         public T[] value(final T x) {

  593.             // Parameters for array building
  594.             final Field<T> field = auxiliaryElements.getDate().getField();
  595.             final int dimension = 6;

  596.             // Compute the time difference from the true longitude difference
  597.             final T shiftedLm = trueToMean(x);
  598.             final T dLm = shiftedLm.subtract(auxiliaryElements.getLM());
  599.             final T dt = dLm.divide(context.getMeanMotion());

  600.             final FieldSinCos<T> scL = FastMath.sinCos(x);
  601.             final T cosL = scL.cos();
  602.             final T sinL = scL.sin();
  603.             final T roa  = auxiliaryElements.getB().multiply(auxiliaryElements.getB()).divide(auxiliaryElements.getH().multiply(sinL).add(auxiliaryElements.getK().multiply(cosL)).add(1.));
  604.             final T roa2 = roa.multiply(roa);
  605.             final T r = auxiliaryElements.getSma().multiply(roa);
  606.             final T X = r.multiply(cosL);
  607.             final T Y = r.multiply(sinL);
  608.             final T naob = context.getMeanMotion().multiply(auxiliaryElements.getSma())
  609.                     .divide(auxiliaryElements.getB());
  610.             final T Xdot = naob.multiply(auxiliaryElements.getH().add(sinL)).negate();
  611.             final T Ydot = naob.multiply(auxiliaryElements.getK().add(cosL));
  612.             final FieldVector3D<T> vel = new FieldVector3D<>(Xdot, auxiliaryElements.getVectorF(), Ydot,
  613.                     auxiliaryElements.getVectorG());

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

  616.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  617.             final FieldOrbit<T> recomposedOrbit = new FieldEquinoctialOrbit<>(shiftedOrbit.getA(),
  618.                     shiftedOrbit.getEquinoctialEx(), shiftedOrbit.getEquinoctialEy(), shiftedOrbit.getHx(),
  619.                     shiftedOrbit.getHy(), shiftedOrbit.getLM(), PositionAngleType.MEAN, shiftedOrbit.getFrame(),
  620.                     state.getDate(), context.getMu());

  621.             // Get the corresponding attitude
  622.             final FieldAttitude<T> recomposedAttitude;
  623.             if (contribution.dependsOnAttitudeRate()) {
  624.                 recomposedAttitude = attitudeProvider.getAttitude(recomposedOrbit,
  625.                         recomposedOrbit.getDate(), recomposedOrbit.getFrame());
  626.             } else {
  627.                 final FieldRotation<T> rotation = attitudeProvider.getAttitudeRotation(recomposedOrbit,
  628.                         recomposedOrbit.getDate(), recomposedOrbit.getFrame());
  629.                 final FieldVector3D<T> zeroVector = FieldVector3D.getZero(recomposedOrbit.getA().getField());
  630.                 recomposedAttitude = new FieldAttitude<>(recomposedOrbit.getDate(), recomposedOrbit.getFrame(),
  631.                         rotation, zeroVector, zeroVector);
  632.             }

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

  636.             final FieldVector3D<T> acc = contribution.acceleration(shiftedState, parameters);

  637.             // Compute the derivatives of the elements by the speed
  638.             final T[] deriv = MathArrays.buildArray(field, dimension);
  639.             // da/dv
  640.             deriv[0] = getAoV(vel).dotProduct(acc);
  641.             // dex/dv
  642.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  643.             // dey/dv
  644.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  645.             // dhx/dv
  646.             deriv[3] = getQoV(X).dotProduct(acc);
  647.             // dhy/dv
  648.             deriv[4] = getPoV(Y).dotProduct(acc);
  649.             // dλ/dv
  650.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  651.             // Compute mean elements rates
  652.             final T[] val;
  653.             if (meanMode) {
  654.                 val = MathArrays.buildArray(field, dimension);
  655.                 for (int i = 0; i < 6; i++) {
  656.                     // da<sub>i</sub>/dt
  657.                     val[i] = deriv[i].multiply(roa2);
  658.                 }
  659.             } else {
  660.                 val = MathArrays.buildArray(field, dimension * 2);
  661.                 //Compute cos(j*L) and sin(j*L);
  662.                 final FieldSinCos<T> scjL = FastMath.sinCos(x.multiply(j));
  663.                 final T cosjL = j == 1 ? cosL : scjL.cos();
  664.                 final T sinjL = j == 1 ? sinL : scjL.sin();

  665.                 for (int i = 0; i < 6; i++) {
  666.                     // da<sub>i</sub>/dv * cos(jL)
  667.                     val[i] = deriv[i].multiply(cosjL);
  668.                     // da<sub>i</sub>/dv * sin(jL)
  669.                     val[i + 6] = deriv[i].multiply(sinjL);
  670.                 }
  671.             }

  672.             return val;
  673.         }

  674.         /**
  675.          * Converts true longitude to mean longitude.
  676.          * @param x True longitude
  677.          * @return Eccentric longitude
  678.          */
  679.         private T trueToMean(final T x) {
  680.             return eccentricToMean(trueToEccentric(x));
  681.         }

  682.         /**
  683.          * Converts true longitude to eccentric longitude.
  684.          * @param lv True longitude
  685.          * @return Eccentric longitude
  686.          */
  687.         private T trueToEccentric (final T lv) {
  688.             final FieldSinCos<T> sclV = FastMath.sinCos(lv);
  689.             final T cosLv   = sclV.cos();
  690.             final T sinLv   = sclV.sin();
  691.             final T num     = auxiliaryElements.getH().multiply(cosLv).subtract(auxiliaryElements.getK().multiply(sinLv));
  692.             final T den     = auxiliaryElements.getB().add(auxiliaryElements.getK().multiply(cosLv)).add(auxiliaryElements.getH().multiply(sinLv)).add(1.);
  693.             return FastMath.atan(num.divide(den)).multiply(2.).add(lv);
  694.         }

  695.         /**
  696.          * Converts eccentric longitude to mean longitude.
  697.          * @param le Eccentric longitude
  698.          * @return Mean longitude
  699.          */
  700.         private T eccentricToMean (final T le) {
  701.             final FieldSinCos<T> scle = FastMath.sinCos(le);
  702.             return le.subtract(auxiliaryElements.getK().multiply(scle.sin())).add(auxiliaryElements.getH().multiply(scle.cos()));
  703.         }

  704.         /**
  705.          * Compute δa/δv.
  706.          * @param vel satellite velocity
  707.          * @return δa/δv
  708.          */
  709.         private FieldVector3D<T> getAoV(final FieldVector3D<T> vel) {
  710.             return new FieldVector3D<>(context.getTon2a(), vel);
  711.         }

  712.         /**
  713.          * Compute δh/δv.
  714.          * @param X    satellite position component along f, equinoctial reference frame
  715.          *             1st vector
  716.          * @param Y    satellite position component along g, equinoctial reference frame
  717.          *             2nd vector
  718.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  719.          *             1st vector
  720.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  721.          *             2nd vector
  722.          * @return δh/δv
  723.          */
  724.         private FieldVector3D<T> getHoV(final T X, final T Y, final T Xdot, final T Ydot) {
  725.             final T kf = (Xdot.multiply(Y).multiply(2.).subtract(X.multiply(Ydot))).multiply(context.getOoMU());
  726.             final T kg = X.multiply(Xdot).multiply(context.getOoMU());
  727.             final T kw = auxiliaryElements.getK().multiply(
  728.                     auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X)))
  729.                     .multiply(context.getOOAB());
  730.             return new FieldVector3D<>(kf, auxiliaryElements.getVectorF(), kg.negate(), auxiliaryElements.getVectorG(),
  731.                     kw, auxiliaryElements.getVectorW());
  732.         }

  733.         /**
  734.          * Compute δk/δv.
  735.          * @param X    satellite position component along f, equinoctial reference frame
  736.          *             1st vector
  737.          * @param Y    satellite position component along g, equinoctial reference frame
  738.          *             2nd vector
  739.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  740.          *             1st vector
  741.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  742.          *             2nd vector
  743.          * @return δk/δv
  744.          */
  745.         private FieldVector3D<T> getKoV(final T X, final T Y, final T Xdot, final T Ydot) {
  746.             final T kf = Y.multiply(Ydot).multiply(context.getOoMU());
  747.             final T kg = (X.multiply(Ydot).multiply(2.).subtract(Xdot.multiply(Y))).multiply(context.getOoMU());
  748.             final T kw = auxiliaryElements.getH().multiply(
  749.                     auxiliaryElements.getQ().multiply(Y).multiply(I).subtract(auxiliaryElements.getP().multiply(X)))
  750.                     .multiply(context.getOOAB());
  751.             return new FieldVector3D<>(kf.negate(), auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(),
  752.                     kw.negate(), auxiliaryElements.getVectorW());
  753.         }

  754.         /**
  755.          * Compute δp/δv.
  756.          * @param Y satellite position component along g, equinoctial reference frame
  757.          *          2nd vector
  758.          * @return δp/δv
  759.          */
  760.         private FieldVector3D<T> getPoV(final T Y) {
  761.             return new FieldVector3D<>(context.getCo2AB().multiply(Y), auxiliaryElements.getVectorW());
  762.         }

  763.         /**
  764.          * Compute δq/δv.
  765.          * @param X satellite position component along f, equinoctial reference frame
  766.          *          1st vector
  767.          * @return δq/δv
  768.          */
  769.         private FieldVector3D<T> getQoV(final T X) {
  770.             return new FieldVector3D<>(context.getCo2AB().multiply(X).multiply(I), auxiliaryElements.getVectorW());
  771.         }

  772.         /**
  773.          * Compute δλ/δv.
  774.          * @param X    satellite position component along f, equinoctial reference frame
  775.          *             1st vector
  776.          * @param Y    satellite position component along g, equinoctial reference frame
  777.          *             2nd vector
  778.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  779.          *             1st vector
  780.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  781.          *             2nd vector
  782.          * @return δλ/δv
  783.          */
  784.         private FieldVector3D<T> getLoV(final T X, final T Y, final T Xdot, final T Ydot) {
  785.             final FieldVector3D<T> pos = new FieldVector3D<>(X, auxiliaryElements.getVectorF(), Y,
  786.                     auxiliaryElements.getVectorG());
  787.             final FieldVector3D<T> v2 = new FieldVector3D<>(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot),
  788.                     auxiliaryElements.getH().negate(), getKoV(X, Y, Xdot, Ydot));
  789.             return new FieldVector3D<>(context.getOOA().multiply(-2.), pos, context.getOoBpo(), v2,
  790.                     context.getOOA().multiply(auxiliaryElements.getQ().multiply(Y).multiply(I)
  791.                             .subtract(auxiliaryElements.getP().multiply(X))),
  792.                     auxiliaryElements.getVectorW());
  793.         }

  794.     }

  795.     /** Internal class for numerical quadrature. */
  796.     protected class IntegrableFunction implements UnivariateVectorFunction {

  797.         /** Current state. */
  798.         private final SpacecraftState state;

  799.         /**
  800.          * Signal that this class is used to compute the values required by the mean
  801.          * element variations or by the short periodic element variations.
  802.          */
  803.         private final boolean meanMode;

  804.         /**
  805.          * The j index.
  806.          * <p>
  807.          * Used only for short periodic variation. Ignored for mean elements variation.
  808.          * </p>
  809.          */
  810.         private final int j;

  811.         /** Container for attributes. */
  812.         private final AbstractGaussianContributionContext context;

  813.         /** Auxiliary Elements. */
  814.         private final AuxiliaryElements auxiliaryElements;

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

  817.         /**
  818.          * Build a new instance.
  819.          * @param state      current state information: date, kinematics, attitude
  820.          * @param meanMode   if true return the value associated to the mean elements
  821.          *                   variation, if false return the values associated to the
  822.          *                   short periodic elements variation
  823.          * @param j          the j index. used only for short periodic variation.
  824.          *                   Ignored for mean elements variation.
  825.          * @param parameters list of the estimated values for each driver at state date of the force model parameters
  826.          *                   only 1 value for each parameter
  827.          */
  828.         IntegrableFunction(final SpacecraftState state, final boolean meanMode, final int j,
  829.                 final double[] parameters) {

  830.             this.meanMode = meanMode;
  831.             this.j = j;
  832.             this.parameters = parameters.clone();
  833.             this.auxiliaryElements = new AuxiliaryElements(state.getOrbit(), I);
  834.             this.context = new AbstractGaussianContributionContext(auxiliaryElements, this.parameters);
  835.             // remove derivatives from state
  836.             final double[] stateVector = new double[6];
  837.             final PositionAngleType positionAngleType = PositionAngleType.MEAN;
  838.             OrbitType.EQUINOCTIAL.mapOrbitToArray(state.getOrbit(), positionAngleType, stateVector, null);
  839.             final Orbit fixedOrbit = OrbitType.EQUINOCTIAL.mapArrayToOrbit(stateVector, null, positionAngleType,
  840.                     state.getDate(), context.getMu(), state.getFrame());
  841.             this.state = new SpacecraftState(fixedOrbit, state.getAttitude(), state.getMass());
  842.         }

  843.         /** {@inheritDoc} */
  844.         @SuppressWarnings("checkstyle:FinalLocalVariable")
  845.         @Override
  846.         public double[] value(final double x) {

  847.             // Compute the time difference from the true longitude difference
  848.             final double shiftedLm = trueToMean(x);
  849.             final double dLm = shiftedLm - auxiliaryElements.getLM();
  850.             final double dt = dLm / context.getMeanMotion();

  851.             final SinCos scL  = FastMath.sinCos(x);
  852.             final double cosL = scL.cos();
  853.             final double sinL = scL.sin();
  854.             final double roa  = auxiliaryElements.getB() * auxiliaryElements.getB() / (1. + auxiliaryElements.getH() * sinL + auxiliaryElements.getK() * cosL);
  855.             final double roa2 = roa * roa;
  856.             final double r = auxiliaryElements.getSma() * roa;
  857.             final double X = r * cosL;
  858.             final double Y = r * sinL;
  859.             final double naob = context.getMeanMotion() * auxiliaryElements.getSma() / auxiliaryElements.getB();
  860.             final double Xdot = -naob * (auxiliaryElements.getH() + sinL);
  861.             final double Ydot = naob * (auxiliaryElements.getK() + cosL);
  862.             final Vector3D vel = new Vector3D(Xdot, auxiliaryElements.getVectorF(), Ydot,
  863.                     auxiliaryElements.getVectorG());

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

  866.             // Recompose an orbit with time held fixed to be compliant with DSST theory
  867.             final Orbit recomposedOrbit = new EquinoctialOrbit(shiftedOrbit.getA(), shiftedOrbit.getEquinoctialEx(),
  868.                     shiftedOrbit.getEquinoctialEy(), shiftedOrbit.getHx(), shiftedOrbit.getHy(), shiftedOrbit.getLM(),
  869.                     PositionAngleType.MEAN, shiftedOrbit.getFrame(), state.getDate(), context.getMu());

  870.             // Get the corresponding attitude
  871.             final Attitude recomposedAttitude;
  872.             if (contribution.dependsOnAttitudeRate()) {
  873.                 recomposedAttitude = attitudeProvider.getAttitude(recomposedOrbit,
  874.                         recomposedOrbit.getDate(), recomposedOrbit.getFrame());
  875.             } else {
  876.                 final Rotation rotation = attitudeProvider.getAttitudeRotation(recomposedOrbit,
  877.                         recomposedOrbit.getDate(), recomposedOrbit.getFrame());
  878.                 final Vector3D zeroVector = Vector3D.ZERO;
  879.                 recomposedAttitude = new Attitude(recomposedOrbit.getDate(), recomposedOrbit.getFrame(),
  880.                         rotation, zeroVector, zeroVector);
  881.             }

  882.             // create shifted SpacecraftState with attitude at specified time
  883.             final SpacecraftState shiftedState = new SpacecraftState(recomposedOrbit, recomposedAttitude,
  884.                     state.getMass());

  885.             // here parameters is a list of all span values of each parameter driver
  886.             final Vector3D acc = contribution.acceleration(shiftedState, parameters);

  887.             // Compute the derivatives of the elements by the speed
  888.             final double[] deriv = new double[6];
  889.             // da/dv
  890.             deriv[0] = getAoV(vel).dotProduct(acc);
  891.             // dex/dv
  892.             deriv[1] = getKoV(X, Y, Xdot, Ydot).dotProduct(acc);
  893.             // dey/dv
  894.             deriv[2] = getHoV(X, Y, Xdot, Ydot).dotProduct(acc);
  895.             // dhx/dv
  896.             deriv[3] = getQoV(X).dotProduct(acc);
  897.             // dhy/dv
  898.             deriv[4] = getPoV(Y).dotProduct(acc);
  899.             // dλ/dv
  900.             deriv[5] = getLoV(X, Y, Xdot, Ydot).dotProduct(acc);

  901.             // Compute mean elements rates
  902.             final double[] val;
  903.             if (meanMode) {
  904.                 val = new double[6];
  905.                 for (int i = 0; i < 6; i++) {
  906.                     // da<sub>i</sub>/dt
  907.                     val[i] = roa2 * deriv[i];
  908.                 }
  909.             } else {
  910.                 val = new double[12];
  911.                 //Compute cos(j*L) and sin(j*L);
  912.                 final SinCos scjL  = FastMath.sinCos(j * x);
  913.                 final double cosjL = j == 1 ? cosL : scjL.cos();
  914.                 final double sinjL = j == 1 ? sinL : scjL.sin();

  915.                 for (int i = 0; i < 6; i++) {
  916.                     // da<sub>i</sub>/dv * cos(jL)
  917.                     val[i] = cosjL * deriv[i];
  918.                     // da<sub>i</sub>/dv * sin(jL)
  919.                     val[i + 6] = sinjL * deriv[i];
  920.                 }
  921.             }
  922.             return val;
  923.         }

  924.         /**
  925.          * Converts true longitude to eccentric longitude.
  926.          * @param lv True longitude
  927.          * @return Eccentric longitude
  928.          */
  929.         private double trueToEccentric (final double lv) {
  930.             final SinCos scLv    = FastMath.sinCos(lv);
  931.             final double num     = auxiliaryElements.getH() * scLv.cos() - auxiliaryElements.getK() * scLv.sin();
  932.             final double den     = auxiliaryElements.getB() + 1. + auxiliaryElements.getK() * scLv.cos() + auxiliaryElements.getH() * scLv.sin();
  933.             return lv + 2. * FastMath.atan(num / den);
  934.         }

  935.         /**
  936.          * Converts eccentric longitude to mean longitude.
  937.          * @param le Eccentric longitude
  938.          * @return Mean longitude
  939.          */
  940.         private double eccentricToMean (final double le) {
  941.             final SinCos scLe = FastMath.sinCos(le);
  942.             return le - auxiliaryElements.getK() * scLe.sin() + auxiliaryElements.getH() * scLe.cos();
  943.         }

  944.         /**
  945.          * Converts true longitude to mean longitude.
  946.          * @param lv True longitude
  947.          * @return Eccentric longitude
  948.          */
  949.         private double trueToMean(final double lv) {
  950.             return eccentricToMean(trueToEccentric(lv));
  951.         }

  952.         /**
  953.          * Compute δa/δv.
  954.          * @param vel satellite velocity
  955.          * @return δa/δv
  956.          */
  957.         private Vector3D getAoV(final Vector3D vel) {
  958.             return new Vector3D(context.getTon2a(), vel);
  959.         }

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

  980.         /**
  981.          * Compute δk/δv.
  982.          * @param X    satellite position component along f, equinoctial reference frame
  983.          *             1st vector
  984.          * @param Y    satellite position component along g, equinoctial reference frame
  985.          *             2nd vector
  986.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  987.          *             1st vector
  988.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  989.          *             2nd vector
  990.          * @return δk/δv
  991.          */
  992.         private Vector3D getKoV(final double X, final double Y, final double Xdot, final double Ydot) {
  993.             final double kf = Y * Ydot * context.getOoMU();
  994.             final double kg = (2. * X * Ydot - Xdot * Y) * context.getOoMU();
  995.             final double kw = auxiliaryElements.getH() *
  996.                     (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOAB();
  997.             return new Vector3D(-kf, auxiliaryElements.getVectorF(), kg, auxiliaryElements.getVectorG(), -kw,
  998.                     auxiliaryElements.getVectorW());
  999.         }

  1000.         /**
  1001.          * Compute δp/δv.
  1002.          * @param Y satellite position component along g, equinoctial reference frame
  1003.          *          2nd vector
  1004.          * @return δp/δv
  1005.          */
  1006.         private Vector3D getPoV(final double Y) {
  1007.             return new Vector3D(context.getCo2AB() * Y, auxiliaryElements.getVectorW());
  1008.         }

  1009.         /**
  1010.          * Compute δq/δv.
  1011.          * @param X satellite position component along f, equinoctial reference frame
  1012.          *          1st vector
  1013.          * @return δq/δv
  1014.          */
  1015.         private Vector3D getQoV(final double X) {
  1016.             return new Vector3D(I * context.getCo2AB() * X, auxiliaryElements.getVectorW());
  1017.         }

  1018.         /**
  1019.          * Compute δλ/δv.
  1020.          * @param X    satellite position component along f, equinoctial reference frame
  1021.          *             1st vector
  1022.          * @param Y    satellite position component along g, equinoctial reference frame
  1023.          *             2nd vector
  1024.          * @param Xdot satellite velocity component along f, equinoctial reference frame
  1025.          *             1st vector
  1026.          * @param Ydot satellite velocity component along g, equinoctial reference frame
  1027.          *             2nd vector
  1028.          * @return δλ/δv
  1029.          */
  1030.         private Vector3D getLoV(final double X, final double Y, final double Xdot, final double Ydot) {
  1031.             final Vector3D pos = new Vector3D(X, auxiliaryElements.getVectorF(), Y, auxiliaryElements.getVectorG());
  1032.             final Vector3D v2 = new Vector3D(auxiliaryElements.getK(), getHoV(X, Y, Xdot, Ydot),
  1033.                     -auxiliaryElements.getH(), getKoV(X, Y, Xdot, Ydot));
  1034.             return new Vector3D(-2. * context.getOOA(), pos, context.getOoBpo(), v2,
  1035.                     (I * auxiliaryElements.getQ() * Y - auxiliaryElements.getP() * X) * context.getOOA(),
  1036.                     auxiliaryElements.getVectorW());
  1037.         }

  1038.     }

  1039.     /**
  1040.      * Class used to {@link #integrate(UnivariateVectorFunction, double, double)
  1041.      * integrate} a {@link org.hipparchus.analysis.UnivariateVectorFunction
  1042.      * function} of the orbital elements using the Gaussian quadrature rule to get
  1043.      * the acceleration.
  1044.      */
  1045.     protected static class GaussQuadrature {

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

  1047.         /** Points for quadrature of order 12. */
  1048.         private static final double[] P_12 = { -0.98156063424671910000, -0.90411725637047490000,
  1049.             -0.76990267419430470000, -0.58731795428661740000, -0.36783149899818024000, -0.12523340851146890000,
  1050.             0.12523340851146890000, 0.36783149899818024000, 0.58731795428661740000, 0.76990267419430470000,
  1051.             0.90411725637047490000, 0.98156063424671910000 };

  1052.         /** Weights for quadrature of order 12. */
  1053.         private static final double[] W_12 = { 0.04717533638651220000, 0.10693932599531830000, 0.16007832854334633000,
  1054.             0.20316742672306584000, 0.23349253653835478000, 0.24914704581340286000, 0.24914704581340286000,
  1055.             0.23349253653835478000, 0.20316742672306584000, 0.16007832854334633000, 0.10693932599531830000,
  1056.             0.04717533638651220000 };

  1057.         /** Points for quadrature of order 16. */
  1058.         private static final double[] P_16 = { -0.98940093499164990000, -0.94457502307323260000,
  1059.             -0.86563120238783160000, -0.75540440835500310000, -0.61787624440264380000, -0.45801677765722737000,
  1060.             -0.28160355077925890000, -0.09501250983763745000, 0.09501250983763745000, 0.28160355077925890000,
  1061.             0.45801677765722737000, 0.61787624440264380000, 0.75540440835500310000, 0.86563120238783160000,
  1062.             0.94457502307323260000, 0.98940093499164990000 };

  1063.         /** Weights for quadrature of order 16. */
  1064.         private static final double[] W_16 = { 0.02715245941175405800, 0.06225352393864777000, 0.09515851168249283000,
  1065.             0.12462897125553388000, 0.14959598881657685000, 0.16915651939500256000, 0.18260341504492360000,
  1066.             0.18945061045506847000, 0.18945061045506847000, 0.18260341504492360000, 0.16915651939500256000,
  1067.             0.14959598881657685000, 0.12462897125553388000, 0.09515851168249283000, 0.06225352393864777000,
  1068.             0.02715245941175405800 };

  1069.         /** Points for quadrature of order 20. */
  1070.         private static final double[] P_20 = { -0.99312859918509490000, -0.96397192727791390000,
  1071.             -0.91223442825132600000, -0.83911697182221890000, -0.74633190646015080000, -0.63605368072651510000,
  1072.             -0.51086700195082700000, -0.37370608871541955000, -0.22778585114164507000, -0.07652652113349734000,
  1073.             0.07652652113349734000, 0.22778585114164507000, 0.37370608871541955000, 0.51086700195082700000,
  1074.             0.63605368072651510000, 0.74633190646015080000, 0.83911697182221890000, 0.91223442825132600000,
  1075.             0.96397192727791390000, 0.99312859918509490000 };

  1076.         /** Weights for quadrature of order 20. */
  1077.         private static final double[] W_20 = { 0.01761400713915226400, 0.04060142980038684000, 0.06267204833410904000,
  1078.             0.08327674157670477000, 0.10193011981724048000, 0.11819453196151844000, 0.13168863844917678000,
  1079.             0.14209610931838212000, 0.14917298647260380000, 0.15275338713072600000, 0.15275338713072600000,
  1080.             0.14917298647260380000, 0.14209610931838212000, 0.13168863844917678000, 0.11819453196151844000,
  1081.             0.10193011981724048000, 0.08327674157670477000, 0.06267204833410904000, 0.04060142980038684000,
  1082.             0.01761400713915226400 };

  1083.         /** Points for quadrature of order 24. */
  1084.         private static final double[] P_24 = { -0.99518721999702130000, -0.97472855597130950000,
  1085.             -0.93827455200273270000, -0.88641552700440100000, -0.82000198597390300000, -0.74012419157855440000,
  1086.             -0.64809365193697550000, -0.54542147138883950000, -0.43379350762604520000, -0.31504267969616340000,
  1087.             -0.19111886747361634000, -0.06405689286260563000, 0.06405689286260563000, 0.19111886747361634000,
  1088.             0.31504267969616340000, 0.43379350762604520000, 0.54542147138883950000, 0.64809365193697550000,
  1089.             0.74012419157855440000, 0.82000198597390300000, 0.88641552700440100000, 0.93827455200273270000,
  1090.             0.97472855597130950000, 0.99518721999702130000 };

  1091.         /** Weights for quadrature of order 24. */
  1092.         private static final double[] W_24 = { 0.01234122979998733500, 0.02853138862893380600, 0.04427743881741981000,
  1093.             0.05929858491543691500, 0.07334648141108027000, 0.08619016153195320000, 0.09761865210411391000,
  1094.             0.10744427011596558000, 0.11550566805372553000, 0.12167047292780335000, 0.12583745634682825000,
  1095.             0.12793819534675221000, 0.12793819534675221000, 0.12583745634682825000, 0.12167047292780335000,
  1096.             0.11550566805372553000, 0.10744427011596558000, 0.09761865210411391000, 0.08619016153195320000,
  1097.             0.07334648141108027000, 0.05929858491543691500, 0.04427743881741981000, 0.02853138862893380600,
  1098.             0.01234122979998733500 };

  1099.         /** Points for quadrature of order 32. */
  1100.         private static final double[] P_32 = { -0.99726386184948160000, -0.98561151154526840000,
  1101.             -0.96476225558750640000, -0.93490607593773970000, -0.89632115576605220000, -0.84936761373256990000,
  1102.             -0.79448379596794250000, -0.73218211874028970000, -0.66304426693021520000, -0.58771575724076230000,
  1103.             -0.50689990893222950000, -0.42135127613063540000, -0.33186860228212767000, -0.23928736225213710000,
  1104.             -0.14447196158279646000, -0.04830766568773831000, 0.04830766568773831000, 0.14447196158279646000,
  1105.             0.23928736225213710000, 0.33186860228212767000, 0.42135127613063540000, 0.50689990893222950000,
  1106.             0.58771575724076230000, 0.66304426693021520000, 0.73218211874028970000, 0.79448379596794250000,
  1107.             0.84936761373256990000, 0.89632115576605220000, 0.93490607593773970000, 0.96476225558750640000,
  1108.             0.98561151154526840000, 0.99726386184948160000 };

  1109.         /** Weights for quadrature of order 32. */
  1110.         private static final double[] W_32 = { 0.00701861000947013600, 0.01627439473090571200, 0.02539206530926214200,
  1111.             0.03427386291302141000, 0.04283589802222658600, 0.05099805926237621600, 0.05868409347853559000,
  1112.             0.06582222277636193000, 0.07234579410884862000, 0.07819389578707042000, 0.08331192422694673000,
  1113.             0.08765209300440380000, 0.09117387869576390000, 0.09384439908080441000, 0.09563872007927487000,
  1114.             0.09654008851472784000, 0.09654008851472784000, 0.09563872007927487000, 0.09384439908080441000,
  1115.             0.09117387869576390000, 0.08765209300440380000, 0.08331192422694673000, 0.07819389578707042000,
  1116.             0.07234579410884862000, 0.06582222277636193000, 0.05868409347853559000, 0.05099805926237621600,
  1117.             0.04283589802222658600, 0.03427386291302141000, 0.02539206530926214200, 0.01627439473090571200,
  1118.             0.00701861000947013600 };

  1119.         /** Points for quadrature of order 40. */
  1120.         private static final double[] P_40 = { -0.99823770971055930000, -0.99072623869945710000,
  1121.             -0.97725994998377420000, -0.95791681921379170000, -0.93281280827867660000, -0.90209880696887420000,
  1122.             -0.86595950321225960000, -0.82461223083331170000, -0.77830565142651940000, -0.72731825518992710000,
  1123.             -0.67195668461417960000, -0.61255388966798030000, -0.54946712509512820000, -0.48307580168617870000,
  1124.             -0.41377920437160500000, -0.34199409082575850000, -0.26815218500725370000, -0.19269758070137110000,
  1125.             -0.11608407067525522000, -0.03877241750605081600, 0.03877241750605081600, 0.11608407067525522000,
  1126.             0.19269758070137110000, 0.26815218500725370000, 0.34199409082575850000, 0.41377920437160500000,
  1127.             0.48307580168617870000, 0.54946712509512820000, 0.61255388966798030000, 0.67195668461417960000,
  1128.             0.72731825518992710000, 0.77830565142651940000, 0.82461223083331170000, 0.86595950321225960000,
  1129.             0.90209880696887420000, 0.93281280827867660000, 0.95791681921379170000, 0.97725994998377420000,
  1130.             0.99072623869945710000, 0.99823770971055930000 };

  1131.         /** Weights for quadrature of order 40. */
  1132.         private static final double[] W_40 = { 0.00452127709853309800, 0.01049828453115270400, 0.01642105838190797300,
  1133.             0.02224584919416689000, 0.02793700698002338000, 0.03346019528254786500, 0.03878216797447199000,
  1134.             0.04387090818567333000, 0.04869580763507221000, 0.05322784698393679000, 0.05743976909939157000,
  1135.             0.06130624249292891000, 0.06480401345660108000, 0.06791204581523394000, 0.07061164739128681000,
  1136.             0.07288658239580408000, 0.07472316905796833000, 0.07611036190062619000, 0.07703981816424793000,
  1137.             0.07750594797842482000, 0.07750594797842482000, 0.07703981816424793000, 0.07611036190062619000,
  1138.             0.07472316905796833000, 0.07288658239580408000, 0.07061164739128681000, 0.06791204581523394000,
  1139.             0.06480401345660108000, 0.06130624249292891000, 0.05743976909939157000, 0.05322784698393679000,
  1140.             0.04869580763507221000, 0.04387090818567333000, 0.03878216797447199000, 0.03346019528254786500,
  1141.             0.02793700698002338000, 0.02224584919416689000, 0.01642105838190797300, 0.01049828453115270400,
  1142.             0.00452127709853309800 };

  1143.         /** Points for quadrature of order 48. */
  1144.         private static final double[] P_48 = { -0.99877100725242610000, -0.99353017226635080000,
  1145.             -0.98412458372282700000, -0.97059159254624720000, -0.95298770316043080000, -0.93138669070655440000,
  1146.             -0.90587913671556960000, -0.87657202027424800000, -0.84358826162439350000, -0.80706620402944250000,
  1147.             -0.76715903251574020000, -0.72403413092381470000, -0.67787237963266400000, -0.62886739677651370000,
  1148.             -0.57722472608397270000, -0.52316097472223300000, -0.46690290475095840000, -0.40868648199071680000,
  1149.             -0.34875588629216070000, -0.28736248735545555000, -0.22476379039468908000, -0.16122235606889174000,
  1150.             -0.09700469920946270000, -0.03238017096286937000, 0.03238017096286937000, 0.09700469920946270000,
  1151.             0.16122235606889174000, 0.22476379039468908000, 0.28736248735545555000, 0.34875588629216070000,
  1152.             0.40868648199071680000, 0.46690290475095840000, 0.52316097472223300000, 0.57722472608397270000,
  1153.             0.62886739677651370000, 0.67787237963266400000, 0.72403413092381470000, 0.76715903251574020000,
  1154.             0.80706620402944250000, 0.84358826162439350000, 0.87657202027424800000, 0.90587913671556960000,
  1155.             0.93138669070655440000, 0.95298770316043080000, 0.97059159254624720000, 0.98412458372282700000,
  1156.             0.99353017226635080000, 0.99877100725242610000 };

  1157.         /** Weights for quadrature of order 48. */
  1158.         private static final double[] W_48 = { 0.00315334605230596250, 0.00732755390127620800, 0.01147723457923446900,
  1159.             0.01557931572294386600, 0.01961616045735556700, 0.02357076083932435600, 0.02742650970835688000,
  1160.             0.03116722783279807000, 0.03477722256477045000, 0.03824135106583080600, 0.04154508294346483000,
  1161.             0.04467456085669424000, 0.04761665849249054000, 0.05035903555385448000, 0.05289018948519365000,
  1162.             0.05519950369998416500, 0.05727729210040315000, 0.05911483969839566000, 0.06070443916589384000,
  1163.             0.06203942315989268000, 0.06311419228625403000, 0.06392423858464817000, 0.06446616443595010000,
  1164.             0.06473769681268386000, 0.06473769681268386000, 0.06446616443595010000, 0.06392423858464817000,
  1165.             0.06311419228625403000, 0.06203942315989268000, 0.06070443916589384000, 0.05911483969839566000,
  1166.             0.05727729210040315000, 0.05519950369998416500, 0.05289018948519365000, 0.05035903555385448000,
  1167.             0.04761665849249054000, 0.04467456085669424000, 0.04154508294346483000, 0.03824135106583080600,
  1168.             0.03477722256477045000, 0.03116722783279807000, 0.02742650970835688000, 0.02357076083932435600,
  1169.             0.01961616045735556700, 0.01557931572294386600, 0.01147723457923446900, 0.00732755390127620800,
  1170.             0.00315334605230596250 };

  1171.         /** Node points. */
  1172.         private final double[] nodePoints;

  1173.         /** Node weights. */
  1174.         private final double[] nodeWeights;

  1175.         /** Number of points. */
  1176.         private final int numberOfPoints;

  1177.         /**
  1178.          * Creates a Gauss integrator of the given order.
  1179.          *
  1180.          * @param numberOfPoints Order of the integration rule.
  1181.          */
  1182.         GaussQuadrature(final int numberOfPoints) {

  1183.             this.numberOfPoints = numberOfPoints;

  1184.             switch (numberOfPoints) {
  1185.                 case 12:
  1186.                     this.nodePoints = P_12.clone();
  1187.                     this.nodeWeights = W_12.clone();
  1188.                     break;
  1189.                 case 16:
  1190.                     this.nodePoints = P_16.clone();
  1191.                     this.nodeWeights = W_16.clone();
  1192.                     break;
  1193.                 case 20:
  1194.                     this.nodePoints = P_20.clone();
  1195.                     this.nodeWeights = W_20.clone();
  1196.                     break;
  1197.                 case 24:
  1198.                     this.nodePoints = P_24.clone();
  1199.                     this.nodeWeights = W_24.clone();
  1200.                     break;
  1201.                 case 32:
  1202.                     this.nodePoints = P_32.clone();
  1203.                     this.nodeWeights = W_32.clone();
  1204.                     break;
  1205.                 case 40:
  1206.                     this.nodePoints = P_40.clone();
  1207.                     this.nodeWeights = W_40.clone();
  1208.                     break;
  1209.                 case 48:
  1210.                 default:
  1211.                     this.nodePoints = P_48.clone();
  1212.                     this.nodeWeights = W_48.clone();
  1213.                     break;
  1214.             }

  1215.         }

  1216.         /**
  1217.          * Integrates a given function on the given interval.
  1218.          *
  1219.          * @param f          Function to integrate.
  1220.          * @param lowerBound Lower bound of the integration interval.
  1221.          * @param upperBound Upper bound of the integration interval.
  1222.          * @return the integral of the weighted function.
  1223.          */
  1224.         public double[] integrate(final UnivariateVectorFunction f, final double lowerBound, final double upperBound) {

  1225.             final double[] adaptedPoints = nodePoints.clone();
  1226.             final double[] adaptedWeights = nodeWeights.clone();
  1227.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1228.             return basicIntegrate(f, adaptedPoints, adaptedWeights);
  1229.         }

  1230.         /**
  1231.          * Integrates a given function on the given interval.
  1232.          *
  1233.          * @param <T>        the type of the field elements
  1234.          * @param f          Function to integrate.
  1235.          * @param lowerBound Lower bound of the integration interval.
  1236.          * @param upperBound Upper bound of the integration interval.
  1237.          * @param field      field utilized by default
  1238.          * @return the integral of the weighted function.
  1239.          */
  1240.         public <T extends CalculusFieldElement<T>> T[] integrate(final CalculusFieldUnivariateVectorFunction<T> f,
  1241.                 final T lowerBound, final T upperBound, final Field<T> field) {

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

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

  1245.             for (int i = 0; i < numberOfPoints; i++) {
  1246.                 adaptedPoints[i] = zero.newInstance(nodePoints[i]);
  1247.                 adaptedWeights[i] = zero.newInstance(nodeWeights[i]);
  1248.             }

  1249.             transform(adaptedPoints, adaptedWeights, lowerBound, upperBound);
  1250.             return basicIntegrate(f, adaptedPoints, adaptedWeights, field);
  1251.         }

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

  1273.         /**
  1274.          * Performs a change of variable so that the integration can be performed on an
  1275.          * arbitrary interval {@code [a, b]}.
  1276.          * <p>
  1277.          * It is assumed that the natural interval is {@code [-1, 1]}.
  1278.          * </p>
  1279.          * @param <T>     the type of the field elements
  1280.          * @param points  Points to adapt to the new interval.
  1281.          * @param weights Weights to adapt to the new interval.
  1282.          * @param a       Lower bound of the integration interval.
  1283.          * @param b       Lower bound of the integration interval
  1284.          */
  1285.         private <T extends CalculusFieldElement<T>> void transform(final T[] points, final T[] weights, final T a,
  1286.                 final T b) {
  1287.             // Scaling
  1288.             final T scale = (b.subtract(a)).divide(2.);
  1289.             final T shift = a.add(scale);
  1290.             for (int i = 0; i < points.length; i++) {
  1291.                 points[i] = scale.multiply(points[i]).add(shift);
  1292.                 weights[i] = scale.multiply(weights[i]);
  1293.             }
  1294.         }

  1295.         /**
  1296.          * Returns an estimate of the integral of {@code f(x) * w(x)}, where {@code w}
  1297.          * is a weight function that depends on the actual flavor of the Gauss
  1298.          * integration scheme.
  1299.          *
  1300.          * @param f       Function to integrate.
  1301.          * @param points  Nodes.
  1302.          * @param weights Nodes weights.
  1303.          * @return the integral of the weighted function.
  1304.          */
  1305.         private double[] basicIntegrate(final UnivariateVectorFunction f, final double[] points,
  1306.                 final double[] weights) {
  1307.             double x = points[0];
  1308.             double w = weights[0];
  1309.             double[] v = f.value(x);
  1310.             final double[] y = new double[v.length];
  1311.             for (int j = 0; j < v.length; j++) {
  1312.                 y[j] = w * v[j];
  1313.             }
  1314.             final double[] t = y.clone();
  1315.             final double[] c = new double[v.length];
  1316.             final double[] s = t.clone();
  1317.             for (int i = 1; i < points.length; i++) {
  1318.                 x = points[i];
  1319.                 w = weights[i];
  1320.                 v = f.value(x);
  1321.                 for (int j = 0; j < v.length; j++) {
  1322.                     y[j] = w * v[j] - c[j];
  1323.                     t[j] = s[j] + y[j];
  1324.                     c[j] = (t[j] - s[j]) - y[j];
  1325.                     s[j] = t[j];
  1326.                 }
  1327.             }
  1328.             return s;
  1329.         }

  1330.         /**
  1331.          * Returns an estimate of the integral of {@code f(x) * w(x)}, where {@code w}
  1332.          * is a weight function that depends on the actual flavor of the Gauss
  1333.          * integration scheme.
  1334.          *
  1335.          * @param <T>     the type of the field elements.
  1336.          * @param f       Function to integrate.
  1337.          * @param points  Nodes.
  1338.          * @param weights Nodes weight
  1339.          * @param field   field utilized by default
  1340.          * @return the integral of the weighted function.
  1341.          */
  1342.         private <T extends CalculusFieldElement<T>> T[] basicIntegrate(final CalculusFieldUnivariateVectorFunction<T> f,
  1343.                 final T[] points, final T[] weights, final Field<T> field) {

  1344.             T x = points[0];
  1345.             T w = weights[0];
  1346.             T[] v = f.value(x);

  1347.             final T[] y = MathArrays.buildArray(field, v.length);
  1348.             for (int j = 0; j < v.length; j++) {
  1349.                 y[j] = v[j].multiply(w);
  1350.             }
  1351.             final T[] t = y.clone();
  1352.             final T[] c = MathArrays.buildArray(field, v.length);
  1353.             final T[] s = t.clone();
  1354.             for (int i = 1; i < points.length; i++) {
  1355.                 x = points[i];
  1356.                 w = weights[i];
  1357.                 v = f.value(x);
  1358.                 for (int j = 0; j < v.length; j++) {
  1359.                     y[j] = v[j].multiply(w).subtract(c[j]);
  1360.                     t[j] = y[j].add(s[j]);
  1361.                     c[j] = (t[j].subtract(s[j])).subtract(y[j]);
  1362.                     s[j] = t[j];
  1363.                 }
  1364.             }
  1365.             return s;
  1366.         }

  1367.     }

  1368.     /**
  1369.      * Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  1370.      * coefficients.
  1371.      * <p>
  1372.      * Those coefficients are given in Danielson paper by expression 4.4-(6)
  1373.      * </p>
  1374.      * @author Petre Bazavan
  1375.      * @author Lucian Barbulescu
  1376.      */
  1377.     protected class FourierCjSjCoefficients {

  1378.         /** Maximum possible value for j. */
  1379.         private final int jMax;

  1380.         /**
  1381.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1382.          * <p>
  1383.          * the index i corresponds to the following elements: <br/>
  1384.          * - 0 for a <br>
  1385.          * - 1 for k <br>
  1386.          * - 2 for h <br>
  1387.          * - 3 for q <br>
  1388.          * - 4 for p <br>
  1389.          * - 5 for λ <br>
  1390.          * </p>
  1391.          */
  1392.         private final double[][] cCoef;

  1393.         /**
  1394.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1395.          * <p>
  1396.          * the index i corresponds to the following elements: <br/>
  1397.          * - 0 for a <br>
  1398.          * - 1 for k <br>
  1399.          * - 2 for h <br>
  1400.          * - 3 for q <br>
  1401.          * - 4 for p <br>
  1402.          * - 5 for λ <br>
  1403.          * </p>
  1404.          */
  1405.         private final double[][] sCoef;

  1406.         /**
  1407.          * Standard constructor.
  1408.          * @param state             the current state
  1409.          * @param jMax              maximum value for j
  1410.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1411.          * @param parameters        list of parameter values at state date for each driver
  1412.          * of the force model parameters (1 value per parameter)
  1413.          */
  1414.         FourierCjSjCoefficients(final SpacecraftState state, final int jMax, final AuxiliaryElements auxiliaryElements,
  1415.                 final double[] parameters) {

  1416.             // Initialise the fields
  1417.             this.jMax = jMax;

  1418.             // Allocate the arrays
  1419.             final int rows = jMax + 1;
  1420.             cCoef = new double[rows][6];
  1421.             sCoef = new double[rows][6];

  1422.             // Compute the coefficients
  1423.             computeCoefficients(state, auxiliaryElements, parameters);
  1424.         }

  1425.         /**
  1426.          * Compute the Fourrier coefficients.
  1427.          * <p>
  1428.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients
  1429.          * need to be computed as D<sub>i</sub><sup>m</sup> is always 0.
  1430.          * </p>
  1431.          * @param state             the current state
  1432.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1433.          * @param parameters        list of parameter values at state date for each driver
  1434.          * of the force model parameters (1 value per parameter)
  1435.          */
  1436.         private void computeCoefficients(final SpacecraftState state, final AuxiliaryElements auxiliaryElements,
  1437.                 final double[] parameters) {

  1438.             // Computes the limits for the integral
  1439.             final double[] ll = getLLimits(state, auxiliaryElements);
  1440.             // Computes integrated mean element rates if Llow < Lhigh
  1441.             if (ll[0] < ll[1]) {
  1442.                 // Compute 1 / PI
  1443.                 final double ooPI = 1 / FastMath.PI;

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

  1448.                     // divide by PI and set the values for the coefficients
  1449.                     for (int i = 0; i < 6; i++) {
  1450.                         cCoef[j][i] = ooPI * curentCoefficients[i];
  1451.                         sCoef[j][i] = ooPI * curentCoefficients[i + 6];
  1452.                     }
  1453.                 }
  1454.             }
  1455.         }

  1456.         /**
  1457.          * Get the coefficient C<sub>i</sub><sup>j</sup>.
  1458.          * @param i i index - corresponds to the required variation
  1459.          * @param j j index
  1460.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1461.          */
  1462.         public double getCij(final int i, final int j) {
  1463.             return cCoef[j][i];
  1464.         }

  1465.         /**
  1466.          * Get the coefficient S<sub>i</sub><sup>j</sup>.
  1467.          * @param i i index - corresponds to the required variation
  1468.          * @param j j index
  1469.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1470.          */
  1471.         public double getSij(final int i, final int j) {
  1472.             return sCoef[j][i];
  1473.         }
  1474.     }

  1475.     /**
  1476.      * Compute the C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup>
  1477.      * coefficients with field elements.
  1478.      * <p>
  1479.      * Those coefficients are given in Danielson paper by expression 4.4-(6)
  1480.      * </p>
  1481.      * @author Petre Bazavan
  1482.      * @author Lucian Barbulescu
  1483.      * @param <T> type of the field elements
  1484.      */
  1485.     protected class FieldFourierCjSjCoefficients<T extends CalculusFieldElement<T>> {

  1486.         /** Maximum possible value for j. */
  1487.         private final int jMax;

  1488.         /**
  1489.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1490.          * <p>
  1491.          * the index i corresponds to the following elements: <br/>
  1492.          * - 0 for a <br>
  1493.          * - 1 for k <br>
  1494.          * - 2 for h <br>
  1495.          * - 3 for q <br>
  1496.          * - 4 for p <br>
  1497.          * - 5 for λ <br>
  1498.          * </p>
  1499.          */
  1500.         private final T[][] cCoef;

  1501.         /**
  1502.          * The C<sub>i</sub><sup>j</sup> coefficients.
  1503.          * <p>
  1504.          * the index i corresponds to the following elements: <br/>
  1505.          * - 0 for a <br>
  1506.          * - 1 for k <br>
  1507.          * - 2 for h <br>
  1508.          * - 3 for q <br>
  1509.          * - 4 for p <br>
  1510.          * - 5 for λ <br>
  1511.          * </p>
  1512.          */
  1513.         private final T[][] sCoef;

  1514.         /**
  1515.          * Standard constructor.
  1516.          * @param state             the current state
  1517.          * @param jMax              maximum value for j
  1518.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1519.          * @param parameters        values of the force model parameters
  1520.          * @param field             field used by default
  1521.          */
  1522.         FieldFourierCjSjCoefficients(final FieldSpacecraftState<T> state, final int jMax,
  1523.                 final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters, final Field<T> field) {
  1524.             // Initialise the fields
  1525.             this.jMax = jMax;

  1526.             // Allocate the arrays
  1527.             final int rows = jMax + 1;
  1528.             cCoef = MathArrays.buildArray(field, rows, 6);
  1529.             sCoef = MathArrays.buildArray(field, rows, 6);

  1530.             // Compute the coefficients
  1531.             computeCoefficients(state, auxiliaryElements, parameters, field);
  1532.         }

  1533.         /**
  1534.          * Compute the Fourrier coefficients.
  1535.          * <p>
  1536.          * Only the C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup> coefficients
  1537.          * need to be computed as D<sub>i</sub><sup>m</sup> is always 0.
  1538.          * </p>
  1539.          * @param state             the current state
  1540.          * @param auxiliaryElements auxiliary elements related to the current orbit
  1541.          * @param parameters        values of the force model parameters
  1542.          * @param field             field used by default
  1543.          */
  1544.         private void computeCoefficients(final FieldSpacecraftState<T> state,
  1545.                 final FieldAuxiliaryElements<T> auxiliaryElements, final T[] parameters, final Field<T> field) {
  1546.             // Zero
  1547.             final T zero = field.getZero();
  1548.             // Computes the limits for the integral
  1549.             final T[] ll = getLLimits(state, auxiliaryElements);
  1550.             // Computes integrated mean element rates if Llow < Lhigh
  1551.             if (ll[0].getReal() < ll[1].getReal()) {
  1552.                 // Compute 1 / PI
  1553.                 final T ooPI = zero.getPi().reciprocal();

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

  1558.                     // divide by PI and set the values for the coefficients
  1559.                     for (int i = 0; i < 6; i++) {
  1560.                         cCoef[j][i] = curentCoefficients[i].multiply(ooPI);
  1561.                         sCoef[j][i] = curentCoefficients[i + 6].multiply(ooPI);
  1562.                     }
  1563.                 }
  1564.             }
  1565.         }

  1566.         /**
  1567.          * Get the coefficient C<sub>i</sub><sup>j</sup>.
  1568.          * @param i i index - corresponds to the required variation
  1569.          * @param j j index
  1570.          * @return the coefficient C<sub>i</sub><sup>j</sup>
  1571.          */
  1572.         public T getCij(final int i, final int j) {
  1573.             return cCoef[j][i];
  1574.         }

  1575.         /**
  1576.          * Get the coefficient S<sub>i</sub><sup>j</sup>.
  1577.          * @param i i index - corresponds to the required variation
  1578.          * @param j j index
  1579.          * @return the coefficient S<sub>i</sub><sup>j</sup>
  1580.          */
  1581.         public T getSij(final int i, final int j) {
  1582.             return sCoef[j][i];
  1583.         }
  1584.     }

  1585.     /**
  1586.      * This class handles the short periodic coefficients described in Danielson
  1587.      * 2.5.3-26.
  1588.      *
  1589.      * <p>
  1590.      * The value of M is 0. Also, since the values of the Fourier coefficient
  1591.      * D<sub>i</sub><sup>m</sup> is 0 then the values of the coefficients
  1592.      * D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1593.      * </p>
  1594.      * @author Petre Bazavan
  1595.      * @author Lucian Barbulescu
  1596.      *
  1597.      */
  1598.     protected static class GaussianShortPeriodicCoefficients implements ShortPeriodTerms {

  1599.         /** Maximum value for j index. */
  1600.         private final int jMax;

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

  1603.         /** Prefix for coefficients keys. */
  1604.         private final String coefficientsKeyPrefix;

  1605.         /** All coefficients slots. */
  1606.         private final transient TimeSpanMap<Slot> slots;

  1607.         /**
  1608.          * Constructor.
  1609.          * @param coefficientsKeyPrefix prefix for coefficients keys
  1610.          * @param jMax                  maximum value for j index
  1611.          * @param interpolationPoints   number of points used in the interpolation
  1612.          *                              process
  1613.          * @param slots                 all coefficients slots
  1614.          */
  1615.         GaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix, final int jMax,
  1616.                 final int interpolationPoints, final TimeSpanMap<Slot> slots) {
  1617.             // Initialize fields
  1618.             this.jMax = jMax;
  1619.             this.interpolationPoints = interpolationPoints;
  1620.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1621.             this.slots = slots;
  1622.         }

  1623.         /**
  1624.          * Get the slot valid for some date.
  1625.          * @param meanStates mean states defining the slot
  1626.          * @return slot valid at the specified date
  1627.          */
  1628.         public Slot createSlot(final SpacecraftState... meanStates) {
  1629.             final Slot slot = new Slot(jMax, interpolationPoints);
  1630.             final AbsoluteDate first = meanStates[0].getDate();
  1631.             final AbsoluteDate last = meanStates[meanStates.length - 1].getDate();
  1632.             final int compare = first.compareTo(last);
  1633.             if (compare < 0) {
  1634.                 slots.addValidAfter(slot, first, false);
  1635.             } else if (compare > 0) {
  1636.                 slots.addValidBefore(slot, first, false);
  1637.             } else {
  1638.                 // single date, valid for all time
  1639.                 slots.addValidAfter(slot, AbsoluteDate.PAST_INFINITY, false);
  1640.             }
  1641.             return slot;
  1642.         }

  1643.         /**
  1644.          * Compute the short periodic coefficients.
  1645.          *
  1646.          * @param state       current state information: date, kinematics, attitude
  1647.          * @param slot        coefficients slot
  1648.          * @param fourierCjSj Fourier coefficients
  1649.          * @param uijvij      U and V coefficients
  1650.          * @param n           Keplerian mean motion
  1651.          * @param a           semi major axis
  1652.          */
  1653.         private void computeCoefficients(final SpacecraftState state, final Slot slot,
  1654.                 final FourierCjSjCoefficients fourierCjSj, final UijVijCoefficients uijvij, final double n,
  1655.                 final double a) {

  1656.             // get the current date
  1657.             final AbsoluteDate date = state.getDate();

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

  1660.             // 1. / n
  1661.             final double oon = 1. / n;
  1662.             // 3. / (2 * a * n)
  1663.             final double to2an = 1.5 * oon / a;
  1664.             // 3. / (4 * a * n)
  1665.             final double to4an = to2an / 2;

  1666.             // Compute the coefficients for each element
  1667.             final int size = jMax + 1;
  1668.             final double[] di1 = new double[6];
  1669.             final double[] di2 = new double[6];
  1670.             final double[][] currentCij = new double[size][6];
  1671.             final double[][] currentSij = new double[size][6];
  1672.             for (int i = 0; i < 6; i++) {

  1673.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  1674.                 di1[i] = -oon * fourierCjSj.getCij(i, 0);
  1675.                 if (i == 5) {
  1676.                     di1[i] += to2an * uijvij.getU1(0, 0);
  1677.                 }
  1678.                 di2[i] = 0.;
  1679.                 if (i == 5) {
  1680.                     di2[i] += -to4an * fourierCjSj.getCij(0, 0);
  1681.                 }

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

  1684.                 for (int j = 1; j <= jMax; j++) {
  1685.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  1686.                     currentCij[j][i] = oon * uijvij.getU1(j, i);
  1687.                     if (i == 5) {
  1688.                         currentCij[j][i] += -to2an * uijvij.getU2(j);
  1689.                     }
  1690.                     currentSij[j][i] = oon * uijvij.getV1(j, i);
  1691.                     if (i == 5) {
  1692.                         currentSij[j][i] += -to2an * uijvij.getV2(j);
  1693.                     }

  1694.                     // add the computed coefficients to C<sub>i</sub>⁰
  1695.                     currentCij[0][i] -= currentCij[j][i] * uijvij.currentRhoSigmaj[0][j] +
  1696.                         currentSij[j][i] * uijvij.currentRhoSigmaj[1][j];
  1697.                 }

  1698.             }

  1699.             // add the values to the interpolators
  1700.             slot.cij[0].addGridPoint(date, currentCij[0]);
  1701.             slot.dij[1].addGridPoint(date, di1);
  1702.             slot.dij[2].addGridPoint(date, di2);
  1703.             for (int j = 1; j <= jMax; j++) {
  1704.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  1705.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  1706.             }

  1707.         }

  1708.         /**
  1709.          * Compute the coefficient k₂⁰ by using the equation 2.5.3-(9a) from Danielson.
  1710.          * <p>
  1711.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  1712.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² +
  1713.          * ρ<sub>k</sub>²)]
  1714.          * </p>
  1715.          * @param kMax             max value fot k index
  1716.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  1717.          *                         σ<sub>j</sub> coefficients
  1718.          * @return the coefficient k₂⁰
  1719.          */
  1720.         private double computeK20(final int kMax, final double[][] currentRhoSigmaj) {
  1721.             double k20 = 0.;

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

  1728.                 // multiply by 2 / k²
  1729.                 currentTerm *= 2. / (kIndex * kIndex);

  1730.                 // add the term to the result
  1731.                 k20 += currentTerm;
  1732.             }

  1733.             return k20;
  1734.         }

  1735.         /** {@inheritDoc} */
  1736.         @Override
  1737.         public double[] value(final Orbit meanOrbit) {

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

  1740.             // Get the True longitude L
  1741.             final double L = meanOrbit.getLv();

  1742.             // Compute the center (l - λ)
  1743.             final double center = L - meanOrbit.getLM();
  1744.             // Compute (l - λ)²
  1745.             final double center2 = center * center;

  1746.             // Initialize short periodic variations
  1747.             final double[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  1748.             final double[] d1 = slot.dij[1].value(meanOrbit.getDate());
  1749.             final double[] d2 = slot.dij[2].value(meanOrbit.getDate());
  1750.             for (int i = 0; i < 6; i++) {
  1751.                 shortPeriodicVariation[i] += center * d1[i] + center2 * d2[i];
  1752.             }

  1753.             for (int j = 1; j <= JMAX; j++) {
  1754.                 final double[] c = slot.cij[j].value(meanOrbit.getDate());
  1755.                 final double[] s = slot.sij[j].value(meanOrbit.getDate());
  1756.                 final SinCos sc  = FastMath.sinCos(j * L);
  1757.                 final double cos = sc.cos();
  1758.                 final double sin = sc.sin();
  1759.                 for (int i = 0; i < 6; i++) {
  1760.                     // add corresponding term to the short periodic variation
  1761.                     shortPeriodicVariation[i] += c[i] * cos;
  1762.                     shortPeriodicVariation[i] += s[i] * sin;
  1763.                 }
  1764.             }

  1765.             return shortPeriodicVariation;

  1766.         }

  1767.         /** {@inheritDoc} */
  1768.         public String getCoefficientsKeyPrefix() {
  1769.             return coefficientsKeyPrefix;
  1770.         }

  1771.         /**
  1772.          * {@inheritDoc}
  1773.          * <p>
  1774.          * For Gaussian forces, there are JMAX cj coefficients, JMAX sj coefficients and
  1775.          * 3 dj coefficients. As JMAX = 12, this sums up to 27 coefficients. The j index
  1776.          * is the integer multiplier for the true longitude argument in the cj and sj
  1777.          * coefficients and to the degree in the polynomial dj coefficients.
  1778.          * </p>
  1779.          */
  1780.         @Override
  1781.         public Map<String, double[]> getCoefficients(final AbsoluteDate date, final Set<String> selected) {

  1782.             // select the coefficients slot
  1783.             final Slot slot = slots.get(date);

  1784.             final Map<String, double[]> coefficients = new HashMap<>(2 * JMAX + 3);
  1785.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  1786.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  1787.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  1788.             for (int j = 1; j <= JMAX; j++) {
  1789.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  1790.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  1791.             }

  1792.             return coefficients;

  1793.         }

  1794.         /**
  1795.          * Put a coefficient in a map if selected.
  1796.          * @param map      map to populate
  1797.          * @param selected set of coefficients that should be put in the map (empty set
  1798.          *                 means all coefficients are selected)
  1799.          * @param value    coefficient value
  1800.          * @param id       coefficient identifier
  1801.          * @param indices  list of coefficient indices
  1802.          */
  1803.         private void storeIfSelected(final Map<String, double[]> map, final Set<String> selected, final double[] value,
  1804.                 final String id, final int... indices) {
  1805.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  1806.             keyBuilder.append(id);
  1807.             for (int index : indices) {
  1808.                 keyBuilder.append('[').append(index).append(']');
  1809.             }
  1810.             final String key = keyBuilder.toString();
  1811.             if (selected.isEmpty() || selected.contains(key)) {
  1812.                 map.put(key, value);
  1813.             }
  1814.         }

  1815.     }

  1816.     /**
  1817.      * This class handles the short periodic coefficients described in Danielson
  1818.      * 2.5.3-26.
  1819.      *
  1820.      * <p>
  1821.      * The value of M is 0. Also, since the values of the Fourier coefficient
  1822.      * D<sub>i</sub><sup>m</sup> is 0 then the values of the coefficients
  1823.      * D<sub>i</sub><sup>m</sup> for m &gt; 2 are also 0.
  1824.      * </p>
  1825.      * @author Petre Bazavan
  1826.      * @author Lucian Barbulescu
  1827.      * @param <T> type of the field elements
  1828.      */
  1829.     protected static class FieldGaussianShortPeriodicCoefficients<T extends CalculusFieldElement<T>>
  1830.             implements FieldShortPeriodTerms<T> {

  1831.         /** Maximum value for j index. */
  1832.         private final int jMax;

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

  1835.         /** Prefix for coefficients keys. */
  1836.         private final String coefficientsKeyPrefix;

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

  1839.         /**
  1840.          * Constructor.
  1841.          * @param coefficientsKeyPrefix prefix for coefficients keys
  1842.          * @param jMax                  maximum value for j index
  1843.          * @param interpolationPoints   number of points used in the interpolation
  1844.          *                              process
  1845.          * @param slots                 all coefficients slots
  1846.          */
  1847.         FieldGaussianShortPeriodicCoefficients(final String coefficientsKeyPrefix, final int jMax,
  1848.                 final int interpolationPoints, final FieldTimeSpanMap<FieldSlot<T>, T> slots) {
  1849.             // Initialize fields
  1850.             this.jMax = jMax;
  1851.             this.interpolationPoints = interpolationPoints;
  1852.             this.coefficientsKeyPrefix = coefficientsKeyPrefix;
  1853.             this.slots = slots;
  1854.         }

  1855.         /**
  1856.          * Get the slot valid for some date.
  1857.          * @param meanStates mean states defining the slot
  1858.          * @return slot valid at the specified date
  1859.          */
  1860.         @SuppressWarnings("unchecked")
  1861.         public FieldSlot<T> createSlot(final FieldSpacecraftState<T>... meanStates) {
  1862.             final FieldSlot<T> slot = new FieldSlot<>(jMax, interpolationPoints);
  1863.             final FieldAbsoluteDate<T> first = meanStates[0].getDate();
  1864.             final FieldAbsoluteDate<T> last = meanStates[meanStates.length - 1].getDate();
  1865.             if (first.compareTo(last) <= 0) {
  1866.                 slots.addValidAfter(slot, first);
  1867.             } else {
  1868.                 slots.addValidBefore(slot, first);
  1869.             }
  1870.             return slot;
  1871.         }

  1872.         /**
  1873.          * Compute the short periodic coefficients.
  1874.          *
  1875.          * @param state       current state information: date, kinematics, attitude
  1876.          * @param slot        coefficients slot
  1877.          * @param fourierCjSj Fourier coefficients
  1878.          * @param uijvij      U and V coefficients
  1879.          * @param n           Keplerian mean motion
  1880.          * @param a           semi major axis
  1881.          * @param field       field used by default
  1882.          */
  1883.         private void computeCoefficients(final FieldSpacecraftState<T> state, final FieldSlot<T> slot,
  1884.                 final FieldFourierCjSjCoefficients<T> fourierCjSj, final FieldUijVijCoefficients<T> uijvij, final T n,
  1885.                 final T a, final Field<T> field) {

  1886.             // Zero
  1887.             final T zero = field.getZero();

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

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

  1892.             // 1. / n
  1893.             final T oon = n.reciprocal();
  1894.             // 3. / (2 * a * n)
  1895.             final T to2an = oon.multiply(1.5).divide(a);
  1896.             // 3. / (4 * a * n)
  1897.             final T to4an = to2an.divide(2.);

  1898.             // Compute the coefficients for each element
  1899.             final int size = jMax + 1;
  1900.             final T[] di1 = MathArrays.buildArray(field, 6);
  1901.             final T[] di2 = MathArrays.buildArray(field, 6);
  1902.             final T[][] currentCij = MathArrays.buildArray(field, size, 6);
  1903.             final T[][] currentSij = MathArrays.buildArray(field, size, 6);
  1904.             for (int i = 0; i < 6; i++) {

  1905.                 // compute D<sub>i</sub>¹ and D<sub>i</sub>² (all others are 0)
  1906.                 di1[i] = oon.negate().multiply(fourierCjSj.getCij(i, 0));
  1907.                 if (i == 5) {
  1908.                     di1[i] = di1[i].add(to2an.multiply(uijvij.getU1(0, 0)));
  1909.                 }
  1910.                 di2[i] = zero;
  1911.                 if (i == 5) {
  1912.                     di2[i] = di2[i].add(to4an.negate().multiply(fourierCjSj.getCij(0, 0)));
  1913.                 }

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

  1916.                 for (int j = 1; j <= jMax; j++) {
  1917.                     // compute the current C<sub>i</sub><sup>j</sup> and S<sub>i</sub><sup>j</sup>
  1918.                     currentCij[j][i] = oon.multiply(uijvij.getU1(j, i));
  1919.                     if (i == 5) {
  1920.                         currentCij[j][i] = currentCij[j][i].add(to2an.negate().multiply(uijvij.getU2(j)));
  1921.                     }
  1922.                     currentSij[j][i] = oon.multiply(uijvij.getV1(j, i));
  1923.                     if (i == 5) {
  1924.                         currentSij[j][i] = currentSij[j][i].add(to2an.negate().multiply(uijvij.getV2(j)));
  1925.                     }

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

  1930.             }

  1931.             // add the values to the interpolators
  1932.             slot.cij[0].addGridPoint(date, currentCij[0]);
  1933.             slot.dij[1].addGridPoint(date, di1);
  1934.             slot.dij[2].addGridPoint(date, di2);
  1935.             for (int j = 1; j <= jMax; j++) {
  1936.                 slot.cij[j].addGridPoint(date, currentCij[j]);
  1937.                 slot.sij[j].addGridPoint(date, currentSij[j]);
  1938.             }

  1939.         }

  1940.         /**
  1941.          * Compute the coefficient k₂⁰ by using the equation 2.5.3-(9a) from Danielson.
  1942.          * <p>
  1943.          * After inserting 2.5.3-(8) into 2.5.3-(9a) the result becomes:<br>
  1944.          * k₂⁰ = &Sigma;<sub>k=1</sub><sup>kMax</sup>[(2 / k²) * (σ<sub>k</sub>² +
  1945.          * ρ<sub>k</sub>²)]
  1946.          * </p>
  1947.          * @param kMax             max value fot k index
  1948.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  1949.          *                         σ<sub>j</sub> coefficients
  1950.          * @param field            field used by default
  1951.          * @return the coefficient k₂⁰
  1952.          */
  1953.         private T computeK20(final int kMax, final T[][] currentRhoSigmaj, final Field<T> field) {
  1954.             T k20 = field.getZero();

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

  1961.                 // multiply by 2 / k²
  1962.                 currentTerm = currentTerm.multiply(2. / (kIndex * kIndex));

  1963.                 // add the term to the result
  1964.                 k20 = k20.add(currentTerm);
  1965.             }

  1966.             return k20;
  1967.         }

  1968.         /** {@inheritDoc} */
  1969.         @Override
  1970.         public T[] value(final FieldOrbit<T> meanOrbit) {

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

  1973.             // Get the True longitude L
  1974.             final T L = meanOrbit.getLv();

  1975.             // Compute the center (l - λ)
  1976.             final T center = L.subtract(meanOrbit.getLM());
  1977.             // Compute (l - λ)²
  1978.             final T center2 = center.square();

  1979.             // Initialize short periodic variations
  1980.             final T[] shortPeriodicVariation = slot.cij[0].value(meanOrbit.getDate());
  1981.             final T[] d1 = slot.dij[1].value(meanOrbit.getDate());
  1982.             final T[] d2 = slot.dij[2].value(meanOrbit.getDate());
  1983.             for (int i = 0; i < 6; i++) {
  1984.                 shortPeriodicVariation[i] = shortPeriodicVariation[i]
  1985.                         .add(center.multiply(d1[i]).add(center2.multiply(d2[i])));
  1986.             }

  1987.             for (int j = 1; j <= JMAX; j++) {
  1988.                 final T[] c = slot.cij[j].value(meanOrbit.getDate());
  1989.                 final T[] s = slot.sij[j].value(meanOrbit.getDate());
  1990.                 final FieldSinCos<T> sc = FastMath.sinCos(L.multiply(j));
  1991.                 final T cos = sc.cos();
  1992.                 final T sin = sc.sin();
  1993.                 for (int i = 0; i < 6; i++) {
  1994.                     // add corresponding term to the short periodic variation
  1995.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(c[i].multiply(cos));
  1996.                     shortPeriodicVariation[i] = shortPeriodicVariation[i].add(s[i].multiply(sin));
  1997.                 }
  1998.             }

  1999.             return shortPeriodicVariation;

  2000.         }

  2001.         /** {@inheritDoc} */
  2002.         public String getCoefficientsKeyPrefix() {
  2003.             return coefficientsKeyPrefix;
  2004.         }

  2005.         /**
  2006.          * {@inheritDoc}
  2007.          * <p>
  2008.          * For Gaussian forces, there are JMAX cj coefficients, JMAX sj coefficients and
  2009.          * 3 dj coefficients. As JMAX = 12, this sums up to 27 coefficients. The j index
  2010.          * is the integer multiplier for the true longitude argument in the cj and sj
  2011.          * coefficients and to the degree in the polynomial dj coefficients.
  2012.          * </p>
  2013.          */
  2014.         @Override
  2015.         public Map<String, T[]> getCoefficients(final FieldAbsoluteDate<T> date, final Set<String> selected) {

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

  2018.             final Map<String, T[]> coefficients = new HashMap<>(2 * JMAX + 3);
  2019.             storeIfSelected(coefficients, selected, slot.cij[0].value(date), "d", 0);
  2020.             storeIfSelected(coefficients, selected, slot.dij[1].value(date), "d", 1);
  2021.             storeIfSelected(coefficients, selected, slot.dij[2].value(date), "d", 2);
  2022.             for (int j = 1; j <= JMAX; j++) {
  2023.                 storeIfSelected(coefficients, selected, slot.cij[j].value(date), "c", j);
  2024.                 storeIfSelected(coefficients, selected, slot.sij[j].value(date), "s", j);
  2025.             }

  2026.             return coefficients;

  2027.         }

  2028.         /**
  2029.          * Put a coefficient in a map if selected.
  2030.          * @param map      map to populate
  2031.          * @param selected set of coefficients that should be put in the map (empty set
  2032.          *                 means all coefficients are selected)
  2033.          * @param value    coefficient value
  2034.          * @param id       coefficient identifier
  2035.          * @param indices  list of coefficient indices
  2036.          */
  2037.         private void storeIfSelected(final Map<String, T[]> map, final Set<String> selected, final T[] value,
  2038.                 final String id, final int... indices) {
  2039.             final StringBuilder keyBuilder = new StringBuilder(getCoefficientsKeyPrefix());
  2040.             keyBuilder.append(id);
  2041.             for (int index : indices) {
  2042.                 keyBuilder.append('[').append(index).append(']');
  2043.             }
  2044.             final String key = keyBuilder.toString();
  2045.             if (selected.isEmpty() || selected.contains(key)) {
  2046.                 map.put(key, value);
  2047.             }
  2048.         }

  2049.     }

  2050.     /**
  2051.      * The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients
  2052.      * described by equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2053.      * <p>
  2054.      * The index i takes only the values 1 and 2<br>
  2055.      * For U only the index 0 for j is used.
  2056.      * </p>
  2057.      *
  2058.      * @author Petre Bazavan
  2059.      * @author Lucian Barbulescu
  2060.      */
  2061.     protected static class UijVijCoefficients {

  2062.         /**
  2063.          * The U₁<sup>j</sup> coefficients.
  2064.          * <p>
  2065.          * The first index identifies the Fourier coefficients used<br>
  2066.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2067.          * S<sub>i</sub><sup>j</sup><br>
  2068.          * The only exception is when j = 0 when only the coefficient for fourier index
  2069.          * = 1 (i == 0) is needed.<br>
  2070.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are
  2071.          * computed, because are required to compute the coefficients U₂<sup>j</sup>
  2072.          * </p>
  2073.          */
  2074.         private final double[][] u1ij;

  2075.         /**
  2076.          * The V₁<sup>j</sup> coefficients.
  2077.          * <p>
  2078.          * The first index identifies the Fourier coefficients used<br>
  2079.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2080.          * S<sub>i</sub><sup>j</sup><br>
  2081.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed,
  2082.          * because are required to compute the coefficients V₂<sup>j</sup>
  2083.          * </p>
  2084.          */
  2085.         private final double[][] v1ij;

  2086.         /**
  2087.          * The U₂<sup>j</sup> coefficients.
  2088.          * <p>
  2089.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2090.          * they are the only ones required.
  2091.          * </p>
  2092.          */
  2093.         private final double[] u2ij;

  2094.         /**
  2095.          * The V₂<sup>j</sup> coefficients.
  2096.          * <p>
  2097.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2098.          * they are the only ones required.
  2099.          * </p>
  2100.          */
  2101.         private final double[] v2ij;

  2102.         /**
  2103.          * The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub>
  2104.          * coefficients.
  2105.          */
  2106.         private final double[][] currentRhoSigmaj;

  2107.         /**
  2108.          * The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier
  2109.          * coefficients.
  2110.          */
  2111.         private final FourierCjSjCoefficients fourierCjSj;

  2112.         /** The maximum value for j index. */
  2113.         private final int jMax;

  2114.         /**
  2115.          * Constructor.
  2116.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  2117.          *                         σ<sub>j</sub> coefficients
  2118.          * @param fourierCjSj      the fourier coefficients C<sub>i</sub><sup>j</sup>
  2119.          *                         and the S<sub>i</sub><sup>j</sup>
  2120.          * @param jMax             maximum value for j index
  2121.          */
  2122.         UijVijCoefficients(final double[][] currentRhoSigmaj, final FourierCjSjCoefficients fourierCjSj,
  2123.                 final int jMax) {
  2124.             this.currentRhoSigmaj = currentRhoSigmaj;
  2125.             this.fourierCjSj = fourierCjSj;
  2126.             this.jMax = jMax;

  2127.             // initialize the internal arrays.
  2128.             this.u1ij = new double[6][2 * jMax + 1];
  2129.             this.v1ij = new double[6][2 * jMax + 1];
  2130.             this.u2ij = new double[jMax + 1];
  2131.             this.v2ij = new double[jMax + 1];

  2132.             // compute the coefficients
  2133.             computeU1V1Coefficients();
  2134.             computeU2V2Coefficients();
  2135.         }

  2136.         /** Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients. */
  2137.         private void computeU1V1Coefficients() {
  2138.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2139.             // for j >= 1
  2140.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2141.             u1ij[0][0] = 0;
  2142.             for (int j = 1; j <= jMax; j++) {
  2143.                 // compute 1 / j
  2144.                 final double ooj = 1. / j;

  2145.                 for (int i = 0; i < 6; i++) {
  2146.                     // j is aready between 1 and J
  2147.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2148.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2149.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2150.                     if (j > 1) {
  2151.                         // k starts with 1 because j-J is less than or equal to 0
  2152.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2153.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2154.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2155.                             u1ij[i][j] += fourierCjSj.getCij(i, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2156.                                     fourierCjSj.getSij(i, j - kIndex) * currentRhoSigmaj[0][kIndex];

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

  2163.                     // since j must be between 1 and J-1 and is already between 1 and J
  2164.                     // the following sum is skiped only for j = jMax
  2165.                     if (j != jMax) {
  2166.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2167.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2168.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2169.                             u1ij[i][j] += -fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[1][kIndex] +
  2170.                                     fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[0][kIndex];

  2171.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2172.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2173.                             v1ij[i][j] += fourierCjSj.getCij(i, j + kIndex) * currentRhoSigmaj[0][kIndex] +
  2174.                                     fourierCjSj.getSij(i, j + kIndex) * currentRhoSigmaj[1][kIndex];
  2175.                         }
  2176.                     }

  2177.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2178.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2179.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2180.                         u1ij[i][j] += -fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2181.                                 fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2182.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2183.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2184.                         v1ij[i][j] += fourierCjSj.getCij(i, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2185.                                 fourierCjSj.getSij(i, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2186.                     }

  2187.                     // divide by 1 / j
  2188.                     u1ij[i][j] *= -ooj;
  2189.                     v1ij[i][j] *= ooj;

  2190.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2191.                     if (i == 0) {
  2192.                         // - (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2193.                         u1ij[0][0] += -u1ij[0][j] * currentRhoSigmaj[0][j] - v1ij[0][j] * currentRhoSigmaj[1][j];
  2194.                     }
  2195.                 }
  2196.             }

  2197.             // Terms with j > jMax are required only when computing the coefficients
  2198.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2199.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2200.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2201.                 // compute 1 / j
  2202.                 final double ooj = 1. / j;
  2203.                 // the value of i is 0
  2204.                 u1ij[0][j] = 0.;
  2205.                 v1ij[0][j] = 0.;

  2206.                 // k starts from j-J as it is always greater than or equal to 1
  2207.                 for (int kIndex = j - jMax; kIndex <= j - 1; kIndex++) {
  2208.                     // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2209.                     // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2210.                     u1ij[0][j] += fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[1][kIndex] +
  2211.                             fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[0][kIndex];

  2212.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2213.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2214.                     v1ij[0][j] += fourierCjSj.getCij(0, j - kIndex) * currentRhoSigmaj[0][kIndex] -
  2215.                             fourierCjSj.getSij(0, j - kIndex) * currentRhoSigmaj[1][kIndex];
  2216.                 }
  2217.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2218.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2219.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2220.                     u1ij[0][j] += -fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[1][j + kIndex] -
  2221.                             fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[0][j + kIndex];

  2222.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2223.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2224.                     v1ij[0][j] += fourierCjSj.getCij(0, kIndex) * currentRhoSigmaj[0][j + kIndex] +
  2225.                             fourierCjSj.getSij(0, kIndex) * currentRhoSigmaj[1][j + kIndex];
  2226.                 }

  2227.                 // divide by 1 / j
  2228.                 u1ij[0][j] *= -ooj;
  2229.                 v1ij[0][j] *= ooj;
  2230.             }
  2231.         }

  2232.         /**
  2233.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2234.          * <p>
  2235.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2236.          * </p>
  2237.          */
  2238.         private void computeU2V2Coefficients() {
  2239.             for (int j = 1; j <= jMax; j++) {
  2240.                 // compute 1 / j
  2241.                 final double ooj = 1. / j;

  2242.                 // only the values for i == 0 are computed
  2243.                 u2ij[j] = v1ij[0][j];
  2244.                 v2ij[j] = u1ij[0][j];

  2245.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2246.                 if (j > 1) {
  2247.                     for (int l = 1; l <= j - 1; l++) {
  2248.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2249.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2250.                         u2ij[j] += u1ij[0][j - l] * currentRhoSigmaj[1][l] + v1ij[0][j - l] * currentRhoSigmaj[0][l];

  2251.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2252.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2253.                         v2ij[j] += u1ij[0][j - l] * currentRhoSigmaj[0][l] - v1ij[0][j - l] * currentRhoSigmaj[1][l];
  2254.                     }
  2255.                 }

  2256.                 for (int l = 1; l <= jMax; l++) {
  2257.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2258.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2259.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2260.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2261.                     u2ij[j] += -u1ij[0][j + l] * currentRhoSigmaj[1][l] + u1ij[0][l] * currentRhoSigmaj[1][j + l] +
  2262.                             v1ij[0][j + l] * currentRhoSigmaj[0][l] - v1ij[0][l] * currentRhoSigmaj[0][j + l];

  2263.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2264.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2265.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2266.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2267.                     u2ij[j] += u1ij[0][j + l] * currentRhoSigmaj[0][l] + u1ij[0][l] * currentRhoSigmaj[0][j + l] +
  2268.                             v1ij[0][j + l] * currentRhoSigmaj[1][l] + v1ij[0][l] * currentRhoSigmaj[1][j + l];
  2269.                 }

  2270.                 // divide by 1 / j
  2271.                 u2ij[j] *= -ooj;
  2272.                 v2ij[j] *= ooj;
  2273.             }
  2274.         }

  2275.         /**
  2276.          * Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2277.          *
  2278.          * @param j j index
  2279.          * @param i Fourier index (starts at 0)
  2280.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2281.          */
  2282.         public double getU1(final int j, final int i) {
  2283.             return u1ij[i][j];
  2284.         }

  2285.         /**
  2286.          * Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2287.          *
  2288.          * @param j j index
  2289.          * @param i Fourier index (starts at 0)
  2290.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2291.          */
  2292.         public double getV1(final int j, final int i) {
  2293.             return v1ij[i][j];
  2294.         }

  2295.         /**
  2296.          * Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2297.          *
  2298.          * @param j j index
  2299.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2300.          */
  2301.         public double getU2(final int j) {
  2302.             return u2ij[j];
  2303.         }

  2304.         /**
  2305.          * Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2306.          *
  2307.          * @param j j index
  2308.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2309.          */
  2310.         public double getV2(final int j) {
  2311.             return v2ij[j];
  2312.         }
  2313.     }

  2314.     /**
  2315.      * The U<sub>i</sub><sup>j</sup> and V<sub>i</sub><sup>j</sup> coefficients
  2316.      * described by equations 2.5.3-(21) and 2.5.3-(22) from Danielson.
  2317.      * <p>
  2318.      * The index i takes only the values 1 and 2<br>
  2319.      * For U only the index 0 for j is used.
  2320.      * </p>
  2321.      *
  2322.      * @author Petre Bazavan
  2323.      * @author Lucian Barbulescu
  2324.      * @param <T> type of the field elements
  2325.      */
  2326.     protected static class FieldUijVijCoefficients<T extends CalculusFieldElement<T>> {

  2327.         /**
  2328.          * The U₁<sup>j</sup> coefficients.
  2329.          * <p>
  2330.          * The first index identifies the Fourier coefficients used<br>
  2331.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2332.          * S<sub>i</sub><sup>j</sup><br>
  2333.          * The only exception is when j = 0 when only the coefficient for fourier index
  2334.          * = 1 (i == 0) is needed.<br>
  2335.          * Also, for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are
  2336.          * computed, because are required to compute the coefficients U₂<sup>j</sup>
  2337.          * </p>
  2338.          */
  2339.         private final T[][] u1ij;

  2340.         /**
  2341.          * The V₁<sup>j</sup> coefficients.
  2342.          * <p>
  2343.          * The first index identifies the Fourier coefficients used<br>
  2344.          * Those coefficients are computed for all Fourier C<sub>i</sub><sup>j</sup> and
  2345.          * S<sub>i</sub><sup>j</sup><br>
  2346.          * for fourier index = 1 (i == 0), the coefficients up to 2 * jMax are computed,
  2347.          * because are required to compute the coefficients V₂<sup>j</sup>
  2348.          * </p>
  2349.          */
  2350.         private final T[][] v1ij;

  2351.         /**
  2352.          * The U₂<sup>j</sup> coefficients.
  2353.          * <p>
  2354.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2355.          * they are the only ones required.
  2356.          * </p>
  2357.          */
  2358.         private final T[] u2ij;

  2359.         /**
  2360.          * The V₂<sup>j</sup> coefficients.
  2361.          * <p>
  2362.          * Only the coefficients that use the Fourier index = 1 (i == 0) are computed as
  2363.          * they are the only ones required.
  2364.          * </p>
  2365.          */
  2366.         private final T[] v2ij;

  2367.         /**
  2368.          * The current computed values for the ρ<sub>j</sub> and σ<sub>j</sub>
  2369.          * coefficients.
  2370.          */
  2371.         private final T[][] currentRhoSigmaj;

  2372.         /**
  2373.          * The C<sub>i</sub><sup>j</sup> and the S<sub>i</sub><sup>j</sup> Fourier
  2374.          * coefficients.
  2375.          */
  2376.         private final FieldFourierCjSjCoefficients<T> fourierCjSj;

  2377.         /** The maximum value for j index. */
  2378.         private final int jMax;

  2379.         /**
  2380.          * Constructor.
  2381.          * @param currentRhoSigmaj the current computed values for the ρ<sub>j</sub> and
  2382.          *                         σ<sub>j</sub> coefficients
  2383.          * @param fourierCjSj      the fourier coefficients C<sub>i</sub><sup>j</sup>
  2384.          *                         and the S<sub>i</sub><sup>j</sup>
  2385.          * @param jMax             maximum value for j index
  2386.          * @param field            field used by default
  2387.          */
  2388.         FieldUijVijCoefficients(final T[][] currentRhoSigmaj, final FieldFourierCjSjCoefficients<T> fourierCjSj,
  2389.                 final int jMax, final Field<T> field) {
  2390.             this.currentRhoSigmaj = currentRhoSigmaj;
  2391.             this.fourierCjSj = fourierCjSj;
  2392.             this.jMax = jMax;

  2393.             // initialize the internal arrays.
  2394.             this.u1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2395.             this.v1ij = MathArrays.buildArray(field, 6, 2 * jMax + 1);
  2396.             this.u2ij = MathArrays.buildArray(field, jMax + 1);
  2397.             this.v2ij = MathArrays.buildArray(field, jMax + 1);

  2398.             // compute the coefficients
  2399.             computeU1V1Coefficients(field);
  2400.             computeU2V2Coefficients();
  2401.         }

  2402.         /**
  2403.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2404.          * @param field field used by default
  2405.          */
  2406.         private void computeU1V1Coefficients(final Field<T> field) {
  2407.             // Zero
  2408.             final T zero = field.getZero();

  2409.             // generate the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients
  2410.             // for j >= 1
  2411.             // also the U₁⁰ for Fourier index = 1 (i == 0) coefficient will be computed
  2412.             u1ij[0][0] = zero;
  2413.             for (int j = 1; j <= jMax; j++) {
  2414.                 // compute 1 / j
  2415.                 final double ooj = 1. / j;

  2416.                 for (int i = 0; i < 6; i++) {
  2417.                     // j is aready between 1 and J
  2418.                     u1ij[i][j] = fourierCjSj.getSij(i, j);
  2419.                     v1ij[i][j] = fourierCjSj.getCij(i, j);

  2420.                     // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2421.                     if (j > 1) {
  2422.                         // k starts with 1 because j-J is less than or equal to 0
  2423.                         for (int kIndex = 1; kIndex <= j - 1; kIndex++) {
  2424.                             // C<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub> +
  2425.                             // S<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub>
  2426.                             u1ij[i][j] = u1ij[i][j]
  2427.                                     .add(fourierCjSj.getCij(i, j - kIndex).multiply(currentRhoSigmaj[1][kIndex]).add(
  2428.                                             fourierCjSj.getSij(i, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])));

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

  2436.                     // since j must be between 1 and J-1 and is already between 1 and J
  2437.                     // the following sum is skiped only for j = jMax
  2438.                     if (j != jMax) {
  2439.                         for (int kIndex = 1; kIndex <= jMax - j; kIndex++) {
  2440.                             // -C<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub> +
  2441.                             // S<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub>
  2442.                             u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, j + kIndex).negate()
  2443.                                     .multiply(currentRhoSigmaj[1][kIndex])
  2444.                                     .add(fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex])));

  2445.                             // C<sub>i</sub><sup>j+k</sup> * ρ<sub>k</sub> +
  2446.                             // S<sub>i</sub><sup>j+k</sup> * σ<sub>k</sub>
  2447.                             v1ij[i][j] = v1ij[i][j]
  2448.                                     .add(fourierCjSj.getCij(i, j + kIndex).multiply(currentRhoSigmaj[0][kIndex]).add(
  2449.                                             fourierCjSj.getSij(i, j + kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2450.                         }
  2451.                     }

  2452.                     for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2453.                         // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2454.                         // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2455.                         u1ij[i][j] = u1ij[i][j].add(fourierCjSj.getCij(i, kIndex).negate()
  2456.                                 .multiply(currentRhoSigmaj[1][j + kIndex])
  2457.                                 .subtract(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2458.                         // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2459.                         // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2460.                         v1ij[i][j] = v1ij[i][j]
  2461.                                 .add(fourierCjSj.getCij(i, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])
  2462.                                         .add(fourierCjSj.getSij(i, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2463.                     }

  2464.                     // divide by 1 / j
  2465.                     u1ij[i][j] = u1ij[i][j].multiply(-ooj);
  2466.                     v1ij[i][j] = v1ij[i][j].multiply(ooj);

  2467.                     // if index = 1 (i == 0) add the computed terms to U₁⁰
  2468.                     if (i == 0) {
  2469.                         // - (U₁<sup>j</sup> * ρ<sub>j</sub> + V₁<sup>j</sup> * σ<sub>j</sub>
  2470.                         u1ij[0][0] = u1ij[0][0].add(u1ij[0][j].negate().multiply(currentRhoSigmaj[0][j])
  2471.                                 .subtract(v1ij[0][j].multiply(currentRhoSigmaj[1][j])));
  2472.                     }
  2473.                 }
  2474.             }

  2475.             // Terms with j > jMax are required only when computing the coefficients
  2476.             // U₂<sup>j</sup> and V₂<sup>j</sup>
  2477.             // and those coefficients are only required for Fourier index = 1 (i == 0).
  2478.             for (int j = jMax + 1; j <= 2 * jMax; j++) {
  2479.                 // compute 1 / j
  2480.                 final double ooj = 1. / j;
  2481.                 // the value of i is 0
  2482.                 u1ij[0][j] = zero;
  2483.                 v1ij[0][j] = zero;

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

  2490.                     // C<sub>i</sub><sup>j-k</sup> * ρ<sub>k</sub> -
  2491.                     // S<sub>i</sub><sup>j-k</sup> * σ<sub>k</sub>
  2492.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, j - kIndex).multiply(currentRhoSigmaj[0][kIndex])
  2493.                             .subtract(fourierCjSj.getSij(0, j - kIndex).multiply(currentRhoSigmaj[1][kIndex])));
  2494.                 }
  2495.                 for (int kIndex = 1; kIndex <= jMax; kIndex++) {
  2496.                     // C<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub> -
  2497.                     // S<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub>
  2498.                     u1ij[0][j] = u1ij[0][j]
  2499.                             .add(fourierCjSj.getCij(0, kIndex).negate().multiply(currentRhoSigmaj[1][j + kIndex])
  2500.                                     .subtract(fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])));

  2501.                     // C<sub>i</sub><sup>k</sup> * ρ<sub>j+k</sub> +
  2502.                     // S<sub>i</sub><sup>k</sup> * σ<sub>j+k</sub>
  2503.                     v1ij[0][j] = v1ij[0][j].add(fourierCjSj.getCij(0, kIndex).multiply(currentRhoSigmaj[0][j + kIndex])
  2504.                             .add(fourierCjSj.getSij(0, kIndex).multiply(currentRhoSigmaj[1][j + kIndex])));
  2505.                 }

  2506.                 // divide by 1 / j
  2507.                 u1ij[0][j] = u1ij[0][j].multiply(-ooj);
  2508.                 v1ij[0][j] = v1ij[0][j].multiply(ooj);
  2509.             }
  2510.         }

  2511.         /**
  2512.          * Build the U₁<sup>j</sup> and V₁<sup>j</sup> coefficients.
  2513.          * <p>
  2514.          * Only the coefficients for Fourier index = 1 (i == 0) are required.
  2515.          * </p>
  2516.          */
  2517.         private void computeU2V2Coefficients() {
  2518.             for (int j = 1; j <= jMax; j++) {
  2519.                 // compute 1 / j
  2520.                 final double ooj = 1. / j;

  2521.                 // only the values for i == 0 are computed
  2522.                 u2ij[j] = v1ij[0][j];
  2523.                 v2ij[j] = u1ij[0][j];

  2524.                 // 1 - δ<sub>1j</sub> is 1 for all j > 1
  2525.                 if (j > 1) {
  2526.                     for (int l = 1; l <= j - 1; l++) {
  2527.                         // U₁<sup>j-l</sup> * σ<sub>l</sub> +
  2528.                         // V₁<sup>j-l</sup> * ρ<sub>l</sub>
  2529.                         u2ij[j] = u2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[1][l])
  2530.                                 .add(v1ij[0][j - l].multiply(currentRhoSigmaj[0][l])));

  2531.                         // U₁<sup>j-l</sup> * ρ<sub>l</sub> -
  2532.                         // V₁<sup>j-l</sup> * σ<sub>l</sub>
  2533.                         v2ij[j] = v2ij[j].add(u1ij[0][j - l].multiply(currentRhoSigmaj[0][l])
  2534.                                 .subtract(v1ij[0][j - l].multiply(currentRhoSigmaj[1][l])));
  2535.                     }
  2536.                 }

  2537.                 for (int l = 1; l <= jMax; l++) {
  2538.                     // -U₁<sup>j+l</sup> * σ<sub>l</sub> +
  2539.                     // U₁<sup>l</sup> * σ<sub>j+l</sub> +
  2540.                     // V₁<sup>j+l</sup> * ρ<sub>l</sub> -
  2541.                     // V₁<sup>l</sup> * ρ<sub>j+l</sub>
  2542.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].negate().multiply(currentRhoSigmaj[1][l])
  2543.                             .add(u1ij[0][l].multiply(currentRhoSigmaj[1][j + l]))
  2544.                             .add(v1ij[0][j + l].multiply(currentRhoSigmaj[0][l]))
  2545.                             .subtract(v1ij[0][l].multiply(currentRhoSigmaj[0][j + l])));

  2546.                     // U₁<sup>j+l</sup> * ρ<sub>l</sub> +
  2547.                     // U₁<sup>l</sup> * ρ<sub>j+l</sub> +
  2548.                     // V₁<sup>j+l</sup> * σ<sub>l</sub> +
  2549.                     // V₁<sup>l</sup> * σ<sub>j+l</sub>
  2550.                     u2ij[j] = u2ij[j].add(u1ij[0][j + l].multiply(currentRhoSigmaj[0][l])
  2551.                             .add(u1ij[0][l].multiply(currentRhoSigmaj[0][j + l]))
  2552.                             .add(v1ij[0][j + l].multiply(currentRhoSigmaj[1][l]))
  2553.                             .add(v1ij[0][l].multiply(currentRhoSigmaj[1][j + l])));
  2554.                 }

  2555.                 // divide by 1 / j
  2556.                 u2ij[j] = u2ij[j].multiply(-ooj);
  2557.                 v2ij[j] = v2ij[j].multiply(ooj);
  2558.             }
  2559.         }

  2560.         /**
  2561.          * Get the coefficient U₁<sup>j</sup> for Fourier index i.
  2562.          *
  2563.          * @param j j index
  2564.          * @param i Fourier index (starts at 0)
  2565.          * @return the coefficient U₁<sup>j</sup> for the given Fourier index i
  2566.          */
  2567.         public T getU1(final int j, final int i) {
  2568.             return u1ij[i][j];
  2569.         }

  2570.         /**
  2571.          * Get the coefficient V₁<sup>j</sup> for Fourier index i.
  2572.          *
  2573.          * @param j j index
  2574.          * @param i Fourier index (starts at 0)
  2575.          * @return the coefficient V₁<sup>j</sup> for the given Fourier index i
  2576.          */
  2577.         public T getV1(final int j, final int i) {
  2578.             return v1ij[i][j];
  2579.         }

  2580.         /**
  2581.          * Get the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2582.          *
  2583.          * @param j j index
  2584.          * @return the coefficient U₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2585.          */
  2586.         public T getU2(final int j) {
  2587.             return u2ij[j];
  2588.         }

  2589.         /**
  2590.          * Get the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0).
  2591.          *
  2592.          * @param j j index
  2593.          * @return the coefficient V₂<sup>j</sup> for Fourier index = 1 (i == 0)
  2594.          */
  2595.         public T getV2(final int j) {
  2596.             return v2ij[j];
  2597.         }
  2598.     }

  2599.     /** Coefficients valid for one time slot. */
  2600.     protected static class Slot {

  2601.         /**
  2602.          * The coefficients D<sub>i</sub><sup>j</sup>.
  2603.          * <p>
  2604.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2605.          * i corresponds to the equinoctial element, as follows: - i=0 for a <br/>
  2606.          * - i=1 for k <br/>
  2607.          * - i=2 for h <br/>
  2608.          * - i=3 for q <br/>
  2609.          * - i=4 for p <br/>
  2610.          * - i=5 for λ <br/>
  2611.          * </p>
  2612.          */
  2613.         private final ShortPeriodicsInterpolatedCoefficient[] dij;

  2614.         /**
  2615.          * The coefficients C<sub>i</sub><sup>j</sup>.
  2616.          * <p>
  2617.          * The index order is cij[j][i] <br/>
  2618.          * i corresponds to the equinoctial element, as follows: <br/>
  2619.          * - i=0 for a <br/>
  2620.          * - i=1 for k <br/>
  2621.          * - i=2 for h <br/>
  2622.          * - i=3 for q <br/>
  2623.          * - i=4 for p <br/>
  2624.          * - i=5 for λ <br/>
  2625.          * </p>
  2626.          */
  2627.         private final ShortPeriodicsInterpolatedCoefficient[] cij;

  2628.         /**
  2629.          * The coefficients S<sub>i</sub><sup>j</sup>.
  2630.          * <p>
  2631.          * The index order is sij[j][i] <br/>
  2632.          * i corresponds to the equinoctial element, as follows: <br/>
  2633.          * - i=0 for a <br/>
  2634.          * - i=1 for k <br/>
  2635.          * - i=2 for h <br/>
  2636.          * - i=3 for q <br/>
  2637.          * - i=4 for p <br/>
  2638.          * - i=5 for λ <br/>
  2639.          * </p>
  2640.          */
  2641.         private final ShortPeriodicsInterpolatedCoefficient[] sij;

  2642.         /**
  2643.          * Simple constructor.
  2644.          * @param jMax                maximum value for j index
  2645.          * @param interpolationPoints number of points used in the interpolation process
  2646.          */
  2647.         Slot(final int jMax, final int interpolationPoints) {

  2648.             dij = new ShortPeriodicsInterpolatedCoefficient[3];
  2649.             cij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];
  2650.             sij = new ShortPeriodicsInterpolatedCoefficient[jMax + 1];

  2651.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and
  2652.             // D<sub>i</sub><sup>j</sup> coefficients
  2653.             for (int j = 0; j <= jMax; j++) {
  2654.                 cij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2655.                 if (j > 0) {
  2656.                     sij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2657.                 }
  2658.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2659.                 if (j == 1 || j == 2) {
  2660.                     dij[j] = new ShortPeriodicsInterpolatedCoefficient(interpolationPoints);
  2661.                 }
  2662.             }

  2663.         }

  2664.     }

  2665.     /** Coefficients valid for one time slot.
  2666.      * @param <T> type of the field elements
  2667.      */
  2668.     protected static class FieldSlot<T extends CalculusFieldElement<T>> {

  2669.         /**
  2670.          * The coefficients D<sub>i</sub><sup>j</sup>.
  2671.          * <p>
  2672.          * Only for j = 1 and j = 2 the coefficients are not 0. <br>
  2673.          * i corresponds to the equinoctial element, as follows: - 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>[] dij;

  2682.         /**
  2683.          * The coefficients C<sub>i</sub><sup>j</sup>.
  2684.          * <p>
  2685.          * The index order is cij[j][i] <br/>
  2686.          * i corresponds to the equinoctial element, as follows: <br/>
  2687.          * - i=0 for a <br/>
  2688.          * - i=1 for k <br/>
  2689.          * - i=2 for h <br/>
  2690.          * - i=3 for q <br/>
  2691.          * - i=4 for p <br/>
  2692.          * - i=5 for λ <br/>
  2693.          * </p>
  2694.          */
  2695.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] cij;

  2696.         /**
  2697.          * The coefficients S<sub>i</sub><sup>j</sup>.
  2698.          * <p>
  2699.          * The index order is sij[j][i] <br/>
  2700.          * i corresponds to the equinoctial element, as follows: <br/>
  2701.          * - i=0 for a <br/>
  2702.          * - i=1 for k <br/>
  2703.          * - i=2 for h <br/>
  2704.          * - i=3 for q <br/>
  2705.          * - i=4 for p <br/>
  2706.          * - i=5 for λ <br/>
  2707.          * </p>
  2708.          */
  2709.         private final FieldShortPeriodicsInterpolatedCoefficient<T>[] sij;

  2710.         /**
  2711.          * Simple constructor.
  2712.          * @param jMax                maximum value for j index
  2713.          * @param interpolationPoints number of points used in the interpolation process
  2714.          */
  2715.         @SuppressWarnings("unchecked")
  2716.         FieldSlot(final int jMax, final int interpolationPoints) {

  2717.             dij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2718.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, 3);
  2719.             cij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2720.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);
  2721.             sij = (FieldShortPeriodicsInterpolatedCoefficient<T>[]) Array
  2722.                     .newInstance(FieldShortPeriodicsInterpolatedCoefficient.class, jMax + 1);

  2723.             // Initialize the C<sub>i</sub><sup>j</sup>, S<sub>i</sub><sup>j</sup> and
  2724.             // D<sub>i</sub><sup>j</sup> coefficients
  2725.             for (int j = 0; j <= jMax; j++) {
  2726.                 cij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2727.                 if (j > 0) {
  2728.                     sij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2729.                 }
  2730.                 // Initialize only the non-zero D<sub>i</sub><sup>j</sup> coefficients
  2731.                 if (j == 1 || j == 2) {
  2732.                     dij[j] = new FieldShortPeriodicsInterpolatedCoefficient<>(interpolationPoints);
  2733.                 }
  2734.             }

  2735.         }

  2736.     }

  2737. }