TIRFProvider.java

  1. /* Copyright 2002-2018 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.      * @exception OrekitException if nutation cannot be computed
  52.      */
  53.     protected TIRFProvider(final EOPHistory eopHistory)
  54.         throws OrekitException {

  55.         this.ut1        = TimeScalesFactory.getUT1(eopHistory);
  56.         this.eopHistory = eopHistory;
  57.         this.era        = eopHistory.getConventions().getEarthOrientationAngleFunction(ut1);

  58.     }

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

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public TIRFProvider getNonInterpolatingProvider()
  67.         throws OrekitException {
  68.         return new TIRFProvider(eopHistory.getNonInterpolatingEOPHistory());
  69.     }

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

  73.         // compute proper rotation
  74.         final double correctedERA = era.value(date);

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

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

  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  86.         throws OrekitException {

  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.      * @exception OrekitException if nutation model cannot be computed
  103.      */
  104.     public double getEarthRotationAngle(final AbsoluteDate date) throws OrekitException {
  105.         return MathUtils.normalizeAngle(era.value(date), 0);
  106.     }

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

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

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

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

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

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

  139.     }

  140. }