Skip to content

Commit

Permalink
chore!: do not allow control margin for simplified variable speed tra…
Browse files Browse the repository at this point in the history
…in (#569)

* chore: do not allow control margin for simplified variable speed train

ECALC-1483
  • Loading branch information
frodehk authored Aug 21, 2024
1 parent a38bb28 commit 82d7e58
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/libecalc/presentation/yaml/mappers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
)
from libecalc.presentation.yaml.yaml_entities import Resource, Resources
from libecalc.presentation.yaml.yaml_keywords import EcalcYamlKeywords
from libecalc.presentation.yaml.yaml_types.models.yaml_compressor_trains import (
YamlCompatibleTrainsControlMargin,
)


def _compressor_chart_mapper(
Expand Down Expand Up @@ -542,6 +545,16 @@ def _simplified_variable_speed_compressor_train_mapper(
if EcalcYamlKeywords.models_type_compressor_train_stages in train_spec:
# The stages are pre defined, known
stages = train_spec.get(EcalcYamlKeywords.models_type_compressor_train_stages)
for stage in stages:
if stage.get(EcalcYamlKeywords.models_type_compressor_train_stage_control_margin):
name = model_config.get(EcalcYamlKeywords.name)
raise ValueError(
f"{name}: {EcalcYamlKeywords.models_type_compressor_train_stage_control_margin}"
f" is not allowed for {model_config.get(EcalcYamlKeywords.type)}. "
f"{EcalcYamlKeywords.models_type_compressor_train_stage_control_margin} "
f"is only supported for the following train-types: "
f"{', '.join(YamlCompatibleTrainsControlMargin)}."
)
return dto.CompressorTrainSimplifiedWithKnownStages(
fluid_model=fluid_model,
stages=[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List, Literal, Optional, Union

from pydantic import Field
from pydantic import Field, model_validator

from libecalc.presentation.yaml.yaml_keywords import EcalcYamlKeywords
from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.models.model_reference_validation import (
FluidModelReference,
Expand Down Expand Up @@ -125,6 +126,21 @@ class YamlSimplifiedVariableSpeedCompressorTrain(YamlCompressorTrainBase):
title="POWER_ADJUSTMENT_CONSTANT",
)

@model_validator(mode="after")
def check_control_margin(self):
compressor_train = self.compressor_train
if not isinstance(compressor_train, YamlUnknownCompressorStages):
for stage in compressor_train.stages:
if stage.control_margin:
raise ValueError(
f"{self.name}: {EcalcYamlKeywords.models_type_compressor_train_stage_control_margin}"
f" is not allowed for {self.type.value}. "
f"{EcalcYamlKeywords.models_type_compressor_train_stage_control_margin} "
f"is only supported for the following train-types: "
f"{', '.join(YamlCompatibleTrainsControlMargin)}."
)
return self

def to_dto(self):
raise NotImplementedError

Expand Down Expand Up @@ -175,3 +191,9 @@ def to_dto(self):
YamlSingleSpeedCompressorTrain,
YamlVariableSpeedCompressorTrainMultipleStreamsAndPressures,
]

YamlCompatibleTrainsControlMargin = [
EcalcYamlKeywords.models_type_compressor_train_single_speed,
EcalcYamlKeywords.models_type_compressor_train_variable_speed,
EcalcYamlKeywords.models_type_compressor_train_variable_speed_multiple_streams_and_pressures,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import pytest
from libecalc.presentation.yaml.yaml_keywords import EcalcYamlKeywords
from libecalc.presentation.yaml.yaml_types.models.yaml_compressor_stages import (
YamlCompressorStage,
YamlCompressorStages,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_compressor_trains import (
YamlCompatibleTrainsControlMargin,
YamlSimplifiedVariableSpeedCompressorTrain,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import YamlModelType


def test_control_margin_not_allowed():
stage = YamlCompressorStage(
compressor_chart="compressor_chart1",
inlet_temperature=25,
control_margin=10,
)

stages = YamlCompressorStages(stages=[stage])

with pytest.raises(ValueError) as exc:
YamlSimplifiedVariableSpeedCompressorTrain(
name="simplified_train1",
type=YamlModelType.SIMPLIFIED_VARIABLE_SPEED_COMPRESSOR_TRAIN,
compressor_train=stages,
fluid_model="fluid_model1",
)

assert (
f"simplified_train1: {EcalcYamlKeywords.models_type_compressor_train_stage_control_margin} "
f"is not allowed for {EcalcYamlKeywords.models_type_compressor_train_simplified}. "
f"{EcalcYamlKeywords.models_type_compressor_train_stage_control_margin} is only "
f"supported for the following train-types: "
f"{', '.join(YamlCompatibleTrainsControlMargin)}"
) in str(exc.value)

0 comments on commit 82d7e58

Please sign in to comment.