TLEPropagatorBuilder.java

  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. import org.orekit.annotation.DefaultDataContext;
  19. import org.orekit.attitudes.AttitudeProvider;
  20. import org.orekit.attitudes.FrameAlignedProvider;
  21. import org.orekit.data.DataContext;
  22. import org.orekit.frames.Frame;
  23. import org.orekit.orbits.Orbit;
  24. import org.orekit.orbits.PositionAngleType;
  25. import org.orekit.propagation.Propagator;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.analytical.tle.TLE;
  28. import org.orekit.propagation.analytical.tle.TLEPropagator;
  29. import org.orekit.propagation.analytical.tle.generation.TleGenerationAlgorithm;
  30. import org.orekit.utils.ParameterDriver;
  31. import org.orekit.utils.ParameterDriversList;

  32. import java.util.List;

  33. /** Builder for TLEPropagator.
  34.  * @author Pascal Parraud
  35.  * @author Thomas Paulet
  36.  * @since 6.0
  37.  */
  38. public class TLEPropagatorBuilder extends AbstractAnalyticalPropagatorBuilder<TLEPropagator> {

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

  41.     /** Template TLE. */
  42.     private final TLE templateTLE;

  43.     /** TLE generation algorithm. */
  44.     private final TleGenerationAlgorithm generationAlgorithm;

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

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

  93.     /** Build a new instance.
  94.      * <p>
  95.      * The template TLE is used as a model to {@link
  96.      * #createInitialOrbit() create initial orbit}. It defines the
  97.      * inertial frame, the central attraction coefficient, orbit type, satellite number,
  98.      * classification, .... and is also used together with the {@code positionScale} to
  99.      * convert from the {@link ParameterDriver#setNormalizedValue(double) normalized}
  100.      * parameters used by the callers of this builder to the real orbital parameters.
  101.      * </p>
  102.      * @param templateTLE reference TLE from which real orbits will be built
  103.      * @param positionAngleType position angle type to use
  104.      * @param positionScale scaling factor used for orbital parameters normalization
  105.      * (typically set to the expected standard deviation of the position)
  106.      * @param dataContext used to access frames and time scales.
  107.      * @param generationAlgorithm TLE generation algorithm
  108.      * @param attitudeProvider attitude law to use
  109.      * @since 12.2
  110.      */
  111.     public TLEPropagatorBuilder(final TLE templateTLE, final PositionAngleType positionAngleType,
  112.                                 final double positionScale, final DataContext dataContext,
  113.                                 final TleGenerationAlgorithm generationAlgorithm, final AttitudeProvider attitudeProvider) {
  114.         super(TLEPropagator.selectExtrapolator(templateTLE, dataContext.getFrames().getTEME(), attitudeProvider).getInitialState().getOrbit(),
  115.               positionAngleType, positionScale, false, attitudeProvider, Propagator.DEFAULT_MASS);

  116.         // Supported parameters: Bstar
  117.         addSupportedParameters(templateTLE.getParametersDrivers());

  118.         this.templateTLE         = templateTLE;
  119.         this.dataContext         = dataContext;
  120.         this.generationAlgorithm = generationAlgorithm;
  121.     }

  122.     /** Copy constructor.
  123.      * @param builder builder to copy from
  124.      */
  125.     private TLEPropagatorBuilder(final TLEPropagatorBuilder builder) {
  126.         this(builder.getTemplateTLE(), builder.getPositionAngleType(),
  127.              builder.getPositionScale(), builder.dataContext,
  128.              builder.generationAlgorithm, builder.getAttitudeProvider());
  129.     }

  130.     /** {@inheritDoc}. */
  131.     @Override
  132.     public TLEPropagatorBuilder clone() {
  133.         // Call to super clone() method to avoid warning
  134.         final TLEPropagatorBuilder clonedBuilder = (TLEPropagatorBuilder) super.clone();

  135.         // Use copy constructor to unlink orbital drivers
  136.         final TLEPropagatorBuilder builder = new TLEPropagatorBuilder(clonedBuilder);

  137.         // Set mass
  138.         builder.setMass(getMass());

  139.         // Ensure drivers' selection consistency
  140.         final ParameterDriversList propDrivers = clonedBuilder.getPropagationParametersDrivers();
  141.         builder.getPropagationParametersDrivers().getDrivers().
  142.                         forEach(driver -> driver.setSelected(propDrivers.findByName(driver.getName()).isSelected()));
  143.         return new TLEPropagatorBuilder(clonedBuilder);
  144.     }

  145.     /** {@inheritDoc} */
  146.     @Override
  147.     public TLEPropagator buildPropagator(final double[] normalizedParameters) {

  148.         // create the orbit
  149.         setParameters(normalizedParameters);
  150.         final Orbit           orbit = createInitialOrbit();
  151.         final SpacecraftState state = new SpacecraftState(orbit);
  152.         final Frame           teme  = dataContext.getFrames().getTEME();

  153.         // TLE related to the orbit
  154.         final TLE tle = generationAlgorithm.generate(state, templateTLE);
  155.         final List<ParameterDriver> drivers = templateTLE.getParametersDrivers();
  156.         for (int index = 0; index < drivers.size(); index++) {
  157.             if (drivers.get(index).isSelected()) {
  158.                 tle.getParametersDrivers().get(index).setSelected(true);
  159.             }
  160.         }

  161.         // propagator
  162.         final TLEPropagator propagator = TLEPropagator.selectExtrapolator(tle, getAttitudeProvider(), getMass(), teme);
  163.         getImpulseManeuvers().forEach(propagator::addEventDetector);
  164.         return propagator;
  165.     }

  166.     /** Getter for the template TLE.
  167.      * @return the template TLE
  168.      */
  169.     public TLE getTemplateTLE() {
  170.         return templateTLE;
  171.     }
  172. }