TODProvider.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.Rotation;
  22. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  23. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  24. import org.orekit.errors.OrekitException;
  25. import org.orekit.errors.OrekitInternalError;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.time.TimeVectorFunction;
  29. import org.orekit.time.TimeScalarFunction;
  30. import org.orekit.utils.IERSConventions;

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

  37.     /** Serializable UID. */
  38.     private static final long serialVersionUID = 20131209L;

  39.     /** Conventions. */
  40.     private final IERSConventions conventions;

  41.     /** EOP history. */
  42.     private final EOPHistory eopHistory;

  43.     /** Function computing the mean obliquity. */
  44.     private final transient TimeScalarFunction obliquityFunction;

  45.     /** Function computing the nutation angles. */
  46.     private final transient TimeVectorFunction nutationFunction;

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

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

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public TODProvider getNonInterpolatingProvider()
  67.         throws OrekitException {
  68.         return new TODProvider(conventions, eopHistory.getNonInterpolatingEOPHistory());
  69.     }

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

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

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

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

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

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

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

  92.     }

  93.     /** Replace the instance with a data transfer object for serialization.
  94.     /** {@inheritDoc} */
  95.     @Override
  96.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date)
  97.         throws OrekitException {

  98.         // compute nutation angles
  99.         final T[] angles = nutationFunction.value(date);

  100.         // compute the mean obliquity of the ecliptic
  101.         final T moe = obliquityFunction.value(date);

  102.         T dpsi = angles[0];
  103.         T deps = angles[1];
  104.         if (eopHistory != null) {
  105.             // apply the corrections for the nutation parameters
  106.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  107.             dpsi = dpsi.add(correction[0]);
  108.             deps = deps.add(correction[1]);
  109.         }

  110.         // compute the true obliquity of the ecliptic
  111.         final T toe = moe.add(deps);

  112.         // complete nutation
  113.         final FieldRotation<T> nutation = new FieldRotation<>(RotationOrder.XZX, RotationConvention.FRAME_TRANSFORM,
  114.                                                               moe, dpsi.negate(), toe.negate());

  115.         // set up the transform from parent MOD
  116.         return new FieldTransform<>(date, nutation);

  117.     }

  118.     /** Replace the instance with a data transfer object for serialization.
  119.      * <p>
  120.      * This intermediate class serializes only the frame key.
  121.      * </p>
  122.      * @return data transfer object that will be serialized
  123.      */
  124.     private Object writeReplace() {
  125.         return new DataTransferObject(conventions, eopHistory);
  126.     }

  127.     /** Internal class used only for serialization. */
  128.     private static class DataTransferObject implements Serializable {

  129.         /** Serializable UID. */
  130.         private static final long serialVersionUID = 20131209L;

  131.         /** Conventions. */
  132.         private final IERSConventions conventions;

  133.         /** EOP history. */
  134.         private final EOPHistory eopHistory;

  135.         /** Simple constructor.
  136.          * @param conventions IERS conventions to apply
  137.          * @param eopHistory EOP history
  138.          */
  139.         DataTransferObject(final IERSConventions conventions, final EOPHistory eopHistory) {
  140.             this.conventions = conventions;
  141.             this.eopHistory  = eopHistory;
  142.         }

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

  154.     }

  155. }