1 /* Copyright 2002-2025 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.conversion;
18
19 import org.orekit.annotation.DefaultDataContext;
20 import org.orekit.attitudes.AttitudeProvider;
21 import org.orekit.attitudes.FrameAlignedProvider;
22 import org.orekit.data.DataContext;
23 import org.orekit.frames.Frame;
24 import org.orekit.orbits.Orbit;
25 import org.orekit.orbits.PositionAngleType;
26 import org.orekit.propagation.Propagator;
27 import org.orekit.propagation.SpacecraftState;
28 import org.orekit.propagation.analytical.tle.TLE;
29 import org.orekit.propagation.analytical.tle.TLEPropagator;
30 import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
31 import org.orekit.utils.ParameterDriver;
32 import org.orekit.utils.ParameterDriversList;
33
34 import java.util.List;
35
36 /** Builder for TLEPropagator.
37 * @author Pascal Parraud
38 * @author Thomas Paulet
39 * @since 6.0
40 */
41 public class TLEPropagatorBuilder extends AbstractAnalyticalPropagatorBuilder<TLEPropagator> {
42
43 /** Data context used to access frames and time scales. */
44 private final DataContext dataContext;
45
46 /** Template TLE. */
47 private final TLE templateTLE;
48
49 /** TLE generation algorithm. */
50 private final TleGenerationAlgorithm generationAlgorithm;
51
52 /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
53 * default data context}.
54 * <p>
55 * The template TLE is used as a model to {@link
56 * #createInitialOrbit() create initial orbit}. It defines the
57 * inertial frame, the central attraction coefficient, orbit type, satellite number,
58 * classification, .... and is also used together with the {@code positionScale} to
59 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
60 * parameters used by the callers of this builder to the real orbital parameters.
61 * </p>
62 * @param templateTLE reference TLE from which real orbits will be built
63 * @param positionAngleType position angle type to use
64 * @param positionScale scaling factor used for orbital parameters normalization
65 * (typically set to the expected standard deviation of the position)
66 * @param generationAlgorithm TLE generation algorithm
67 * @since 12.0
68 * @see #TLEPropagatorBuilder(TLE, PositionAngleType, double, DataContext, TleGenerationAlgorithm)
69 * @see #TLEPropagatorBuilder(TLE, PositionAngleType, double, DataContext, TleGenerationAlgorithm, AttitudeProvider)
70 */
71 @DefaultDataContext
72 public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
73 final double positionScale, final TleGenerationAlgorithm generationAlgorithm) {
74 this(templateTLE, positionAngleType, positionScale, DataContext.getDefault(), generationAlgorithm);
75 }
76
77 /** Build a new instance.
78 * <p>
79 * The template TLE is used as a model to {@link
80 * #createInitialOrbit() create initial orbit}. It defines the
81 * inertial frame, the central attraction coefficient, orbit type, satellite number,
82 * classification, .... and is also used together with the {@code positionScale} to
83 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
84 * parameters used by the callers of this builder to the real orbital parameters.
85 * The default attitude provider is aligned with the orbit's inertial frame.
86 * </p>
87 * @param templateTLE reference TLE from which real orbits will be built
88 * @param positionAngleType position angle type to use
89 * @param positionScale scaling factor used for orbital parameters normalization
90 * (typically set to the expected standard deviation of the position)
91 * @param dataContext used to access frames and time scales.
92 * @param generationAlgorithm TLE generation algorithm
93 * @since 12.0
94 * @see #TLEPropagatorBuilder(TLE, PositionAngleType, double, DataContext, TleGenerationAlgorithm, AttitudeProvider)
95 */
96 public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
97 final double positionScale, final DataContext dataContext,
98 final TleGenerationAlgorithm generationAlgorithm) {
99 this(templateTLE, positionAngleType, positionScale, dataContext, generationAlgorithm, FrameAlignedProvider.of(dataContext.getFrames().getTEME()));
100 }
101
102 /** Build a new instance.
103 * <p>
104 * The template TLE is used as a model to {@link
105 * #createInitialOrbit() create initial orbit}. It defines the
106 * inertial frame, the central attraction coefficient, orbit type, satellite number,
107 * classification, .... and is also used together with the {@code positionScale} to
108 * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
109 * parameters used by the callers of this builder to the real orbital parameters.
110 * </p>
111 * @param templateTLE reference TLE from which real orbits will be built
112 * @param positionAngleType position angle type to use
113 * @param positionScale scaling factor used for orbital parameters normalization
114 * (typically set to the expected standard deviation of the position)
115 * @param dataContext used to access frames and time scales.
116 * @param generationAlgorithm TLE generation algorithm
117 * @param attitudeProvider attitude law to use
118 * @since 12.2
119 */
120 public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
121 final double positionScale, final DataContext dataContext,
122 final TleGenerationAlgorithm generationAlgorithm, final AttitudeProvider attitudeProvider) {
123 super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames().getTEME(), attitudeProvider).getInitialState().getOrbit(),
124 positionAngleType, positionScale, false, attitudeProvider, Propagator.DEFAULT_MASS);
125
126 // Supported parameters: Bstar
127 addSupportedParameters(templateTLE.getParametersDrivers());
128
129 this.templateTLE = templateTLE;
130 this.dataContext = dataContext;
131 this.generationAlgorithm = generationAlgorithm;
132 }
133
134 /** Copy constructor.
135 * @param builder builder to copy from
136 */
137 private TLEPropagatorBuilder(final TLEPropagatorBuilder builder) {
138 this(builder.getTemplateTLE(), builder.getPositionAngleType(),
139 builder.getPositionScale(), builder.dataContext,
140 builder.generationAlgorithm, builder.getAttitudeProvider());
141 }
142
143 /** {@inheritDoc}. */
144 @Override
145 public TLEPropagatorBuilder clone() {
146 // Call to super clone() method to avoid warning
147 final TLEPropagatorBuilder clonedBuilder = (TLEPropagatorBuilder) super.clone();
148
149 // Use copy constructor to unlink orbital drivers
150 final TLEPropagatorBuilder builder = new TLEPropagatorBuilder(clonedBuilder);
151
152 // Set mass
153 builder.setMass(getMass());
154
155 // Ensure drivers' selection consistency
156 final ParameterDriversList propDrivers = clonedBuilder.getPropagationParametersDrivers();
157 builder.getPropagationParametersDrivers().getDrivers().
158 forEach(driver -> driver.setSelected(propDrivers.findByName(driver.getName()).isSelected()));
159 return new TLEPropagatorBuilder(clonedBuilder);
160 }
161
162 /** {@inheritDoc} */
163 @Override
164 public TLEPropagator buildPropagator(final double[] normalizedParameters) {
165
166 // create the orbit
167 setParameters(normalizedParameters);
168 final Orbit orbit = createInitialOrbit();
169 final SpacecraftState state = new SpacecraftState(orbit);
170 final Frame teme = dataContext.getFrames().getTEME();
171
172 // TLE related to the orbit
173 final TLE tle = generationAlgorithm.generate(state, templateTLE);
174 final List<ParameterDriver> drivers = templateTLE.getParametersDrivers();
175 for (int index = 0; index < drivers.size(); index++) {
176 if (drivers.get(index).isSelected()) {
177 tle.getParametersDrivers().get(index).setSelected(true);
178 }
179 }
180
181 // propagator
182 final TLEPropagator propagator = TLEPropagator.selectExtrapolator(tle, getAttitudeProvider(), getMass(), teme);
183 getImpulseManeuvers().forEach(propagator::addEventDetector);
184 return propagator;
185 }
186
187 /** Getter for the template TLE.
188 * @return the template TLE
189 */
190 public TLE getTemplateTLE() {
191 return templateTLE;
192 }
193 }