SolidTidesField.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.forces.gravity;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.bodies.CelestialBody;
  21. import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
  22. import org.orekit.forces.gravity.potential.TideSystem;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.TimeVectorFunction;
  26. import org.orekit.utils.LoveNumbers;

  27. /** Gravity field corresponding to solid tides.
  28.  * <p>
  29.  * This solid tides force model implementation corresponds to the method described
  30.  * in <a href="http://www.iers.org/nn_11216/IERS/EN/Publications/TechnicalNotes/tn36.html">
  31.  * IERS conventions (2010)</a>, chapter 6, section 6.2.
  32.  * </p>
  33.  * <p>
  34.  * The computation of the spherical harmonics part is done using the algorithm
  35.  * designed by S. A. Holmes and W. E. Featherstone from Department of Spatial Sciences,
  36.  * Curtin University of Technology, Perth, Australia and described in their 2002 paper:
  37.  * <a href="https://www.researchgate.net/publication/226460594_A_unified_approach_to_the_Clenshaw_summation_and_the_recursive_computation_of_very_high_degree_and_order_normalised_associated_Legendre_functions">
  38.  * A unified approach to the Clenshaw summation and the recursive computation of
  39.  * very high degree and order normalised associated Legendre functions</a>
  40.  * (Journal of Geodesy (2002) 76: 279–299).
  41.  * </p>
  42.  * <p>
  43.  * Note that this class is <em>not</em> thread-safe, and that tides computation
  44.  * are computer intensive if repeated. So this class is really expected to
  45.  * be wrapped within a {@link
  46.  * org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider}
  47.  * that will both ensure thread safety and improve performances using caching.
  48.  * </p>
  49.  * @see SolidTides
  50.  * @author Luc Maisonobe
  51.  * @since 6.1
  52.  */
  53. class SolidTidesField implements NormalizedSphericalHarmonicsProvider {

  54.     /** Maximum degree for normalized Legendre functions. */
  55.     private static final int MAX_LEGENDRE_DEGREE = 4;

  56.     /** Love numbers. */
  57.     private final LoveNumbers love;

  58.     /** Function computing frequency dependent terms (ΔC₂₀, ΔC₂₁, ΔS₂₁, ΔC₂₂, ΔS₂₂). */
  59.     private final TimeVectorFunction deltaCSFunction;

  60.     /** Permanent tide to be <em>removed</em> from ΔC₂₀ when zero-tide potentials are used. */
  61.     private final double deltaC20PermanentTide;

  62.     /** Function computing pole tide terms (ΔC₂₁, ΔS₂₁). */
  63.     private final TimeVectorFunction poleTideFunction;

  64.     /** Rotating body frame. */
  65.     private final Frame centralBodyFrame;

  66.     /** Central body reference radius. */
  67.     private final double ae;

  68.     /** Central body attraction coefficient. */
  69.     private final double mu;

  70.     /** Tide system used in the central attraction model. */
  71.     private final TideSystem centralTideSystem;

  72.     /** Tide generating bodies (typically Sun and Moon). Read only after construction. */
  73.     private final CelestialBody[] bodies;

  74.     /** First recursion coefficients for tesseral terms. Read only after construction. */
  75.     private final double[][] anm;

  76.     /** Second recursion coefficients for tesseral terms. Read only after construction. */
  77.     private final double[][] bnm;

  78.     /** Third recursion coefficients for sectorial terms. Read only after construction. */
  79.     private final double[] dmm;

  80.     /** Simple constructor.
  81.      * @param love Love numbers
  82.      * @param deltaCSFunction function computing frequency dependent terms (ΔC₂₀, ΔC₂₁, ΔS₂₁, ΔC₂₂, ΔS₂₂)
  83.      * @param deltaC20PermanentTide permanent tide to be <em>removed</em> from ΔC₂₀ when zero-tide potentials are used
  84.      * @param poleTideFunction function computing pole tide terms (ΔC₂₁, ΔS₂₁), may be null
  85.      * @param centralBodyFrame rotating body frame
  86.      * @param ae central body reference radius
  87.      * @param mu central body attraction coefficient
  88.      * @param centralTideSystem tide system used in the central attraction model
  89.      * @param bodies tide generating bodies (typically Sun and Moon)
  90.      */
  91.     SolidTidesField(final LoveNumbers love, final TimeVectorFunction deltaCSFunction,
  92.                            final double deltaC20PermanentTide, final TimeVectorFunction poleTideFunction,
  93.                            final Frame centralBodyFrame, final double ae, final double mu,
  94.                            final TideSystem centralTideSystem, final CelestialBody... bodies) {

  95.         // store mode parameters
  96.         this.centralBodyFrame  = centralBodyFrame;
  97.         this.ae                = ae;
  98.         this.mu                = mu;
  99.         this.centralTideSystem = centralTideSystem;
  100.         this.bodies            = bodies;

  101.         // compute recursion coefficients for Legendre functions
  102.         this.anm               = buildTriangularArray(5, false);
  103.         this.bnm               = buildTriangularArray(5, false);
  104.         this.dmm               = new double[love.getSize()];
  105.         recursionCoefficients();

  106.         // Love numbers
  107.         this.love = love;

  108.         // frequency dependent terms
  109.         this.deltaCSFunction = deltaCSFunction;

  110.         // permanent tide
  111.         this.deltaC20PermanentTide = deltaC20PermanentTide;

  112.         // pole tide
  113.         this.poleTideFunction = poleTideFunction;

  114.     }

  115.     /** {@inheritDoc} */
  116.     @Override
  117.     public int getMaxDegree() {
  118.         return MAX_LEGENDRE_DEGREE;
  119.     }

  120.     /** {@inheritDoc} */
  121.     @Override
  122.     public int getMaxOrder() {
  123.         return MAX_LEGENDRE_DEGREE;
  124.     }

  125.     /** {@inheritDoc} */
  126.     @Override
  127.     public double getMu() {
  128.         return mu;
  129.     }

  130.     /** {@inheritDoc} */
  131.     @Override
  132.     public double getAe() {
  133.         return ae;
  134.     }

  135.     /** {@inheritDoc} */
  136.     @Override
  137.     public AbsoluteDate getReferenceDate() {
  138.         return AbsoluteDate.ARBITRARY_EPOCH;
  139.     }

  140.     /** {@inheritDoc} */
  141.     @Override
  142.     public TideSystem getTideSystem() {
  143.         // not really used here, but for consistency we can state that either
  144.         // we add the permanent tide or it was already in the central attraction
  145.         return TideSystem.ZERO_TIDE;
  146.     }

  147.     /** {@inheritDoc} */
  148.     @Override
  149.     public NormalizedSphericalHarmonics onDate(final AbsoluteDate date) {

  150.         // computed Cnm and Snm coefficients
  151.         final double[][] cnm = buildTriangularArray(5, true);
  152.         final double[][] snm = buildTriangularArray(5, true);

  153.         // work array to hold Legendre coefficients
  154.         final double[][] pnm = buildTriangularArray(5, true);

  155.         // step 1: frequency independent part
  156.         // equations 6.6 (for degrees 2 and 3) and 6.7 (for degree 4) in IERS conventions 2010
  157.         for (final CelestialBody body : bodies) {

  158.             // compute tide generating body state
  159.             final Vector3D position = body.getPosition(date, centralBodyFrame);

  160.             // compute polar coordinates
  161.             final double x    = position.getX();
  162.             final double y    = position.getY();
  163.             final double z    = position.getZ();
  164.             final double x2   = x * x;
  165.             final double y2   = y * y;
  166.             final double z2   = z * z;
  167.             final double r2   = x2 + y2 + z2;
  168.             final double r    = FastMath.sqrt (r2);
  169.             final double rho2 = x2 + y2;
  170.             final double rho  = FastMath.sqrt(rho2);

  171.             // evaluate Pnm
  172.             evaluateLegendre(z / r, rho / r, pnm);

  173.             // update spherical harmonic coefficients
  174.             frequencyIndependentPart(r, body.getGM(), x / rho, y / rho, pnm, cnm, snm);

  175.         }

  176.         // step 2: frequency dependent corrections
  177.         frequencyDependentPart(date, cnm, snm);

  178.         if (centralTideSystem == TideSystem.ZERO_TIDE) {
  179.             // step 3: remove permanent tide which is already considered
  180.             // in the central body gravity field
  181.             removePermanentTide(cnm);
  182.         }

  183.         if (poleTideFunction != null) {
  184.             // add pole tide
  185.             poleTide(date, cnm, snm);
  186.         }

  187.         return new TideHarmonics(date, cnm, snm);

  188.     }

  189.     /** Compute recursion coefficients. */
  190.     private void recursionCoefficients() {

  191.         // pre-compute the recursion coefficients
  192.         // (see equations 11 and 12 from Holmes and Featherstone paper)
  193.         for (int n = 0; n < anm.length; ++n) {
  194.             for (int m = 0; m < n; ++m) {
  195.                 final double f = (n - m) * (n + m );
  196.                 anm[n][m] = FastMath.sqrt((2 * n - 1) * (2 * n + 1) / f);
  197.                 bnm[n][m] = FastMath.sqrt((2 * n + 1) * (n + m - 1) * (n - m - 1) / (f * (2 * n - 3)));
  198.             }
  199.         }

  200.         // sectorial terms corresponding to equation 13 in Holmes and Featherstone paper
  201.         dmm[0] = Double.NaN; // dummy initialization for unused term
  202.         dmm[1] = Double.NaN; // dummy initialization for unused term
  203.         for (int m = 2; m < dmm.length; ++m) {
  204.             dmm[m] = FastMath.sqrt((2 * m + 1) / (2.0 * m));
  205.         }

  206.     }

  207.     /** Evaluate Legendre functions.
  208.      * @param t cos(θ), where θ is the polar angle
  209.      * @param u sin(θ), where θ is the polar angle
  210.      * @param pnm the computed coefficients. Modified in place.
  211.      */
  212.     private void evaluateLegendre(final double t, final double u, final double[][] pnm) {

  213.         // as the degree is very low, we use the standard forward column method
  214.         // and store everything (see equations 11 and 13 from Holmes and Featherstone paper)
  215.         pnm[0][0] = 1;
  216.         pnm[1][0] = anm[1][0] * t;
  217.         pnm[1][1] = FastMath.sqrt(3) * u;
  218.         for (int m = 2; m < dmm.length; ++m) {
  219.             pnm[m][m - 1] = anm[m][m - 1] * t * pnm[m - 1][m - 1];
  220.             pnm[m][m]     = dmm[m] * u * pnm[m - 1][m - 1];
  221.         }
  222.         for (int m = 0; m < dmm.length; ++m) {
  223.             for (int n = m + 2; n < pnm.length; ++n) {
  224.                 pnm[n][m] = anm[n][m] * t * pnm[n - 1][m] - bnm[n][m] * pnm[n - 2][m];
  225.             }
  226.         }

  227.     }

  228.     /** Update coefficients applying frequency independent step, for one tide generating body.
  229.      * @param r distance to tide generating body
  230.      * @param gm tide generating body attraction coefficient
  231.      * @param cosLambda cosine of the tide generating body longitude
  232.      * @param sinLambda sine of the tide generating body longitude
  233.      * @param pnm the Legendre coefficients. See {@link #evaluateLegendre(double, double, double[][])}.
  234.      * @param cnm the computed Cnm coefficients. Modified in place.
  235.      * @param snm the computed Snm coefficients. Modified in place.
  236.      */
  237.     private void frequencyIndependentPart(final double r,
  238.                                           final double gm,
  239.                                           final double cosLambda,
  240.                                           final double sinLambda,
  241.                                           final double[][] pnm,
  242.                                           final double[][] cnm,
  243.                                           final double[][] snm) {

  244.         final double rRatio = ae / r;
  245.         double fM           = gm / mu;
  246.         double cosMLambda   = 1;
  247.         double sinMLambda   = 0;
  248.         for (int m = 0; m < love.getSize(); ++m) {

  249.             double fNPlus1 = fM;
  250.             for (int n = m; n < love.getSize(); ++n) {
  251.                 fNPlus1 *= rRatio;
  252.                 final double coeff = (fNPlus1 / (2 * n + 1)) * pnm[n][m];
  253.                 final double cCos  = coeff * cosMLambda;
  254.                 final double cSin  = coeff * sinMLambda;

  255.                 // direct effect of degree n tides on degree n coefficients
  256.                 // equation 6.6 from IERS conventions (2010)
  257.                 final double kR = love.getReal(n, m);
  258.                 final double kI = love.getImaginary(n, m);
  259.                 cnm[n][m] += kR * cCos + kI * cSin;
  260.                 snm[n][m] += kR * cSin - kI * cCos;

  261.                 if (n == 2) {
  262.                     // indirect effect of degree 2 tides on degree 4 coefficients
  263.                     // equation 6.7 from IERS conventions (2010)
  264.                     final double kP = love.getPlus(n, m);
  265.                     cnm[4][m] += kP * cCos;
  266.                     snm[4][m] += kP * cSin;
  267.                 }

  268.             }

  269.             // prepare next iteration on order
  270.             final double tmp = cosMLambda * cosLambda - sinMLambda * sinLambda;
  271.             sinMLambda = sinMLambda * cosLambda + cosMLambda * sinLambda;
  272.             cosMLambda = tmp;
  273.             fM        *= rRatio;

  274.         }

  275.     }

  276.     /** Update coefficients applying frequency dependent step.
  277.      * @param date current date
  278.      * @param cnm the Cnm coefficients. Modified in place.
  279.      * @param snm the Snm coefficients. Modified in place.
  280.      */
  281.     private void frequencyDependentPart(final AbsoluteDate date,
  282.                                         final double[][] cnm,
  283.                                         final double[][] snm) {
  284.         final double[] deltaCS = deltaCSFunction.value(date);
  285.         cnm[2][0] += deltaCS[0]; // ΔC₂₀
  286.         cnm[2][1] += deltaCS[1]; // ΔC₂₁
  287.         snm[2][1] += deltaCS[2]; // ΔS₂₁
  288.         cnm[2][2] += deltaCS[3]; // ΔC₂₂
  289.         snm[2][2] += deltaCS[4]; // ΔS₂₂
  290.     }

  291.     /** Remove the permanent tide already counted in zero-tide central gravity fields.
  292.      * @param cnm the Cnm coefficients. Modified in place.
  293.      */
  294.     private void removePermanentTide(final double[][] cnm) {
  295.         cnm[2][0] -= deltaC20PermanentTide;
  296.     }

  297.     /** Update coefficients applying pole tide.
  298.      * @param date current date
  299.      * @param cnm the Cnm coefficients. Modified in place.
  300.      * @param snm the Snm coefficients. Modified in place.
  301.      */
  302.     private void poleTide(final AbsoluteDate date,
  303.                           final double[][] cnm,
  304.                           final double[][] snm) {
  305.         final double[] deltaCS = poleTideFunction.value(date);
  306.         cnm[2][1] += deltaCS[0]; // ΔC₂₁
  307.         snm[2][1] += deltaCS[1]; // ΔS₂₁
  308.     }

  309.     /** Create a triangular array.
  310.      * @param size array size
  311.      * @param withDiagonal if true, the array contains a[p][p] terms, otherwise each
  312.      * row ends up at a[p][p-1]
  313.      * @return new triangular array
  314.      */
  315.     private double[][] buildTriangularArray(final int size, final boolean withDiagonal) {
  316.         final double[][] array = new double[size][];
  317.         for (int i = 0; i < array.length; ++i) {
  318.             array[i] = new double[withDiagonal ? i + 1 : i];
  319.         }
  320.         return array;
  321.     }

  322.     /** The Tidal geopotential evaluated on a specific date. */
  323.     private static class TideHarmonics implements NormalizedSphericalHarmonics {

  324.         /** evaluation date. */
  325.         private final AbsoluteDate date;

  326.         /** Cached cnm. */
  327.         private final double[][] cnm;

  328.         /** Cached snm. */
  329.         private final double[][] snm;

  330.         /** Construct the tidal harmonics on the given date.
  331.          *
  332.          * @param date of evaluation
  333.          * @param cnm the Cnm coefficients. Not copied.
  334.          * @param snm the Snm coeffiecients. Not copied.
  335.          */
  336.         private TideHarmonics(final AbsoluteDate date,
  337.                               final double[][] cnm,
  338.                               final double[][] snm) {
  339.             this.date = date;
  340.             this.cnm = cnm;
  341.             this.snm = snm;
  342.         }

  343.         /** {@inheritDoc} */
  344.         @Override
  345.         public AbsoluteDate getDate() {
  346.             return date;
  347.         }

  348.         /** {@inheritDoc} */
  349.         @Override
  350.         public double getNormalizedCnm(final int n, final int m) {
  351.             return cnm[n][m];
  352.         }

  353.         /** {@inheritDoc} */
  354.         @Override
  355.         public double getNormalizedSnm(final int n, final int m) {
  356.             return snm[n][m];
  357.         }

  358.     }

  359. }