Skip to content

Commit 5ce2f63

Browse files
committed
feat: allow cross overs both in and out of the same compressor train in a compressor system
This can be done if it is made sure that the compressor trains in the compressor system are processed in the right order. You can only pass rates to a compressor train that has not been processed yet. Hence, the indexes in the list specifying the cross overs must be larger than the index of the compressor train where the cross over comes from (or zero, meaning no cross over).
1 parent 09929cb commit 5ce2f63

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def calculate_operational_settings_after_cross_over(
287287
f" {type(energy_usage_model).__name__} has not been implemented."
288288
f" This should not happen. Please contact eCalc support."
289289
)
290-
transfer_rate = requested_rates[consumer_index] - consumer_maximum_rate
290+
transfer_rate = rates_after_cross_over[consumer_index] - consumer_maximum_rate
291291
# Only transfer when max rate is exceeded
292292
transfer_rate = np.where(transfer_rate > 0, transfer_rate, 0)
293293

src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/yaml_energy_usage_model_consumer_system.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal
22

3-
from pydantic import Field
3+
from pydantic import Field, model_validator
44

55
from libecalc.presentation.yaml.yaml_types import YamlBase
66
from libecalc.presentation.yaml.yaml_types.components.legacy.energy_usage_model.common import (
@@ -65,6 +65,36 @@ class YamlCompressorSystemOperationalSetting(YamlBase):
6565
description="Set suction pressure equal for all consumers in a consumer system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/SUCTION_PRESSURE",
6666
)
6767

68+
@model_validator(mode="after")
69+
def ensure_increasing_cross_over(self):
70+
if self.crossover is None:
71+
return self
72+
for compressor_train_index, crossover_to in enumerate(self.crossover):
73+
crossover_to_compressor_train_index = (
74+
crossover_to - 1
75+
) # compressor_train_index is 0-indexed, crossover_to is 1-indexed
76+
no_crossover = crossover_to == 0
77+
if crossover_to_compressor_train_index > compressor_train_index or no_crossover:
78+
pass # passing excess rate to a comp. train not yet evaluated or no crossover defined for this comp. train
79+
else:
80+
raise ValueError(
81+
f"Crossover: {self.crossover}\n"
82+
"The compressor trains in the compressor system are not defined in the correct order, according to "
83+
"the way the crossovers are set up. eCalc can now try to pass excess rates to compressor trains in "
84+
"the system that has already been evaluated. \n\n"
85+
"To avoid loops and to avoid passing rates to compressor trains that have already been "
86+
"processed, the index of the crossovers should be either 0 (no crossover) or larger than the index "
87+
"of the current compressor train (passing excess rate to a compressor train not yet evaluated). \n\n"
88+
"CROSSOVER: [2, 3, 0] is valid, but CROSSOVER: [2, 1, 0] is not. \n"
89+
)
90+
91+
return self
92+
93+
def train_not_evaluated(self, index: int):
94+
if self.crossover is None:
95+
return False
96+
return self.crossover[index] == 0
97+
6898

6999
class YamlPumpSystemOperationalSettings(YamlCompressorSystemOperationalSetting):
70100
fluid_densities: list[YamlExpressionType] = Field(

0 commit comments

Comments
 (0)