DHU_AB.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. from typing import Union
  2. import numpy as np
  3. import pandas as pd
  4. import pymc as pm
  5. import pytensor.tensor as pt
  6. from .._base._base_device import BaseDevice
  7. from ...components.coil_water import CoolingCoil2
  8. from ...components.coil_steam import SteamCoilFs,SteamCoilFs2,SteamCoil
  9. from ...components.wheel2 import WheelS2,WheelS2V2,WheelS2V3
  10. from ...components.wheel3 import WheelS3,WheelS3V2,WheelS3V3
  11. from ...components.mixed import Mixed
  12. from ..utils.fit_utils import (
  13. observe,record,reorder_posterior
  14. )
  15. from ...tools.optimizer import optimizer
  16. from ...tools.data_cleaner import DataCleaner
  17. class DHU_AB(BaseDevice):
  18. val_rw_adj_target = ('coil_2_DoutA','coil_3_DoutA')
  19. def __init__(
  20. self,
  21. DHU_type = 'A',
  22. exist_Fa_H = True,
  23. exist_Fa_B = True,
  24. wheel_1 = None,
  25. wheel_2 = 'WheelS3',
  26. coolingcoil_2 = 'CoolingCoil2',
  27. coolingcoil_3 = 'CoolingCoil2',
  28. heatingcoil_1 = 'SteamCoil',
  29. heatingcoil_2 = 'SteamCoil',
  30. mixed_1 = 'Mixed',
  31. mixed_2 = 'Mixed',
  32. **kwargs
  33. ) -> None:
  34. super().__init__()
  35. self.DHU_type = DHU_type.replace('DHU_','')
  36. if self.DHU_type == 'A':
  37. wheel_1 = wheel_1 if wheel_1 is not None else 'WheelS3'
  38. elif self.DHU_type == 'B':
  39. wheel_1 = wheel_1 if wheel_1 is not None else 'WheelS2'
  40. else:
  41. raise Exception('DHU_type must be A or B')
  42. if 'components' in kwargs:
  43. self.components = kwargs['components']
  44. else:
  45. self.components = {
  46. 'wheel_1' : wheel_1,
  47. 'wheel_2' : wheel_2,
  48. 'coil_2' : coolingcoil_2,
  49. 'coil_3' : coolingcoil_3,
  50. 'heatingcoil_1': heatingcoil_1,
  51. 'heatingcoil_2': heatingcoil_2,
  52. 'mixed_1' : mixed_1,
  53. 'mixed_2' : mixed_2
  54. }
  55. self.exist_Fa_H = exist_Fa_H
  56. self.exist_Fa_B = exist_Fa_B
  57. self.record_load_info(
  58. components = self.components,
  59. DHU_type = self.DHU_type,
  60. exist_Fa_H = self.exist_Fa_H,
  61. exist_Fa_B = self.exist_Fa_B
  62. )
  63. self.components = {k:eval(v)(k) for k,v in self.components.items()}
  64. for idx in [1,2]:
  65. heatingcoil_idx = f'heatingcoil_{idx}'
  66. if isinstance(self.components[heatingcoil_idx],SteamCoilFs2):
  67. self.model_observe_data_columns[f'{heatingcoil_idx}_FP'] = f'{heatingcoil_idx}_FP'
  68. self.model_observe_data_columns[f'{heatingcoil_idx}_Fs'] = f'{heatingcoil_idx}_Fs'
  69. elif isinstance(self.components[heatingcoil_idx],SteamCoilFs):
  70. self.model_observe_data_columns[f'{heatingcoil_idx}_Fs'] = f'{heatingcoil_idx}_Fs'
  71. elif isinstance(self.components[heatingcoil_idx],SteamCoil):
  72. pass
  73. else:
  74. raise Exception('WRONG')
  75. @property
  76. def model_input_data_columns(self):
  77. columns = {
  78. 'Tin_F' : 'coil_1_ToutA',
  79. 'Hin_F' : 'coil_1_HoutA',
  80. 'fan_1_Hz' : 'fan_1_Hz',
  81. 'fan_2_Hz' : 'fan_2_Hz',
  82. 'coil_1_TinW' : 'coil_1_TinW',
  83. 'coil_2_TinW' : 'coil_2_TinW',
  84. 'coil_3_TinW' : 'coil_3_TinW',
  85. 'coil_1_Val' : 'coil_1_Val',
  86. 'coil_2_Val' : 'coil_2_Val',
  87. 'coil_3_Val' : 'coil_3_Val',
  88. 'wheel_1_TinR': 'wheel_1_TinR',
  89. 'wheel_2_TinR': 'wheel_2_TinR',
  90. }
  91. if self.exist_Fa_H:
  92. columns['mixed_1_TinM'] = 'mixed_1_TinM'
  93. columns['mixed_1_HinM'] = 'mixed_1_HinM'
  94. if self.exist_Fa_B:
  95. columns['mixed_2_TinM'] = 'mixed_2_TinM'
  96. columns['mixed_2_HinM'] = 'mixed_2_HinM'
  97. return columns
  98. @property
  99. def model_observe_data_columns(self):
  100. columns = {
  101. 'mixed_1_ToutA' : 'mixed_1_ToutA',
  102. 'mixed_1_DoutA' : 'mixed_1_DoutA',
  103. 'coil_2_ToutA' : 'coil_2_ToutA',
  104. 'coil_2_DoutA' : 'coil_2_DoutA',
  105. 'wheel_2_ToutP' : 'wheel_2_ToutP',
  106. 'wheel_2_DoutP' : 'wheel_2_DoutP',
  107. 'wheel_2_ToutR' : 'wheel_2_ToutR',
  108. 'wheel_2_ToutC' : 'wheel_2_ToutC',
  109. }
  110. if self.DHU_type == 'A':
  111. columns['wheel_1_ToutC'] = 'wheel_1_ToutC'
  112. return columns
  113. def fit(
  114. self,
  115. input_data : pd.DataFrame,
  116. observed_data: pd.DataFrame,
  117. rw_FA_val : bool = False,
  118. plot_TVP : bool = True,
  119. ):
  120. if len(input_data) < 30:
  121. raise Exception('数据量过少')
  122. with pm.Model() as self.MODEL_PYMC:
  123. param_prior = {name:comp.prior() for name,comp in self.components.items()}
  124. param_prior['F_air'] = AirFlow_DHU_AB.prior(
  125. rw_FA_val = rw_FA_val,
  126. N = len(input_data),
  127. exist_Fa_H = self.exist_Fa_H,
  128. exist_Fa_B = self.exist_Fa_B
  129. )
  130. res = self.model(
  131. **{k:input_data.loc[:,v].values for k,v in self.model_input_data_columns.items()},
  132. engine = 'pymc',
  133. components = self.components,
  134. param = param_prior
  135. )
  136. for std_name,name in self.model_observe_data_columns.items():
  137. if name not in observed_data.columns:
  138. continue
  139. observed_data = observed_data.rename(columns={name:std_name})
  140. observe('mixed_1_ToutA',res['mixed_1']['ToutA'],observed=observed_data)
  141. observe('mixed_1_DoutA',res['mixed_1']['DoutA'],observed=observed_data)
  142. observe('coil_2_ToutA',res['coil_2']['ToutA'],observed=observed_data)
  143. observe('coil_2_DoutA',res['coil_2']['DoutA'],observed=observed_data)
  144. observe('wheel_2_ToutP',res['wheel_2']['ToutP'],observed=observed_data)
  145. observe('wheel_2_ToutC',res['wheel_2']['ToutC'],observed=observed_data)
  146. observe('wheel_2_DoutP',res['wheel_2']['DoutP'],observed=observed_data,sigma=0.3)
  147. observe('wheel_2_ToutR',res['wheel_2']['ToutR'],observed=observed_data)
  148. if self.DHU_type == 'A':
  149. observe('wheel_1_ToutC',res['wheel_1']['ToutC'],observed=observed_data)
  150. for idx in [1,2]:
  151. heatingcoil_idx = f'heatingcoil_{idx}'
  152. if isinstance(self.components[heatingcoil_idx],SteamCoilFs2):
  153. observe(f'{heatingcoil_idx}_FP',res[heatingcoil_idx]['FP'],observed=observed_data,sigma=10000)
  154. observe(f'{heatingcoil_idx}_Fs',res[heatingcoil_idx]['Fs'],observed=observed_data,sigma=20)
  155. elif isinstance(self.components[heatingcoil_idx],SteamCoilFs):
  156. observe(f'{heatingcoil_idx}_Fs',res[heatingcoil_idx]['Fs'],observed=observed_data,sigma=20)
  157. elif isinstance(self.components[heatingcoil_idx],SteamCoil):
  158. record(f'{heatingcoil_idx}_Fs',res[heatingcoil_idx]['Fs'])
  159. else:
  160. raise Exception('WRONG')
  161. self.param_posterior = pm.find_MAP(maxeval=50000,include_transformed=False)
  162. self.record_model(
  163. model_name = 'ATD',
  164. model = reorder_posterior(param_prior,self.param_posterior),
  165. train_data = {'x':np.array([1])},
  166. train_metric = {'R2':1,'MAE':1,'MAPE':1}
  167. )
  168. self.TVP_data = self.get_TVP(self.param_posterior,observed_data)
  169. self.TVP_metric = self.get_metric(self.TVP_data)
  170. if plot_TVP:
  171. self.plot_TVP(self.TVP_data).show()
  172. return self
  173. @property
  174. def F_air_val_rw(self):
  175. return self.model_info['model_ATD']['F_air']['val_rw']
  176. def set_F_air_val_rw(self,value:float):
  177. self.model_info['model_ATD']['F_air']['val_rw'] = value
  178. return self
  179. def clean_data(
  180. self,
  181. data : pd.DataFrame,
  182. data_type : list=['input','observed'],
  183. print_process: bool = True,
  184. fill_zero : bool = False,
  185. save_log : Union[str,None] = None
  186. ) -> pd.DataFrame:
  187. data = data.replace(-9999,np.nan)
  188. clean_data = DataCleaner(data,print_process=print_process)
  189. if 'input' in data_type:
  190. clean_data = (
  191. clean_data
  192. .rm_rolling_fluct(window=60,fun='ptp',thre=0.1,include_cols=['State'])
  193. .rm_rule('State != 1')
  194. .rm_outrange(method='raw',upper=140,lower=20,include_cols=['wheel_1_TinR','wheel_2_TinR'])
  195. )
  196. if self.DHU_type == 'A':
  197. clean_data = (
  198. clean_data
  199. .rm_rule('wheel_1_ToutC<=coil_1_ToutA')
  200. )
  201. if 'observed' in data_type:
  202. pass
  203. clean_data = clean_data.get_data(
  204. fill = 0 if fill_zero else None,
  205. save_log = save_log
  206. )
  207. return clean_data
  208. def optimize(
  209. self,
  210. cur_input_data : pd.DataFrame,
  211. wheel_1_TinR_ub: float = 120,
  212. wheel_1_TinR_lb: float = 70,
  213. wheel_2_TinR_ub: float = 120,
  214. wheel_2_TinR_lb: float = 70,
  215. constrains : list = None,
  216. logging : bool = True
  217. ) -> list:
  218. constrains = [] if constrains is None else constrains
  219. cur_input_data = cur_input_data.iloc[[0],:]
  220. opt_var_boundary = {
  221. 'wheel_1_TinR':{'lb':wheel_1_TinR_lb,'ub':wheel_1_TinR_ub},
  222. 'wheel_2_TinR':{'lb':wheel_2_TinR_lb,'ub':wheel_2_TinR_ub},
  223. }
  224. opt_var_value = cur_input_data.loc[:,list(opt_var_boundary.keys())]
  225. oth_var_value = (
  226. cur_input_data
  227. .loc[:,list(self.model_input_data_columns.values())]
  228. .drop(opt_var_value.columns,axis=1)
  229. )
  230. opt_res = optimizer(
  231. model = self,
  232. opt_var_boundary = opt_var_boundary,
  233. opt_var_value = opt_var_value,
  234. oth_var_value = oth_var_value,
  235. target = 'summary_Fs',
  236. target_min = True,
  237. constrains = constrains,
  238. logging = logging,
  239. other_kwargs = {'NIND':2000,'MAXGEN':50}
  240. )
  241. return opt_res
  242. def model(self,*args,**kwargs):
  243. if self.DHU_type == 'A':
  244. return model_A(*args,**kwargs)
  245. elif self.DHU_type == 'B':
  246. return model_B(*args,**kwargs)
  247. else:
  248. raise ValueError('DHU_type must be A or B')
  249. def model_A(
  250. Tin_F, # 前表冷后温度
  251. Hin_F, # 前表冷后湿度
  252. fan_1_Hz, # 处理侧风机频率
  253. fan_2_Hz, # 再生侧风机频率
  254. coil_1_TinW, # 前表冷进水温度
  255. coil_2_TinW, # 中表冷进水温度
  256. coil_3_TinW, # 后表冷进水温度
  257. coil_1_Val, # 前表冷阀门开度
  258. coil_2_Val, # 中表冷阀门开度
  259. coil_3_Val, # 后表冷阀门开度
  260. wheel_1_TinR, # 前转轮再生侧温度
  261. wheel_2_TinR, # 后转轮再生侧温度
  262. engine : str,
  263. components: dict,
  264. param : dict,
  265. mixed_1_TinM = 0, # 回风温度(处理侧)
  266. mixed_1_HinM = 0, # 回风湿度(处理侧)
  267. mixed_2_TinM = 0, # 补风温度(再生侧)
  268. mixed_2_HinM = 0, # 补风湿度(再生侧)
  269. ) -> dict:
  270. # 水的质量流量
  271. coil_2_FW = coil_2_Val / 100
  272. coil_3_FW = coil_3_Val / 100
  273. # 空气的质量流量
  274. air_flow = AirFlow_DHU_AB.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param,type='DHU_A')
  275. # 前转轮
  276. wheel_1_res = components['wheel_1'].model(
  277. TinP = Tin_F,
  278. HinP = Hin_F,
  279. FP = air_flow['wheel_1_FaP'],
  280. TinR = wheel_1_TinR,
  281. HinR = 0,
  282. FR = air_flow['wheel_1_FaR'],
  283. TinC = Tin_F,
  284. HinC = Hin_F,
  285. FC = air_flow['wheel_1_FaC'],
  286. engine = engine,
  287. param = param['wheel_1']
  288. )
  289. # 处理侧混风(回风)
  290. mixed_1_res = components['mixed_1'].model(
  291. TinA = wheel_1_res['ToutP'],
  292. HinA = wheel_1_res['HoutP'],
  293. FA = air_flow['mixed_1_FaA'],
  294. TinM = mixed_1_TinM,
  295. HinM = mixed_1_HinM,
  296. FM = air_flow['mixed_1_FaM'],
  297. engine = engine
  298. )
  299. # 中表冷
  300. coil_2_res = components['coil_2'].model(
  301. TinA = mixed_1_res['ToutA'],
  302. HinA = mixed_1_res['HoutA'],
  303. FA = air_flow['coil_2_FaA'],
  304. TinW = coil_2_TinW,
  305. FW = coil_2_FW,
  306. engine = engine,
  307. param = param['coil_2']
  308. )
  309. # 后转轮
  310. wheel_2_res = components['wheel_2'].model(
  311. TinP = coil_2_res['ToutA'],
  312. HinP = coil_2_res['HoutA'],
  313. FP = air_flow['wheel_2_FaP'],
  314. TinC = wheel_1_res['ToutC'],
  315. HinC = wheel_1_res['HoutC'],
  316. FC = air_flow['wheel_2_FaC'],
  317. TinR = wheel_2_TinR,
  318. HinR = 0,
  319. FR = air_flow['wheel_2_FaR'],
  320. engine = engine,
  321. param = param['wheel_2'],
  322. )
  323. # 后表冷
  324. coil_3_res = components['coil_3'].model(
  325. TinA = wheel_2_res['ToutP'],
  326. HinA = wheel_2_res['HoutP'],
  327. FA = air_flow['coil_3_FaA'],
  328. TinW = coil_3_TinW,
  329. FW = coil_3_FW,
  330. engine = engine,
  331. param = param['coil_3']
  332. )
  333. # 后转轮湿度修正
  334. wheel_2_res_adj = components['wheel_2'].model(
  335. TinP = coil_2_res['ToutA'],
  336. HinP = coil_2_res['HoutA'],
  337. FP = air_flow['wheel_2_FaP'],
  338. TinC = wheel_1_res['ToutC'],
  339. HinC = wheel_1_res['HoutC'],
  340. FC = air_flow['wheel_2_FaC'],
  341. TinR = wheel_2_TinR,
  342. HinR = wheel_2_res['HoutC'],
  343. FR = air_flow['wheel_2_FaR'],
  344. engine = engine,
  345. param = param['wheel_2'],
  346. )
  347. # 再生侧混风(排风)
  348. mixed_2_res = components['mixed_2'].model(
  349. TinA = wheel_2_res_adj['ToutR'],
  350. HinA = wheel_2_res_adj['HoutR'],
  351. FA = air_flow['mixed_2_FaA'],
  352. TinM = mixed_2_TinM,
  353. HinM = mixed_2_HinM,
  354. FM = air_flow['mixed_2_FaM'],
  355. engine = engine
  356. )
  357. # 前转轮湿度修正
  358. wheel_1_res_adj = components['wheel_1'].model(
  359. TinP = Tin_F,
  360. HinP = Hin_F,
  361. FP = air_flow['wheel_1_FaP'],
  362. TinR = wheel_1_TinR,
  363. HinR = mixed_2_res['HoutA'],
  364. FR = air_flow['wheel_1_FaR'],
  365. TinC = Tin_F,
  366. HinC = Hin_F,
  367. FC = air_flow['wheel_1_FaC'],
  368. engine = engine,
  369. param = param['wheel_1']
  370. )
  371. # 前再生加热盘管
  372. heatingcoil_1_res = components['heatingcoil_1'].model(
  373. TinA = mixed_2_res['ToutA'],
  374. ToutA = wheel_1_TinR,
  375. FA = air_flow['heatingcoil_1_Fa'],
  376. param = param['heatingcoil_1'],
  377. engine = engine
  378. )
  379. # 后再生加热盘管
  380. heatingcoil_2_res = components['heatingcoil_2'].model(
  381. TinA = wheel_2_res_adj['ToutC'],
  382. ToutA = wheel_2_TinR,
  383. FA = air_flow['heatingcoil_2_Fa'],
  384. param = param['heatingcoil_2'],
  385. engine = engine
  386. )
  387. return {
  388. 'coil_2' : coil_2_res,
  389. 'coil_3' : coil_3_res,
  390. 'wheel_1' : wheel_1_res_adj,
  391. 'wheel_2' : wheel_2_res_adj,
  392. 'mixed_1' : mixed_1_res,
  393. 'mixed_2' : mixed_2_res,
  394. 'heatingcoil_1': heatingcoil_1_res,
  395. 'heatingcoil_2': heatingcoil_2_res,
  396. 'Fa' : air_flow,
  397. 'summary' : {
  398. 'Fs':heatingcoil_1_res['Fs'] + heatingcoil_2_res['Fs'],
  399. }
  400. }
  401. def model_B(
  402. Tin_F, # 前表冷后温度
  403. Hin_F, # 前表冷后湿度
  404. fan_1_Hz, # 处理侧风机频率
  405. fan_2_Hz, # 再生侧风机频率
  406. coil_1_TinW, # 前表冷进水温度
  407. coil_2_TinW, # 中表冷进水温度
  408. coil_3_TinW, # 后表冷进水温度
  409. coil_1_Val, # 前表冷阀门开度
  410. coil_2_Val, # 中表冷阀门开度
  411. coil_3_Val, # 后表冷阀门开度
  412. wheel_1_TinR, # 前转轮再生侧温度
  413. wheel_2_TinR, # 后转轮再生侧温度
  414. engine : str,
  415. components: dict,
  416. param : dict,
  417. mixed_1_TinM = 0, # 回风温度(处理侧)
  418. mixed_1_HinM = 0, # 回风湿度(处理侧)
  419. mixed_2_TinM = 0, # 补风温度(再生侧)
  420. mixed_2_HinM = 0, # 补风湿度(再生侧)
  421. ) -> dict:
  422. # 水的质量流量
  423. coil_2_FW = coil_2_Val / 100
  424. coil_3_FW = coil_3_Val / 100
  425. # 空气的质量流量
  426. air_flow = AirFlow_DHU_AB.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param,type='DHU_B')
  427. # 前转轮
  428. wheel_1_res = components['wheel_1'].model(
  429. TinP = Tin_F,
  430. HinP = Hin_F,
  431. FP = air_flow['wheel_1_FaP'],
  432. TinR = wheel_1_TinR,
  433. HinR = 0,
  434. FR = air_flow['wheel_1_FaR'],
  435. engine = engine,
  436. param = param['wheel_1'],
  437. )
  438. # 处理侧混风(回风)
  439. mixed_1_res = components['mixed_1'].model(
  440. TinA = wheel_1_res['ToutP'],
  441. HinA = wheel_1_res['HoutP'],
  442. FA = air_flow['mixed_1_FaA'],
  443. TinM = mixed_1_TinM,
  444. HinM = mixed_1_HinM,
  445. FM = air_flow['mixed_1_FaM'],
  446. engine = engine
  447. )
  448. # 中表冷
  449. coil_2_res = components['coil_2'].model(
  450. TinA = mixed_1_res['ToutA'],
  451. HinA = mixed_1_res['HoutA'],
  452. FA = air_flow['coil_2_FaA'],
  453. TinW = coil_2_TinW,
  454. FW = coil_2_FW,
  455. engine = engine,
  456. param = param['coil_2']
  457. )
  458. # 后转轮
  459. wheel_2_res = components['wheel_2'].model(
  460. TinP = coil_2_res['ToutA'],
  461. HinP = coil_2_res['HoutA'],
  462. FP = air_flow['wheel_2_FaP'],
  463. TinC = mixed_1_res['ToutA'],
  464. HinC = mixed_1_res['HoutA'],
  465. FC = air_flow['wheel_2_FaC'],
  466. TinR = wheel_2_TinR,
  467. HinR = 0,
  468. FR = air_flow['wheel_2_FaR'],
  469. engine = engine,
  470. param = param['wheel_2'],
  471. )
  472. # 后表冷
  473. coil_3_res = components['coil_3'].model(
  474. TinA = wheel_2_res['ToutP'],
  475. HinA = wheel_2_res['HoutP'],
  476. FA = air_flow['coil_3_FaA'],
  477. TinW = coil_3_TinW,
  478. FW = coil_3_FW,
  479. engine = engine,
  480. param = param['coil_3']
  481. )
  482. # 后转轮湿度修正
  483. wheel_2_res_adj = components['wheel_2'].model(
  484. TinP = coil_2_res['ToutA'],
  485. HinP = coil_2_res['HoutA'],
  486. FP = air_flow['wheel_2_FaP'],
  487. TinC = mixed_1_res['ToutA'],
  488. HinC = mixed_1_res['HoutA'],
  489. FC = air_flow['wheel_2_FaC'],
  490. TinR = wheel_2_TinR,
  491. HinR = wheel_2_res['HoutC'],
  492. FR = air_flow['wheel_2_FaR'],
  493. engine = engine,
  494. param = param['wheel_2'],
  495. )
  496. # 再生侧混风(排风)
  497. mixed_2_res = components['mixed_2'].model(
  498. TinA = wheel_2_res_adj['ToutR'],
  499. HinA = wheel_2_res_adj['HoutR'],
  500. FA = air_flow['mixed_2_FaA'],
  501. TinM = mixed_2_TinM,
  502. HinM = mixed_2_HinM,
  503. FM = air_flow['mixed_2_FaM'],
  504. engine = engine
  505. )
  506. # 前转轮湿度修正
  507. wheel_1_res_adj = components['wheel_1'].model(
  508. TinP = Tin_F,
  509. HinP = Hin_F,
  510. FP = air_flow['wheel_1_FaP'],
  511. TinR = wheel_1_TinR,
  512. HinR = mixed_2_res['HoutA'],
  513. FR = air_flow['wheel_1_FaR'],
  514. engine = engine,
  515. param = param['wheel_1'],
  516. )
  517. # 前蒸气盘管
  518. heatingcoil_1_res = components['heatingcoil_1'].model(
  519. TinA = mixed_2_res['ToutA'],
  520. ToutA = wheel_1_TinR,
  521. FA = air_flow['heatingcoil_1_Fa'],
  522. param = param['heatingcoil_1'],
  523. engine = engine
  524. )
  525. # 后蒸气盘管
  526. heatingcoil_2_res = components['heatingcoil_2'].model(
  527. TinA = wheel_2_res_adj['ToutC'],
  528. ToutA = wheel_2_TinR,
  529. FA = air_flow['heatingcoil_2_Fa'],
  530. param = param['heatingcoil_2'],
  531. engine = engine
  532. )
  533. return {
  534. 'coil_2' : coil_2_res,
  535. 'coil_3' : coil_3_res,
  536. 'wheel_1' : wheel_1_res_adj,
  537. 'wheel_2' : wheel_2_res_adj,
  538. 'mixed_1' : mixed_1_res,
  539. 'mixed_2' : mixed_2_res,
  540. 'heatingcoil_1': heatingcoil_1_res,
  541. 'heatingcoil_2': heatingcoil_2_res,
  542. 'Fa' : air_flow,
  543. 'summary' : {
  544. 'Fs':heatingcoil_1_res['Fs'] + heatingcoil_2_res['Fs'],
  545. }
  546. }
  547. class AirFlow_DHU_AB:
  548. @classmethod
  549. def model(cls,fan_1_Hz,fan_2_Hz,param,type):
  550. # 当定频风机固定的时候,各出入口处的基准的风量
  551. F_air_S_base = 1
  552. F_air_X_base = param['F_air']['X_base']
  553. F_air_H_base = param['F_air'].get('H_base',0)
  554. F_air_B_base = param['F_air'].get('B_base',0)
  555. F_air_val_rw = param['F_air'].get('val_rw',0)
  556. F_air_val_pct = param['F_air'].get('val_pct',0)
  557. # 新风阀的变化造成的基准风量变化
  558. F_air_S_base_adj = F_air_S_base
  559. F_air_X_base_adj = F_air_X_base + F_air_val_rw
  560. F_air_H_base_adj = F_air_H_base - F_air_val_rw * F_air_val_pct if 'H_base' in param['F_air'] else 0
  561. F_air_B_base_adj = F_air_B_base - F_air_val_rw * (1 - F_air_val_pct) if 'B_base' in param['F_air'] else 0
  562. # F_air_X_base_adj = F_air_X_base + F_air_val_rw
  563. # F_air_B_base_adj = F_air_B_base - F_air_val_rw * F_air_val_pct[0] if 'B_base' in param['F_air'] else 0
  564. # F_air_S_base_adj = F_air_S_base + F_air_val_rw * F_air_val_pct[1] if 'H_base' in param['F_air'] else 0
  565. # F_air_H_base_adj = F_air_H_base - F_air_val_rw * F_air_val_pct[2] if 'H_base' in param['F_air'] else 0
  566. # 考虑风机频率变化对风量的影响,得到最终风量
  567. # 因为从数据上看,排风机的频率不会影响到新风量,所以在新风阀不动的情况下,新风的增加量可以认为全部进入送风
  568. F_air_HzP_X = param['F_air']['HzP_X']
  569. F_air_HzP_H = param['F_air'].get('HzP_H',0)
  570. F_air_HzP_S = F_air_HzP_X + F_air_HzP_H
  571. F_air_HzR_B = param['F_air'].get('HzR_B',0)
  572. Fa_S = F_air_S_base_adj + F_air_HzP_S * (fan_1_Hz / 50)
  573. Fa_H = F_air_H_base_adj + F_air_HzP_H * (fan_1_Hz / 50)
  574. Fa_X = F_air_X_base_adj + F_air_HzP_X * (fan_1_Hz / 50)
  575. Fa_B = F_air_B_base_adj + F_air_HzR_B * (fan_2_Hz / 50)
  576. Fa_P = Fa_B + Fa_X + Fa_H - Fa_S
  577. if type == 'DHU_A':
  578. wheel_1_FaP = Fa_S - Fa_H
  579. wheel_1_FaC = Fa_X - wheel_1_FaP
  580. wheel_1_FaR = Fa_P
  581. wheel_2_FaP = Fa_S
  582. wheel_2_FaC = wheel_1_FaC
  583. wheel_2_FaR = wheel_1_FaC
  584. mixed_1_FaM = Fa_H
  585. mixed_1_FaA = wheel_1_FaP
  586. mixed_2_FaM = Fa_B
  587. mixed_2_FaA = wheel_1_FaC
  588. coil_2_FaA = Fa_S
  589. coil_3_FaA = Fa_S
  590. heatingcoil_1_Fa = Fa_P
  591. heatingcoil_2_Fa = wheel_1_FaC
  592. elif type == 'DHU_B':
  593. wheel_1_FaP = Fa_X
  594. wheel_1_FaC = None
  595. wheel_1_FaR = Fa_P
  596. wheel_2_FaP = Fa_S
  597. wheel_2_FaC = Fa_X + Fa_H - Fa_S
  598. wheel_2_FaR = wheel_2_FaC
  599. mixed_1_FaM = Fa_H
  600. mixed_1_FaA = Fa_X
  601. mixed_2_FaM = Fa_B
  602. mixed_2_FaA = wheel_2_FaC
  603. coil_2_FaA = Fa_S
  604. coil_3_FaA = Fa_S
  605. heatingcoil_1_Fa = Fa_P
  606. heatingcoil_2_Fa = wheel_2_FaC
  607. else:
  608. raise Exception('type error')
  609. return {
  610. 'Fa_S':Fa_S,'Fa_H':Fa_H,'Fa_X':Fa_X,'Fa_B':Fa_B,'Fa_P':Fa_P,
  611. 'wheel_1_FaP':wheel_1_FaP,'wheel_1_FaC':wheel_1_FaC,'wheel_1_FaR':wheel_1_FaR,
  612. 'wheel_2_FaP':wheel_2_FaP,'wheel_2_FaC':wheel_2_FaC,'wheel_2_FaR':wheel_2_FaR,
  613. 'mixed_1_FaM':mixed_1_FaM,'mixed_1_FaA':mixed_1_FaA,
  614. 'mixed_2_FaM':mixed_2_FaM,'mixed_2_FaA':mixed_2_FaA,
  615. 'coil_2_FaA':coil_2_FaA,'coil_3_FaA':coil_3_FaA,
  616. 'heatingcoil_1_Fa':heatingcoil_1_Fa,'heatingcoil_2_Fa':heatingcoil_2_Fa
  617. }
  618. @classmethod
  619. def prior(
  620. cls,
  621. rw_FA_val : bool,
  622. N : int,
  623. exist_Fa_H: bool,
  624. exist_Fa_B: bool
  625. ) -> dict:
  626. param = {}
  627. # 新风参数
  628. param['HzP_X'] = pm.HalfNormal('F_air_HzP_X',sigma=1,initval=1)
  629. param['X_base'] = pm.TruncatedNormal('F_air_X_base',mu=0.5,sigma=0.2,lower=0,initval=0.5)
  630. if exist_Fa_H:
  631. param['HzP_H'] = pm.HalfNormal('F_air_HzP_H',sigma=1,initval=0.1)
  632. param['H_base'] = pm.TruncatedNormal('F_air_H_base',mu=0.6,sigma=0.2,lower=0,upper=0.999,initval=0.6)
  633. if exist_Fa_B:
  634. param['HzR_B'] = pm.HalfNormal('F_air_HzR_B',sigma=1,initval=0.5)
  635. param['B_base'] = pm.TruncatedNormal('F_air_B_base',mu=0.2,sigma=0.1,lower=0,initval=0.1)
  636. if rw_FA_val:
  637. period = 48
  638. n_segments = int(np.ceil(N/period))
  639. remainder = N % period
  640. repeat = [period] * (n_segments - 1) + ([remainder] if remainder != 0 else [])
  641. rw = pm.GaussianRandomWalk(
  642. 'rw',sigma=0.1,init_dist=pm.Normal.dist(mu=0,sigma=0.3),shape=n_segments)
  643. param['val_rw'] = pm.Deterministic('F_air_val_rw',pt.repeat(rw,repeat))
  644. param['val_pct'] = pm.Beta('F_air_val_pct',alpha=8,beta=1,initval=0.9)
  645. # param['val_pct'] = pm.Dirichlet('F_air_val_pct',np.array([0.1,0.1,0.8]),initval=np.array([0.1,0.1,0.8]))
  646. else:
  647. param['val_rw'] = 0
  648. param['val_pct'] = 0
  649. return param