TIRFProvider.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.hipparchus.util.MathUtils;
  26. import org.orekit.annotation.DefaultDataContext;
  27. import org.orekit.data.DataContext;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitInternalError;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.time.TimeScalarFunction;
  33. import org.orekit.time.TimeScale;
  34. import org.orekit.utils.Constants;

  35. /** Terrestrial Intermediate Reference Frame.
  36.  * <p> The pole motion is not considered : Pseudo Earth Fixed Frame. It handles
  37.  * the earth rotation angle, its parent frame is the {@link CIRFProvider}</p>
  38.  */
  39. class TIRFProvider implements EOPBasedTransformProvider {

  40.     /** Serializable UID. */
  41.     private static final long serialVersionUID = 20130919L;

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

  44.     /** EOP history. */
  45.     private final EOPHistory eopHistory;

  46.     /** UT1 time scale. */
  47.     private final transient TimeScale ut1;

  48.     /** ERA function. */
  49.     private final transient TimeScalarFunction era;

  50.     /** Simple constructor.
  51.      * @param eopHistory EOP history
  52.      * @param ut1 the UT1 time scale.
  53.      */
  54.     protected TIRFProvider(final EOPHistory eopHistory, final TimeScale ut1) {

  55.         this.ut1        = ut1;
  56.         this.eopHistory = eopHistory;
  57.         this.era        = eopHistory.getConventions().getEarthOrientationAngleFunction(
  58.                 ut1,
  59.                 eopHistory.getTimeScales().getTAI());

  60.     }

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

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public TIRFProvider getNonInterpolatingProvider() {
  69.         return new TIRFProvider(eopHistory.getEOPHistoryWithoutCachedTidalCorrection(), ut1);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public Transform getTransform(final AbsoluteDate date) {
  74.         return new Transform(date, getRotation(date), getRotationRate(date));
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public KinematicTransform getKinematicTransform(final AbsoluteDate date) {
  79.         return KinematicTransform.of(date, getRotation(date), getRotationRate(date));
  80.     }

  81.     /** {@inheritDoc} */
  82.     @Override
  83.     public StaticTransform getStaticTransform(final AbsoluteDate date) {
  84.         return StaticTransform.of(date, getRotation(date));
  85.     }

  86.     /** Form rotation to parent CIRF.
  87.      * @param date transform date
  88.      * @return rotation to parent at date
  89.      * @since 12.1
  90.      */
  91.     private Rotation getRotation(final AbsoluteDate date) {
  92.         // compute proper rotation
  93.         final double correctedERA = era.value(date);
  94.         // set up the transform from parent CIRF
  95.         return new Rotation(Vector3D.PLUS_K, correctedERA, RotationConvention.FRAME_TRANSFORM);
  96.     }

  97.     /** Form rotation rate w.r.t. parent CIRF.
  98.      * @param date transform date
  99.      * @return rotation rate at date
  100.      * @since 12.1
  101.      */
  102.     private Vector3D getRotationRate(final AbsoluteDate date) {
  103.         // compute true angular rotation of Earth, in rad/s
  104.         final double lod = (eopHistory == null) ? 0.0 : eopHistory.getLOD(date);
  105.         final double omp = AVE * (1 - lod / Constants.JULIAN_DAY);
  106.         return new Vector3D(omp, Vector3D.PLUS_K);
  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {
  111.         return new FieldTransform<>(date, getRotation(date), getRotationRate(date));
  112.     }

  113.     /** {@inheritDoc} */
  114.     @Override
  115.     public <T extends CalculusFieldElement<T>> FieldKinematicTransform<T> getKinematicTransform(final FieldAbsoluteDate<T> date) {
  116.         return FieldKinematicTransform.of(date, getRotation(date), getRotationRate(date));
  117.     }

  118.     /** {@inheritDoc} */
  119.     @Override
  120.     public <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getStaticTransform(final FieldAbsoluteDate<T> date) {
  121.         return FieldStaticTransform.of(date, getRotation(date));
  122.     }

  123.     /** Form rotation to parent CIRF.
  124.      * @param <T> type of the elements
  125.      * @param date transform date
  126.      * @return rotation to parent at date
  127.      * @since 12.1
  128.      */
  129.     private <T extends CalculusFieldElement<T>> FieldRotation<T> getRotation(final FieldAbsoluteDate<T> date) {
  130.         // compute proper rotation
  131.         final T correctedERA = era.value(date);

  132.         // set up the transform from parent CIRF
  133.         return new FieldRotation<>(
  134.                 FieldVector3D.getPlusK(date.getField()),
  135.                 correctedERA,
  136.                 RotationConvention.FRAME_TRANSFORM);
  137.     }

  138.     /** Form rotation rate w.r.t. parent CIRF.
  139.      * @param <T> type of the elements
  140.      * @param date transform date
  141.      * @return rotation rate at date
  142.      * @since 12.1
  143.      */
  144.     private <T extends CalculusFieldElement<T>> FieldVector3D<T> getRotationRate(final FieldAbsoluteDate<T> date) {
  145.         // compute true angular rotation of Earth, in rad/s
  146.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  147.         final T omp = lod.divide(Constants.JULIAN_DAY).subtract(1).multiply(-AVE);
  148.         return new FieldVector3D<>(omp, Vector3D.PLUS_K);
  149.     }

  150.     /** Get the Earth Rotation Angle at the current date.
  151.      * @param  date the date
  152.      * @return Earth Rotation Angle at the current date in radians
  153.      */
  154.     public double getEarthRotationAngle(final AbsoluteDate date) {
  155.         return MathUtils.normalizeAngle(era.value(date), 0);
  156.     }

  157.     /** Replace the instance with a data transfer object for serialization.
  158.      * <p>
  159.      * This intermediate class serializes only the frame key.
  160.      * </p>
  161.      * @return data transfer object that will be serialized
  162.      */
  163.     @DefaultDataContext
  164.     private Object writeReplace() {
  165.         return new DataTransferObject(eopHistory);
  166.     }

  167.     /** Internal class used only for serialization. */
  168.     @DefaultDataContext
  169.     private static class DataTransferObject implements Serializable {

  170.         /** Serializable UID. */
  171.         private static final long serialVersionUID = 20131209L;

  172.         /** EOP history. */
  173.         private final EOPHistory eopHistory;

  174.         /** Simple constructor.
  175.          * @param eopHistory EOP history
  176.          */
  177.         DataTransferObject(final EOPHistory eopHistory) {
  178.             this.eopHistory = eopHistory;
  179.         }

  180.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  181.          * @return replacement {@link TIRFProvider}
  182.          */
  183.         private Object readResolve() {
  184.             try {
  185.                 // retrieve a managed frame
  186.                 return new TIRFProvider(eopHistory,
  187.                         DataContext.getDefault().getTimeScales().getUT1(eopHistory));
  188.             } catch (OrekitException oe) {
  189.                 throw new OrekitInternalError(oe);
  190.             }
  191.         }

  192.     }

  193. }