CIRFProvider.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.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.errors.OrekitInternalError;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.time.TimeVectorFunction;

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

  42.     /** Serializable UID. */
  43.     private static final long serialVersionUID = 20130806L;

  44.     /** Function computing CIP/CIO components. */
  45.     private final transient TimeVectorFunction xysPxy2Function;

  46.     /** EOP history. */
  47.     private final EOPHistory eopHistory;

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

  56.         // load the nutation model
  57.         xysPxy2Function = eopHistory.getConventions().getXYSpXY2Function();

  58.         // store correction to the model
  59.         this.eopHistory = eopHistory;

  60.     }

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

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public CIRFProvider getNonInterpolatingProvider()
  69.         throws OrekitException {
  70.         return new CIRFProvider(eopHistory.getNonInterpolatingEOPHistory());
  71.     }

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

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

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

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

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

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

  98.     }

  99.     /** {@inheritDoc} */
  100.     @Override
  101.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  102.         throws OrekitException {

  103.         final T[] xys  = xysPxy2Function.value(date);
  104.         final T[] dxdy = eopHistory.getNonRotatinOriginNutationCorrection(date);

  105.         // position of the Celestial Intermediate Pole (CIP)
  106.         final T xCurrent = xys[0].add(dxdy[0]);
  107.         final T yCurrent = xys[1].add(dxdy[1]);

  108.         // position of the Celestial Intermediate Origin (CIO)
  109.         final T sCurrent = xys[2].subtract(xCurrent.multiply(yCurrent).multiply(0.5));

  110.         // set up the bias, precession and nutation rotation
  111.         final T x2Py2  = xCurrent.multiply(xCurrent).add(yCurrent.multiply(yCurrent));
  112.         final T zP1    = x2Py2.subtract(1).negate().sqrt().add(1);
  113.         final T r      = x2Py2.sqrt();
  114.         final T sPe2   = sCurrent.add(yCurrent.atan2(xCurrent)).multiply(0.5);
  115.         final T cos    = sPe2.cos();
  116.         final T sin    = sPe2.sin();
  117.         final T xPr    = xCurrent.add(r);
  118.         final T xPrCos = xPr.multiply(cos);
  119.         final T xPrSin = xPr.multiply(sin);
  120.         final T yCos   = yCurrent.multiply(cos);
  121.         final T ySin   = yCurrent.multiply(sin);
  122.         final FieldRotation<T> bpn  = new FieldRotation<>(zP1.multiply(xPrCos.add(ySin)),
  123.                                                           r.multiply(yCos.add(xPrSin)).negate(),
  124.                                                           r.multiply(xPrCos.subtract(ySin)),
  125.                                                           zP1.multiply(yCos.subtract(xPrSin)),
  126.                                                           true);

  127.         return new FieldTransform<>(date, bpn, FieldVector3D.getZero(date.getField()));

  128.     }

  129.     /** Replace the instance with a data transfer object for serialization.
  130.      * <p>
  131.      * This intermediate class serializes only the frame key.
  132.      * </p>
  133.      * @return data transfer object that will be serialized
  134.      */
  135.     private Object writeReplace() {
  136.         return new DataTransferObject(eopHistory);
  137.     }

  138.     /** Internal class used only for serialization. */
  139.     private static class DataTransferObject implements Serializable {

  140.         /** Serializable UID. */
  141.         private static final long serialVersionUID = 20131209L;

  142.         /** EOP history. */
  143.         private final EOPHistory eopHistory;

  144.         /** Simple constructor.
  145.          * @param eopHistory EOP history
  146.          */
  147.         DataTransferObject(final EOPHistory eopHistory) {
  148.             this.eopHistory = eopHistory;
  149.         }

  150.         /** Replace the deserialized data transfer object with a {@link CIRFProvider}.
  151.          * @return replacement {@link CIRFProvider}
  152.          */
  153.         private Object readResolve() {
  154.             try {
  155.                 // retrieve a managed frame
  156.                 return new CIRFProvider(eopHistory);
  157.             } catch (OrekitException oe) {
  158.                 throw new OrekitInternalError(oe);
  159.             }
  160.         }

  161.     }

  162. }