Skip to content

Energysystem

EnEnergysystem

Bases: EnBaseModel

Represents an energy system model, encapsulating multiple components such as buses, sinks, sources, converters, storages, and constraints. This class provides methods to add components to the energy system and to convert it into a compatible format for integration with the oemof library.

Designed to handle different types of energy system elements, each of which is stored in its respective categorized list. The class allows for integration with external energy system processing tools by supporting the transformation of its components.

Attributes:

Name Type Description
busses list[EnBus]

List of all buses in the energy system.

sinks list[EnSink]

List of all sinks in the energy system.

sources list[EnSource]

List of all sources in the energy system.

converters list[EnConverter]

List of all converters in the energy system.

generic_storages list[EnGenericStorage]

List of all generic storages in the energy system.

constraints list[EnConstraints]

List of all constraints in the energy system.

Source code in backend/app/ensys/components/energysystem.py
class EnEnergysystem(EnBaseModel):
    """
    Represents an energy system model, encapsulating multiple components such as buses,
    sinks, sources, converters, storages, and constraints. This class provides methods
    to add components to the energy system and to convert it into a compatible format
    for integration with the oemof library.

    Designed to handle different types of energy system elements, each of which is
    stored in its respective categorized list. The class allows for integration with
    external energy system processing tools by supporting the transformation of its
    components.

    :ivar busses: List of all buses in the energy system.
    :type busses: list[EnBus]
    :ivar sinks: List of all sinks in the energy system.
    :type sinks: list[EnSink]
    :ivar sources: List of all sources in the energy system.
    :type sources: list[EnSource]
    :ivar converters: List of all converters in the energy system.
    :type converters: list[EnConverter]
    :ivar generic_storages: List of all generic storages in the energy system.
    :type generic_storages: list[EnGenericStorage]
    :ivar constraints: List of all constraints in the energy system.
    :type constraints: list[EnConstraints]
    """
    busses: list[EnBus] = Field(
        default=[],
        title='Busses',
        description='List of all busses.'
    )

    sinks: list[EnSink] = Field(
        default=[],
        title='Sinks',
        description='List of all sinks.'
    )

    sources: list[EnSource] = Field(
        default=[],
        title='Sources',
        description='List of all sources.'
    )

    converters: list[EnConverter] = Field(
        default=[],
        title='Converters',
        description='List of all converters.'
    )

    generic_storages: list[EnGenericStorage] = Field(
        default=[],
        title='Generic Storages',
        description='List of all generic storages.'
    )

    constraints: list[EnConstraints] = Field(
        default=[],
        title='Constraints',
        description='List of all constraints.'
    )

    def add(self, elem: EnSink | EnSource | EnBus | EnGenericStorage | EnConverter | EnConstraints):
        """
        Adds an element to the corresponding list based on its type. Determines
        the type of the given element and appends it to its respective
        container (e.g., sinks, sources, busses, etc.). Raises an exception
        if the type of the element is not recognized.

        :param elem: The element to be added. It should be one of the following
                     types: EnSink, EnSource, EnBus, EnGenericStorage,
                     EnConverter, or EnConstraints.
        :type elem: EnSink | EnSource | EnBus | EnGenericStorage | EnConverter | EnConstraints
        :return: None
        """
        if type(elem) is EnSink:
            self.sinks.append(elem)
        elif type(elem) is EnSource:
            self.sources.append(elem)
        elif type(elem) is EnBus:
            self.busses.append(elem)
        elif type(elem) is EnGenericStorage:
            self.generic_storages.append(elem)
        elif type(elem) is EnConverter:
            self.converters.append(elem)
        elif type(elem) is EnConstraints:
            self.constraints.append(elem)
        else:
            raise Exception("Unknown Type given!")

    def to_oemof_energysystem(self, energysystem: solph.EnergySystem) -> solph.EnergySystem:
        """
        Converts the internal energy system components to an oemof energy system and adds
        them to the provided oemof energy system instance. Each component in the internal
        energy system is iterated through, converted to its corresponding oemof object,
        and subsequently added to the provided energy system. This includes busses, sinks,
        sources, converters, and generic storages.

        :param energysystem: The oemof energy system instance to which the converted components
            of the internal energy system are added.
        :return: An updated oemof energy system instance containing all converted components.
        :rtype: solph.EnergySystem
        """
        for bus in self.busses:
            energysystem.add(bus.to_oemof(energysystem))

        for sink in self.sinks:
            energysystem.add(sink.to_oemof(energysystem))

        for source in self.sources:
            energysystem.add(source.to_oemof(energysystem))

        for converter in self.converters:
            energysystem.add(converter.to_oemof(energysystem))

        for generic_storage in self.generic_storages:
            energysystem.add(generic_storage.to_oemof(energysystem))

        # TODO: Adding Constraints

        return energysystem

