MODProvider.java

  1. /* Copyright 2002-2019 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 java.util.HashMap;
  20. import java.util.Map;

  21. import org.hipparchus.Field;
  22. import org.hipparchus.RealFieldElement;
  23. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  24. import org.hipparchus.geometry.euclidean.threed.Rotation;
  25. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  26. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  27. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitInternalError;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.time.FieldAbsoluteDate;
  32. import org.orekit.time.TimeScalarFunction;
  33. import org.orekit.time.TimeVectorFunction;
  34. import org.orekit.utils.IERSConventions;

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

  42.     /** Serializable UID. */
  43.     private static final long serialVersionUID = 20130920L;

  44.     /** Conventions. */
  45.     private final IERSConventions conventions;

  46.     /** Function computing the precession angles. */
  47.     private final transient TimeVectorFunction precessionFunction;

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

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

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

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

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

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

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

  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public <T extends RealFieldElement<T>> FieldTransform<T> getTransform(final FieldAbsoluteDate<T> date) {

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

  81.         @SuppressWarnings("unchecked")
  82.         FieldRotation<T> fR4 = (FieldRotation<T>) fieldR4.get(date.getField());
  83.         if (fR4 == null) {
  84.             fR4 = new FieldRotation<>(date.getField(), r4);
  85.             fieldR4.put(date.getField(), fR4);
  86.         }

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

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

  95.     }

  96.     /** Replace the instance with a data transfer object for serialization.
  97.      * <p>
  98.      * This intermediate class serializes only the frame key.
  99.      * </p>
  100.      * @return data transfer object that will be serialized
  101.      */
  102.     private Object writeReplace() {
  103.         return new DataTransferObject(conventions);
  104.     }

  105.     /** Internal class used only for serialization. */
  106.     private static class DataTransferObject implements Serializable {

  107.         /** Serializable UID. */
  108.         private static final long serialVersionUID = 20131209L;

  109.         /** Conventions. */
  110.         private final IERSConventions conventions;

  111.         /** Simple constructor.
  112.          * @param conventions IERSConventions conventions
  113.          */
  114.         DataTransferObject(final IERSConventions conventions) {
  115.             this.conventions = conventions;
  116.         }

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

  128.     }

  129. }