TEMEProvider.java

  1. /* Copyright 2002-2013 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.Vector3D;
  21. import org.apache.commons.math3.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.TimeFunction;
  25. import org.orekit.utils.IERSConventions;

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

  35.     /** Serializable UID. */
  36.     private static final long serialVersionUID = 20131209L;

  37.     /** Conventions. */
  38.     private final IERSConventions conventions;

  39.     /** EOP history. */
  40.     private final EOPHistory eopHistory;

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

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

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

  58.     /** Get the EOP history.
  59.      * @return EOP history
  60.      * @since 6.1
  61.      */
  62.     EOPHistory getEOPHistory() {
  63.         return eopHistory;
  64.     }

  65.     /** Get the transform from True Of Date date.
  66.      * @param date new value of the date
  67.      * @return transform at the specified date
  68.      * @exception OrekitException if the nutation model data embedded in the
  69.      * library cannot be read
  70.      */
  71.     public synchronized Transform getTransform(final AbsoluteDate date) throws OrekitException {
  72.         final double eqe = getEquationOfEquinoxes(date);
  73.         return new Transform(date, new Rotation(Vector3D.PLUS_K, -eqe));
  74.     }

  75.     /** Get the Equation of the Equinoxes at the current date.
  76.      * @param  date the date
  77.      * @return equation of the equinoxes
  78.      * @exception OrekitException if nutation model cannot be computed
  79.      */
  80.     private double getEquationOfEquinoxes(final AbsoluteDate date)
  81.         throws OrekitException {

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

  84.         // nutation in longitude
  85.         double dPsi = angles[0];

  86.         if (eopHistory != null) {
  87.             // apply the corrections for the nutation parameters
  88.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  89.             dPsi += correction[0];
  90.         }

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

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

  95.         // apply correction if needed
  96.         return eqe + angles[2];

  97.     }

  98.     /** Replace the instance with a data transfer object for serialization.
  99.      * <p>
  100.      * This intermediate class serializes only the frame key.
  101.      * </p>
  102.      * @return data transfer object that will be serialized
  103.      */
  104.     private Object writeReplace() {
  105.         return new DataTransferObject(conventions, eopHistory);
  106.     }

  107.     /** Internal class used only for serialization. */
  108.     private static class DataTransferObject implements Serializable {

  109.         /** Serializable UID. */
  110.         private static final long serialVersionUID = 20131209L;

  111.         /** Conventions. */
  112.         private final IERSConventions conventions;

  113.         /** EOP history. */
  114.         private final EOPHistory eopHistory;

  115.         /** Simple constructor.
  116.          * @param conventions IERS conventions to apply
  117.          * @param eopHistory EOP history
  118.          */
  119.         public DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  120.             this.conventions = conventions;
  121.             this.eopHistory  = eopHistory;
  122.         }

  123.         /** Replace the deserialized data transfer object with a {@link TEMEProvider}.
  124.          * @return replacement {@link TEMEProvider}
  125.          */
  126.         private Object readResolve() {
  127.             try {
  128.                 // retrieve a managed frame
  129.                 return new TEMEProvider(conventions, eopHistory);
  130.             } catch (OrekitException oe) {
  131.                 throw OrekitException.createInternalError(oe);
  132.             }
  133.         }

  134.     }

  135. }