LogarithmicBarrierCartesianFuel.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. import org.hipparchus.util.FastMath;

  20. /**
  21.  * Fuel cost penalized with a logarithmic term, which is a barrier so is not defined for epsilon equal to 0 or 1.
  22.  *
  23.  * @author Romain Serra
  24.  * @since 13.0
  25.  */
  26. public class LogarithmicBarrierCartesianFuel extends PenalizedCartesianFuelCost {

  27.     /**
  28.      * Constructor.
  29.      *
  30.      * @param name                   adjoint name
  31.      * @param massFlowRateFactor     mass flow rate factor
  32.      * @param maximumThrustMagnitude maximum thrust magnitude
  33.      * @param epsilon                penalty weight
  34.      */
  35.     public LogarithmicBarrierCartesianFuel(final String name, final double massFlowRateFactor,
  36.                                            final double maximumThrustMagnitude, final double epsilon) {
  37.         super(name, massFlowRateFactor, maximumThrustMagnitude, epsilon);
  38.     }

  39.     /** {@inheritDoc} */
  40.     @Override
  41.     public double evaluatePenaltyFunction(final double controlNorm) {
  42.         return FastMath.log(controlNorm) + FastMath.log(1. - controlNorm);
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public Vector3D getThrustAccelerationVector(final double[] adjointVariables, final double mass) {
  47.         final double thrustForceMagnitude = getThrustForceMagnitude(adjointVariables, mass);
  48.         return getThrustDirection(adjointVariables).scalarMultiply(thrustForceMagnitude / mass);
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public void updateAdjointDerivatives(final double[] adjointVariables, final double mass,
  53.                                          final double[] adjointDerivatives) {
  54.         if (getAdjointDimension() > 6) {
  55.             adjointDerivatives[6] += getAdjointVelocityNorm(adjointVariables) * getThrustForceMagnitude(adjointVariables,
  56.                     mass) / (mass * mass);
  57.         }
  58.     }

  59.     /**
  60.      * Computes the Euclidean norm of the thrust force.
  61.      * @param adjointVariables adjoint variables
  62.      * @param mass mass
  63.      * @return thrust force magnitude
  64.      */
  65.     private double getThrustForceMagnitude(final double[] adjointVariables, final double mass) {
  66.         final double twoEpsilon = getEpsilon() * 2;
  67.         double otherTerm = getAdjointVelocityNorm(adjointVariables) / mass - 1;
  68.         if (getAdjointDimension() > 6) {
  69.             otherTerm -= getMassFlowRateFactor() * adjointVariables[6];
  70.         }
  71.         return twoEpsilon * getMaximumThrustMagnitude() / (twoEpsilon + otherTerm + FastMath.sqrt(otherTerm * otherTerm + twoEpsilon * twoEpsilon));
  72.     }
  73. }