TIRFProvider.java

  1. /* Copyright 2002-2023 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.         // compute proper rotation
  75.         final double correctedERA = era.value(date);

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

  80.         // set up the transform from parent CIRF
  81.         final Rotation rotation     = new Rotation(Vector3D.PLUS_K, correctedERA, RotationConvention.FRAME_TRANSFORM);
  82.         return new Transform(date, rotation, rotationRate);

  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public StaticTransform getStaticTransform(final AbsoluteDate date) {
  87.         // compute proper rotation
  88.         final double correctedERA = era.value(date);
  89.         // set up the transform from parent CIRF
  90.         final Rotation rotation = new Rotation(
  91.                 Vector3D.PLUS_K,
  92.                 correctedERA,
  93.                 RotationConvention.FRAME_TRANSFORM);
  94.         return StaticTransform.of(date, rotation);
  95.     }

  96.     /** {@inheritDoc} */
  97.     @Override
  98.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

  99.         // compute proper rotation
  100.         final T correctedERA = era.value(date);

  101.         // compute true angular rotation of Earth, in rad/s
  102.         final T lod = (eopHistory == null) ? date.getField().getZero() : eopHistory.getLOD(date);
  103.         final T omp = lod.divide(Constants.JULIAN_DAY).subtract(1).multiply(-AVE);
  104.         final FieldVector3D<T> rotationRate = new FieldVector3D<>(omp, Vector3D.PLUS_K);

  105.         // set up the transform from parent CIRF
  106.         final FieldRotation<T> rotation = new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  107.                                                               correctedERA,
  108.                                                               RotationConvention.FRAME_TRANSFORM);
  109.         return new FieldTransform<>(date, rotation, rotationRate);

  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public <T extends CalculusFieldElement<T>> FieldStaticTransform<T> getStaticTransform(final FieldAbsoluteDate<T> date) {
  114.         // compute proper rotation
  115.         final T correctedERA = era.value(date);
  116.         // set up the transform from parent CIRF
  117.         final FieldRotation<T> rotation = new FieldRotation<>(
  118.                 FieldVector3D.getPlusK(date.getField()),
  119.                 correctedERA,
  120.                 RotationConvention.FRAME_TRANSFORM);
  121.         return FieldStaticTransform.of(date, rotation);
  122.     }

  123.     /** Get the Earth Rotation Angle at the current date.
  124.      * @param  date the date
  125.      * @return Earth Rotation Angle at the current date in radians
  126.      */
  127.     public double getEarthRotationAngle(final AbsoluteDate date) {
  128.         return MathUtils.normalizeAngle(era.value(date), 0);
  129.     }

  130.     /** Replace the instance with a data transfer object for serialization.
  131.      * <p>
  132.      * This intermediate class serializes only the frame key.
  133.      * </p>
  134.      * @return data transfer object that will be serialized
  135.      */
  136.     @DefaultDataContext
  137.     private Object writeReplace() {
  138.         return new DataTransferObject(eopHistory);
  139.     }

  140.     /** Internal class used only for serialization. */
  141.     @DefaultDataContext
  142.     private static class DataTransferObject implements Serializable {

  143.         /** Serializable UID. */
  144.         private static final long serialVersionUID = 20131209L;

  145.         /** EOP history. */
  146.         private final EOPHistory eopHistory;

  147.         /** Simple constructor.
  148.          * @param eopHistory EOP history
  149.          */
  150.         DataTransferObject(final EOPHistory eopHistory) {
  151.             this.eopHistory = eopHistory;
  152.         }

  153.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  154.          * @return replacement {@link TIRFProvider}
  155.          */
  156.         private Object readResolve() {
  157.             try {
  158.                 // retrieve a managed frame
  159.                 return new TIRFProvider(eopHistory,
  160.                         DataContext.getDefault().getTimeScales().getUT1(eopHistory));
  161.             } catch (OrekitException oe) {
  162.                 throw new OrekitInternalError(oe);
  163.             }
  164.         }

  165.     }

  166. }