TEMEProvider.java

  1. /* Copyright 2002-2023 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 java.io.Serializable;

  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Rotation;
  23. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.hipparchus.util.FastMath;
  26. import org.orekit.annotation.DefaultDataContext;
  27. import org.orekit.data.DataContext;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitInternalError;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.time.TimeScalarFunction;
  33. import org.orekit.time.TimeScales;
  34. import org.orekit.time.TimeVectorFunction;
  35. import org.orekit.utils.IERSConventions;

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

  45.     /** Serializable UID. */
  46.     private static final long serialVersionUID = 20131209L;

  47.     /** Conventions. */
  48.     private final IERSConventions conventions;

  49.     /** EOP history. */
  50.     private final EOPHistory eopHistory;

  51.     /** Function computing the mean obliquity. */
  52.     private final transient TimeScalarFunction obliquityFunction;

  53.     /** Function computing the nutation angles. */
  54.     private final transient TimeVectorFunction nutationFunction;

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

  70.     /**
  71.      * Private constructor.
  72.      *
  73.      * @param conventions       IERS conventions to apply
  74.      * @param eopHistory        EOP history
  75.      * @param obliquityFunction to use.
  76.      * @param nutationFunction  to use.
  77.      */
  78.     private TEMEProvider(final IERSConventions conventions,
  79.                          final EOPHistory eopHistory,
  80.                          final TimeScalarFunction obliquityFunction,
  81.                          final TimeVectorFunction nutationFunction) {
  82.         this.conventions = conventions;
  83.         this.eopHistory = eopHistory;
  84.         this.obliquityFunction = obliquityFunction;
  85.         this.nutationFunction = nutationFunction;
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public EOPHistory getEOPHistory() {
  90.         return eopHistory;
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     public TEMEProvider getNonInterpolatingProvider() {
  95.         return new TEMEProvider(conventions, eopHistory.getEOPHistoryWithoutCachedTidalCorrection(),
  96.                 obliquityFunction, nutationFunction);
  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public Transform getTransform(final AbsoluteDate date) {
  101.         final double eqe = getEquationOfEquinoxes(date);
  102.         return new Transform(date, new Rotation(Vector3D.PLUS_K, eqe, RotationConvention.FRAME_TRANSFORM));
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  107.         final T eqe = getEquationOfEquinoxes(date);
  108.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  109.                                                               eqe,
  110.                                                               RotationConvention.FRAME_TRANSFORM));
  111.     }

  112.     /** Get the Equation of the Equinoxes at the current date.
  113.      * @param  date the date
  114.      * @return equation of the equinoxes
  115.      */
  116.     private double getEquationOfEquinoxes(final AbsoluteDate date) {

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

  119.         // nutation in longitude
  120.         double dPsi = angles[0];

  121.         if (eopHistory != null) {
  122.             // apply the corrections for the nutation parameters
  123.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  124.             dPsi += correction[0];
  125.         }

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

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

  130.         // apply correction if needed
  131.         return eqe + angles[2];

  132.     }

  133.     /** Get the Equation of the Equinoxes at the current date.
  134.      * @param  date the date
  135.      * @param <T> type of the field elements
  136.      * @return equation of the equinoxes
  137.      */
  138.     private <T extends CalculusFieldElement<T>> T getEquationOfEquinoxes(final FieldAbsoluteDate<T> date) {

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

  141.         // nutation in longitude
  142.         T dPsi = angles[0];

  143.         if (eopHistory != null) {
  144.             // apply the corrections for the nutation parameters
  145.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  146.             dPsi = dPsi.add(correction[0]);
  147.         }

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

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

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

  154.     }

  155.     /** Replace the instance with a data transfer object for serialization.
  156.      * <p>
  157.      * This intermediate class serializes only the frame key.
  158.      * </p>
  159.      * @return data transfer object that will be serialized
  160.      */
  161.     @DefaultDataContext
  162.     private Object writeReplace() {
  163.         return new DataTransferObject(conventions, eopHistory);
  164.     }

  165.     /** Internal class used only for serialization. */
  166.     @DefaultDataContext
  167.     private static class DataTransferObject implements Serializable {

  168.         /** Serializable UID. */
  169.         private static final long serialVersionUID = 20131209L;

  170.         /** Conventions. */
  171.         private final IERSConventions conventions;

  172.         /** EOP history. */
  173.         private final EOPHistory eopHistory;

  174.         /** Simple constructor.
  175.          * @param conventions IERS conventions to apply
  176.          * @param eopHistory EOP history
  177.          */
  178.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  179.             this.conventions = conventions;
  180.             this.eopHistory  = eopHistory;
  181.         }

  182.         /** Replace the deserialized data transfer object with a {@link TEMEProvider}.
  183.          * @return replacement {@link TEMEProvider}
  184.          */
  185.         private Object readResolve() {
  186.             try {
  187.                 // retrieve a managed frame
  188.                 return new TEMEProvider(conventions, eopHistory,
  189.                         DataContext.getDefault().getTimeScales());
  190.             } catch (OrekitException oe) {
  191.                 throw new OrekitInternalError(oe);
  192.             }
  193.         }

  194.     }

  195. }