def setup(self): self.nw = network(['water', 'air']) self.comp = combustion.combustion_engine('combustion engine') self.pipe = piping.pipe('pipe') self.conn = connection(self.comp, 'out1', self.pipe, 'in1') self.bus = bus('mybus') self.sub = subsystems.subsystem('MySub')
def test_set_attr_errors(): """Test errors of set_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') # ValueErrors set_attr_ValueError(comb, offdesign=['Q']) set_attr_ValueError(conn, offdesign=['f']) set_attr_ValueError(nw, m_unit='kg') set_attr_ValueError(nw, h_unit='kg') set_attr_ValueError(nw, p_unit='kg') set_attr_ValueError(nw, T_unit='kg') set_attr_ValueError(nw, v_unit='kg') set_attr_ValueError(conn, state=5) # TypeErrors set_attr_TypeError(comb, P=[5]) set_attr_TypeError(comb, tiP_char=7) set_attr_TypeError(comb, design='f') set_attr_TypeError(comb, lamb=dc_cc()) set_attr_TypeError(comb, design_path=7) set_attr_TypeError(comb, local_design=5) set_attr_TypeError(comb, local_offdesign=5) set_attr_TypeError(pipeline, hydro_group=5) set_attr_TypeError(comb, printout=5) set_attr_TypeError(conn, design='h') set_attr_TypeError(conn, fluid_balance=1) set_attr_TypeError(conn, h0=[4]) set_attr_TypeError(conn, fluid=5) set_attr_TypeError(conn, design_path=5) set_attr_TypeError(conn, local_design=5) set_attr_TypeError(conn, local_offdesign=5) set_attr_TypeError(conn, printout=5) set_attr_TypeError(conn, label=5) set_attr_TypeError(conn, state='f') set_attr_TypeError(nw, m_range=5) set_attr_TypeError(nw, p_range=5) set_attr_TypeError(nw, h_range=5) set_attr_TypeError(nw, iterinfo=5) set_attr_TypeError(mybus, P='some value') set_attr_TypeError(mybus, printout=5) # KeyErrors set_attr_KeyError(dc_cc(), x=7) set_attr_KeyError(comb, wow=5) set_attr_KeyError(conn, jey=5) set_attr_KeyError(mybus, power_output=100000) # NotImplementedError set_attr_NotImplementedError(conn, Td_bp=ref(conn, 1, 0))
def test_wrong_bus_param_func(): """Test missing/wrong bus parameter specification in equations.""" # this test does not need setup, since the function is called without # network initialisation instance = reactors.water_electrolyzer('electrolyzer') some_bus = bus('some_bus') param = 'G' some_bus.add_comps({'comp': instance, 'param': param}) with raises(ValueError): instance.bus_func(some_bus.comps.loc[instance])
def test_wrong_bus_param_func(self): """ Test missing/wrong bus parameter specification for water electrolyzer. """ # this test does not need setup, since the function is called without # network initialisation self.nw = network(['H2O', 'O2', 'H2']) self.instance = reactors.water_electrolyzer('electrolyzer') some_bus = bus('some_bus') param = 'G' some_bus.add_comps({'c': self.instance, 'p': param}) self.instance.bus_func(some_bus.comps.loc[self.instance])
def test_combustion_chamber(self): """ Test component properties of combustion chamber. """ instance = combustion_chamber('combustion chamber') self.setup_combustion_chamber_network(instance) # connection parameter specification air = { 'N2': 0.7556, 'O2': 0.2315, 'Ar': 0.0129, 'H2O': 0, 'CO2': 0, 'CH4': 0 } fuel = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 0, 'CO2': 0.04, 'CH4': 0.96} self.c1.set_attr(fluid=air, p=1, T=30) self.c2.set_attr(fluid=fuel, T=30) self.c3.set_attr(T=1200) # test specified bus value on combustion_chamber (must be equal to ti) b = bus('thermal input', P=1e6) b.add_comps({'c': instance}) self.nw.add_busses(b) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of thermal input must be ' + str(b.P.val) + ', is ' + str(instance.ti.val) + '.') eq_(round(b.P.val, 1), round(instance.ti.val, 1), msg) b.set_attr(P=np.nan) # test specified thermal input for combustion_chamber instance.set_attr(ti=1e6) self.nw.solve('design') convergence_check(self.nw.lin_dep) ti = (self.c2.m.val_SI * self.c2.fluid.val['CH4'] * instance.fuels['CH4']['LHV']) msg = ('Value of thermal input must be ' + str(instance.ti.val) + ', is ' + str(ti) + '.') eq_(round(ti, 1), round(instance.ti.val, 1), msg) # test specified lamb for combustion_chamber self.c3.set_attr(T=np.nan) instance.set_attr(lamb=1) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of oxygen in flue gas must be 0.0, is ' + str(round(self.c3.fluid.val['O2'], 4)) + '.') eq_(0.0, round(self.c3.fluid.val['O2'], 4), msg)
def test_wrong_bus_param_deriv(): """Test missing/wrong bus parameter specification in derivatives.""" # this test does not need setup, since the function is called without # network initialisation instance = reactors.water_electrolyzer('electrolyzer') # required for calling bus_deriv method without network initialisation instance.num_vars = 1 instance.num_nw_fluids = 1 instance.num_nw_vars = 1 some_bus = bus('some_bus') param = 'G' some_bus.add_comps({'comp': instance, 'param': param}) with raises(ValueError): instance.bus_deriv(some_bus)
def test_bus_add_comps_errors(): """Test errors adding components to busses.""" mybus = bus('mybus') comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') bus_add_comps_TypeError(mybus, {'comp': conn}) bus_add_comps_TypeError(mybus, {'f': comb}) bus_add_comps_TypeError(mybus, {'comp': comb, 'char': 'Hi'}) bus_add_comps_TypeError(mybus, {'comp': comb, 'param': 5}) bus_add_comps_TypeError(mybus, {'comp': comb, 'P_ref': 'what'}) bus_add_comps_TypeError(mybus, comb) with raises(ValueError): mybus.add_comps({'comp': comb, 'base': 5})
def construct_busses(c, *args): r""" Create busses of the network. Parameters ---------- c : pandas.core.series.Series Bus information from .csv-file. Returns ------- b : tespy.connections.bus TESPy bus object. """ # set up bus with label and specify value for power b = bus(c.label, P=c.P) b.P.is_set = c.P_set return b
def test_get_attr_errors(): """Test errors of get_attr methods.""" nw = network(['water', 'air']) comb = combustion.combustion_engine('combustion engine') pipeline = piping.pipe('pipeline') conn = connection(comb, 'out1', pipeline, 'in1') mybus = bus('mybus') sub = subsystems.subsystem('MySub') get_attr_KeyError(comb, 'wow') get_attr_KeyError(conn, 'key') get_attr_KeyError(mybus, 'components') get_attr_KeyError(nw, 'missing') get_attr_KeyError(ref(conn, 1, 0), 'comp') get_attr_KeyError(sub, 'test') get_attr_KeyError(char_line(), 'test') get_attr_KeyError(data_container(), 'somekey') get_attr_KeyError(char_map(), 'Stuff')
def setup(self): # %% network self.nw = network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components # sources & sinks c_in = source('coolant in') cb = source('consumer back flow') cf = sink('consumer feed flow') amb_in = source('source ambient') amb_out = sink('sink ambient') ic_in = source('source intercool') ic_out = sink('sink intercool') c_out = sink('coolant out') # consumer system cd = heat_exchanger('condenser') rp = pump('recirculation pump') cons = heat_exchanger_simple('consumer') # evaporator system va = valve('valve') dr = drum('drum') ev = heat_exchanger('evaporator') su = heat_exchanger('superheater') pu = pump('pump evaporator') # compressor-system cp1 = compressor('compressor 1') cp2 = compressor('compressor 2') he = heat_exchanger('intercooler') # busses self.power = bus('total compressor power') self.power.add_comps({'c': cp1}, {'c': cp2}) self.heat = bus('total delivered heat') self.heat.add_comps({'c': cd, 'char': -1}) self.nw.add_busses(self.power, self.heat) # %% connections # consumer system c_in_cd = connection(c_in, 'out1', cd, 'in1') cb_rp = connection(cb, 'out1', rp, 'in1') rp_cd = connection(rp, 'out1', cd, 'in2') self.cd_cons = connection(cd, 'out2', cons, 'in1') cons_cf = connection(cons, 'out1', cf, 'in1') self.nw.add_conns(c_in_cd, cb_rp, rp_cd, self.cd_cons, cons_cf) # connection condenser - evaporator system cd_va = connection(cd, 'out1', va, 'in1') self.nw.add_conns(cd_va) # evaporator system va_dr = connection(va, 'out1', dr, 'in1') dr_pu = connection(dr, 'out1', pu, 'in1') pu_ev = connection(pu, 'out1', ev, 'in2') ev_dr = connection(ev, 'out2', dr, 'in2') dr_su = connection(dr, 'out2', su, 'in2') self.nw.add_conns(va_dr, dr_pu, pu_ev, ev_dr, dr_su) self.amb_in_su = connection(amb_in, 'out1', su, 'in1') su_ev = connection(su, 'out1', ev, 'in1') ev_amb_out = connection(ev, 'out1', amb_out, 'in1') self.nw.add_conns(self.amb_in_su, su_ev, ev_amb_out) # connection evaporator system - compressor system su_cp1 = connection(su, 'out2', cp1, 'in1') self.nw.add_conns(su_cp1) # compressor-system cp1_he = connection(cp1, 'out1', he, 'in1') he_cp2 = connection(he, 'out1', cp2, 'in1') cp2_c_out = connection(cp2, 'out1', c_out, 'in1') ic_in_he = connection(ic_in, 'out1', he, 'in2') he_ic_out = connection(he, 'out2', ic_out, 'in1') self.nw.add_conns(cp1_he, he_cp2, ic_in_he, he_ic_out, cp2_c_out) # %% component parametrization # condenser system x = np.array([ 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175, 1.2125, 1.2375, 1.25 ]) y = np.array([ 0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056, 0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000, 0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614 ]) rp.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) cons.set_attr(pr=1, design=['pr'], offdesign=['zeta']) # evaporator system x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.array([ 0.0100, 0.0400, 0.0700, 0.1100, 0.1500, 0.2000, 0.2500, 0.3000, 0.3500, 0.4000, 0.4500, 0.5000, 0.5500, 0.6000, 0.6500, 0.7000, 0.7500, 0.8000, 0.8500, 0.9000, 0.9500, 1.0000, 1.5000, 2.0000 ]) y = np.array([ 0.0185, 0.0751, 0.1336, 0.2147, 0.2997, 0.4118, 0.5310, 0.6582, 0.7942, 0.9400, 0.9883, 0.9913, 0.9936, 0.9953, 0.9966, 0.9975, 0.9983, 0.9988, 0.9992, 0.9996, 0.9998, 1.0000, 1.0008, 1.0014 ]) kA_char2 = dc_cc(func=char_line(x, y), param='m') ev.set_attr(pr1=1, pr2=.999, ttd_l=5, design=['ttd_l'], offdesign=['kA'], kA_char1=kA_char1, kA_char2=kA_char2) # no kA modification for hot side! x = np.array([0, 1]) y = np.array([1, 1]) kA_char1 = dc_cc(func=char_line(x, y), param='m') # characteristic line for superheater kA x = np.array( [0, 0.045, 0.136, 0.244, 0.43, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2]) y = np.array( [0, 0.037, 0.112, 0.207, 0.5, 0.8, 0.85, 0.9, 0.95, 1, 1.04, 1.07]) kA_char2 = dc_cc(func=char_line(x, y), param='m') su.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, offdesign=['zeta1', 'zeta2', 'kA']) x = np.array([ 0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.6375, 0.7125, 0.7875, 0.9, 0.9875, 1, 1.0625, 1.125, 1.175, 1.2125, 1.2375, 1.25 ]) y = np.array([ 0.0076, 0.1390, 0.2731, 0.4003, 0.5185, 0.6263, 0.7224, 0.8056, 0.8754, 0.9312, 0.9729, 1.0006, 1.0203, 1.0158, 1.0051, 1.0000, 0.9746, 0.9289, 0.8832, 0.8376, 0.7843, 0.7614 ]) pu.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) # compressor system x = np.array([0, 0.4, 1, 1.2]) y = np.array([0.5, 0.9, 1, 1.1]) cp1.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) cp2.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'], eta_s_char=dc_cc(func=char_line(x, y), param='m')) # characteristic line for intercooler kA x = np.linspace(0, 2.5, 26) y = np.array([ 0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045, 0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806, 1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621, 1.7058, 1.7488 ]) # x = np.array([0, 1]) # y = np.array([1, 1]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) # x = np.array([0, 1]) # y = np.array([1, 1]) kA_char2 = dc_cc(func=char_line(x, y), param='m') he.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, offdesign=['zeta1', 'zeta2', 'kA']) # characteristic line for condenser kA x = np.linspace(0, 2.5, 26) y = np.array([ 0.0000, 0.2455, 0.3747, 0.4798, 0.5718, 0.6552, 0.7323, 0.8045, 0.8727, 0.9378, 1.0000, 1.0599, 1.1176, 1.1736, 1.2278, 1.2806, 1.3320, 1.3822, 1.4313, 1.4792, 1.5263, 1.5724, 1.6176, 1.6621, 1.7058, 1.7488 ]) kA_char1 = dc_cc(func=char_line(x, y), param='m') x = np.linspace(0, 2.5, 26) y = np.array([ 0.000, 0.164, 0.283, 0.389, 0.488, 0.581, 0.670, 0.756, 0.840, 0.921, 1.000, 1.078, 1.154, 1.228, 1.302, 1.374, 1.446, 1.516, 1.585, 1.654, 1.722, 1.789, 1.855, 1.921, 1.986, 2.051 ]) kA_char2 = dc_cc(func=char_line(x, y), param='m') cd.set_attr(kA_char1=kA_char1, kA_char2=kA_char2, pr2=0.9998, design=['pr2'], offdesign=['zeta2', 'kA']) # %% connection parametrization # condenser system c_in_cd.set_attr(fluid={'water': 0, 'NH3': 1}, p=60) rp_cd.set_attr(T=60, fluid={'water': 1, 'NH3': 0}, p=10) self.cd_cons.set_attr(T=105) cons_cf.set_attr(h=ref(cb_rp, 1, 0), p=ref(cb_rp, 1, 0)) cd_va.set_attr(p=ref(c_in_cd, 1, -1000), Td_bp=-5, h0=500, design=['Td_bp']) # evaporator system cold side pu_ev.set_attr(m=ref(va_dr, 10, 0), p0=5) dr_su.set_attr(p0=5, T=5) su_cp1.set_attr(p=ref(dr_su, 1, -5000), Td_bp=5, h0=1700, design=['Td_bp', 'p']) # evaporator system hot side self.amb_in_su.set_attr(m=20, T=12, p=1, fluid={'water': 1, 'NH3': 0}) su_ev.set_attr(p=ref(self.amb_in_su, 1, -100), design=['p']) ev_amb_out.set_attr() # compressor-system cp1_he.set_attr(p=15) he_cp2.set_attr(T=40, p=ref(cp1_he, 1, -1000), design=['T', 'p']) ic_in_he.set_attr(p=1, T=20, m=5, fluid={'water': 1, 'NH3': 0}) he_ic_out.set_attr(p=ref(ic_in_he, 1, -200), design=['p']) cp2_c_out.set_attr(p=ref(c_in_cd, 1, 0), h=ref(c_in_cd, 1, 0))
# back h4_pib21 = connection(h4.comps['merge_0'], 'out1', pib21, 'in1') pib21_k4 = connection(pib21, 'out1', k4.comps['valve_1'], 'in1', T=ref(h4_pib21, 1, -pib21.L.val / dT_return), design=['T']) nw.add_conns(k4_pif21, pif21_h4) nw.add_conns(h4_pib21, pib21_k4) nw.add_subsys(h4) # %% busses # heat_losses = bus('network losses') heat_consumer = bus('network consumer') nw.check_network() for comp in nw.comps.index: if isinstance(comp, pipe): comp.set_attr(Tamb=0) heat_losses.add_comps({'comp': comp}) if (isinstance(comp, heat_exchanger_simple) and not isinstance(comp, pipe)): heat_consumer.add_comps({'comp': comp}) nw.add_busses(heat_losses, heat_consumer)
# generator efficiency x = np.array([ 0.100, 0.345, 0.359, 0.383, 0.410, 0.432, 0.451, 0.504, 0.541, 0.600, 0.684, 0.805, 1.000, 1.700, 10 ]) y = np.array([ 0.976, 0.989, 0.990, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999, 1.000, 0.999, 0.99 ]) * 0.984 gen1 = char_line(x=x, y=y) gen2 = char_line(x=x, y=y) gen3 = char_line(x=x, y=y) power = bus('power output') power.add_comps({ 'c': g_turb, 'char': gen1 }, { 'c': comp, 'char': 1 }, { 'c': comp_fuel, 'char': mot1 }, { 'c': turb_hp, 'char': gen2 }, { 'c': pump1, 'char': mot2
def test_buslabel_duplicate(self): with raises(TESPyNetworkError): a = bus('mybus') b = bus('mybus') self.nw.add_busses(a, b)
def setup(self): """Set up the model.""" # %% network setup fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O'] self.nw = 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', label='ambient air flow') cp_cc = connection(cp, 'out1', cc, 'in1') sf_cc = connection(sf, 'out1', cc, 'in2') cc_gt = connection(cc, 'out1', gt, 'in1') gt_fg = connection(gt, 'out1', fg, 'in1') self.nw.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg) # %% component parameters cc.set_attr(lamb=3) cp.set_attr(eta_s=0.9, pr=15) gt.set_attr(eta_s=0.9) # %% connection parameters amb_cp.set_attr(T=20, p=1, m=100, fluid={ 'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0, 'CO2': 0.0004, 'O2': 0.2314 }) sf_cc.set_attr(T=20, fluid={ 'CO2': 0.04, 'Ar': 0, 'N2': 0, 'O2': 0, 'H2O': 0, 'CH4': 0.96 }) gt_fg.set_attr(p=1) # motor efficiency x = np.array([ 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 10 ]) y = np.array([ 0.01, 0.3148, 0.5346, 0.6843, 0.7835, 0.8477, 0.8885, 0.9145, 0.9318, 0.9443, 0.9546, 0.9638, 0.9724, 0.9806, 0.9878, 0.9938, 0.9982, 0.999, 0.9995, 0.9999, 1, 0.9977, 0.9947, 0.9909, 0.9853, 0.9644 ]) * 0.975 self.motor_bus_based = char_line(x=x, y=y) self.motor_comp_based = char_line(x=x, y=1 / y) # generator efficiency x = np.array([ 0.100, 0.345, 0.359, 0.383, 0.410, 0.432, 0.451, 0.504, 0.541, 0.600, 0.684, 0.805, 1.000, 1.700, 10 ]) y = np.array([ 0.976, 0.989, 0.990, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996, 0.997, 0.998, 0.999, 1.000, 0.999, 0.99 ]) * 0.975 self.generator = char_line(x=x, y=y) power_bus_total = bus('total power output') power_bus_total.add_comps( { 'comp': cp, 'char': self.motor_bus_based, 'base': 'bus' }, { 'comp': gt, 'char': self.generator }) thermal_input = bus('thermal input') thermal_input.add_comps({'comp': cc}) compressor_power_comp = bus('compressor power input') compressor_power_comp.add_comps({ 'comp': cp, 'char': self.motor_comp_based }) compressor_power_bus = bus('compressor power input bus based') compressor_power_bus.add_comps({ 'comp': cp, 'char': self.motor_bus_based, 'base': 'bus' }) self.nw.add_busses(power_bus_total, thermal_input, compressor_power_comp, compressor_power_bus) # %% solving self.nw.solve('design') self.nw.save('tmp')
0.15056329, 0.12272329, 0.09374696, 0.06363430, 0.03238531, 0.00000000 ]) * 1e5 char = char_line(x=x, y=y) pu.set_attr(flow_char=dc_cc(func=char, is_set=True)) pu.set_attr(eta_s=0.90) # bhes bhe1.set_attr(D=2, L=0.1, ks=0.00001) bhe2.set_attr(D=2, L=0.1, ks=0.00001) bhe3.set_attr(D=2, L=0.1, ks=0.00001) # consumer cons.set_attr(D=2, L=0.1, ks=0.00001) # busses heat = bus('consumer heat demand') heat.add_comps({'c': cons, 'p': 'P'}) btes.add_busses(heat) # consumer heat demand heat.set_attr(P=-3000) # W ## connection parametrization # system inlet inflow_head = 2 # bar fc_pu.set_attr(p=inflow_head, m=0.6, fluid={'water': 1}) # for BHEs: # Tout: bhe1_mg.set_attr(T=303.15)
dh_source.dh_heat_exchanger.set_attr(T=t_dh_in, p=10, fluid={ 'Ar': 0, 'N2': 0, 'H2O': 1, 'CH4': 0, 'CO2': 0, 'O2': 0 }) dh_heat_exchanger.dh_sink.set_attr(T=t_dh_out) # %% Busses # power bus power = bus('power output') x = np.array([0.2, 0.4, 0.6, 0.8, 1.0, 1.1]) y = np.array([0.85, 0.93, 0.95, 0.96, 0.97, 0.96]) # create a characteristic line for a generator gen1 = char_line(x=x, y=y) power.add_comps({ 'comp': gas_turbine, 'char': gen1 }, { 'comp': steam_turbine, 'char': gen1 }, {'comp': air_compressor}) nw.add_busses(power) # heat bus
def __init__(self): self.nw = network( fluids=['BICUBIC::water'], p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False) # components # main cycle eco = heat_exchanger_simple('economizer') eva = heat_exchanger_simple('evaporator') sup = heat_exchanger_simple('superheater') cc = cycle_closer('cycle closer') hpt = turbine('high pressure turbine') sp1 = splitter('splitter 1', num_out=2) mpt = turbine('mid pressure turbine') sp2 = splitter('splitter 2', num_out=2) lpt = turbine('low pressure turbine') con = condenser('condenser') pu1 = pump('feed water pump') fwh1 = condenser('feed water preheater 1') fwh2 = condenser('feed water preheater 2') dsh = desuperheater('desuperheater') me2 = merge('merge2', num_in=2) pu2 = pump('feed water pump 2') pu3 = pump('feed water pump 3') me = merge('merge', num_in=2) # cooling water cwi = source('cooling water source') cwo = sink('cooling water sink') # connections # main cycle cc_hpt = connection(cc, 'out1', hpt, 'in1', label='feed steam') hpt_sp1 = connection(hpt, 'out1', sp1, 'in1', label='extraction1') sp1_mpt = connection(sp1, 'out1', mpt, 'in1', state='g') mpt_sp2 = connection(mpt, 'out1', sp2, 'in1', label='extraction2') sp2_lpt = connection(sp2, 'out1', lpt, 'in1') lpt_con = connection(lpt, 'out1', con, 'in1') con_pu1 = connection(con, 'out1', pu1, 'in1') pu1_fwh1 = connection(pu1, 'out1', fwh1, 'in2') fwh1_me = connection(fwh1, 'out2', me, 'in1', state='l') me_fwh2 = connection(me, 'out1', fwh2, 'in2', state='l') fwh2_dsh = connection(fwh2, 'out2', dsh, 'in2', state='l') dsh_me2 = connection(dsh, 'out2', me2, 'in1') me2_eco = connection(me2, 'out1', eco, 'in1', state='l') eco_eva = connection(eco, 'out1', eva, 'in1') eva_sup = connection(eva, 'out1', sup, 'in1') sup_cc = connection(sup, 'out1', cc, 'in1') self.nw.add_conns(cc_hpt, hpt_sp1, sp1_mpt, mpt_sp2, sp2_lpt, lpt_con, con_pu1, pu1_fwh1, fwh1_me, me_fwh2, fwh2_dsh, dsh_me2, me2_eco, eco_eva, eva_sup, sup_cc) # cooling water cwi_con = connection(cwi, 'out1', con, 'in2') con_cwo = connection(con, 'out2', cwo, 'in1') self.nw.add_conns(cwi_con, con_cwo) # preheating sp1_dsh = connection(sp1, 'out2', dsh, 'in1') dsh_fwh2 = connection(dsh, 'out1', fwh2, 'in1') fwh2_pu2 = connection(fwh2, 'out1', pu2, 'in1') pu2_me2 = connection(pu2, 'out1', me2, 'in2') sp2_fwh1 = connection(sp2, 'out2', fwh1, 'in1') fwh1_pu3 = connection(fwh1, 'out1', pu3, 'in1') pu3_me = connection(pu3, 'out1', me, 'in2') self.nw.add_conns(sp1_dsh, dsh_fwh2, fwh2_pu2, pu2_me2, sp2_fwh1, fwh1_pu3, pu3_me) # busses # power bus self.power = bus('power') self.power.add_comps( {'comp': hpt, 'char': -1}, {'comp': mpt, 'char': -1}, {'comp': lpt, 'char': -1}, {'comp': pu1, 'char': -1}, {'comp': pu2, 'char': -1}, {'comp': pu3, 'char': -1}) # heating bus self.heat = bus('heat') self.heat.add_comps( {'comp': eco, 'char': 1}, {'comp': eva, 'char': 1}, {'comp': sup, 'char': 1}) self.nw.add_busses(self.power, self.heat) # parametrization # components hpt.set_attr(eta_s=0.9) mpt.set_attr(eta_s=0.9) lpt.set_attr(eta_s=0.9) pu1.set_attr(eta_s=0.8) pu2.set_attr(eta_s=0.8) pu3.set_attr(eta_s=0.8) eco.set_attr(pr=0.99) eva.set_attr(pr=0.99) sup.set_attr(pr=0.99) con.set_attr(pr1=0.99, pr2=0.99, ttd_u=5) fwh1.set_attr(pr1=0.99, pr2=0.99, ttd_u=5) fwh2.set_attr(pr1=0.99, pr2=0.99, ttd_u=5) dsh.set_attr(pr1=0.99, pr2=0.99) # connections eco_eva.set_attr(x=0) eva_sup.set_attr(x=1) cc_hpt.set_attr(m=200, T=650, p=100, fluid={'water': 1}) hpt_sp1.set_attr(p=20) mpt_sp2.set_attr(p=3) lpt_con.set_attr(p=0.05) cwi_con.set_attr(T=20, p=10, fluid={'water': 1})
def test_heat_ex_simple(self): """ Test component properties of simple heat exchanger. """ instance = heat_exchanger_simple('heat exchanger') self.setup_heat_exchanger_simple_network(instance) fl = {'Ar': 0, 'H2O': 1} self.c1.set_attr(fluid=fl, m=1, p=10, T=100) # trigger heat exchanger parameter groups instance.set_attr(hydro_group='HW', L=100, ks=100, pr=0.99, Tamb=20) # test grouped parameter settings with missing parameters instance.hydro_group.is_set = True instance.kA_group.is_set = True self.nw.solve('design', init_only=True) msg = ('Hydro group must no be set, if one parameter is missing!') eq_(instance.hydro_group.is_set, False, msg) msg = ('kA group must no be set, if one parameter is missing!') eq_(instance.kA_group.is_set, False, msg) # test diameter calculation from specified dimensions (as pipe) # with Hazen-Williams method instance.set_attr(hydro_group='HW', D='var', L=100, ks=100, pr=0.99, Tamb=20) b = bus('heat', P=-1e5) b.add_comps({'c': instance}) self.nw.add_busses(b) self.nw.solve('design') pr = round(self.c2.p.val_SI / self.c1.p.val_SI, 3) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(instance.pr.val) + '.') eq_(pr, round(instance.pr.val, 3), msg) # make zeta system variable and use previously calculated diameter # to calculate zeta. The value for zeta must not change zeta = round(instance.zeta.val, 0) instance.set_attr(D=instance.D.val, zeta='var', pr=np.nan) instance.D.is_var = False self.nw.solve('design') msg = ('Value of zeta must be ' + str(zeta) + ', is ' + str(round(instance.zeta.val, 0)) + '.') eq_(zeta, round(instance.zeta.val, 0), msg) # same test with pressure ratio as sytem variable pr = round(instance.pr.val, 3) instance.set_attr(zeta=np.nan, pr='var') self.nw.solve('design') msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(round(instance.pr.val, 3)) + '.') eq_(pr, round(instance.pr.val, 3), msg) # test heat transfer coefficient as variable of the system (ambient # temperature required) instance.set_attr(kA='var', pr=np.nan) b.set_attr(P=-5e4) self.nw.solve('design') # due to heat output being half of reference (for Tamb) kA should be # somewhere near to that (actual value is 677) msg = ('Value of heat transfer coefficient must be 667, is ' + str(instance.kA.val) + '.') eq_(677, round(instance.kA.val, 0), msg) # test heat transfer as variable of the system instance.set_attr(Q='var', kA=np.nan) Q = -5e4 b.set_attr(P=Q) self.nw.solve('design') msg = ('Value of heat transfer must be ' + str(Q) + ', is ' + str(instance.Q.val) + '.') eq_(Q, round(instance.Q.val, 0), msg)
def test_heat_ex(self): """ Test component properties of heat exchanger. """ instance = heat_exchanger('heat exchanger') self.setup_heat_exchanger_network(instance) # design specification instance.set_attr(pr1=0.98, pr2=0.98, ttd_u=5, design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA']) self.c1.set_attr(T=120, p=3, fluid={'Ar': 0, 'H2O': 1}) self.c2.set_attr(T=70) self.c3.set_attr(T=40, p=5, fluid={'Ar': 1, 'H2O': 0}) b = bus('heat transfer', P=-80e3) b.add_comps({'c': instance}) self.nw.add_busses(b) self.nw.solve('design') self.nw.save('tmp') # check heat transfer Q = self.c1.m.val_SI * (self.c2.h.val_SI - self.c1.h.val_SI) td_log = ( (self.c2.T.val - self.c3.T.val - self.c1.T.val + self.c4.T.val) / np.log((self.c2.T.val - self.c3.T.val) / (self.c1.T.val - self.c4.T.val))) kA = round(-Q / td_log, 0) msg = ('Value of heat transfer must be ' + str(round(Q, 0)) + ', is ' + str(round(instance.Q.val, 0)) + '.') eq_(round(Q, 0), round(instance.Q.val, 0), msg) # check upper terminal temperature difference msg = ('Value of terminal temperature difference must be ' + str(round(instance.ttd_u.val, 1)) + ', is ' + str(round(self.c1.T.val - self.c4.T.val, 1)) + '.') eq_(round(instance.ttd_u.val, 1), round(self.c1.T.val - self.c4.T.val, 1), msg) # check lower terminal temperature difference self.c2.set_attr(T=np.nan) instance.set_attr(ttd_l=20) self.nw.solve('design') msg = ('Value of terminal temperature difference must be ' + str(instance.ttd_l.val) + ', is ' + str(self.c2.T.val - self.c3.T.val) + '.') eq_(round(self.c2.T.val - self.c3.T.val, 1), round(instance.ttd_l.val, 1), msg) # check specified kA value (by offdesign parameter), reset temperatures # to design state self.c2.set_attr(T=70) instance.set_attr(ttd_l=np.nan) self.nw.solve('offdesign', design_path='tmp') msg = ('Value of heat flow must be ' + str(instance.Q.val) + ', is ' + str(round(Q, 0)) + '.') eq_(round(Q, 0), round(instance.Q.val, 0), msg) msg = ('Value of heat transfer coefficient must be ' + str(kA) + ', is ' + str(round(instance.kA.val, 0)) + '.') eq_(kA, round(instance.kA.val, 0), msg) # trigger negative lower terminal temperature difference as result self.c4.set_attr(T=np.nan) self.c2.set_attr(T=30) self.nw.solve('design') msg = ('Value of upper terminal temperature differences must be ' 'smaller than zero, is ' + str(round(instance.ttd_l.val, 1)) + '.') eq_(True, instance.ttd_l.val < 0, msg) # trigger negative upper terminal temperature difference as result self.c4.set_attr(T=100) self.c2.set_attr(h=200e3, T=np.nan) instance.set_attr(pr1=0.98, pr2=0.98, ttd_u=np.nan, design=['pr1', 'pr2']) self.c1.set_attr(h=150e3, T=np.nan) self.c3.set_attr(T=40) self.nw.solve('design') msg = ('Value of upper terminal temperature differences must be ' 'smaller than zero, is ' + str(round(instance.ttd_u.val, 1)) + '.') eq_(True, instance.ttd_u.val < 0, msg) shutil.rmtree('./tmp', ignore_errors=True)
def test_water_electrolyzer(self): """ Test component properties of water electrolyzer. """ # check bus function: # power output on component and bus must be indentical power = bus('power') power.add_comps({'c': self.instance, 'p': 'P'}) power.set_attr(P=2.5e6) self.nw.add_busses(power) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of power must be ' + str(power.P.val) + ', is ' + str(self.instance.P.val) + '.') eq_(round(power.P.val, 1), round(self.instance.P.val), msg) power.set_attr(P=np.nan) # check bus function: # heat output on component and bus must be indentical heat = bus('heat') heat.add_comps({'c': self.instance, 'p': 'Q'}) heat.set_attr(P=-8e5) self.nw.add_busses(heat) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of heat flow must be ' + str(heat.P.val) + ', is ' + str(self.instance.Q.val) + '.') eq_(round(heat.P.val, 1), round(self.instance.Q.val), msg) self.nw.save('tmp') # check bus function: # heat output on component and bus must identical (offdesign test) Q = heat.P.val * 0.9 heat.set_attr(P=Q) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat flow must be ' + str(Q) + ', is ' + str(self.instance.Q.val) + '.') eq_(round(Q, 1), round(self.instance.Q.val), msg) # delete both busses again self.nw.del_busses(heat, power) # test efficiency vs. specific energy consumption self.instance.set_attr(eta=0.9, e='var') self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of efficiency must be ' + str(self.instance.eta.val) + ', is ' + str(self.instance.e0 / self.instance.e.val) + '.') eq_(round(self.instance.eta.val, 2), round(self.instance.e0 / self.instance.e.val, 2), msg) # test efficiency value > 1 e = 130e6 self.instance.set_attr(e=np.nan, eta=np.nan) self.instance.set_attr(e=e) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of efficiency must be ' + str(self.instance.e0 / e) + ', is ' + str(self.instance.eta.val) + '.') eq_(round(self.instance.e0 / e, 2), round(self.instance.eta.val, 2), msg) # test specific energy consumption e = 150e6 self.instance.set_attr(e=np.nan, eta=np.nan) self.instance.set_attr(e=e) self.nw.solve('design') convergence_check(self.nw.lin_dep) msg = ('Value of specific energy consumption e must be ' + str(e) + ', is ' + str(self.instance.e.val) + '.') eq_(round(e, 1), round(self.instance.e.val, 1), msg) # test cooling loop pressure ratio, zeta as variable value pr = 0.95 self.instance.set_attr(pr_c=pr, e=np.nan, zeta='var', P=2.5e6, design=['pr_c']) self.nw.solve('design') shutil.rmtree('./tmp', ignore_errors=True) self.nw.save('tmp') convergence_check(self.nw.lin_dep) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(self.instance.pr_c.val) + '.') eq_(round(pr, 2), round(self.instance.pr_c.val, 2), msg) # use zeta as offdesign parameter, at design point pressure # ratio must not change self.instance.set_attr(zeta=np.nan, offdesign=['zeta']) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of pressure ratio must be ' + str(pr) + ', is ' + str(self.instance.pr_c.val) + '.') eq_(round(pr, 2), round(self.instance.pr_c.val, 2), msg) # test heat output specification in offdesign mode Q = self.instance.Q.val * 0.9 self.instance.set_attr(Q=Q, P=np.nan) self.nw.solve('offdesign', design_path='tmp') convergence_check(self.nw.lin_dep) msg = ('Value of heat must be ' + str(Q) + ', is ' + str(self.instance.Q.val) + '.') eq_(round(Q, 0), round(self.instance.Q.val, 0), msg) shutil.rmtree('./tmp', ignore_errors=True)
comp_hydro = connection(comp, 'out1', hydro, 'in1') el_oxy = connection(el, 'out2', oxy, 'in1') cw_cold_el = connection(cw_cold, 'out1', el, 'in1') el_cw_hot = connection(el, 'out1', cw_hot, 'in1') nw.add_conns(fw_el, el_comp, comp_hydro, el_oxy, cw_cold_el, el_cw_hot) # %% busses # create characteristic line for the compressor motor x = np.array([0.2, 0.4, 0.6, 0.8, 1.0, 1.1]) y = np.array([0.85, 0.93, 0.95, 0.96, 0.97, 0.96]) mot1 = char_line(x=x, y=y) power = bus('total power bus') power.add_comps({'comp': el, 'param': 'P'}, {'comp': comp, 'char': mot1}) nw.add_busses(power) # %% parameters comp.set_attr(eta_s=0.9) el.set_attr(P=Q_hydro * 1e6 / 0.8, eta=eta_e, pr_c=0.99, design=['eta', 'pr_c'], offdesign=['eta_char', 'zeta']) fw_el.set_attr(p=10, T=15) cw_cold_el.set_attr(p=5, T=T_cw_cold, fluid={'H2O': 1, 'H2': 0, 'O2': 0}) el_cw_hot.set_attr(T=T_cw_hot)
# District Heating dh_heater.set_attr(pr1=0.99, pr2=0.99, ttd_u=5, design=['ttd_u', 'pr1', 'pr2'], offdesign=['kA', 'zeta1', 'zeta2']) # %% Busses # characteristic function for generator efficiency x = np.array([0, 0.2, 0.4, 0.6, 0.8, 1, 1.2]) y = np.array([0, 0.86, 0.9, 0.93, 0.95, 0.96, 0.95]) gen = char_line(x=x, y=y) gas_turbine_bus = bus('gas_turbine_bus') gas_turbine_bus.add_comps({ 'c': compressor_gtp, 'char': gen }, { 'c': gas_turbine, 'char': gen }) steam_turbine_bus = bus('steam_turbine_bus') steam_turbine_bus.add_comps({ 'c': hp_turbine, 'char': gen }, { 'c': lp_turbine, 'char': gen
def test_combustion_engine(self): """ Test component properties of combustion engine. """ instance = combustion_engine('combustion engine') self.setup_combustion_engine_network(instance) air = { 'N2': 0.7556, 'O2': 0.2315, 'Ar': 0.0129, 'H2O': 0, 'CO2': 0, 'CH4': 0 } fuel = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 0, 'CO2': 0.04, 'CH4': 0.96} water1 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0} water2 = {'N2': 0, 'O2': 0, 'Ar': 0, 'H2O': 1, 'CO2': 0, 'CH4': 0} # connection parametrisation instance.set_attr(pr1=0.99, pr2=0.99, lamb=1.0, design=['pr1', 'pr2'], offdesign=['zeta1', 'zeta2']) self.c1.set_attr(p=5, T=30, fluid=air) self.c2.set_attr(T=30, fluid=fuel) self.c4.set_attr(p=3, T=60, m=50, fluid=water1) self.c5.set_attr(p=3, T=80, m=50, fluid=water2) # create busses TI = bus('thermal input') Q1 = bus('heat output 1') Q2 = bus('heat output 2') Q = bus('heat output') Qloss = bus('thermal heat loss') TI.add_comps({'c': instance, 'p': 'TI'}) Q1.add_comps({'c': instance, 'p': 'Q1'}) Q2.add_comps({'c': instance, 'p': 'Q2'}) Q.add_comps({'c': instance, 'p': 'Q'}) Qloss.add_comps({'c': instance, 'p': 'Qloss'}) self.nw.add_busses(TI, Q1, Q2, Q, Qloss) # test specified thermal input bus value ti = 1e6 TI.set_attr(P=ti) self.nw.solve('design') self.nw.save('tmp') # calculate in offdesign mode self.nw.solve('offdesign', init_path='tmp', design_path='tmp') msg = ('Value of thermal input must be ' + str(TI.P.val) + ', is ' + str(instance.ti.val) + '.') eq_(round(TI.P.val, 1), round(instance.ti.val, 1), msg) # test specified thermal input in component TI.set_attr(P=np.nan) instance.set_attr(ti=ti) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') msg = ('Value of thermal input must be ' + str(ti) + ', is ' + str(instance.ti.val) + '.') eq_(round(ti, 1), round(instance.ti.val, 1), msg) instance.set_attr(ti=np.nan) # test specified heat output 1 bus value Q1.set_attr(P=instance.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') # heat output is at design point value, thermal input must therefore # not have changed msg = ('Value of thermal input must be ' + str(ti) + ', is ' + str(instance.ti.val) + '.') eq_(round(ti, 1), round(instance.ti.val, 1), msg) # calculate heat output over cooling loop heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) msg = ('Value of thermal input must be ' + str(heat1) + ', is ' + str(instance.Q1.val) + '.') eq_(round(heat1, 1), round(instance.Q1.val, 1), msg) Q1.set_attr(P=np.nan) # test specified heat output 2 bus value Q2.set_attr(P=1.2 * instance.Q2.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') # calculate heat output over cooling loop, due to characteristic # function Q1 is equal to Q2 for this combustion engine heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) msg = ('Value of heat output 2 must be ' + str(heat1) + ', is ' + str(instance.Q2.val) + '.') eq_(round(heat1, 1), round(instance.Q2.val, 1), msg) # test specified heat output 2 in component Q2.set_attr(P=np.nan) instance.set_attr(Q2=heat1) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') heat1 = self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) msg = ('Value of heat output 2 must be ' + str(heat1) + ', is ' + str(instance.Q2.val) + '.') eq_(round(heat1, 1), round(instance.Q2.val, 1), msg) # test total heat output bus value instance.set_attr(Q2=np.nan) Q.set_attr(P=1.5 * instance.Q1.val) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') heat = (self.c4.m.val_SI * (self.c6.h.val_SI - self.c4.h.val_SI) + self.c5.m.val_SI * (self.c7.h.val_SI - self.c5.h.val_SI)) msg = ('Value of total heat output must be ' + str(Q.P.val) + ', is ' + str(heat) + '.') eq_(round(Q.P.val, 1), round(heat, 1), msg) # test specified heat loss bus value Q.set_attr(P=np.nan) Qloss.set_attr(P=1e5) self.nw.solve('offdesign', init_path='tmp', design_path='tmp') msg = ('Value of heat loss must be ' + str(Qloss.P.val) + ', is ' + str(instance.Qloss.val) + '.') eq_(round(Qloss.P.val, 1), round(instance.Qloss.val, 1), msg) shutil.rmtree('./tmp', ignore_errors=True)
ws = connection(turb, 'out1', cond, 'in1') c_p = connection(cond, 'out1', pu, 'in1') fw = connection(pu, 'out1', eco, 'in2') nw.add_conns(suph_ls, ls, ws, c_p, fw) # district heating dh_c = connection(dh_in, 'out1', cond, 'in2') dh_i = connection(cond, 'out2', dh_whr, 'in2') dh_w = connection(dh_whr, 'out2', dh_out, 'in1') nw.add_conns(dh_c, dh_i, dh_w) # %% busses power = bus('power output') power.add_comps({'comp': g_turb}, {'comp': comp}, {'comp': turb}, {'comp': pu}) heat_out = bus('heat output') heat_out.add_comps({'comp': cond}, {'comp': dh_whr}) heat_in = bus('heat input') heat_in.add_comps({'comp': c_c}) nw.add_busses(power, heat_out, heat_in) # %% component parameters # gas turbine comp.set_attr(pr=14, eta_s=0.91, design=['pr', 'eta_s'], offdesign=['eta_s_char']) g_turb.set_attr(eta_s=0.88, design=['eta_s'], offdesign=['eta_s_char', 'cone'])
def setup(self): self.nw = network(['water', 'air']) self.instance = combustion.combustion_engine('combustion engine') self.bus = bus('power') self.bus.add_comps({'c': self.instance, 'p': 'Param'})
def test_bus_duplicate(self): with raises(TESPyNetworkError): b = bus('mybus') self.nw.add_busses(b, b)
def test_network_buslabel_duplicate(self): b = bus('mybus') self.nw.add_busses(self.bus) self.nw.add_busses(b)
x = np.array([ 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 10 ]) y = 1 / (np.array([ 0.01, 0.3148, 0.5346, 0.6843, 0.7835, 0.8477, 0.8885, 0.9145, 0.9318, 0.9443, 0.9546, 0.9638, 0.9724, 0.9806, 0.9878, 0.9938, 0.9982, 1.0009, 1.002, 1.0015, 1, 0.9977, 0.9947, 0.9909, 0.9853, 0.9644 ]) * 0.98) mot1 = char_line(x=x, y=y) mot2 = char_line(x=x, y=y) mot3 = char_line(x=x, y=y) mot4 = char_line(x=x, y=y) power = bus('total compressor power') power.add_comps({ 'c': cp, 'char': mot1 }, { 'c': pu, 'char': mot2 }, { 'c': dhp, 'char': mot3 }, { 'c': erp, 'char': mot4 }) heat = bus('total delivered heat')
def __init__(self, working_fluid): self.working_fluid = working_fluid fluids = ['water', self.working_fluid, 'air'] self.nw = network(fluids=fluids) self.nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg') # geo parameters geo_mass_flow = 210 geo_steam_share = 0.1 T_brine_in = 144.8 T_reinjection = 70.8 # ambient parameters T_amb = 0 p_amb = 1 # main components geo_steam = source('steam source') geo_brine = source('brine source') geo_reinjection = sink('reinjection well') air_in = source('ambient air source') air_out = sink('ambient air sink') air_cond = condenser('main condenser') orc_cc = cycle_closer('orc cycle closer') evap_steam = condenser('steam evaporator') evap_splitter = splitter('splitter evaporation') evap_merge = merge('merge evaporation') evap_steam = condenser('steam evaporator') geo_steam_pump = pump('geosteam condensate pump') evap_brine = heat_exchanger('brine evaporator') dr = drum('drum') eco = heat_exchanger('economiser') feed_water_pump = pump('feed water pump') geo_merge = merge('brine merge') tur = turbine('turbine') ls_valve = valve('live steam valve') ihe = heat_exchanger('internal heat exchanger') # busses power_bus = bus('power output') power_bus.add_comps({ 'c': tur, 'char': -1 }, { 'c': feed_water_pump, 'char': -1 }, { 'c': geo_steam_pump, 'char': -1 }) geothermal_bus = bus('thermal input') geothermal_bus.add_comps({ 'c': eco, 'char': -1 }, { 'c': evap_brine, 'char': -1 }, { 'c': evap_steam, 'char': -1 }) self.nw.add_busses(power_bus, geothermal_bus) # turbine to condenser ls_in = connection(orc_cc, 'out1', ls_valve, 'in1') lsv_tur = connection(ls_valve, 'out1', tur, 'in1') tur_ihe = connection(tur, 'out1', ihe, 'in1') ihe_cond = connection(ihe, 'out1', air_cond, 'in1') self.nw.add_conns(ls_in, lsv_tur, tur_ihe, ihe_cond) # condenser to steam generator cond_fwp = connection(air_cond, 'out1', feed_water_pump, 'in1') fwp_ihe = connection(feed_water_pump, 'out1', ihe, 'in2') self.nw.add_conns(cond_fwp, fwp_ihe) # steam generator ihe_eco = connection(ihe, 'out2', eco, 'in2') eco_dr = connection(eco, 'out2', dr, 'in1') dr_esp = connection(dr, 'out1', evap_splitter, 'in1') esp_eb = connection(evap_splitter, 'out1', evap_brine, 'in2') esp_es = connection(evap_splitter, 'out2', evap_steam, 'in2') eb_em = connection(evap_brine, 'out2', evap_merge, 'in1') es_em = connection(evap_steam, 'out2', evap_merge, 'in2') em_dr = connection(evap_merge, 'out1', dr, 'in2') ls_out = connection(dr, 'out2', orc_cc, 'in1') self.nw.add_conns(ihe_eco, eco_dr, dr_esp, esp_eb, esp_es, eb_em, es_em, em_dr, ls_out) # air cold side air_cold = connection(air_in, 'out1', air_cond, 'in2') air_hot = connection(air_cond, 'out2', air_out, 'in1') self.nw.add_conns(air_cold, air_hot) # geo source gs_es = connection(geo_steam, 'out1', evap_steam, 'in1', label='geosteam') es_gsp = connection(evap_steam, 'out1', geo_steam_pump, 'in1') gsp_gm = connection(geo_steam_pump, 'out1', geo_merge, 'in1') gb_eb = connection(geo_brine, 'out1', evap_brine, 'in1', label='geobrine') eb_gm = connection(evap_brine, 'out1', geo_merge, 'in2') self.nw.add_conns(gs_es, es_gsp, gsp_gm, gb_eb, eb_gm) gm_eco = connection(geo_merge, 'out1', eco, 'in1') eco_gr = connection(eco, 'out1', geo_reinjection, 'in1', label='reinjection') self.nw.add_conns(gm_eco, eco_gr) # fluid settings ihe_eco.set_attr(fluid={self.working_fluid: 1, 'air': 0, 'water': 0}) air_cold.set_attr(fluid={self.working_fluid: 0, 'air': 1, 'water': 0}) gs_es.set_attr(fluid={self.working_fluid: 0, 'air': 0, 'water': 1}) gb_eb.set_attr(fluid={self.working_fluid: 0, 'air': 0, 'water': 1}) # connection parameters ls_stable_p0 = PSI('P', 'T', T_brine_in + 273.15, 'Q', 1, self.working_fluid) / 1e5 lsv_tur.set_attr(p0=ls_stable_p0) ws_stable_h0 = ( PSI('H', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid) + 0.5 * (PSI('H', 'T', T_brine_in + 273.15, 'Q', 1, self.working_fluid) - PSI('H', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid))) / 1e3 tur_ihe.set_attr(h=ws_stable_h0) ihe_cond.set_attr( Td_bp=2, design=['Td_bp'], p0=PSI('P', 'T', T_amb + 273.15, 'Q', 1, self.working_fluid) / 1e5) fwp_ihe.set_attr(h=ref(cond_fwp, 1, 1e3)) # steam generator gs_es.set_attr(m=geo_mass_flow * geo_steam_share, T=T_brine_in, x=1, p0=5) gb_eb.set_attr(m=geo_mass_flow * (1 - geo_steam_share), T=T_brine_in, x=0) em_dr.set_attr() eb_em.set_attr(x=0.5) es_em.set_attr(x=0.5, design=['x']) eb_gm.set_attr(T=T_brine_in - 20) eco_dr.set_attr(Td_bp=-2) # main condenser air_cold.set_attr(p=p_amb, T=T_amb) air_hot.set_attr(T=15) # component parameters # turbines tur.set_attr(design=['eta_s'], offdesign=['cone', 'eta_s_char']) ls_valve.set_attr(pr=1, design=['pr']) # condensing ihe.set_attr(pr1=1, pr2=1, offdesign=['kA_char']) air_cond.set_attr(pr1=1, pr2=1, ttd_u=10, design=['ttd_u'], offdesign=['kA_char']) feed_water_pump.set_attr(design=['eta_s'], offdesign=['eta_s_char']) # steam generator evap_steam.set_attr( pr1=0.99, offdesign=['kA_char']) # no pr2 due to drum pressure balance evap_brine.set_attr( pr1=1, ttd_l=10, offdesign=['kA_char']) # no pr2 due to drum pressure balance eco.set_attr(pr1=1, pr2=1) geo_steam_pump.set_attr(eta_s=0.75, design=['eta_s'], offdesign=['eta_s_char']) self.nw.set_attr(iterinfo=False) self.nw.solve('design') self.nw.print_results() tur.set_attr(eta_s=0.9) feed_water_pump.set_attr(eta_s=0.75) tur_ihe.set_attr(h=None) fwp_ihe.set_attr(h=None) eb_gm.set_attr(T=None)
# feed water con = connection(cond, 'out1', pump, 'in1') fw_c = connection(pump, 'out1', preheater, 'in2') fw_w = connection(preheater, 'out2', steam_generator, 'in1') fs_out = connection(steam_generator, 'out1', closer, 'in1') nw.add_conns(con, fw_c, fw_w, fs_out) # cooling water cw_in = connection(source_cw, 'out1', cond, 'in2') cw_out = connection(cond, 'out2', sink_cw, 'in1') nw.add_conns(cw_in, cw_out) # %% busses # power bus power_bus = bus('power') power_bus.add_comps({'c': turbine_hp, 'char': -1}, {'c': turbine_lp, 'char': -1}, {'c': pump, 'char': -1}) # heating bus heat_bus = bus('heat') heat_bus.add_comps({'c': cond, 'char': -1}) nw.add_busses(power_bus, heat_bus) # %% parametrization of components turbine_hp.set_attr(eta_s=0.9, design=['eta_s'], offdesign=['eta_s_char', 'cone']) turbine_lp.set_attr(eta_s=0.9, design=['eta_s'],