TEMEProvider.java

  1. /* Copyright 2002-2016 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.apache.commons.math3.geometry.euclidean.threed.Rotation;
  20. import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
  21. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  22. import org.apache.commons.math3.util.FastMath;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitInternalError;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.TimeFunction;
  27. import org.orekit.utils.IERSConventions;

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

  37.     /** Serializable UID. */
  38.     private static final long serialVersionUID = 20131209L;

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

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

  43.     /** Function computing the mean obliquity. */
  44.     private final transient TimeFunction<Double> obliquityFunction;

  45.     /** Function computing the nutation angles. */
  46.     private final transient TimeFunction<double[]> nutationFunction;

  47.     /** Simple constructor.
  48.      * @param conventions IERS conventions to apply
  49.      * @param eopHistory EOP history
  50.      * @exception OrekitException if the nutation model data embedded in the
  51.      * library cannot be read
  52.      */
  53.     TEMEProvider(final IERSConventions conventions, final EOPHistory eopHistory)
  54.         throws OrekitException {
  55.         this.conventions       = conventions;
  56.         this.eopHistory        = eopHistory;
  57.         this.obliquityFunction = conventions.getMeanObliquityFunction();
  58.         this.nutationFunction  = conventions.getNutationFunction();
  59.     }

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

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

  71.     /** Get the transform from True Of Date date.
  72.      * @param date new value of the date
  73.      * @return transform at the specified date
  74.      * @exception OrekitException if the nutation model data embedded in the
  75.      * library cannot be read
  76.      */
  77.     public synchronized Transform getTransform(final AbsoluteDate date) throws OrekitException {
  78.         final double eqe = getEquationOfEquinoxes(date);
  79.         return new Transform(date, new Rotation(Vector3D.PLUS_K, eqe, RotationConvention.FRAME_TRANSFORM));
  80.     }

  81.     /** Get the Equation of the Equinoxes at the current date.
  82.      * @param  date the date
  83.      * @return equation of the equinoxes
  84.      * @exception OrekitException if nutation model cannot be computed
  85.      */
  86.     private double getEquationOfEquinoxes(final AbsoluteDate date)
  87.         throws OrekitException {

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

  90.         // nutation in longitude
  91.         double dPsi = angles[0];

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

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

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

  101.         // apply correction if needed
  102.         return eqe + angles[2];

  103.     }

  104.     /** Replace the instance with a data transfer object for serialization.
  105.      * <p>
  106.      * This intermediate class serializes only the frame key.
  107.      * </p>
  108.      * @return data transfer object that will be serialized
  109.      */
  110.     private Object writeReplace() {
  111.         return new DataTransferObject(conventions, eopHistory);
  112.     }

  113.     /** Internal class used only for serialization. */
  114.     private static class DataTransferObject implements Serializable {

  115.         /** Serializable UID. */
  116.         private static final long serialVersionUID = 20131209L;

  117.         /** Conventions. */
  118.         private final IERSConventions conventions;

  119.         /** EOP history. */
  120.         private final EOPHistory eopHistory;

  121.         /** Simple constructor.
  122.          * @param conventions IERS conventions to apply
  123.          * @param eopHistory EOP history
  124.          */
  125.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  126.             this.conventions = conventions;
  127.             this.eopHistory  = eopHistory;
  128.         }

  129.         /** Replace the deserialized data transfer object with a {@link TEMEProvider}.
  130.          * @return replacement {@link TEMEProvider}
  131.          */
  132.         private Object readResolve() {
  133.             try {
  134.                 // retrieve a managed frame
  135.                 return new TEMEProvider(conventions, eopHistory);
  136.             } catch (OrekitException oe) {
  137.                 throw new OrekitInternalError(oe);
  138.             }
  139.         }

  140.     }

  141. }