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

  21. /**
  22.  * Fuel cost penalized with a logarithmic term, which is a barrier so is not defined for epsilon equal to 0 or 1.
  23.  *
  24.  * @author Romain Serra
  25.  * @since 13.0
  26.  */
  27. public class FieldLogarithmicBarrierCartesianFuel<T extends CalculusFieldElement<T>>
  28.         extends FieldPenalizedCartesianFuelCost<T> {

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

  41.     /** {@inheritDoc} */
  42.     @Override
  43.     public T evaluateFieldPenaltyFunction(final T controlNorm) {
  44.         return FastMath.log(controlNorm).add(FastMath.log(controlNorm.negate().add(1)));
  45.     }

  46.     /** {@inheritDoc} */
  47.     @Override
  48.     public FieldVector3D<T> getFieldThrustAccelerationVector(final T[] adjointVariables, final T mass) {
  49.         final T thrustForceMagnitude = getThrustForceMagnitude(adjointVariables, mass);
  50.         return getFieldThrustDirection(adjointVariables).scalarMultiply(thrustForceMagnitude.divide(mass));
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public void updateFieldAdjointDerivatives(final T[] adjointVariables, final T mass, final T[] adjointDerivatives) {
  55.         if (getAdjointDimension() > 6) {
  56.             adjointDerivatives[6] = adjointDerivatives[6].add(getFieldAdjointVelocityNorm(adjointVariables)
  57.                     .multiply(getThrustForceMagnitude(adjointVariables, mass)).divide(mass.square()));
  58.         }
  59.     }

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

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     public LogarithmicBarrierCartesianFuel toCartesianCost() {
  78.         return new LogarithmicBarrierCartesianFuel(getAdjointName(), getMassFlowRateFactor().getReal(),
  79.                 getMaximumThrustMagnitude().getReal(), getEpsilon().getReal());
  80.     }
  81. }