DHU_AB.py 26 KB

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