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.orbits.FieldOrbit;
23  import org.orekit.propagation.FieldSpacecraftState;
24  
25  /**
26   * Class modelling impulsive maneuvers to set the osculating semi-major axis to a given value.
27   * The impulse vector is tangential and computed in the same frame as the orbit.
28   * The resulting osculating eccentricity depends on the execution location. The instantaneous orbital plane is left unchanged.
29   * A constraint on the maximum magnitude can be optionally set.
30   * @see FieldAbstractInPlaneImpulseProvider
31   * @see OsculatingSmaChangeImpulseProvider
32   * @param <T> type of the field element
33   * @author Romain Serra
34   * @since 14.0
35   */
36  public class FieldSmaChangingImpulseProvider<T extends CalculusFieldElement<T>> extends FieldAbstractInPlaneImpulseProvider<T> {
37  
38      /** Target osculating semi-major axis. */
39      private final T targetSemiMajorAxis;
40  
41      /**
42       * Constructor with default maximum magnitude set to positive infinity (unconstrained).
43       * @param targetSemiMajorAxis osculating value to achieve
44       */
45      public FieldSmaChangingImpulseProvider(final T targetSemiMajorAxis) {
46          this(targetSemiMajorAxis.getField().getZero().newInstance(Double.POSITIVE_INFINITY), targetSemiMajorAxis);
47      }
48  
49      /**
50       * Constructor.
51       * @param maximumMagnitude maximum magnitude
52       * @param targetSemiMajorAxis osculating value to achieve
53       */
54      public FieldSmaChangingImpulseProvider(final T maximumMagnitude, final T targetSemiMajorAxis) {
55          super(maximumMagnitude);
56          this.targetSemiMajorAxis = targetSemiMajorAxis;
57      }
58  
59      @Override
60      public FieldVector3D<T> getUnconstrainedImpulse(final FieldSpacecraftState<T> state, final boolean isForward) {
61          final FieldOrbit<T> orbit = state.getOrbit();
62          final FieldVector3D<T> position = orbit.getPosition();
63          final FieldVector3D<T> velocity = orbit.getVelocity();
64          final T mu = orbit.getMu();
65          final T targetEnergy = mu.negate().divide(targetSemiMajorAxis.multiply(2));
66          final T targetSpeed = FastMath.sqrt((targetEnergy.add(mu.divide(position.getNorm2()))).multiply(2));
67          return velocity.normalize().scalarMultiply(targetSpeed.subtract(velocity.getNorm2()));
68      }
69  }