TODProvider.java

  1. /* Copyright 2002-2013 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.orekit.errors.OrekitException;
  22. import org.orekit.errors.TimeStampedCacheException;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.TimeFunction;
  25. import org.orekit.utils.IERSConventions;

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

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

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

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

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

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

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

  54.     /** Get the EOP history.
  55.      * @return EOP history
  56.      */
  57.     EOPHistory getEOPHistory() {
  58.         return eopHistory;
  59.     }

  60.     /** Get the LoD (Length of Day) value.
  61.      * <p>The data provided comes from the IERS files. It is smoothed data.</p>
  62.      * @param date date at which the value is desired
  63.      * @return LoD in seconds (0 if date is outside covered range)
  64.      * @exception TimeStampedCacheException if EOP data cannot be retrieved
  65.      */
  66.     double getLOD(final AbsoluteDate date) throws TimeStampedCacheException {
  67.         return (eopHistory == null) ? 0.0 : eopHistory.getLOD(date);
  68.     }

  69.     /** Get the pole IERS Reference Pole correction.
  70.      * <p>The data provided comes from the IERS files. It is smoothed data.</p>
  71.      * @param date date at which the correction is desired
  72.      * @return pole correction ({@link PoleCorrection#NULL_CORRECTION
  73.      * PoleCorrection.NULL_CORRECTION} if date is outside covered range)
  74.      */
  75.     public PoleCorrection getPoleCorrection(final AbsoluteDate date) {
  76.         return (eopHistory == null) ? PoleCorrection.NULL_CORRECTION : eopHistory.getPoleCorrection(date);
  77.     }

  78.     /** Get the transform from Mean Of Date at specified date.
  79.      * <p>The update considers the nutation effects from IERS data.</p>
  80.      * @param date new value of the date
  81.      * @return transform at the specified date
  82.      * @exception OrekitException if the nutation model data embedded in the
  83.      * library cannot be read
  84.      */
  85.     public Transform getTransform(final AbsoluteDate date) throws OrekitException {

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

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

  90.         double dpsi = angles[0];
  91.         double deps = angles[1];
  92.         if (eopHistory != null) {
  93.             // apply the corrections for the nutation parameters
  94.             final double[] correction = eopHistory.getEquinoxNutationCorrection(date);
  95.             dpsi += correction[0];
  96.             deps += correction[1];
  97.         }

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

  100.         // set up the elementary rotations for nutation
  101.         final Rotation r1 = new Rotation(Vector3D.PLUS_I,  toe);
  102.         final Rotation r2 = new Rotation(Vector3D.PLUS_K,  dpsi);
  103.         final Rotation r3 = new Rotation(Vector3D.PLUS_I, -moe);

  104.         // complete nutation
  105.         final Rotation nutation = r1.applyTo(r2.applyTo(r3));

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

  108.     }

  109.     /** Replace the instance with a data transfer object for serialization.
  110.      * <p>
  111.      * This intermediate class serializes only the frame key.
  112.      * </p>
  113.      * @return data transfer object that will be serialized
  114.      */
  115.     private Object writeReplace() {
  116.         return new DataTransferObject(conventions, eopHistory);
  117.     }

  118.     /** Internal class used only for serialization. */
  119.     private static class DataTransferObject implements Serializable {

  120.         /** Serializable UID. */
  121.         private static final long serialVersionUID = 20131209L;

  122.         /** Conventions. */
  123.         private final IERSConventions conventions;

  124.         /** EOP history. */
  125.         private final EOPHistory eopHistory;

  126.         /** Simple constructor.
  127.          * @param conventions IERS conventions to apply
  128.          * @param eopHistory EOP history
  129.          */
  130.         public DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  131.             this.conventions = conventions;
  132.             this.eopHistory  = eopHistory;
  133.         }

  134.         /** Replace the deserialized data transfer object with a {@link TODProvider}.
  135.          * @return replacement {@link TODProvider}
  136.          */
  137.         private Object readResolve() {
  138.             try {
  139.                 // retrieve a managed frame
  140.                 return new TODProvider(conventions, eopHistory);
  141.             } catch (OrekitException oe) {
  142.                 throw OrekitException.createInternalError(oe);
  143.             }
  144.         }

  145.     }

  146. }