Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merge Queue- Start here]refactor: Use a list comprehension to create a transformed list #112

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,17 @@ def evaluate_consumers(
"""
consumer_rates = operational_setting.rates

consumer_results = []
for i, consumer in enumerate(self.consumers):
consumer_results.append(
CompressorResult(
name=consumer.name,
consumer_model_result=consumer.facility_model.evaluate_rate_ps_pd(
rate=consumer_rates[i],
suction_pressure=operational_setting.suction_pressures[i],
discharge_pressure=operational_setting.discharge_pressures[i],
),
)
return [
CompressorResult(
name=consumer.name,
consumer_model_result=consumer.facility_model.evaluate_rate_ps_pd(
rate=consumer_rates[i],
suction_pressure=operational_setting.suction_pressures[i],
discharge_pressure=operational_setting.discharge_pressures[i],
),
)
return consumer_results
for i, consumer in enumerate(self.consumers)
]


class PumpSystemConsumerFunction(ConsumerSystemConsumerFunction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,146 +133,139 @@ def from_result_list_to_dto(
result_list: List[CompressorTrainResultSingleTimeStep],
compressor_charts: Optional[List[Union[dto.SingleSpeedChart, dto.VariableSpeedChart]]],
) -> List[CompressorStageResult]:
stage_results = []
number_of_stages = max([len(t.stage_results) for t in result_list])
for i in range(number_of_stages):
stage_results.append(
CompressorStageResult(
energy_usage=[result_list[t].stage_results[i].power_megawatt for t in range(len(result_list))],
energy_usage_unit=Unit.MEGA_WATT,
power=[result_list[t].stage_results[i].power_megawatt for t in range(len(result_list))],
power_unit=Unit.MEGA_WATT,
mass_rate_kg_per_hr=[
result_list[t].stage_results[i].mass_rate_asv_corrected_kg_per_hour
return [
CompressorStageResult(
energy_usage=[result_list[t].stage_results[i].power_megawatt for t in range(len(result_list))],
energy_usage_unit=Unit.MEGA_WATT,
power=[result_list[t].stage_results[i].power_megawatt for t in range(len(result_list))],
power_unit=Unit.MEGA_WATT,
mass_rate_kg_per_hr=[
result_list[t].stage_results[i].mass_rate_asv_corrected_kg_per_hour for t in range(len(result_list))
],
mass_rate_before_asv_kg_per_hr=[
result_list[t].stage_results[i].mass_rate_kg_per_hour for t in range(len(result_list))
],
inlet_stream_condition=CompressorStreamCondition(
pressure=[
result_list[t].stage_results[i].inlet_stream.pressure_bara
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
mass_rate_before_asv_kg_per_hr=[
result_list[t].stage_results[i].mass_rate_kg_per_hour for t in range(len(result_list))
pressure_before_choking=[
result_list[t].stage_results[i].inlet_pressure_before_choking for t in range(len(result_list))
],
inlet_stream_condition=CompressorStreamCondition(
pressure=[
result_list[t].stage_results[i].inlet_stream.pressure_bara
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
pressure_before_choking=[
result_list[t].stage_results[i].inlet_pressure_before_choking
for t in range(len(result_list))
],
# Note: Here we reverse the lingo from "before ASV" to "ASV corrected"
actual_rate_m3_per_hr=[
result_list[t].stage_results[i].inlet_actual_rate_asv_corrected_m3_per_hour
for t in range(len(result_list))
],
actual_rate_before_asv_m3_per_hr=[
result_list[t].stage_results[i].inlet_actual_rate_m3_per_hour
for t in range(len(result_list))
],
density_kg_per_m3=[
result_list[t].stage_results[i].inlet_stream.density_kg_per_m3
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
kappa=[
result_list[t].stage_results[i].inlet_stream.kappa
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
z=[
result_list[t].stage_results[i].inlet_stream.z
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
temperature_kelvin=[
result_list[t].stage_results[i].inlet_stream.temperature_kelvin
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
),
outlet_stream_condition=CompressorStreamCondition(
pressure=[
result_list[t].stage_results[i].outlet_stream.pressure_bara
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
pressure_before_choking=[
result_list[t].stage_results[i].outlet_pressure_before_choking
for t in range(len(result_list))
],
actual_rate_m3_per_hr=[
result_list[t].stage_results[i].outlet_actual_rate_m3_per_hour
for t in range(len(result_list))
],
actual_rate_before_asv_m3_per_hr=None, # Todo: Add me
density_kg_per_m3=[
result_list[t].stage_results[i].outlet_stream.density_kg_per_m3
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
kappa=[
result_list[t].stage_results[i].outlet_stream.kappa
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
z=[
result_list[t].stage_results[i].outlet_stream.z
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
temperature_kelvin=[
result_list[t].stage_results[i].outlet_stream.temperature_kelvin
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
),
polytropic_enthalpy_change_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_enthalpy_change_kJ_per_kg
# Note: Here we reverse the lingo from "before ASV" to "ASV corrected"
actual_rate_m3_per_hr=[
result_list[t].stage_results[i].inlet_actual_rate_asv_corrected_m3_per_hour
for t in range(len(result_list))
],
polytropic_head_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_head_kJ_per_kg for t in range(len(result_list))
actual_rate_before_asv_m3_per_hr=[
result_list[t].stage_results[i].inlet_actual_rate_m3_per_hour for t in range(len(result_list))
],
polytropic_efficiency=[
result_list[t].stage_results[i].polytropic_efficiency for t in range(len(result_list))
density_kg_per_m3=[
result_list[t].stage_results[i].inlet_stream.density_kg_per_m3
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
polytropic_enthalpy_change_before_choke_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_enthalpy_change_before_choke_kJ_per_kg
kappa=[
result_list[t].stage_results[i].inlet_stream.kappa
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
speed=[result.speed for result in result_list],
asv_recirculation_loss_mw=[
result_list[t].stage_results[i].asv_recirculation_loss_mw for t in range(len(result_list))
z=[
result_list[t].stage_results[i].inlet_stream.z
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
# Validity flags
is_valid=[result_list[t].stage_results[i].is_valid for t in range(len(result_list))],
chart_area_flags=[result_list[t].stage_results[i].chart_area_flag for t in range(len(result_list))],
rate_has_recirculation=[
bool(result_list[t].stage_results[i].rate_has_recirculation) for t in range(len(result_list))
temperature_kelvin=[
result_list[t].stage_results[i].inlet_stream.temperature_kelvin
if result_list[t].stage_results[i].inlet_stream is not None
else np.nan
for t in range(len(result_list))
],
rate_exceeds_maximum=[
bool(result_list[t].stage_results[i].rate_exceeds_maximum) for t in range(len(result_list))
),
outlet_stream_condition=CompressorStreamCondition(
pressure=[
result_list[t].stage_results[i].outlet_stream.pressure_bara
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
pressure_is_choked=[
bool(result_list[t].stage_results[i].pressure_is_choked) for t in range(len(result_list))
pressure_before_choking=[
result_list[t].stage_results[i].outlet_pressure_before_choking for t in range(len(result_list))
],
head_exceeds_maximum=[
bool(result_list[t].stage_results[i].head_exceeds_maximum) for t in range(len(result_list))
actual_rate_m3_per_hr=[
result_list[t].stage_results[i].outlet_actual_rate_m3_per_hour for t in range(len(result_list))
],
fluid_composition={},
chart=compressor_charts[i] if compressor_charts is not None else None,
)
actual_rate_before_asv_m3_per_hr=None, # Todo: Add me
density_kg_per_m3=[
result_list[t].stage_results[i].outlet_stream.density_kg_per_m3
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
kappa=[
result_list[t].stage_results[i].outlet_stream.kappa
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
z=[
result_list[t].stage_results[i].outlet_stream.z
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
temperature_kelvin=[
result_list[t].stage_results[i].outlet_stream.temperature_kelvin
if result_list[t].stage_results[i].outlet_stream is not None
else np.nan
for t in range(len(result_list))
],
),
polytropic_enthalpy_change_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_enthalpy_change_kJ_per_kg
for t in range(len(result_list))
],
polytropic_head_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_head_kJ_per_kg for t in range(len(result_list))
],
polytropic_efficiency=[
result_list[t].stage_results[i].polytropic_efficiency for t in range(len(result_list))
],
polytropic_enthalpy_change_before_choke_kJ_per_kg=[
result_list[t].stage_results[i].polytropic_enthalpy_change_before_choke_kJ_per_kg
for t in range(len(result_list))
],
speed=[result.speed for result in result_list],
asv_recirculation_loss_mw=[
result_list[t].stage_results[i].asv_recirculation_loss_mw for t in range(len(result_list))
],
# Validity flags
is_valid=[result_list[t].stage_results[i].is_valid for t in range(len(result_list))],
chart_area_flags=[result_list[t].stage_results[i].chart_area_flag for t in range(len(result_list))],
rate_has_recirculation=[
bool(result_list[t].stage_results[i].rate_has_recirculation) for t in range(len(result_list))
],
rate_exceeds_maximum=[
bool(result_list[t].stage_results[i].rate_exceeds_maximum) for t in range(len(result_list))
],
pressure_is_choked=[
bool(result_list[t].stage_results[i].pressure_is_choked) for t in range(len(result_list))
],
head_exceeds_maximum=[
bool(result_list[t].stage_results[i].head_exceeds_maximum) for t in range(len(result_list))
],
fluid_composition={},
chart=compressor_charts[i] if compressor_charts is not None else None,
)
return stage_results
for i in range(number_of_stages)
]

class Config:
extra = Extra.forbid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _evaluate_rate_ps_pd(
:param rate: Rate values [Sm3/day]
:param suction_pressure: suction pressure [bara]
:param discharge_pressure: discharge pressure [bara]
:return:
:return: train result
"""
if isinstance(self, CompressorTrainSimplifiedUnknownStages):
self.stages = self.get_stages(
Expand Down Expand Up @@ -140,18 +140,13 @@ def _evaluate_rate_ps_pd(
inlet_pressure = inlet_pressure * pressure_ratios_per_stage

# Converting from individual stage results to a train results and adding max rate per time step.
train_result = []
for time_step in range(len(compressor_stages_result_per_time_step[0])):
# Merging
train_result.append(
CompressorTrainResultSingleTimeStep(
speed=np.nan,
stage_results=[
result[time_step].stage_results[0] for result in compressor_stages_result_per_time_step
],
)
return [
CompressorTrainResultSingleTimeStep(
speed=np.nan,
stage_results=[result[time_step].stage_results[0] for result in compressor_stages_result_per_time_step],
)
return train_result
for time_step in range(len(compressor_stages_result_per_time_step[0]))
]

def calculate_compressor_stage_work_given_outlet_pressure(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,15 @@ def get_single_speed_equivalent_train(
A single speed compressor train at given shaft speed

"""
single_speed_compressor_stages = []
for stage in compressor_train.stages:
single_speed_compressor_stages.append(
CompressorTrainStage(
compressor_chart=get_single_speed_equivalent(compressor_chart=stage.compressor_chart, speed=speed),
inlet_temperature_kelvin=stage.inlet_temperature_kelvin,
remove_liquid_after_cooling=stage.remove_liquid_after_cooling,
pressure_drop_ahead_of_stage=stage.pressure_drop_ahead_of_stage,
)
single_speed_compressor_stages = [
CompressorTrainStage(
compressor_chart=get_single_speed_equivalent(compressor_chart=stage.compressor_chart, speed=speed),
inlet_temperature_kelvin=stage.inlet_temperature_kelvin,
remove_liquid_after_cooling=stage.remove_liquid_after_cooling,
pressure_drop_ahead_of_stage=stage.pressure_drop_ahead_of_stage,
)
for stage in compressor_train.stages
]

return SingleSpeedCompressorTrainCommonShaft(
data_transfer_object=dto.SingleSpeedCompressorTrain(
Expand Down
Loading