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
19
20 import org.hipparchus.CalculusFieldElement;
21 import org.hipparchus.util.FastMath;
22
23 /**
24 * Abstract class for cost with Cartesian coordinates.
25 *
26 * @param <T> field type
27 * @author Romain Serra
28 * @see CartesianCost
29 * @since 13.0
30 */
31 public abstract class FieldAbstractCartesianCost<T extends CalculusFieldElement<T>> implements FieldCartesianCost<T> {
32
33 /** Name of adjoint vector. */
34 private final String name;
35
36 /** Mass flow rate factor (always positive). */
37 private final T massFlowRateFactor;
38
39 /** Dimension of adjoint vector. */
40 private final int adjointDimension;
41
42 /**
43 * Constructor.
44 * @param name name
45 * @param massFlowRateFactor mass flow rate factor
46 */
47 protected FieldAbstractCartesianCost(final String name, final T massFlowRateFactor) {
48 this.name = name;
49 this.massFlowRateFactor = FastMath.abs(massFlowRateFactor);
50 this.adjointDimension = this.massFlowRateFactor.isZero() ? 6 : 7;
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public int getAdjointDimension() {
56 return adjointDimension;
57 }
58
59 /**
60 * Getter for adjoint vector name.
61 * @return name
62 */
63 @Override
64 public String getAdjointName() {
65 return name;
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public T getMassFlowRateFactor() {
71 return massFlowRateFactor;
72 }
73
74 /**
75 * Computes the Euclidean norm of the adjoint velocity vector.
76 * @param adjointVariables adjoint vector
77 * @return norm of adjoint velocity
78 */
79 protected T getFieldAdjointVelocityNorm(final T[] adjointVariables) {
80 return FastMath.sqrt(adjointVariables[3].square().add(adjointVariables[4].square()).add(adjointVariables[5].square()));
81 }
82 }