...
 
Commits (2)
......@@ -38,10 +38,10 @@ consumption and storage unit will inherit from it.**
- SeveralEnergyUnit: Energy unit based on a fixed power curve enabling to
multiply several times (nb_unit) the same power curve.
- AssemblyEnergyUnit: assembly units have at least a production unit
and a consumption unit and are using one or several energy types. It
inherits from OptObject and is the parent class of ConversionUnit and
ReversibleUnit.
- AssemblyUnit: assembly units have at least a production unit
and a consumption unit and they are using one or several energy types. It
can also integrate reversible energy units. It inherits from OptObject and it
is the parent class of ConversionUnit and ReversibleUnit.
..
Copyright 2018 G2Elab / MAGE
......@@ -70,6 +70,7 @@ from ...general.optimisation.elements import Quantity, Constraint, \
from ...general.optimisation.core import OptObject
from .production_units import ProductionUnit
from .consumption_units import ConsumptionUnit
from .reversible_units import ReversibleUnit
__docformat__ = "restructuredtext en"
......@@ -1035,7 +1036,10 @@ class AssemblyUnit(OptObject):
"""
**Description**
Simple Assembly unit
Simple Assembly unit: assembly units have at least a production unit
and a consumption unit and they are using one or several energy types. It
can also integrate reversible energy units. It inherits from OptObject and it
is the parent class of ConversionUnit and ReversibleUnit.
**Attributes**
......@@ -1047,7 +1051,7 @@ class AssemblyUnit(OptObject):
"""
def __init__(self, time, name, prod_units=None, cons_units=None,
verbose=True):
rev_units=None, verbose=True):
OptObject.__init__(self, name=name, description='Assembly unit',
verbose=verbose)
......@@ -1056,10 +1060,12 @@ class AssemblyUnit(OptObject):
# production units
self.cons_units = [] # Initialize an empty list for the consumption
# units
self.rev_units = [] # Initialize an empty list for the reversible
# units
self.poles = {} # Initialize an empty dictionary for the poles
# An assembly unit is created with at least a production unit and a
# consumption unit
# consumption unit, and can integrate reversible unit.
if not prod_units:
raise IndexError('You have to fill at least a production unit.')
elif not isinstance(prod_units, list):
......@@ -1086,6 +1092,18 @@ class AssemblyUnit(OptObject):
else:
self._add_consumption_unit(cons_unit)
# Assembly units can integrate reversible units.
if not (rev_units is None or isinstance(rev_units, list)):
raise TypeError('rev_units should be a list or None.')
else:
for rev_unit in rev_units:
# rev_units should only contain ReversibleUnit objects
if not isinstance(rev_unit, ReversibleUnit):
raise TypeError('The elements in rev_units have to be the'
' type "ReversibleUnit".')
else:
self._add_reversible_unit(rev_unit)
def _add_production_unit(self, prod_unit):
"""
:param prod_unit: production unit to be added to the
......@@ -1113,3 +1131,20 @@ class AssemblyUnit(OptObject):
else:
print('Consumption unit {0} already in the consumption_units '
'list'.format(cons_unit.name))
def _add_reversible_unit(self, rev_unit):
"""
:param rev_unit: reversible unit to be added to the
reversible_units list
"""
if rev_unit not in self.rev_units:
poles_nb = len(self.poles)
# Adding the various poles of the reversible_unit to the
# assembly_unit.
for p in range(1, len(rev_unit.poles) + 1):
self.poles[poles_nb + p] = rev_unit.poles[p]
self.rev_units.append(rev_unit)
rev_unit.parent = self
else:
print('Reversible unit {0} already in the reversible_units list'
.format(rev_unit.name))