DSSTForceModel.java

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

  18. import java.util.List;
  19. import java.util.stream.Stream;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.Field;
  22. import org.hipparchus.util.MathArrays;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.propagation.FieldSpacecraftState;
  25. import org.orekit.propagation.PropagationType;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.events.EventDetector;
  28. import org.orekit.propagation.events.EventDetectorsProvider;
  29. import org.orekit.propagation.events.FieldEventDetector;
  30. import org.orekit.propagation.integration.AbstractGradientConverter;
  31. import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
  32. import org.orekit.propagation.semianalytical.dsst.utilities.FieldAuxiliaryElements;
  33. import org.orekit.time.AbsoluteDate;
  34. import org.orekit.time.FieldAbsoluteDate;
  35. import org.orekit.utils.ParameterDriver;
  36. import org.orekit.utils.ParameterDriversProvider;
  37. import org.orekit.utils.TimeSpanMap.Span;

  38. /** This interface represents a force modifying spacecraft motion for a {@link
  39.  *  org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSSTPropagator}.
  40.  *  <p>
  41.  *  Objects implementing this interface are intended to be added to a {@link
  42.  *  org.orekit.propagation.semianalytical.dsst.DSSTPropagator DSST propagator}
  43.  *  before the propagation is started.
  44.  *  </p>
  45.  *  <p>
  46.  *  The propagator will call at the very beginning of a propagation the {@link
  47.  *  #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])} method allowing
  48.  *  preliminary computation such as truncation if needed.
  49.  *  </p>
  50.  *  <p>
  51.  *  Then the propagator will call at each step:
  52.  *  <ol>
  53.  *  <li>the {@link #getMeanElementRate(SpacecraftState, AuxiliaryElements, double[])} method.
  54.  *  The force model instance will extract all the state data needed to compute
  55.  *  the mean element rates that contribute to the mean state derivative.</li>
  56.  *  <li>the {@link #updateShortPeriodTerms(double[], SpacecraftState...)} method,
  57.  *  if osculating parameters are desired, on a sample of points within the
  58.  *  last step.</li>
  59.  *  </ol>
  60.  *
  61.  * @author Romain Di Constanzo
  62.  * @author Pascal Parraud
  63.  */
  64. public interface DSSTForceModel extends ParameterDriversProvider, EventDetectorsProvider {

  65.     /**
  66.      * Initialize the force model at the start of propagation.
  67.      * <p> The default implementation of this method does nothing.</p>
  68.      *
  69.      * @param initialState spacecraft state at the start of propagation.
  70.      * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
  71.      * @since 11.0
  72.      */
  73.     default void init(SpacecraftState initialState, AbsoluteDate target) {
  74.     }

  75.     /**
  76.      * Initialize the force model at the start of propagation.
  77.      * <p> The default implementation of this method does nothing.</p>
  78.      *
  79.      * @param initialState spacecraft state at the start of propagation.
  80.      * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
  81.      * @param <T> type of the elements
  82.      * @since 11.1
  83.      */
  84.     default <T extends CalculusFieldElement<T>> void init(FieldSpacecraftState<T> initialState, FieldAbsoluteDate<T> target) {
  85.         init(initialState.toSpacecraftState(), target.toAbsoluteDate());
  86.     }

  87.     /** {@inheritDoc}.*/
  88.     @Override
  89.     default Stream<EventDetector> getEventDetectors() {
  90.         return getEventDetectors(getParametersDrivers());
  91.     }

  92.     /** {@inheritDoc}.*/
  93.     @Override
  94.     default <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventDetectors(Field<T> field) {
  95.         return getFieldEventDetectors(field, getParametersDrivers());
  96.     }

  97.     /** Performs initialization prior to propagation for the current force model.
  98.      *  <p>
  99.      *  This method aims at being called at the very beginning of a propagation.
  100.      *  </p>
  101.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  102.      *  @param type type of the elements used during the propagation
  103.      *  @param parameters values of the force model parameters for specific date
  104.      *  (1 value only per parameter driver) obtained for example by calling
  105.      *  {@link #getParameters(AbsoluteDate)} on force model.
  106.      *  @return a list of objects that will hold short period terms (the objects
  107.      *  are also retained by the force model, which will update them during propagation)
  108.      */
  109.     List<ShortPeriodTerms> initializeShortPeriodTerms(AuxiliaryElements auxiliaryElements,
  110.                                                       PropagationType type, double[] parameters);

  111.     /** Performs initialization prior to propagation for the current force model.
  112.      *  <p>
  113.      *  This method aims at being called at the very beginning of a propagation.
  114.      *  </p>
  115.      *  @param <T> type of the elements
  116.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  117.      *  @param type type of the elements used during the propagation
  118.      *  @param parameters values of the force model parameters for specific date
  119.      *  (1 value only per parameter driver) obtained for example by calling
  120.      *  {@link #getParameters(AbsoluteDate)} on force model or
  121.      *  {@link AbstractGradientConverter#getParametersAtStateDate(FieldSpacecraftState, ParameterDriversProvider)}
  122.      *  on gradient converter.
  123.      *  @return a list of objects that will hold short period terms (the objects
  124.      *  are also retained by the force model, which will update them during propagation)
  125.      */
  126.     <T extends CalculusFieldElement<T>> List<FieldShortPeriodTerms<T>> initializeShortPeriodTerms(FieldAuxiliaryElements<T> auxiliaryElements,
  127.                                                                                                   PropagationType type, T[] parameters);

  128.     /** Extract the proper parameter drivers' values from the array in input of the
  129.      * {@link #updateShortPeriodTerms(double[], SpacecraftState...) updateShortPeriodTerms} method.
  130.      *  Parameters are filtered given an input date.
  131.      * @param parameters the input parameters array containing all span values of all drivers
  132.      * from which the parameter values at date date wants to be extracted
  133.      * @param date the date
  134.      * @return the parameters given the date
  135.      */
  136.     default double[] extractParameters(final double[] parameters, final AbsoluteDate date) {

  137.         // Find out the indexes of the parameters in the whole array of parameters
  138.         final List<ParameterDriver> allParameters = getParametersDrivers();
  139.         final double[] outParameters = new double[allParameters.size()];
  140.         int index = 0;
  141.         int paramIndex = 0;
  142.         for (int i = 0; i < allParameters.size(); i++) {
  143.             final ParameterDriver driver = allParameters.get(i);
  144.             final String driverNameforDate = driver.getNameSpan(date);
  145.             // Loop on the spans
  146.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  147.                 // Add all the parameter drivers of the span
  148.                 if (span.getData().equals(driverNameforDate)) {
  149.                     outParameters[index++] = parameters[paramIndex];
  150.                 }
  151.                 paramIndex++;
  152.             }
  153.         }
  154.         return outParameters;
  155.     }

  156.     /** Extract the proper parameter drivers' values from the array in input of the
  157.      * {@link #updateShortPeriodTerms(CalculusFieldElement[], FieldSpacecraftState...)
  158.      * updateShortPeriodTerms} method. Parameters are filtered given an input date.
  159.      * @param parameters the input parameters array containing all span values of all drivers
  160.      * from which the parameter values at date date wants to be extracted
  161.      * @param date the date
  162.      * @param <T> extends CalculusFieldElement
  163.      * @return the parameters given the date
  164.      */
  165.     default <T extends CalculusFieldElement<T>> T[] extractParameters(final T[] parameters,
  166.                                                                       final FieldAbsoluteDate<T> date) {

  167.         // Find out the indexes of the parameters in the whole array of parameters
  168.         final List<ParameterDriver> allParameters = getParametersDrivers();
  169.         final T[] outParameters = MathArrays.buildArray(date.getField(), allParameters.size());
  170.         int index = 0;
  171.         int paramIndex = 0;
  172.         for (int i = 0; i < allParameters.size(); i++) {
  173.             final ParameterDriver driver = allParameters.get(i);
  174.             final String driverNameforDate = driver.getNameSpan(date.toAbsoluteDate());
  175.             // Loop on the spans
  176.             for (Span<String> span = driver.getNamesSpanMap().getFirstSpan(); span != null; span = span.next()) {
  177.                 // Add all the parameter drivers of the span
  178.                 if (span.getData().equals(driverNameforDate)) {
  179.                     outParameters[index++] = parameters[paramIndex];
  180.                 }
  181.                 ++paramIndex;
  182.             }
  183.         }
  184.         return outParameters;
  185.     }


  186.     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  187.      *
  188.      *  @param state current state information: date, kinematics, attitude
  189.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  190.      *  @param parameters values of the force model parameters at state date (only 1 span for
  191.      *  each parameter driver) obtained for example by calling {@link #getParameters(AbsoluteDate)}
  192.      *  on force model.
  193.      *  @return the mean element rates dai/dt
  194.      */
  195.     double[] getMeanElementRate(SpacecraftState state,
  196.                                 AuxiliaryElements auxiliaryElements, double[] parameters);

  197.     /** Computes the mean equinoctial elements rates da<sub>i</sub> / dt.
  198.      *
  199.      *  @param <T> type of the elements
  200.      *  @param state current state information: date, kinematics, attitude
  201.      *  @param auxiliaryElements auxiliary elements related to the current orbit
  202.      *  @param parameters values of the force model parameters at state date (only 1 span for
  203.      *  each parameter driver) obtained for example by calling {@link #getParameters(Field, FieldAbsoluteDate)}
  204.      *  on force model  or
  205.      *  {@link AbstractGradientConverter#getParametersAtStateDate(FieldSpacecraftState, ParameterDriversProvider)}
  206.      *  on gradient converter.
  207.      *  @return the mean element rates dai/dt
  208.      */
  209.     <T extends CalculusFieldElement<T>> T[] getMeanElementRate(FieldSpacecraftState<T> state,
  210.                                                                FieldAuxiliaryElements<T> auxiliaryElements, T[] parameters);

  211.     /** Register an attitude provider.
  212.      * <p>
  213.      * Register an attitude provider that can be used by the force model.
  214.      * </p>
  215.      * @param provider the {@link AttitudeProvider}
  216.      */
  217.     void registerAttitudeProvider(AttitudeProvider provider);

  218.     /** Update the short period terms.
  219.      * <p>
  220.      * The {@link ShortPeriodTerms short period terms} that will be updated
  221.      * are the ones that were returned during the call to {@link
  222.      * #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])}.
  223.      * </p>
  224.      * @param parameters values of the force model parameters (all span values for each parameters)
  225.      * obtained for example by calling
  226.      * {@link #getParametersAllValues()}
  227.      * on force model. The extract parameter method {@link #extractParameters(double[], AbsoluteDate)} is called in
  228.      * the method to select the right parameter corresponding to the mean state date.
  229.      * @param meanStates mean states information: date, kinematics, attitude
  230.      */
  231.     void updateShortPeriodTerms(double[] parameters, SpacecraftState... meanStates);

  232.     /** Update the short period terms.
  233.      * <p>
  234.      * The {@link ShortPeriodTerms short period terms} that will be updated
  235.      * are the ones that were returned during the call to {@link
  236.      * #initializeShortPeriodTerms(AuxiliaryElements, PropagationType, double[])}.
  237.      * </p>
  238.      * @param <T> type of the elements
  239.      * @param parameters values of the force model parameters (all span values for each parameters)
  240.      * obtained for example by calling {@link #getParametersAllValues(Field)} on force model or
  241.      *  {@link AbstractGradientConverter#getParameters(FieldSpacecraftState, ParameterDriversProvider)}
  242.      *  on gradient converter. The extract parameter method
  243.      *  {@link #extractParameters(CalculusFieldElement[], FieldAbsoluteDate)} is called in
  244.      * the method to select the right parameter.
  245.      * @param meanStates mean states information: date, kinematics, attitude
  246.      */
  247.     @SuppressWarnings("unchecked")
  248.     <T extends CalculusFieldElement<T>> void updateShortPeriodTerms(T[] parameters, FieldSpacecraftState<T>... meanStates);

  249. }