Skip to content

Commit

Permalink
refactor: remove duplicate function for converting to standard rate
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenengelsen committed May 16, 2023
1 parent 7ccf2c1 commit 93de4f4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,47 @@ def standard_to_mass_rate(self, standard_rates: Union[np.ndarray, float]) -> Uni
mass_rate_kg_per_hour = standard_rates * self.standard_conditions_density / UnitConstants.HOURS_PER_DAY
return mass_rate_kg_per_hour

def mass_rate_to_standard_rate(self, mass_rate_kg_per_hour: np.ndarray) -> np.ndarray:
"""kg/h to Sm3/day."""
fluid_density_standard_conditions = self.standard_conditions_density
def mass_rate_to_standard_rate(self, mass_rate_kg_per_hour: Union[np.ndarray, float]) -> Union[np.ndarray, float]:
"""Convert mass rate from kg/h to Sm3/day.
standard_rates_m3_per_day = mass_rate_kg_per_hour / (
fluid_density_standard_conditions / UnitConstants.HOURS_PER_DAY
)
return standard_rates_m3_per_day
Args:
mass_rate_kg_per_hour: One or more mass rates to convert [kg/h]
def mass_rate_to_standard(self, mass_rates: Union[np.ndarray, float]) -> Union[np.ndarray, float]:
"""kg/h to Sm3/day."""
Returns:
Mass rates in Sm3/day
"""
fluid_density_standard_conditions = self.standard_conditions_density
return mass_rates * UnitConstants.HOURS_PER_DAY / fluid_density_standard_conditions
return mass_rate_kg_per_hour * UnitConstants.HOURS_PER_DAY / fluid_density_standard_conditions

def get_fluid_stream(self, pressure_bara: float, temperature_Kelvin: float) -> FluidStream:
def get_fluid_stream(self, pressure_bara: float, temperature_kelvin: float) -> FluidStream:
"""Return a fluid stream for given pressure and temperature
Args:
pressure_bara: Pressure setpoint for fluid stream [bara]
temperature_kelvin: Temperature setpoint for fluid stream [kelvin]
Returns:
Fluid stream at set temperature and pressure
"""
return FluidStream(
fluid_model=self.fluid_model, pressure_bara=pressure_bara, temperature_kelvin=temperature_Kelvin
fluid_model=self.fluid_model, pressure_bara=pressure_bara, temperature_kelvin=temperature_kelvin
)

