ForceModel.java

  1. /* Copyright 2002-2025 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.stream.Stream;

  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.Field;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.orekit.propagation.FieldSpacecraftState;
  24. import org.orekit.propagation.SpacecraftState;
  25. import org.orekit.propagation.events.EventDetector;
  26. import org.orekit.propagation.events.EventDetectorsProvider;
  27. import org.orekit.propagation.events.FieldEventDetector;
  28. import org.orekit.propagation.numerical.FieldTimeDerivativesEquations;
  29. import org.orekit.propagation.numerical.TimeDerivativesEquations;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.utils.ParameterDriversProvider;

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

  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.     /** {@inheritDoc}.*/
  93.     @Override
  94.     default Stream<EventDetector> getEventDetectors() {
  95.         return getEventDetectors(getParametersDrivers());
  96.     }

  97.     /** {@inheritDoc}.*/
  98.     @Override
  99.     default <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventDetectors(Field<T> field) {
  100.         return getFieldEventDetectors(field, getParametersDrivers());
  101.     }

  102.     /** Compute the contribution of the force model to the perturbing
  103.      * acceleration.
  104.      * <p>
  105.      * The default implementation simply adds the {@link #acceleration(SpacecraftState, double[]) acceleration}
  106.      * as a non-Keplerian acceleration.
  107.      * </p>
  108.      * @param s current state information: date, kinematics, attitude
  109.      * @param adder object where the contribution should be added
  110.      */
  111.     default void addContribution(SpacecraftState s, TimeDerivativesEquations adder) {
  112.         final double[] parameters = getParameters(s.getDate());
  113.         adder.addNonKeplerianAcceleration(acceleration(s, getParameters(s.getDate())));
  114.         adder.addMassDerivative(getMassDerivative(s, parameters));
  115.     }

  116.     /** Compute the contribution of the force model to the perturbing
  117.      * acceleration.
  118.      * @param s current state information: date, kinematics, attitude
  119.      * @param adder object where the contribution should be added
  120.      * @param <T> type of the elements
  121.      */
  122.     default <T extends CalculusFieldElement<T>> void addContribution(FieldSpacecraftState<T> s, FieldTimeDerivativesEquations<T> adder) {
  123.         final T[] parameters = getParameters(s.getDate().getField(), s.getDate());
  124.         adder.addNonKeplerianAcceleration(acceleration(s, parameters));
  125.         adder.addMassDerivative(getMassDerivative(s, parameters));
  126.     }

  127.     /**
  128.      * Compute the mass rate. Zero by default.
  129.      * @param state current state information: date, kinematics, attitude
  130.      * @param parameters values of the force model parameters at state date
  131.      * @return mass rate (kg/s)
  132.      * @since 13.1
  133.      */
  134.     default double getMassDerivative(SpacecraftState state, double[] parameters) {
  135.         return 0.;
  136.     }

  137.     /**
  138.      * Compute the mass rate. Zero by default.
  139.      * @param <T> field type
  140.      * @param state current state information: date, kinematics, attitude
  141.      * @param parameters values of the force model parameters at state date
  142.      * @return mass rate (kg/s)
  143.      * @since 13.1
  144.      */
  145.     default <T extends CalculusFieldElement<T>> T getMassDerivative(FieldSpacecraftState<T> state, T[] parameters) {
  146.         return state.getMass().getField().getZero();
  147.     }

  148.     /** Check if force model depends on position only at a given, fixed date.
  149.      * @return true if force model depends on position only, false
  150.      * if it depends on velocity, either directly or due to a dependency
  151.      * on attitude
  152.      * @since 9.0
  153.      */
  154.     boolean dependsOnPositionOnly();

  155.     /** Check if force model depends on attitude's rotation rate or acceleration at a given, fixed date.
  156.      * If false, it essentially means that at most the attitude's rotation is used when computing the acceleration vector.
  157.      * The default implementation returns false as common forces do not.
  158.      * @return true if force model depends on attitude derivatives
  159.      * @since 12.1
  160.      */
  161.     default boolean dependsOnAttitudeRate() {
  162.         return false;
  163.     }

  164.     /** Compute acceleration.
  165.      * @param s current state information: date, kinematics, attitude
  166.      * @param parameters values of the force model parameters at state date,
  167.      * only 1 value for each parameterDriver
  168.      * @return acceleration in same frame as state
  169.      * @since 9.0
  170.      */
  171.     Vector3D acceleration(SpacecraftState s, double[] parameters);

  172.     /** Compute acceleration.
  173.      * @param s current state information: date, kinematics, attitude
  174.      * @param parameters values of the force model parameters at state date,
  175.      * only 1 value for each parameterDriver
  176.      * @return acceleration in same frame as state
  177.      * @param <T> type of the elements
  178.      * @since 9.0
  179.      */
  180.     <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters);
  181. }