GTODProvider.java

  1. /* Copyright 2002-2022 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.CalculusFieldElement;
  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.      * @param conventions IERS conventions to use
  57.      * @param eopHistory EOP history (may be null)
  58.      * @param timeScales  set of time scales to use.
  59.      * @since 10.1
  60.      */
  61.     protected GTODProvider(final IERSConventions conventions,
  62.                            final EOPHistory eopHistory,
  63.                            final TimeScales timeScales) {
  64.         final TimeScale ut1 = eopHistory == null ?
  65.                 timeScales.getUTC() : // UT1 wihthout EOP is UTC
  66.                 timeScales.getUT1(eopHistory.getConventions(), eopHistory.isSimpleEop());
  67.         this.conventions   = conventions;
  68.         this.eopHistory    = eopHistory;
  69.         this.gastFunction  = conventions.getGASTFunction(ut1, eopHistory, timeScales);
  70.     }

  71.     /**
  72.      * Private constructor.
  73.      *
  74.      * @param conventions  IERS conventions to use
  75.      * @param eopHistory   EOP history (may be null)
  76.      * @param gastFunction GAST function
  77.      */
  78.     private GTODProvider(final IERSConventions conventions,
  79.                          final EOPHistory eopHistory,
  80.                          final TimeScalarFunction gastFunction) {
  81.         this.conventions = conventions;
  82.         this.eopHistory = eopHistory;
  83.         this.gastFunction = gastFunction;
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     public EOPHistory getEOPHistory() {
  88.         return eopHistory;
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     public GTODProvider getNonInterpolatingProvider() {
  93.         return new GTODProvider(conventions, eopHistory.getNonInterpolatingEOPHistory(),
  94.                 gastFunction);
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public Transform getTransform(final AbsoluteDate date) {

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

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

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

  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public StaticTransform getStaticTransform(final AbsoluteDate date) {

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

  113.         // set up the transform from parent TOD
  114.         return StaticTransform.of(
  115.                 date,
  116.                 new Rotation(Vector3D.PLUS_K, gast, RotationConvention.FRAME_TRANSFORM));

  117.     }

  118.     /** {@inheritDoc} */
  119.     @Override
  120.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

  123.         // compute true angular rotation of Earth, in rad/s
  124.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  125.         final T omp = lod.multiply(-1.0 / Constants.JULIAN_DAY).add(1).multiply(AVE);
  126.         final FieldVector3D<T> rotationRate = new FieldVector3D<>(date.getField().getZero(),
  127.                                                                   date.getField().getZero(),
  128.                                                                   date.getField().getZero().add(omp));

  129.         // set up the transform from parent TOD
  130.         return new FieldTransform<>(date,
  131.                                     new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  132.                                                         gast, RotationConvention.FRAME_TRANSFORM),
  133.                                     rotationRate);

  134.     }

  135.     /** Replace the instance with a data transfer object for serialization.
  136.      * <p>
  137.      * This intermediate class serializes only the frame key.
  138.      * </p>
  139.      * @return data transfer object that will be serialized
  140.      */
  141.     @DefaultDataContext
  142.     private Object writeReplace() {
  143.         return new DataTransferObject(conventions, eopHistory);
  144.     }

  145.     /** Internal class used only for serialization. */
  146.     @DefaultDataContext
  147.     private static class DataTransferObject implements Serializable {

  148.         /** Serializable UID. */
  149.         private static final long serialVersionUID = 20131209L;

  150.         /** Conventions. */
  151.         private final IERSConventions conventions;

  152.         /** EOP history. */
  153.         private final EOPHistory eopHistory;

  154.         /** Simple constructor.
  155.          * @param conventions IERS conventions to apply
  156.          * @param eopHistory EOP history
  157.          */
  158.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  159.             this.conventions = conventions;
  160.             this.eopHistory  = eopHistory;
  161.         }

  162.         /** Replace the deserialized data transfer object with a {@link GTODProvider}.
  163.          * @return replacement {@link GTODProvider}
  164.          */
  165.         private Object readResolve() {
  166.             try {
  167.                 // retrieve a managed frame
  168.                 return new GTODProvider(conventions, eopHistory,
  169.                         DataContext.getDefault().getTimeScales());
  170.             } catch (OrekitException oe) {
  171.                 throw new OrekitInternalError(oe);
  172.             }
  173.         }

  174.     }

  175. }