FieldUnboundedCartesianEnergy.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.orekit.propagation.events.EventDetectionSettings;
  21. import org.orekit.propagation.events.FieldEventDetectionSettings;
  22. import org.orekit.propagation.events.FieldEventDetector;

  23. import java.util.stream.Stream;

  24. /**
  25.  * Class for unbounded energy cost with Cartesian coordinates.
  26.  * Here, the control vector is chosen as the thrust force, expressed in the propagation frame.
  27.  * This leads to the optimal thrust being in the same direction as the adjoint velocity.
  28.  *
  29.  * @param <T> field type
  30.  * @author Romain Serra
  31.  * @see FieldUnboundedCartesianEnergyNeglectingMass
  32.  * @see UnboundedCartesianEnergy
  33.  * @since 13.0
  34.  */
  35. public class FieldUnboundedCartesianEnergy<T extends CalculusFieldElement<T>> extends FieldCartesianEnergyConsideringMass<T> {

  36.     /**
  37.      * Constructor.
  38.      * @param name name
  39.      * @param massFlowRateFactor mass flow rate factor
  40.      * @param eventDetectionSettings detection settings for singularity detections
  41.      */
  42.     public FieldUnboundedCartesianEnergy(final String name, final T massFlowRateFactor,
  43.                                          final FieldEventDetectionSettings<T> eventDetectionSettings) {
  44.         super(name, massFlowRateFactor, eventDetectionSettings);
  45.     }

  46.     /**
  47.      * Constructor.
  48.      * @param name name
  49.      * @param massFlowRateFactor mass flow rate factor
  50.      */
  51.     public FieldUnboundedCartesianEnergy(final String name, final T massFlowRateFactor) {
  52.         this(name, massFlowRateFactor, new FieldEventDetectionSettings<>(massFlowRateFactor.getField(),
  53.                 EventDetectionSettings.getDefaultEventDetectionSettings()));
  54.     }

  55.     /** {@inheritDoc} */
  56.     @Override
  57.     protected T getFieldThrustForceNorm(final T[] adjointVariables, final T mass) {
  58.         final T adjointVelocityNorm = getFieldAdjointVelocityNorm(adjointVariables);
  59.         T factor = adjointVelocityNorm.divide(mass);
  60.         if (getAdjointDimension() > 6) {
  61.             factor = factor.subtract(adjointVariables[6].multiply(getMassFlowRateFactor()));
  62.         }
  63.         if (factor.getReal() < 0.) {
  64.             return adjointVelocityNorm.getField().getZero();
  65.         } else {
  66.             return factor;
  67.         }
  68.     }

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public Stream<FieldEventDetector<T>> getFieldEventDetectors(final Field<T> field) {
  72.         return Stream.of(new FieldSingularityDetector(getEventDetectionSettings(), field.getZero()));
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public UnboundedCartesianEnergy toCartesianCost() {
  77.         return new UnboundedCartesianEnergy(getAdjointName(), getMassFlowRateFactor().getReal(),
  78.                 getEventDetectionSettings().toEventDetectionSettings());
  79.     }
  80. }