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

facade.DSO.__init__()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nop 6
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
        super().__init__(*args, label=label)
46
        self.facade_type = "dso"
47
        self.energy_price = energy_price
48
        self.feedin_tariff = feedin_tariff
49
50
        self.el_bus = el_bus
51
52
    def build_subnetwork(self):
53
        internal_bus = Bus(label="internal_bus")
54
        self.add_subnode(internal_bus)
55
56
        feedin = Converter(
57
            inputs={self.el_bus: Flow(variable_costs=self.feedin_tariff)},
58
            outputs={internal_bus: Flow()},
59
            label="feedin_converter",
60
        )
61
        sink = Sink(inputs={internal_bus: Flow()}, label="feedin_sink")
62
        self.add_subnode(sink, feedin)
63
64
        bus_c = Bus()
65
        consumption = Converter(
66
            inputs={bus_c: Flow()},
67
            outputs={self.el_bus: Flow(variable_costs=self.energy_price)},
68
            label="consumption_converter",
69
        )
70
        source = Source(
71
            outputs={internal_bus: Flow()}, label="consumption_sink"
72
        )
73
        self.add_subnode(source, consumption)
74
75
76
# class CriticalDemand(Facade):
77
#     """
78
#     Defines a non dispatchable sink to serve critical and non-critical demand.
79
#
80
#     See :py:func:`~.sink` for more information, including parameters.
81
#
82
#     Notes
83
#     -----
84
#     Tested with:
85
#     - test_sink_non_dispatchable_single_input_bus()
86
#     - test_sink_non_dispatchable_multiple_input_busses()
87
#
88
#     Returns
89
#     -------
90
#     Indirectly updated `model` and dict of asset in `kwargs` with the sink
91
#     object.
92
#
93
#     """
94
#
95
#     # sink_non_dispatchable(model, dict_asset, **kwargs)
96
#
97
#     def __init__(
98
#         self, name, el_bus, demand_reduction_factor, total_demand, *args
99
#     ):
100
#         super().__init__(*args, name=name)
101
#         self.facade_type = "dso"
102
#         self.demand_reduction_factor = demand_reduction_factor
103
#         self.total_demand = total_demand
104
#
105
#         self.el_bus = el_bus
106
#
107
#     def build_subnetwork(self):
108
#
109
#         demand_reduction_factor = 1 - dict_asset[EFFICIENCY][VALUE]
110
#         tot_demand = dict_asset[TIMESERIES]
111
#         non_critical_demand_ts = tot_demand * demand_reduction_factor
112
#         non_critical_demand_peak = non_critical_demand_ts.max()
113
#         if non_critical_demand_peak == 0:
114
#             max_non_critical = 1
115
#         else:
116
#             max_non_critical = (
117
#                 non_critical_demand_ts / non_critical_demand_peak
118
#             )
119
#         critical_demand_ts = tot_demand * dict_asset[EFFICIENCY][VALUE]
120
#
121
#         # # check if the sink has multiple input busses
122
#         # if isinstance(dict_asset[INFLOW_DIRECTION], list):
123
#         #     pass
124
#         #     # inputs_noncritical = {}
125
#         #     # inputs_critical = {}
126
#         #     # index = 0
127
#         #     # for bus in dict_asset[INFLOW_DIRECTION]:
128
#         #     #     inputs_critical[kwargs[OEMOF_BUSSES][bus]] = solph.Flow(
129
#         #     #         fix=dict_asset[TIMESERIES], nominal_value=1
130
#         #     #     )
131
#         #     #     index += 1
132
#         # else:
133
#         #     inputs_noncritical = {
134
#         #         kwargs[OEMOF_BUSSES][dict_asset[INFLOW_DIRECTION]]: solph.Flow(
135
#         #             min=0,
136
#         #             max=max_non_critical,
137
#         #             nominal_value=non_critical_demand_peak,
138
#         #             variable_costs=-1e-15,
139
#         #         )
140
#         #     }
141
#         #     inputs_critical = {
142
#         #         kwargs[OEMOF_BUSSES][dict_asset[INFLOW_DIRECTION]]: solph.Flow(
143
#         #             fix=critical_demand_ts, nominal_value=1
144
#         #         )
145
#         #     }
146
#
147
#         non_critical_demand = Sink(
148
#             inputs={
149
#                 self.el_bus: Flow(
150
#                     min=0,
151
#                     max=max_non_critical,
152
#                     nominal_value=non_critical_demand_peak,
153
#                     variable_costs=-1e-15,
154
#                 )
155
#             },
156
#         )
157
#         critical_demand = solph.components.Sink(
158
#             label=reducable_demand_name(dict_asset[LABEL], critical=True),
159
#             inputs=inputs_critical,
160
#         )
161
#
162
#         # create and add demand sink and critical demand sink
163
#
164
#         model.add(critical_demand)
165
#         model.add(non_critical_demand)
166
#         kwargs[OEMOF_SINK].update(
167
#             {reducable_demand_name(dict_asset[LABEL]): non_critical_demand}
168
#         )
169
#         kwargs[OEMOF_SINK].update(
170
#             {
171
#                 reducable_demand_name(
172
#                     dict_asset[LABEL], critical=True
173
#                 ): critical_demand
174
#             }
175
#         )
176
#         logging.debug(
177
#             f"Added: Reducable Non-dispatchable sink {dict_asset[LABEL]} to bus {dict_asset[INFLOW_DIRECTION]}"
178
#         )
179