GTODProvider.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.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitInternalError;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.time.TimeScalarFunction;
  30. import org.orekit.time.TimeScalesFactory;
  31. import org.orekit.time.UT1Scale;
  32. import org.orekit.utils.Constants;
  33. import org.orekit.utils.IERSConventions;

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

  43.     /** Serializable UID. */
  44.     private static final long serialVersionUID = 20141228L;

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

  47.     /** Conventions. */
  48.     private final IERSConventions conventions;

  49.     /** EOP history. */
  50.     private final EOPHistory eopHistory;

  51.     /** GAST function. */
  52.     private final transient TimeScalarFunction gastFunction;

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

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

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

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

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

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

  85.         // set up the transform from parent TOD
  86.         return new Transform(date, new Rotation(Vector3D.PLUS_K, gast, RotationConvention.FRAME_TRANSFORM), rotationRate);

  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

  91.         // compute Greenwich apparent sidereal time, in radians
  92.         final T gast = gastFunction.value(date);

  93.         // compute true angular rotation of Earth, in rad/s
  94.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  95.         final T omp = lod.multiply(-1.0 / Constants.JULIAN_DAY).add(1).multiply(AVE);
  96.         final FieldVector3D<T> rotationRate = new FieldVector3D<>(date.getField().getZero(),
  97.                                                                   date.getField().getZero(),
  98.                                                                   date.getField().getZero().add(omp));

  99.         // set up the transform from parent TOD
  100.         return new FieldTransform<>(date,
  101.                                     new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  102.                                                         gast, RotationConvention.FRAME_TRANSFORM),
  103.                                     rotationRate);

  104.     }

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

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

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

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

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

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

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

  141.     }

  142. }