AbstractCartesianCost.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.util.FastMath;

  20. /**
  21.  * Abstract class for cost with Cartesian coordinates.
  22.  *
  23.  * @author Romain Serra
  24.  * @see CartesianCost
  25.  * @since 13.0
  26.  */
  27. public abstract class AbstractCartesianCost implements CartesianCost {

  28.     /** Name of adjoint vector. */
  29.     private final String name;

  30.     /** Mass flow rate factor (always positive). */
  31.     private final double massFlowRateFactor;

  32.     /** Dimension of adjoint vector. */
  33.     private final int adjointDimension;

  34.     /**
  35.      * Constructor.
  36.      * @param name name
  37.      * @param massFlowRateFactor mass flow rate factor
  38.      */
  39.     protected AbstractCartesianCost(final String name, final double massFlowRateFactor) {
  40.         this.name = name;
  41.         this.massFlowRateFactor = FastMath.abs(massFlowRateFactor);
  42.         this.adjointDimension = this.massFlowRateFactor == 0. ? 6 : 7;
  43.     }

  44.     /**
  45.      * {@inheritDoc}
  46.      */
  47.     @Override
  48.     public int getAdjointDimension() {
  49.         return adjointDimension;
  50.     }

  51.     /**
  52.      * Getter for adjoint vector name.
  53.      * @return name
  54.      */
  55.     @Override
  56.     public String getAdjointName() {
  57.         return name;
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public double getMassFlowRateFactor() {
  62.         return massFlowRateFactor;
  63.     }

  64.     /**
  65.      * Computes the Euclidean norm of the adjoint velocity vector.
  66.      * @param adjointVariables adjoint vector
  67.      * @return norm of adjoint velocity
  68.      */
  69.     protected double getAdjointVelocityNorm(final double[] adjointVariables) {
  70.         return FastMath.sqrt(adjointVariables[3] * adjointVariables[3] + adjointVariables[4] * adjointVariables[4] + adjointVariables[5] * adjointVariables[5]);
  71.     }

  72.     /**
  73.      * Computes the Euclidean norm of the adjoint velocity vector.
  74.      * @param adjointVariables adjoint vector
  75.      * @param <T> field type
  76.      * @return norm of adjoint velocity
  77.      */
  78.     protected <T extends CalculusFieldElement<T>> T getFieldAdjointVelocityNorm(final T[] adjointVariables) {
  79.         return FastMath.sqrt(adjointVariables[3].square().add(adjointVariables[4].square()).add(adjointVariables[5].square()));
  80.     }
  81. }