Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: define yaml classes for remaining elements in MODELS #307

Merged
merged 7 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.VARIABLE_SPEED] = YamlChartType.VARIABLE_SPEED
curves: YamlCurve = Field(..., description="One single compressor chart curve.", title="CURVE")
units: YamlUnits = None

def to_dto(self):
raise NotImplementedError
Comment on lines +94 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a mistake to define this as needed in YamlBase, as I have done currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean it should be defined in YamlBase instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it doesnt matter that much. We want to skip dtos completely, and map directly to domain. dtos are no longer needed, but we will need some clever ways to map to domain. WIP :)



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,94 @@
import enum
from typing import List, 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,
)
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: str = Field(
...,
description="Inlet temperature in Celsius for stage",
title="INLET_TEMPERATURE",
)
compressor_chart: YamlCompressorChart = Field(
...,
description="Reference to compressor chart model for stage, must be defined in MODELS or FACILITY_INPUTS",
title="COMPRESSOR_CHART",
)


class YamlCompressorStage(YamlCompressorStageBase):
pressure_drop_ahead_of_stage: str = 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",
)
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(
...,
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: str = 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",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from typing import List, Literal, 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,
YamlUnknownCompressorStages,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import (
YamlModelType,
YamlPressureControl,
)
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: 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",
)


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",
)
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(
...,
description="Compressor train definition",
title="COMPRESSOR_TRAIN",
)

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: YamlCompressorStages = Field(
...,
description="Compressor train definition",
title="COMPRESSOR_TRAIN",
)

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",
)

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="STREAMS",
)

def to_dto(self):
raise NotImplementedError
14 changes: 14 additions & 0 deletions src/libecalc/presentation/yaml/yaml_types/models/yaml_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ class YamlModelType(str, enum.Enum):
COMPRESSOR_CHART = "COMPRESSOR_CHART"
TURBINE = "TURBINE"
FLUID = "FLUID"
SINGLE_SPEED_COMPRESSOR_TRAIN = "SINGLE_SPEED_COMPRESSOR_TRAIN"
VARIABLE_SPEED_COMPRESSOR_TRAIN = "VARIABLE_SPEED_COMPRESSOR_TRAIN"
SIMPLIFIED_VARIABLE_SPEED_COMPRESSOR_TRAIN = "SIMPLIFIED_VARIABLE_SPEED_COMPRESSOR_TRAIN"
VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES = (
"VARIABLE_SPEED_COMPRESSOR_TRAIN_MULTIPLE_STREAMS_AND_PRESSURES"
)


class YamlChartType(str, enum.Enum):
VARIABLE_SPEED = "VARIABLE_SPEED"
GENERIC_FROM_INPUT = "GENERIC_FROM_INPUT"
GENERIC_FROM_DESIGN_POINT = "GENERIC_FROM_DESIGN_POINT"


class YamlPressureControl(enum.Enum):
DOWNSTREAM_CHOKE = "DOWNSTREAM_CHOKE"
UPSTREAM_CHOKE = "UPSTREAM_CHOKE"
INDIVIDUAL_ASV_PRESSURE = "INDIVIDUAL_ASV_PRESSURE"
INDIVIDUAL_ASV_RATE = "INDIVIDUAL_ASV_RATE"
COMMON_ASV = "COMMON_ASV"