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   * @author Romain Serra
32   * @since 14.0
33   */
34  public abstract class FieldAbstractInPlaneImpulseProvider<T extends CalculusFieldElement<T>> implements FieldImpulseProvider<T> {
35  
36      /** Maximum impulse magnitude. */
37      private final T maximumMagnitude;
38  
39      /**
40       * Constructor.
41       * @param maximumMagnitude maximum magnitude
42       */
43      protected FieldAbstractInPlaneImpulseProvider(final T maximumMagnitude) {
44          this.maximumMagnitude = FastMath.abs(maximumMagnitude);
45      }
46  
47      /**
48       * Getter for the maximum impulse's magnitude.
49       * @return maximum magnitude
50       */
51      public T getMaximumMagnitude() {
52          return maximumMagnitude;
53      }
54  
55      @Override
56      public FieldVector3D<T> getImpulse(final FieldSpacecraftState<T> state, final boolean isForward) {
57          final FieldVector3D<T> impulse = getUnconstrainedImpulse(state, isForward);
58          if (impulse.getNorm2().getReal() > maximumMagnitude.getReal()) {
59              return impulse.normalize().scalarMultiply(maximumMagnitude);
60          }
61          return impulse;
62      }
63  
64      /**
65       * Compute the impulse without magnitude constraint.
66       * @param state state immediately before (or after in backward time) the maneuver
67       * @param isForward flag on propagation direction
68       * @return impulse vector
69       */
70      protected abstract FieldVector3D<T> getUnconstrainedImpulse(FieldSpacecraftState<T> state, boolean isForward);
71  }