MODProvider.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 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.      * @exception OrekitException if IERS conventions tables cannot be read
  55.      */
  56.     MODProvider(final IERSConventions conventions) throws OrekitException {
  57.         this.conventions        = conventions;
  58.         this.precessionFunction = conventions.getPrecessionFunction();
  59.         final TimeScalarFunction epsilonAFunction = conventions.getMeanObliquityFunction();
  60.         final AbsoluteDate date0 = conventions.getNutationReferenceEpoch();
  61.         final double epsilon0 = epsilonAFunction.value(date0);
  62.         r4 = new Rotation(Vector3D.PLUS_I, epsilon0, RotationConvention.FRAME_TRANSFORM);
  63.         fieldR4 = new HashMap<>();
  64.     }

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

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

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

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

  76.     }

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

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

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

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

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

  97.     }

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

  107.     /** Internal class used only for serialization. */
  108.     private static class DataTransferObject implements Serializable {

  109.         /** Serializable UID. */
  110.         private static final long serialVersionUID = 20131209L;

  111.         /** Conventions. */
  112.         private final IERSConventions conventions;

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

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

  130.     }

  131. }