CIRFProvider.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.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.errors.OrekitInternalError;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.TimeFunction;

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

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

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

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

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

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

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

  56.     }

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

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

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

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

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

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

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

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

  99.     }

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

  109.     /** Internal class used only for serialization. */
  110.     private static class DataTransferObject implements Serializable {

  111.         /** Serializable UID. */
  112.         private static final long serialVersionUID = 20131209L;

  113.         /** EOP history. */
  114.         private final EOPHistory eopHistory;

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

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

  132.     }

  133. }