|
1 | 1 | from typing import Literal
|
2 | 2 |
|
3 |
| -from pydantic import Field |
| 3 | +from pydantic import Field, model_validator |
4 | 4 |
|
5 | 5 | from libecalc.presentation.yaml.yaml_types import YamlBase
|
6 | 6 | from libecalc.presentation.yaml.yaml_types.components.legacy.energy_usage_model.common import (
|
@@ -65,6 +65,36 @@ class YamlCompressorSystemOperationalSetting(YamlBase):
|
65 | 65 | description="Set suction pressure equal for all consumers in a consumer system operational setting. \n\n$ECALC_DOCS_KEYWORDS_URL/SUCTION_PRESSURE",
|
66 | 66 | )
|
67 | 67 |
|
| 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 | + |
68 | 98 |
|
69 | 99 | class YamlPumpSystemOperationalSettings(YamlCompressorSystemOperationalSetting):
|
70 | 100 | fluid_densities: list[YamlExpressionType] = Field(
|
|
0 commit comments