Exemplo n.º 1
0
    def setup_reaction_parameters(self):
        r"""Setup parameters for reaction (gas name aliases and LHV)."""
        self.fuel_list = []
        fuels = [
            'methane', 'ethane', 'propane', 'butane', 'hydrogen', 'nDodecane'
        ]
        for f in fuels:
            self.fuel_list += [
                x for x in self.nw_fluids
                if x in [a.replace(' ', '') for a in CP.get_aliases(f)]
            ]

        if len(self.fuel_list) == 0:
            msg = ('Your network\'s fluids do not contain any fuels, that are '
                   'available for the component ' + self.label + ' of type ' +
                   self.component() + '. Available fuels are: ' +
                   ', '.join(fuels) + '.')
            logging.error(msg)
            raise TESPyComponentError(msg)

        else:
            msg = ('The fuels for component ' + self.label + ' of type ' +
                   self.component() + ' are: ' + ', '.join(self.fuel_list) +
                   '.')
            logging.debug(msg)

        for fluid in ['o2', 'co2', 'h2o', 'n2']:
            try:
                setattr(self, fluid, [
                    x for x in self.nw_fluids if x in [
                        a.replace(' ', '')
                        for a in CP.get_aliases(fluid.upper())
                    ]
                ][0])
            except IndexError:
                msg = ('The component ' + self.label + ' (class ' +
                       self.__class__.__name__ + ') requires that the fluid '
                       '[fluid] is in the network\'s list of fluids.')
                aliases = ', '.join(CP.get_aliases(fluid.upper()))
                msg = msg.replace(
                    '[fluid]',
                    fluid.upper() + ' (aliases: ' + aliases + ')')
                logging.error(msg)
                raise TESPyComponentError(msg)

        self.fuels = {}
        for f in self.fuel_list:
            self.fuels[f] = {}
            structure = fluid_structure(f)
            for el in ['C', 'H', 'O']:
                if el in structure:
                    self.fuels[f][el] = structure[el]
                else:
                    self.fuels[f][el] = 0
            self.fuels[f]['LHV'] = self.calc_lhv(f)
Exemplo n.º 2
0
    def comp_init(self, nw):

        if not self.P.is_set:
            self.set_attr(P='var')
            msg = ('The power input of a water electrolyzer must be set! '
                   'We are adding the power input of component ' + self.label +
                   ' as custom variable of the system.')
            logging.info(msg)

        for fluid in ['o2', 'h2o', 'h2']:
            try:
                setattr(self, fluid, [
                    x for x in nw.fluids if x in [
                        a.replace(' ', '')
                        for a in CP.get_aliases(fluid.upper())
                    ]
                ][0])
            except IndexError:
                msg = ('The component ' + self.label + ' (class ' +
                       self.__class__.__name__ + ') requires that the fluid '
                       '[fluid] is in the network\'s list of fluids.')
                aliases = ', '.join(CP.get_aliases(fluid.upper()))
                msg = msg.replace(
                    '[fluid]',
                    fluid.upper() + ' (aliases: ' + aliases + ')')
                logging.error(msg)
                raise TESPyComponentError(msg)

        self.e0 = self.calc_e0()

        Component.comp_init(self, nw)
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     msg = ('Version 0.4.x introduced PEP 8 conform class names for all '
            'classes used in TESPy. Please refer to '
            'https://tespy.readthedocs.io/en/master/whats_new.html '
            'learn about the changes necessary to adapt your script to the '
            'latest API.')
     logging.error(msg)
     raise TESPyComponentError(msg)
Exemplo n.º 4
0
    def __init__(self, label, num_consumer, **kwargs):

        if not isinstance(label, str):
            raise TESPyComponentError('Subsystem label must be of type str!')

        elif len([x for x in [';', ', ', '.'] if x in label]) > 0:
            raise TESPyComponentError(
                'Can\'t use ' + str([';', ', ', '.']) + ' ', 'in label.')
        else:
            self.label = label

        if num_consumer <= 1:
            raise TESPyComponentError('Minimum number of consumers is 2.')
        else:
            self.num_consumer = num_consumer

        for key in self.attr():
            self.__dict__.update({key: np.nan})
            self.__dict__.update({key + '_set': False})

        self.subsys_init()
        self.set_attr(**kwargs)
Exemplo n.º 5
0
    def __init__(self, label, num_consumer):

        if not isinstance(label, str):
            msg = 'Subsystem label must be of type str!'
            logging.error(msg)
            raise ValueError(msg)

        elif len([x for x in [';', ', ', '.'] if x in label]) > 0:
            msg = 'Can\'t use ' + str([';', ', ', '.']) + ' in label.'
            logging.error(msg)
            raise ValueError(msg)
        else:
            self.label = label

        if num_consumer <= 1:
            raise TESPyComponentError('Minimum number of consumers is 2.')
        else:
            self.num_consumer = num_consumer

        self.comps = {}
        self.conns = {}
        self.create_comps()
        self.create_conns()
