CartesianFlightDurationCost.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.geometry.euclidean.threed.Vector3D;

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

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

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

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

  54.     /**
  55.      * {@inheritDoc}
  56.      */
  57.     @Override
  58.     public Vector3D getThrustAccelerationVector(final double[] adjointVariables, final double mass) {
  59.         return new Vector3D(adjointVariables[3], adjointVariables[4], adjointVariables[5]).normalize()
  60.                 .scalarMultiply(maximumThrustMagnitude);
  61.     }

  62.     /**
  63.      * {@inheritDoc}
  64.      */
  65.     @Override
  66.     public void updateAdjointDerivatives(final double[] adjointVariables, final double mass,
  67.                                          final double[] adjointDerivatives) {
  68.         if (getAdjointDimension() > 6) {
  69.             adjointDerivatives[6] += getAdjointVelocityNorm(adjointVariables) * maximumThrustMagnitude / (mass * mass);
  70.         }
  71.     }

  72.     /**
  73.      * {@inheritDoc}
  74.      */
  75.     @Override
  76.     public double getHamiltonianContribution(final double[] adjointVariables, final double mass) {
  77.         return -1.;
  78.     }
  79. }