Source code for tespy.components.subsystem

# -*- coding: utf-8

"""Module for custom component groups.

It is possible to create subsystems of component groups in tespy. The subsystem
class is the base class for custom subsystems.


This file is part of project TESPy (github.com/oemof/tespy). It's copyrighted
by the contributors recorded in the version control history of the file,
available from its original location tespy/components/subsystems.py

SPDX-License-Identifier: MIT
"""

from tespy.tools import logger


[docs] class Subsystem: r""" Class Subsystem is the base class of all TESPy subsystems. Parameters ---------- label : str The label of the subsystem. Example ------- Basic example for a setting up a Subsystem object. This example does not run a TESPy calculation! >>> from tespy.components import Subsystem >>> mysub = Subsystem('mySubsystem') >>> type(mysub) <class 'tespy.components.subsystem.Subsystem'> >>> mysub.get_attr('label') 'mySubsystem' """ def __init__(self, label): if not isinstance(label, str): msg = 'Subsystem label must be of type str!' logger.error(msg) raise ValueError(msg) elif len([x for x in [';', ', ', '.'] if x in label]) > 0: msg = 'Can\'t use ' + str([';', ', ', '.']) + ' in label.' logger.error(msg) raise ValueError(msg) else: self.label = label self.comps = {} self.conns = {} self.create_comps() self.create_conns()
[docs] def get_attr(self, key): r""" Get the value of a subsystem's attribute. Parameters ---------- key : str The attribute you want to retrieve. Returns ------- out : Value of specified attribute. """ if key in self.__dict__: return self.__dict__[key] else: msg = 'Subsystem ' + self.label + ' has no attribute ' + key + '.' logger.error(msg) raise KeyError(msg)
[docs] def create_comps(self): """Create the subsystem's components.""" return
[docs] def create_conns(self): """Create the subsystem's connections.""" return