Skip to content

Commit f280fc2

Browse files
committed
refactor: rename variables to include units
1 parent 5e3546b commit f280fc2

14 files changed

Lines changed: 66 additions & 62 deletions

File tree

src/libecalc/domain/process/compressor/core/results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ def mass_rate_kg_per_hour(self) -> float:
134134
if self.inlet_stream is None:
135135
return 0.0
136136
else:
137-
return self.inlet_stream.mass_rate
137+
return self.inlet_stream.mass_rate_kg_per_h
138138

139139
@property
140140
def mass_rate_asv_corrected_kg_per_hour(self) -> float:
141141
"""Mass rate in kg/hour, corrected for ASV."""
142142
if self.inlet_stream_including_asv is None:
143143
return 0.0
144144
else:
145-
return self.inlet_stream_including_asv.mass_rate
145+
return self.inlet_stream_including_asv.mass_rate_kg_per_h
146146

147147
@property
148148
def is_valid(self) -> bool:

src/libecalc/domain/process/compressor/core/train/simplified_train.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def evaluate_given_constraints(
163163
temperature_kelvin=self.stages[0].inlet_temperature_kelvin,
164164
standard_rate_m3_per_day=constraints.rate,
165165
)
166-
if inlet_stream.mass_rate > 0:
166+
if inlet_stream.mass_rate_kg_per_h > 0:
167167
compressor_stages_result = []
168168
for stage in self.stages:
169169
compressor_stage_result = self.calculate_compressor_stage_work_given_outlet_pressure(
@@ -206,7 +206,7 @@ def calculate_compressor_stage_work_given_outlet_pressure(
206206
)
207207

208208
# To avoid passing empty arrays down to the enthalpy calculation.
209-
if inlet_stream.mass_rate > 0:
209+
if inlet_stream.mass_rate_kg_per_h > 0:
210210
polytropic_enthalpy_change_joule_per_kg, polytropic_efficiency = calculate_enthalpy_change_head_iteration(
211211
inlet_streams=inlet_stream,
212212
outlet_pressure=outlet_pressure,
@@ -234,7 +234,7 @@ def calculate_compressor_stage_work_given_outlet_pressure(
234234
else:
235235
polytropic_enthalpy_change_to_use_joule_per_kg = polytropic_enthalpy_change_joule_per_kg
236236
asv_corrected_actual_rate_m3_per_hour = inlet_stream.volumetric_rate
237-
mass_rate_to_use_kg_per_hour = inlet_stream.mass_rate
237+
mass_rate_to_use_kg_per_hour = inlet_stream.mass_rate_kg_per_h
238238
rate_has_recirc = False
239239
pressure_is_choked = False
240240
rate_exceeds_maximum = False
@@ -246,7 +246,7 @@ def calculate_compressor_stage_work_given_outlet_pressure(
246246
polytropic_enthalpy_change_joule_per_kg = 0.0
247247
polytropic_efficiency = np.nan
248248
asv_corrected_actual_rate_m3_per_hour = inlet_stream.volumetric_rate
249-
mass_rate_to_use_kg_per_hour = inlet_stream.mass_rate
249+
mass_rate_to_use_kg_per_hour = inlet_stream.mass_rate_kg_per_h
250250
rate_has_recirc = False
251251
pressure_is_choked = False
252252
rate_exceeds_maximum = False
@@ -255,7 +255,7 @@ def calculate_compressor_stage_work_given_outlet_pressure(
255255

256256
outlet_stream = inlet_stream.create_stream_with_new_pressure_and_enthalpy_change(
257257
pressure_bara=outlet_pressure,
258-
enthalpy_change=polytropic_enthalpy_change_to_use_joule_per_kg, # type: ignore[arg-type]
258+
enthalpy_change_joule_per_kg=polytropic_enthalpy_change_to_use_joule_per_kg, # type: ignore[arg-type]
259259
)
260260

261261
power_mw = (
@@ -290,11 +290,11 @@ def calculate_compressor_stage_work_given_outlet_pressure(
290290
outlet_stream=outlet_stream,
291291
inlet_stream_including_asv=FluidStream(
292292
thermo_system=inlet_stream.thermo_system,
293-
mass_rate=mass_rate_to_use_kg_per_hour,
293+
mass_rate_kg_per_h=mass_rate_to_use_kg_per_hour,
294294
),
295295
outlet_stream_including_asv=FluidStream(
296296
thermo_system=outlet_stream.thermo_system,
297-
mass_rate=mass_rate_to_use_kg_per_hour,
297+
mass_rate_kg_per_h=mass_rate_to_use_kg_per_hour,
298298
),
299299
power_megawatt=power_mw, # type: ignore[arg-type]
300300
chart_area_flag=chart_area_flag,
@@ -460,7 +460,7 @@ def calculate_maximum_rate_for_stage(
460460
enthalpy_change_joule_per_kg = polytropic_head / polytropic_efficiency
461461

462462
outlet_stream = inlet_stream.create_stream_with_new_pressure_and_enthalpy_change(
463-
pressure_bara=outlet_pressure, enthalpy_change=enthalpy_change_joule_per_kg
463+
pressure_bara=outlet_pressure, enthalpy_change_joule_per_kg=enthalpy_change_joule_per_kg
464464
)
465465

466466
# Set convergence criterion on actual volume rate

src/libecalc/domain/process/compressor/core/train/stage.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ def evaluate(
165165
)
166166
inlet_stream_compressor_asv_corrected = FluidStream(
167167
thermo_system=inlet_stream_compressor.thermo_system,
168-
mass_rate=mass_rate_asv_corrected_kg_per_hour,
168+
mass_rate_kg_per_h=mass_rate_asv_corrected_kg_per_hour,
169169
)
170170
power_megawatt = calculate_power_in_megawatt(
171171
enthalpy_change_joule_per_kg=enthalpy_change_J_per_kg,
172-
mass_rate_kg_per_hour=inlet_stream_compressor_asv_corrected.mass_rate,
172+
mass_rate_kg_per_hour=inlet_stream_compressor_asv_corrected.mass_rate_kg_per_h,
173173
)
174174

175175
(
@@ -187,7 +187,7 @@ def evaluate(
187187
inlet_stream_including_asv=inlet_stream_compressor_asv_corrected,
188188
outlet_stream_including_asv=FluidStream(
189189
thermo_system=outlet_stream.thermo_system,
190-
mass_rate=inlet_stream_compressor_asv_corrected.mass_rate,
190+
mass_rate_kg_per_h=inlet_stream_compressor_asv_corrected.mass_rate_kg_per_h,
191191
),
192192
polytropic_head_kJ_per_kg=polytropic_head_J_per_kg / 1000,
193193
polytropic_efficiency=polytropic_efficiency,
@@ -246,7 +246,9 @@ def evaluate_given_speed_and_target_discharge_pressure(
246246
)
247247

248248
max_recirculation = max(
249-
maximum_rate * result_no_recirculation.inlet_stream.density - inlet_stream_stage.mass_rate - EPSILON,
249+
maximum_rate * result_no_recirculation.inlet_stream.density
250+
- inlet_stream_stage.mass_rate_kg_per_h
251+
- EPSILON,
250252
0,
251253
)
252254
result_max_recirculation = self.evaluate(

src/libecalc/domain/process/compressor/core/train/utils/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def calculate_outlet_pressure_and_stream(
110110

111111
outlet_stream_compressor_current_iteration = inlet_stream.create_stream_with_new_pressure_and_enthalpy_change(
112112
pressure_bara=float(outlet_pressure_this_stage_bara_based_on_inlet_z_and_kappa),
113-
enthalpy_change=polytropic_head_joule_per_kg / polytropic_efficiency,
113+
enthalpy_change_joule_per_kg=polytropic_head_joule_per_kg / polytropic_efficiency,
114114
)
115115

116116
outlet_pressure_this_stage_bara = outlet_pressure_this_stage_bara_based_on_inlet_z_and_kappa * 0.95
@@ -140,7 +140,7 @@ def calculate_outlet_pressure_and_stream(
140140

141141
outlet_stream_compressor_current_iteration = inlet_stream.create_stream_with_new_pressure_and_enthalpy_change(
142142
pressure_bara=outlet_pressure_this_stage_bara,
143-
enthalpy_change=polytropic_head_joule_per_kg / polytropic_efficiency,
143+
enthalpy_change_joule_per_kg=polytropic_head_joule_per_kg / polytropic_efficiency,
144144
)
145145

146146
diff = abs(outlet_pressure_previous - outlet_pressure_this_stage_bara) / outlet_pressure_this_stage_bara

src/libecalc/domain/process/compressor/core/train/utils/enthalpy_calculations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def calculate_enthalpy_change_head_iteration(
9797
# Update outlet streams
9898
outlet_streams = [
9999
stream.create_stream_with_new_pressure_and_enthalpy_change(
100-
pressure_bara=pressure, enthalpy_change=enthalpy_change
100+
pressure_bara=pressure, enthalpy_change_joule_per_kg=enthalpy_change
101101
)
102102
for stream, pressure, enthalpy_change in zip(inlet_streams, outlet_pressure, enthalpy_change_joule_per_kg)
103103
]

src/libecalc/domain/process/compressor/core/train/variable_speed_compressor_train_common_shaft_multiple_streams_and_pressures.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ def calculate_compressor_train(
434434
else:
435435
stage_inlet_stream = stage_inlet_stream.from_standard_rate(
436436
thermo_system=stage_inlet_stream.thermo_system,
437-
standard_rate=stage_inlet_stream.standard_rate - constraints.stream_rates[stream_number],
437+
standard_rate_m3_per_day=stage_inlet_stream.standard_rate
438+
- constraints.stream_rates[stream_number],
438439
)
439440
for stream_number in self.inlet_stream_connected_to_stage.get(stage_number):
440441
if stream_number > 0:
@@ -706,7 +707,7 @@ def set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
706707
if fluid_stream is not None:
707708
self.fluid_to_recirculate_in_stage_when_inlet_rate_is_zero[stage_number] = FluidStream(
708709
thermo_system=fluid_stream.thermo_system,
709-
mass_rate=EPSILON,
710+
mass_rate_kg_per_h=EPSILON,
710711
)
711712

712713
def get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(self, stage_number: int) -> FluidStream:

src/libecalc/domain/process/value_objects/fluid_stream/fluid_stream.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class FluidStream:
2020
"""
2121

2222
thermo_system: ThermoSystemInterface
23-
mass_rate: float
23+
mass_rate_kg_per_h: float
2424

2525
def __post_init__(self):
2626
"""Validate stream properties"""
27-
if self.mass_rate < 0:
28-
raise NegativeMassRateException(self.mass_rate)
27+
if self.mass_rate_kg_per_h < 0:
28+
raise NegativeMassRateException(self.mass_rate_kg_per_h)
2929

3030
@property
3131
def conditions(self) -> ProcessConditions:
@@ -80,12 +80,12 @@ def vapor_fraction_molar(self) -> float:
8080
@cached_property
8181
def volumetric_rate(self) -> float:
8282
"""Calculate volumetric flow rate [m³/h]."""
83-
return self.mass_rate / self.density
83+
return self.mass_rate_kg_per_h / self.density
8484

8585
@cached_property
8686
def standard_rate(self) -> float:
8787
"""Calculate standard volumetric flow rate [Sm³/day]."""
88-
return self.mass_rate / self.standard_density_gas_phase_after_flash * UnitConstants.HOURS_PER_DAY
88+
return self.mass_rate_kg_per_h / self.standard_density_gas_phase_after_flash * UnitConstants.HOURS_PER_DAY
8989

9090
def create_stream_with_new_conditions(
9191
self, conditions: ProcessConditions, remove_liquid: bool = False
@@ -107,11 +107,11 @@ def create_stream_with_new_conditions(
107107
)
108108
return FluidStream(
109109
thermo_system=new_state,
110-
mass_rate=self.mass_rate,
110+
mass_rate_kg_per_h=self.mass_rate_kg_per_h,
111111
)
112112

113113
def create_stream_with_new_pressure_and_enthalpy_change(
114-
self, pressure_bara: float, enthalpy_change: float, remove_liquid: bool = False
114+
self, pressure_bara: float, enthalpy_change_joule_per_kg: float, remove_liquid: bool = False
115115
) -> FluidStream:
116116
"""Create a new stream with modified pressure and changed enthalpy.
117117
This performs a PH-flash on the fluid.
@@ -127,17 +127,17 @@ def create_stream_with_new_pressure_and_enthalpy_change(
127127
"""
128128
new_state = self.thermo_system.flash_to_pressure_and_enthalpy_change(
129129
pressure_bara=pressure_bara,
130-
enthalpy_change=enthalpy_change,
130+
enthalpy_change=enthalpy_change_joule_per_kg,
131131
remove_liquid=remove_liquid,
132132
)
133133

134134
return FluidStream(
135135
thermo_system=new_state,
136-
mass_rate=self.mass_rate,
136+
mass_rate_kg_per_h=self.mass_rate_kg_per_h,
137137
)
138138

139139
@classmethod
140-
def from_standard_rate(cls, standard_rate: float, thermo_system: ThermoSystemInterface) -> FluidStream:
140+
def from_standard_rate(cls, standard_rate_m3_per_day: float, thermo_system: ThermoSystemInterface) -> FluidStream:
141141
"""Create a stream from standard volumetric flow rate.
142142
143143
This allows creating a stream based on standard volumetric flow rate instead of mass rate.
@@ -153,6 +153,6 @@ def from_standard_rate(cls, standard_rate: float, thermo_system: ThermoSystemInt
153153
"""
154154
# Calculate mass rate from standard rate
155155
standard_density = thermo_system.standard_density_gas_phase_after_flash
156-
mass_rate = standard_rate * standard_density / UnitConstants.HOURS_PER_DAY
156+
mass_rate_kg_per_h = standard_rate_m3_per_day * standard_density / UnitConstants.HOURS_PER_DAY
157157

158-
return cls(thermo_system=thermo_system, mass_rate=mass_rate)
158+
return cls(thermo_system=thermo_system, mass_rate_kg_per_h=mass_rate_kg_per_h)

src/libecalc/domain/process/value_objects/fluid_stream/mixing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
5858
if not streams:
5959
raise EmptyStreamListException()
6060

61-
total_mass_rate = sum(s.mass_rate for s in streams)
61+
total_mass_rate = sum(s.mass_rate_kg_per_h for s in streams)
6262
if total_mass_rate == 0:
6363
raise ZeroTotalMassRateException()
6464

6565
# Calculate mass-weighted average temperature
66-
temperature_mix = sum(s.mass_rate * s.temperature_kelvin for s in streams) / total_mass_rate
66+
temperature_mix = sum(s.mass_rate_kg_per_h * s.temperature_kelvin for s in streams) / total_mass_rate
6767

6868
# Lowest pressure among all streams
6969
reference_pressure = min(s.pressure_bara for s in streams)
@@ -82,7 +82,7 @@ def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
8282
raise IncompatibleEoSModelsException(reference_eos_model, s.thermo_system.eos_model)
8383

8484
# Compute total molar flow for each stream
85-
stream_total_molar_rates = [s.mass_rate / s.molar_mass for s in streams]
85+
stream_total_molar_rates = [s.mass_rate_kg_per_h / s.molar_mass for s in streams]
8686
mix_total_molar_rate = sum(stream_total_molar_rates)
8787

8888
# Sum molar flow of each component across all streams
@@ -117,5 +117,5 @@ def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
117117
# Create a new stream with calculated properties
118118
return FluidStream(
119119
thermo_system=thermo_system_mix,
120-
mass_rate=total_mass_rate,
120+
mass_rate_kg_per_h=total_mass_rate,
121121
)

src/libecalc/infrastructure/neqsim_fluid_provider/neqsim_fluid_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def create_stream_from_standard_rate(
7272
temperature_kelvin=temperature_kelvin,
7373
)
7474
return FluidStream.from_standard_rate(
75-
standard_rate=standard_rate_m3_per_day,
75+
standard_rate_m3_per_day=standard_rate_m3_per_day,
7676
thermo_system=thermo_system,
7777
)
7878

@@ -95,7 +95,7 @@ def create_stream_from_mass_rate(
9595
)
9696
return FluidStream(
9797
thermo_system=thermo_system,
98-
mass_rate=mass_rate_kg_per_h,
98+
mass_rate_kg_per_h=mass_rate_kg_per_h,
9999
)
100100

101101
def standard_rate_to_mass_rate(

tests/libecalc/core/models/compressor_modelling/test_compressor_model_vs_unisim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_fluid_streams(unisim_test_data):
266266
outlet_streams_enthalpy = [
267267
s.create_stream_with_new_pressure_and_enthalpy_change(
268268
pressure_bara=unisim_test_data.output_stream_data.pressures[index],
269-
enthalpy_change=compressor_data_enthalpy_change_joule_per_kg[index],
269+
enthalpy_change_joule_per_kg=compressor_data_enthalpy_change_joule_per_kg[index],
270270
)
271271
for index, s in enumerate(inlet_streams)
272272
]

0 commit comments

Comments
 (0)