GTODProvider.java

  1. /* Copyright 2002-2019 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.      */
  57.     protected GTODProvider(final IERSConventions conventions, final EOPHistory eopHistory) {
  58.         final UT1Scale ut1 = TimeScalesFactory.getUT1(eopHistory);
  59.         this.conventions   = conventions;
  60.         this.eopHistory    = eopHistory;
  61.         this.gastFunction  = conventions.getGASTFunction(ut1, eopHistory);
  62.     }

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

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public GTODProvider getNonInterpolatingProvider() {
  71.         return new GTODProvider(conventions, eopHistory.getNonInterpolatingEOPHistory());
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     public Transform getTransform(final AbsoluteDate date) {

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

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

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

  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

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

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

  101.     }

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

  111.     /** Internal class used only for serialization. */
  112.     private static class DataTransferObject implements Serializable {

  113.         /** Serializable UID. */
  114.         private static final long serialVersionUID = 20131209L;

  115.         /** Conventions. */
  116.         private final IERSConventions conventions;

  117.         /** EOP history. */
  118.         private final EOPHistory eopHistory;

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

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

  138.     }

  139. }