TODProvider.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.hipparchus.geometry.euclidean.threed.Rotation;
  20. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  21. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  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. import org.orekit.utils.IERSConventions;

  27. /** Provider for True of Date (ToD) frame.
  28.  * <p>This frame handles nutation effects according to selected IERS conventions.</p>
  29.  * <p>Transform is computed with reference to the {@link MODProvider Mean of Date} frame.</p>
  30.  * @author Pascal Parraud
  31.  */
  32. class TODProvider implements EOPBasedTransformProvider {

  33.     /** Serializable UID. */
  34.     private static final long serialVersionUID = 20131209L;

  35.     /** Conventions. */
  36.     private final IERSConventions conventions;

  37.     /** EOP history. */
  38.     private final EOPHistory eopHistory;

  39.     /** Function computing the mean obliquity. */
  40.     private final transient TimeFunction<Double> obliquityFunction;

  41.     /** Function computing the nutation angles. */
  42.     private final transient TimeFunction<double[]> nutationFunction;

  43.     /** Simple constructor.
  44.      * @param conventions IERS conventions to apply
  45.      * @param eopHistory EOP history
  46.      * @exception OrekitException if IERS conventions tables cannot be read
  47.      */
  48.     TODProvider(final IERSConventions conventions, final EOPHistory eopHistory)
  49.         throws OrekitException {
  50.         this.conventions       = conventions;
  51.         this.eopHistory        = eopHistory;
  52.         this.obliquityFunction = conventions.getMeanObliquityFunction();
  53.         this.nutationFunction  = conventions.getNutationFunction();
  54.     }

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

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public TODProvider getNonInterpolatingProvider()
  63.         throws OrekitException {
  64.         return new TODProvider(conventions, eopHistory.getNonInterpolatingEOPHistory());
  65.     }

  66.     /** Get the transform from Mean Of Date at specified date.
  67.      * <p>The update considers the nutation effects from IERS data.</p>
  68.      * @param date new value of the date
  69.      * @return transform at the specified date
  70.      * @exception OrekitException if the nutation model data embedded in the
  71.      * library cannot be read
  72.      */
  73.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

  74.         // compute nutation angles
  75.         final double[] angles = nutationFunction.value(date);

  76.         // compute the mean obliquity of the ecliptic
  77.         final double moe = obliquityFunction.value(date);

  78.         double dpsi = angles[0];
  79.         double deps = angles[1];
  80.         if (eopHistory != null) {
  81.             // apply the corrections for the nutation parameters
  82.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  83.             dpsi += correction[0];
  84.             deps += correction[1];
  85.         }

  86.         // compute the true obliquity of the ecliptic
  87.         final double toe = moe + deps;

  88.         // complete nutation
  89.         final Rotation nutation = new Rotation(RotationOrder.XZX, RotationConvention.FRAME_TRANSFORM,
  90.                                                moe, -dpsi, -toe);

  91.         // set up the transform from parent MOD
  92.         return new Transform(date, nutation);

  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(conventions, 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.         /** Conventions. */
  108.         private final IERSConventions conventions;

  109.         /** EOP history. */
  110.         private final EOPHistory eopHistory;

  111.         /** Simple constructor.
  112.          * @param conventions IERS conventions to apply
  113.          * @param eopHistory EOP history
  114.          */
  115.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  116.             this.conventions = conventions;
  117.             this.eopHistory  = eopHistory;
  118.         }

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

  130.     }

  131. }