1   /* Copyright 2022-2026 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.control.heuristics;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.forces.maneuvers.FieldImpulseProvider;
23  import org.orekit.propagation.FieldSpacecraftState;
24  
25  /**
26   * Abstract class modelling impulsive, in-plane maneuvers.
27   * The impulse vector is computed in the same frame as the orbit. The instantaneous orbital plane is left unchanged.
28   * A constraint on the maximum magnitude can be optionally set.
29   * @see AbstractInPlaneImpulseProvider
30   * @see org.orekit.forces.maneuvers.FieldImpulseManeuver
31   * @param <T> type of the field element
32   * @author Romain Serra
33   * @since 14.0
34   */
35  public abstract class FieldAbstractInPlaneImpulseProvider<T extends CalculusFieldElement<T>> implements FieldImpulseProvider<T> {
36  
37      /** Maximum impulse magnitude. */
38      private final T maximumMagnitude;
39  
40      /**
41       * Constructor.
42       * @param maximumMagnitude maximum magnitude
43       */
44      protected FieldAbstractInPlaneImpulseProvider(final T maximumMagnitude) {
45          this.maximumMagnitude = FastMath.abs(maximumMagnitude);
46      }
47  
48      /**
49       * Getter for the maximum impulse's magnitude.
50       * @return maximum magnitude
51       */
52      public T getMaximumMagnitude() {
53          return maximumMagnitude;
54      }
55  
56      @Override
57      public FieldVector3D<T> getImpulse(final FieldSpacecraftState<T> state, final boolean isForward) {
58          final FieldVector3D<T> impulse = getUnconstrainedImpulse(state, isForward);
59          if (impulse.getNorm2().getReal() > maximumMagnitude.getReal()) {
60              return impulse.normalize().scalarMultiply(maximumMagnitude);
61          }
62          return impulse;
63      }
64  
65      /**
66       * Compute the impulse without magnitude constraint.
67       * @param state state immediately before (or after in backward time) the maneuver
68       * @param isForward flag on propagation direction
69       * @return impulse vector
70       */
71      protected abstract FieldVector3D<T> getUnconstrainedImpulse(FieldSpacecraftState<T> state, boolean isForward);
72  }