1 /* Copyright 2002-2022 CS GROUP
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.propagation.integration;
18
19 import java.util.function.Supplier;
20
21 import org.hipparchus.CalculusFieldElement;
22 import org.hipparchus.util.MathArrays;
23 import org.orekit.propagation.FieldSpacecraftState;
24 import org.orekit.time.FieldAbsoluteDate;
25
26 /** Temporary adapter from {@link FieldAdditionalEquations} to {@link FieldAdditionalDerivativesProvider}.
27 * @since 11.1
28 * @deprecated must be removed in 12.0 when {@link AdditionalEquations} is removed
29 */
30 @Deprecated
31 public class FieldAdditionalEquationsAdapter<T extends CalculusFieldElement<T>> implements FieldAdditionalDerivativesProvider<T> {
32
33 /** Wrapped equations. */
34 private final FieldAdditionalEquations<T> equations;
35
36 /** Supplier for reference state. */
37 private final Supplier<FieldSpacecraftState<T>> stateSupplier;
38
39 /** Dimension. */
40 private int dimension;
41
42 /** Simple constructor.
43 * @param equations wrapped equations
44 * @param stateSupplier supplier for reference state
45 */
46 public FieldAdditionalEquationsAdapter(final FieldAdditionalEquations<T> equations, final Supplier<FieldSpacecraftState<T>> stateSupplier) {
47 this.equations = equations;
48 this.stateSupplier = stateSupplier;
49 this.dimension = -1;
50 }
51
52 /** {@inheritDoc} */
53 @Override
54 public String getName() {
55 return equations.getName();
56 }
57
58 /** {@inheritDoc} */
59 @Override
60 public int getDimension() {
61 if (dimension < 0) {
62 // retrieve the dimension the first time we need it
63 dimension = stateSupplier.get().getAdditionalState(getName()).length;
64 }
65 return dimension;
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public boolean yield(final FieldSpacecraftState<T> state) {
71 return false;
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public void init(final FieldSpacecraftState<T> initialState, final FieldAbsoluteDate<T> target) {
77 equations.init(initialState, target);
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public T[] derivatives(final FieldSpacecraftState<T> state) {
83 final T[] pDot = MathArrays.buildArray(state.getDate().getField(), getDimension());
84 equations.computeDerivatives(state, pDot);
85 return pDot;
86 }
87
88 }