| Conditions | 7 |
| Total Lines | 78 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 - |
||
| 138 | def _create(self, group=None): |
||
| 139 | """Creates the linear constraint for the |
||
| 140 | :class:`oemof.solph.components.TransformerBlock` block. |
||
| 141 | |||
| 142 | Parameters |
||
| 143 | ---------- |
||
| 144 | group : list |
||
| 145 | List of :class:`oemof.solph.components.ExtractionTurbineCHP` |
||
| 146 | (trsf) objects for which the linear relation of inputs and outputs |
||
| 147 | is created e.g. group = [trsf1, trsf2, trsf3, ...]. Note that the |
||
| 148 | relation is created for all existing relations of the inputs and |
||
| 149 | all outputs of the transformer. The components inside the list need |
||
| 150 | to hold all needed attributes. |
||
| 151 | """ |
||
| 152 | if group is None: |
||
| 153 | return None |
||
| 154 | |||
| 155 | m = self.parent_block() |
||
| 156 | |||
| 157 | for n in group: |
||
| 158 | n.inflow = list(n.inputs)[0] |
||
| 159 | n.main_flow = [ |
||
| 160 | k for k, v in n.conversion_factor_full_condensation.items() |
||
| 161 | ][0] |
||
| 162 | n.main_output = [o for o in n.outputs if n.main_flow == o][0] |
||
| 163 | n.tapped_output = [o for o in n.outputs if n.main_flow != o][0] |
||
| 164 | n.conversion_factor_full_condensation_sq = ( |
||
| 165 | n.conversion_factor_full_condensation[n.main_output] |
||
| 166 | ) |
||
| 167 | n.flow_relation_index = [ |
||
| 168 | n.conversion_factors[n.main_output][t] |
||
| 169 | / n.conversion_factors[n.tapped_output][t] |
||
| 170 | for t in m.TIMESTEPS |
||
| 171 | ] |
||
| 172 | n.main_flow_loss_index = [ |
||
| 173 | ( |
||
| 174 | n.conversion_factor_full_condensation_sq[t] |
||
| 175 | - n.conversion_factors[n.main_output][t] |
||
| 176 | ) |
||
| 177 | / n.conversion_factors[n.tapped_output][t] |
||
| 178 | for t in m.TIMESTEPS |
||
| 179 | ] |
||
| 180 | |||
| 181 | def _input_output_relation_rule(block): |
||
| 182 | """Connection between input, main output and tapped output.""" |
||
| 183 | for t in m.TIMESTEPS: |
||
|
|
|||
| 184 | for g in group: |
||
| 185 | lhs = m.flow[g.inflow, g, t] |
||
| 186 | rhs = ( |
||
| 187 | m.flow[g, g.main_output, t] |
||
| 188 | + m.flow[g, g.tapped_output, t] |
||
| 189 | * g.main_flow_loss_index[t] |
||
| 190 | ) / g.conversion_factor_full_condensation_sq[t] |
||
| 191 | block.input_output_relation.add((g, t), (lhs == rhs)) |
||
| 192 | |||
| 193 | self.input_output_relation = Constraint( |
||
| 194 | group, m.TIMESTEPS, noruleinit=True |
||
| 195 | ) |
||
| 196 | self.input_output_relation_build = BuildAction( |
||
| 197 | rule=_input_output_relation_rule |
||
| 198 | ) |
||
| 199 | |||
| 200 | def _out_flow_relation_rule(block): |
||
| 201 | """Relation between main and tapped output in full chp mode.""" |
||
| 202 | for t in m.TIMESTEPS: |
||
| 203 | for g in group: |
||
| 204 | lhs = m.flow[g, g.main_output, t] |
||
| 205 | rhs = ( |
||
| 206 | m.flow[g, g.tapped_output, t] |
||
| 207 | * g.flow_relation_index[t] |
||
| 208 | ) |
||
| 209 | block.out_flow_relation.add((g, t), (lhs >= rhs)) |
||
| 210 | |||
| 211 | self.out_flow_relation = Constraint( |
||
| 212 | group, m.TIMESTEPS, noruleinit=True |
||
| 213 | ) |
||
| 214 | self.out_flow_relation_build = BuildAction( |
||
| 215 | rule=_out_flow_relation_rule |
||
| 216 | ) |
||
| 217 |