Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -28,14 +28,27 @@
from libecalc.presentation.yaml.yaml_node import YamlDict, YamlList
from libecalc.presentation.yaml.yaml_types.components.yaml_asset import YamlAsset
from libecalc.presentation.yaml.yaml_types.components.yaml_installation import YamlInstallation
from libecalc.presentation.yaml.yaml_types.components.yaml_process_system import (
YamlProcessSimulation,
YamlProcessSystem,
YamlProcessUnit,
)
from libecalc.presentation.yaml.yaml_types.facility_model.yaml_facility_model import YamlFacilityModel
from libecalc.presentation.yaml.yaml_types.fuel_type.yaml_fuel_type import YamlFuelType
from libecalc.presentation.yaml.yaml_types.models import YamlConsumerModel
from libecalc.presentation.yaml.yaml_types.models import YamlConsumerModel, YamlFluidModel
from libecalc.presentation.yaml.yaml_types.streams.yaml_inlet_stream import YamlInletStream
from libecalc.presentation.yaml.yaml_types.time_series.yaml_time_series import YamlTimeSeriesCollection
from libecalc.presentation.yaml.yaml_types.yaml_default_datetime import YamlDefaultDatetime
from libecalc.presentation.yaml.yaml_types.yaml_variable import YamlVariable, YamlVariableReferenceId, YamlVariables
from libecalc.presentation.yaml.yaml_validation_context import YamlModelValidationContext

# Top-level YAML keywords used only by experimental/new sections
_PROCESS_UNITS_KEY = "PROCESS_UNITS"
_PROCESS_SYSTEMS_KEY = "PROCESS_SYSTEMS"
_INLET_STREAMS_KEY = "INLET_STREAMS"
_FLUID_MODELS_KEY = "FLUID_MODELS"
_PROCESS_SIMULATIONS_KEY = "PROCESS_SIMULATIONS"

dt_adapter = TypeAdapter(datetime.datetime)


Expand Down Expand Up @@ -397,6 +410,67 @@ def installations(self) -> Iterable[YamlInstallation]:
pass
return installations

@property
def inlet_streams(self) -> dict[str, YamlInletStream]:
inlet_streams: dict[str, YamlInletStream] = {}
raw = self._get_yaml_dict_or_empty(_INLET_STREAMS_KEY)
adapter = TypeAdapter(YamlInletStream)

for name, stream in raw.items():
try:
inlet_streams[name] = adapter.validate_python(stream)
except PydanticValidationError:
pass
return inlet_streams

@property
def fluid_models(self) -> dict[str, YamlFluidModel]:
fluid_models: dict[str, YamlFluidModel] = {}
raw = self._get_yaml_dict_or_empty(_FLUID_MODELS_KEY)

for name, fluid_model in raw.items():
try:
fluid_models[name] = TypeAdapter(YamlFluidModel).validate_python(fluid_model)
except PydanticValidationError:
pass
return fluid_models

@property
def process_units(self) -> dict[str, YamlProcessUnit]:
process_units: dict[str, YamlProcessUnit] = {}
raw = self._get_yaml_dict_or_empty(_PROCESS_UNITS_KEY)

for name, unit_data in raw.items():
try:
process_units[name] = TypeAdapter(YamlProcessUnit).validate_python(unit_data)
except PydanticValidationError:
pass
return process_units

@property
def process_systems(self) -> dict[str, YamlProcessSystem]:
process_systems: dict[str, YamlProcessSystem] = {}
raw = self._get_yaml_dict_or_empty(_PROCESS_SYSTEMS_KEY)

for name, process_system in raw.items():
try:
process_systems[name] = TypeAdapter(YamlProcessSystem).validate_python(process_system)
except PydanticValidationError:
pass

return process_systems

@property
def process_simulations(self) -> list[YamlProcessSimulation]:
process_simulations: list[YamlProcessSimulation] = []
adapter = TypeAdapter(YamlProcessSimulation)
for process_simulation in self._get_yaml_list_or_empty(_PROCESS_SIMULATIONS_KEY):
try:
process_simulations.append(adapter.validate_python(process_simulation))
except PydanticValidationError:
pass
return process_simulations

@property
def start(self) -> datetime.datetime | None:
start_value = self._internal_datamodel.get(EcalcYamlKeywords.start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from libecalc.common.string.string_utils import get_duplicates
from libecalc.presentation.yaml.yaml_types import YamlBase
from libecalc.presentation.yaml.yaml_types.components.yaml_installation import YamlInstallation
from libecalc.presentation.yaml.yaml_types.components.yaml_process_system import (
YamlProcessSimulation,
YamlProcessSystem,
YamlProcessUnit,
)
from libecalc.presentation.yaml.yaml_types.facility_model.yaml_facility_model import YamlFacilityModel
from libecalc.presentation.yaml.yaml_types.fuel_type.yaml_fuel_type import YamlFuelType
from libecalc.presentation.yaml.yaml_types.models import YamlConsumerModel, YamlFluidModel
Expand Down Expand Up @@ -61,6 +66,21 @@ class YamlAsset(YamlBase):
description="Defines variables used in an energy usage model by means of expressions or constants."
"\n\n$ECALC_DOCS_KEYWORDS_URL/VARIABLES",
)
process_units: dict[str, YamlProcessUnit] = Field(
default_factory=dict,
title="PROCESS_UNITS",
description="Defines process units used in PROCESS_SYSTEMS.",
)
process_systems: dict[str, YamlProcessSystem] = Field(
default_factory=dict,
title="PROCESS_SYSTEMS",
description="Defines process systems to use in process simulations.",
)
process_simulations: list[YamlProcessSimulation] = Field(
default_factory=list,
title="PROCESS_SIMULATIONS",
description="Defines one or more process simulations to be run.",
)
installations: list[YamlInstallation] = Field(
...,
title="INSTALLATIONS",
Expand Down Expand Up @@ -147,6 +167,16 @@ def validate_unique_references(self):
for fuel_type in self.fuel_types:
references.append(fuel_type.name)

if self.process_systems is not None:
references.extend(self.process_systems.keys())

if self.process_units is not None:
references.extend(self.process_units.keys())

if self.process_simulations is not None:
for process_simulation in self.process_simulations:
references.append(process_simulation.name)

if self.fluid_models is not None:
references.extend(self.fluid_models.keys())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,14 @@ class YamlProcessSimulation(YamlBase):
name: str
target: YamlParallelProcessSystem | YamlSerialProcessSystem | ProcessSystemReference
stream_distribution: YamlStreamDistribution


YamlProcessUnit = Annotated[
YamlCompressor,
Field(discriminator="type"),
]

YamlProcessSystem = Annotated[
YamlParallelProcessSystem | YamlSerialProcessSystem | YamlCompressorStageProcessSystem,
Field(discriminator="type"),
]