Skip to content

Commit

Permalink
chore: define yaml classes for remaining elements in MODELS (#307)
Browse files Browse the repository at this point in the history
* chore: add yaml class for remaining elements in models
  • Loading branch information
frodehk authored Dec 14, 2023
1 parent eff911e commit fedb807
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ def to_dto(self):
raise NotImplementedError


class YamlSingleSpeedChart(YamlBase):
name: str = Field(
...,
description="Name of the model. See documentation for more information.",
title="NAME",
)
type: Literal[YamlModelType.COMPRESSOR_CHART] = Field(
YamlModelType.COMPRESSOR_CHART,
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
chart_type: Literal[YamlChartType.SINGLE_SPEED] = YamlChartType.SINGLE_SPEED
curves: YamlCurve = Field(..., description="One single compressor chart curve.", title="CURVE")
units: YamlUnits = None

def to_dto(self):
raise NotImplementedError


class YamlVariableSpeedChart(YamlBase):
name: str = Field(
...,
Expand Down Expand Up @@ -143,7 +162,7 @@ def to_dto(self):


YamlCompressorChart = Annotated[
Union[YamlVariableSpeedChart, YamlGenericFromDesignPointChart, YamlGenericFromInputChart],
Union[YamlSingleSpeedChart, YamlVariableSpeedChart, YamlGenericFromDesignPointChart, YamlGenericFromInputChart],
Field(discriminator="chart_type"),
]
if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import enum
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 (
YamlGenericFromDesignPointChart,
YamlGenericFromInputChart,
YamlSingleSpeedChart,
YamlVariableSpeedChart,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import YamlPressureControl


class YamlControlMarginUnits(enum.Enum):
FRACTION = "FRACTION"
PERCENTAGE = "PERCENTAGE"


class YamlInterstageControlPressure(YamlBase):
upstream_pressure_control: YamlPressureControl = Field(
...,
description="Pressure control.",
title="UPSTREAM_PRESSURE_CONTROL",
)
downstream_pressure_control: YamlPressureControl = Field(
...,
description="Pressure control.",
title="DOWNSTREAM_PRESSURE_CONTROL",
)


class YamlCompressorStageBase(YamlBase):
inlet_temperature: float = Field(
...,
description="Inlet temperature in Celsius for stage",
title="INLET_TEMPERATURE",
)
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: Optional[
Annotated[
float,
Field(
...,
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
),
]
]


class YamlCompressorStageMultipleStreams(YamlCompressorStageBase):
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: 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="List of compressor stages",
title="STAGES",
)


class YamlSingleSpeedCompressorStages(YamlBase):
stages: List[YamlSingleSpeedCompressorStage] = Field(
...,
description="List of compressor stages",
title="STAGES",
)


class YamlVariableSpeedCompressorStages(YamlBase):
stages: List[YamlVariableSpeedCompressorStage] = Field(
...,
description="List of compressor stages",
title="STAGES",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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


class YamlCompressorTrainBase(YamlBase):
name: str = Field(
...,
description="Name of the model. See documentation for more information.",
title="NAME",
)
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):
type: Literal[YamlModelType.SINGLE_SPEED_COMPRESSOR_TRAIN] = Field(
YamlModelType.SINGLE_SPEED_COMPRESSOR_TRAIN,
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
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


class YamlVariableSpeedCompressorTrain(YamlCompressorTrainBase):
type: Literal[YamlModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN] = Field(
YamlModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN,
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
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


class YamlSimplifiedVariableSpeedCompressorTrain(YamlCompressorTrainBase):
type: Literal[YamlModelType.SIMPLIFIED_VARIABLE_SPEED_COMPRESSOR_TRAIN] = Field(
YamlModelType.SIMPLIFIED_VARIABLE_SPEED_COMPRESSOR_TRAIN,
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
compressor_train: Union[YamlCompressorStages, YamlUnknownCompressorStages] = Field(
...,
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


class YamlVariableSpeedCompressorTrainMultipleStreamsAndPressures(YamlCompressorTrainBase):
type: Literal[YamlModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES] = Field(
YamlModelType.VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES,
description="Defines the type of model. See documentation for more information.",
title="TYPE",
)
streams: List[YamlStream] = Field(
...,
description="A list of all in- and out-going streams for the compressor train. "
"The same equation of state (EOS) must be used for each INGOING stream fluid models",
title="STREAMS",
)
stages: List[YamlCompressorStageMultipleStreams] = Field(
...,
description="A list of all stages in compressor model.",
title="STAGES",
)

def to_dto(self):
raise NotImplementedError
Loading

0 comments on commit fedb807

Please sign in to comment.