TEMEProvider.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  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.errors.OrekitException;
  27. import org.orekit.errors.OrekitInternalError;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.time.TimeVectorFunction;
  31. import org.orekit.time.TimeScalarFunction;
  32. import org.orekit.utils.IERSConventions;

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

  42.     /** Serializable UID. */
  43.     private static final long serialVersionUID = 20131209L;

  44.     /** Conventions. */
  45.     private final IERSConventions conventions;

  46.     /** EOP history. */
  47.     private final EOPHistory eopHistory;

  48.     /** Function computing the mean obliquity. */
  49.     private final transient TimeScalarFunction obliquityFunction;

  50.     /** Function computing the nutation angles. */
  51.     private final transient TimeVectorFunction nutationFunction;

  52.     /** Simple constructor.
  53.      * @param conventions IERS conventions to apply
  54.      * @param eopHistory EOP history
  55.      */
  56.     TEMEProvider(final IERSConventions conventions, final EOPHistory eopHistory) {
  57.         this.conventions       = conventions;
  58.         this.eopHistory        = eopHistory;
  59.         this.obliquityFunction = conventions.getMeanObliquityFunction();
  60.         this.nutationFunction  = conventions.getNutationFunction();
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public EOPHistory getEOPHistory() {
  65.         return eopHistory;
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public TEMEProvider getNonInterpolatingProvider() {
  70.         return new TEMEProvider(conventions, eopHistory.getNonInterpolatingEOPHistory());
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public Transform getTransform(final AbsoluteDate date) {
  75.         final double eqe = getEquationOfEquinoxes(date);
  76.         return new Transform(date, new Rotation(Vector3D.PLUS_K, eqe, RotationConvention.FRAME_TRANSFORM));
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  81.         final T eqe = getEquationOfEquinoxes(date);
  82.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  83.                                                               eqe,
  84.                                                               RotationConvention.FRAME_TRANSFORM));
  85.     }

  86.     /** Get the Equation of the Equinoxes at the current date.
  87.      * @param  date the date
  88.      * @return equation of the equinoxes
  89.      */
  90.     private double getEquationOfEquinoxes(final AbsoluteDate date) {

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

  93.         // nutation in longitude
  94.         double dPsi = angles[0];

  95.         if (eopHistory != null) {
  96.             // apply the corrections for the nutation parameters
  97.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  98.             dPsi += correction[0];
  99.         }

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

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

  104.         // apply correction if needed
  105.         return eqe + angles[2];

  106.     }

  107.     /** Get the Equation of the Equinoxes at the current date.
  108.      * @param  date the date
  109.      * @param <T> type of the field elements
  110.      * @return equation of the equinoxes
  111.      */
  112.     private <T extends RealFieldElement<T>> T getEquationOfEquinoxes(final FieldAbsoluteDate<T> date) {

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

  115.         // nutation in longitude
  116.         T dPsi = angles[0];

  117.         if (eopHistory != null) {
  118.             // apply the corrections for the nutation parameters
  119.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  120.             dPsi = dPsi.add(correction[0]);
  121.         }

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

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

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

  128.     }

  129.     /** Replace the instance with a data transfer object for serialization.
  130.      * <p>
  131.      * This intermediate class serializes only the frame key.
  132.      * </p>
  133.      * @return data transfer object that will be serialized
  134.      */
  135.     private Object writeReplace() {
  136.         return new DataTransferObject(conventions, eopHistory);
  137.     }

  138.     /** Internal class used only for serialization. */
  139.     private static class DataTransferObject implements Serializable {

  140.         /** Serializable UID. */
  141.         private static final long serialVersionUID = 20131209L;

  142.         /** Conventions. */
  143.         private final IERSConventions conventions;

  144.         /** EOP history. */
  145.         private final EOPHistory eopHistory;

  146.         /** Simple constructor.
  147.          * @param conventions IERS conventions to apply
  148.          * @param eopHistory EOP history
  149.          */
  150.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  151.             this.conventions = conventions;
  152.             this.eopHistory  = eopHistory;
  153.         }

  154.         /** Replace the deserialized data transfer object with a {@link TEMEProvider}.
  155.          * @return replacement {@link TEMEProvider}
  156.          */
  157.         private Object readResolve() {
  158.             try {
  159.                 // retrieve a managed frame
  160.                 return new TEMEProvider(conventions, eopHistory);
  161.             } catch (OrekitException oe) {
  162.                 throw new OrekitInternalError(oe);
  163.             }
  164.         }

  165.     }

  166. }