def get_fluid_streams(self, pressure_bara: np.ndarray, temperature_kelvin: np.ndarray) -> List[FluidStream]:
""":param pressure_bara:
:param temperature_kelvin:
:return:
"""Get multiple fluid streams from multiple temperatures and pressures
Args:
pressure_bara: array of pressures [bara]
temperature_kelvin: array of temperatures [kelvin]
Returns:
List of fluid streams at set temperatures and pressures
"""
streams = [
FluidStream(
fluid_model=self.fluid_model, pressure_bara=pressure_value, temperature_kelvin=temperature_value
)
self.get_fluid_stream(pressure_bara=pressure_value, temperature_kelvin=temperature_value)
for pressure_value, temperature_value in zip(pressure_bara, temperature_kelvin)
]

Expand All @@ -174,13 +187,13 @@ def set_new_pressure_and_temperature(
return new_fluid_stream

def set_new_pressure_and_enthalpy_change(
self, new_pressure: float, enthalpy_change_J_per_kg: float, remove_liquid: bool = True
self, new_pressure: float, enthalpy_change_joule_per_kg: float, remove_liquid: bool = True
) -> FluidStream:
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_joule_per_kg=new_fluid_stream._neqsim_fluid_stream.enthalpy_joule_per_kg
+ enthalpy_change_J_per_kg,
new_enthalpy_J_per_kg=new_fluid_stream._neqsim_fluid_stream.enthalpy_joule_per_kg
+ enthalpy_change_joule_per_kg,
remove_liquid=remove_liquid,
)
return new_fluid_stream
Expand All @@ -196,16 +209,29 @@ def mix_in_stream(
self_mass_rate: float,
other_mass_rate: float,
pressure_bara: float,
temperature_Kelvin: float,
temperature_kelvin: float,
) -> FluidStream:
"""Mix in a new fluid stream and get combined fluid stream
Args:
other_fluid_stream: Fluid stream to be mixed in
self_mass_rate: Mass rate of the current fluid stream
other_mass_rate: Mass rate of the "mix-in" fluid stream
pressure_bara: Pressure of the fluid streams (Must be equal for both streams)
temperature_kelvin: Temperature of the fluid streams ( Must be equal for both streams)
Returns:
New fluid stream with mixed in fluid
"""
new_fluid_stream = self.copy()
composition_dict, new_fluid_stream._neqsim_fluid_stream = new_fluid_stream._neqsim_fluid_stream.mix_streams(
stream_1=new_fluid_stream._neqsim_fluid_stream,
stream_2=other_fluid_stream._neqsim_fluid_stream,
mass_rate_stream_1=self_mass_rate,
mass_rate_stream_2=other_mass_rate,
pressure=pressure_bara,
temperature=temperature_Kelvin,
temperature=temperature_kelvin,
eos_model=_map_eos_model_to_neqsim[new_fluid_stream.fluid_model.eos_model],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def _calculate_train_result(mass_rate: float) -> CompressorTrainResultSingleTime
# If solution not found along max speed curve, run at max_mass_rate, but using the defined pressure control.
elif self.data_transfer_object.pressure_control is not None:
if self._evaluate_rate_ps_pd(
rate=inlet_stream.mass_rate_to_standard(mass_rates=max_mass_rate),
rate=inlet_stream.mass_rate_to_standard_rate(mass_rate_kg_per_hour=max_mass_rate),
suction_pressure=np.asarray([inlet_stream.pressure_bara]),
discharge_pressure=np.asarray([target_discharge_pressure]),
)[0].is_valid:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ def _calculate_train_result_given_speed_at_stone_wall(
* stream_density
)
_max_valid_std_rate_for_stream_at_given_speed = maximize_x_given_boolean_condition_function(
x_min=self.streams[stream_to_maximize].fluid.mass_rate_to_standard(
mass_rates=x_min_mass_rate_kg_per_hr
x_min=self.streams[stream_to_maximize].fluid.mass_rate_to_standard_rate(
mass_rate_kg_per_hour=x_min_mass_rate_kg_per_hr
),
x_max=self.streams[stream_to_maximize].fluid.mass_rate_to_standard(
mass_rates=x_max_mass_rate_kg_per_hr
x_max=self.streams[stream_to_maximize].fluid.mass_rate_to_standard_rate(
mass_rate_kg_per_hour=x_max_mass_rate_kg_per_hr
),
bool_func=lambda x: _calculate_train_result(std_rate_for_stream=x, speed=speed).is_valid,
)
Expand Down Expand Up @@ -544,15 +544,15 @@ def _calculate_train_result_given_speed_at_stone_wall(
max_mass_rate_kg_per_hr_at_max_speed = max_actual_rate_m3_per_hr_at_max_speed * stream_density_at_max_speed
max_mass_rate_kg_per_hr_at_min_speed = max_actual_rate_m3_per_hr_at_min_speed * stream_density_at_min_speed

min_std_rate_for_stream_m3_per_day_at_max_speed = self.streams[stream_to_maximize].fluid.mass_rate_to_standard(
mass_rates=min_mass_rate_kg_per_hr_at_max_speed
)
max_std_rate_for_stream_m3_per_day_at_max_speed = self.streams[stream_to_maximize].fluid.mass_rate_to_standard(
mass_rates=max_mass_rate_kg_per_hr_at_max_speed
)
max_std_rate_for_stream_m3_per_day_at_min_speed = self.streams[stream_to_maximize].fluid.mass_rate_to_standard(
mass_rates=max_mass_rate_kg_per_hr_at_min_speed
)
min_std_rate_for_stream_m3_per_day_at_max_speed = self.streams[
stream_to_maximize
].fluid.mass_rate_to_standard_rate(mass_rate_kg_per_hour=min_mass_rate_kg_per_hr_at_max_speed)
max_std_rate_for_stream_m3_per_day_at_max_speed = self.streams[
stream_to_maximize
].fluid.mass_rate_to_standard_rate(mass_rate_kg_per_hour=max_mass_rate_kg_per_hr_at_max_speed)
max_std_rate_for_stream_m3_per_day_at_min_speed = self.streams[
stream_to_maximize
].fluid.mass_rate_to_standard_rate(mass_rate_kg_per_hour=max_mass_rate_kg_per_hr_at_min_speed)

result_min_std_rate_for_stream_at_max_speed = _calculate_train_result_at_max_speed_given_std_rate_for_stream(
std_rate_for_stream=min_std_rate_for_stream_m3_per_day_at_max_speed
Expand Down

0 comments on commit 93de4f4

Please sign in to comment.