Skip to content

Commit 29fe490

Browse files
committed
chore: allow pressure input values to be zero
1 parent 01276f5 commit 29fe490

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/libecalc/presentation/yaml/domain/expression_time_series_pressure.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class InvalidPressureException(DomainValidationException):
99

1010
def __init__(self, pressure: float, pressure_expression: str):
1111
if str(pressure) == pressure_expression:
12-
msg = f"All pressure values must be positive, got {pressure}."
12+
msg = f"All pressure values must be non-negative, got {pressure}."
1313
else:
14-
msg = f"All pressure values must be positive, got {pressure} in {pressure_expression}."
14+
msg = f"All pressure values must be non-negative, got {pressure} in {pressure_expression}."
1515
super().__init__(message=msg)
1616

1717

@@ -30,9 +30,13 @@ def __init__(
3030
self._validate()
3131

3232
def _validate(self):
33-
"""Validate that all pressure values are positive."""
33+
"""Validate that all pressure values are non-negative."""
34+
# TODO: Currently all pressures must be non-negative, but in the future we want to only allow positive pressures
35+
# There are many situations where input values of zero means that equipment should be turned off
36+
# When the rest of the codebase is more mature with this respect (specific start/end dates for equipment,
37+
# instead of using rates/pressures of zero), we can tighten this validation
3438
for pressure in self._pressure_values:
35-
if pressure <= 0:
39+
if pressure < 0:
3640
raise InvalidPressureException(pressure, str(self._time_series_expression.get_expression()))
3741

3842
def get_periods(self) -> Periods:

src/libecalc/presentation/yaml/mappers/consumer_function_mapper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,21 @@ def validate_increasing_pressure(
129129
discharge_pressure: list[float],
130130
intermediate_pressure: list[float] | None = None,
131131
):
132+
# TODO: Currently all pressures must be non-negative, meaning that we allow zero pressures. This also means that we
133+
# allow zero discharge pressure, which is not physically meaningful in most cases. The compressor does no work.
134+
# In the future we want to only allow positive pressures, and then we can tighten this validation to require
135+
# strictly increasing pressures (i.e. suction < discharge, and suction < intermediate < discharge).
132136
for i in range(len(suction_pressure)):
133137
sp = suction_pressure[i]
134138
dp = discharge_pressure[i]
135139
if intermediate_pressure:
136140
ip = intermediate_pressure[i]
137-
if not (sp < ip < dp):
141+
if not (sp <= ip <= dp):
138142
raise ProcessPressureRatioValidationException(
139143
message=f"Invalid pressures at index {i+1}: suction pressure ({sp}) must be less than intermediate pressure ({ip}), which must be less than discharge pressure ({dp})."
140144
)
141145
else:
142-
if not (sp < dp):
146+
if not (sp <= dp):
143147
raise ProcessPressureRatioValidationException(
144148
message=f"Invalid pressures at index {i+1}: suction pressure ({sp}) must be less than discharge pressure ({dp})."
145149
)

tests/libecalc/presentation/yaml/domain/test_time_series_pressure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def test_expression_with_negative_pressure(expression_evaluator_factory):
22-
evaluator = expression_evaluator_factory.from_periods(periods=periods, variables={"SIM1;PS": [10, 0, 20]})
22+
evaluator = expression_evaluator_factory.from_periods(periods=periods, variables={"SIM1;PS": [10, -1, 20]})
2323
with pytest.raises(InvalidPressureException):
2424
ExpressionTimeSeriesPressure(
2525
time_series_expression=TimeSeriesExpression(expression="SIM1;PS", expression_evaluator=evaluator)
@@ -40,7 +40,7 @@ def test_expression_where_sum_of_variables_give_negative_pressure(expression_eva
4040

4141
def test_expressions_with_pressure_ratio_less_than_one(expression_evaluator_factory):
4242
evaluator = expression_evaluator_factory.from_periods(
43-
periods=periods, variables={"SIM1;PS": [10, 15, 20], "SIM1;PMID": [10, 15, 20], "SIM1;PD": [15, 15, 20]}
43+
periods=periods, variables={"SIM1;PS": [10, 15, 20], "SIM1;PMID": [10, 14, 20], "SIM1;PD": [15, 13, 20]}
4444
)
4545

4646
with pytest.raises(ProcessPressureRatioValidationException):

0 commit comments

Comments
 (0)