Skip to content

Commit

Permalink
chore: change some types
Browse files Browse the repository at this point in the history
  • Loading branch information
frodehk committed Dec 1, 2023
1 parent afde757 commit 3a5d499
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class YamlSingleSpeedChart(YamlBase):
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
chart_type: Literal[YamlChartType.VARIABLE_SPEED] = YamlChartType.VARIABLE_SPEED
chart_type: Literal[YamlChartType.SINGLE_SPEED] = YamlChartType.SINGLE_SPEED
curves: YamlCurve = Field(..., description="One single compressor chart curve.", title="CURVE")
units: YamlUnits = None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import enum
from typing import List, Union
from typing import Annotated, List, Optional, Union

from pydantic import Field

from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.models.yaml_compressor_chart import (
YamlCompressorChart,
YamlGenericFromDesignPointChart,
YamlGenericFromInputChart,
YamlSingleSpeedChart,
YamlVariableSpeedChart,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import YamlPressureControl

Expand All @@ -29,65 +32,141 @@ class YamlInterstageControlPressure(YamlBase):


class YamlCompressorStageBase(YamlBase):
inlet_temperature: str = Field(
inlet_temperature: float = Field(
...,
description="Inlet temperature in Celsius for stage",
title="INLET_TEMPERATURE",
)
compressor_chart: YamlCompressorChart = Field(
compressor_chart: Union[
YamlSingleSpeedChart, YamlVariableSpeedChart, YamlGenericFromDesignPointChart, YamlGenericFromInputChart
] = Field(
...,
description="Reference to compressor chart model for stage, must be defined in MODELS or FACILITY_INPUTS",
title="COMPRESSOR_CHART",
)


class YamlSingleSpeedCompressorStage(YamlCompressorStageBase):
pressure_drop_ahead_of_stage: Optional[
Annotated[
float,
Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
),
]
]
compressor_chart: YamlSingleSpeedChart


class YamlVariableSpeedCompressorStage(YamlCompressorStageBase):
pressure_drop_ahead_of_stage: Optional[
Annotated[
float,
Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
),
]
]
compressor_chart: YamlVariableSpeedChart


class YamlCompressorStage(YamlCompressorStageBase):
pressure_drop_ahead_of_stage: str = Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
)
pressure_drop_ahead_of_stage: Optional[
Annotated[
float,
Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
),
]
]


class YamlCompressorStageMultipleStreams(YamlCompressorStageBase):
control_margin: str = Field(
0.0,
description="Surge control margin, see documentation for more details.",
title="CONTROL_MARGIN",
)
control_margin_unit: YamlControlMarginUnits = Field(
YamlControlMarginUnits.PERCENTAGE,
description="The unit of the surge control margin.",
title="CONTROL_MARGIN_UNIT",
)
control_margin: Optional[
Annotated[
float,
Field(
0.0,
description="Surge control margin, see documentation for more details.",
title="CONTROL_MARGIN",
),
]
]
control_margin_unit: Optional[
Annotated[
YamlControlMarginUnits,
Field(
YamlControlMarginUnits.PERCENTAGE,
description="The unit of the surge control margin.",
title="CONTROL_MARGIN_UNIT",
),
]
]
stream: Union[str, List[str]] = Field(
...,
description="Reference to stream from STREAMS.",
title="STREAM",
)
pressure_drop_ahead_of_stage: str = Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
)
interstage_control_pressure: YamlInterstageControlPressure = Field(
pressure_drop_ahead_of_stage: Optional[
Annotated[
float,
Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
),
]
]
interstage_control_pressure: Optional[
Annotated[
YamlInterstageControlPressure,
Field(
...,
description="Pressure control. Can only be specified for one (only one) of the stages 2, ..., N.",
title="INTERSTAGE_CONTROL_PRESSURE",
),
]
]


class YamlUnknownCompressorStages(YamlCompressorStageBase):
maximum_pressure_ratio_per_stage: Optional[
Annotated[
float,
Field(
...,
description="Maximum pressure ratio per stage. Number of compressors will be large enough to ensure no "
"pressure ratios are above a given maximum pressure ratio per stage, but not larger",
title="MAXIMUM_PRESSURE_RATIO_PER_STAGE",
),
]
]


class YamlCompressorStages(YamlBase):
stages: List[YamlCompressorStage] = Field(
...,
description="Pressure control. Can only be specified for one (only one) of the stages 2, ..., N.",
title="INTERSTAGE_CONTROL_PRESSURE",
description="List of compressor stages",
title="STAGES",
)


