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

  21. /**
  22.  * Class for unbounded energy cost with Cartesian coordinates neglecting the mass consumption.
  23.  * Under this assumption, the mass is constant and there is no need to consider the corresponding adjoint variable.
  24.  * Here, the control vector is chosen as the acceleration given by thrusting, expressed in the propagation frame.
  25.  * This leads to the optimal thrust force being equal to the adjoint velocity vector times the mass.
  26.  *
  27.  * @param <T> field type
  28.  * @author Romain Serra
  29.  * @since 13.0
  30.  */
  31. public class FieldUnboundedCartesianEnergyNeglectingMass<T extends CalculusFieldElement<T>> implements FieldCartesianCost<T> {

  32.     /** Adjoint vector name. */
  33.     private final String name;

  34.     /** Field. */
  35.     private final Field<T> field;

  36.     /**
  37.      * Constructor.
  38.      * @param name name
  39.      * @param field field
  40.      */
  41.     public FieldUnboundedCartesianEnergyNeglectingMass(final String name, final Field<T> field) {
  42.         this.name = name;
  43.         this.field = field;
  44.     }

  45.     /**
  46.      * Getter for adjoint vector name.
  47.      * @return name
  48.      */
  49.     @Override
  50.     public String getAdjointName() {
  51.         return name;
  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     public int getAdjointDimension() {
  56.         return 6;
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public T getMassFlowRateFactor() {
  61.         return field.getZero();
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public FieldVector3D<T> getFieldThrustAccelerationVector(final T[] adjointVariables, final T mass) {
  66.         return new FieldVector3D<>(adjointVariables[3], adjointVariables[4], adjointVariables[5]);
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public void updateFieldAdjointDerivatives(final T[] adjointVariables, final T mass, final T[] adjointDerivatives) {
  71.         // nothing to do
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public T getFieldHamiltonianContribution(final T[] adjointVariables, final T mass) {
  76.         final FieldVector3D<T> thrustAcceleration = getFieldThrustAccelerationVector(adjointVariables, mass);
  77.         return thrustAcceleration.getNormSq().multiply(-1. / 2.);
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public UnboundedCartesianEnergyNeglectingMass toCartesianCost() {
  82.         return new UnboundedCartesianEnergyNeglectingMass(getAdjointName());
  83.     }
  84. }