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