DHU_1.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. from copy import deepcopy
  2. import numpy as np
  3. import pandas as pd
  4. import psychrolib
  5. psychrolib.SetUnitSystem(psychrolib.SI)
  6. get_Enthalpy = np.vectorize(psychrolib.GetMoistAirEnthalpy)
  7. from .._model._base import BaseModel
  8. from ..components.coil import CoolingCoil
  9. from ..components.wheel import WheelS2,WheelS3
  10. from ..components.mixed import Mixed
  11. class DHU_1(BaseModel):
  12. def __init__(self) -> None:
  13. super().__init__()
  14. def fit(self,param):
  15. self.record_model(
  16. model_name = 'AIR',
  17. model = param,
  18. train_data = {'x':np.array([1])},
  19. train_metric = {'R2':1,'MAE':1,'MAPE':1}
  20. )
  21. return self
  22. def fit2(self,input_data:dict,observe_data:dict):
  23. import pymc as pm
  24. with pm.Model() as self.MODEL:
  25. prior = {
  26. 'coil_1' : CoolingCoil.prior('coil_1'),
  27. 'coil_2' : CoolingCoil.prior('coil_2'),
  28. 'coil_3' : CoolingCoil.prior('coil_3'),
  29. 'wheel_1': WheelS2.prior('wheel_1'),
  30. 'wheel_2': WheelS3.prior('wheel_2'),
  31. }
  32. output = self.model(**input_data,engine='pymc',param=prior)
  33. def predict(self,**kwargs) -> dict:
  34. param = self.model_info['model_AIR']
  35. kwargs = deepcopy(kwargs)
  36. COP = kwargs.pop('COP')
  37. price_E = kwargs.pop('price_E')
  38. price_S = kwargs.pop('price_S')
  39. pred_res = self.model(**kwargs,engine='numpy',param=param)
  40. # 中表冷冷量
  41. coil_2_Ein = get_Enthalpy(pred_res['mixed_1']['ToutA'],pred_res['mixed_1']['HoutA'])
  42. coil_2_Eout = get_Enthalpy(pred_res['coil_2']['ToutA'],pred_res['coil_2']['HoutA'])
  43. pred_res['coil_2']['Q'] = (coil_2_Eout - coil_2_Ein) * (pred_res['F_air']['FF_air']*66000) / (3.6*10**6)
  44. # 后表冷冷量
  45. coil_3_Ein = get_Enthalpy(pred_res['wheel_2']['ToutP'],pred_res['wheel_2']['HoutP'])
  46. coil_3_Eout = get_Enthalpy(pred_res['coil_3']['ToutA'],pred_res['coil_3']['HoutA'])
  47. pred_res['coil_3']['Q'] = (coil_3_Eout - coil_3_Ein) * (pred_res['F_air']['FR_air']*66000) / (3.6*10**6)
  48. # 前再生热量
  49. steamcoil_1_Ein = get_Enthalpy(pred_res['mixed_2']['ToutA'],pred_res['mixed_2']['HoutA'])
  50. steamcoil_1_Eout = get_Enthalpy(kwargs['wheel_1_TinR'],pred_res['mixed_2']['HoutA'])
  51. pred_res['steamcoil_1']['Q'] = (steamcoil_1_Eout - steamcoil_1_Ein) * (pred_res['F_air']['FO_air']*66000) / (3.6*10**6)
  52. # 后再生热量
  53. steamcoil_2_Ein = get_Enthalpy(pred_res['wheel_2']['ToutC'],pred_res['wheel_2']['HoutC'])
  54. steamcoil_2_Eout = get_Enthalpy(kwargs['wheel_2_TinR'],pred_res['wheel_2']['HoutC'])
  55. pred_res['steamcoil_2']['Q'] = (steamcoil_2_Eout - steamcoil_2_Ein) * ((pred_res['F_air']['FO_air']-pred_res['F_air']['FS_air'])*66000) / (3.6*10**6)
  56. # 前转轮焓升
  57. wheel_1_EinP = get_Enthalpy(pred_res['coil_1']['ToutA'],pred_res['coil_1']['HoutA'])
  58. wheel_1_EoutP = get_Enthalpy(pred_res['wheel_1']['ToutP'],pred_res['wheel_1']['HoutP'])
  59. pred_res['wheel_1']['E_diff'] = (wheel_1_EoutP - wheel_1_EinP) / 1000
  60. # 后转轮焓升
  61. wheel_2_EinP = get_Enthalpy(pred_res['coil_2']['ToutA'],pred_res['coil_2']['HoutA'])
  62. wheel_2_EoutP = get_Enthalpy(pred_res['wheel_2']['ToutP'],pred_res['wheel_2']['HoutP'])
  63. pred_res['wheel_2']['E_diff'] = (wheel_2_EoutP - wheel_2_EinP) / 1000
  64. # 耗冷费用折算
  65. pred_res['summary']['cost_cooling'] = np.abs(pred_res['coil_2']['Q'] + pred_res['coil_3']['Q']) / COP * price_E
  66. # 耗热费用折算
  67. pred_res['summary']['cost_heating'] = (pred_res['steamcoil_1']['Q'] + pred_res['steamcoil_2']['Q']) *3600/2260/1000*price_S
  68. # 冷热费用合计
  69. pred_res['summary']['cost_total'] = pred_res['summary']['cost_cooling'] + pred_res['summary']['cost_heating']
  70. return pred_res
  71. def predict_system(self,**kwargs) -> pd.DataFrame:
  72. pred_res = self.predict(**kwargs)
  73. system_output = {}
  74. for equp_name,output_info in pred_res.items():
  75. for output_name,output_value in output_info.items():
  76. system_output[f'{equp_name}_{output_name}'] = output_value
  77. system_output = dict(zip(
  78. system_output.keys(),
  79. np.broadcast_arrays(*system_output.values())
  80. ))
  81. system_output = pd.DataFrame(system_output)
  82. return system_output
  83. @classmethod
  84. def model(
  85. cls,
  86. Tin_F, # 新风温度
  87. Hin_F, # 新风湿度
  88. HzP, # 处理侧风机频率
  89. HzR, # 再生侧风机频率
  90. coil_1_TinW, # 前表冷进水温度
  91. coil_2_TinW, # 中表冷进水温度
  92. coil_3_TinW, # 后表冷进水温度
  93. coil_1_Val, # 前表冷阀门开度
  94. coil_2_Val, # 中表冷阀门开度
  95. coil_3_Val, # 后表冷阀门开度
  96. wheel_1_TinR, # 前转轮再生侧温度
  97. wheel_2_TinR, # 后转轮再生侧温度
  98. mixed_1_TinM, # 回风温度(处理侧)
  99. mixed_1_HinM, # 回风湿度(处理侧)
  100. mixed_2_TinM, # 补风温度(再生侧)
  101. mixed_2_HinM, # 补风湿度(再生侧)
  102. engine,
  103. param
  104. ) -> dict:
  105. # 空气的质量流量
  106. FF_air = 1 # 新风
  107. FB_air = 0 # 回风
  108. FR_air = 0.74 # 送风
  109. FS_air = 0.2 # 补风
  110. FO_air = FF_air + FB_air + FS_air - FR_air # 排风
  111. # 水的质量流量
  112. coil_1_FW = coil_1_Val
  113. coil_2_FW = coil_2_Val
  114. coil_3_FW = coil_3_Val
  115. # 前表冷
  116. coil_1_res = CoolingCoil.model(
  117. TinA = Tin_F,
  118. HinA = Hin_F,
  119. FA = FF_air,
  120. TinW = coil_1_TinW,
  121. FW = coil_1_FW,
  122. engine = engine,
  123. param = param['coil_1']
  124. )
  125. # 前转轮
  126. wheel_1_res = WheelS2.model(
  127. TinP = coil_1_res['ToutA'],
  128. HinP = coil_1_res['HoutA'],
  129. FP = FF_air,
  130. TinR = wheel_1_TinR,
  131. HinR = 0,
  132. FR = FO_air,
  133. engine = engine,
  134. param = param['wheel_1']
  135. )
  136. # 处理侧混风(回风)
  137. mixed_1_res = Mixed.model(
  138. TinA = wheel_1_res['ToutP'],
  139. HinA = wheel_1_res['HoutP'],
  140. FA = FF_air,
  141. TinM = mixed_1_TinM,
  142. HinM = mixed_1_HinM,
  143. FM = FB_air,
  144. engine = engine
  145. )
  146. # 中表冷
  147. coil_2_res = CoolingCoil.model(
  148. TinA = mixed_1_res['ToutA'],
  149. HinA = mixed_1_res['HoutA'],
  150. FA = FR_air,
  151. TinW = coil_2_TinW,
  152. FW = coil_2_FW,
  153. engine = engine,
  154. param = param['coil_2']
  155. )
  156. # 后转轮
  157. wheel_2_res = WheelS3.model(
  158. TinP = coil_2_res['ToutA'],
  159. HinP = coil_2_res['HoutA'],
  160. FP = FR_air,
  161. TinC = wheel_1_res['ToutP'],
  162. HinC = wheel_1_res['HoutP'],
  163. FC = FO_air-FS_air,
  164. TinR = wheel_2_TinR,
  165. HinR = wheel_1_res['HoutP'],
  166. FR = FO_air-FS_air,
  167. engine = engine,
  168. param = param['wheel_2'],
  169. )
  170. # 后表冷
  171. coil_3_res = CoolingCoil.model(
  172. TinA = wheel_2_res['ToutP'],
  173. HinA = wheel_2_res['HoutP'],
  174. FA = FR_air,
  175. TinW = coil_3_TinW,
  176. FW = coil_3_FW,
  177. engine = engine,
  178. param = param['coil_3']
  179. )
  180. # 再生侧混风(排风)
  181. mixed_2_res = Mixed.model(
  182. TinA = wheel_2_res['ToutR'],
  183. HinA = wheel_2_res['HoutR'],
  184. FA = FO_air-FS_air,
  185. TinM = mixed_2_TinM,
  186. HinM = mixed_2_HinM,
  187. FM = FS_air,
  188. engine = engine
  189. )
  190. # 前转轮湿度修正
  191. wheel_1_res_adj = WheelS2.model(
  192. TinP = coil_1_res['ToutA'],
  193. HinP = coil_1_res['HoutA'],
  194. FP = FF_air,
  195. TinR = wheel_1_TinR,
  196. HinR = mixed_2_res['HoutA'],
  197. FR = FO_air,
  198. engine = engine,
  199. param = param['wheel_1']
  200. )
  201. return {
  202. 'coil_1' : coil_1_res,
  203. 'coil_2' : coil_2_res,
  204. 'coil_3' : coil_3_res,
  205. 'wheel_1' : wheel_1_res_adj,
  206. 'wheel_2' : wheel_2_res,
  207. 'mixed_1' : mixed_1_res,
  208. 'mixed_2' : mixed_2_res,
  209. 'steamcoil_1': {},
  210. 'steamcoil_2': {},
  211. 'F_air' : {
  212. 'FF_air': FF_air,
  213. 'FB_air': FB_air,
  214. 'FR_air': FR_air,
  215. 'FS_air': FS_air,
  216. 'FO_air': FO_air
  217. },
  218. 'summary':{}
  219. }