CIRFProvider.java

  1. /* Copyright 2002-2019 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.      * @see Frame
  51.      */
  52.     CIRFProvider(final EOPHistory eopHistory) {

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

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

  57.     }

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

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

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public Transform getTransform(final AbsoluteDate date) {

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

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

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

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

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

  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

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

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

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

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

  123.     }

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

  133.     /** Internal class used only for serialization. */
  134.     private static class DataTransferObject implements Serializable {

  135.         /** Serializable UID. */
  136.         private static final long serialVersionUID = 20131209L;

  137.         /** EOP history. */
  138.         private final EOPHistory eopHistory;

  139.         /** Simple constructor.
  140.          * @param eopHistory EOP history
  141.          */
  142.         DataTransferObject(final EOPHistory eopHistory) {
  143.             this.eopHistory = eopHistory;
  144.         }

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

  156.     }

  157. }