1 /* Copyright 2022-2026 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
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.hipparchus.util.FieldSinCos;
24 import org.hipparchus.util.MathUtils;
25 import org.hipparchus.util.SinCos;
26
27 /** Grid entry in Global Pressure Temperature models.
28 * @author Luc Maisonobe
29 * @since 12.1
30 */
31 class GridEntry {
32
33 /** Latitude (radian). */
34 private final double latitude;
35
36 /** Longitude (radian). */
37 private final double longitude;
38
39 /** Undulation. */
40 private final double undulation;
41
42 /** Height correction. */
43 private final double hS;
44
45 /** Seasonal models. */
46 private final Map<SeasonalModelType, SeasonalModel> models;
47
48 /** Build an entry from its components.
49 * @param latitude latitude (radian)
50 * @param longitude longitude (radian)
51 * @param undulation undulation (m)
52 * @param hS height correction
53 * @param models seasonal models
54 */
55 GridEntry(final double latitude, final double longitude,
56 final double undulation, final double hS, final Map<SeasonalModelType, SeasonalModel> models) {
57
58 this.latitude = latitude;
59 this.longitude = longitude;
60 this.undulation = undulation;
61 this.hS = hS;
62 this.models = models;
63 }
64
65 /** Build a new entry 360° to the East of instance.
66 * @return new wrapping entry (always same type as instance)
67 */
68 public GridEntry buildWrappedEntry() {
69 return new GridEntry(latitude, longitude + MathUtils.TWO_PI, undulation, hS, models);
70 }
71
72 /** Get latitude (radian).
73 * @return latitude (radian)
74 */
75 public double getLatitude() {
76 return latitude;
77 }
78
79 /** Get longitude (radian).
80 * @return longitude (radian)
81 */
82 public double getLongitude() {
83 return longitude;
84 }
85
86 /** Get undulation.
87 * @return undulation
88 */
89 public double getUndulation() {
90 return undulation;
91 }
92
93 /** Get height correction.
94 * @return height correction
95 */
96 public double getHs() {
97 return hS;
98 }
99
100 /** Check if an entry has a model.
101 * @param type model type
102 * @return true if the entry has the model
103 * @since 13.0
104 */
105 public boolean hasModel(final SeasonalModelType type) {
106 return models.containsKey(type);
107 }
108
109 /** Evaluate the entry at one date.
110 * @param sc1 sine and cosine of yearly harmonic term
111 * @param sc2 sine and cosine of bi-yearly harmonic term
112 * @param altitude altitude
113 * @return evaluated entry
114 */
115 public EvaluatedGridEntry evaluate(final SinCos sc1, final SinCos sc2, final double altitude) {
116
117 // evaluate all models
118 final Map<SeasonalModelType, Double> evaluatedModels = new HashMap<>(models.size());
119 for (final Map.Entry<SeasonalModelType, SeasonalModel> entry : models.entrySet()) {
120 evaluatedModels.put(entry.getKey(), entry.getValue().evaluate(sc1, sc2));
121 }
122
123 // build the evaluated grid entry
124 return new EvaluatedGridEntry(this, altitude, evaluatedModels);
125
126 }
127
128 /** Evaluate the entry at one date.
129 * @param <T> type of the field elements
130 * @param sc1 sine and cosine of yearly harmonic term
131 * @param sc2 sine and cosine of bi-yearly harmonic term
132 * @param altitude altitude
133 * @return evaluated entry
134 */
135 public <T extends CalculusFieldElement<T>> FieldEvaluatedGridEntry<T> evaluate(final FieldSinCos<T> sc1,
136 final FieldSinCos<T> sc2,
137 final T altitude) {
138
139 // evaluate all models
140 final Map<SeasonalModelType, T> evaluatedModels = new HashMap<>(models.size());
141 for (final Map.Entry<SeasonalModelType, SeasonalModel> entry : models.entrySet()) {
142 evaluatedModels.put(entry.getKey(), entry.getValue().evaluate(sc1, sc2));
143 }
144
145 // build the evaluated grid entry
146 return new FieldEvaluatedGridEntry<>(this, altitude, evaluatedModels);
147
148 }
149
150 }