TIRFProvider.java

  1. /* Copyright 2002-2016 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.apache.commons.math3.analysis.differentiation.DerivativeStructure;
  20. import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
  21. import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
  22. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  23. import org.apache.commons.math3.util.MathUtils;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitInternalError;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.TimeFunction;
  28. import org.orekit.time.TimeScalesFactory;
  29. import org.orekit.time.UT1Scale;
  30. import org.orekit.utils.Constants;

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

  36.     /** Serializable UID. */
  37.     private static final long serialVersionUID = 20130919L;

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

  40.     /** EOP history. */
  41.     private final EOPHistory eopHistory;

  42.     /** ERA function. */
  43.     private final transient TimeFunction<DerivativeStructure> era;

  44.     /** Simple constructor.
  45.      * @param eopHistory EOP history
  46.      * @exception OrekitException if nutation cannot be computed
  47.      */
  48.     protected TIRFProvider(final EOPHistory eopHistory)
  49.         throws OrekitException {

  50.         final UT1Scale ut1   = TimeScalesFactory.getUT1(eopHistory);
  51.         this.eopHistory      = eopHistory;
  52.         this.era             = eopHistory.getConventions().getEarthOrientationAngleFunction(ut1);

  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public EOPHistory getEOPHistory() {
  57.         return eopHistory;
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public TIRFProvider getNonInterpolatingProvider()
  62.         throws OrekitException {
  63.         return new TIRFProvider(eopHistory.getNonInterpolatingEOPHistory());
  64.     }

  65.     /** Get the transform from CIRF 2000 at specified date.
  66.      * <p>The update considers the earth rotation from IERS data.</p>
  67.      * @param date new value of the date
  68.      * @return transform at the specified date
  69.      * @exception OrekitException if the nutation model data embedded in the
  70.      * library cannot be read
  71.      */
  72.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

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

  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 CIRF2000
  80.         final Rotation rotation     = new Rotation(Vector3D.PLUS_K, correctedERA, RotationConvention.FRAME_TRANSFORM);
  81.         return new Transform(date, rotation, rotationRate);

  82.     }

  83.     /** Get the Earth Rotation Angle at the current date.
  84.      * @param  date the date
  85.      * @return Earth Rotation Angle at the current date in radians
  86.      * @exception OrekitException if nutation model cannot be computed
  87.      */
  88.     public double getEarthRotationAngle(final AbsoluteDate date) throws OrekitException {
  89.         return MathUtils.normalizeAngle(era.value(date).getValue(), 0);
  90.     }

  91.     /** Replace the instance with a data transfer object for serialization.
  92.      * <p>
  93.      * This intermediate class serializes only the frame key.
  94.      * </p>
  95.      * @return data transfer object that will be serialized
  96.      */
  97.     private Object writeReplace() {
  98.         return new DataTransferObject(eopHistory);
  99.     }

  100.     /** Internal class used only for serialization. */
  101.     private static class DataTransferObject implements Serializable {

  102.         /** Serializable UID. */
  103.         private static final long serialVersionUID = 20131209L;

  104.         /** EOP history. */
  105.         private final EOPHistory eopHistory;

  106.         /** Simple constructor.
  107.          * @param eopHistory EOP history
  108.          */
  109.         DataTransferObject(final EOPHistory eopHistory) {
  110.             this.eopHistory = eopHistory;
  111.         }

  112.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  113.          * @return replacement {@link TIRFProvider}
  114.          */
  115.         private Object readResolve() {
  116.             try {
  117.                 // retrieve a managed frame
  118.                 return new TIRFProvider(eopHistory);
  119.             } catch (OrekitException oe) {
  120.                 throw new OrekitInternalError(oe);
  121.             }
  122.         }

  123.     }

  124. }