AbstractTimeScales.java

  1. /* Contributed in the public domain.
  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.time;

  18. import java.util.concurrent.ConcurrentHashMap;
  19. import java.util.concurrent.ConcurrentMap;

  20. import org.hipparchus.util.MathArrays;
  21. import org.hipparchus.util.Pair;
  22. import org.orekit.frames.EOPHistory;
  23. import org.orekit.utils.Constants;
  24. import org.orekit.utils.IERSConventions;

  25. /**
  26.  * Abstract base class for {@link TimeScales} that implements some common functionality.
  27.  *
  28.  * @author Evan Ward
  29.  * @author Luc Maisonobe
  30.  * @since 10.1
  31.  */
  32. public abstract class AbstractTimeScales implements TimeScales {

  33.     /** GMST time scales. */
  34.     private final ConcurrentMap<Pair<IERSConventions, Boolean>, GMSTScale> gmstMap;
  35.     /** UT1 time scales. */
  36.     private final ConcurrentMap<Pair<IERSConventions, Boolean>, UT1Scale> ut1Map;

  37.     /** Simple constructor. */
  38.     public AbstractTimeScales() {
  39.         final int n = IERSConventions.values().length;
  40.         gmstMap = new ConcurrentHashMap<>(n * 2);
  41.         ut1Map = new ConcurrentHashMap<>(n * 2);
  42.     }

  43.     /**
  44.      * Get the Universal Time 1 scale.
  45.      * <p>
  46.      * As this method allow associating any history with the time scale, it may involve
  47.      * large data sets. So this method does <em>not</em> cache the resulting {@link
  48.      * UT1Scale UT1Scale} instance, a new instance will be returned each time. In order to
  49.      * avoid wasting memory, calling {@link #getUT1(IERSConventions, boolean)} with the
  50.      * single enumerate corresponding to the conventions may be a better solution. This
  51.      * method is made available only for expert use.
  52.      * </p>
  53.      *
  54.      * @param history EOP parameters providing dUT1 (may be null if no correction is
  55.      *                desired)
  56.      * @return Universal Time 1 scale
  57.      * @see #getUT1(IERSConventions, boolean)
  58.      */
  59.     protected UT1Scale getUT1(final EOPHistory history) {
  60.         return new UT1Scale(history, getUTC());
  61.     }

  62.     /**
  63.      * Get the EOP history for the given conventions.
  64.      *
  65.      * @param conventions to use in computing the EOP history.
  66.      * @param simpleEOP   whether to ignore some small tidal effects.
  67.      * @return EOP history.
  68.      */
  69.     protected abstract EOPHistory getEopHistory(IERSConventions conventions,
  70.                                                 boolean simpleEOP);

  71.     @Override
  72.     public UT1Scale getUT1(final IERSConventions conventions, final boolean simpleEOP) {
  73.         return ut1Map.computeIfAbsent(
  74.             new Pair<>(conventions, simpleEOP),
  75.             k -> getUT1(getEopHistory(conventions, simpleEOP)));
  76.     }

  77.     @Override
  78.     public GMSTScale getGMST(final IERSConventions conventions, final boolean simpleEOP) {
  79.         return gmstMap.computeIfAbsent(
  80.             new Pair<>(conventions, simpleEOP),
  81.             k -> new GMSTScale(getUT1(conventions, simpleEOP)));
  82.     }

  83.     @Override
  84.     public AbsoluteDate getJulianEpoch() {
  85.         return new AbsoluteDate(DateComponents.JULIAN_EPOCH, TimeComponents.H12, this.getTT());
  86.     }

  87.     @Override
  88.     public AbsoluteDate getModifiedJulianEpoch() {
  89.         return new AbsoluteDate(DateComponents.MODIFIED_JULIAN_EPOCH, TimeComponents.H00, this.getTT());
  90.     }

  91.     @Override
  92.     public AbsoluteDate getFiftiesEpoch() {
  93.         return new AbsoluteDate(DateComponents.FIFTIES_EPOCH, TimeComponents.H00, this.getTT());
  94.     }

  95.     @Override
  96.     public AbsoluteDate getCcsdsEpoch() {
  97.         return new AbsoluteDate(DateComponents.CCSDS_EPOCH, TimeComponents.H00, this.getTAI());
  98.     }

  99.     @Override
  100.     public AbsoluteDate getGalileoEpoch() {
  101.         return new AbsoluteDate(DateComponents.GALILEO_EPOCH, TimeComponents.H00, this.getGST());
  102.     }

  103.     @Override
  104.     public AbsoluteDate getGpsEpoch() {
  105.         return new AbsoluteDate(DateComponents.GPS_EPOCH, TimeComponents.H00, this.getGPS());
  106.     }

  107.     @Override
  108.     public AbsoluteDate getQzssEpoch() {
  109.         return new AbsoluteDate(DateComponents.QZSS_EPOCH, TimeComponents.H00, this.getQZSS());
  110.     }

  111.     @Override
  112.     public AbsoluteDate getIrnssEpoch() {
  113.         return new AbsoluteDate(DateComponents.IRNSS_EPOCH, TimeComponents.H00, this.getIRNSS());
  114.     }

  115.     @Override
  116.     public AbsoluteDate getBeidouEpoch() {
  117.         return new AbsoluteDate(DateComponents.BEIDOU_EPOCH, TimeComponents.H00, this.getBDT());
  118.     }

  119.     @Override
  120.     public AbsoluteDate getGlonassEpoch() {
  121.         return new AbsoluteDate(DateComponents.GLONASS_EPOCH,
  122.                 new TimeComponents(29.0), this.getTAI()).shiftedBy(-10800.0);
  123.     }

  124.     @Override
  125.     public AbsoluteDate getJ2000Epoch() {
  126.         return new AbsoluteDate(DateComponents.J2000_EPOCH, TimeComponents.H12, this.getTT());
  127.     }

  128.     @Override
  129.     public AbsoluteDate getJavaEpoch() {
  130.         return new AbsoluteDate(DateComponents.JAVA_EPOCH, this.getTAI()).shiftedBy(8.000082);
  131.     }

  132.     @Override
  133.     public AbsoluteDate getPastInfinity() {
  134.         return getJavaEpoch().shiftedBy(Double.NEGATIVE_INFINITY);
  135.     }

  136.     @Override
  137.     public AbsoluteDate getFutureInfinity() {
  138.         return getJavaEpoch().shiftedBy(Double.POSITIVE_INFINITY);
  139.     }

  140.     @Override
  141.     public AbsoluteDate createJulianEpoch(final double julianEpoch) {
  142.         return new AbsoluteDate(getJ2000Epoch(),
  143.                 Constants.JULIAN_YEAR * (julianEpoch - 2000.0));
  144.     }

  145.     @Override
  146.     public AbsoluteDate createBesselianEpoch(final double besselianEpoch) {
  147.         return new AbsoluteDate(getJ2000Epoch(),
  148.                 MathArrays.linearCombination(
  149.                         Constants.BESSELIAN_YEAR, besselianEpoch - 1900,
  150.                         Constants.JULIAN_DAY, -36525,
  151.                         Constants.JULIAN_DAY, 0.31352));
  152.     }

  153. }