How to use the tespy.networks.networks.network function in tespy

To help you get started, we’ve selected a few tespy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oemof / tespy / tests / test_components / test_reactors.py View on Github external
def setup(self):
        """Set up network for electrolyzer tests."""
        self.nw = network(['O2', 'H2', 'H2O'], T_unit='C', p_unit='bar')
        self.instance = water_electrolyzer('electrolyzer')

        fw = source('feed water')
        cw_in = source('cooling water')
        o2 = sink('oxygen sink')
        h2 = sink('hydrogen sink')
        cw_out = sink('cooling water sink')

        self.instance.set_attr(pr_c=0.99)

        cw_el = connection(cw_in, 'out1', self.instance, 'in1',
                           fluid={'H2O': 1, 'H2': 0, 'O2': 0}, T=20, p=1)
        el_cw = connection(self.instance, 'out1', cw_out, 'in1', T=45)

        self.nw.add_conns(cw_el, el_cw)
github oemof / tespy / tests / error_tests.py View on Github external
def setup(self):
        self.nw = network(['TESPy::fuel', 'TESPy::fuel_fg', 'Air'])
        label = 'combustion chamber'
        self.instance = combustion.combustion_chamber_stoich(label)
        c1 = connection(basics.source('air'), 'out1', self.instance, 'in1')
        c2 = connection(basics.source('fuel'), 'out1', self.instance, 'in2')
        c3 = connection(self.instance, 'out1', basics.sink('flue gas'), 'in1')
        self.nw.add_conns(c1, c2, c3)
github oemof / tespy / tests / test_models / test_gas_turbine_models.py View on Github external
def setup_combustion_chamber_model(self):
        """Set up the model using the combustion chamber."""
        # %% network setup
        fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O']
        self.nw1 = network(
            fluids=fluid_list, p_unit='bar', T_unit='C',
            p_range=[0.5, 20], T_range=[10, 2000])

        # %% components
        amb = source('ambient')
        sf = source('fuel')
        cc = combustion_chamber('combustion')
        cp = compressor('compressor')
        gt = turbine('turbine')
        fg = sink('flue gas outlet')

        # %% connections
        amb_cp = connection(amb, 'out1', cp, 'in1')
        cp_cc = connection(cp, 'out1', cc, 'in1')
        sf_cc = connection(sf, 'out1', cc, 'in2')
        cc_gt = connection(cc, 'out1', gt, 'in1', label='flue gas after cc')
github oemof / tespy / tests / test_errors.py View on Github external
def test_turbine_missing_char_parameter():
    """Turbine with invalid parameter for eta_s_char function."""
    nw = network(['CH4'])
    so = basics.source('source')
    si = basics.sink('sink')
    instance = turbomachinery.turbine('turbine')
    c1 = connection(so, 'out1', instance, 'in1')
    c2 = connection(instance, 'out1', si, 'in1')
    nw.add_conns(c1, c2)
    instance.set_attr(eta_s_char=dc_cc(func=char_line([0, 1], [1, 2]),
                                       is_set=True, param=None))
    nw.solve('design', init_only=True)
    with raises(ValueError):
        instance.eta_s_char_func()
github oemof / tespy / tests / test_networks / test_network.py View on Github external
def setup_network_individual_offdesign(self):
        """Set up network for individual offdesign tests."""
        self.nw = network(['H2O'], T_unit='C', p_unit='bar', v_unit='m3 / s')

        so = basics.source('source')
        sp = nodes.splitter('splitter', num_out=2)
        self.pump1 = turbomachinery.pump('pump 1')
        self.sc1 = heat_exchangers.solar_collector('collector field 1')
        v1 = piping.valve('valve1')
        self.pump2 = turbomachinery.pump('pump 2')
        self.sc2 = heat_exchangers.solar_collector('collector field 2')
        v2 = piping.valve('valve2')
        me = nodes.merge('merge', num_in=2)
        si = basics.sink('sink')

        self.pump1.set_attr(eta_s=0.8, design=['eta_s'],
                            offdesign=['eta_s_char'])
        self.pump2.set_attr(eta_s=0.8, design=['eta_s'],
                            offdesign=['eta_s_char'])
github oemof / tespy / tests / test_errors.py View on Github external
def test_missing_water_in_network(self):
        """Test missing water in network fluids with water electrolyzer."""
        self.nw = network(['O2', 'H2'])
        self.setup_electrolyzer_network()
        with raises(TESPyComponentError):
            self.nw.solve('design')
github oemof / tespy / tests / test_components / test_turbomachinery.py View on Github external
def setup_network(self, instance):
        self.nw = network(['INCOMP::DowQ', 'NH3', 'N2', 'O2', 'Ar'],
                          T_unit='C', p_unit='bar', v_unit='m3 / s')
        self.source = source('source')
        self.sink = sink('sink')
        self.c1 = connection(self.source, 'out1', instance, 'in1')
        self.c2 = connection(instance, 'out1', self.sink, 'in1')
        self.nw.add_conns(self.c1, self.c2)
github oemof / tespy / tests / test_components / test_piping.py View on Github external
def setup_piping_network(self, instance):
        self.nw = network(['CH4'], T_unit='C', p_unit='bar')
        self.source = source('source')
        self.sink = sink('sink')
        self.c1 = connection(self.source, 'out1', instance, 'in1')
        self.c2 = connection(instance, 'out1', self.sink, 'in1')
        self.nw.add_conns(self.c1, self.c2)
github oemof / tespy / tespy / networks / networks.py View on Github external
def post_processing(self):
        r"""Calculate bus, component parameters and connection parameters."""
        # components
        self.comps.apply(network.process_components, axis=1)

        # busses
        for b in self.busses.values():
            b.P.val = 0
            for cp in b.comps.index:
                # get components bus func value
                val = cp.bus_func(b.comps.loc[cp])
                # save as reference value
                if self.mode == 'design':
                    b.comps.loc[cp].P_ref = (
                        cp.bus_func(b.comps.loc[cp]) /
                        abs(b.comps.loc[cp].char.evaluate(1)))
                b.P.val += val

        # connections
        for c in self.conns.index:
github oemof / tespy / tespy / networks / networks.py View on Github external
Note
        ----
        The methods
        :func:`tespy.networks.network.init_comp_design_params` (components) and
        the :func:`tespy.networks.network.init_conn_design_params`
        (connections) handle the parameter specification.
        """
        # components without any parameters
        not_required = ['source', 'sink', 'node', 'merge', 'splitter',
                        'separator', 'drum', 'subsystem_interface']
        # fetch all components, reindex with label
        cp_sort = self.comps.copy()
        # get class name
        cp_sort['cp'] = cp_sort.apply(network.get_class_base, axis=1)
        cp_sort['label'] = cp_sort.apply(network.get_props, axis=1,
                                         args=('label',))
        cp_sort['comp'] = cp_sort.index
        cp_sort.set_index('label', inplace=True)

        # iter through unique types of components (class names)
        for c in cp_sort.cp.unique():
            if c not in not_required:
                path = hlp.modify_path_os(self.design_path +
                                          '/comps/' + c + '.csv')
                msg = ('Reading design point information for components of '
                       'type ' + c + ' from path ' + path + '.')
                logging.debug(msg)

                # read data
                df = pd.read_csv(path, sep=';', decimal='.',
                                 converters={'busses': ast.literal_eval,