TEMEProvider.java

  1. /* Copyright 2002-2018 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.      * @exception OrekitException if the nutation model data embedded in the
  56.      * library cannot be read
  57.      */
  58.     TEMEProvider(final IERSConventions conventions, final EOPHistory eopHistory)
  59.         throws OrekitException {
  60.         this.conventions       = conventions;
  61.         this.eopHistory        = eopHistory;
  62.         this.obliquityFunction = conventions.getMeanObliquityFunction();
  63.         this.nutationFunction  = conventions.getNutationFunction();
  64.     }

  65.     /** {@inheritDoc} */
  66.     @Override
  67.     public EOPHistory getEOPHistory() {
  68.         return eopHistory;
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public TEMEProvider getNonInterpolatingProvider()
  73.         throws OrekitException {
  74.         return new TEMEProvider(conventions, eopHistory.getNonInterpolatingEOPHistory());
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {
  79.         final double eqe = getEquationOfEquinoxes(date);
  80.         return new Transform(date, new Rotation(Vector3D.PLUS_K, eqe, RotationConvention.FRAME_TRANSFORM));
  81.     }

  82.     /** {@inheritDoc} */
  83.     @Override
  84.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  85.         throws OrekitException {
  86.         final T eqe = getEquationOfEquinoxes(date);
  87.         return new FieldTransform<>(date, new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  88.                                                               eqe,
  89.                                                               RotationConvention.FRAME_TRANSFORM));
  90.     }

  91.     /** Get the Equation of the Equinoxes at the current date.
  92.      * @param  date the date
  93.      * @return equation of the equinoxes
  94.      * @exception OrekitException if nutation model cannot be computed
  95.      */
  96.     private double getEquationOfEquinoxes(final AbsoluteDate date)
  97.         throws OrekitException {

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

  100.         // nutation in longitude
  101.         double dPsi = angles[0];

  102.         if (eopHistory != null) {
  103.             // apply the corrections for the nutation parameters
  104.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  105.             dPsi += correction[0];
  106.         }

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

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

  111.         // apply correction if needed
  112.         return eqe + angles[2];

  113.     }

  114.     /** Get the Equation of the Equinoxes at the current date.
  115.      * @param  date the date
  116.      * @param <T> type of the field elements
  117.      * @return equation of the equinoxes
  118.      * @exception OrekitException if nutation model cannot be computed
  119.      */
  120.     private <T extends RealFieldElement<T>> T getEquationOfEquinoxes(final FieldAbsoluteDate<T> date)
  121.         throws OrekitException {

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

  124.         // nutation in longitude
  125.         T dPsi = angles[0];

  126.         if (eopHistory != null) {
  127.             // apply the corrections for the nutation parameters
  128.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  129.             dPsi = dPsi.add(correction[0]);
  130.         }

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

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

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

  137.     }

  138.     /** Replace the instance with a data transfer object for serialization.
  139.      * <p>
  140.      * This intermediate class serializes only the frame key.
  141.      * </p>
  142.      * @return data transfer object that will be serialized
  143.      */
  144.     private Object writeReplace() {
  145.         return new DataTransferObject(conventions, eopHistory);
  146.     }

  147.     /** Internal class used only for serialization. */
  148.     private static class DataTransferObject implements Serializable {

  149.         /** Serializable UID. */
  150.         private static final long serialVersionUID = 20131209L;

  151.         /** Conventions. */
  152.         private final IERSConventions conventions;

  153.         /** EOP history. */
  154.         private final EOPHistory eopHistory;

  155.         /** Simple constructor.
  156.          * @param conventions IERS conventions to apply
  157.          * @param eopHistory EOP history
  158.          */
  159.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  160.             this.conventions = conventions;
  161.             this.eopHistory  = eopHistory;
  162.         }

  163.         /** Replace the deserialized data transfer object with a {@link TEMEProvider}.
  164.          * @return replacement {@link TEMEProvider}
  165.          */
  166.         private Object readResolve() {
  167.             try {
  168.                 // retrieve a managed frame
  169.                 return new TEMEProvider(conventions, eopHistory);
  170.             } catch (OrekitException oe) {
  171.                 throw new OrekitInternalError(oe);
  172.             }
  173.         }

  174.     }

  175. }