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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.6] - 2025-07-30

### Changed
- `Sink`, `Source` and `SourceAndSink` now accept multiple `flows` as `inputs` and `outputs` instead of just one. This enables to model more use cases using these classes.
- Further, both `Sink` and `Source` now have a `prevent_simultaneous_flow_rates` argument to prevent simultaneous flow rates of more than one of their Flows.

### Deprecated
- For the classes `Sink`, `Source` and `SourceAndSink`: `.sink`, `.source` and `.prevent_simultaneous_sink_and_source` are deprecated in favor of the new arguments `inputs`, `outputs` and `prevent_simultaneous_flow_rates`.

## [2.1.5] - 2025-07-08

### Fixed
Expand Down
1 change: 0 additions & 1 deletion flixopt/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
if TYPE_CHECKING:
import plotly.graph_objects as go

warnings.filterwarnings('ignore', category=DeprecationWarning)
logger = logging.getLogger('flixopt')


Expand Down
151 changes: 130 additions & 21 deletions flixopt/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import logging
import warnings
from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Set, Tuple, Union

import linopy
Expand Down Expand Up @@ -586,52 +587,160 @@ class for source (output-flow) and sink (input-flow) in one commponent
def __init__(
self,
label: str,
source: Flow,
sink: Flow,
prevent_simultaneous_sink_and_source: bool = True,
inputs: List[Flow] = None,
outputs: List[Flow] = None,
prevent_simultaneous_flow_rates: bool = True,
meta_data: Optional[Dict] = None,
**kwargs,
):
"""
Args:
label: The label of the Element. Used to identify it in the FlowSystem
source: output-flow of this component
sink: input-flow of this component
prevent_simultaneous_sink_and_source: If True, inflow and outflow can not be active simultaniously.
outputs: output-flows of this component
inputs: input-flows of this component
prevent_simultaneous_flow_rates: If True, inflow and outflow can not be active simultaniously.
meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types.
"""
source = kwargs.pop('source', None)
sink = kwargs.pop('sink', None)
prevent_simultaneous_sink_and_source = kwargs.pop('prevent_simultaneous_sink_and_source', None)
if source is not None:
warnings.deprecated(
'The use of the source argument is deprecated. Use the outputs argument instead.',
stacklevel=2,
)
if outputs is not None:
raise ValueError('Either source or outputs can be specified, but not both.')
outputs = [source]

if sink is not None:
warnings.deprecated(
'The use of the sink argument is deprecated. Use the outputs argument instead.',
stacklevel=2,
)
if inputs is not None:
raise ValueError('Either sink or outputs can be specified, but not both.')
inputs = [sink]

if prevent_simultaneous_sink_and_source is not None:
warnings.deprecated(
'The use of the prevent_simultaneous_sink_and_source argument is deprecated. Use the prevent_simultaneous_flow_rates argument instead.',
stacklevel=2,
)
prevent_simultaneous_flow_rates = prevent_simultaneous_sink_and_source

super().__init__(
label,
inputs=[sink],
outputs=[source],
prevent_simultaneous_flows=[sink, source] if prevent_simultaneous_sink_and_source is True else None,
inputs=inputs,
outputs=outputs,
prevent_simultaneous_flows=inputs + outputs if prevent_simultaneous_flow_rates is True else None,
meta_data=meta_data,
)
self.source = source
self.sink = sink
self.prevent_simultaneous_sink_and_source = prevent_simultaneous_sink_and_source
self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates

@property
def source(self) -> Flow:
warnings.warn(
'The source property is deprecated. Use the outputs property instead.',
DeprecationWarning,
stacklevel=2,
)
return self.outputs[0]

@property
def sink(self) -> Flow:
warnings.warn(
'The sink property is deprecated. Use the outputs property instead.',
DeprecationWarning,
stacklevel=2,
)
return self.inputs[0]

@property
def prevent_simultaneous_sink_and_source(self) -> bool:
warnings.warn(
'The prevent_simultaneous_sink_and_source property is deprecated. Use the prevent_simultaneous_flow_rates property instead.',
DeprecationWarning,
stacklevel=2,
)
return self.prevent_simultaneous_flow_rates


@register_class_for_io
class Source(Component):
def __init__(self, label: str, source: Flow, meta_data: Optional[Dict] = None):
def __init__(
self,
label: str,
outputs: List[Flow] = None,
meta_data: Optional[Dict] = None,
prevent_simultaneous_flow_rates: bool = False,
**kwargs
):
"""
Args:
label: The label of the Element. Used to identify it in the FlowSystem
source: output-flow of source
outputs: output-flows of source
meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types.
"""
super().__init__(label, outputs=[source], meta_data=meta_data)
self.source = source
source = kwargs.pop('source', None)
if source is not None:
warnings.warn(
'The use of the source argument is deprecated. Use the outputs argument instead.',
DeprecationWarning,
stacklevel=2,
)
if outputs is not None:
raise ValueError('Either source or outputs can be specified, but not both.')
outputs = [source]

self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates
super().__init__(label, outputs=outputs, meta_data=meta_data, prevent_simultaneous_flows=outputs if prevent_simultaneous_flow_rates else None)

@property
def source(self) -> Flow:
warnings.warn(
'The source property is deprecated. Use the outputs property instead.',
DeprecationWarning,
stacklevel=2,
)
return self.outputs[0]


@register_class_for_io
class Sink(Component):
def __init__(self, label: str, sink: Flow, meta_data: Optional[Dict] = None):
def __init__(
self,
label: str,
inputs: List[Flow] = None,
meta_data: Optional[Dict] = None,
prevent_simultaneous_flow_rates: bool = False,
**kwargs
):
"""
Args:
label: The label of the Element. Used to identify it in the FlowSystem
meta_data: used to store more information about the element. Is not used internally, but saved in the results
sink: input-flow of sink
inputs: output-flows of source
meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types.
"""
super().__init__(label, inputs=[sink], meta_data=meta_data)
self.sink = sink
sink = kwargs.pop('sink', None)
if sink is not None:
warnings.warn(
'The use of the sink argument is deprecated. Use the outputs argument instead.',
DeprecationWarning,
stacklevel=2,
)
if inputs is not None:
raise ValueError('Either sink or outputs can be specified, but not both.')
inputs = [sink]

self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates
super().__init__(label, inputs=inputs, meta_data=meta_data, prevent_simultaneous_flows=inputs if prevent_simultaneous_flow_rates else None)

@property
def sink(self) -> Flow:
warnings.warn(
'The sink property is deprecated. Use the outputs property instead.',
DeprecationWarning,
stacklevel=2,
)
return self.inputs[0]