FieldCartesianFlightDurationCost.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.geometry.euclidean.threed.FieldVector3D;

  20. /**
  21.  * Class for minimizing the flight duration (a.k.a. time of flight) with Cartesian coordinates.
  22.  * It is the integral over time of the constant one. The control is assumed to be bounded.
  23.  * It also assumes that no external acceleration depends on mass.
  24.  * If the mass flow rate factor is zero, then there is no adjoint for the mass.
  25.  *
  26.  * @author Romain Serra
  27.  * @see CartesianCost
  28.  * @see CartesianFlightDurationCost
  29.  * @since 13.0
  30.  */
  31. public class FieldCartesianFlightDurationCost<T extends CalculusFieldElement<T>> extends FieldAbstractCartesianCost<T> {

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

  36.     /**
  37.      * Constructor.
  38.      *
  39.      * @param name                   name
  40.      * @param massFlowRateFactor     mass flow rate factor
  41.      * @param maximumThrustMagnitude maximum thrust magnitude
  42.      */
  43.     public FieldCartesianFlightDurationCost(final String name, final T massFlowRateFactor, final T maximumThrustMagnitude) {
  44.         super(name, massFlowRateFactor);
  45.         this.maximumThrustMagnitude = maximumThrustMagnitude;
  46.     }

  47.     /**
  48.      * Getter for maximum thrust magnitude.
  49.      *
  50.      * @return maximum thrust
  51.      */
  52.     public T getMaximumThrustMagnitude() {
  53.         return maximumThrustMagnitude;
  54.     }

  55.     /**
  56.      * {@inheritDoc}
  57.      */
  58.     @Override
  59.     public FieldVector3D<T> getFieldThrustAccelerationVector(final T[] adjointVariables, final T mass) {
  60.         return new FieldVector3D<>(adjointVariables[3], adjointVariables[4], adjointVariables[5]).normalize()
  61.                 .scalarMultiply(maximumThrustMagnitude);
  62.     }

  63.     /**
  64.      * {@inheritDoc}
  65.      */
  66.     @Override
  67.     public void updateFieldAdjointDerivatives(final T[] adjointVariables, final T mass, final T[] adjointDerivatives) {
  68.         if (getAdjointDimension() > 6) {
  69.             adjointDerivatives[6] =  adjointDerivatives[6].add(getFieldAdjointVelocityNorm(adjointVariables)
  70.                     .multiply(maximumThrustMagnitude).divide(mass.square()));
  71.         }
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public T getFieldHamiltonianContribution(final T[] adjointVariables, final T mass) {
  76.         return mass.getField().getOne().newInstance(-1.);
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public CartesianFlightDurationCost toCartesianCost() {
  81.         return new CartesianFlightDurationCost(getAdjointName(), getMassFlowRateFactor().getReal(),
  82.                 getMaximumThrustMagnitude().getReal());
  83.     }
  84. }