1   /* Copyright 2022-2025 Thales Alenia Space
2    * Licensed to CS Communication & Systèmes (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.troposphere.iturp834;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.util.FastMath;
21  import org.hipparchus.util.MathUtils;
22  import org.orekit.bodies.FieldGeodeticPoint;
23  import org.orekit.bodies.GeodeticPoint;
24  import org.orekit.utils.Constants;
25  import org.orekit.utils.units.Unit;
26  
27  /** Grid data with harmonic seasonal fluctuation.
28   * @author Luc Maisonobe
29   * @since 13.0
30   */
31  class SeasonalGrid extends AbstractGrid {
32  
33      /** Annual pulsation. */
34      private static final double OMEGA = MathUtils.TWO_PI / Constants.JULIAN_YEAR;
35  
36      /** Average data. */
37      private final double[][] average;
38  
39      /** Seasonal fluctuation data. */
40      private final double[][] seasonal;
41  
42      /** Second of minimum data. */
43      private final double[][] minSecond;
44  
45      /** Build a grid by parsing three resource files.
46       * @param unit unit of the average and seasonal fluctuation values in resource files
47       * @param averageName name of the resource holding the average data
48       * @param seasonalName name of the resource holding the seasonal fluctuation data
49       * @param minDayName name of the resource holding the day of minimum data
50       */
51      SeasonalGrid(final Unit unit,
52                   final String averageName, final String seasonalName, final String minDayName) {
53          average   = parse(unit,     averageName);
54          seasonal  = parse(unit,     seasonalName);
55          // we convert from days to SI units (i.e. seconds) upon reading
56          minSecond = parse(Unit.DAY, minDayName);
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public GridCell getCell(final GeodeticPoint location, final double secondOfYear) {
62          return new GridCell((a, s, m) -> a - s * FastMath.cos(OMEGA * (secondOfYear - m)),
63                              getRawCell(location, average),
64                              getRawCell(location, seasonal),
65                              getRawCell(location, minSecond));
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public <T extends CalculusFieldElement<T>> FieldGridCell<T> getCell(final FieldGeodeticPoint<T> location,
71                                                                          final T secondOfYear) {
72          return new FieldGridCell<>((a, s, m) -> a.subtract(s.multiply(FastMath.cos(secondOfYear.subtract(m).multiply(OMEGA)))),
73                                     getRawCell(location, average),
74                                     getRawCell(location, seasonal),
75                                     getRawCell(location, minSecond));
76      }
77  
78  }