From c75f83006752e509615da5938f00c892bc88985e Mon Sep 17 00:00:00 2001 From: olelod Date: Fri, 22 Nov 2024 11:41:07 +0100 Subject: [PATCH] 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). --- .../system/consumer_function.py | 2 +- ...yaml_energy_usage_model_consumer_system.py | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py b/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py index 5963bab35d..41f756099f 100644 --- a/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py +++ b/src/libecalc/core/consumers/legacy_consumer/system/consumer_function.py @@ -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) diff --git a/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/yaml_energy_usage_model_consumer_system.py b/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/yaml_energy_usage_model_consumer_system.py index 6503cfe98a..d0dad2af01 100644 --- a/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/yaml_energy_usage_model_consumer_system.py +++ b/src/libecalc/presentation/yaml/yaml_types/components/legacy/energy_usage_model/yaml_energy_usage_model_consumer_system.py @@ -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 ( @@ -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(