BoundedCartesianEnergy.java

  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.control.indirect.adjoint.cost;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.propagation.events.EventDetectionSettings;
  20. import org.orekit.propagation.events.EventDetector;

  21. import java.util.stream.Stream;

  22. /**
  23.  * Class for bounded energy cost with Cartesian coordinates.
  24.  * An energy cost is proportional to the integral over time of the squared Euclidean norm of the control vector, often scaled with 1/2.
  25.  * This type of cost is not optimal in terms of mass consumption, however its solutions showcase a smoother behavior favorable for convergence in shooting techniques.
  26.  * Here, the control vector is chosen as the thrust force divided by the maximum thrust magnitude and expressed in the propagation frame.
  27.  *
  28.  * @author Romain Serra
  29.  * @see UnboundedCartesianEnergy
  30.  * @since 12.2
  31.  */
  32. public class BoundedCartesianEnergy extends CartesianEnergyConsideringMass {

  33.     /** Maximum value of thrust force Euclidean norm. */
  34.     private final double maximumThrustMagnitude;

  35.     /**
  36.      * Constructor.
  37.      * @param name name
  38.      * @param massFlowRateFactor mass flow rate factor
  39.      * @param maximumThrustMagnitude maximum thrust magnitude
  40.      * @param eventDetectionSettings singularity event detection settings
  41.      */
  42.     public BoundedCartesianEnergy(final String name, final double massFlowRateFactor,
  43.                                   final double maximumThrustMagnitude,
  44.                                   final EventDetectionSettings eventDetectionSettings) {
  45.         super(name, massFlowRateFactor, eventDetectionSettings);
  46.         this.maximumThrustMagnitude = FastMath.abs(maximumThrustMagnitude);
  47.     }

  48.     /**
  49.      * Constructor.
  50.      * @param name name
  51.      * @param massFlowRateFactor mass flow rate factor
  52.      * @param maximumThrustMagnitude maximum thrust magnitude
  53.      */
  54.     public BoundedCartesianEnergy(final String name, final double massFlowRateFactor,
  55.                                   final double maximumThrustMagnitude) {
  56.         this(name, massFlowRateFactor, maximumThrustMagnitude, EventDetectionSettings.getDefaultEventDetectionSettings());
  57.     }

  58.     /** Getter for maximum thrust magnitude.
  59.      * @return maximum thrust
  60.      * @since 13.0
  61.      */
  62.     public double getMaximumThrustMagnitude() {
  63.         return maximumThrustMagnitude;
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     protected double getThrustForceNorm(final double[] adjointVariables, final double mass) {
  68.         final double adjointVelocityNorm = getAdjointVelocityNorm(adjointVariables);
  69.         double factor = adjointVelocityNorm / mass;
  70.         if (getAdjointDimension() > 6) {
  71.             factor -= getMassFlowRateFactor() * adjointVariables[6];
  72.         }
  73.         if (factor > maximumThrustMagnitude) {
  74.             return maximumThrustMagnitude;
  75.         } else {
  76.             return FastMath.max(0., factor);
  77.         }
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public Stream<EventDetector> getEventDetectors() {
  82.         return Stream.of(new SingularityDetector(getEventDetectionSettings(), 0.),
  83.                 new SingularityDetector(getEventDetectionSettings(), maximumThrustMagnitude));
  84.     }
  85. }