Skip to content

Commit

Permalink
refactor: consumer system v2 types
Browse files Browse the repository at this point in the history
  • Loading branch information
jsolaas committed Oct 22, 2024
1 parent d8f28ab commit a7177b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/libecalc/core/consumers/base/component.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC, abstractmethod
from typing import List

from libecalc.common.stream_conditions import TimeSeriesStreamConditions
from libecalc.common.utils.rates import TimeSeriesFloat
from libecalc.common.variables import ExpressionEvaluator
from libecalc.core.result import EcalcModelResult
from libecalc.domain.stream_conditions import StreamConditions


class BaseConsumer(ABC):
Expand All @@ -20,9 +20,7 @@ class BaseConsumerWithoutOperationalSettings(ABC):
id: str

@abstractmethod
def get_max_rate(
self, inlet_stream: TimeSeriesStreamConditions, target_pressure: TimeSeriesFloat
) -> List[float]: ...
def get_max_rate(self, inlet_stream: StreamConditions, target_pressure: TimeSeriesFloat) -> List[float]: ...

@abstractmethod
def evaluate(self, **kwargs) -> EcalcModelResult: ...
def evaluate(self, streams: List[StreamConditions]) -> EcalcModelResult: ...
17 changes: 7 additions & 10 deletions src/libecalc/core/consumers/consumer_system.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import itertools
import operator
from functools import reduce
from typing import Dict, List, Optional, Protocol, Tuple, TypeVar, Union
from typing import Dict, Generic, List, Optional, Protocol, Tuple, TypeVar

import networkx as nx

from libecalc.common.priority_optimizer import EvaluatorResult
from libecalc.common.utils.rates import (
TimeSeriesInt,
)
from libecalc.core.consumers.compressor import Compressor
from libecalc.core.consumers.pump import Pump
from libecalc.core.consumers.base import BaseConsumerWithoutOperationalSettings
from libecalc.core.result import ComponentResult, ConsumerSystemResult, EcalcModelResult
from libecalc.domain.stream_conditions import Rate, StreamConditions

Consumer = TypeVar("Consumer", bound=Union[Compressor, Pump])
Consumer = TypeVar("Consumer", bound=BaseConsumerWithoutOperationalSettings)


class Crossover(Protocol):
Expand All @@ -27,7 +26,7 @@ class SystemComponentConditions(Protocol):
crossover: List[Crossover]


class ConsumerSystem:
class ConsumerSystem(Generic[Consumer]):
"""
A system of possibly interdependent consumers and or other consumer systems.
Expand All @@ -37,9 +36,7 @@ class ConsumerSystem:
for a period of time -> Turn of compressor #2, and vice versa.
"""

def __init__(
self, id: str, consumers: List[Union[Compressor, Pump]], component_conditions: SystemComponentConditions
):
def __init__(self, id: str, consumers: List[Consumer], component_conditions: SystemComponentConditions):
self.id = id
self._consumers = consumers
self._component_conditions = component_conditions
Expand Down Expand Up @@ -76,8 +73,8 @@ def _get_stream_conditions_adjusted_for_crossover(
if has_crossover_out:
# TODO: Mix inlet streams and check pressure? Is consumer a Compressor or Pump or should it actually be trains also? Currently it is trains also.
max_rate = consumer.get_max_rate(
inlet_stream=inlet_streams[0],
target_pressure=consumer_stream_conditions[-1].pressure,
inlet_stream=inlet_streams[0], # First inlet stream
target_pressure=consumer_stream_conditions[-1].pressure, # Outlet stream pressure
)
crossover_stream, inlet_streams = ConsumerSystem._get_crossover_stream(
max_rate,
Expand Down

0 comments on commit a7177b1

Please sign in to comment.