TIRFProvider.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.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.getNonInterpolatingEOPHistory(), 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 <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

  87.         // compute proper rotation
  88.         final T correctedERA = era.value(date);

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

  93.         // set up the transform from parent CIRF
  94.         final FieldRotation<T> rotation = new FieldRotation<>(FieldVector3D.getPlusK(date.getField()),
  95.                                                               correctedERA,
  96.                                                               RotationConvention.FRAME_TRANSFORM);
  97.         return new FieldTransform<>(date, rotation, rotationRate);

  98.     }

  99.     /** Get the Earth Rotation Angle at the current date.
  100.      * @param  date the date
  101.      * @return Earth Rotation Angle at the current date in radians
  102.      */
  103.     public double getEarthRotationAngle(final AbsoluteDate date) {
  104.         return MathUtils.normalizeAngle(era.value(date), 0);
  105.     }

  106.     /** Replace the instance with a data transfer object for serialization.
  107.      * <p>
  108.      * This intermediate class serializes only the frame key.
  109.      * </p>
  110.      * @return data transfer object that will be serialized
  111.      */
  112.     @DefaultDataContext
  113.     private Object writeReplace() {
  114.         return new DataTransferObject(eopHistory);
  115.     }

  116.     /** Internal class used only for serialization. */
  117.     @DefaultDataContext
  118.     private static class DataTransferObject implements Serializable {

  119.         /** Serializable UID. */
  120.         private static final long serialVersionUID = 20131209L;

  121.         /** EOP history. */
  122.         private final EOPHistory eopHistory;

  123.         /** Simple constructor.
  124.          * @param eopHistory EOP history
  125.          */
  126.         DataTransferObject(final EOPHistory eopHistory) {
  127.             this.eopHistory = eopHistory;
  128.         }

  129.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  130.          * @return replacement {@link TIRFProvider}
  131.          */
  132.         private Object readResolve() {
  133.             try {
  134.                 // retrieve a managed frame
  135.                 return new TIRFProvider(eopHistory,
  136.                         DataContext.getDefault().getTimeScales().getUT1(eopHistory));
  137.             } catch (OrekitException oe) {
  138.                 throw new OrekitInternalError(oe);
  139.             }
  140.         }

  141.     }

  142. }