Skip to content

Commit

Permalink
Update HIP-RA-X functions to include pressure in all calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolm-dsider committed Feb 20, 2024
1 parent cf47148 commit dd34c85
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 101 deletions.
42 changes: 24 additions & 18 deletions src/geophires_x/GeoPHIRESUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ def quantity(value: float, unit: str) -> PlainQuantity:


@lru_cache
def density_water_kg_per_m3(
Twater_degC: float,
pressure: Optional[PlainQuantity] = None) -> float:
def density_water_kg_per_m3(Twater_degC: float, pressure: Optional[PlainQuantity] = None) -> float:
"""
Calculate the density of water as a function of temperature.
Args:
Twater_degC: The temperature of water in degrees C.
pressure: Pressure - should be provided
pressure: Pressure - should be provided as a Pint quantity that knows its units
Returns:
The density of water in kg/m³.
Raises:
Expand Down Expand Up @@ -244,15 +242,13 @@ def RecoverableHeat(Twater_degC: float) -> float:


@lru_cache
def vapor_pressure_water_kPa(
Twater_degC: float,
pressure: Optional[PlainQuantity] = None) -> float:
def vapor_pressure_water_kPa(Twater_degC: float, pressure: Optional[PlainQuantity] = None) -> float:
"""
Calculate the vapor pressure of water as a function of temperature.
Args:
Twater_degC: the temperature of water in degrees C
pressure: Pressure - should be provided
pressure: Pressure - should be provided as a Pint quantity that knows its units
Returns:
The vapor pressure of water as a function of temperature in kPa
Raises:
Expand All @@ -275,22 +271,23 @@ def vapor_pressure_water_kPa(
return (quantity(CP.PropsSI('P', 'T', celsius_to_kelvin(Twater_degC), 'Q', 0, 'Water'), 'Pa')
.to('kPa').magnitude)


except (NotImplementedError, ValueError) as e:
raise ValueError(f'Input temperature {Twater_degC} is out of range or otherwise not implemented') from e


@lru_cache
def entropy_water_kJ_per_kg_per_K(temperature_degC: float) -> float:
def entropy_water_kJ_per_kg_per_K(temperature_degC: float, pressure: Optional[PlainQuantity] = None) -> float:
"""
Calculate the entropy of water as a function of temperature
TODO take pressure as a parameter https://github.com/NREL/GEOPHIRES-X/issues/119
Args:
temperature_degC: the temperature of water in degrees C
pressure: Pressure - should be provided as a Pint quantity that knows its units
Returns:
the entropy of water as a function of temperature in kJ/(kg·K)
Raises:
TypeError: If temperature is not a float or convertible to float.
ValueError: If temperature is not within the range of 0 to 373.946 degrees C.
"""
try:
Expand All @@ -299,19 +296,23 @@ def entropy_water_kJ_per_kg_per_K(temperature_degC: float) -> float:
raise TypeError(f'Input temperature ({temperature_degC}) must be a float')

try:
return CP.PropsSI('S', 'T', celsius_to_kelvin(temperature_degC), 'Q', 0, 'Water') * 1e-3
if pressure is not None:
return CP.PropsSI('S', 'T', celsius_to_kelvin(temperature_degC),
'P', pressure.to('Pa').magnitude, 'Water') * 1e-3
else:
return CP.PropsSI('S', 'T', celsius_to_kelvin(temperature_degC), 'Q', 0, 'Water') * 1e-3
except (NotImplementedError, ValueError) as e:
raise ValueError(f'Input temperature {temperature_degC} is out of range or otherwise not implemented') from e


@lru_cache
def enthalpy_water_kJ_per_kg(temperature_degC: float) -> float:
def enthalpy_water_kJ_per_kg(temperature_degC: float, pressure: Optional[PlainQuantity] = None) -> float:
"""
Calculate the enthalpy of water as a function of temperature
TODO take pressure as a parameter https://github.com/NREL/GEOPHIRES-X/issues/119
Args:
temperature_degC: the temperature of water in degrees C (float)
pressure: Pressure - should be provided as a Pint quantity that knows its units
Returns:
the enthalpy of water as a function of temperature in kJ/kg
Raises:
Expand All @@ -324,7 +325,12 @@ def enthalpy_water_kJ_per_kg(temperature_degC: float) -> float:
raise TypeError(f'Input temperature ({temperature_degC}) must be a float')

try:
return CP.PropsSI('H', 'T', celsius_to_kelvin(temperature_degC), 'Q', 0, 'Water') * 1e-3
if pressure is not None:
return CP.PropsSI('H', 'T', celsius_to_kelvin(temperature_degC),
'P', pressure.to('Pa').magnitude, 'Water') * 1e-3
else:
return CP.PropsSI('H', 'T', celsius_to_kelvin(temperature_degC), 'Q', 0, 'Water') * 1e-3

except (NotImplementedError, ValueError) as e:
raise ValueError(f'Input temperature {temperature_degC} is out of range or otherwise not implemented') from e

Expand Down Expand Up @@ -456,15 +462,15 @@ def json_dumpse(obj) -> str:
return json.dumps(obj, cls=_EnhancedJSONEncoder)


def lithostatic_pressure_MPa(rho_kg_per_m3: float, depth_m: float) -> float:
def static_pressure_MPa(rho_kg_per_m3: float, depth_m: float) -> float:
"""
Calculate lithostatic pressure in a reservoir.
Calculate litho- (or hydro-) static pressure in a reservoir.
Args:
rho_kg_per_m3 (float): Density of the fluid in kg/m^3.
depth_m (float): Depth of the reservoir in meters.
Returns:
float: Lithostatic pressure in megapascals (MPa).
pint quantity: Lithostatic pressure in megapascals (MPa).
"""

g = scipy.constants.g # Acceleration due to gravity (m/s^2)
Expand Down
6 changes: 3 additions & 3 deletions src/geophires_x/Reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .Units import *
import geophires_x.Model as Model

from geophires_x.GeoPHIRESUtils import heat_capacity_water_J_per_kg_per_K, quantity, lithostatic_pressure_MPa
from geophires_x.GeoPHIRESUtils import heat_capacity_water_J_per_kg_per_K, quantity, static_pressure_MPa
from geophires_x.GeoPHIRESUtils import density_water_kg_per_m3

class Reservoir:
Expand Down Expand Up @@ -795,7 +795,7 @@ def Calculate(self, model: Model) -> None:
model.logger.info(f'complete {str(__class__)}: {sys._getframe().f_code.co_name}')

def lithostatic_pressure(self) -> PlainQuantity:
return quantity(lithostatic_pressure_MPa(self.rhorock.quantity().to('kg/m**3').magnitude,
self.depth.quantity().to('m').magnitude), 'MPa')
return quantity(static_pressure_MPa(self.rhorock.quantity().to('kg/m**3').magnitude,
self.depth.quantity().to('m').magnitude), 'MPa')


1 change: 1 addition & 0 deletions src/geophires_x/Units.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class CostPerDistanceUnit(str, Enum):

class PressureUnit(str, Enum):
"""Pressure Units"""
MPASCAL = "mPa"
KPASCAL = "kPa"
PASCAL = "Pa"
BAR = "bar"
Expand Down
2 changes: 1 addition & 1 deletion src/geophires_x/WellBores.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pint.facets.plain import PlainQuantity

from .Parameter import floatParameter, intParameter, boolParameter, OutputParameter, ReadParameter
from geophires_x.GeoPHIRESUtils import vapor_pressure_water_kPa, quantity, lithostatic_pressure_MPa
from geophires_x.GeoPHIRESUtils import vapor_pressure_water_kPa, quantity, static_pressure_MPa
from geophires_x.GeoPHIRESUtils import density_water_kg_per_m3
from geophires_x.GeoPHIRESUtils import viscosity_water_Pa_sec
from .Units import *
Expand Down
Loading

0 comments on commit dd34c85

Please sign in to comment.