velitherm
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    Velitherm

    License: LGPL v3 Node.js CI npm version codecov

    A library of basic thermodynamics equations for soaring flight.

    As used by the weather site https://www.velivole.fr / https://www.meteo.guru

    Zero-dependency!

    If you are new to weather thermodynamics, you should probably start here: Basic Concepts of Thermodynamics for Soaring Flight

    Si vous n'êtes pas à l'aise en thermodynamique appliquée à la météorologie, vous devriez peut-être commencer ici: Bases de la thermodynamique pour le vol libre et le vol à voile

    Installation

    npm install --save velitherm
    

    Usage

    Keep in mind that some equations are numerical approximations of differential equations that have no analytic solutions. The approximations used are the typical weather science approximations which produce good results for temperatures in the range of -40°C to +40°C and air pressures in the range of 1050hPa to 200hPa - which are the typical values in the troposphere - but often lack precision outside this range.

    You can check velitherm-visu for a real-world example of using this library. It is hosted at aircalc.velivole.fr.

    Common JS

    const velitherm = require('velitherm');
    
    // must be very close to 1000
    const alt = velitherm.altitudeFromPressure(898.746);

    ECMAScript 6

    import * as velitherm from 'velitherm';
    
    // must be very close to 1000
    const alt = velitherm.altitudeFromPressure(898.746);

    TypeScript

    import * as velitherm from 'velitherm';
    
    // must be very close to 1000
    const alt = velitherm.altitudeFromPressure(898.746);

    C/C++

    #include "node_modules/velitherm/include/velitherm.h"
    
    // must be very close to 1000
    double alt = velitherm::altitudeFromPressure(898.746);

    Barometric and hypsometric equations

    There is no single analytical equation that can be used to give a precise value for the altitude / pressure relationship. In fact, this relationship depends on the full vertical temperature and humidity profile and it is impossible to reduce to a single formula. There are two levels of approximation that are widely used:

    • The barometric formula, which is an ICAO standard and gives a rough value that does not take into account the pressure or the temperature of the day and it is always constant - in aviation it is referred by the callsign QNH
    • The hypsometric formula, which is commonly used in weather science and it is a better estimation that takes into account the pressure and the temperature of the day - so it varies from one day to another - in aviation it is referred by the callsign QFF

    If you are coming from an aviation background, and QNH, QFF and QFE are altimeter settings to you, then you should know that they actually refer to different equations for calculating the altitude from the pressure. QFE refers to the surface pressure of a given site - airport or weather station - and not an equation. If you want to use velitherm to convert between altimeter settings, the right way to do it would be to convert the pressure to altitude using the input setting and then convert it back to pressure using the output setting.

    Example

    An air parcel with relative humidify of 75% and temperature of 25°C rises from 0m AMSL to 500m AMSL where the surrounding temperature is 20°C. What is its new relative humidity? What is its new temperature? Has there been condensation and did it form a cloud? Has the ceiling being reached or will the air parcel continue to rise? The pressure of the day is 1017hPa.

    Solution:

    import * as velitherm from 'velitherm';
    
    // When the air rises, its specific humidity remains constant
    const q = velitherm.specificHumidity(75, 1017, 25);
    console.log('Specific humidity = ', Math.round(q), 'g/kg');
    
    // Find the current pressure at 500m AMSL
    const P1 = velitherm.pressureFromAltitude(500, 1017, 25);
    console.log('Pressure at 500m = ', Math.round(P1), 'hPa');
    
    // Take into account the adiabatic cooling
    const T1 = 25 - 500 * velitherm.gamma;
    console.log('The new temperature of the air parcel at 500m = ', (T1-25)/2, '°C');
    
    // Compute the new relative humidity of the air parcel at this pressure and temperature
    const w1 = velitherm.relativeHumidity(q, P1, T1);
    console.log('Relative humidity after rising to 500m = ', Math.round(w1), '%');
    
    // If the air parcel has reached 100% humidity, there is condensation
    if (w1 < 100) {
      console.log('No, it did not form a cloud');
    } else {
      console.log('Yes, it did form a cloud');
    }
    
    if (T1 < 20) {
      console.log('The ceiling has been reached');
    } else {
      console.log('The air parcel will continue to rise');
    }

    API

    Table of Contents

    velitherm

    velivole.fr/meteo.guru Basic Thermodynamics Equations for Soaring Flight

    Copyright © 2022 Momtchil Momtchev momtchil@momtchev.com

    Licensed under the LGPL License, Version 3.0 (the "License") You may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.gnu.org/licenses/lgpl-3.0.en.html

    All methods use:

    Pressure in hPa

    Temperature in °C

    Height in meters

    Relative humidity in % from 0 to 100

    Specific humidity in g/kg

    Mixing ratio in g/kg

    Type: string

    G

    Earth's average gravity acceleration (m/s2)

    Type: number

    Cp

    The thermal capacity of air (J/kg)

    Type: number

    L

    The enthalpy of vaporization of water (J/kg)

    Type: number

    gamma

    The adiabatic lapse rate of dry air (°C/m)

    Type: number

    P0

    The average sea level pressure (hPa)

    Type: number

    T0

    The temperature of the ICAO standard atmosphere (°C)

    Type: number

    Rd

    The specific gas constant of dry air J/(kg*K)

    Type: number

    Rv

    The specific gas constant of water vapor J/(kg*K)

    Type: number

    Md

    Molar mass of dry air kg/mol

    Type: number

    Mv

    Molar mass of water vapor kg/mol

    Type: number

    R

    Universal gas constant J/(kg*mol)

    Type: number

    K

    Absolute zero in °C

    Type: number

    altitudeFromStandardPressure

    Altitude from pressure using the barometric formula and ICAO's definition of standard atmosphere.

    This is a very rough approximation that is an ICAO standard. It is used when calculating QNH. It does not take into account the pressure and temperature of the day.

    Parameters

    • pressure number Pressure
    • pressure0 number? Optional sea-level pressure of the day (optional, default P0)

    Returns number

    pressureFromStandardAltitude

    Pressure from altitude using the barometric formula and ICAO's definition of standard atmosphere.

    This is a very rough approximation that is an ICAO standard. It is used when calculating QNH. It does not take into account the pressure and temperature of the day.

    Parameters

    • height number Height
    • pressure0 number? Optional sea-level pressure of the day (optional, default P0)

    Returns number

    altitudeFromPressure

    Altitude from pressure using the hypsometric formula.

    This is a better equation that takes into account the pressure and the temperature of the day. It is not a standard and different weather institutions use slightly different parameters. It is used when calculating the QFF.

    Parameters

    • pressure number Pressure
    • pressure0 number? Optional sea-level pressure of the day (optional, default P0)
    • temp number? Optional average temperature from the ground to the given level (optional, default T0)

    Returns number

    pressureFromAltitude

    Pressure from altitude using the hypsometric formula.

    This is a better equation that takes into account the pressure and the temperature of the day. It is not a standard and different weather institutions use slightly different parameters. It is used when calculating the QFF.

    Parameters

    • height number Height
    • pressure0 number? Optional sea-level pressure of the day (optional, default P0)
    • temp number? Optional average temperature from the ground to the given level (optional, default T0)

    Returns number

    waterVaporSaturationPressure

    (Saturation) Water vapor pressure.

    Clausius–Clapeyron equation - the most fundamental equation in weather science.

    This is the Magnus-Tetens approximation.

    Parameters

    • temp number Temperature (optional, default T0)

    Returns number

    relativeHumidity

    Relative humidity from specific humidity.

    This is from the Magnus-Tetens approximation.

    Parameters

    • specificHumidity number Specific humidity
    • pressure number? Optional pressure (optional, default P0)
    • temp number? Optional temperature (optional, default T0)

    Returns number

    dewPoint

    Dew point from relative humidity.

    Approximation of the Magnus equation with the Sonntag 1990 coefficients.

    Parameters

    • relativeHumidity number Relative humidity
    • temp number? Optional temperature (optional, default T0)

    Returns number

    relativeHumidityFromDewPoint

    Relative humidity from dew point.

    Approximation of the Magnus equation with the Sonntag 1990 coefficients.

    Parameters

    • dewPoint number Relative humidity
    • temp number? Optional temperature (optional, default T0)

    Returns number

    mixingRatio

    Mixing ratio from specific humidity.

    Analytic equation from the definition.

    Parameters

    • specificHumidity number Specific humidity

    Returns number

    specificHumidityFromMixingRatio

    Specific humidity from mixing ratio.

    Analytic equation from the definition.

    Parameters

    • mixingRatio number Mixing ratio

    Returns number

    specificHumidity

    Specific humidity from relative humidity.

    Approximation of the Magnus equation with the Sonntag 1990 coefficients.

    Parameters

    • relativeHumidity number Relative humidity
    • pressure number? Optional pressure (optional, default P0)
    • temp number? Optional temperature (optional, default T0)

    Returns number

    airDensity

    Air density.

    Analytic equation from Avogadro's Law.

    Parameters

    • relativeHumidity number Relative humidity
    • pressure number? Optional pressure (optional, default P0)
    • temp number? Optional temperature (optional, default T0)

    Returns number

    LCL

    Lifted Condensation Level.

    This is the altitude at which a mechanically lifted air parcel from the ground will condensate.

    It corresponds to the cloud base level when the clouds are formed by mechanical lifting.

    This approximation is known as the Espy equation with the Stull coefficient.

    Parameters

    • temp number Temperature at 2m
    • dewPoint number Dew point at 2m

    Returns number

    gammaMoist

    Moist adiabatic lapse rate from pressure and temperature.

    Copied from Roland Stull, Practical Meteorology (copylefted, available online).

    Rather complex approximation based on the Magnus-Tetens equation and the barometric equation.

    Parameters

    • temp number Temperature
    • pressure number? Optional pressure (optional, default P0)

    Returns number

    adiabaticExpansion

    Adiabatic expansion rate from pressure change rate.

    This equation allows to calculate the expansion ratio of an air parcel from the the previous pressure and the new pressure.

    An adiabatic expansion is an isentropic process that is governed by the Ideal gas law in general and the constant entropy relationship in particular: (P / P0) = (V / V0) ^ gamma Where P=pressure, V=volume, gamma=heat capacity ratio (1.4 for air, a diatomic gas)

    Analytic equation.

    Parameters

    • volume0 number Old volume
    • pressure number New pressure
    • pressure0 number Old pressure (optional, default P0)

    Returns number

    adiabaticCooling

    Adiabatic cooling rate from pressure change rate.

    This equation allows to calculate the cooling ratio of an air parcel from the the previous pressure and the new pressure.

    It is by combining this equation with the barometric equation that the adiabatic lapse rate of dry air can be obtained.

    An adiabatic expansion is an isentropic process that is governed by the Ideal gas law in general and the constant entropy relationship in particular: (P / P0) = (V / V0) ^ gamma Where P=pressure, V=volume, gamma=heat capacity ratio (1.4 for air, a diatomic gas)

    Keep in mind that if you intend to use this method to calculate a rate relative to height in meters, you will need very precise altitude calculations for good results. As the dry adiabatic rate is a constant that does not depend on the temperature or the pressure, most of the time you will be better off simply using the gamma constant.

    https://en.wikipedia.org/wiki/Ideal_gas_law contains a very good introduction to this subject.

    Analytic equation.

    Parameters

    • temp0 number Old temperature
    • pressure number New pressure
    • pressure0 number Old pressure (optional, default P0)

    Examples

    // Compute the adiabatic cooling per meter
    // when rising from 0m AMSL to 100m AMSL starting at 15°C
    
    const gamma = (15 - velitherm.adiabaticCooling(15,
                          velitherm.pressureFromStandardAltitude(100),
                          velitherm.pressureFromStandardAltitude(0))
                   ) / 100;
    
    // It should be very close to the provided constant
    assert(Math.abs(gamma - velitherm.gamma) < 1e-5)

    Returns number

    Install

    npm i velitherm

    DownloadsWeekly Downloads

    8

    Version

    1.2.0

    License

    LGPL-3.0-or-later

    Unpacked Size

    149 kB

    Total Files

    22

    Last publish

    Collaborators

    • mmomtchev