TIRFProvider.java

  1. /* Copyright 2002-2019 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  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.errors.OrekitException;
  27. import org.orekit.errors.OrekitInternalError;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.FieldAbsoluteDate;
  30. import org.orekit.time.TimeScalarFunction;
  31. import org.orekit.time.TimeScalesFactory;
  32. import org.orekit.time.UT1Scale;
  33. import org.orekit.utils.Constants;

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

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

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

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

  45.     /** UT1 time scale. */
  46.     private final transient UT1Scale ut1;

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

  49.     /** Simple constructor.
  50.      * @param eopHistory EOP history
  51.      */
  52.     protected TIRFProvider(final EOPHistory eopHistory) {

  53.         this.ut1        = TimeScalesFactory.getUT1(eopHistory);
  54.         this.eopHistory = eopHistory;
  55.         this.era        = eopHistory.getConventions().getEarthOrientationAngleFunction(ut1);

  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public EOPHistory getEOPHistory() {
  60.         return eopHistory;
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public TIRFProvider getNonInterpolatingProvider() {
  65.         return new TIRFProvider(eopHistory.getNonInterpolatingEOPHistory());
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public Transform getTransform(final AbsoluteDate date) {

  70.         // compute proper rotation
  71.         final double correctedERA = era.value(date);

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

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

  79.     }

  80.     /** {@inheritDoc} */
  81.     @Override
  82.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

  83.         // compute proper rotation
  84.         final T correctedERA = era.value(date);

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

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

  94.     }

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

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

  111.     /** Internal class used only for serialization. */
  112.     private static class DataTransferObject implements Serializable {

  113.         /** Serializable UID. */
  114.         private static final long serialVersionUID = 20131209L;

  115.         /** EOP history. */
  116.         private final EOPHistory eopHistory;

  117.         /** Simple constructor.
  118.          * @param eopHistory EOP history
  119.          */
  120.         DataTransferObject(final EOPHistory eopHistory) {
  121.             this.eopHistory = eopHistory;
  122.         }

  123.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  124.          * @return replacement {@link TIRFProvider}
  125.          */
  126.         private Object readResolve() {
  127.             try {
  128.                 // retrieve a managed frame
  129.                 return new TIRFProvider(eopHistory);
  130.             } catch (OrekitException oe) {
  131.                 throw new OrekitInternalError(oe);
  132.             }
  133.         }

  134.     }

  135. }