1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.control.indirect.adjoint.cost;
18
19
20 import java.util.function.Function;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.hipparchus.util.FastMath;
24 import org.orekit.propagation.FieldSpacecraftState;
25 import org.orekit.propagation.events.FieldEventDetectionSettings;
26 import org.orekit.propagation.events.FieldEventDetector;
27 import org.orekit.propagation.events.functions.EventFunction;
28 import org.orekit.propagation.events.functions.EventFunctionModifier;
29 import org.orekit.propagation.events.handlers.FieldResetDerivativesOnEvent;
30
31
32
33
34
35
36
37
38
39 public abstract class FieldAbstractCartesianCost<T extends CalculusFieldElement<T>> implements FieldCartesianCost<T> {
40
41
42 private final String name;
43
44
45 private final T massFlowRateFactor;
46
47
48 private final int adjointDimension;
49
50
51
52
53
54
55 protected FieldAbstractCartesianCost(final String name, final T massFlowRateFactor) {
56 this.name = name;
57 this.massFlowRateFactor = FastMath.abs(massFlowRateFactor);
58 this.adjointDimension = this.massFlowRateFactor.isZero() ? 6 : 7;
59 }
60
61
62 @Override
63 public int getAdjointDimension() {
64 return adjointDimension;
65 }
66
67
68
69
70
71 @Override
72 public String getAdjointName() {
73 return name;
74 }
75
76
77 @Override
78 public T getMassFlowRateFactor() {
79 return massFlowRateFactor;
80 }
81
82
83
84
85
86
87 protected T getFieldAdjointVelocityNorm(final T[] adjointVariables) {
88 return FastMath.sqrt(adjointVariables[3].square().add(adjointVariables[4].square()).add(adjointVariables[5].square()));
89 }
90
91
92
93
94
95
96
97
98 protected FieldEventDetector<T> buildSwitchDetector(final FieldSwitchFunction eventFunction,
99 final FieldEventDetectionSettings<T> fieldEventDetectionSettings) {
100 return FieldEventDetector.of(eventFunction, new FieldResetDerivativesOnEvent<>(), fieldEventDetectionSettings);
101 }
102
103
104
105
106 public class FieldSwitchFunction implements EventFunctionModifier {
107
108
109 private final EventFunction baseFunction;
110
111 protected FieldSwitchFunction(final Function<FieldSpacecraftState<T>, T> fieldFunction) {
112 this.baseFunction = EventFunction.of(getMassFlowRateFactor().getField(), fieldFunction);
113 }
114
115 @Override
116 public EventFunction getBaseFunction() {
117 return baseFunction;
118 }
119
120 @Override
121 public boolean dependsOnMainVariablesOnly() {
122 return false;
123 }
124 }
125 }