1 /* Copyright 2022-2026 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.util.FastMath;
21 import org.orekit.propagation.events.EventDetectionSettings;
22 import org.orekit.propagation.events.EventDetector;
23 import org.orekit.propagation.events.handlers.ResetDerivativesOnEvent;
24
25 /**
26 * Abstract class for cost with Cartesian coordinates.
27 *
28 * @author Romain Serra
29 * @see CartesianCost
30 * @since 13.0
31 */
32 public abstract class AbstractCartesianCost implements CartesianCost {
33
34 /** Name of adjoint vector. */
35 private final String name;
36
37 /** Mass flow rate factor (always positive). */
38 private final double massFlowRateFactor;
39
40 /** Dimension of adjoint vector. */
41 private final int adjointDimension;
42
43 /**
44 * Constructor.
45 * @param name name
46 * @param massFlowRateFactor mass flow rate factor
47 */
48 protected AbstractCartesianCost(final String name, final double massFlowRateFactor) {
49 this.name = name;
50 this.massFlowRateFactor = FastMath.abs(massFlowRateFactor);
51 this.adjointDimension = this.massFlowRateFactor == 0. ? 6 : 7;
52 }
53
54 /**
55 * {@inheritDoc}
56 */
57 @Override
58 public int getAdjointDimension() {
59 return adjointDimension;
60 }
61
62 /**
63 * Getter for adjoint vector name.
64 * @return name
65 */
66 @Override
67 public String getAdjointName() {
68 return name;
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public double getMassFlowRateFactor() {
74 return massFlowRateFactor;
75 }
76
77 /**
78 * Computes the Euclidean norm of the adjoint velocity vector.
79 * @param adjointVariables adjoint vector
80 * @return norm of adjoint velocity
81 */
82 protected double getAdjointVelocityNorm(final double[] adjointVariables) {
83 return FastMath.sqrt(adjointVariables[3] * adjointVariables[3] + adjointVariables[4] * adjointVariables[4] + adjointVariables[5] * adjointVariables[5]);
84 }
85
86 /**
87 * Build event detector for control switches.
88 * @param controlSwitchFunction switch function
89 * @param detectionSettings event detection settings
90 * @return event detector
91 * @since 14.0
92 */
93 protected EventDetector buildSwitchDetector(final ControlSwitchFunction controlSwitchFunction,
94 final EventDetectionSettings detectionSettings) {
95 return EventDetector.of(controlSwitchFunction, new ResetDerivativesOnEvent(), detectionSettings);
96 }
97 }