Skip to content

Commit

Permalink
refactor: make units lowercase in function names
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenengelsen committed May 15, 2023
1 parent 871c038 commit 272f0d7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(

self._neqsim_fluid_stream = NeqsimFluid.create_thermo_system(
composition=self._map_fluid_composition_to_neqsim(fluid_composition=self.fluid_model.composition),
temperature_Kelvin=temperature_kelvin,
temperature_kelvin=temperature_kelvin,
pressure_bara=pressure_bara,
eos_model=_map_eos_model_to_neqsim[self.fluid_model.eos_model],
)
Expand All @@ -81,7 +81,7 @@ def __init__(
else:
_neqsim_fluid_at_standard_conditions = NeqsimFluid.create_thermo_system(
composition=self._map_fluid_composition_to_neqsim(fluid_composition=self.fluid_model.composition),
temperature_Kelvin=UnitConstants.STANDARD_TEMPERATURE_KELVIN,
temperature_kelvin=UnitConstants.STANDARD_TEMPERATURE_KELVIN,
pressure_bara=UnitConstants.STANDARD_PRESSURE_BARA,
eos_model=_map_eos_model_to_neqsim[self.fluid_model.eos_model],
)
Expand Down Expand Up @@ -179,7 +179,8 @@ def set_new_pressure_and_enthalpy_change(
new_fluid_stream = self.copy()
new_fluid_stream._neqsim_fluid_stream = new_fluid_stream._neqsim_fluid_stream.set_new_pressure_and_enthalpy(
new_pressure=new_pressure,
new_enthalpy_J_per_kg=new_fluid_stream._neqsim_fluid_stream.enthalpy_J_per_kg + enthalpy_change_J_per_kg,
new_enthalpy_J_per_kg=new_fluid_stream._neqsim_fluid_stream.enthalpy_joule_per_kg
+ enthalpy_change_J_per_kg,
remove_liquid=remove_liquid,
)
return new_fluid_stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_set_new_pressure_and_enthalpy_or_temperature(fluid_streams: List[List[F
pressure_increase_factor = 3.0

inlet_enthalpies_all_fluids = [
np.asarray([s._neqsim_fluid_stream.enthalpy_J_per_kg for s in stream]) for stream in fluid_streams
np.asarray([s._neqsim_fluid_stream.enthalpy_joule_per_kg for s in stream]) for stream in fluid_streams
]

new_enthalpies_all_fluids = [
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_set_new_pressure_and_enthalpy_or_temperature(fluid_streams: List[List[F
)
]
new_enthalpies_all_fluids_after_setting_new_temperature = [
np.asarray([s._neqsim_fluid_stream.enthalpy_J_per_kg for s in streams])
np.asarray([s._neqsim_fluid_stream.enthalpy_joule_per_kg for s in streams])
for streams in streams_with_new_pressure_and_temperature
]
np.testing.assert_allclose(
Expand Down
18 changes: 9 additions & 9 deletions src/ecalc/libraries/neqsim/neqsim_ecalc_wrapper/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
def create_thermo_system(
cls,
composition: Dict[str, float],
temperature_Kelvin: float = STANDARD_TEMPERATURE_KELVIN,
temperature_kelvin: float = STANDARD_TEMPERATURE_KELVIN,
pressure_bara: float = STANDARD_PRESSURE_BARA,
eos_model: NeqsimEoSModelType = NeqsimEoSModelType.SRK,
mixing_rule: int = NEQSIM_MIXING_RULE,
Expand All @@ -61,7 +61,7 @@ def create_thermo_system(
Not necessary here because compressor.run-method does flash on inlet and outlet.
:param composition: A dict with the composition of the thermodynamic_system components name: molar fraction.
:param temperature_Kelvin: The initial system temperature in Kelvin
:param temperature_kelvin: The initial system temperature in Kelvin
:param pressure_bara: The initial system pressure in absolute bar
:param eos_model: The name of the underlaying EOS model
:param mixing_rule: The Neqsim mixing rule.
Expand All @@ -80,7 +80,7 @@ def create_thermo_system(
components=components,
molar_fraction=molar_fractions,
eos_model=eos_model,
temperature_Kelvin=temperature_Kelvin,
temperature_kelvin=temperature_kelvin,
pressure_bara=pressure_bara,
mixing_rule=mixing_rule,
)
Expand All @@ -93,7 +93,7 @@ def _init_thermo_system(
components: List[str],
molar_fraction: List[float],
eos_model,
temperature_Kelvin,
temperature_kelvin,
pressure_bara,
mixing_rule,
) -> ThermodynamicSystem:
Expand All @@ -108,7 +108,7 @@ def _init_thermo_system(
"""
use_gerg = "gerg" in eos_model.name.lower()

thermodynamic_system = eos_model.value(float(temperature_Kelvin), float(pressure_bara))
thermodynamic_system = eos_model.value(float(temperature_kelvin), float(pressure_bara))

[
thermodynamic_system.addComponent(component, float(value))
Expand Down Expand Up @@ -150,7 +150,7 @@ def z(self) -> float:
return self._thermodynamic_system.getZ()

@property
def enthalpy_J_per_kg(self) -> float:
def enthalpy_joule_per_kg(self) -> float:
if self._use_gerg:
return self._gerg_properties.enthalpy_joule_per_kg
else:
Expand Down Expand Up @@ -194,7 +194,7 @@ def _ph_flash(thermodynamic_system: ThermodynamicSystem, use_gerg: bool, enthalp
"""
thermodynamic_operations = ThermodynamicOperations(thermodynamic_system)
if use_gerg:
enthalpy_joule = _get_enthalpy_joule_for_GERG2008_Joule_per_kg(
enthalpy_joule = _get_enthalpy_joule_for_GERG2008_joule_per_kg(
enthalpy=enthalpy, thermodynamic_system=thermodynamic_system
)
thermodynamic_operations.PHflashGERG2008(float(enthalpy_joule))
Expand Down Expand Up @@ -248,7 +248,7 @@ def mix_streams(
composition_dict,
NeqsimFluid.create_thermo_system(
composition=composition_dict,
temperature_Kelvin=temperature,
temperature_kelvin=temperature,
pressure_bara=pressure,
eos_model=eos_model,
),
Expand Down Expand Up @@ -346,5 +346,5 @@ def get_GERG2008_properties(thermodynamic_system: ThermodynamicSystem):
)


def _get_enthalpy_joule_for_GERG2008_Joule_per_kg(enthalpy: float, thermodynamic_system: ThermodynamicSystem) -> float:
def _get_enthalpy_joule_for_GERG2008_joule_per_kg(enthalpy: float, thermodynamic_system: ThermodynamicSystem) -> float:
return enthalpy * thermodynamic_system.getTotalNumberOfMoles() * thermodynamic_system.getMolarMass()
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def test_gerg_model_against_unisim(medium_fluid_with_gerg: NeqsimFluid) -> None:
assert math.isclose(very_high_pressure.z, 1.65, rel_tol=0.01)

assert math.isclose(
low_pressure.enthalpy_J_per_kg - medium_pressure.enthalpy_J_per_kg, 17634 - -93366, rel_tol=0.01
low_pressure.enthalpy_joule_per_kg - medium_pressure.enthalpy_joule_per_kg, 17634 - -93366, rel_tol=0.01
)
assert math.isclose(
medium_pressure.enthalpy_J_per_kg - high_pressure.enthalpy_J_per_kg, -93366 - -219900, rel_tol=0.02
medium_pressure.enthalpy_joule_per_kg - high_pressure.enthalpy_joule_per_kg, -93366 - -219900, rel_tol=0.02
)

assert math.isclose(
high_pressure.enthalpy_J_per_kg - very_high_pressure.enthalpy_J_per_kg, -219900 - -194900, rel_tol=0.02
high_pressure.enthalpy_joule_per_kg - very_high_pressure.enthalpy_joule_per_kg, -219900 - -194900, rel_tol=0.02
)
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ def inlet_fluid() -> NeqsimFluid:
See outlet fluid below.
"""
return NeqsimFluid.create_thermo_system(
composition=INLET_FLUID_COMPOSITION, temperature_Kelvin=36.0 + 273.15, pressure_bara=1700 / 100
composition=INLET_FLUID_COMPOSITION, temperature_kelvin=36.0 + 273.15, pressure_bara=1700 / 100
)


@pytest.fixture
def outlet_fluid() -> NeqsimFluid:
"""Inlet liquid to test liquids takeoff compared to UniSim. see inlet conditions above."""
return NeqsimFluid.create_thermo_system(
composition=OUTLET_FLUID_COMPOSITION, temperature_Kelvin=38 + 273.15, pressure_bara=4327.67395 / 100
composition=OUTLET_FLUID_COMPOSITION, temperature_kelvin=38 + 273.15, pressure_bara=4327.67395 / 100
)


Expand Down Expand Up @@ -129,4 +129,6 @@ def test_liquid_takeoff(inlet_fluid, outlet_fluid) -> None:
assert math.isclose(outlet_fluid.density, fluid_after_liquid_takeoff.density, rel_tol=0.01)
assert math.isclose(outlet_fluid.pressure_bara, fluid_after_liquid_takeoff.pressure_bara, rel_tol=0.01)
assert math.isclose(outlet_fluid.molar_mass, fluid_after_liquid_takeoff.molar_mass, rel_tol=0.01)
assert math.isclose(outlet_fluid.enthalpy_J_per_kg, fluid_after_liquid_takeoff.enthalpy_J_per_kg, rel_tol=0.5)
assert math.isclose(
outlet_fluid.enthalpy_joule_per_kg, fluid_after_liquid_takeoff.enthalpy_joule_per_kg, rel_tol=0.5
)
35 changes: 21 additions & 14 deletions src/ecalc/libraries/neqsim/tests/unit_tests/test_neqsim_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@

def test_gerg_properties(medium_fluid: NeqsimFluid, medium_fluid_with_gerg: NeqsimFluid) -> None:
medium_fluid_np_ne = medium_fluid.set_new_pressure_and_enthalpy(
new_pressure=20.0, new_enthalpy_J_per_kg=medium_fluid.enthalpy_J_per_kg + 10000
new_pressure=20.0, new_enthalpy_J_per_kg=medium_fluid.enthalpy_joule_per_kg + 10000
)
medium_fluid_with_gerg_np_ne = medium_fluid_with_gerg.set_new_pressure_and_enthalpy(
new_pressure=20.0, new_enthalpy_J_per_kg=medium_fluid_with_gerg.enthalpy_J_per_kg + 10000
new_pressure=20.0, new_enthalpy_J_per_kg=medium_fluid_with_gerg.enthalpy_joule_per_kg + 10000
)
assert medium_fluid_with_gerg_np_ne.enthalpy_J_per_kg - medium_fluid_with_gerg.enthalpy_J_per_kg == pytest.approx(
10000
assert (
medium_fluid_with_gerg_np_ne.enthalpy_joule_per_kg - medium_fluid_with_gerg.enthalpy_joule_per_kg
== pytest.approx(10000)
)
assert medium_fluid_np_ne.enthalpy_J_per_kg - medium_fluid.enthalpy_J_per_kg == pytest.approx(10000)
assert medium_fluid_np_ne.enthalpy_joule_per_kg - medium_fluid.enthalpy_joule_per_kg == pytest.approx(10000)

# Pinning properties to ensure stability:
# Before flash
assert np.isclose(medium_fluid_with_gerg.density, 0.8249053143219223)
assert np.isclose(medium_fluid_with_gerg.z, 0.9971825132713872)
assert np.isclose(medium_fluid_with_gerg.enthalpy_J_per_kg, -21220.02998198086)
assert np.isclose(medium_fluid_with_gerg.enthalpy_joule_per_kg, -21220.02998198086)
assert np.isclose(medium_fluid_with_gerg._gerg_properties.kappa, 1.2719274851916846)

# After flash
assert np.isclose(medium_fluid_with_gerg_np_ne.density, 16.182809350995125)
assert np.isclose(medium_fluid_with_gerg_np_ne.z, 0.9532768832922157)
assert np.isclose(medium_fluid_with_gerg_np_ne.enthalpy_J_per_kg, -11220.029982279037)
assert np.isclose(medium_fluid_with_gerg_np_ne.enthalpy_joule_per_kg, -11220.029982279037)
assert np.isclose(medium_fluid_with_gerg_np_ne._gerg_properties.kappa, 1.2451895327851366)


Expand Down Expand Up @@ -54,7 +55,7 @@ def test_fluid_z(heavy_fluid: NeqsimFluid) -> None:


def test_fluid_enthalpy_J_per_kg(heavy_fluid: NeqsimFluid) -> None:
enthalpy_J_per_kg = heavy_fluid.enthalpy_J_per_kg
enthalpy_J_per_kg = heavy_fluid.enthalpy_joule_per_kg
assert isinstance(enthalpy_J_per_kg, float)
assert np.isclose(enthalpy_J_per_kg, 27365.875930712697) # Ensure stability in estimate

Expand Down Expand Up @@ -91,22 +92,24 @@ def test_fluid_set_new_pressure_and_enthalpy(heavy_fluid: NeqsimFluid) -> None:
fluid = heavy_fluid

increase_enthalpy = fluid.set_new_pressure_and_enthalpy(
new_pressure=fluid.pressure_bara, new_enthalpy_J_per_kg=fluid.enthalpy_J_per_kg * 2
new_pressure=fluid.pressure_bara, new_enthalpy_J_per_kg=fluid.enthalpy_joule_per_kg * 2
)

decrease_enthalpy = fluid.set_new_pressure_and_enthalpy(
new_pressure=fluid.pressure_bara, new_enthalpy_J_per_kg=fluid.enthalpy_J_per_kg / 2
new_pressure=fluid.pressure_bara, new_enthalpy_J_per_kg=fluid.enthalpy_joule_per_kg / 2
)

increase_pressure = fluid.set_new_pressure_and_enthalpy(
new_pressure=fluid.pressure_bara * 2, new_enthalpy_J_per_kg=fluid.enthalpy_J_per_kg
new_pressure=fluid.pressure_bara * 2, new_enthalpy_J_per_kg=fluid.enthalpy_joule_per_kg
)

decrease_pressure = fluid.set_new_pressure_and_enthalpy(
new_pressure=fluid.pressure_bara / 2, new_enthalpy_J_per_kg=fluid.enthalpy_J_per_kg
new_pressure=fluid.pressure_bara / 2, new_enthalpy_J_per_kg=fluid.enthalpy_joule_per_kg
)

assert increase_enthalpy.enthalpy_J_per_kg > fluid.enthalpy_J_per_kg > decrease_enthalpy.enthalpy_J_per_kg
assert (
increase_enthalpy.enthalpy_joule_per_kg > fluid.enthalpy_joule_per_kg > decrease_enthalpy.enthalpy_joule_per_kg
)

assert increase_pressure.pressure_bara > fluid.pressure_bara > decrease_pressure.pressure_bara

Expand Down Expand Up @@ -144,7 +147,11 @@ def test_fluid_set_new_pressure_and_temperature(heavy_fluid: NeqsimFluid) -> Non
)

assert increase_temperature.temperature_kelvin > fluid.temperature_kelvin > decrease_temperature.temperature_kelvin
assert increase_temperature.enthalpy_J_per_kg > fluid.enthalpy_J_per_kg > decrease_temperature.enthalpy_J_per_kg
assert (
increase_temperature.enthalpy_joule_per_kg
> fluid.enthalpy_joule_per_kg
> decrease_temperature.enthalpy_joule_per_kg
)

assert increase_pressure.pressure_bara > fluid.pressure_bara > decrease_pressure.pressure_bara

Expand Down

0 comments on commit 272f0d7

Please sign in to comment.