Skip to content

Commit ad896fc

Browse files
committed
refactor: pass fluid_service to SimplifiedStreamMixer in __init__
- Remove unnecessary @DataClass(frozen=True) decorator - Convert mix_streams from static method to instance method - Update Mixer to create SimplifiedStreamMixer instance - Update tests to use new instance-based API
1 parent fe7d83b commit ad896fc

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/libecalc/domain/process/entities/process_units/mixer/mixer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Mixer:
88
def __init__(self, number_of_inputs: int, fluid_service: FluidService):
99
self.number_of_inputs = number_of_inputs
10-
self.fluid_service = fluid_service
10+
self._stream_mixer = SimplifiedStreamMixer(fluid_service)
1111

1212
def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
1313
"""
@@ -22,4 +22,4 @@ def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
2222
if self.number_of_inputs != len(streams):
2323
raise ValueError("Number of input streams must match the number of inputs defined for the mixer.")
2424

25-
return SimplifiedStreamMixer.mix_streams(streams=streams, fluid_service=self.fluid_service)
25+
return self._stream_mixer.mix_streams(streams=streams)

src/libecalc/domain/process/entities/process_units/simplified_stream_mixer/simplified_stream_mixer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections import defaultdict
2-
from dataclasses import dataclass
32

43
from libecalc.domain.process.value_objects.fluid_stream import FluidService, FluidStream
54
from libecalc.domain.process.value_objects.fluid_stream.exceptions import (
@@ -12,7 +11,6 @@
1211

1312

1413
# TODO: Use enthalpy balance instead of simplified mixing?
15-
@dataclass(frozen=True)
1614
class SimplifiedStreamMixer:
1715
"""Process unit for mixing multiple fluid streams.
1816
@@ -24,13 +22,14 @@ class SimplifiedStreamMixer:
2422
Note: This method is most appropriate when mixing streams with similar temperatures.
2523
"""
2624

27-
@staticmethod
28-
def mix_streams(streams: list[FluidStream], fluid_service: FluidService) -> FluidStream:
25+
def __init__(self, fluid_service: FluidService):
26+
self._fluid_service = fluid_service
27+
28+
def mix_streams(self, streams: list[FluidStream]) -> FluidStream:
2929
"""Mix multiple streams using component-wise molar balance.
3030
3131
Args:
3232
streams: List of streams to mix (must have same EoS model)
33-
fluid_service: Service for performing flash operations
3433
3534
Returns:
3635
A new FluidStream representing the mixed stream
@@ -83,7 +82,7 @@ def mix_streams(streams: list[FluidStream], fluid_service: FluidService) -> Flui
8382
)
8483

8584
# Get properties at mixed conditions via fluid service
86-
mix_props = fluid_service.flash_pt(
85+
mix_props = self._fluid_service.flash_pt(
8786
fluid_model=mix_fluid_model,
8887
pressure_bara=reference_pressure,
8988
temperature_kelvin=temperature_mix,

tests/libecalc/domain/process/entities/process_units/test_stream_mixer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_mix_medium_and_ultra_rich_compositions(self, medium_composition, ultra_
4444
ultra_rich_stream = FluidStream(fluid=ultra_rich_fluid, mass_rate_kg_per_h=mass_rate_ultra_rich)
4545

4646
# Mix streams using StreamMixer
47-
mixed_stream = SimplifiedStreamMixer.mix_streams([medium_stream, ultra_rich_stream], fluid_service=service)
47+
mixer = SimplifiedStreamMixer(fluid_service=service)
48+
mixed_stream = mixer.mix_streams([medium_stream, ultra_rich_stream])
4849

4950
# Expected values from mixing medium (30%) and ultra rich (70%) compositions
5051
expected_values = {
@@ -88,7 +89,8 @@ def test_mix_streams_with_different_conditions(self, medium_composition):
8889
stream2 = FluidStream(fluid=fluid2, mass_rate_kg_per_h=500.0)
8990

9091
# Mix streams
91-
mixed_stream = SimplifiedStreamMixer.mix_streams([stream1, stream2], fluid_service=service)
92+
mixer = SimplifiedStreamMixer(fluid_service=service)
93+
mixed_stream = mixer.mix_streams([stream1, stream2])
9294

9395
# Verify the mixed stream uses the simplified mass-weighted average temperature and lowest pressure
9496
expected_temperature = (
@@ -123,4 +125,5 @@ def test_mix_streams_with_different_eos_models(self, medium_composition):
123125
stream2 = FluidStream(fluid=pr_fluid, mass_rate_kg_per_h=500.0)
124126

125127
with pytest.raises(IncompatibleEoSModelsException):
126-
SimplifiedStreamMixer.mix_streams([stream1, stream2], fluid_service=service)
128+
mixer = SimplifiedStreamMixer(fluid_service=service)
129+
mixer.mix_streams([stream1, stream2])

0 commit comments

Comments
 (0)