ForceModel.java

  1. /* Copyright 2002-2022 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.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.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.MathArrays;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.events.EventDetector;
  28. import org.orekit.propagation.events.FieldEventDetector;
  29. import org.orekit.propagation.numerical.FieldTimeDerivativesEquations;
  30. import org.orekit.propagation.numerical.TimeDerivativesEquations;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.ParameterDriver;

  34. /** This interface represents a force modifying spacecraft motion.
  35.  *
  36.  * <p>
  37.  * Objects implementing this interface are intended to be added to a
  38.  * {@link org.orekit.propagation.numerical.NumericalPropagator numerical propagator}
  39.  * before the propagation is started.
  40.  *
  41.  * <p>
  42.  * The propagator will call at each step the {@link #addContribution(SpacecraftState,
  43.  * TimeDerivativesEquations)} method. The force model instance will extract all the
  44.  * state data it needs (date, position, velocity, frame, attitude, mass) from the first
  45.  * parameter. From these state data, it will compute the perturbing acceleration. It
  46.  * will then add this acceleration to the second parameter which will take thins
  47.  * contribution into account and will use the Gauss equations to evaluate its impact
  48.  * on the global state derivative.
  49.  * </p>
  50.  * <p>
  51.  * Force models which create discontinuous acceleration patterns (typically for maneuvers
  52.  * start/stop or solar eclipses entry/exit) must provide one or more {@link
  53.  * org.orekit.propagation.events.EventDetector events detectors} to the
  54.  * propagator thanks to their {@link #getEventsDetectors()} method. This method
  55.  * is called once just before propagation starts. The events states will be checked by
  56.  * the propagator to ensure accurate propagation and proper events handling.
  57.  * </p>
  58.  *
  59.  * @author Mathieu Rom&eacute;ro
  60.  * @author Luc Maisonobe
  61.  * @author V&eacute;ronique Pommier-Maurussane
  62.  */
  63. public interface ForceModel {

  64.     /**
  65.      * Initialize the force model at the start of propagation. This method will be called
  66.      * before any calls to {@link #addContribution(SpacecraftState, TimeDerivativesEquations)},
  67.      * {@link #addContribution(FieldSpacecraftState, FieldTimeDerivativesEquations)},
  68.      * {@link #acceleration(SpacecraftState, double[])} or {@link #acceleration(FieldSpacecraftState, CalculusFieldElement[])}
  69.      *
  70.      * <p> The default implementation of this method does nothing.</p>
  71.      *
  72.      * @param initialState spacecraft state at the start of propagation.
  73.      * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
  74.      */
  75.     default void init(SpacecraftState initialState, AbsoluteDate target) {
  76.     }

  77.     /**
  78.      * Initialize the force model at the start of propagation. This method will be called
  79.      * before any calls to {@link #addContribution(SpacecraftState, TimeDerivativesEquations)},
  80.      * {@link #addContribution(FieldSpacecraftState, FieldTimeDerivativesEquations)},
  81.      * {@link #acceleration(SpacecraftState, double[])} or {@link #acceleration(FieldSpacecraftState, CalculusFieldElement[])}
  82.      *
  83.      * <p> The default implementation of this method does nothing.</p>
  84.      *
  85.      * @param initialState spacecraft state at the start of propagation.
  86.      * @param target       date of propagation. Not equal to {@code initialState.getDate()}.
  87.      * @param <T> type of the elements
  88.      */
  89.     default <T extends CalculusFieldElement<T>> void init(FieldSpacecraftState<T> initialState, FieldAbsoluteDate<T> target) {
  90.         init(initialState.toSpacecraftState(), target.toAbsoluteDate());
  91.     }

  92.     /** Compute the contribution of the force model to the perturbing
  93.      * acceleration.
  94.      * <p>
  95.      * The default implementation simply adds the {@link #acceleration(SpacecraftState, double[]) acceleration}
  96.      * as a non-Keplerian acceleration.
  97.      * </p>
  98.      * @param s current state information: date, kinematics, attitude
  99.      * @param adder object where the contribution should be added
  100.      */
  101.     default void addContribution(SpacecraftState s, TimeDerivativesEquations adder) {
  102.         adder.addNonKeplerianAcceleration(acceleration(s, getParameters()));
  103.     }

  104.     /** Compute the contribution of the force model to the perturbing
  105.      * acceleration.
  106.      * @param s current state information: date, kinematics, attitude
  107.      * @param adder object where the contribution should be added
  108.      * @param <T> type of the elements
  109.      */
  110.     default <T extends CalculusFieldElement<T>> void addContribution(FieldSpacecraftState<T> s, FieldTimeDerivativesEquations<T> adder) {
  111.         adder.addNonKeplerianAcceleration(acceleration(s, getParameters(s.getDate().getField())));
  112.     }

  113.     /** Get force model parameters.
  114.      * @return force model parameters
  115.      * @since 9.0
  116.      */
  117.     default double[] getParameters() {
  118.         final List<ParameterDriver> drivers = getParametersDrivers();
  119.         final double[] parameters = new double[drivers.size()];
  120.         for (int i = 0; i < drivers.size(); ++i) {
  121.             parameters[i] = drivers.get(i).getValue();
  122.         }
  123.         return parameters;
  124.     }

  125.     /** Get force model parameters.
  126.      * @param field field to which the elements belong
  127.      * @param <T> type of the elements
  128.      * @return force model parameters
  129.      * @since 9.0
  130.      */
  131.     default <T extends CalculusFieldElement<T>> T[] getParameters(final Field<T> field) {
  132.         final List<ParameterDriver> drivers = getParametersDrivers();
  133.         final T[] parameters = MathArrays.buildArray(field, drivers.size());
  134.         for (int i = 0; i < drivers.size(); ++i) {
  135.             parameters[i] = field.getZero().add(drivers.get(i).getValue());
  136.         }
  137.         return parameters;
  138.     }

  139.     /** Check if force models depends on position only.
  140.      * @return true if force model depends on position only, false
  141.      * if it depends on velocity, either directly or due to a dependency
  142.      * on attitude
  143.      * @since 9.0
  144.      */
  145.     boolean dependsOnPositionOnly();

  146.     /** Compute acceleration.
  147.      * @param s current state information: date, kinematics, attitude
  148.      * @param parameters values of the force model parameters
  149.      * @return acceleration in same frame as state
  150.      * @since 9.0
  151.      */
  152.     Vector3D acceleration(SpacecraftState s, double[] parameters);

  153.     /** Compute acceleration.
  154.      * @param s current state information: date, kinematics, attitude
  155.      * @param parameters values of the force model parameters
  156.      * @return acceleration in same frame as state
  157.      * @param <T> type of the elements
  158.      * @since 9.0
  159.      */
  160.     <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters);

  161.     /** Get the discrete events related to the model.
  162.      * @return stream of events detectors
  163.      */
  164.     Stream<EventDetector> getEventsDetectors();

  165.     /** Get the discrete events related to the model.
  166.      * @param field field to which the state belongs
  167.      * @param <T> extends CalculusFieldElement&lt;T&gt;
  168.      * @return stream of events detectors
  169.      */
  170.     <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(Field<T> field);

  171.     /** Get the drivers for force model parameters.
  172.      * @return drivers for force model parameters
  173.      * @since 8.0
  174.      */
  175.     List<ParameterDriver> getParametersDrivers();

  176.     /** Get parameter value from its name.
  177.      * @param name parameter name
  178.      * @return parameter value
  179.      * @since 8.0
  180.      */
  181.     ParameterDriver getParameterDriver(String name);

  182.     /** Check if a parameter is supported.
  183.      * <p>Supported parameters are those listed by {@link #getParametersDrivers()}.</p>
  184.      * @param name parameter name to check
  185.      * @return true if the parameter is supported
  186.      * @see #getParametersDrivers()
  187.      */
  188.     boolean isSupported(String name);

  189. }