1   /* Copyright 2022-2025 Romain Serra
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.maneuvers;
18  
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.time.FieldAbsoluteDate;
25  
26  /** Interface providing velocity increment vectors to impulsive maneuvers (Field version).
27   *
28   * @author Romain Serra
29   * @see ImpulseProvider
30   * @see FieldImpulseManeuver
31   * @since 13.0
32   */
33  public interface FieldImpulseProvider<T extends CalculusFieldElement<T>> {
34  
35      /**
36       * Method returning the impulse to be applied (Field version).
37       * @param state state before the maneuver is applied if {@code isForward} is true, after otherwise
38       * @param isForward flag on propagation direction
39       * @return impulse in satellite's frame
40       */
41      FieldVector3D<T> getImpulse(FieldSpacecraftState<T> state, boolean isForward);
42  
43      /**
44       * Method called at start of propagation.
45       * @param initialState state at start of propagation
46       * @param targetDate target end date
47       */
48      default void init(FieldSpacecraftState<T> initialState, FieldAbsoluteDate<T> targetDate) {
49          // nothing by default
50      }
51  
52      /**
53       * Method called at end of propagation.
54       * @param finalState state at end of propagation
55       */
56      default void finish(FieldSpacecraftState<T> finalState) {
57          // nothing by default
58      }
59  
60      /**
61       * Get a provider returning a given vector for forward propagation and its opposite for backward.
62       * @param forwardImpulse forward impulse vector
63       * @param <T> field type
64       * @return constant provider
65       */
66      static <T extends CalculusFieldElement<T>> FieldImpulseProvider<T> of(final FieldVector3D<T> forwardImpulse) {
67          return (state, isForward) -> isForward ? forwardImpulse : forwardImpulse.negate();
68      }
69  
70      /**
71       * Get a provider returning a given vector for forward propagation and its opposite for backward.
72       * @param forwardImpulse forward impulse vector
73       * @param field field
74       * @param <T> field type
75       * @return constant provider
76       */
77      static <T extends CalculusFieldElement<T>> FieldImpulseProvider<T> of(final Field<T> field,
78                                                                            final Vector3D forwardImpulse) {
79          return of(new FieldVector3D<>(field, forwardImpulse));
80      }
81  
82      /**
83       * Get a provider from a non-Field version.
84       * @param impulseProvider impulse provider
85       * @param <T> field type
86       * @return provider
87       */
88      static <T extends CalculusFieldElement<T>> FieldImpulseProvider<T> of(final ImpulseProvider impulseProvider) {
89          return (state, isForward) -> {
90              final Vector3D deltaV = impulseProvider.getImpulse(state.toSpacecraftState(), isForward);
91              return new FieldVector3D<>(state.getDate().getField(), deltaV);
92          };
93      }
94  }