GTODProvider.java

  1. /* Copyright 2002-2020 CS GROUP
  2.  * Licensed to CS GROUP (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.annotation.DefaultDataContext;
  26. import org.orekit.data.DataContext;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitInternalError;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.time.TimeScalarFunction;
  32. import org.orekit.time.TimeScale;
  33. import org.orekit.time.TimeScales;
  34. import org.orekit.utils.Constants;
  35. import org.orekit.utils.IERSConventions;

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

  45.     /** Serializable UID. */
  46.     private static final long serialVersionUID = 20141228L;

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

  49.     /** Conventions. */
  50.     private final IERSConventions conventions;

  51.     /** EOP history. */
  52.     private final EOPHistory eopHistory;

  53.     /** GAST function. */
  54.     private final transient TimeScalarFunction gastFunction;

  55.     /** Simple constructor.
  56.      *
  57.      * <p>This method uses the {@link DataContext#getDefault() default data context} if
  58.      * {@code eopHistory == null}.
  59.      *
  60.      * @param conventions IERS conventions to use
  61.      * @param eopHistory EOP history (may be null)
  62.      * @deprecated use {@link #GTODProvider(IERSConventions, EOPHistory, TimeScales)}
  63.      * instead.
  64.      */
  65.     @Deprecated
  66.     @DefaultDataContext
  67.     protected GTODProvider(final IERSConventions conventions,
  68.                            final EOPHistory eopHistory) {
  69.         this(conventions, eopHistory,
  70.                 eopHistory == null ?
  71.                         DataContext.getDefault().getTimeScales() :
  72.                         eopHistory.getTimeScales());
  73.     }

  74.     /** Simple constructor.
  75.      * @param conventions IERS conventions to use
  76.      * @param eopHistory EOP history (may be null)
  77.      * @param timeScales  set of time scales to use.
  78.      * @since 10.1
  79.      */
  80.     protected GTODProvider(final IERSConventions conventions,
  81.                            final EOPHistory eopHistory,
  82.                            final TimeScales timeScales) {
  83.         final TimeScale ut1 = eopHistory == null ?
  84.                 timeScales.getUTC() : // UT1 wihthout EOP is UTC
  85.                 timeScales.getUT1(eopHistory.getConventions(), eopHistory.isSimpleEop());
  86.         this.conventions   = conventions;
  87.         this.eopHistory    = eopHistory;
  88.         this.gastFunction  = conventions.getGASTFunction(ut1, eopHistory, timeScales);
  89.     }

  90.     /**
  91.      * Private constructor.
  92.      *
  93.      * @param conventions  IERS conventions to use
  94.      * @param eopHistory   EOP history (may be null)
  95.      * @param gastFunction GAST function
  96.      */
  97.     private GTODProvider(final IERSConventions conventions,
  98.                          final EOPHistory eopHistory,
  99.                          final TimeScalarFunction gastFunction) {
  100.         this.conventions = conventions;
  101.         this.eopHistory = eopHistory;
  102.         this.gastFunction = gastFunction;
  103.     }

  104.     /** {@inheritDoc} */
  105.     @Override
  106.     public EOPHistory getEOPHistory() {
  107.         return eopHistory;
  108.     }

  109.     /** {@inheritDoc} */
  110.     @Override
  111.     public GTODProvider getNonInterpolatingProvider() {
  112.         return new GTODProvider(conventions, eopHistory.getNonInterpolatingEOPHistory(),
  113.                 gastFunction);
  114.     }

  115.     /** {@inheritDoc} */
  116.     @Override
  117.     public Transform getTransform(final AbsoluteDate date) {

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

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

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

  126.     }

  127.     /** {@inheritDoc} */
  128.     @Override
  129.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

  132.         // compute true angular rotation of Earth, in rad/s
  133.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  134.         final T omp = lod.multiply(-1.0 / Constants.JULIAN_DAY).add(1).multiply(AVE);
  135.         final FieldVector3D<T> rotationRate = new FieldVector3D<>(date.getField().getZero(),
  136.                                                                   date.getField().getZero(),
  137.                                                                   date.getField().getZero().add(omp));

  138.         // set up the transform from parent TOD
  139.         return new FieldTransform<>(date,
  140.                                     new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  141.                                                         gast, RotationConvention.FRAME_TRANSFORM),
  142.                                     rotationRate);

  143.     }

  144.     /** Replace the instance with a data transfer object for serialization.
  145.      * <p>
  146.      * This intermediate class serializes only the frame key.
  147.      * </p>
  148.      * @return data transfer object that will be serialized
  149.      */
  150.     @DefaultDataContext
  151.     private Object writeReplace() {
  152.         return new DataTransferObject(conventions, eopHistory);
  153.     }

  154.     /** Internal class used only for serialization. */
  155.     @DefaultDataContext
  156.     private static class DataTransferObject implements Serializable {

  157.         /** Serializable UID. */
  158.         private static final long serialVersionUID = 20131209L;

  159.         /** Conventions. */
  160.         private final IERSConventions conventions;

  161.         /** EOP history. */
  162.         private final EOPHistory eopHistory;

  163.         /** Simple constructor.
  164.          * @param conventions IERS conventions to apply
  165.          * @param eopHistory EOP history
  166.          */
  167.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  168.             this.conventions = conventions;
  169.             this.eopHistory  = eopHistory;
  170.         }

  171.         /** Replace the deserialized data transfer object with a {@link GTODProvider}.
  172.          * @return replacement {@link GTODProvider}
  173.          */
  174.         private Object readResolve() {
  175.             try {
  176.                 // retrieve a managed frame
  177.                 return new GTODProvider(conventions, eopHistory,
  178.                         DataContext.getDefault().getTimeScales());
  179.             } catch (OrekitException oe) {
  180.                 throw new OrekitInternalError(oe);
  181.             }
  182.         }

  183.     }

  184. }