FieldEvaluatedGridEntry.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 org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.utils.Constants;

  21. import java.util.Map;

  22. /** Grid entry in Global Pressure Temperature models, evaluated at some date.
  23.  * @param <T> type oif the field elements
  24.  * @author Luc Maisonobe
  25.  * @since 13.0
  26.  */
  27. class FieldEvaluatedGridEntry<T extends CalculusFieldElement<T>> {

  28.     /** Standard gravity constant [m/s²]. */
  29.     private static final double G = Constants.G0_STANDARD_GRAVITY;

  30.     /** Molar mass of dry air in kg/mol. */
  31.     private static final double DMTR = 28.965e-3;

  32.     /** Universal gas constant in J/K/mol. */
  33.     private static final double RG = 8.3143;

  34.     /** Underlying fixed grid entry. */
  35.     private final GridEntry entry;

  36.     /** Corrected height. */
  37.     private final T correctedHeight;

  38.     /** Virtual temperature factor. */
  39.     private final T factor;

  40.     /** Evaluated seasonal models. */
  41.     private final Map<SeasonalModelType, T> evaluatedModels;

  42.     /** Build an entry from its components.
  43.      * @param entry underlying fixed entry
  44.      * @param altitude altitude
  45.      * @param evaluatedModels evaluated models
  46.      */
  47.     FieldEvaluatedGridEntry(final GridEntry entry, final T altitude,
  48.                             final Map<SeasonalModelType, T> evaluatedModels) {
  49.         this.entry           = entry;
  50.         this.evaluatedModels = evaluatedModels;
  51.         this.correctedHeight = altitude.subtract(entry.getUndulation() + entry.getHs());
  52.         final T t0 = getEvaluatedModel(SeasonalModelType.TEMPERATURE);
  53.         final T qv = getEvaluatedModel(SeasonalModelType.QV).multiply(0.001);
  54.         final T tv = t0.multiply(qv.multiply(0.6077).add(1));
  55.         this.factor          = correctedHeight.negate().multiply(G * DMTR / RG).divide(tv);
  56.     }

  57.     /** Get underlying fixed entry.
  58.      * @return underlying fixed entry
  59.      */
  60.     public GridEntry getEntry() {
  61.         return entry;
  62.     }

  63.     /** Get evaluated model.
  64.      * @param type model type
  65.      * @return evaluated model type
  66.      */
  67.     public T getEvaluatedModel(final SeasonalModelType type) {
  68.         return evaluatedModels.get(type);
  69.     }

  70.     /** Get temperature.
  71.      * @return temperature
  72.      */
  73.     public T getTemperature() {
  74.         final T t0   = getEvaluatedModel(SeasonalModelType.TEMPERATURE);
  75.         final T dtdh = getEvaluatedModel(SeasonalModelType.DT).multiply(0.001);
  76.         return t0.add(dtdh.multiply(correctedHeight));
  77.     }

  78.     /** Get pressure.
  79.      * @return pressure
  80.      */
  81.     public T getPressure() {
  82.         final T p0 = getEvaluatedModel(SeasonalModelType.PRESSURE).multiply(0.01);
  83.         return FastMath.exp(factor).multiply(p0);
  84.     }

  85.     /** Get water vapor pressure.
  86.      * <p>
  87.      * This applies only to GPT2w and GPT3 as GPT2 does not have water vapor decrease factor λ
  88.      * </p>
  89.      * @return water vapor pressure
  90.      */
  91.     public T getWaterVaporPressure() {
  92.         final T p0     = getEvaluatedModel(SeasonalModelType.PRESSURE).multiply(0.01);
  93.         final T qv     = getEvaluatedModel(SeasonalModelType.QV).multiply(0.001);
  94.         final T e0     = p0.multiply(qv).divide(qv.multiply(0.378).add(0.622));
  95.         final T lambda = getEvaluatedModel(SeasonalModelType.LAMBDA);
  96.         return FastMath.exp(factor.multiply(lambda.add(1))).multiply(e0);
  97.     }

  98. }