Skip to content

Commit 750222f

Browse files
committed
Merge branch 'fix/#929-reactors-missing-powerconnection-adapters' into dev
2 parents 5e42ee4 + 38fe980 commit 750222f

4 files changed

Lines changed: 250 additions & 41 deletions

File tree

docs/whats_new/v0-9-14.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ Bug Fixes
1414
silent error because if not used, it did not do any trouble. Only when
1515
importing a :code:`Network` and reconstructing the component parameters the
1616
:code:`CharMap` could not be constructed successfully because it was missing
17-
dimensions (`PR #934 <https://github.com/oemof/tespy/pull/934>`__).
17+
dimensions (`PR #933 <https://github.com/oemof/tespy/pull/933>`__).
18+
- The reactor classes :code:`FuelCell` and :code:`WaterElectrolyzer` were
19+
missing the implementation for a :code:`PowerConnection`
20+
(`PR #934 <https://github.com/oemof/tespy/pull/934>`__).
1821

1922
Other Changes
2023
#############

src/tespy/components/reactors/fuel_cell.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def get_parameters(self):
214214
}
215215

216216
def get_mandatory_constraints(self):
217-
return {
217+
constraints = {
218218
'mass_flow_constraints': dc_cmc(**{
219219
'func': self.reactor_mass_flow_func,
220220
'deriv': self.reactor_mass_flow_deriv,
@@ -247,6 +247,14 @@ def get_mandatory_constraints(self):
247247
"description": "reactor pressure equality equations"
248248
})
249249
}
250+
if len(self.power_outl) > 0:
251+
constraints["energy_connector_balance"] = dc_cmc(**{
252+
"func": self.energy_connector_balance_func,
253+
"dependents": self.energy_connector_dependents,
254+
"num_eq_sets": 1
255+
})
256+
257+
return constraints
250258

251259
@staticmethod
252260
def get_bypass_constraints():
@@ -260,6 +268,10 @@ def inlets():
260268
def outlets():
261269
return ['out1', 'out2']
262270

271+
@staticmethod
272+
def poweroutlets():
273+
return ["power"]
274+
263275
def _add_missing_fluids(self, connections):
264276
if self.inl[1] in connections:
265277
return ["O2"]
@@ -325,6 +337,28 @@ def calc_e0(self):
325337

326338
return e0
327339

340+
def energy_connector_balance_func(self):
341+
r"""
342+
(optional) energy balance equation connecting the power connector to
343+
the component's power. Since the power of the FuelCell is negative by
344+
definition of the system, the two quantities are added in the residual
345+
so the power on the PowerConnection is positive again.
346+
347+
Returns
348+
-------
349+
residual : float
350+
Residual value of equation
351+
352+
.. math::
353+
354+
0=\dot E + P
355+
"""
356+
return self.power_outl[0].E.val_SI + self.P.val_SI
357+
358+
def energy_connector_dependents(self):
359+
return [self.power_outl[0].E, self.P]
360+
361+
328362
def eta_func(self):
329363
r"""
330364
Equation for efficiency.
@@ -454,7 +488,7 @@ def energy_balance_deriv(self, increment_filter, k, dependents=None):
454488

455489
# derivatives for variable P
456490
if self.P.is_var:
457-
self.jacobian[k, self.p.J_col] = 1
491+
self.jacobian[k, self.P.J_col] = 1
458492

459493
def energy_balance_dependents(self):
460494
return [

src/tespy/components/reactors/water_electrolyzer.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def get_parameters(self):
253253
}
254254

255255
def get_mandatory_constraints(self):
256-
return {
256+
constraints = {
257257
'mass_flow_constraints': dc_cmc(**{
258258
'func': self.reactor_mass_flow_func,
259259
'deriv': self.reactor_mass_flow_deriv,
@@ -291,6 +291,14 @@ def get_mandatory_constraints(self):
291291
"description": "equation for same temperature of product gases"
292292
})
293293
}
294+
if len(self.power_inl) > 0:
295+
constraints["energy_connector_balance"] = dc_cmc(**{
296+
"func": self.energy_connector_balance_func,
297+
"dependents": self.energy_connector_dependents,
298+
"num_eq_sets": 1
299+
})
300+
301+
return constraints
294302

295303
@staticmethod
296304
def get_bypass_constraints():
@@ -304,6 +312,10 @@ def inlets():
304312
def outlets():
305313
return ['out1', 'out2', 'out3']
306314

315+
@staticmethod
316+
def powerinlets():
317+
return ["power"]
318+
307319
def _add_missing_fluids(self, connections):
308320
if self.inl[1] in connections:
309321
return ["H2O"]
@@ -369,6 +381,25 @@ def calc_e0(self):
369381

370382
return e0
371383

384+
def energy_connector_balance_func(self):
385+
r"""
386+
(optional) energy balance equation connecting the power connector to
387+
the component's power
388+
389+
Returns
390+
-------
391+
residual : float
392+
Residual value of equation
393+
394+
.. math::
395+
396+
0=\dot E - P
397+
"""
398+
return self.power_inl[0].E.val_SI - self.P.val_SI
399+
400+
def energy_connector_dependents(self):
401+
return [self.power_inl[0].E, self.P]
402+
372403
def gas_temperature_func(self):
373404
r"""
374405
Equation for temperature equality of product gases.

0 commit comments

Comments
 (0)