TLEPropagatorBuilder.java

  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. import java.util.List;

  19. import org.orekit.annotation.DefaultDataContext;
  20. import org.orekit.attitudes.FrameAlignedProvider;
  21. import org.orekit.data.DataContext;
  22. import org.orekit.estimation.leastsquares.AbstractBatchLSModel;
  23. import org.orekit.estimation.leastsquares.BatchLSModel;
  24. import org.orekit.estimation.leastsquares.ModelObserver;
  25. import org.orekit.estimation.measurements.ObservedMeasurement;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.orbits.Orbit;
  28. import org.orekit.orbits.PositionAngleType;
  29. import org.orekit.propagation.Propagator;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.propagation.analytical.tle.TLE;
  32. import org.orekit.propagation.analytical.tle.TLEPropagator;
  33. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.ParameterDriversList;

  36. /** Builder for TLEPropagator.
  37.  * @author Pascal Parraud
  38.  * @author Thomas Paulet
  39.  * @since 6.0
  40.  */
  41. public class TLEPropagatorBuilder extends AbstractPropagatorBuilder {

  42.     /** Data context used to access frames and time scales. */
  43.     private final DataContext dataContext;

  44.     /** Template TLE. */
  45.     private final TLE templateTLE;

  46.     /** TLE generation algorithm. */
  47.     private final TleGenerationAlgorithm generationAlgorithm;

  48.     /** Build a new instance. This constructor uses the {@link DataContext#getDefault()
  49.      * default data context}.
  50.      * <p>
  51.      * The template TLE is used as a model to {@link
  52.      * #createInitialOrbit() create initial orbit}. It defines the
  53.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  54.      * classification, .... and is also used together with the {@code positionScale} to
  55.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  56.      * parameters used by the callers of this builder to the real orbital parameters.
  57.      * </p>
  58.      * @param templateTLE reference TLE from which real orbits will be built
  59.      * @param positionAngleType position angle type to use
  60.      * @param positionScale scaling factor used for orbital parameters normalization
  61.      * (typically set to the expected standard deviation of the position)
  62.      * @param generationAlgorithm TLE generation algorithm
  63.      * @since 12.0
  64.      * @see #TLEPropagatorBuilder(TLE, PositionAngleType, double, DataContext, TleGenerationAlgorithm)
  65.      */
  66.     @DefaultDataContext
  67.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
  68.                                 final double positionScale, final TleGenerationAlgorithm generationAlgorithm) {
  69.         this(templateTLE, positionAngleType, positionScale, DataContext.getDefault(), generationAlgorithm);
  70.     }

  71.     /** Build a new instance.
  72.      * <p>
  73.      * The template TLE is used as a model to {@link
  74.      * #createInitialOrbit() create initial orbit}. It defines the
  75.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  76.      * classification, .... and is also used together with the {@code positionScale} to
  77.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  78.      * parameters used by the callers of this builder to the real orbital parameters.
  79.      * The default attitude provider is aligned with the orbit's inertial frame.
  80.      * </p>
  81.      * @param templateTLE reference TLE from which real orbits will be built
  82.      * @param positionAngleType position angle type to use
  83.      * @param positionScale scaling factor used for orbital parameters normalization
  84.      * (typically set to the expected standard deviation of the position)
  85.      * @param dataContext used to access frames and time scales.
  86.      * @param generationAlgorithm TLE generation algorithm
  87.      * @since 12.0
  88.      */
  89.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
  90.                                 final double positionScale, final DataContext dataContext,
  91.                                 final TleGenerationAlgorithm generationAlgorithm) {
  92.         super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames().getTEME()).getInitialState().getOrbit(),
  93.                 positionAngleType, positionScale, false, FrameAlignedProvider.of(dataContext.getFrames().getTEME()));

  94.         // Supported parameters: Bstar
  95.         addSupportedParameters(templateTLE.getParametersDrivers());

  96.         this.templateTLE         = templateTLE;
  97.         this.dataContext         = dataContext;
  98.         this.generationAlgorithm = generationAlgorithm;
  99.     }

  100.     /** {@inheritDoc} */
  101.     @Override
  102.     public TLEPropagatorBuilder copy() {
  103.         return new TLEPropagatorBuilder(templateTLE, getPositionAngleType(), getPositionScale(),
  104.                                         dataContext, generationAlgorithm);
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public TLEPropagator buildPropagator(final double[] normalizedParameters) {

  109.         // create the orbit
  110.         setParameters(normalizedParameters);
  111.         final Orbit           orbit = createInitialOrbit();
  112.         final SpacecraftState state = new SpacecraftState(orbit);
  113.         final Frame           teme  = dataContext.getFrames().getTEME();

  114.         // TLE related to the orbit
  115.         final TLE tle = generationAlgorithm.generate(state, templateTLE);
  116.         final List<ParameterDriver> drivers = templateTLE.getParametersDrivers();
  117.         for (int index = 0; index < drivers.size(); index++) {
  118.             if (drivers.get(index).isSelected()) {
  119.                 tle.getParametersDrivers().get(index).setSelected(true);
  120.             }
  121.         }

  122.         // propagator
  123.         return TLEPropagator.selectExtrapolator(tle, getAttitudeProvider(), Propagator.DEFAULT_MASS, teme);

  124.     }

  125.     /** Getter for the template TLE.
  126.      * @return the template TLE
  127.      */
  128.     public TLE getTemplateTLE() {
  129.         return templateTLE;
  130.     }

  131.     /** {@inheritDoc} */
  132.     @Override
  133.     public AbstractBatchLSModel buildLeastSquaresModel(final PropagatorBuilder[] builders,
  134.                                                        final List<ObservedMeasurement<?>> measurements,
  135.                                                        final ParameterDriversList estimatedMeasurementsParameters,
  136.                                                        final ModelObserver observer) {
  137.         return new BatchLSModel(builders, measurements, estimatedMeasurementsParameters, observer);
  138.     }

  139. }