Skip to content

Commit

Permalink
chore: add setter/getter for fluid to recirculate
Browse files Browse the repository at this point in the history
  • Loading branch information
olelod committed Sep 12, 2023
1 parent 1205a62 commit 8786eea
Showing 1 changed file with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(

# in rare cases we can end up with trying to mix two streams with zero mass rate, and need the fluid from the
# previous time step to recirculate. This will take care of that.
self.fluid_to_recirculate_in_stage = [None] * len(self.stages)
self.fluid_to_recirculate_in_stage_when_inlet_rate_is_zero = [None] * len(self.stages)

@staticmethod
def _check_intermediate_pressure_stage_number_is_valid(
Expand Down Expand Up @@ -868,8 +868,11 @@ def calculate_compressor_train_given_rate_ps_speed(
mass_rate_this_stage_kg_per_hour += mass_rate_additional_inlet_stream_kg_per_hour

if mass_rate_this_stage_kg_per_hour == 0:
if self.fluid_to_recirculate_in_stage[stage_number]:
inlet_stream = self.fluid_to_recirculate_in_stage[stage_number]
fluid_to_recirculate = self.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_number
)
if fluid_to_recirculate:
inlet_stream = fluid_to_recirculate
else:
raise ValueError(
f"Trying to recirculate fluid in stage {stage_number} without defining which "
Expand All @@ -892,7 +895,9 @@ def calculate_compressor_train_given_rate_ps_speed(
)

mass_rate_previous_stage_kg_per_hour = mass_rate_this_stage_kg_per_hour
self.fluid_to_recirculate_in_stage[stage_number] = inlet_stream
self.set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_number, fluid_stream=inlet_stream
)
return CompressorTrainResultSingleTimeStep(
stage_results=stage_results,
speed=speed,
Expand Down Expand Up @@ -1149,8 +1154,9 @@ def _update_inlet_fluid_and_std_rates_for_last_subtrain(

# update inlet fluid for the subtrain with new composition
if inlet_mass_rate == 0:
if self.fluid_to_recirculate_in_stage[0]:
updated_inlet_fluid = self.fluid_to_recirculate_in_stage[0]
fluid_to_recirculate = self.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(stage_number=0)
if fluid_to_recirculate:
updated_inlet_fluid = fluid_to_recirculate
else:
raise ValueError("Trying to recirculate unknown fluid in compressor stage")
else:
Expand Down Expand Up @@ -1304,10 +1310,17 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(
+ compressor_train_results_to_return_last_part.stage_results
)

self.fluid_to_recirculate_in_stage = (
compressor_train_first_part.fluid_to_recirculate_in_stage
+ compressor_train_last_part.fluid_to_recirculate_in_stage
)
for stage_number in range(len(self.stages)):
self.set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_number,
fluid_stream=compressor_train_first_part.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_number
)
if stage_number < stage_number_for_intermediate_pressure_target
else compressor_train_last_part.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_number - stage_number_for_intermediate_pressure_target
),
)

return CompressorTrainResultSingleTimeStep(
speed=speed,
Expand All @@ -1316,6 +1329,29 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(
or compressor_train_results_to_return_last_part.failure_status,
)

def set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
self, stage_number: int, fluid_stream: FluidStream
) -> None:
"""Keep track of what fluid passes through each compressor stage in the compressor train at a given calculation
step. This is done in case of the possibility of having a zero inlet rate at the next calculation step when
adding/subtracting ingoing/outgoing streams.
Args:
stage_number: The stage number (zero index)
fluid_stream: The fluid stream passing through compressor stage number <stage_number>
"""
self.fluid_to_recirculate_in_stage_when_inlet_rate_is_zero[stage_number] = fluid_stream

def get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(self, stage_number: int) -> FluidStream:
"""Retrieve the fluid that passed through a given compressor stage in the compressor train at the previous
calculation step.
Arge:
stage_number: The stage number (zero index)
"""
return self.fluid_to_recirculate_in_stage_when_inlet_rate_is_zero[stage_number]


def split_rates_on_stage_number(
compressor_train: VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
Expand Down Expand Up @@ -1391,10 +1427,16 @@ def split_train_on_stage_number(
),
)

compressor_train_first_part.fluid_to_recirculate_in_stage = compressor_train.fluid_to_recirculate_in_stage[
:stage_number
]
compressor_train_last_part.fluid_to_recirculate_in_stage = compressor_train.fluid_to_recirculate_in_stage[
stage_number:
]
for stage_no in range(len(compressor_train.stages)):
if stage_no < stage_number:
compressor_train_first_part.set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_no,
fluid_stream=compressor_train.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(stage_no),
)
else:
compressor_train_last_part.set_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(
stage_number=stage_no - stage_number,
fluid_stream=compressor_train.get_fluid_to_recirculate_in_stage_when_inlet_rate_is_zero(stage_no),
)

return compressor_train_first_part, compressor_train_last_part

0 comments on commit 8786eea

Please sign in to comment.