Skip to content

Commit

Permalink
chore!: control margin required for compressors (#635)
Browse files Browse the repository at this point in the history
* chore: control margin required for compressors and generic charts restricted to simplified trains

ECALC-1620
  • Loading branch information
frodehk authored Oct 31, 2024
1 parent 48732d4 commit 2b3ea2a
Show file tree
Hide file tree
Showing 13 changed files with 5,930 additions and 6,979 deletions.
3 changes: 2 additions & 1 deletion docs/drafts/next.draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ sidebar_position: -36
## Breaking changes

* Removing support for Python 3.8, 3.9, 3.10. If you have downloaded/installed libeCalc manually, you will need to
run with at least Python 3.11 from now on.
run with at least Python 3.11 from now on.
* control margin is required for compressors, except for simplified trains (control margin not allowed). Simplified trains have to use generic charts.
2 changes: 1 addition & 1 deletion src/libecalc/examples/advanced/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ MODELS:
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: generic_from_design_point_compressor_chart
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_variable_speed_compressor_chart
COMPRESSOR_CHART: generic_from_design_point_compressor_chart

VARIABLES:
hydrocarbon_export_sm3_per_day:
Expand Down
18 changes: 14 additions & 4 deletions src/libecalc/fixtures/cases/all_energy_usage_models/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
CompressorWithTurbine,
FluidComposition,
FluidModel,
GenericChartFromDesignPoint,
GenericChartFromInput,
PumpModel,
Turbine,
VariableSpeedCompressorTrain,
Expand Down Expand Up @@ -126,14 +128,18 @@ def simplified_variable_speed_compressor_train_with_gerg_fluid2(predefined_varia
stages=[
CompressorStage(
inlet_temperature_kelvin=303.15,
compressor_chart=predefined_variable_speed_compressor_chart_dto,
compressor_chart=GenericChartFromInput(polytropic_efficiency_fraction=0.75),
remove_liquid_after_cooling=True,
pressure_drop_before_stage=0,
control_margin=0,
),
CompressorStage(
inlet_temperature_kelvin=303.15,
compressor_chart=predefined_variable_speed_compressor_chart_dto,
compressor_chart=GenericChartFromDesignPoint(
polytropic_efficiency_fraction=0.75,
design_rate_actual_m3_per_hour=5000,
design_polytropic_head_J_per_kg=100000,
),
remove_liquid_after_cooling=True,
pressure_drop_before_stage=0,
control_margin=0,
Expand Down Expand Up @@ -256,14 +262,18 @@ def simplified_variable_speed_compressor_train_known_stages(
stages=[
CompressorStage(
inlet_temperature_kelvin=303.15,
compressor_chart=predefined_variable_speed_compressor_chart_dto,
compressor_chart=GenericChartFromInput(polytropic_efficiency_fraction=0.75),
remove_liquid_after_cooling=True,
pressure_drop_before_stage=0,
control_margin=0,
),
CompressorStage(
inlet_temperature_kelvin=303.15,
compressor_chart=predefined_variable_speed_compressor_chart_dto,
compressor_chart=GenericChartFromDesignPoint(
polytropic_efficiency_fraction=0.75,
design_rate_actual_m3_per_hour=5000,
design_polytropic_head_J_per_kg=100000,
),
remove_liquid_after_cooling=True,
pressure_drop_before_stage=0,
control_margin=0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ MODELS:
COMPRESSOR_TRAIN:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file
COMPRESSOR_CHART: generic_chart
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart
COMPRESSOR_CHART: generic_chart_from_design_point
- NAME: generic_chart_from_design_point
TYPE: COMPRESSOR_CHART
CHART_TYPE: GENERIC_FROM_DESIGN_POINT
Expand Down Expand Up @@ -185,6 +185,8 @@ MODELS:
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: variable_speed_compressor_train_predefined_variable_speed_chart_user_defined_fluid_composition
TYPE: VARIABLE_SPEED_COMPRESSOR_TRAIN
Expand All @@ -193,8 +195,12 @@ MODELS:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: turbine
TYPE: TURBINE
Expand Down Expand Up @@ -236,20 +242,28 @@ MODELS:
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file #variable_speed_compressor_chart_stage_1 # Assume defined in MODELS
STREAM:
- in_stream_stage_1
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file #variable_speed_compressor_chart_stage_2
STREAM:
- in_stream_stage_2
- another_in_stream_stage_2 # Will be mixed/flashed with the stream coming from stage 1 before entering stage 2 compressor
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
# Will be added with outlet stream of previous stage. This stream to be defined with a rate and pressure, and
# final pressure of stream for next stage based on outlet pressure of previous stream and this stream
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file #variable_speed_compressor_chart_stage_3
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
# No stream defined, meaning that there is no ingoing or outgoing streams ahead of this stage
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file #variable_speed_compressor_chart_stage_4
STREAM:
- out_stream_stage_4_export
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
INTERSTAGE_CONTROL_PRESSURE:
# An interstage pressure control is defined before this stage. The pressure controls below, defines what will
# be used to control the pressure if the speed is governed by the other
Expand All @@ -258,6 +272,8 @@ MODELS:
DOWNSTREAM_PRESSURE_CONTROL: INDIVIDUAL_ASV_PRESSURE
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file #variable_speed_compressor_chart_stage_5
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
# The final outlet stream does not need to be defined, what going out of the last compressor is the outlet stream
PRESSURE_CONTROL: INDIVIDUAL_ASV_PRESSURE
POWER_ADJUSTMENT_CONSTANT: 1
Expand All @@ -269,8 +285,12 @@ MODELS:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: single_speed_compressor_train_asv_pressure_control
TYPE: SINGLE_SPEED_COMPRESSOR_TRAIN
Expand All @@ -280,8 +300,12 @@ MODELS:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: single_speed_compressor_train_downstream_choke_pressure_control
TYPE: SINGLE_SPEED_COMPRESSOR_TRAIN
Expand All @@ -291,8 +315,12 @@ MODELS:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: single_speed_compressor_train_downstream_choking_and_maximum_discharge_pressure
TYPE: SINGLE_SPEED_COMPRESSOR_TRAIN
Expand All @@ -303,8 +331,12 @@ MODELS:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: user_defined_single_speed_compressor_chart
CONTROL_MARGIN: 0
CONTROL_MARGIN_UNIT: PERCENTAGE # PERCENTAGE is default, FRACTION is other possible value
POWER_ADJUSTMENT_CONSTANT: 1
- NAME: medium_gas_gerg
TYPE: FLUID
Expand All @@ -324,9 +356,9 @@ MODELS:
COMPRESSOR_TRAIN:
STAGES: # stages for train with predefined number of compressors
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart_curves_from_file
COMPRESSOR_CHART: generic_chart
- INLET_TEMPERATURE: 30
COMPRESSOR_CHART: predefined_compressor_chart
COMPRESSOR_CHART: generic_chart_from_design_point
POWER_ADJUSTMENT_CONSTANT: 1

FUEL_TYPES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def check_model_reference_wrapper(model_reference: Any, info: ValidationInfo):
},
) from e

# Also check compressor models in turbine
model = models_context[model_reference]

# Also check compressor models in turbine
if model.type == YamlModelType.COMPRESSOR_WITH_TURBINE:
# Handle the compressor_model in turbine, it should be limited to the specified types.
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class YamlCompressorStageWithMarginAndPressureDrop(YamlCompressorStage):
description="Pressure drop before compression stage [in bar]",
title="PRESSURE_DROP_AHEAD_OF_STAGE",
)
control_margin: Optional[float] = Field(
0.0,
control_margin: float = Field(
ge=0,
description="Surge control margin, see documentation for more details.",
title="CONTROL_MARGIN",
)
control_margin_unit: Optional[YamlControlMarginUnits] = Field(
YamlControlMarginUnits.PERCENTAGE,
control_margin_unit: YamlControlMarginUnits = Field(
...,
description="The unit of the surge control margin.",
title="CONTROL_MARGIN_UNIT",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List, Literal, Optional, Union

from pydantic import Field
from pydantic import Field, model_validator
from pydantic_core.core_schema import ValidationInfo

from libecalc.presentation.yaml.yaml_keywords import EcalcYamlKeywords
from libecalc.presentation.yaml.yaml_types import YamlBase
Expand All @@ -15,6 +16,7 @@
YamlUnknownCompressorStages,
)
from libecalc.presentation.yaml.yaml_types.models.yaml_enums import (
YamlChartType,
YamlModelType,
YamlPressureControl,
)
Expand Down Expand Up @@ -146,6 +148,34 @@ class YamlSimplifiedVariableSpeedCompressorTrain(YamlCompressorTrainBase):
def to_dto(self):
raise NotImplementedError

@model_validator(mode="after")
def check_compressor_chart(self, info: ValidationInfo):
if info.context is not None:
train = info.context["model_types"][self.name].compressor_train
allowed_charts_simplified_trains = [
YamlChartType.GENERIC_FROM_INPUT.value,
YamlChartType.GENERIC_FROM_DESIGN_POINT.value,
]
# If known compressor stages
if hasattr(train, EcalcYamlKeywords.models_type_compressor_train_stages.lower()):
for stage in train.stages:
compressor_chart = info.context["model_types"][stage.compressor_chart]

if compressor_chart.chart_type not in allowed_charts_simplified_trains:
raise ValueError(
f"{compressor_chart.chart_type.value} compressor chart is not supported for {self.type.value}. "
f"Allowed charts are {', '.join(allowed_charts_simplified_trains)}."
)
else:
# Unknown compressor stages
compressor_chart = info.context["model_types"][train.compressor_chart]
if compressor_chart.chart_type not in allowed_charts_simplified_trains:
raise ValueError(
f"{compressor_chart.chart_type} compressor chart is not supported for {self.type}. "
f"Allowed charts are {', '.join(allowed_charts_simplified_trains)}."
)
return self


class YamlMultipleStreamsStream(YamlBase):
type: Literal["INGOING", "OUTGOING"]
Expand Down
Loading

0 comments on commit 2b3ea2a

Please sign in to comment.