SecularTrendSphericalHarmonics.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.potential;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.time.AbsoluteDate;

  20. /** Simple implementation of {@link RawSphericalHarmonicsProvider} for gravity fields with secular trend.
  21.  * @author Luc Maisonobe
  22.  * @since 6.0
  23.  */
  24. class SecularTrendSphericalHarmonics implements RawSphericalHarmonicsProvider {

  25.     /** Non-secular part of the field. */
  26.     private final RawSphericalHarmonicsProvider provider;

  27.     /** Reference date for the harmonics. */
  28.     private final AbsoluteDate referenceDate;

  29.     /** Converter from triangular to flatten array.
  30.      * @since 11.1
  31.      */
  32.     private final Flattener flattener;

  33.     /** Secular trend of the cosine coefficients. */
  34.     private final double[] cTrend;

  35.     /** Secular trend of the sine coefficients. */
  36.     private final double[] sTrend;

  37.     /** Simple constructor.
  38.      * @param provider underlying provider for the non secular part
  39.      * @param referenceDate reference date for the harmonics (considered to be at 12:00 TT)
  40.      * @param flattener flattener from triangular to flatten array
  41.      * @param cTrend secular trend of the cosine coefficients (s<sup>-1</sup>)
  42.      * @param sTrend secular trend of the sine coefficients (s<sup>-1</sup>)
  43.      * @since 11.1
  44.      */
  45.     SecularTrendSphericalHarmonics(final RawSphericalHarmonicsProvider provider, final AbsoluteDate referenceDate,
  46.                                    final Flattener flattener, final double[] cTrend, final double[] sTrend) {
  47.         this.provider      = provider;
  48.         this.referenceDate = referenceDate;
  49.         this.flattener     = flattener;
  50.         this.cTrend        = cTrend.clone();
  51.         this.sTrend        = sTrend.clone();
  52.     }

  53.     /** {@inheritDoc} */
  54.     public int getMaxDegree() {
  55.         return FastMath.max(flattener.getDegree(), provider.getMaxDegree());
  56.     }

  57.     /** {@inheritDoc} */
  58.     public int getMaxOrder() {
  59.         return FastMath.max(flattener.getOrder(), provider.getMaxOrder());
  60.     }

  61.     /** {@inheritDoc} */
  62.     public double getMu() {
  63.         return provider.getMu();
  64.     }

  65.     /** {@inheritDoc} */
  66.     public double getAe() {
  67.         return provider.getAe();
  68.     }

  69.     /** {@inheritDoc} */
  70.     public AbsoluteDate getReferenceDate() {
  71.         return referenceDate;
  72.     }

  73.     /** {@inheritDoc} */
  74.     public TideSystem getTideSystem() {
  75.         return provider.getTideSystem();
  76.     }

  77.     @Override
  78.     public RawSphericalHarmonics onDate(final AbsoluteDate date) {
  79.         final RawSphericalHarmonics harmonics = provider.onDate(date);
  80.         //compute date offset from reference
  81.         final double dateOffset = date.durationFrom(referenceDate);
  82.         return new RawSphericalHarmonics() {

  83.             @Override
  84.             public AbsoluteDate getDate() {
  85.                 return date;
  86.             }

  87.             /** {@inheritDoc} */
  88.             public double getRawCnm(final int n, final int m) {

  89.                 // retrieve the constant part of the coefficient
  90.                 double cnm = harmonics.getRawCnm(n, m);

  91.                 if (flattener.withinRange(n, m)) {
  92.                     // add secular trend
  93.                     cnm += dateOffset * cTrend[flattener.index(n, m)];
  94.                 }

  95.                 return cnm;

  96.             }

  97.             /** {@inheritDoc} */
  98.             public double getRawSnm(final int n, final int m) {

  99.                 // retrieve the constant part of the coefficient
  100.                 double snm = harmonics.getRawSnm(n, m);

  101.                 if (flattener.withinRange(n, m)) {
  102.                     // add secular trend
  103.                     snm += dateOffset * sTrend[flattener.index(n, m)];
  104.                 }

  105.                 return snm;

  106.             }

  107.         };
  108.     }

  109. }