Tide.java

  1. /* Copyright 2002-2024 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.models.earth.displacement;

  18. import org.orekit.data.BodiesElements;

  19. /**
  20.  * Class representing a tide.
  21.  * @since 9.1
  22.  * @author Luc Maisonobe
  23.  */
  24. public class Tide {

  25.     /** M₂ tide. */
  26.     public static final Tide M2 = new Tide(255555);

  27.     /** S₂ tide. */
  28.     public static final Tide S2 = new Tide(273555);

  29.     /** N₂ tide. */
  30.     public static final Tide N2 = new Tide(245655);

  31.     /** K₂ tide. */
  32.     public static final Tide K2 = new Tide(275555);

  33.     /** K₁ tide. */
  34.     public static final Tide K1 = new Tide(165555);

  35.     /** O₁ tide. */
  36.     public static final Tide O1 = new Tide(145555);

  37.     /** P₁ tide. */
  38.     public static final Tide P1 = new Tide(163555);

  39.     /** Q₁ tide. */
  40.     public static final Tide Q1 = new Tide(135655);

  41.     /** Mf tide. */
  42.     public static final Tide MF = new Tide(75555);

  43.     /** Mm tide. */
  44.     public static final Tide MM = new Tide(65455);

  45.     /** Ssa tide. */
  46.     public static final Tide SSA = new Tide(57555);

  47.     /** Doodson number. */
  48.     private final int doodsonNumber;

  49.     /** Multipliers for Doodson arguments (τ, s, h, p, N', ps). */
  50.     private final int[] doodsonMultipliers;

  51.     /** Multipliers for Delaunay arguments (l, l', F, D, Ω). */
  52.     private final int[] delaunayMultipliers;

  53.     /** Simple constructor.
  54.      * @param cTau coefficient for mean lunar time
  55.      * @param cS coefficient for mean longitude of the Moon
  56.      * @param cH coefficient for mean longitude of the Sun
  57.      * @param cP coefficient for longitude of Moon mean perigee
  58.      * @param cNprime negative of the longitude of the Moon's mean ascending node on the ecliptic
  59.      * @param cPs coefficient for longitude of Sun mean perigee
  60.      */
  61.     public Tide(final int cTau, final int cS, final int cH, final int cP, final int cNprime, final int cPs) {
  62.         doodsonNumber      = doodsonMultipliersToDoodsonNumber(cTau, cS, cH, cP, cNprime, cPs);
  63.         doodsonMultipliers = new int[] {
  64.             cTau, cS, cH, cP, cNprime, cPs
  65.         };
  66.         this.delaunayMultipliers = doodsonMultipliersToDelaunayMultipliers(doodsonMultipliers);
  67.     }

  68.     /** Simple constructor.
  69.      * @param doodsonNumber Doodson Number
  70.      */
  71.     public Tide(final int doodsonNumber) {
  72.         this.doodsonNumber       = doodsonNumber;
  73.         this.doodsonMultipliers  = doodsonNumberToDoodsonMultipliers(doodsonNumber);
  74.         this.delaunayMultipliers = doodsonMultipliersToDelaunayMultipliers(doodsonMultipliers);
  75.     }

  76.     /** Convert Doodson number to Doodson mutipliers.
  77.      * @param doodsonNumber Doodson number
  78.      * @return Doodson multipliers
  79.      */
  80.     private static int[] doodsonNumberToDoodsonMultipliers(final int doodsonNumber) {
  81.         // CHECKSTYLE: stop Indentation check
  82.         return new int[] {
  83.              (doodsonNumber / 100000) % 10,
  84.             ((doodsonNumber /  10000) % 10) - 5,
  85.             ((doodsonNumber /   1000) % 10) - 5,
  86.             ((doodsonNumber /    100) % 10) - 5,
  87.             ((doodsonNumber /     10) % 10) - 5,
  88.             (doodsonNumber            % 10) - 5
  89.         };
  90.         // CHECKSTYLE: resume Indentation check
  91.     }

  92.     /** Convert Doodson mutipliers to Doodson number.
  93.      * @param cTau coefficient for mean lunar time
  94.      * @param cS coefficient for mean longitude of the Moon
  95.      * @param cH coefficient for mean longitude of the Sun
  96.      * @param cP coefficient for longitude of Moon mean perigee
  97.      * @param cNprime negative of the longitude of the Moon's mean ascending node on the ecliptic
  98.      * @param cPs coefficient for longitude of Sun mean perigee
  99.      * @return Doodson number
  100.      */
  101.     private static int doodsonMultipliersToDoodsonNumber(final int cTau, final int cS, final int cH,
  102.                                                          final int cP, final int cNprime, final int cPs) {
  103.         return ((((cTau * 10 + (cS + 5)) * 10 + (cH + 5)) * 10 + (cP + 5)) * 10 + (cNprime + 5)) * 10 + (cPs + 5);
  104.     }

  105.     /** Convert Doodson mutipliers to Delaunay multipliers.
  106.      * @param dom Doodson multipliers
  107.      * @return Delaunay multipliers
  108.      */
  109.     private static int[] doodsonMultipliersToDelaunayMultipliers(final int[] dom) {
  110.         return new int[] {
  111.             dom[3],
  112.             dom[5],
  113.             dom[0] - dom[1] - dom[2] - dom[3] - dom[5],
  114.             dom[2] + dom[5],
  115.             dom[0] - dom[1] - dom[2] - dom[3] + dom[4] - dom[5]
  116.         };
  117.     }

  118.     /** Get the multipliers for Delaunay arguments (l, l', F, D, Ω).
  119.      * <p>
  120.      * Beware that for tides the multipliers for Delaunay arguments have an opposite
  121.      * sign with respect to the convention used for nutation computation! Here, we
  122.      * obey the tides convention.
  123.      * </p>
  124.      * @return multipliers for Delaunay arguments (l, l', F, D, Ω)
  125.      */
  126.     public int[] getDelaunayMultipliers() {
  127.         return delaunayMultipliers.clone();
  128.     }

  129.     /** Get the multipliers for Doodson arguments (τ, s, h, p, N', ps).
  130.      * @return multipliers for Doodson arguments (τ, s, h, p, N', ps)
  131.      */
  132.     public int[] getDoodsonMultipliers() {
  133.         return doodsonMultipliers.clone();
  134.     }

  135.     /** Get the Doodson number.
  136.      * @return Doodson number
  137.      */
  138.     public int getDoodsonNumber() {
  139.         return doodsonNumber;
  140.     }

  141.     /** Get the multiplier for the τ Doodson argument.
  142.      * <p>
  143.      * This multiplier identifies semi-diurnal tides (2),
  144.      * diurnal tides (1) and long period tides (0)
  145.      * </p>
  146.      * @return multiplier for the τ Doodson argument
  147.      */
  148.     public int getTauMultiplier() {
  149.         return doodsonMultipliers[0];
  150.     }

  151.     /** Get the phase of the tide.
  152.      * @param elements elements to use
  153.      * @return phase of the tide (radians)
  154.      */
  155.     public double getPhase(final BodiesElements elements) {
  156.         return doodsonMultipliers[0]  * elements.getGamma()  -
  157.                delaunayMultipliers[0] * elements.getL()      -
  158.                delaunayMultipliers[1] * elements.getLPrime() -
  159.                delaunayMultipliers[2] * elements.getF()      -
  160.                delaunayMultipliers[3] * elements.getD()      -
  161.                delaunayMultipliers[4] * elements.getOmega();
  162.     }

  163.     /** Get the angular rate of the tide.
  164.      * @param elements elements to use
  165.      * @return angular rate of the tide (radians/second)
  166.      */
  167.     public double getRate(final BodiesElements elements) {
  168.         return doodsonMultipliers[0]  * elements.getGammaDot()  -
  169.                delaunayMultipliers[0] * elements.getLDot()      -
  170.                delaunayMultipliers[1] * elements.getLPrimeDot() -
  171.                delaunayMultipliers[2] * elements.getFDot()      -
  172.                delaunayMultipliers[3] * elements.getDDot()      -
  173.                delaunayMultipliers[4] * elements.getOmegaDot();
  174.     }

  175.     @Override
  176.     public boolean equals(final Object object) {
  177.         if (object instanceof Tide) {
  178.             return doodsonNumber == ((Tide) object).doodsonNumber;
  179.         }
  180.         return false;
  181.     }

  182.     @Override
  183.     public int hashCode() {
  184.         return doodsonNumber;
  185.     }

  186. }