CIRFProvider.java

  1. /* Copyright 2002-2020 CS GROUP
  2.  * Licensed to CS GROUP (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.hipparchus.util.FieldSinCos;
  26. import org.hipparchus.util.SinCos;
  27. import org.orekit.errors.OrekitException;
  28. import org.orekit.errors.OrekitInternalError;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.time.FieldAbsoluteDate;
  31. import org.orekit.time.TimeVectorFunction;

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

  44.     /** Serializable UID. */
  45.     private static final long serialVersionUID = 20130806L;

  46.     /** Function computing CIP/CIO components. */
  47.     private final transient TimeVectorFunction xysPxy2Function;

  48.     /** EOP history. */
  49.     private final EOPHistory eopHistory;

  50.     /** Simple constructor.
  51.      * @param eopHistory EOP history
  52.      * @see Frame
  53.      */
  54.     CIRFProvider(final EOPHistory eopHistory) {

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

  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.         return new CIRFProvider(eopHistory.getNonInterpolatingEOPHistory());
  70.     }

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

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

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

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

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

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

  96.     }

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

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

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

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

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

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

  124.     }

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

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

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

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

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

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

  157.     }

  158. }