TIRFProvider.java

  1. /* Copyright 2002-2013 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.Vector3D;
  22. import org.apache.commons.math3.util.MathUtils;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.TimeFunction;
  26. import org.orekit.time.TimeScalesFactory;
  27. import org.orekit.time.UT1Scale;
  28. import org.orekit.utils.Constants;

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

  34.     /** Serializable UID. */
  35.     private static final long serialVersionUID = 20130919L;

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

  38.     /** EOP history. */
  39.     private final EOPHistory eopHistory;

  40.     /** ERA function. */
  41.     private final transient TimeFunction<DerivativeStructure> era;

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

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

  51.     }

  52.     /** Get the EOP history.
  53.      * @return EOP history
  54.      */
  55.     EOPHistory getEOPHistory() {
  56.         return eopHistory;
  57.     }

  58.     /** Get the transform from CIRF 2000 at specified date.
  59.      * <p>The update considers the earth rotation from IERS data.</p>
  60.      * @param date new value of the date
  61.      * @return transform at the specified date
  62.      * @exception OrekitException if the nutation model data embedded in the
  63.      * library cannot be read
  64.      */
  65.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

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

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

  72.         // set up the transform from parent CIRF2000
  73.         final Rotation rotation     = new Rotation(Vector3D.PLUS_K, -correctedERA);
  74.         return new Transform(date, rotation, rotationRate);

  75.     }

  76.     /** Get the Earth Rotation Angle at the current date.
  77.      * @param  date the date
  78.      * @return Earth Rotation Angle at the current date in radians
  79.      * @exception OrekitException if nutation model cannot be computed
  80.      */
  81.     public double getEarthRotationAngle(final AbsoluteDate date) throws OrekitException {
  82.         return MathUtils.normalizeAngle(era.value(date).getValue(), 0);
  83.     }

  84.     /** Replace the instance with a data transfer object for serialization.
  85.      * <p>
  86.      * This intermediate class serializes only the frame key.
  87.      * </p>
  88.      * @return data transfer object that will be serialized
  89.      */
  90.     private Object writeReplace() {
  91.         return new DataTransferObject(eopHistory);
  92.     }

  93.     /** Internal class used only for serialization. */
  94.     private static class DataTransferObject implements Serializable {

  95.         /** Serializable UID. */
  96.         private static final long serialVersionUID = 20131209L;

  97.         /** EOP history. */
  98.         private final EOPHistory eopHistory;

  99.         /** Simple constructor.
  100.          * @param eopHistory EOP history
  101.          */
  102.         public DataTransferObject(final EOPHistory eopHistory) {
  103.             this.eopHistory = eopHistory;
  104.         }

  105.         /** Replace the deserialized data transfer object with a {@link TIRFProvider}.
  106.          * @return replacement {@link TIRFProvider}
  107.          */
  108.         private Object readResolve() {
  109.             try {
  110.                 // retrieve a managed frame
  111.                 return new TIRFProvider(eopHistory);
  112.             } catch (OrekitException oe) {
  113.                 throw OrekitException.createInternalError(oe);
  114.             }
  115.         }

  116.     }

  117. }