Skip to content

Commit

Permalink
fix: make sure that suction pressure is less than or equal to dischar…
Browse files Browse the repository at this point in the history
…ge pressure for compressor train

chore: add test of validation of operational conditions when suction pressure exceeds discharge pressure
  • Loading branch information
olelod committed Jun 29, 2023
1 parent 329c8e9 commit 18a4ad5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,30 @@ def _validate_operational_conditions(
f" The affected time steps will not be calculated, and rate is set to zero."
)
rate = np.where(intermediate_pressure <= 0, 0, rate)
intermediate_pressure = np.where(
np.logical_and(np.min(rate, axis=0) <= 0, intermediate_pressure <= 0), 1, intermediate_pressure
)
intermediate_pressure = np.where(intermediate_pressure <= 0, 1, intermediate_pressure)
if not np.all(suction_pressure > 0):
logger.warning(
f"Inlet pressure needs to be a positive value. Given values: {suction_pressure.tolist()}."
f" The affected time steps will not be calculated, and rate is set to zero."
)
rate = np.where(suction_pressure <= 0, 0, rate)
suction_pressure = np.where(
np.logical_and(np.min(rate, axis=0) <= 0, suction_pressure <= 0), 1, suction_pressure
)
suction_pressure = np.where(suction_pressure <= 0, 1, suction_pressure)
if not np.all(discharge_pressure > 0):
logger.warning(
f"Outlet pressure needs to be a positive value. Given values: {discharge_pressure.tolist()}"
f" The affected time steps will not be calculated, and rate is set to zero."
)
rate = np.where(discharge_pressure <= 0, 0, rate)
discharge_pressure = np.where(
np.logical_and(np.min(rate, axis=0) <= 0, discharge_pressure <= 0), 1, discharge_pressure
)

discharge_pressure = np.where(discharge_pressure <= 0, 1, discharge_pressure)
if not np.all(discharge_pressure >= suction_pressure):
logger.warning(
f"Inlet pressure needs to be a less than or equal to outlet pressure. Given values for inlet"
f" pressure: {suction_pressure.tolist()}. Given values for outlet pressure:"
f" {discharge_pressure.tolist()}. The affected time steps will not be calculated,"
f" and rate is set to zero."
)
rate = np.where(discharge_pressure < suction_pressure, 0, rate)
suction_pressure = np.where(suction_pressure > discharge_pressure, discharge_pressure, suction_pressure)
# for multiple stream train, rate is 2D
if np.ndim(rate) == 2:
# check if any of the streams have changed value during validation, streams along axis 0, time along axis 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,24 @@ def test_validate_operational_conditions(compressor_train):
assert np.all(intermediate_pressure == 2)
assert np.all(discharge_pressure == 3)
assert failure_status == [CompressorTrainCommonShaftFailureStatus.INVALID_RATE_INPUT, None]

# test that suction_pressure, when suction_pressure > discharge_pressure, is set to discharge_pressure,
# and that rate at the same time is set to 0.
[
rate,
suction_pressure,
discharge_pressure,
intermediate_pressure,
failure_status,
] = compressor_train.validate_operational_conditions(
rate=np.asarray([1000, 1000]),
suction_pressure=np.asarray([4, 3]),
intermediate_pressure=np.asarray([2, 2]),
discharge_pressure=np.asarray([3, 3]),
)
assert rate[0] == 0
assert rate[1] == 1000
assert np.all(suction_pressure == 3)
assert np.all(intermediate_pressure == 2)
assert np.all(discharge_pressure == 3)
assert failure_status == [CompressorTrainCommonShaftFailureStatus.INVALID_SUCTION_PRESSURE_INPUT, None]

0 comments on commit 18a4ad5

Please sign in to comment.