HeightDependentPressureTemperatureHumidityConverter.java

  1. /* Copyright 2002-2024 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.models.earth.weather.water.WaterVaporPressureProvider;

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

  30.     /** Water pressure provider for water vapor pressure. */
  31.     private final WaterVaporPressureProvider provider;

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

  41.     /** Convert weather parameters.
  42.      * @param pth0 weather at reference altitude
  43.      * @param h altitude at which weather is requested
  44.      * @return converted weather
  45.      */
  46.     public PressureTemperatureHumidity convert(final PressureTemperatureHumidity pth0,
  47.                                                final double h) {

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

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

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

  57.     }

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

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

  76. }