FixedPointTleGenerationAlgorithm.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.analytical.tle.generation;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.annotation.DefaultDataContext;
  20. import org.orekit.data.DataContext;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.orbits.FieldKeplerianOrbit;
  23. import org.orekit.orbits.KeplerianOrbit;
  24. import org.orekit.orbits.OrbitType;
  25. import org.orekit.propagation.FieldSpacecraftState;
  26. import org.orekit.propagation.SpacecraftState;
  27. import org.orekit.propagation.analytical.tle.FieldTLE;
  28. import org.orekit.propagation.analytical.tle.TLE;
  29. import org.orekit.propagation.conversion.osc2mean.FixedPointConverter;
  30. import org.orekit.propagation.conversion.osc2mean.TLETheory;
  31. import org.orekit.time.TimeScale;
  32. import org.orekit.utils.ParameterDriver;

  33. /**
  34.  * Fixed Point method to reverse SGP4 and SDP4 propagation algorithm
  35.  * and generate a usable TLE from a spacecraft state.
  36.  * <p>
  37.  * Using this algorithm, the B* value is not computed. In other words,
  38.  * the B* value from the template TLE is set to the generated one.
  39.  * </p>
  40.  * @author Thomas Paulet
  41.  * @author Bryan Cazabonne
  42.  * @since 12.0
  43.  */
  44. public class FixedPointTleGenerationAlgorithm implements TleGenerationAlgorithm {

  45.     /** Default value for epsilon. */
  46.     public static final double EPSILON_DEFAULT = 1.0e-10;

  47.     /** Default value for maxIterations. */
  48.     public static final int MAX_ITERATIONS_DEFAULT = 100;

  49.     /** Default value for scale. */
  50.     public static final double SCALE_DEFAULT = 1.0;

  51.     /** Osculating to mean orbit converter. */
  52.     private final FixedPointConverter converter;

  53.     /** UTC time scale. */
  54.     private final TimeScale utc;

  55.     /**
  56.      * Default constructor.
  57.      * <p>
  58.      * Uses the {@link DataContext#getDefault() default data context}
  59.      * as well as {@link #EPSILON_DEFAULT}, {@link #MAX_ITERATIONS_DEFAULT},
  60.      * {@link #SCALE_DEFAULT} for method convergence.
  61.      * </p>
  62.      */
  63.     @DefaultDataContext
  64.     public FixedPointTleGenerationAlgorithm() {
  65.         this(EPSILON_DEFAULT, MAX_ITERATIONS_DEFAULT, SCALE_DEFAULT);
  66.     }

  67.     /**
  68.      * Constructor.
  69.      * <p>
  70.      * Uses the {@link DataContext#getDefault() default data context}.
  71.      * </p>
  72.      * @param epsilon used to compute threshold for convergence check
  73.      * @param maxIterations maximum number of iterations for convergence
  74.      * @param scale scale factor of the Fixed Point algorithm
  75.      */
  76.     @DefaultDataContext
  77.     public FixedPointTleGenerationAlgorithm(final double epsilon,
  78.                                             final int maxIterations,
  79.                                             final double scale) {
  80.         this(epsilon, maxIterations, scale,
  81.              DataContext.getDefault().getTimeScales().getUTC(),
  82.              DataContext.getDefault().getFrames().getTEME());
  83.     }

  84.     /**
  85.      * Constructor.
  86.      * @param epsilon used to compute threshold for convergence check
  87.      * @param maxIterations maximum number of iterations for convergence
  88.      * @param scale scale factor of the Fixed Point algorithm
  89.      * @param utc UTC time scale
  90.      * @param teme TEME frame
  91.      */
  92.     public FixedPointTleGenerationAlgorithm(final double epsilon,
  93.                                             final int maxIterations,
  94.                                             final double scale,
  95.                                             final TimeScale utc,
  96.                                             final Frame teme) {
  97.         this.converter = new FixedPointConverter(new TLETheory(utc, teme),
  98.                                                  epsilon,
  99.                                                  maxIterations,
  100.                                                  scale);
  101.         this.utc       = utc;
  102.     }

  103.     /** {@inheritDoc} */
  104.     @Override
  105.     public TLE generate(final SpacecraftState state, final TLE templateTLE) {
  106.         final KeplerianOrbit mean = (KeplerianOrbit) OrbitType.KEPLERIAN.convertType(converter.convertToMean(state.getOrbit()));
  107.         final TLE tle = TleGenerationUtil.newTLE(mean, templateTLE, templateTLE.getBStar(mean.getDate()), utc);
  108.         // reset estimated parameters from template to generated tle
  109.         for (final ParameterDriver templateDrivers : templateTLE.getParametersDrivers()) {
  110.             if (templateDrivers.isSelected()) {
  111.                 // set to selected for the new TLE
  112.                 tle.getParameterDriver(templateDrivers.getName()).setSelected(true);
  113.             }
  114.         }
  115.         return tle;
  116.     }

  117.     /** {@inheritDoc} */
  118.     @Override
  119.     public <T extends CalculusFieldElement<T>> FieldTLE<T> generate(final FieldSpacecraftState<T> state,
  120.                                                                     final FieldTLE<T> templateTLE) {
  121.         final T bStar = state.getMass().getField().getZero().newInstance(templateTLE.getBStar());
  122.         final FieldKeplerianOrbit<T> mean = (FieldKeplerianOrbit<T>) OrbitType.KEPLERIAN.convertType(converter.convertToMean(state.getOrbit()));
  123.         final FieldTLE<T> tle = TleGenerationUtil.newTLE(mean, templateTLE, bStar, utc);
  124.         // reset estimated parameters from template to generated tle
  125.         for (final ParameterDriver templateDrivers : templateTLE.getParametersDrivers()) {
  126.             if (templateDrivers.isSelected()) {
  127.                 // set to selected for the new TLE
  128.                 tle.getParameterDriver(templateDrivers.getName()).setSelected(true);
  129.             }
  130.         }
  131.         return tle;
  132.     }

  133. }