MODProvider.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 java.util.HashMap;
  19. import java.util.Map;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.Field;
  22. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  23. import org.hipparchus.geometry.euclidean.threed.Rotation;
  24. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  25. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  26. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.FieldAbsoluteDate;
  29. import org.orekit.time.TimeScalarFunction;
  30. import org.orekit.time.TimeScales;
  31. import org.orekit.time.TimeVectorFunction;
  32. import org.orekit.utils.IERSConventions;

  33. /** Mean Equator, Mean Equinox Frame.
  34.  * <p>This frame handles precession effects according to to selected IERS conventions.</p>
  35.  * <p>Its parent frame is the GCRF frame.
  36.  * <p>It is sometimes called Mean of Date (MoD) frame.
  37.  * @author Pascal Parraud
  38.  */
  39. class MODProvider implements TransformProvider {

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

  42.     /** Function computing the precession angles. */
  43.     private final transient TimeVectorFunction precessionFunction;

  44.     /** Constant rotation between ecliptic and equator poles at J2000.0. */
  45.     private final Rotation r4;

  46.     /** Constant rotations between ecliptic and equator poles at J2000.0. */
  47.     private final transient Map<Field<? extends CalculusFieldElement<?>>, FieldRotation<? extends CalculusFieldElement<?>>> fieldR4;

  48.     /** Simple constructor.
  49.      * @param conventions IERS conventions to apply
  50.      * @param timeScales used to define this frame.
  51.      */
  52.     MODProvider(final IERSConventions conventions, final TimeScales timeScales) {
  53.         this.conventions        = conventions;
  54.         this.precessionFunction = conventions.getPrecessionFunction(timeScales);
  55.         final TimeScalarFunction epsilonAFunction =
  56.                 conventions.getMeanObliquityFunction(timeScales);
  57.         final AbsoluteDate date0 = conventions.getNutationReferenceEpoch(timeScales);
  58.         final double epsilon0 = epsilonAFunction.value(date0);
  59.         r4 = new Rotation(Vector3D.PLUS_I, epsilon0, RotationConvention.FRAME_TRANSFORM);
  60.         fieldR4 = new HashMap<>();
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public Transform getTransform(final AbsoluteDate date) {

  65.         // compute the precession angles phiA, omegaA, chiA
  66.         final double[] angles = precessionFunction.value(date);

  67.         // complete precession
  68.         final Rotation precession = r4.compose(new Rotation(RotationOrder.ZXZ, RotationConvention.FRAME_TRANSFORM,
  69.                                                             -angles[0], -angles[1], angles[2]),
  70.                                                RotationConvention.FRAME_TRANSFORM);

  71.         // set up the transform from parent GCRF
  72.         return new Transform(date, precession);

  73.     }

  74.     /** {@inheritDoc} */
  75.     @SuppressWarnings("unchecked")
  76.     @Override
  77.     public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

  78.         // compute the precession angles phiA, omegaA, chiA
  79.         final T[] angles = precessionFunction.value(date);

  80.         final FieldRotation<T> fR4;
  81.         synchronized (fieldR4) {
  82.             fR4 = (FieldRotation<T>) fieldR4.computeIfAbsent(date.getField(),
  83.                                                              f -> new FieldRotation<>((Field<T>) f, r4));
  84.         }

  85.         // complete precession
  86.         final FieldRotation<T> precession = fR4.compose(new FieldRotation<>(RotationOrder.ZXZ, RotationConvention.FRAME_TRANSFORM,
  87.                                                                             angles[0].negate(),
  88.                                                                             angles[1].negate(),
  89.                                                                             angles[2]),
  90.                                                         RotationConvention.FRAME_TRANSFORM);

  91.         // set up the transform from parent GCRF
  92.         return new FieldTransform<>(date, precession);

  93.     }

  94. }