TEMEProvider.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.frames;


  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Rotation;
  22. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.time.TimeScalarFunction;
  28. import org.orekit.time.TimeScales;
  29. import org.orekit.time.TimeVectorFunction;
  30. import org.orekit.utils.IERSConventions;

  31. /** True Equator Mean Equinox Frame.
  32.  * <p>This frame is used for the SGP4 model in TLE propagation. This frame has <em>no</em>
  33.  * official definition and there are some ambiguities about whether it should be used
  34.  * as "of date" or "of epoch". This frame should therefore be used <em>only</em> for
  35.  * TLE propagation and not for anything else, as recommended by the CCSDS Orbit Data Message
  36.  * blue book.</p>
  37.  * @author Luc Maisonobe
  38.  */
  39. class TEMEProvider implements EOPBasedTransformProvider {

  40.     /** Conventions. */
  41.     private final IERSConventions conventions;

  42.     /** EOP history. */
  43.     private final EOPHistory eopHistory;

  44.     /** Function computing the mean obliquity. */
  45.     private final transient TimeScalarFunction obliquityFunction;

  46.     /** Function computing the nutation angles. */
  47.     private final transient TimeVectorFunction nutationFunction;

  48.     /**
  49.      * Simple constructor.
  50.      *  @param conventions IERS conventions to apply
  51.      * @param eopHistory  EOP history or {@code null} if no corrections should be
  52.      *                    applied.
  53.      * @param timeScales  other time scales used in computing the transform.
  54.      */
  55.     TEMEProvider(final IERSConventions conventions,
  56.                  final EOPHistory eopHistory,
  57.                  final TimeScales timeScales) {
  58.         this.conventions       = conventions;
  59.         this.eopHistory        = eopHistory;
  60.         this.obliquityFunction = conventions.getMeanObliquityFunction(timeScales);
  61.         this.nutationFunction  = conventions.getNutationFunction(timeScales);
  62.     }

  63.     /**
  64.      * Private constructor.
  65.      *
  66.      * @param conventions       IERS conventions to apply
  67.      * @param eopHistory        EOP history
  68.      * @param obliquityFunction to use.
  69.      * @param nutationFunction  to use.
  70.      */
  71.     private TEMEProvider(final IERSConventions conventions,
  72.                          final EOPHistory eopHistory,
  73.                          final TimeScalarFunction obliquityFunction,
  74.                          final TimeVectorFunction nutationFunction) {
  75.         this.conventions = conventions;
  76.         this.eopHistory = eopHistory;
  77.         this.obliquityFunction = obliquityFunction;
  78.         this.nutationFunction = nutationFunction;
  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public EOPHistory getEOPHistory() {
  83.         return eopHistory;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public TEMEProvider getNonInterpolatingProvider() {
  88.         return new TEMEProvider(conventions, eopHistory.getEOPHistoryWithoutCachedTidalCorrection(),
  89.                 obliquityFunction, nutationFunction);
  90.     }

  91.     /** {@inheritDoc} */
  92.     @Override
  93.     public Transform getTransform(final AbsoluteDate date) {
  94.         final double eqe = getEquationOfEquinoxes(date);
  95.         return new Transform(date, new Rotation(Vector3D.PLUS_K, eqe, RotationConvention.FRAME_TRANSFORM));
  96.     }

  97.     /** {@inheritDoc} */
  98.     @Override
  99.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  100.         final T eqe = getEquationOfEquinoxes(date);
  101.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  102.                                                               eqe,
  103.                                                               RotationConvention.FRAME_TRANSFORM));
  104.     }

  105.     /** Get the Equation of the Equinoxes at the current date.
  106.      * @param  date the date
  107.      * @return equation of the equinoxes
  108.      */
  109.     private double getEquationOfEquinoxes(final AbsoluteDate date) {

  110.         // compute nutation angles
  111.         final double[] angles = nutationFunction.value(date);

  112.         // nutation in longitude
  113.         double dPsi = angles[0];

  114.         if (eopHistory != null) {
  115.             // apply the corrections for the nutation parameters
  116.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  117.             dPsi += correction[0];
  118.         }

  119.         // mean obliquity of ecliptic
  120.         final double moe = obliquityFunction.value(date);

  121.         // original definition of equation of equinoxes
  122.         final double eqe = dPsi * FastMath.cos(moe);

  123.         // apply correction if needed
  124.         return eqe + angles[2];

  125.     }

  126.     /** Get the Equation of the Equinoxes at the current date.
  127.      * @param  date the date
  128.      * @param <T> type of the field elements
  129.      * @return equation of the equinoxes
  130.      */
  131.     private <T extends CalculusFieldElement<T>> T getEquationOfEquinoxes(final FieldAbsoluteDate<T> date) {

  132.         // compute nutation angles
  133.         final T[] angles = nutationFunction.value(date);

  134.         // nutation in longitude
  135.         T dPsi = angles[0];

  136.         if (eopHistory != null) {
  137.             // apply the corrections for the nutation parameters
  138.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  139.             dPsi = dPsi.add(correction[0]);
  140.         }

  141.         // mean obliquity of ecliptic
  142.         final T moe = obliquityFunction.value(date);

  143.         // original definition of equation of equinoxes
  144.         final T eqe = dPsi.multiply(moe.cos());

  145.         // apply correction if needed
  146.         return eqe.add(angles[2]);

  147.     }

  148. }