CIRFProvider.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.geometry.euclidean.threed.Rotation;
  20. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  21. import org.apache.commons.math3.util.FastMath;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.TimeFunction;

  25. /** Celestial Intermediate Reference Frame 2000.
  26.  * <p>This provider includes precession effects according to either the IAU 2006 precession
  27.  * (also known as Nicole Capitaines's P03 precession theory) and IAU 2000A_R06 nutation
  28.  * for IERS 2010 conventions or the IAU 2000A precession-nutation model for IERS 2003
  29.  * conventions. These models replaced the older IAU-76 precession (Lieske) and IAU-80
  30.  * theory of nutation (Wahr) which were used in the classical equinox-based paradigm.
  31.  * It <strong>must</strong> be used with the Earth Rotation Angle (REA) defined by
  32.  * Capitaine's model and <strong>not</strong> IAU-82 sidereal
  33.  * time which is consistent with the older models only.</p>
  34.  * <p>Its parent frame is the GCRF frame.<p>
  35.  */
  36. class CIRFProvider implements TransformProvider {

  37.     /** Serializable UID. */
  38.     private static final long serialVersionUID = 20130806L;

  39.     /** Function computing CIP/CIO components. */
  40.     private final transient TimeFunction<double[]> xysPxy2Function;

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

  43.     /** Simple constructor.
  44.      * @param eopHistory EOP history
  45.      * @exception OrekitException if the nutation model data embedded in the
  46.      * library cannot be read.
  47.      * @see Frame
  48.      */
  49.     public CIRFProvider(final EOPHistory eopHistory)
  50.         throws OrekitException {

  51.         // load the nutation model
  52.         xysPxy2Function = eopHistory.getConventions().getXYSpXY2Function();

  53.         // store correction to the model
  54.         this.eopHistory = eopHistory;

  55.     }

  56.     /** Get the EOP history.
  57.      * @return EOP history
  58.      */
  59.     EOPHistory getEOPHistory() {
  60.         return eopHistory;
  61.     }

  62.     /** Get the transform from GCRF to CIRF2000 at the specified date.
  63.      * <p>The transform considers the nutation and precession effects from IERS data.</p>
  64.      * @param date new value of the date
  65.      * @return transform at the specified date
  66.      * @exception OrekitException if the nutation model data embedded in the
  67.      * library cannot be read
  68.      */
  69.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

  70.         final double[] xys  = xysPxy2Function.value(date);
  71.         final double[] dxdy = eopHistory.getNonRotatinOriginNutationCorrection(date);

  72.         // position of the Celestial Intermediate Pole (CIP)
  73.         final double xCurrent = xys[0] + dxdy[0];
  74.         final double yCurrent = xys[1] + dxdy[1];

  75.         // position of the Celestial Intermediate Origin (CIO)
  76.         final double sCurrent = xys[2] - xCurrent * yCurrent / 2;

  77.         // set up the bias, precession and nutation rotation
  78.         final double x2Py2  = xCurrent * xCurrent + yCurrent * yCurrent;
  79.         final double zP1    = 1 + FastMath.sqrt(1 - x2Py2);
  80.         final double r      = FastMath.sqrt(x2Py2);
  81.         final double sPe2   = 0.5 * (sCurrent + FastMath.atan2(yCurrent, xCurrent));
  82.         final double cos    = FastMath.cos(sPe2);
  83.         final double sin    = FastMath.sin(sPe2);
  84.         final double xPr    = xCurrent + r;
  85.         final double xPrCos = xPr * cos;
  86.         final double xPrSin = xPr * sin;
  87.         final double yCos   = yCurrent * cos;
  88.         final double ySin   = yCurrent * sin;
  89.         final Rotation bpn  = new Rotation(zP1 * (xPrCos + ySin), -r * (yCos + xPrSin),
  90.                                            r * (xPrCos - ySin), zP1 * (yCos - xPrSin),
  91.                                            true);

  92.         return new Transform(date, bpn, Vector3D.ZERO);

  93.     }

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

  103.     /** Internal class used only for serialization. */
  104.     private static class DataTransferObject implements Serializable {

  105.         /** Serializable UID. */
  106.         private static final long serialVersionUID = 20131209L;

  107.         /** EOP history. */
  108.         private final EOPHistory eopHistory;

  109.         /** Simple constructor.
  110.          * @param eopHistory EOP history
  111.          */
  112.         public DataTransferObject(final EOPHistory eopHistory) {
  113.             this.eopHistory = eopHistory;
  114.         }

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

  126.     }

  127. }