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