1   /* Copyright 2002-2019 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.forces.gravity.potential;
18  
19  import org.orekit.time.AbsoluteDate;
20  import org.orekit.time.DateComponents;
21  import org.orekit.time.TimeComponents;
22  import org.orekit.time.TimeScalesFactory;
23  
24  /** Simple implementation of {@link RawSphericalHarmonicsProvider} for gravity fields with secular trend.
25   * @author Luc Maisonobe
26   * @since 6.0
27   */
28  class SecularTrendSphericalHarmonics implements RawSphericalHarmonicsProvider {
29  
30      /** Non-secular part of the field. */
31      private final RawSphericalHarmonicsProvider provider;
32  
33      /** Reference date for the harmonics. */
34      private final AbsoluteDate referenceDate;
35  
36      /** Secular trend of the cosine coefficients. */
37      private final double[][] cTrend;
38  
39      /** Secular trend of the sine coefficients. */
40      private final double[][] sTrend;
41  
42      /** Simple constructor.
43       * @param provider underlying provider for the non secular part
44       * @param referenceDate reference date for the harmonics (considered to be at 12:00 TT)
45       * @param cTrend secular trend of the cosine coefficients (s<sup>-1</sup>)
46       * @param sTrend secular trend of the sine coefficients (s<sup>-1</sup>)
47       */
48      SecularTrendSphericalHarmonics(final RawSphericalHarmonicsProvider provider,
49                                            final DateComponents referenceDate,
50                                            final double[][] cTrend, final double[][] sTrend) {
51          this.provider      = provider;
52          this.referenceDate = new AbsoluteDate(referenceDate, TimeComponents.H12, TimeScalesFactory.getTT());
53          this.cTrend        = cTrend;
54          this.sTrend        = sTrend;
55      }
56  
57      /** {@inheritDoc} */
58      public int getMaxDegree() {
59          return provider.getMaxDegree();
60      }
61  
62      /** {@inheritDoc} */
63      public int getMaxOrder() {
64          return provider.getMaxOrder();
65      }
66  
67      /** {@inheritDoc} */
68      public double getMu() {
69          return provider.getMu();
70      }
71  
72      /** {@inheritDoc} */
73      public double getAe() {
74          return provider.getAe();
75      }
76  
77      /** {@inheritDoc} */
78      public AbsoluteDate getReferenceDate() {
79          return referenceDate;
80      }
81  
82      /** {@inheritDoc} */
83      public double getOffset(final AbsoluteDate date) {
84          return date.durationFrom(referenceDate);
85      }
86  
87      /** {@inheritDoc} */
88      public TideSystem getTideSystem() {
89          return provider.getTideSystem();
90      }
91  
92      @Override
93      public RawSphericalHarmonics onDate(final AbsoluteDate date) {
94          final RawSphericalHarmonics harmonics = provider.onDate(date);
95          //compute date offset from reference
96          final double dateOffset = getOffset(date);
97          return new RawSphericalHarmonics() {
98  
99              @Override
100             public AbsoluteDate getDate() {
101                 return date;
102             }
103 
104             /** {@inheritDoc} */
105             public double getRawCnm(final int n, final int m) {
106 
107                 // retrieve the constant part of the coefficient
108                 double cnm = harmonics.getRawCnm(n, m);
109 
110                 if (n < cTrend.length && m < cTrend[n].length) {
111                     // add secular trend
112                     cnm += dateOffset * cTrend[n][m];
113                 }
114 
115                 return cnm;
116 
117             }
118 
119             /** {@inheritDoc} */
120             public double getRawSnm(final int n, final int m) {
121 
122                 // retrieve the constant part of the coefficient
123                 double snm = harmonics.getRawSnm(n, m);
124 
125                 if (n < sTrend.length && m < sTrend[n].length) {
126                     // add secular trend
127                     snm += dateOffset * sTrend[n][m];
128                 }
129 
130                 return snm;
131 
132             }
133 
134         };
135     }
136 
137 }