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;
18
19 import org.hipparchus.CalculusFieldElement;
20 import org.hipparchus.util.MathArrays;
21 import org.orekit.frames.Frame;
22 import org.orekit.time.AbsoluteDate;
23 import org.orekit.time.FieldAbsoluteDate;
24
25 /**
26 * Abstract class for common computations regarding adjoint dynamics and gravity for Cartesian coordinates.
27 *
28 * @author Romain Serra
29 * @see CartesianAdjointEquationTerm
30 * @since 12.2
31 */
32 public abstract class AbstractCartesianAdjointGravitationalTerm extends AbstractCartesianAdjointEquationTerm {
33
34 /** Body gravitational parameter. */
35 private final double mu;
36
37 /**
38 * Constructor.
39 * @param mu body gravitational parameter
40 */
41 protected AbstractCartesianAdjointGravitationalTerm(final double mu) {
42 this.mu = mu;
43 }
44
45 /**
46 * Getter for the gravitational constant.
47 * @return mu
48 */
49 public double getMu() {
50 return mu;
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public double[] getRatesContribution(final AbsoluteDate date, final double[] stateVariables,
56 final double[] adjointVariables, final Frame frame) {
57 final double[] contribution = new double[adjointVariables.length];
58 final double[] positionAdjointContribution = getPositionAdjointContribution(date, stateVariables,
59 adjointVariables, frame);
60 System.arraycopy(positionAdjointContribution, 0, contribution, 0, positionAdjointContribution.length);
61 return contribution;
62 }
63
64 /**
65 * Computes the contribution to position adjoint derivatives.
66 *
67 * @param date date
68 * @param stateVariables state variables
69 * @param adjointVariables adjoint variables
70 * @param frame propagation frame
71 * @return contribution to position adjoint derivatives
72 */
73 protected abstract double[] getPositionAdjointContribution(AbsoluteDate date, double[] stateVariables,
74 double[] adjointVariables, Frame frame);
75
76 /** {@inheritDoc} */
77 @Override
78 public <T extends CalculusFieldElement<T>> T[] getFieldRatesContribution(final FieldAbsoluteDate<T> date,
79 final T[] stateVariables,
80 final T[] adjointVariables, final Frame frame) {
81 final T[] contribution = MathArrays.buildArray(date.getField(), adjointVariables.length);
82 final T[] positionAdjointFieldContribution = getPositionAdjointFieldContribution(date, stateVariables,
83 adjointVariables, frame);
84 System.arraycopy(positionAdjointFieldContribution, 0, contribution, 0, positionAdjointFieldContribution.length);
85 return contribution;
86 }
87
88 /**
89 * Computes the contribution to position adjoint derivatives.
90 *
91 * @param <T> field type
92 * @param date date
93 * @param stateVariables state variables
94 * @param adjointVariables adjoint variables
95 * @param frame propagation frame
96 * @return contribution to position adjoint derivatives
97 */
98 protected abstract <T extends CalculusFieldElement<T>> T[] getPositionAdjointFieldContribution(FieldAbsoluteDate<T> date,
99 T[] stateVariables,
100 T[] adjointVariables,
101 Frame frame);
102 }