Exemplo n.º 6
0
    def comp_init(self, nw):

        if not self.P.is_set:
            self.set_attr(P='var')
            msg = ('The power output of cogeneration units must be set! '
                   'We are adding the power output of component ' +
                   self.label + ' as custom variable of the system.')
            logging.info(msg)

        component.comp_init(self, nw)

        o2 = [
            x for x in nw.fluids
            if x in [a.replace(' ', '') for a in CP.get_aliases('O2')]
        ]
        if len(o2) == 0:
            msg = ('Missing oxygen in network fluids, component ' +
                   self.label + ' of type ' + self.component() +
                   ' requires oxygen in network fluids.')
            logging.error(msg)
            raise TESPyComponentError(msg)
        else:
            self.o2 = o2[0]

        h2o = [
            x for x in nw.fluids
            if x in [a.replace(' ', '') for a in CP.get_aliases('H2O')]
        ]
        if len(h2o) == 0:
            msg = ('Missing water in network fluids, component ' + self.label +
                   ' of type ' + self.component() +
                   ' requires water in network fluids.')
            logging.error(msg)
            raise TESPyComponentError(msg)
        else:
            self.h2o = h2o[0]

        h2 = [
            x for x in nw.fluids
            if x in [a.replace(' ', '') for a in CP.get_aliases('H2')]
        ]
        if len(h2) == 0:
            msg = ('Missing hydrogen in network fluids, component ' +
                   self.label + ' of type ' + self.component() +
                   ' requires hydrogen in network fluids.')
            logging.error(msg)
            raise TESPyComponentError(msg)
        else:
            self.h2 = h2[0]

        self.e0 = self.calc_e0()

        # number of mandatroy equations for
        # cooling loop fluids: num_fl
        # fluid composition at reactor inlets/outlets: 3 * num_fl
        # mass flow balances: 3
        # pressure: 2
        # energy balance: 1
        # reactor outlet temperatures: 1
        self.num_eq = self.num_nw_fluids * 4 + 7
        for var in [
                self.e, self.eta, self.eta_char, self.Q, self.pr_c, self.zeta
        ]:
            if var.is_set is True:
                self.num_eq += 1

        self.jacobian = np.zeros(
            (self.num_eq, self.num_i + self.num_o + self.num_vars,
             self.num_nw_vars))

        self.residual = np.zeros(self.num_eq)
        pos = self.num_nw_fluids * 4
        self.jacobian[0:pos] = self.fluid_deriv()
        self.jacobian[pos:pos + 3] = self.mass_flow_deriv()
        self.jacobian[pos + 3:pos + 5] = self.pressure_deriv()
    def comp_init(self, nw):
        if not self.fuel.is_set or not isinstance(self.fuel.val, dict):
            msg = ('You must specify the fuel composition for stoichimetric '
                   'combustion chamber ' + self.label + '.')
            logging.error(msg)
            raise TESPyComponentError(msg)

        if not self.fuel_alias.is_set:
            msg = ('You must specify a fuel alias for stoichimetric '
                   'combustion chamber ' + self.label + '.')
            logging.error(msg)
            raise TESPyComponentError(msg)

        if not self.air.is_set or not isinstance(self.air.val, dict):
            msg = ('You must specify the air composition for stoichimetric '
                   'combustion chamber ' + self.label + '.')
            logging.error(msg)
            raise TESPyComponentError(msg)

        if not self.air_alias.is_set:
            msg = ('You must specify an air alias for stoichimetric '
                   'combustion chamber ' + self.label + '.')
            logging.error(msg)
            raise TESPyComponentError(msg)

        Component.comp_init(self, nw)

        # adjust the names for required fluids according to naming in the
        # network air
        for f in list(self.air.val.keys()):
            alias = [x for x in self.nw_fluids if x in [
                a.replace(' ', '') for a in CP.get_aliases(f)]]
            if len(alias) > 0:
                self.air.val[alias[0]] = self.air.val.pop(f)

        # fuel
        for f in list(self.fuel.val.keys()):
            alias = [x for x in self.air.val.keys() if x in [
                a.replace(' ', '') for a in CP.get_aliases(f)]]
            if len(alias) > 0:
                self.fuel.val[alias[0]] = self.fuel.val.pop(f)

        # list of all fluids of air and fuel
        fluids = list(self.air.val.keys()) + list(self.fuel.val.keys())

        # oxygen
        alias = [x for x in fluids if x in [
            a.replace(' ', '') for a in CP.get_aliases('O2')]]
        if len(alias) == 0:
            msg = 'Oxygen missing in input fluids.'
            logging.error(msg)
            raise TESPyComponentError(msg)
        else:
            self.o2 = alias[0]

        # carbondioxide
        self.co2 = [x for x in self.nw_fluids if x in [
            a.replace(' ', '') for a in CP.get_aliases('CO2')]]
        if len(self.co2) == 0:
            self.co2 = 'CO2'
        else:
            self.co2 = self.co2[0]

        # water
        self.h2o = [x for x in self.nw_fluids if x in [
            a.replace(' ', '') for a in CP.get_aliases('H2O')]]
        if len(self.h2o) == 0:
            self.h2o = 'H2O'
        else:
            self.h2o = self.h2o[0]

        # calculate lower heating value of specified fuel
        self.lhv = self.calc_lhv()
        msg = ('Combustion chamber fuel (' + self.fuel_alias.val +
               ') LHV is ' + str(self.lhv) + ' for component ' +
               self.label + '.')
        logging.debug(msg)
        # generate fluid properties for stoichiometric flue gas
        self.stoich_flue_gas(nw)