GTODProvider.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.analysis.differentiation.DerivativeStructure;
  20. import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
  21. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.TimeFunction;
  25. import org.orekit.time.TimeScalesFactory;
  26. import org.orekit.time.UT1Scale;
  27. import org.orekit.utils.Constants;
  28. import org.orekit.utils.IERSConventions;

  29. /** Greenwich True Of Date Frame, also known as True of Date Rotating frame (TDR)
  30.  * or Greenwich Rotating Coordinate frame (GCR).
  31.  * <p> This frame handles the sidereal time according to IAU-82 model.</p>
  32.  * <p> Its parent frame is the {@link TODProvider}.</p>
  33.  * <p> The pole motion is not applied here.</p>
  34.  * @author Pascal Parraud
  35.  * @author Thierry Ceolin
  36.  */
  37. public class GTODProvider implements TransformProvider {

  38.     /** Serializable UID. */
  39.     private static final long serialVersionUID = 20130922L;

  40.     /** Angular velocity of the Earth, in rad/s. */
  41.     private static final double AVE = 7.292115146706979e-5;

  42.     /** Conventions. */
  43.     private final IERSConventions conventions;

  44.     /** EOP history. */
  45.     private final EOPHistory eopHistory;

  46.     /** GMST function. */
  47.     private final transient TimeFunction<DerivativeStructure> gmstFunction;

  48.     /** GAST function. */
  49.     private final transient TimeFunction<DerivativeStructure> gastFunction;

  50.     /** Simple constructor.
  51.      * @param conventions IERS conventions to use
  52.      * @param eopHistory EOP history (may be null)
  53.      * @exception OrekitException if EOP parameters are desired but cannot be read
  54.      */
  55.     protected GTODProvider(final IERSConventions conventions, final EOPHistory eopHistory)
  56.         throws OrekitException {
  57.         final UT1Scale ut1 = TimeScalesFactory.getUT1(eopHistory);
  58.         this.conventions   = conventions;
  59.         this.eopHistory    = eopHistory;
  60.         this.gmstFunction  = conventions.getGMSTFunction(ut1);
  61.         this.gastFunction  = conventions.getGASTFunction(ut1, eopHistory);
  62.     }

  63.     /** Get the EOP history.
  64.      * @return EOP history
  65.      */
  66.     EOPHistory getEOPHistory() {
  67.         return eopHistory;
  68.     }

  69.     /** Get the transform from TOD at specified date.
  70.      * <p>The update considers the Earth rotation from IERS data.</p>
  71.      * @param date new value of the date
  72.      * @return transform at the specified date
  73.      * @exception OrekitException if the nutation model data embedded in the
  74.      * library cannot be read
  75.      */
  76.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

  77.         // compute Greenwich apparent sidereal time, in radians
  78.         final double gast = gastFunction.value(date).getValue();

  79.         // compute true angular rotation of Earth, in rad/s
  80.         final double lod = (eopHistory == null) ? 0.0 : eopHistory.getLOD(date);
  81.         final double omp = AVE * (1 - lod / Constants.JULIAN_DAY);
  82.         final Vector3D rotationRate = new Vector3D(omp, Vector3D.PLUS_K);

  83.         // set up the transform from parent TOD
  84.         return new Transform(date, new Rotation(Vector3D.PLUS_K, -gast), rotationRate);

  85.     }

  86.     /** Get the Greenwich mean sidereal time, in radians.
  87.      * @param date current date
  88.      * @return Greenwich mean sidereal time, in radians
  89.      * @exception OrekitException if UT1 time scale cannot be retrieved
  90.      * @deprecated as of 6.1, replaced by {@link IERSConventions#getGMSTFunction(org.orekit.time.TimeScale)}
  91.      */
  92.     @Deprecated
  93.     public double getGMST(final AbsoluteDate date) throws OrekitException {
  94.         return gmstFunction.value(date).getValue();
  95.     }

  96.     /** Get the Greenwich apparent sidereal time, in radians.
  97.      * @param date current date
  98.      * @return Greenwich apparent sidereal time, in radians
  99.      * @exception OrekitException if UT1 time scale cannot be retrieved
  100.      * @deprecated as of 6.1, replaced by {@link IERSConventions#getGASTFunction(org.orekit.time.TimeScale, EOPHistory)}
  101.      */
  102.     @Deprecated
  103.     public double getGAST(final AbsoluteDate date) throws OrekitException {
  104.         return gastFunction.value(date).getValue();
  105.     }

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

  115.     /** Internal class used only for serialization. */
  116.     private static class DataTransferObject implements Serializable {

  117.         /** Serializable UID. */
  118.         private static final long serialVersionUID = 20131209L;

  119.         /** Conventions. */
  120.         private final IERSConventions conventions;

  121.         /** EOP history. */
  122.         private final EOPHistory eopHistory;

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

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

  142.     }

  143. }