Passed
Pull Request — dev (#1193)
by Uwe
01:43
created

facade.DSO.define_subnetwork()   A

Complexity

Conditions 1

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 27
rs 9.45
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
3
"""
4
General description
5
-------------------
6
7
A basic example to show how to get the dual variables from the system. Try
8
to understand the plot.
9
10
Code
11
----
12
Download source code: :download:`dual_variable_example.py </../examples/dual_variable_example/dual_variable_example.py>`
13
14
.. dropdown:: Click to display code
15
16
    .. literalinclude:: /../examples/dual_variable_example/dual_variable_example.py
17
        :language: python
18
        :lines: 34-297
19
20
21
Installation requirements
22
-------------------------
23
24
This example requires the version v0.6.x of oemof.solph:
25
26
.. code:: bash
27
28
    pip install 'oemof.solph[examples]>=0.6,<0.7'
29
30
SPDX-FileCopyrightText: Uwe Krien <[email protected]>
31
SPDX-FileCopyrightText: Pierre-François Duc
32
33
SPDX-License-Identifier: MIT
34
"""
35
36
from oemof.solph.components import Converter, Source, Sink
37
from oemof.solph.flows import Flow
38
from oemof.solph.buses import Bus
39
40
from oemof.solph._facades import Facade
41
42
43
class DSO(Facade):
44
    def __init__(self, label, el_bus, *args, energy_price, feedin_tariff):
45
        self.energy_price = energy_price
46
        self.feedin_tariff = feedin_tariff
47
        self.el_bus = el_bus
48
        super().__init__(*args, label=label, facade_type=type(self))
49
50
    def define_subnetwork(self):
51
        internal_bus = Bus(label=self.sub_component_labelling("internal_bus"))
52
53
        feedin = Converter(
54
            inputs={self.el_bus: Flow(variable_costs=self.feedin_tariff * -1)},
55
            outputs={internal_bus: Flow()},
56
            label=self.sub_component_labelling(
57
                "feedin_converter", interface=True
58
            ),
59
        )
60
        sink = Sink(
61
            inputs={internal_bus: Flow()},
62
            label=self.sub_component_labelling("feedin_sink"),
63
        )
64
65
        consumption = Converter(
66
            inputs={internal_bus: Flow()},
67
            outputs={self.el_bus: Flow(variable_costs=self.energy_price)},
68
            label=self.sub_component_labelling(
69
                "consumption_converter", interface=True
70
            ),
71
        )
72
        source = Source(
73
            outputs={internal_bus: Flow()},
74
            label=self.sub_component_labelling("consumption_source"),
75
        )
76
        self.subnodes.extend([source, consumption, sink, feedin, internal_bus])
77
78
79
# class CriticalDemand(Facade):
80
#     """
81
#     Defines a non dispatchable sink to serve critical and non-critical demand.
82
#
83
#     See :py:func:`~.sink` for more information, including parameters.
84
#
85
#     Notes
86
#     -----
87
#     Tested with:
88
#     - test_sink_non_dispatchable_single_input_bus()
89
#     - test_sink_non_dispatchable_multiple_input_busses()
90
#
91
#     Returns
92
#     -------
93
#     Indirectly updated `model` and dict of asset in `kwargs` with the sink
94
#     object.
95
#
96
#     """
97
#
98
#     # sink_non_dispatchable(model, dict_asset, **kwargs)
99
#
100
#     def __init__(
101
#         self, name, el_bus, demand_reduction_factor, total_demand, *args
102
#     ):
103
#         super().__init__(*args, name=name)
104
#         self.facade_type = "dso"
105
#         self.demand_reduction_factor = demand_reduction_factor
106
#         self.total_demand = total_demand
107
#
108
#         self.el_bus = el_bus
109
#
110
#     def build_subnetwork(self):
111
#
112
#         demand_reduction_factor = 1 - dict_asset[EFFICIENCY][VALUE]
113
#         tot_demand = dict_asset[TIMESERIES]
114
#         non_critical_demand_ts = tot_demand * demand_reduction_factor
115
#         non_critical_demand_peak = non_critical_demand_ts.max()
116
#         if non_critical_demand_peak == 0:
117
#             max_non_critical = 1
118
#         else:
119
#             max_non_critical = (
120
#                 non_critical_demand_ts / non_critical_demand_peak
121
#             )
122
#         critical_demand_ts = tot_demand * dict_asset[EFFICIENCY][VALUE]
123
#
124
#         # # check if the sink has multiple input busses
125
#         # if isinstance(dict_asset[INFLOW_DIRECTION], list):
126
#         #     pass
127
#         #     # inputs_noncritical = {}
128
#         #     # inputs_critical = {}
129
#         #     # index = 0
130
#         #     # for bus in dict_asset[INFLOW_DIRECTION]:
131
#         #     #     inputs_critical[kwargs[OEMOF_BUSSES][bus]] = solph.Flow(
132
#         #     #         fix=dict_asset[TIMESERIES], nominal_value=1
133
#         #     #     )
134
#         #     #     index += 1
135
#         # else:
136
#         #     inputs_noncritical = {
137
#         #         kwargs[OEMOF_BUSSES][dict_asset[INFLOW_DIRECTION]]: solph.Flow(
138
#         #             min=0,
139
#         #             max=max_non_critical,
140
#         #             nominal_value=non_critical_demand_peak,
141
#         #             variable_costs=-1e-15,
142
#         #         )
143
#         #     }
144
#         #     inputs_critical = {
145
#         #         kwargs[OEMOF_BUSSES][dict_asset[INFLOW_DIRECTION]]: solph.Flow(
146
#         #             fix=critical_demand_ts, nominal_value=1
147
#         #         )
148
#         #     }
149
#
150
#         non_critical_demand = Sink(
151
#             inputs={
152
#                 self.el_bus: Flow(
153
#                     min=0,
154
#                     max=max_non_critical,
155
#                     nominal_value=non_critical_demand_peak,
156
#                     variable_costs=-1e-15,
157
#                 )
158
#             },
159
#         )
160
#         critical_demand = solph.components.Sink(
161
#             label=reducable_demand_name(dict_asset[LABEL], critical=True),
162
#             inputs=inputs_critical,
163
#         )
164
#
165
#         # create and add demand sink and critical demand sink
166
#
167
#         model.add(critical_demand)
168
#         model.add(non_critical_demand)
169
#         kwargs[OEMOF_SINK].update(
170
#             {reducable_demand_name(dict_asset[LABEL]): non_critical_demand}
171
#         )
172
#         kwargs[OEMOF_SINK].update(
173
#             {
174
#                 reducable_demand_name(
175
#                     dict_asset[LABEL], critical=True
176
#                 ): critical_demand
177
#             }
178
#         )
179
#         logging.debug(
180
#             f"Added: Reducable Non-dispatchable sink {dict_asset[LABEL]} to bus {dict_asset[INFLOW_DIRECTION]}"
181
#         )
182