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 org.hipparchus.CalculusFieldElement;
21 import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
22 import org.orekit.propagation.FieldSpacecraftState;
23 import org.orekit.propagation.events.FieldEventDetectionSettings;
24
25
26
27
28
29
30
31
32
33
34
35
36 abstract class FieldCartesianEnergyConsideringMass<T extends CalculusFieldElement<T>> extends FieldAbstractCartesianCost<T> {
37
38
39 private final FieldEventDetectionSettings<T> eventDetectionSettings;
40
41
42
43
44
45
46
47 protected FieldCartesianEnergyConsideringMass(final String name, final T massFlowRateFactor,
48 final FieldEventDetectionSettings<T> eventDetectionSettings) {
49 super(name, massFlowRateFactor);
50 this.eventDetectionSettings = eventDetectionSettings;
51 }
52
53
54
55
56
57 public FieldEventDetectionSettings<T> getEventDetectionSettings() {
58 return eventDetectionSettings;
59 }
60
61
62 @Override
63 public FieldVector3D<T> getFieldThrustAccelerationVector(final T[] adjointVariables, final T mass) {
64 return getFieldThrustDirection(adjointVariables).scalarMultiply(getFieldThrustForceNorm(adjointVariables, mass).divide(mass));
65 }
66
67
68
69
70
71
72 protected FieldVector3D<T> getFieldThrustDirection(final T[] adjointVariables) {
73 return new FieldVector3D<>(adjointVariables[3], adjointVariables[4], adjointVariables[5]).normalize();
74 }
75
76
77
78
79
80
81
82 protected abstract T getFieldThrustForceNorm(T[] adjointVariables, T mass);
83
84
85 @Override
86 public void updateFieldAdjointDerivatives(final T[] adjointVariables, final T mass, final T[] adjointDerivatives) {
87 if (getAdjointDimension() > 6) {
88 adjointDerivatives[6] = adjointDerivatives[6].add(getFieldThrustForceNorm(adjointVariables, mass)
89 .multiply(getFieldAdjointVelocityNorm(adjointVariables)).divide(mass.square()));
90 }
91 }
92
93
94 @Override
95 public T getFieldHamiltonianContribution(final T[] adjointVariables, final T mass) {
96 final FieldVector3D<T> thrustForce = getFieldThrustAccelerationVector(adjointVariables, mass).scalarMultiply(mass);
97 return thrustForce.getNormSq().multiply(-1. / 2.);
98 }
99
100
101
102
103 class FieldSingularityDetector extends FieldControlSwitchDetector<T> {
104
105
106 private final T detectionValue;
107
108
109
110
111
112
113 FieldSingularityDetector(final FieldEventDetectionSettings<T> detectionSettings, final T detectionValue) {
114 super(detectionSettings);
115 this.detectionValue = detectionValue;
116 }
117
118
119 @Override
120 public T g(final FieldSpacecraftState<T> state) {
121 final T[] adjoint = state.getAdditionalState(getAdjointName());
122 return evaluateVariablePart(adjoint, state.getMass()).subtract(detectionValue);
123 }
124
125
126
127
128
129
130
131 private T evaluateVariablePart(final T[] adjointVariables, final T mass) {
132 final T adjointVelocityNorm = getFieldAdjointVelocityNorm(adjointVariables);
133 T variablePart = adjointVelocityNorm.divide(mass);
134 if (getAdjointDimension() > 6) {
135 variablePart = variablePart.subtract(adjointVariables[6].multiply(getMassFlowRateFactor()));
136 }
137 return variablePart;
138 }
139
140 }
141 }