Skip to content

Commit

Permalink
feat: allow cross overs both in and out of the same compressor train …
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
olelod committed Nov 22, 2024
1 parent 09929cb commit c75f830
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def calculate_operational_settings_after_cross_over(
f" {type(energy_usage_model).__name__} has not been implemented."
f" This should not happen. Please contact eCalc support."
)
transfer_rate = requested_rates[consumer_index] - consumer_maximum_rate
transfer_rate = rates_after_cross_over[consumer_index] - consumer_maximum_rate
# Only transfer when max rate is exceeded
transfer_rate = np.where(transfer_rate > 0, transfer_rate, 0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Literal

from pydantic import Field
from pydantic import Field, model_validator

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

@model_validator(mode="after")
def ensure_increasing_cross_over(self):
if self.crossover is None:
return self
for compressor_train_index, crossover_to in enumerate(self.crossover):
crossover_to_compressor_train_index = (
crossover_to - 1
) # compressor_train_index is 0-indexed, crossover_to is 1-indexed
no_crossover = crossover_to == 0
if crossover_to_compressor_train_index > compressor_train_index or no_crossover:
pass # passing excess rate to a comp. train not yet evaluated or no crossover defined for this comp. train
else:
raise ValueError(
f"Crossover: {self.crossover}\n"
"The compressor trains in the compressor system are not defined in the correct order, according to "
"the way the crossovers are set up. eCalc can now try to pass excess rates to compressor trains in "
"the system that has already been evaluated. \n\n"
"To avoid loops and to avoid passing rates to compressor trains that have already been "
"processed, the index of the crossovers should be either 0 (no crossover) or larger than the index "
"of the current compressor train (passing excess rate to a compressor train not yet evaluated. \n\n"
"CROSSOVER: [2, 3, 0] is valid, but CROSSOVER: [2, 1, 0] is not. \n"
)

return self

def train_not_evaluated(self, index: int):
if self.crossover is None:
return False
return self.crossover[index] == 0


class YamlPumpSystemOperationalSettings(YamlCompressorSystemOperationalSetting):
fluid_densities: list[YamlExpressionType] = Field(
Expand Down

0 comments on commit c75f830

Please sign in to comment.