FieldBoundedCartesianEnergy.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.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.propagation.events.EventDetectionSettings;
  22. import org.orekit.propagation.events.FieldEventDetectionSettings;
  23. import org.orekit.propagation.events.FieldEventDetector;

  24. import java.util.stream.Stream;

  25. /**
  26.  * Class for bounded energy cost with Cartesian coordinates.
  27.  * An energy cost is proportional to the integral over time of the squared Euclidean norm of the control vector, often scaled with 1/2.
  28.  * 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.
  29.  * Here, the control vector is chosen as the thrust force divided by the maximum thrust magnitude and expressed in the propagation frame.
  30.  *
  31.  * @param <T> field type
  32.  * @author Romain Serra
  33.  * @see FieldUnboundedCartesianEnergy
  34.  * @see BoundedCartesianEnergy
  35.  * @since 13.0
  36.  */
  37. public class FieldBoundedCartesianEnergy<T extends CalculusFieldElement<T>> extends FieldCartesianEnergyConsideringMass<T> {

  38.     /** Maximum value of thrust force Euclidean norm. */
  39.     private final T maximumThrustMagnitude;

  40.     /**
  41.      * Constructor.
  42.      * @param name name
  43.      * @param massFlowRateFactor mass flow rate factor
  44.      * @param maximumThrustMagnitude maximum thrust magnitude
  45.      * @param eventDetectionSettings singularity event detection settings
  46.      */
  47.     public FieldBoundedCartesianEnergy(final String name, final T massFlowRateFactor,
  48.                                        final T maximumThrustMagnitude,
  49.                                        final FieldEventDetectionSettings<T> eventDetectionSettings) {
  50.         super(name, massFlowRateFactor, eventDetectionSettings);
  51.         this.maximumThrustMagnitude = FastMath.abs(maximumThrustMagnitude);
  52.     }

  53.     /**
  54.      * Constructor.
  55.      * @param name name
  56.      * @param massFlowRateFactor mass flow rate factor
  57.      * @param maximumThrustMagnitude maximum thrust magnitude
  58.      */
  59.     public FieldBoundedCartesianEnergy(final String name, final T massFlowRateFactor,
  60.                                        final T maximumThrustMagnitude) {
  61.         this(name, massFlowRateFactor, maximumThrustMagnitude, new FieldEventDetectionSettings<>(massFlowRateFactor.getField(),
  62.                 EventDetectionSettings.getDefaultEventDetectionSettings()));
  63.     }

  64.     /** Getter for maximum thrust magnitude.
  65.      * @return maximum thrust
  66.      */
  67.     public T getMaximumThrustMagnitude() {
  68.         return maximumThrustMagnitude;
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     protected T getFieldThrustForceNorm(final T[] adjointVariables, final T mass) {
  73.         final T adjointVelocityNorm = getFieldAdjointVelocityNorm(adjointVariables);
  74.         T factor = adjointVelocityNorm.divide(mass);
  75.         if (getAdjointDimension() > 6) {
  76.             factor = factor.subtract(adjointVariables[6].multiply(getMassFlowRateFactor()));
  77.         }
  78.         final double factorReal = factor.getReal();
  79.         final T zero = mass.getField().getZero();
  80.         if (factorReal > maximumThrustMagnitude.getReal()) {
  81.             return maximumThrustMagnitude;
  82.         } else if (factorReal < 0.) {
  83.             return zero;
  84.         } else {
  85.             return factor;
  86.         }
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public Stream<FieldEventDetector<T>> getFieldEventDetectors(final Field<T> field) {
  91.         final T zero = field.getZero();
  92.         return Stream.of(new FieldSingularityDetector(getEventDetectionSettings(), zero),
  93.                 new FieldSingularityDetector(getEventDetectionSettings(), maximumThrustMagnitude));
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     public BoundedCartesianEnergy toCartesianCost() {
  98.         return new BoundedCartesianEnergy(getAdjointName(), getMassFlowRateFactor().getReal(),
  99.                 maximumThrustMagnitude.getReal(), getEventDetectionSettings().toEventDetectionSettings());
  100.     }

  101. }