add(elem)

Adds an element to the corresponding list based on its type. Determines the type of the given element and appends it to its respective container (e.g., sinks, sources, busses, etc.). Raises an exception if the type of the element is not recognized.

Parameters:

Name Type Description Default
elem EnSink | EnSource | EnBus | EnGenericStorage | EnConverter | EnConstraints

The element to be added. It should be one of the following types: EnSink, EnSource, EnBus, EnGenericStorage, EnConverter, or EnConstraints.

required

Returns:

Type Description

None

Source code in backend/app/ensys/components/energysystem.py
def add(self, elem: EnSink | EnSource | EnBus | EnGenericStorage | EnConverter | EnConstraints):
    """
    Adds an element to the corresponding list based on its type. Determines
    the type of the given element and appends it to its respective
    container (e.g., sinks, sources, busses, etc.). Raises an exception
    if the type of the element is not recognized.

    :param elem: The element to be added. It should be one of the following
                 types: EnSink, EnSource, EnBus, EnGenericStorage,
                 EnConverter, or EnConstraints.
    :type elem: EnSink | EnSource | EnBus | EnGenericStorage | EnConverter | EnConstraints
    :return: None
    """
    if type(elem) is EnSink:
        self.sinks.append(elem)
    elif type(elem) is EnSource:
        self.sources.append(elem)
    elif type(elem) is EnBus:
        self.busses.append(elem)
    elif type(elem) is EnGenericStorage:
        self.generic_storages.append(elem)
    elif type(elem) is EnConverter:
        self.converters.append(elem)
    elif type(elem) is EnConstraints:
        self.constraints.append(elem)
    else:
        raise Exception("Unknown Type given!")

to_oemof_energysystem(energysystem)

Converts the internal energy system components to an oemof energy system and adds them to the provided oemof energy system instance. Each component in the internal energy system is iterated through, converted to its corresponding oemof object, and subsequently added to the provided energy system. This includes busses, sinks, sources, converters, and generic storages.

Parameters:

Name Type Description Default
energysystem EnergySystem

The oemof energy system instance to which the converted components of the internal energy system are added.

required

Returns:

Type Description
solph.EnergySystem

An updated oemof energy system instance containing all converted components.

Source code in backend/app/ensys/components/energysystem.py
def to_oemof_energysystem(self, energysystem: solph.EnergySystem) -> solph.EnergySystem:
    """
    Converts the internal energy system components to an oemof energy system and adds
    them to the provided oemof energy system instance. Each component in the internal
    energy system is iterated through, converted to its corresponding oemof object,
    and subsequently added to the provided energy system. This includes busses, sinks,
    sources, converters, and generic storages.

    :param energysystem: The oemof energy system instance to which the converted components
        of the internal energy system are added.
    :return: An updated oemof energy system instance containing all converted components.
    :rtype: solph.EnergySystem
    """
    for bus in self.busses:
        energysystem.add(bus.to_oemof(energysystem))

    for sink in self.sinks:
        energysystem.add(sink.to_oemof(energysystem))

    for source in self.sources:
        energysystem.add(source.to_oemof(energysystem))

    for converter in self.converters:
        energysystem.add(converter.to_oemof(energysystem))

    for generic_storage in self.generic_storages:
        energysystem.add(generic_storage.to_oemof(energysystem))

    # TODO: Adding Constraints

    return energysystem