FieldAbstractCartesianCost.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.  * @param <T> field type
  24.  * @author Romain Serra
  25.  * @see CartesianCost
  26.  * @since 13.0
  27.  */
  28. public abstract class FieldAbstractCartesianCost<T extends CalculusFieldElement<T>> implements FieldCartesianCost<T> {

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

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

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

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

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

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

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

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