GridEntry.java

  1. /* Copyright 2022-2025 Thales Alenia Space
  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.weather;

  18. import java.util.HashMap;
  19. import java.util.Map;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.util.FieldSinCos;
  22. import org.hipparchus.util.MathUtils;
  23. import org.hipparchus.util.SinCos;

  24. /** Grid entry in Global Pressure Temperature models.
  25.  * @author Luc Maisonobe
  26.  * @since 12.1
  27.  */
  28. class GridEntry {

  29.     /** Conversion factor from degrees to mill arcseconds. */
  30.     public static final int DEG_TO_MAS = 3600000;

  31.     /** Latitude (radian). */
  32.     private final double latitude;

  33.     /** Latitude key (mas). */
  34.     private final int latKey;

  35.     /** Longitude (radian). */
  36.     private final double longitude;

  37.     /** Longitude key (mas). */
  38.     private final int lonKey;

  39.     /** Undulation. */
  40.     private final double undulation;

  41.     /** Height correction. */
  42.     private final double hS;

  43.     /** Seasonal models. */
  44.     private final Map<SeasonalModelType, SeasonalModel> models;

  45.     /** Build an entry from its components.
  46.      * @param latitude latitude (radian)
  47.      * @param latKey latitude key (mas)
  48.      * @param longitude longitude (radian)
  49.      * @param lonKey longitude key (mas)
  50.      * @param undulation undulation (m)
  51.      * @param hS height correction
  52.      * @param models seasonal models
  53.      */
  54.     GridEntry(final double latitude, final int latKey, final double longitude, final int lonKey,
  55.               final double undulation, final double hS, final Map<SeasonalModelType, SeasonalModel> models) {

  56.         this.latitude     = latitude;
  57.         this.latKey       = latKey;
  58.         this.longitude    = longitude;
  59.         this.lonKey       = lonKey;
  60.         this.undulation   = undulation;
  61.         this.hS           = hS;
  62.         this.models       = models;
  63.     }

  64.     /** Build a new entry 360° to the East of instance.
  65.      * @return new wrapping entry (always same type as instance)
  66.      */
  67.     public GridEntry buildWrappedEntry() {
  68.         return new GridEntry(latitude, latKey,
  69.                              longitude + MathUtils.TWO_PI,
  70.                              lonKey + DEG_TO_MAS * 360,
  71.                              undulation, hS,
  72.                              models);
  73.     }

  74.     /** Get latitude (radian).
  75.      * @return latitude (radian)
  76.      */
  77.     public double getLatitude() {
  78.         return latitude;
  79.     }

  80.     /** Get latitude key (mas).
  81.      * @return latitude key (mas)
  82.      */
  83.     public int getLatKey() {
  84.         return latKey;
  85.     }

  86.     /** Get longitude (radian).
  87.      * @return longitude (radian)
  88.      */
  89.     public double getLongitude() {
  90.         return longitude;
  91.     }

  92.     /** Get longitude key (mas).
  93.      * @return longitude key (mas)
  94.      */
  95.     public int getLonKey() {
  96.         return lonKey;
  97.     }

  98.     /** Get undulation.
  99.      * @return undulation
  100.      */
  101.     public double getUndulation() {
  102.         return undulation;
  103.     }

  104.     /** Get height correction.
  105.      * @return height correction
  106.      */
  107.     public double getHs() {
  108.         return hS;
  109.     }

  110.     /** Check if an entry has a model.
  111.      * @param type model type
  112.      * @return true if the entry has the model
  113.      * @since 13.0
  114.      */
  115.     public boolean hasModel(final SeasonalModelType type) {
  116.         return models.containsKey(type);
  117.     }

  118.     /** Evaluate the entry at one date.
  119.      * @param sc1 sine and cosine of yearly harmonic term
  120.      * @param sc2 sine and cosine of bi-yearly harmonic term
  121.      * @param altitude altitude
  122.      * @return evaluated entry
  123.      */
  124.     public EvaluatedGridEntry evaluate(final SinCos sc1, final SinCos sc2, final double altitude) {

  125.         // evaluate all models
  126.         final Map<SeasonalModelType, Double> evaluatedModels = new HashMap<>(models.size());
  127.         for (final Map.Entry<SeasonalModelType, SeasonalModel> entry : models.entrySet()) {
  128.             evaluatedModels.put(entry.getKey(), entry.getValue().evaluate(sc1, sc2));
  129.         }

  130.         // build the evaluated grid entry
  131.         return new EvaluatedGridEntry(this, altitude, evaluatedModels);

  132.     }

  133.     /** Evaluate the entry at one date.
  134.      * @param <T> type of the field elements
  135.      * @param sc1 sine and cosine of yearly harmonic term
  136.      * @param sc2 sine and cosine of bi-yearly harmonic term
  137.      * @param altitude altitude
  138.      * @return evaluated entry
  139.      */
  140.     public <T extends CalculusFieldElement<T>> FieldEvaluatedGridEntry<T> evaluate(final FieldSinCos<T> sc1,
  141.                                                                                    final FieldSinCos<T> sc2,
  142.                                                                                    final T altitude) {

  143.         // evaluate all models
  144.         final Map<SeasonalModelType, T> evaluatedModels = new HashMap<>(models.size());
  145.         for (final Map.Entry<SeasonalModelType, SeasonalModel> entry : models.entrySet()) {
  146.             evaluatedModels.put(entry.getKey(), entry.getValue().evaluate(sc1, sc2));
  147.         }

  148.         // build the evaluated grid entry
  149.         return new FieldEvaluatedGridEntry<>(this, altitude, evaluatedModels);

  150.     }

  151. }