#!/usr/bin/python
#TESPy组件主要概念:
#network:用于形成部件之间的连接,是系统的主要包含区域;
#components:实体模型,如压缩机、蒸发器、泵、阀门等元件,如果设置了一个组件,则必须指定一个(在一个network内)唯一标签,可以在组件文档中找到所有相关方程式;
#connections:用于连接两个组件,进行两个组件之间的物理量传递。基本规格包括:质量流量(m)、体积流量(V)、压力(p)、焓(h)、温度(T)、流体向量;创建连接后需要添加到network中;
#原文链接:https://blog.csdn.net/2301_79313166/article/details/136038489
from tespy.networks import Network #建立网络模型
from tespy.components import (Sink, Source, HeatExchanger, Pump, CycleCloser, Compressor, Valve, SimpleHeatExchanger)#设置组件:包括一个压缩机,两个换热器,一个膨胀阀
from tespy.connections import Connection #建立连接
#from tespy.components import
#my_plant = Network()
#my_plant.set_attr(T_unit='C', p_unit='bar', h_unit='kJ / kg', v_unit='l / s') #指定变量单位,不指定将使用SI单位(公制)
my_plant = Network(p_unit='bar', T_unit='C', h_unit='kJ / kg', v_unit='l / s', iterinfo=False)
#液冷机组:设置组件:包括一个水泵,一个压缩机,一个换热器,一个冷凝器,一个膨胀阀
feed = Source('feed water outlet') #_hot
retn = Sink('return water inlet') #_cold
pump = Pump('pump')
cond = SimpleHeatExchanger('condenser') #冷凝器SimpleHeatExchanger格式
#evap = SimpleHeatExchanger('evaporator') #蒸发器SimpleHeatExchanger格式
he = HeatExchanger('heat exchanger') #换热器SimpleHeatExchanger格式 Heat exchanger
vav = Valve('expansion valve') #膨胀阀
comp = Compressor('compressor') #压缩机
cc = CycleCloser('cycle closer') #此组件用来关闭循环过程
#建立连接,将各个组件通过温度,压力,流量等参数连接在一起
#热水侧
c1 = Connection(feed, 'out1', pump, 'in1', label='1')
c2 = Connection(pump, 'out1', he, 'in1', label='2')
c0 = Connection(he, 'out1', retn, 'in1', label='0')
my_plant.add_conns(c1, c2, c0)
#冷媒侧 #必须有cycle closer闭环
c11 = Connection(cc, 'out1', he, 'in2', label='11')
c3 = Connection(he, 'out2', comp, 'in1', label='3')#将换热器和压缩机进行参数化连接
c4 = Connection(comp, 'out1', cond, 'in1', label='4')
c5 = Connection(cond, 'out1', vav, 'in1', label='5')
c6 = Connection(vav, 'out1', cc, 'in1', label='6')
my_plant.add_conns(c3, c4, c5, c6, c11) #将连接点增加到网络中
#compressor.set_attr(pr=5, eta_s=0.8, design=['eta_s'],offdesign=['char_map_pr', 'char_map_eta_s'], igva='var')
#connect.set_attr(fluid={'water': 1}, p=1, T=20, v=1.5, design=['v'])
#pump.set_attr(eta_s=0.8, flow_char={'char_func': char, 'is_set': True},design=['eta_s'], offdesign=['eta_s_char'])
#condenser.set_attr(pr1=0.98, pr2=0.999, ttd_u=15, design=['pr2', 'ttd_u'],offdesign=['zeta2', 'kA_char'])
#heatexchanger.set_attr(pr1=0.98, pr2=0.98, ttd_u=5,design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA_char'])
c1.set_attr(fluid={'water': 1}, p=0.98, T=29.6, v=2.5, design=['v'])
pump.set_attr(eta_s=0.8, design=['eta_s'], offdesign=['eta_s_char'])
he.set_attr(pr1=0.98, pr2=0.98, ttd_u=5, design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA_char'])#换热器
cond.set_attr(pr=0.98, Q=-2000) #冷凝器,散热量-2000W,出口压力/进口压力=0.98(压缩比=压力损失)
#evap.set_attr(pr=0.9) #蒸发器,出口压力/进口压力=0.98(压缩比=压力损失)the pressure losses (by outlet to inlet pressure ratio)
comp.set_attr(eta_s=0.85) #压缩机 等熵效率0.85
c3.set_attr(fluid={'R410a': 1}, T=10, x=1) #换热器出口温度20℃=蒸发温度evaporation temperature,干度为1,R134A制冷剂 // x=1, offdesign=['m']
c5.set_attr(T=62, x=0) #冷凝器出口温度60℃ = 冷凝温度condensation temperature
#my_plant.set_attr(p_range=[0.05, 10], h_range=[15, 2000])
#cw_he.set_attr(fluid={'water': 1}, T=10, p=3, offdesign=['m'])
my_plant.solve(mode='design') #求解
#my_plant.print_results()
print(f'ev_Q = {abs(he.Q.val)}') #输出COP
print(f'COP = {abs(cond.Q.val) / comp.P.val}') #输出COP
print(f'CP = {comp.P.val}')
print(f'cp = {comp.component()}\n')
#round(cond.lamb.val, 3)
print(f'c1_T={round(c1.T.val, 2)}')
print(f'c2_T={round(c2.T.val, 2)}')
print(f'c3_T={round(c3.T.val, 2)}')
print(f'c4_T={round(c4.T.val, 2)}')
print(f'c5_T={round(c5.T.val, 2)}')
print(f'c6_T={round(c6.T.val, 2)}')
print(f'c0_T={round(c0.T.val, 2)}')
print(f'c11_T={round(c11.T.val, 2)}')
print("\n**** C4 ***\n")
print(f'c4_T={round(c4.T.val, 2)}')
print(f'c4_P={round(c4.p.val, 2)}')
print(f'c4_m={round(c4.m.val, 4)}' + " kg/s")
print(f'c4_vol={round(c4.vol.val, 8)}'+ " m3/kg")
print(f'c4_h={round(c4.h.val, 2)}' + " kJ/kg")
print(f'c4_s={round(c4.s.val, 2)}')
print(f'c4_fluid={c4.fluid.val}')
print(f'c4_v={round(c4.v.val, 8)}')
print(f'c4_x={round(c4.x.val, 2)}')
my_plant.export('mychiller') #输出json文件
Introduction - TESPy 0.7.6.post1 - Newton's Nature documentation