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.         adder.addNonKeplerianAcceleration(acceleration(s, getParameters(s.getDate())));
  113.     }

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

  123.     /** Check if force model depends on position only at a given, fixed date.
  124.      * @return true if force model depends on position only, false
  125.      * if it depends on velocity, either directly or due to a dependency
  126.      * on attitude
  127.      * @since 9.0
  128.      */
  129.     boolean dependsOnPositionOnly();

  130.     /** Check if force model depends on attitude's rotation rate or acceleration at a given, fixed date.
  131.      * If false, it essentially means that at most the attitude's rotation is used when computing the acceleration vector.
  132.      * The default implementation returns false as common forces do not.
  133.      * @return true if force model depends on attitude derivatives
  134.      * @since 12.1
  135.      */
  136.     default boolean dependsOnAttitudeRate() {
  137.         return false;
  138.     }

  139.     /** Compute acceleration.
  140.      * @param s current state information: date, kinematics, attitude
  141.      * @param parameters values of the force model parameters at state date,
  142.      * only 1 value for each parameterDriver
  143.      * @return acceleration in same frame as state
  144.      * @since 9.0
  145.      */
  146.     Vector3D acceleration(SpacecraftState s, double[] parameters);

  147.     /** Compute acceleration.
  148.      * @param s current state information: date, kinematics, attitude
  149.      * @param parameters values of the force model parameters at state date,
  150.      * only 1 value for each parameterDriver
  151.      * @return acceleration in same frame as state
  152.      * @param <T> type of the elements
  153.      * @since 9.0
  154.      */
  155.     <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(FieldSpacecraftState<T> s, T[] parameters);
  156. }