1   /* Copyright 2002-2026 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.analytical.tle;
18  
19  import org.hipparchus.linear.RealMatrix;
20  import org.orekit.orbits.OrbitParamsType;
21  import org.orekit.orbits.PositionAngleType;
22  import org.orekit.propagation.SpacecraftState;
23  import org.orekit.propagation.analytical.AbstractAnalyticalGradientConverter;
24  import org.orekit.propagation.analytical.AbstractAnalyticalMatricesHarvester;
25  import org.orekit.utils.DoubleArrayDictionary;
26  
27  /** Harvester between two-dimensional Jacobian matrices and
28   * one-dimensional {@link TLEPropagator}.
29   * @author Thomas Paulet
30   * @author Bryan Cazabonne
31   * @since 11.1
32   */
33  class TLEHarvester extends AbstractAnalyticalMatricesHarvester {
34  
35      /** Propagator bound to this harvester. */
36      private final TLEPropagator propagator;
37  
38      /** Simple constructor.
39       * <p>
40       * The arguments for initial matrices <em>must</em> be compatible with the
41       * {@link OrbitParamsType orbit type}
42       * and {@link PositionAngleType position angle} that will be used by propagator
43       * </p>
44       * @param propagator propagator bound to this harvester
45       * @param stmName State Transition Matrix state name
46       * @param initialStm initial State Transition Matrix ∂C/∂K₀,
47       *                   if null (which is the most frequent case), assumed to be just the
48       *                   conversion from Keplerian type to Cartesian type at t₀
49       * @param initialJacobianColumns initial columns of the Jacobians matrix with respect to parameters,
50       * if null or if some selected parameters are missing from the dictionary, the corresponding
51       * initial column is assumed to be 0
52       */
53      TLEHarvester(final TLEPropagator propagator, final String stmName,
54                   final RealMatrix initialStm, final DoubleArrayDictionary initialJacobianColumns) {
55          super(propagator);
56          this.propagator = propagator;
57          setInitialStm(stmName, initialStm);
58          setInitialJacobianColumns(initialJacobianColumns);
59      }
60  
61      /** {@inheritDoc}
62       * <p>
63       * As the propagated state is Cartesian for TLE propagators, this is the Jacobian of the
64       * Cartesian coordinates with respect to the TLE mean elements representing the state.
65       * </p>
66       */
67      @Override
68      public RealMatrix getStateJacobianVsBuilderParameters(final SpacecraftState state) {
69          return propagator.getTleGenerationAlgorithm().getJacobianWrtParameters(builderParameters(state));
70      }
71  
72      /** Get the TLE whose orbital elements are the builder parameters representing a state.
73       * @param state state to represent
74       * @return TLE holding the mean elements that represent the given state
75       */
76      private TLE builderParameters(final SpacecraftState state) {
77  
78          final TLE current = propagator.getTLE();
79  
80          if (state.getDate().isEqualTo(current.getDate())) {
81              // the TLE held by the propagator already is the exact representation of the
82              // state at its own epoch, so we use it as is rather than rebuilding it, which
83              // would only add the convergence noise of the osculating to mean iterations
84              return current;
85          }
86  
87          // rebuild the mean elements matching the state, keeping the identification data
88          // (satellite number, launch data, B*, …) of the TLE held by the propagator
89          // FIXME: not sure about the performance of this one
90          return propagator.getTleGenerationAlgorithm().generate(state, current);
91  
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public AbstractAnalyticalGradientConverter getGradientConverter() {
97          return new TLEGradientConverter(propagator);
98      }
99  
100 }