1 /* Copyright 2002-2026 Mark Rutten
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 * Mark Rutten 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.generation;
18
19 import org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresOptimizer;
20 import org.hipparchus.optim.nonlinear.vector.leastsquares.LevenbergMarquardtOptimizer;
21 import org.orekit.annotation.DefaultDataContext;
22 import org.orekit.data.DataContext;
23 import org.orekit.frames.Frame;
24 import org.orekit.orbits.Orbit;
25 import org.orekit.propagation.analytical.tle.TLE;
26 import org.orekit.propagation.conversion.osc2mean.LeastSquaresConverter;
27 import org.orekit.propagation.conversion.osc2mean.TLETheory;
28 import org.orekit.time.TimeScale;
29
30 /**
31 * Least squares method to generate a usable TLE from a spacecraft state.
32 *
33 * @author Mark Rutten
34 * @since 12.0
35 */
36 public class LeastSquaresTleGenerationAlgorithm extends TleGenerationAlgorithm {
37
38 /** Default value for maximum number of iterations.*/
39 public static final int DEFAULT_MAX_ITERATIONS = 1000;
40
41 /** Converter to mean elements.
42 * @since 14.0
43 */
44 private final LeastSquaresConverter converter;
45
46 /**
47 * Default constructor.
48 * <p>Uses:
49 * <ul>
50 * <li>the {@link DataContext#getDefault() default data context}</li>
51 * <li>{@link #DEFAULT_MAX_ITERATIONS}</li>
52 * <li>the {@link LevenbergMarquardtOptimizer}</li>
53 * </ul>
54 * @param templateTLE template TLE
55 * @since 14.0
56 */
57 @DefaultDataContext
58 public LeastSquaresTleGenerationAlgorithm(final TLE templateTLE) {
59 this(templateTLE, DEFAULT_MAX_ITERATIONS);
60 }
61
62 /**
63 * Default constructor.
64 * <p>Uses:
65 * <ul>
66 * <li>the {@link DataContext#getDefault() default data context}</li>
67 * <li>the {@link LevenbergMarquardtOptimizer}</li>
68 * </ul>
69 * @param templateTLE template TLE
70 * @param maxIterations maximum number of iterations for convergence
71 * @since 14.0
72 */
73 @DefaultDataContext
74 public LeastSquaresTleGenerationAlgorithm(final TLE templateTLE,
75 final int maxIterations) {
76 this(templateTLE, maxIterations, DataContext.getDefault().getTimeScales().getUTC(),
77 DataContext.getDefault().getFrames().getTEME());
78 }
79
80 /**
81 * Constructor.
82 * <p>Uses the {@link LevenbergMarquardtOptimizer}.</p>
83 * @param templateTLE template TLE
84 * @param maxIterations maximum number of iterations for convergence
85 * @param utc UTC time scale
86 * @param teme TEME frame
87 * @since 14.0
88 */
89 public LeastSquaresTleGenerationAlgorithm(final TLE templateTLE,
90 final int maxIterations,
91 final TimeScale utc,
92 final Frame teme) {
93 this(templateTLE, utc, teme,
94 new LeastSquaresConverter(new TLETheory(utc, teme),
95 new LevenbergMarquardtOptimizer(),
96 LeastSquaresConverter.DEFAULT_THRESHOLD,
97 maxIterations));
98 }
99
100 /**
101 * Constructor.
102 * <p>Enables to select the {@link LeastSquaresOptimizer optimizer}
103 * for the {@link LeastSquaresConverter least-squares converter}.</p>
104 * @param templateTLE template TLE
105 * @param utc UTC time scale
106 * @param teme TEME frame
107 * @param converter osculating to mean orbit converter using a least-squares algorithm
108 * @since 14.0
109 */
110 public LeastSquaresTleGenerationAlgorithm(final TLE templateTLE,
111 final TimeScale utc,
112 final Frame teme,
113 final LeastSquaresConverter converter) {
114 super(templateTLE, teme, converter);
115 converter.setMeanTheory(new TLETheory(utc, teme));
116 this.converter = converter;
117 }
118
119 /**
120 * Get the Root Mean Square of the TLE estimation.
121 * <p>
122 * Be careful that the RMS is updated each time the
123 * {@link #reset(Orbit)} method is called.
124 * </p>
125 * @return the RMS
126 */
127 public double getRms() {
128 return converter.getRMS();
129 }
130
131 }