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. import org.orekit.utils.ParametersDriversProvider;

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

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

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

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

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

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

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

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

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

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

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

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

  172.     /** Get parameter value from its name.
  173.      * @param name parameter name
  174.      * @return parameter value
  175.      * @since 8.0
  176.      */
  177.     ParameterDriver getParameterDriver(String name);

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

  185. }