HeightDependentPressureTemperatureHumidityConverter.java

  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.weather;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.bodies.GeodeticPoint;
  22. import org.orekit.models.earth.weather.water.WaterVaporPressureProvider;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.time.FieldAbsoluteDate;

  25. /** Converter for weather parameters that change with height.
  26.  * <p>
  27.  * Height variations correspond to equations 5.98, 5.99 and 5.100 from
  28.  * Guochang Xu, GPS - Theory, Algorithms and Applications, Springer, 2007
  29.  * </p>
  30.  * @author Luc Maisonobe
  31.  * @since 12.1
  32.  */
  33. public class HeightDependentPressureTemperatureHumidityConverter {

  34.     /** Water pressure provider for water vapor pressure. */
  35.     private final WaterVaporPressureProvider provider;

  36.     /** Simple constructor.
  37.      * <p>
  38.      * Points outside of altitude range will be silently clipped back to range.
  39.      * </p>
  40.      * @param provider provider for water vapor pressure
  41.      */
  42.     public HeightDependentPressureTemperatureHumidityConverter(final WaterVaporPressureProvider provider) {
  43.         this.provider = provider;
  44.     }

  45.     /** Convert weather parameters.
  46.      * @param pth0 weather at reference altitude
  47.      * @param h altitude at which weather is requested
  48.      * @return converted weather
  49.      */
  50.     public PressureTemperatureHumidity convert(final PressureTemperatureHumidity pth0,
  51.                                                final double h) {

  52.         // retrieve parameters at reference altitude
  53.         final double rh0 = provider.relativeHumidity(pth0.getPressure(), pth0.getTemperature(), pth0.getWaterVaporPressure());

  54.         // compute changes due to altitude change
  55.         final double dh = h - pth0.getAltitude();
  56.         final double p  = pth0.getPressure() * FastMath.pow(1.0 - 2.26e-5 * dh, 5.225);
  57.         final double t  = pth0.getTemperature() - 6.5e-3 * dh;
  58.         final double rh = rh0 * FastMath.exp(-6.396e-4 * dh);

  59.         return new PressureTemperatureHumidity(h, p, t, provider.waterVaporPressure(p, t, rh),
  60.                                                pth0.getTm(), pth0.getLambda());

  61.     }

  62.     /** Convert weather parameters.
  63.      * @param <T> type of the elements
  64.      * @param pth0 weather at reference altitude
  65.      * @param h altitude at which weather is requested
  66.      * @return converted weather
  67.      */
  68.     public <T extends CalculusFieldElement<T>> FieldPressureTemperatureHumidity<T> convert(final FieldPressureTemperatureHumidity<T> pth0,
  69.                                                                                            final T h) {
  70.         // retrieve parameters at reference altitude
  71.         final T rh0 = provider.relativeHumidity(pth0.getPressure(), pth0.getTemperature(), pth0.getWaterVaporPressure());

  72.         // compute changes due to altitude change
  73.         final T dh = h.subtract(pth0.getAltitude());
  74.         final T t  = pth0.getTemperature().subtract(dh.multiply(6.5e-3));
  75.         final T p  = pth0.getPressure().multiply(dh.multiply(2.26e-5).negate().add(1.0).pow(5.225));
  76.         final T rh = rh0.multiply(FastMath.exp(dh.multiply(-6.396e-4)));
  77.         return new FieldPressureTemperatureHumidity<>(h, p, t, provider.waterVaporPressure(p, t, rh),
  78.                                                       pth0.getTm(), pth0.getLambda());
  79.     }

  80.     /** Generate a provider applying altitude dependency to fixed weather parameters.
  81.      * @param basePTH base weather parameters
  82.      * @return a provider that applies altitude dependency
  83.      * @since 13.0
  84.      */
  85.     public PressureTemperatureHumidityProvider getProvider(final PressureTemperatureHumidity basePTH) {
  86.         return new PressureTemperatureHumidityProvider() {

  87.             /** {@inheritDoc} */
  88.             @Override
  89.             public PressureTemperatureHumidity getWeatherParameters(final GeodeticPoint location,
  90.                                                                     final AbsoluteDate date) {
  91.                 return convert(basePTH, location.getAltitude());
  92.             }

  93.             /** {@inheritDoc} */
  94.             @Override
  95.             public <T extends CalculusFieldElement<T>> FieldPressureTemperatureHumidity<T>
  96.                 getWeatherParameters(final FieldGeodeticPoint<T> location, final FieldAbsoluteDate<T> date) {
  97.                 return convert(new FieldPressureTemperatureHumidity<>(date.getField(), basePTH),
  98.                                location.getAltitude());
  99.             }
  100.         };
  101.     }

  102. }