pvtlib.aga8

MIT License

Copyright (c) 2025 Christian Hågenvik

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The code is based upon the python library pyaga8, which is again based upon the open source rust package aga8 (https://crates.io/crates/aga8)

Functions

to_aga8_composition(composition)

Convert a composition dictionary to an AGA8 Composition object.

Classes

AGA8

A class to perform gas property calculations using the AGA8 equations of state, DETAIL [1] and GERG-2008 [2].

class pvtlib.aga8.AGA8[source]

Bases: object

A class to perform gas property calculations using the AGA8 equations of state, DETAIL [1] and GERG-2008 [2].

Parameters:

equation (str, optional) – The equation of state to use. Must be either ‘GERG-2008’ or ‘DETAIL’. Default is ‘GERG-2008’.

Variables:
  • equation (str) – The equation of state being used.

  • adapter (object) – The adapter object corresponding to the selected equation of state.

Methods:
  • calculate_from_PT(composition, pressure, temperature, pressure_unit=’bara’, temperature_unit=’C’, molar_mass=None) – Calculate gas properties using pressure, temperature, and composition as input.

  • calculate_from_rhoT(composition, mass_density, temperature, temperature_unit=’C’, molar_mass=None) – Calculate gas properties using mass density, temperature, and composition as input.

  • .. warning:: – AGA8 is only valid for single-phase gas conditions. It does not check for phase state and will produce erroneous results if applied in the two-phase or liquid region. The user is responsible for ensuring that the operating conditions are within the single-phase gas region before using these calculations.

References

__init__(equation='GERG-2008')[source]
calculate_from_PT(composition, pressure, temperature, pressure_unit='bara', temperature_unit='C', molar_mass=None)[source]

Calculate gas properties using AGA8 with pressure, temperature and composition as input.

Parameters:
  • composition (dict) –

    Composition containing component name as key and mole percent or mole fraction as value.

    C1 : methane N2 : nitrogen CO2 : carbon_dioxide C2 : ethane C3 : propane iC4 : isobutane nC4 : n_butane iC5 : isopentane nC5 : n_pentane nC6 : hexane nC7 : heptane nC8 : octane nC9 : nonane nC10 : decane H2 : hydrogen O2 : oxygen CO : carbon_monoxide H2O : water H2S : hydrogen_sulfide He : helium Ar : argon

  • pressure (float) – P - Pressure

  • temperature (float) – T - Temperature

  • pressure_unit (str) – Unit of pressure. The default unit is bara.

  • temperature_unit (str) – Unit of temperature. The default unit is Celsius (C).

  • molar_mass (float, optional) – Molar mass can be given as an optional input [kg/kmol]. If this is given, this molar mass will be used to calculate the mass density instead of the AGA8 calculated molar mass. The default is None. In that case the AGA8 calculated molar mass will be used.

Notes

Only valid for single-phase gas conditions. Results will be erroneous if the operating point falls within the two-phase or liquid region. No phase check is performed.

Returns:

results (TYPE) – Dictionary with properties from AGA8.

’ P - Pressure [kPa] ‘ T - Temperature [k] ‘ Z - Compressibility factor [-] ‘ dPdD - First derivative of pressure with respect to density at constant temperature [kPa/(mol/l)] ‘d2PdD2 - Second derivative of pressure with respect to density at constant temperature [kPa/(mol/l)^2] ‘d2PdTD - Second derivative of pressure with respect to temperature and density [kPa/(mol/l)/K] ‘ dPdT - First derivative of pressure with respect to temperature at constant density (kPa/K) ‘ U - Internal energy [J/mol] ‘ H - Enthalpy [J/mol] ‘ S - Entropy [J/(mol-K)] ‘ Cv - Isochoric heat capacity [J/(mol-K)] ‘ Cp - Isobaric heat capacity [J/(mol-K)] ‘ W - Speed of sound [m/s] ‘ G - Gibbs energy [J/mol] ‘ JT - Joule-Thomson coefficient [K/kPa] ‘ Kappa - Isentropic Exponent [-] ‘ A - Helmholtz energy [J/mol] ‘ D - Molar density [mol/l] ‘ mm - Molar mass [g/mol] ‘ rho - Mass density [kg/m3]

’ gas_composition - Dictionary containing the composition used in the calculations

Parameters:
  • composition (dict)

  • pressure (float)

  • temperature (float)

calculate_from_rhoT(composition, mass_density, temperature, temperature_unit='C', molar_mass=None)[source]

Calculate gas properties using AGA8 with mass density, temperature and composition as input.

Parameters:
  • gas_composition (dict) – Dictionary with component name as key and mole percent or mole fraction as value.

  • mass_density (float) – Mass density [kg/m3]

  • temperature (float) – Temperature. Unit of measure is defined by temperature_unit.

  • temperature_unit (TYPE, optional) – Unit of measure for temperature. The default is ‘C’.

  • molar_mass (float, optional) – Molar mass can be given as an optional input [kg/kmol]. If this is given, this molar mass will be used to calculate the mass density instead of the AGA8 calculated molar mass. The default is None. In that case the AGA8 calculated molar mass will be used.

  • composition (dict)

Notes

Only valid for single-phase gas conditions. Results will be erroneous if the operating point falls within the two-phase or liquid region. No phase check is performed.

Returns:

results (dict) – Dictionary with properties from AGA8 (same as for the calculate_from_PT method)

Parameters:
  • composition (dict)

  • mass_density (float)

  • temperature (float)

calculate_from_PH(composition, pressure, enthalpy, pressure_unit='bara', molar_mass=None)[source]

Calculate gas properties using AGA8 with pressure, enthalpy and composition as input.

Parameters:
  • composition (dict) – The composition of the gas mixture as a dictionary where keys are component names and values are their mole fractions.

  • pressure (float) – Pressure. Unit is defined by pressure_unit.

  • enthalpy (float) – Enthalpy, H [J/mol]

  • pressure_unit (str, optional) – The unit of the pressure, by default ‘bara’.

  • molar_mass (float, optional) – The molar mass of the gas mixture, by default None. If None, the AGA8 molar mass is used.

Notes

Only valid for single-phase gas conditions. Results will be erroneous if the operating point falls within the two-phase or liquid region. No phase check is performed.

Returns:

results (dict) – Dictionary with properties from AGA8 (same as for the calculate_from_PT method)

Parameters:
  • composition (dict)

  • pressure (float)

  • enthalpy (float)

calculate_from_PS(composition, pressure, entropy, pressure_unit='bara', molar_mass=None)[source]

Calculate gas properties using AGA8 with pressure, entropy and composition as input.

Parameters:
  • composition (dict) – The composition of the gas mixture as a dictionary where keys are component names and values are their mole fractions.

  • pressure (float) – Pressure. Unit is defined by pressure_unit.

  • entropy (float) – Entropy, S [J/mol-K]

  • pressure_unit (str, optional) – The unit of the pressure, by default ‘bara’.

  • molar_mass (float, optional) – The molar mass of the gas mixture, by default None. If None, the AGA8 molar mass is used.

Notes

Only valid for single-phase gas conditions. Results will be erroneous if the operating point falls within the two-phase or liquid region. No phase check is performed.

Returns:

results (dict) – Dictionary with properties from AGA8 (same as for the calculate_from_PT method)

Parameters:
  • composition (dict)

  • pressure (float)

  • entropy (float)

mix(compositions, mix_weights, check_input=False)[source]

Mix fluids consisting of components from the AGA8 component list, based on their masses. Uses molecular weights from the initialized AGA8 equation of state. The function can take any number of compositions and corresponding masses, and will return the resulting composition and total mass of the mixture.

Parameters:
  • compositions (list) – A list of composition dictionaries, where each dictionary contains component names as keys and mole percent or mole fraction as values. Components should be from the AGA8 component list: C1, N2, CO2, C2, C3, iC4, nC4, iC5, nC5, nC6, nC7, nC8, nC9, nC10, H2, O2, CO, H2O, H2S, He, Ar.

  • mix_weights (list) – A list of masses [kg] corresponding to each composition. Must be the same length as compositions. Can include negative values for subtraction operations.

  • check_input (bool, optional) – If True, raises exceptions for invalid inputs. If False, returns NaN values for invalid inputs. Default is False.

Returns:

results (dict) – Dictionary containing: - ‘composition’: Dictionary with component names as keys and mole percent (0-100) as values. - ‘total_mass’: Total mass of the mixture [kg].

Raises:

ValueError – If check_input is True and any of the following occur: - Length of compositions and mix_weights lists don’t match - Any component moles become negative after mixing (non-physical) - Total mass becomes negative after mixing - Invalid component names in compositions

Examples

>>> aga8 = AGA8('GERG-2008')
>>> comp1 = {'C1': 90, 'C2': 10}
>>> comp2 = {'C1': 80, 'C3': 20}
>>> result = aga8.mix([comp1, comp2], [100, 50])
>>> result['composition']
{'C1': 86.67, 'C2': 6.67, 'C3': 6.67}
>>> result['total_mass']
150.0

References

pvtlib.aga8.to_aga8_composition(composition)[source]

Convert a composition dictionary to an AGA8 Composition object.

Parameters:

composition (dict) – A dictionary containing the component names as keys and the mole fractions or mole percentages as values.

Returns:

  • AGA8_COMPOSITION (pyaga8.Composition) – An AGA8 Composition object.

  • aga8_composition_dict (dict) – A dictionary containing the AGA8 component names as keys and the mole fractions as values.