class YamlUnknownCompressorStages(YamlCompressorStageBase):
maximum_pressure_ratio_per_stage: str = Field(
class YamlSingleSpeedCompressorStages(YamlBase):
stages: List[YamlSingleSpeedCompressorStage] = Field(
...,
description="Maximum pressure ratio per stage. Number of compressors will be large enough to ensure no "
"pressure ratios are above a given maximum pressure ratio per stage, but not larger",
title="MAXIMUM_PRESSURE_RATIO_PER_STAGE",
description="List of compressor stages",
title="STAGES",
)


class YamlCompressorStages(YamlBase):
stages: List[YamlCompressorStage] = Field(
class YamlVariableSpeedCompressorStages(YamlBase):
stages: List[YamlVariableSpeedCompressorStage] = Field(
...,
description="List of compressor stages",
title="STAGES",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from typing import List, Literal, Union
from typing import Annotated, List, Literal, Optional, Union

from pydantic import Field

from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.models.yaml_compressor_stages import (
YamlCompressorStageMultipleStreams,
YamlCompressorStages,
YamlSingleSpeedCompressorStages,
YamlUnknownCompressorStages,
YamlVariableSpeedCompressorStages,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import (
YamlModelType,
YamlPressureControl,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_fluid import (
YamlCompositionFluidModel,
YamlPredefinedFluidModel,
)
from libecalc.presentation.yaml.yaml_types.yaml_stream import YamlStream


Expand All @@ -21,26 +27,19 @@ class YamlCompressorTrainBase(YamlBase):
description="Name of the model. See documentation for more information.",
title="NAME",
)
fluid_model: str = Field(..., description="Reference to a fluid model", title="FLUID_MODEL")
pressure_control: YamlPressureControl = Field(
...,
description="Method for pressure control",
title="PRESSURE_CONTROL",
)
power_adjustment_constant: float = Field(
0.0,
description="Constant to adjust power usage in MW",
title="POWER_ADJUSTMENT_CONSTANT",
)
maximum_power: str = Field(
..., description="Optional constant MW maximum power the compressor train can require", title="MAXIMUM_POWER"
)
calculate_max_rate: str = Field(
...,
description="Optional compressor train max standard rate [Sm3/day] in result if set to true. "
"Default false. Use with caution. This will increase runtime significantly.",
title="CALCULATE_MAX_RATE",
fluid_model: Union[YamlPredefinedFluidModel, YamlCompositionFluidModel] = Field(
..., description="Reference to a fluid model", title="FLUID_MODEL"
)
maximum_power: Optional[
Annotated[
float,
Field(
...,
description="Optional constant MW maximum power the compressor train can require",
title="MAXIMUM_POWER",
),
]
]


class YamlSingleSpeedCompressorTrain(YamlCompressorTrainBase):
Expand All @@ -49,16 +48,47 @@ class YamlSingleSpeedCompressorTrain(YamlCompressorTrainBase):
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
maximum_discharge_pressure: str = Field(
...,
description="Maximum discharge pressure in bar (can only use if pressure control is DOWNSTREAM_CHOKE)",
title="MAXIMUM_DISCHARGE_PRESSURE",
)
compressor_train: YamlCompressorStages = Field(
compressor_train: YamlSingleSpeedCompressorStages = Field(
...,
description="Compressor train definition",
title="COMPRESSOR_TRAIN",
)
pressure_control: YamlPressureControl = Field(
...,
description="Method for pressure control",
title="PRESSURE_CONTROL",
)
maximum_discharge_pressure: Optional[
Annotated[
float,
Field(
...,
description="Maximum discharge pressure in bar (can only use if pressure control is DOWNSTREAM_CHOKE)",
title="MAXIMUM_DISCHARGE_PRESSURE",
),
]
]
calculate_max_rate: Optional[
Annotated[
float,
Field(
...,
description="Optional compressor train max standard rate [Sm3/day] in result if set to true. "
"Default false. Use with caution. This will increase runtime significantly.",
title="CALCULATE_MAX_RATE",
),
]
]
power_adjustment_constant: Optional[
Annotated[
float,
Field(
0.0,
description="Constant to adjust power usage in MW",
title="POWER_ADJUSTMENT_CONSTANT",
),
]
]

def to_dto(self):
raise NotImplementedError
Expand All @@ -70,11 +100,37 @@ class YamlVariableSpeedCompressorTrain(YamlCompressorTrainBase):
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
compressor_train: YamlCompressorStages = Field(
compressor_train: YamlVariableSpeedCompressorStages = Field(
...,
description="Compressor train definition",
title="COMPRESSOR_TRAIN",
)
pressure_control: YamlPressureControl = Field(
...,
description="Method for pressure control",
title="PRESSURE_CONTROL",
)
calculate_max_rate: Optional[
Annotated[
float,
Field(
...,
description="Optional compressor train max standard rate [Sm3/day] in result if set to true. "
"Default false. Use with caution. This will increase runtime significantly.",
title="CALCULATE_MAX_RATE",
),
]
]
power_adjustment_constant: Optional[
Annotated[
float,
Field(
0.0,
description="Constant to adjust power usage in MW",
title="POWER_ADJUSTMENT_CONSTANT",
),
]
]

def to_dto(self):
raise NotImplementedError
Expand All @@ -91,6 +147,17 @@ class YamlSimplifiedVariableSpeedCompressorTrain(YamlCompressorTrainBase):
description="Compressor train definition",
title="COMPRESSOR_TRAIN",
)
calculate_max_rate: Optional[
Annotated[
float,
Field(
...,
description="Optional compressor train max standard rate [Sm3/day] in result if set to true. "
"Default false. Use with caution. This will increase runtime significantly.",
title="CALCULATE_MAX_RATE",
),
]
]

def to_dto(self):
raise NotImplementedError
Expand All @@ -111,7 +178,7 @@ class YamlVariableSpeedCompressorTrainMultipleStreamsAndPressures(YamlCompressor
stages: List[YamlCompressorStageMultipleStreams] = Field(
...,
description="A list of all stages in compressor model.",
title="STREAMS",
title="STAGES",
)

def to_dto(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class YamlModelType(str, enum.Enum):


class YamlChartType(str, enum.Enum):
SINGLE_SPEED = "SINGLE_SPEED"
VARIABLE_SPEED = "VARIABLE_SPEED"
GENERIC_FROM_INPUT = "GENERIC_FROM_INPUT"
GENERIC_FROM_DESIGN_POINT = "GENERIC_FROM_DESIGN_POINT"
Expand Down
Loading

0 comments on commit 3a5d499

Please sign in to comment.