TODProvider.java

  1. /* Copyright 2002-2025 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 org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  20. import org.hipparchus.geometry.euclidean.threed.Rotation;
  21. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  22. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;
  25. import org.orekit.time.TimeScalarFunction;
  26. import org.orekit.time.TimeScales;
  27. import org.orekit.time.TimeVectorFunction;
  28. import org.orekit.utils.IERSConventions;

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

  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 TimeScalarFunction obliquityFunction;

  41.     /** Function computing the nutation angles. */
  42.     private final transient TimeVectorFunction nutationFunction;


  43.     /**
  44.      * Simple constructor.
  45.      *  @param conventions IERS conventions to apply
  46.      * @param eopHistory  EOP history, or {@code null} if no correction should be
  47.      *                    applied.
  48.      * @param timeScales         TAI time scale.
  49.      */
  50.     TODProvider(final IERSConventions conventions,
  51.                 final EOPHistory eopHistory,
  52.                 final TimeScales timeScales) {
  53.         this.conventions       = conventions;
  54.         this.eopHistory        = eopHistory;
  55.         this.obliquityFunction = conventions.getMeanObliquityFunction(timeScales);
  56.         this.nutationFunction  =
  57.                 conventions.getNutationFunction(timeScales);
  58.     }

  59.     /**
  60.      * Private constructor.
  61.      *
  62.      * @param conventions       IERS conventions to use.
  63.      * @param eopHistory        or {@code null} if no correction should be applied.
  64.      * @param obliquityFunction to use.
  65.      * @param nutationFunction  to use.
  66.      */
  67.     private TODProvider(final IERSConventions conventions,
  68.                         final EOPHistory eopHistory,
  69.                         final TimeScalarFunction obliquityFunction,
  70.                         final TimeVectorFunction nutationFunction) {
  71.         this.conventions = conventions;
  72.         this.eopHistory = eopHistory;
  73.         this.obliquityFunction = obliquityFunction;
  74.         this.nutationFunction = nutationFunction;
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public EOPHistory getEOPHistory() {
  79.         return eopHistory;
  80.     }

  81.     /** {@inheritDoc} */
  82.     @Override
  83.     public TODProvider getNonInterpolatingProvider() {
  84.         return new TODProvider(conventions, eopHistory.getEOPHistoryWithoutCachedTidalCorrection(),
  85.                 obliquityFunction, nutationFunction);
  86.     }

  87.     /** {@inheritDoc} */
  88.     @Override
  89.     public Transform getTransform(final AbsoluteDate date) {

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

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

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

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

  104.         // complete nutation
  105.         final Rotation nutation = new Rotation(RotationOrder.XZX, RotationConvention.FRAME_TRANSFORM,
  106.                                                moe, -dpsi, -toe);

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

  109.     }

  110.     /** Replace the instance with a data transfer object for serialization.
  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

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

  118.         T dpsi = angles[0];
  119.         T deps = angles[1];
  120.         if (eopHistory != null) {
  121.             // apply the corrections for the nutation parameters
  122.             final T[] correction = eopHistory.getEquinoxNutationCorrection(date);
  123.             dpsi = dpsi.add(correction[0]);
  124.             deps = deps.add(correction[1]);
  125.         }

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

  128.         // complete nutation
  129.         final FieldRotation<T> nutation = new FieldRotation<>(RotationOrder.XZX, RotationConvention.FRAME_TRANSFORM,
  130.                                                               moe, dpsi.negate(), toe.negate());

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

  133.     }

  134. }