Skip to content

Commit 9fb9d74

Browse files
authored
refactor: merge single speed and variable speed common shaft compressor trains (#1136)
chore: update and move some tests
1 parent fedb482 commit 9fb9d74

16 files changed

Lines changed: 1423 additions & 1853 deletions

File tree

src/libecalc/common/energy_model_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class EnergyModelType(str, Enum):
88
PUMP_MODEL = "PUMP_MODEL"
99
COMPRESSOR_TRAIN_SIMPLIFIED_WITH_KNOWN_STAGES = "COMPRESSOR_TRAIN_SIMPLIFIED_WITH_KNOWN_NUMBER_OF_COMPRESSORS"
1010
COMPRESSOR_TRAIN_SIMPLIFIED_WITH_UNKNOWN_STAGES = "COMPRESSOR_TRAIN_SIMPLIFIED_WITH_UNKNOWN_NUMBER_OF_COMPRESSORS"
11+
COMPRESSOR_TRAIN_COMMON_SHAFT = "COMPRESSOR_TRAIN_COMMON_SHAFT"
1112
VARIABLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT = "VARIABLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT"
1213
SINGLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT = "SINGLE_SPEED_COMPRESSOR_TRAIN_COMMON_SHAFT"
1314
VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES = (

src/libecalc/common/serializable_chart.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from libecalc.common.logger import logger
77
from libecalc.common.string.string_utils import to_camel_case
8+
from libecalc.domain.component_validation_error import ProcessChartTypeValidationException
89

910

1011
class EcalcBaseModel(BaseModel):
@@ -85,6 +86,13 @@ def sort_chart_curves_by_speed(cls, curves: list[ChartCurveDTO]) -> list[ChartCu
8586
"""Note: It is essential that the sort the curves by speed in order to set up the interpolations correctly."""
8687
return sorted(curves, key=lambda x: x.speed)
8788

89+
@model_validator(mode="after")
90+
def check_that_there_is_at_least_one_chart_curve(self) -> Self:
91+
if len(self.curves) == 0:
92+
msg = "At least one chart curve must be given to define a compressor performance chart."
93+
raise ProcessChartTypeValidationException(message=msg)
94+
return self
95+
8896
@property
8997
def min_speed(self) -> float:
9098
return min([curve.speed for curve in self.curves])

src/libecalc/domain/infrastructure/energy_components/legacy_consumer/consumer_function/compressor_consumer_function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
ConsumerFunctionResult,
66
)
77
from libecalc.domain.process.compressor.core.base import CompressorModel, CompressorWithTurbineModel
8-
from libecalc.domain.process.compressor.core.train.variable_speed_compressor_train_common_shaft_multiple_streams_and_pressures import (
9-
VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
8+
from libecalc.domain.process.compressor.core.train.compressor_train_common_shaft_multiple_streams_and_pressures import (
9+
CompressorTrainCommonShaftMultipleStreamsAndPressures,
1010
)
1111
from libecalc.domain.time_series_flow_rate import TimeSeriesFlowRate
1212
from libecalc.domain.time_series_power_loss_factor import TimeSeriesPowerLossFactor
@@ -42,7 +42,7 @@ def __init__(
4242

4343
rate_expression = rate_expression if isinstance(rate_expression, list) else [rate_expression]
4444

45-
if not isinstance(self._compressor_model, VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures):
45+
if not isinstance(self._compressor_model, CompressorTrainCommonShaftMultipleStreamsAndPressures):
4646
assert len(rate_expression) == 1
4747
stream_day_rate = np.asarray(rate_expression[0].get_stream_day_values(), dtype=np.float64)
4848
else:

src/libecalc/domain/process/compressor/core/train/base.py

Lines changed: 0 additions & 424 deletions
Large diffs are not rendered by default.

src/libecalc/domain/process/compressor/core/train/compressor_train_common_shaft.py

Lines changed: 945 additions & 0 deletions
Large diffs are not rendered by default.

src/libecalc/domain/process/compressor/core/train/variable_speed_compressor_train_common_shaft_multiple_streams_and_pressures.py renamed to src/libecalc/domain/process/compressor/core/train/compressor_train_common_shaft_multiple_streams_and_pressures.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from libecalc.common.serializable_chart import ChartDTO
1212
from libecalc.domain.component_validation_error import ProcessChartTypeValidationException
1313
from libecalc.domain.process.compressor.core.results import CompressorTrainResultSingleTimeStep
14-
from libecalc.domain.process.compressor.core.train.base import CompressorTrainModel
14+
from libecalc.domain.process.compressor.core.train.compressor_train_common_shaft import CompressorTrainCommonShaft
1515
from libecalc.domain.process.compressor.core.train.stage import CompressorTrainStage
1616
from libecalc.domain.process.compressor.core.train.train_evaluation_input import CompressorTrainEvaluationInput
1717
from libecalc.domain.process.compressor.core.train.types import FluidStreamObjectForMultipleStreams
@@ -26,7 +26,7 @@
2626
from libecalc.domain.process.value_objects.fluid_stream.fluid_model import FluidModel
2727

2828

29-
class VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures(CompressorTrainModel):
29+
class CompressorTrainCommonShaftMultipleStreamsAndPressures(CompressorTrainCommonShaft):
3030
"""An advanced model of a compressor train with variable speed, with the possibility of modelling additional
3131
streams going into or leaving the compressor train between the compressor train stages.
3232
@@ -768,7 +768,7 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(
768768

769769

770770
def split_rates_on_stage_number(
771-
compressor_train: VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
771+
compressor_train: CompressorTrainCommonShaftMultipleStreamsAndPressures,
772772
rates_per_stream: list[float],
773773
stage_number: int,
774774
) -> tuple[list[float], list[float]]:
@@ -806,13 +806,13 @@ def split_rates_on_stage_number(
806806

807807

808808
def split_train_on_stage_number(
809-
compressor_train: VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
809+
compressor_train: CompressorTrainCommonShaftMultipleStreamsAndPressures,
810810
stage_number: int,
811811
pressure_control_first_part: FixedSpeedPressureControl | None = None,
812812
pressure_control_last_part: FixedSpeedPressureControl | None = None,
813813
) -> tuple[
814-
VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
815-
VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures,
814+
CompressorTrainCommonShaftMultipleStreamsAndPressures,
815+
CompressorTrainCommonShaftMultipleStreamsAndPressures,
816816
]:
817817
"""
818818
Splits a variable speed compressor train into two sub-trains at the specified stage number.
@@ -838,7 +838,7 @@ def split_train_on_stage_number(
838838
# First part uses the main fluid factory (already made from first stream)
839839
fluid_factory_first_part = compressor_train.fluid_factory
840840

841-
compressor_train_first_part = VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures(
841+
compressor_train_first_part = CompressorTrainCommonShaftMultipleStreamsAndPressures(
842842
streams=streams_first_part,
843843
fluid_factory=fluid_factory_first_part,
844844
energy_usage_adjustment_constant=compressor_train.energy_usage_adjustment_constant,
@@ -872,7 +872,7 @@ def split_train_on_stage_number(
872872
# This will be updated at runtime after the fluid model (composition) is changed
873873
fluid_factory_last_part = compressor_train.fluid_factory
874874

875-
compressor_train_last_part = VariableSpeedCompressorTrainCommonShaftMultipleStreamsAndPressures(
875+
compressor_train_last_part = CompressorTrainCommonShaftMultipleStreamsAndPressures(
876876
streams=streams_last_part,
877877
fluid_factory=fluid_factory_last_part,
878878
energy_usage_adjustment_constant=compressor_train.energy_usage_adjustment_constant,

0 commit comments

Comments
 (0)