-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathchoke.py
More file actions
45 lines (37 loc) · 1.74 KB
/
choke.py
File metadata and controls
45 lines (37 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from typing import Final
from libecalc.domain.process.process_pipeline.process_error import OutsideCapacityError
from libecalc.domain.process.process_pipeline.process_unit import GasProcessUnit, ProcessUnitId
from libecalc.domain.process.value_objects.fluid_stream import FluidService, FluidStream
class Choke(GasProcessUnit):
def __init__(
self,
fluid_service: FluidService,
process_unit_id: ProcessUnitId | None = None,
pressure_change: float = 0.0,
):
self._id: Final[ProcessUnitId] = process_unit_id or GasProcessUnit._create_id()
self._pressure_change = pressure_change
self._fluid_service = fluid_service
def get_id(self) -> ProcessUnitId:
return self._id
@property
def pressure_change(self) -> float:
return self._pressure_change
def set_pressure_change(self, pressure_change: float) -> None:
if pressure_change < 0:
raise ValueError("Pressure_change cannot be negative")
self._pressure_change = pressure_change
def propagate_stream(self, inlet_stream: FluidStream) -> FluidStream:
if self._pressure_change > 0.0:
pressure_bara = inlet_stream.pressure_bara - self._pressure_change
if pressure_bara < 0.0:
raise OutsideCapacityError("Trying to choke to negative pressure.")
else:
# Delta pressure = 0, i.e. don't do anything
return inlet_stream
return self._fluid_service.create_stream_from_standard_rate(
fluid_model=inlet_stream.fluid_model,
pressure_bara=pressure_bara,
temperature_kelvin=inlet_stream.temperature_kelvin,
standard_rate_m3_per_day=inlet_stream.standard_rate_sm3_per_day,
)