GTODProvider.java

  1. /* Copyright 2002-2024 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.getEOPHistoryWithoutCachedTidalCorrection(),
  94.                 gastFunction);
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public Transform getTransform(final AbsoluteDate date) {
  99.         return new Transform(date, getRotation(date), getRotationRate(date));
  100.     }

  101.     /** {@inheritDoc} */
  102.     @Override
  103.     public KinematicTransform getKinematicTransform(final AbsoluteDate date) {
  104.         return KinematicTransform.of(date, getRotation(date), getRotationRate(date));
  105.     }

  106.     /** {@inheritDoc} */
  107.     @Override
  108.     public StaticTransform getStaticTransform(final AbsoluteDate date) {
  109.         return StaticTransform.of(date, getRotation(date));
  110.     }

  111.     /** Form rotation to parent TOD.
  112.      * @param date transform date
  113.      * @return rotation to parent at date
  114.      * @since 12.1
  115.      */
  116.     private Rotation getRotation(final AbsoluteDate date) {
  117.         // compute Greenwich apparent sidereal time, in radians
  118.         final double gast = gastFunction.value(date);

  119.         // set up the transform from parent TOD
  120.         return new Rotation(Vector3D.PLUS_K, gast, RotationConvention.FRAME_TRANSFORM);
  121.     }

  122.     /** Form rotation rate w.r.t. parent TOD.
  123.      * @param date transform date
  124.      * @return rotation rate at date
  125.      * @since 12.1
  126.      */
  127.     private Vector3D getRotationRate(final AbsoluteDate date) {
  128.         // compute true angular rotation of Earth, in rad/s
  129.         final double lod = (eopHistory == null) ? 0.0 : eopHistory.getLOD(date);
  130.         final double omp = AVE * (1 - lod / Constants.JULIAN_DAY);
  131.         return new Vector3D(omp, Vector3D.PLUS_K);
  132.     }

  133.     /** {@inheritDoc} */
  134.     @Override
  135.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  136.         return new FieldTransform<>(date, getRotation(date), getRotationRate(date));
  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     public <T extends CalculusFieldElement<T>> FieldKinematicTransform<T> getKinematicTransform(final FieldAbsoluteDate<T> date) {
  141.         return FieldKinematicTransform.of(date, getRotation(date), getRotationRate(date));
  142.     }

  143.     /** {@inheritDoc} */
  144.     @Override
  145.     public <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getStaticTransform(final FieldAbsoluteDate<T> date) {
  146.         return FieldStaticTransform.of(date, getRotation(date));
  147.     }

  148.     /** Form rotation to parent TOD.
  149.      * @param <T> type of the elements
  150.      * @param date transform date
  151.      * @return rotation to parent at date
  152.      * @since 12.1
  153.      */
  154.     private <T extends CalculusFieldElement<T>> FieldRotation<T> getRotation(final FieldAbsoluteDate<T> date) {
  155.         // compute Greenwich apparent sidereal time, in radians
  156.         final T gast = gastFunction.value(date);

  157.         // set up the transform from parent TOD
  158.         return new FieldRotation<>(FieldVector3D.getPlusK(date.getField()), gast, RotationConvention.FRAME_TRANSFORM);
  159.     }

  160.     /** Form rotation rate w.r.t. parent TOD.
  161.      * @param <T> type of the elements
  162.      * @param date transform date
  163.      * @return rotation rate at date
  164.      * @since 12.1
  165.      */
  166.     private <T extends CalculusFieldElement<T>> FieldVector3D<T> getRotationRate(final FieldAbsoluteDate<T> date) {
  167.         // compute true angular rotation of Earth, in rad/s
  168.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  169.         final T omp = lod.multiply(-1.0 / Constants.JULIAN_DAY).add(1).multiply(AVE);
  170.         return new FieldVector3D<>(date.getField().getZero(),
  171.                 date.getField().getZero(),
  172.                 date.getField().getZero().add(omp));
  173.     }

  174.     /** Replace the instance with a data transfer object for serialization.
  175.      * <p>
  176.      * This intermediate class serializes only the frame key.
  177.      * </p>
  178.      * @return data transfer object that will be serialized
  179.      */
  180.     @DefaultDataContext
  181.     private Object writeReplace() {
  182.         return new DataTransferObject(conventions, eopHistory);
  183.     }

  184.     /** Internal class used only for serialization. */
  185.     @DefaultDataContext
  186.     private static class DataTransferObject implements Serializable {

  187.         /** Serializable UID. */
  188.         private static final long serialVersionUID = 20131209L;

  189.         /** Conventions. */
  190.         private final IERSConventions conventions;

  191.         /** EOP history. */
  192.         private final EOPHistory eopHistory;

  193.         /** Simple constructor.
  194.          * @param conventions IERS conventions to apply
  195.          * @param eopHistory EOP history
  196.          */
  197.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  198.             this.conventions = conventions;
  199.             this.eopHistory  = eopHistory;
  200.         }

  201.         /** Replace the deserialized data transfer object with a {@link GTODProvider}.
  202.          * @return replacement {@link GTODProvider}
  203.          */
  204.         private Object readResolve() {
  205.             try {
  206.                 // retrieve a managed frame
  207.                 return new GTODProvider(conventions, eopHistory,
  208.                         DataContext.getDefault().getTimeScales());
  209.             } catch (OrekitException oe) {
  210.                 throw new OrekitInternalError(oe);
  211.             }
  212.         }

  213.     }

  214. }