DHU_AB.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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 = 'SteamCoil',
  27. heatingcoil_2 = 'SteamCoil',
  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 'WheelS3V3'
  36. wheel_2 = wheel_2 if wheel_2 is not None else 'WheelS3V2'
  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. 'mixed_2_ToutA': 'mixed_2_ToutA', # 涉及前再生加热盘管的热量
  113. 'wheel_2_ToutC': 'wheel_2_ToutC', # 涉及后再生加热盘管的热量
  114. }
  115. if self.DHU_type == 'A':
  116. columns['wheel_1_ToutC'] = 'wheel_1_ToutC' # A类除湿机前转轮是三分转轮
  117. for idx in [1,2]:
  118. heatingcoil_idx = f'heatingcoil_{idx}'
  119. if isinstance(self.components[heatingcoil_idx],coil_steam.SteamCoilFs2):
  120. columns[f'{heatingcoil_idx}_FP'] = f'{heatingcoil_idx}_FP'
  121. columns[f'{heatingcoil_idx}_Fs'] = f'{heatingcoil_idx}_Fs'
  122. elif isinstance(self.components[heatingcoil_idx],coil_steam.SteamCoilFs):
  123. columns[f'{heatingcoil_idx}_Fs'] = f'{heatingcoil_idx}_Fs'
  124. elif isinstance(self.components[heatingcoil_idx],coil_steam.SteamCoil):
  125. # columns['wheel_2_ToutC'] = 'wheel_2_ToutC'
  126. # columns['wheel_1_ToutR'] = 'wheel_1_ToutR'
  127. # columns['mixed_2_ToutA'] = 'mixed_2_ToutA'
  128. pass
  129. elif isinstance(self.components[heatingcoil_idx],coil_steam.SteamCoilVal):
  130. columns[f'{heatingcoil_idx}_Val'] = f'{heatingcoil_idx}_Val'
  131. else:
  132. raise Exception('WRONG')
  133. exclude_obs = self.other_info.get('exclude_obs',[])
  134. for col in exclude_obs:
  135. if col in columns:
  136. del columns[col]
  137. return columns
  138. def fit(
  139. self,
  140. input_data : pd.DataFrame,
  141. observed_data: pd.DataFrame,
  142. rw_FA_val : bool = False,
  143. plot_TVP : bool = True,
  144. ):
  145. if len(input_data) < 30:
  146. raise Exception('数据量过少')
  147. with pm.Model() as self.MODEL_PYMC:
  148. param_prior = {name:comp.prior() for name,comp in self.components.items()}
  149. param_prior['F_air'] = AirFlow_DHU_AB.prior(
  150. rw_FA_val = rw_FA_val,
  151. N = len(input_data),
  152. exist_Fa_H = self.exist_Fa_H,
  153. exist_Fa_B = self.exist_Fa_B
  154. )
  155. res = self.model(
  156. **{k:input_data.loc[:,v].values for k,v in self.model_input_data_columns.items()},
  157. engine = 'pymc',
  158. components = self.components,
  159. param = param_prior
  160. )
  161. for std_name,name in self.model_observe_data_columns.items():
  162. if name not in observed_data.columns:
  163. raise Exception(f'Missing column: {name}')
  164. observed_data = observed_data.rename(columns={name:std_name})
  165. std_name_equp,std_name_point = std_name.rsplit('_',1)
  166. sigma = {
  167. 'wheel_2_DoutP' : 0.3,
  168. 'heatingcoil_1_Fs': 20,
  169. 'heatingcoil_2_Fs': 20,
  170. 'heatingcoil_1_FP': 10000,
  171. 'heatingcoil_2_FP': 10000,
  172. }
  173. if std_name in ['heatingcoil_1_Val','heatingcoil_2_Val']:
  174. sigma = res[std_name_equp]['sigma']
  175. else:
  176. sigma = {
  177. 'wheel_2_DoutP' : 0.3,
  178. 'heatingcoil_1_Fs': 20,
  179. 'heatingcoil_2_Fs': 20,
  180. 'heatingcoil_1_FP': 10000,
  181. 'heatingcoil_2_FP': 10000,
  182. }.get(std_name,1)
  183. observe(
  184. name = std_name,
  185. var = res[std_name_equp][std_name_point],
  186. observed = observed_data,
  187. sigma = sigma
  188. )
  189. self.param_posterior = pm.find_MAP(maxeval=50000,include_transformed=False)
  190. self.record_load_info(
  191. param_posterior = self.param_posterior
  192. )
  193. self.record_model(
  194. model_name = 'ATD',
  195. model = reorder_posterior(param_prior,self.param_posterior),
  196. train_data = {'x':np.array([1])},
  197. train_metric = {'R2':1,'MAE':1,'MAPE':1}
  198. )
  199. self.TVP_data = self.get_TVP(self.param_posterior,observed_data)
  200. self.TVP_metric = self.get_metric(self.TVP_data)
  201. if plot_TVP:
  202. self.plot_TVP(self.TVP_data).show()
  203. return self
  204. @property
  205. def F_air_val_rw(self):
  206. return self.model_info['model_ATD']['F_air']['val_rw']
  207. def set_F_air_val_rw(self,value:float):
  208. self.model_info['model_ATD']['F_air']['val_rw'] = value
  209. return self
  210. def clean_data(
  211. self,
  212. data : pd.DataFrame,
  213. data_type : list=['input','observed'],
  214. print_process: bool = True,
  215. fill_zero : bool = False,
  216. save_log : Union[str,None] = None
  217. ) -> pd.DataFrame:
  218. data = data.replace(-9999,np.nan)
  219. clean_data = DataCleaner(data,print_process=print_process)
  220. if 'input' in data_type:
  221. clean_data = (
  222. clean_data
  223. .rm_rolling_fluct(window=60,fun='ptp',thre=0.1,include_cols=['State'])
  224. .rm_rule('State != 1')
  225. .rm_outrange(method='raw',upper=140,lower=20,include_cols=['wheel_1_TinR','wheel_2_TinR'])
  226. )
  227. if self.DHU_type == 'A':
  228. clean_data = (
  229. clean_data
  230. .rm_rule('wheel_1_ToutC<=coil_1_ToutA')
  231. )
  232. if 'observed' in data_type:
  233. pass
  234. clean_data = clean_data.get_data(
  235. fill = 0 if fill_zero else None,
  236. save_log = save_log
  237. )
  238. return clean_data
  239. def optimize(
  240. self,
  241. cur_input_data: pd.DataFrame,
  242. wheel_1_TinR : tuple = (70,120),
  243. wheel_2_TinR : tuple = (70,120),
  244. fan_2_Hz : tuple = (30,50),
  245. constrains : list = None,
  246. logging : bool = True,
  247. target : str = 'summary_Fs',
  248. target_min : bool = True
  249. ) -> list:
  250. constrains = [] if constrains is None else constrains
  251. cur_input_data = cur_input_data.iloc[[0],:]
  252. opt_var_boundary = {}
  253. if wheel_1_TinR is not None:
  254. opt_var_boundary['wheel_1_TinR'] = {'lb':min(wheel_1_TinR),'ub':max(wheel_1_TinR)}
  255. if wheel_2_TinR is not None:
  256. opt_var_boundary['wheel_2_TinR'] = {'lb':min(wheel_2_TinR),'ub':max(wheel_2_TinR)}
  257. if fan_2_Hz is not None:
  258. opt_var_boundary['fan_2_Hz'] = {'lb':min(fan_2_Hz),'ub':max(fan_2_Hz)}
  259. opt_var_value = cur_input_data.loc[:,list(opt_var_boundary.keys())]
  260. oth_var_value = (
  261. cur_input_data
  262. .loc[:,list(self.model_input_data_columns.values())]
  263. .drop(opt_var_value.columns,axis=1)
  264. )
  265. opt_res = optimizer(
  266. model = self,
  267. opt_var_boundary = opt_var_boundary,
  268. opt_var_value = opt_var_value,
  269. oth_var_value = oth_var_value,
  270. target = target,
  271. target_min = target_min,
  272. constrains = constrains,
  273. logging = logging,
  274. other_kwargs = {'NIND':2000,'MAXGEN':50}
  275. )
  276. return opt_res
  277. def model(self,*args,**kwargs):
  278. if self.DHU_type == 'A':
  279. return model_A(*args,**kwargs)
  280. elif self.DHU_type == 'B':
  281. return model_B(*args,**kwargs)
  282. else:
  283. raise ValueError('DHU_type must be A or B')
  284. def plot_opt(
  285. self,
  286. cur_input_data: pd.DataFrame,
  287. target_min : str = 'summary_waste',
  288. ):
  289. data_input = (
  290. pd.MultiIndex.from_product(
  291. [
  292. np.linspace(70,120,1000),
  293. np.linspace(70,120,1000),
  294. ],
  295. names=['wheel_1_TinR','wheel_2_TinR']
  296. )
  297. .to_frame(index=False)
  298. )
  299. for col in cur_input_data.columns:
  300. if col in data_input.columns:
  301. continue
  302. data_input[col] = cur_input_data.loc[:,col].iat[0]
  303. data_output = self.predict_system(data_input)
  304. data = (
  305. data_output
  306. .assign(
  307. wheel_1_TinR = data_input.loc[:,'wheel_1_TinR'],
  308. wheel_2_TinR = data_input.loc[:,'wheel_2_TinR'],
  309. )
  310. .assign(coil_3_DoutA=lambda dt:dt.coil_3_DoutA.round(1))
  311. .loc[lambda dt:dt.groupby('coil_3_DoutA')[target_min].idxmin()]
  312. .loc[lambda dt:dt.coil_3_DoutA.mod(1)==0]
  313. )
  314. import plotnine as gg
  315. plot = (
  316. data
  317. .pipe(gg.ggplot)
  318. + gg.aes(x='wheel_1_TinR',y='wheel_2_TinR')
  319. + gg.geom_path(size=1)
  320. + gg.geom_point()
  321. + gg.geom_label(gg.aes(label='coil_3_DoutA'))
  322. + gg.geom_abline(slope=1,intercept=0,color='red',linetype='--')
  323. )
  324. return plot
  325. def plot_check(self,cur_input_data:pd.DataFrame) -> dict:
  326. pa1=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_DoutP')
  327. pa2=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_ToutP')
  328. pa3=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_EFF')
  329. pb1=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_DoutP')
  330. pb2=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_ToutP')
  331. pb3=self.curve(input_data=cur_input_data,x='wheel_2_TinR',y='wheel_2_EFF')
  332. plot_EFF = (pa1|pa2|pa3)/(pb1|pb2|pb3)
  333. p1=self.curve(x='wheel_1_TinR',y='summary_waste_cond1',input_data=cur_input_data)
  334. p2=self.curve(x='wheel_2_TinR',y='summary_waste_cond2',input_data=cur_input_data)
  335. p3=self.curve(x='wheel_1_TinR',y='summary_waste_Qsen1',input_data=cur_input_data)
  336. p4=self.curve(x='wheel_2_TinR',y='summary_waste_Qsen2',input_data=cur_input_data)
  337. p5=self.curve(x='wheel_1_TinR',y='summary_waste_out',input_data=cur_input_data)
  338. p6=self.curve(x='wheel_2_TinR',y='summary_waste_out',input_data=cur_input_data)
  339. plot_waste = (p1|p3|p5)/(p2|p4|p6)
  340. return {'plot_EFF':plot_EFF,'plot_waste':plot_waste}
  341. def model_A(
  342. Tin_F, # 前表冷后温度
  343. Hin_F, # 前表冷后湿度
  344. fan_1_Hz, # 处理侧风机频率
  345. fan_2_Hz, # 再生侧风机频率
  346. coil_1_TinW, # 前表冷进水温度
  347. coil_2_TinW, # 中表冷进水温度
  348. coil_3_TinW, # 后表冷进水温度
  349. coil_1_Val, # 前表冷阀门开度
  350. coil_2_Val, # 中表冷阀门开度
  351. coil_3_Val, # 后表冷阀门开度
  352. wheel_1_TinR, # 前转轮再生侧温度
  353. wheel_2_TinR, # 后转轮再生侧温度
  354. engine : str,
  355. components: dict,
  356. param : dict,
  357. mixed_1_TinM = 0, # 回风温度(处理侧)
  358. mixed_1_HinM = 0, # 回风湿度(处理侧)
  359. mixed_2_TinM = 0, # 补风温度(再生侧)
  360. mixed_2_HinM = 0, # 补风湿度(再生侧)
  361. ) -> dict:
  362. # 水的质量流量
  363. coil_2_FW = coil_2_Val / 100
  364. coil_3_FW = coil_3_Val / 100
  365. # 空气的质量流量
  366. air_flow = AirFlow_DHU_AB.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param,type='DHU_A')
  367. # 前转轮
  368. wheel_1_res = components['wheel_1'].model(
  369. TinP = Tin_F,
  370. HinP = Hin_F,
  371. FP = air_flow['wheel_1_FaP'],
  372. TinR = wheel_1_TinR,
  373. HinR = 0,
  374. FR = air_flow['wheel_1_FaR'],
  375. TinC = Tin_F,
  376. HinC = Hin_F,
  377. FC = air_flow['wheel_1_FaC'],
  378. engine = engine,
  379. param = param['wheel_1']
  380. )
  381. # 处理侧混风(回风)
  382. mixed_1_res = components['mixed_1'].model(
  383. TinA = wheel_1_res['ToutP'],
  384. HinA = wheel_1_res['HoutP'],
  385. FA = air_flow['mixed_1_FaA'],
  386. TinM = mixed_1_TinM,
  387. HinM = mixed_1_HinM,
  388. FM = air_flow['mixed_1_FaM'],
  389. engine = engine
  390. )
  391. # 中表冷
  392. coil_2_res = components['coil_2'].model(
  393. TinA = mixed_1_res['ToutA'],
  394. HinA = mixed_1_res['HoutA'],
  395. FA = air_flow['coil_2_FaA'],
  396. TinW = coil_2_TinW,
  397. FW = coil_2_FW,
  398. engine = engine,
  399. param = param['coil_2']
  400. )
  401. # 后转轮
  402. wheel_2_res = components['wheel_2'].model(
  403. TinP = coil_2_res['ToutA'],
  404. HinP = coil_2_res['HoutA'],
  405. FP = air_flow['wheel_2_FaP'],
  406. TinC = wheel_1_res['ToutC'],
  407. HinC = wheel_1_res['HoutC'],
  408. FC = air_flow['wheel_2_FaC'],
  409. TinR = wheel_2_TinR,
  410. HinR = 0,
  411. FR = air_flow['wheel_2_FaR'],
  412. engine = engine,
  413. param = param['wheel_2'],
  414. )
  415. # 后表冷
  416. coil_3_res = components['coil_3'].model(
  417. TinA = wheel_2_res['ToutP'],
  418. HinA = wheel_2_res['HoutP'],
  419. FA = air_flow['coil_3_FaA'],
  420. TinW = coil_3_TinW,
  421. FW = coil_3_FW,
  422. engine = engine,
  423. param = param['coil_3']
  424. )
  425. # 后转轮湿度修正
  426. wheel_2_res_adj = components['wheel_2'].model(
  427. TinP = coil_2_res['ToutA'],
  428. HinP = coil_2_res['HoutA'],
  429. FP = air_flow['wheel_2_FaP'],
  430. TinC = wheel_1_res['ToutC'],
  431. HinC = wheel_1_res['HoutC'],
  432. FC = air_flow['wheel_2_FaC'],
  433. TinR = wheel_2_TinR,
  434. HinR = wheel_2_res['HoutC'],
  435. FR = air_flow['wheel_2_FaR'],
  436. engine = engine,
  437. param = param['wheel_2'],
  438. )
  439. # 再生侧混风(排风)
  440. mixed_2_res = components['mixed_2'].model(
  441. TinA = wheel_2_res_adj['ToutR'],
  442. HinA = wheel_2_res_adj['HoutR'],
  443. FA = air_flow['mixed_2_FaA'],
  444. TinM = mixed_2_TinM,
  445. HinM = mixed_2_HinM,
  446. FM = air_flow['mixed_2_FaM'],
  447. engine = engine
  448. )
  449. # 前转轮湿度修正
  450. wheel_1_res_adj = components['wheel_1'].model(
  451. TinP = Tin_F,
  452. HinP = Hin_F,
  453. FP = air_flow['wheel_1_FaP'],
  454. TinR = wheel_1_TinR,
  455. HinR = mixed_2_res['HoutA'],
  456. FR = air_flow['wheel_1_FaR'],
  457. TinC = Tin_F,
  458. HinC = Hin_F,
  459. FC = air_flow['wheel_1_FaC'],
  460. engine = engine,
  461. param = param['wheel_1']
  462. )
  463. # 前再生加热盘管
  464. heatingcoil_1_res = components['heatingcoil_1'].model(
  465. TinA = mixed_2_res['ToutA'],
  466. ToutA = wheel_1_TinR,
  467. FA = air_flow['heatingcoil_1_Fa'],
  468. param = param['heatingcoil_1'],
  469. engine = engine
  470. )
  471. # 后再生加热盘管
  472. heatingcoil_2_res = components['heatingcoil_2'].model(
  473. TinA = wheel_2_res_adj['ToutC'],
  474. ToutA = wheel_2_TinR,
  475. FA = air_flow['heatingcoil_2_Fa'],
  476. param = param['heatingcoil_2'],
  477. engine = engine
  478. )
  479. waste = cal_Q_waste(
  480. wheel_1_res = wheel_1_res_adj,
  481. wheel_2_res = wheel_2_res_adj,
  482. heatingcoil_1_res = heatingcoil_1_res,
  483. heatingcoil_2_res = heatingcoil_2_res,
  484. wheel_1_TinR = wheel_1_TinR,
  485. wheel_2_TinR = wheel_2_TinR
  486. )
  487. return {
  488. 'coil_2' : coil_2_res,
  489. 'coil_3' : coil_3_res,
  490. 'wheel_1' : wheel_1_res_adj,
  491. 'wheel_2' : wheel_2_res_adj,
  492. 'mixed_1' : mixed_1_res,
  493. 'mixed_2' : mixed_2_res,
  494. 'heatingcoil_1': heatingcoil_1_res,
  495. 'heatingcoil_2': heatingcoil_2_res,
  496. 'Fa' : air_flow,
  497. 'summary' : {
  498. 'Fs' : heatingcoil_1_res['Fs'] + heatingcoil_2_res['Fs'],
  499. **waste,
  500. }
  501. }
  502. def model_B(
  503. Tin_F, # 前表冷后温度
  504. Hin_F, # 前表冷后湿度
  505. fan_1_Hz, # 处理侧风机频率
  506. fan_2_Hz, # 再生侧风机频率
  507. coil_1_TinW, # 前表冷进水温度
  508. coil_2_TinW, # 中表冷进水温度
  509. coil_3_TinW, # 后表冷进水温度
  510. coil_1_Val, # 前表冷阀门开度
  511. coil_2_Val, # 中表冷阀门开度
  512. coil_3_Val, # 后表冷阀门开度
  513. wheel_1_TinR, # 前转轮再生侧温度
  514. wheel_2_TinR, # 后转轮再生侧温度
  515. engine : str,
  516. components: dict,
  517. param : dict,
  518. mixed_1_TinM = 0, # 回风温度(处理侧)
  519. mixed_1_HinM = 0, # 回风湿度(处理侧)
  520. mixed_2_TinM = 0, # 补风温度(再生侧)
  521. mixed_2_HinM = 0, # 补风湿度(再生侧)
  522. ) -> dict:
  523. # 水的质量流量
  524. coil_2_FW = coil_2_Val / 100
  525. coil_3_FW = coil_3_Val / 100
  526. # 空气的质量流量
  527. air_flow = AirFlow_DHU_AB.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param,type='DHU_B')
  528. # 前转轮
  529. wheel_1_res = components['wheel_1'].model(
  530. TinP = Tin_F,
  531. HinP = Hin_F,
  532. FP = air_flow['wheel_1_FaP'],
  533. TinR = wheel_1_TinR,
  534. HinR = 0,
  535. FR = air_flow['wheel_1_FaR'],
  536. engine = engine,
  537. param = param['wheel_1'],
  538. )
  539. # 处理侧混风(回风)
  540. mixed_1_res = components['mixed_1'].model(
  541. TinA = wheel_1_res['ToutP'],
  542. HinA = wheel_1_res['HoutP'],
  543. FA = air_flow['mixed_1_FaA'],
  544. TinM = mixed_1_TinM,
  545. HinM = mixed_1_HinM,
  546. FM = air_flow['mixed_1_FaM'],
  547. engine = engine
  548. )
  549. # 中表冷
  550. coil_2_res = components['coil_2'].model(
  551. TinA = mixed_1_res['ToutA'],
  552. HinA = mixed_1_res['HoutA'],
  553. FA = air_flow['coil_2_FaA'],
  554. TinW = coil_2_TinW,
  555. FW = coil_2_FW,
  556. engine = engine,
  557. param = param['coil_2']
  558. )
  559. # 后转轮
  560. wheel_2_res = components['wheel_2'].model(
  561. TinP = coil_2_res['ToutA'],
  562. HinP = coil_2_res['HoutA'],
  563. FP = air_flow['wheel_2_FaP'],
  564. TinC = mixed_1_res['ToutA'],
  565. HinC = mixed_1_res['HoutA'],
  566. FC = air_flow['wheel_2_FaC'],
  567. TinR = wheel_2_TinR,
  568. HinR = 0,
  569. FR = air_flow['wheel_2_FaR'],
  570. engine = engine,
  571. param = param['wheel_2'],
  572. )
  573. # 后表冷
  574. coil_3_res = components['coil_3'].model(
  575. TinA = wheel_2_res['ToutP'],
  576. HinA = wheel_2_res['HoutP'],
  577. FA = air_flow['coil_3_FaA'],
  578. TinW = coil_3_TinW,
  579. FW = coil_3_FW,
  580. engine = engine,
  581. param = param['coil_3']
  582. )
  583. # 后转轮湿度修正
  584. wheel_2_res_adj = components['wheel_2'].model(
  585. TinP = coil_2_res['ToutA'],
  586. HinP = coil_2_res['HoutA'],
  587. FP = air_flow['wheel_2_FaP'],
  588. TinC = mixed_1_res['ToutA'],
  589. HinC = mixed_1_res['HoutA'],
  590. FC = air_flow['wheel_2_FaC'],
  591. TinR = wheel_2_TinR,
  592. HinR = wheel_2_res['HoutC'],
  593. FR = air_flow['wheel_2_FaR'],
  594. engine = engine,
  595. param = param['wheel_2'],
  596. )
  597. # 再生侧混风(排风)
  598. mixed_2_res = components['mixed_2'].model(
  599. TinA = wheel_2_res_adj['ToutR'],
  600. HinA = wheel_2_res_adj['HoutR'],
  601. FA = air_flow['mixed_2_FaA'],
  602. TinM = mixed_2_TinM,
  603. HinM = mixed_2_HinM,
  604. FM = air_flow['mixed_2_FaM'],
  605. engine = engine
  606. )
  607. # 前转轮湿度修正
  608. wheel_1_res_adj = components['wheel_1'].model(
  609. TinP = Tin_F,
  610. HinP = Hin_F,
  611. FP = air_flow['wheel_1_FaP'],
  612. TinR = wheel_1_TinR,
  613. HinR = mixed_2_res['HoutA'],
  614. FR = air_flow['wheel_1_FaR'],
  615. engine = engine,
  616. param = param['wheel_1'],
  617. )
  618. # 前蒸气盘管
  619. heatingcoil_1_res = components['heatingcoil_1'].model(
  620. TinA = mixed_2_res['ToutA'],
  621. ToutA = wheel_1_TinR,
  622. FA = air_flow['heatingcoil_1_Fa'],
  623. param = param['heatingcoil_1'],
  624. engine = engine
  625. )
  626. # 后蒸气盘管
  627. heatingcoil_2_res = components['heatingcoil_2'].model(
  628. TinA = wheel_2_res_adj['ToutC'],
  629. ToutA = wheel_2_TinR,
  630. FA = air_flow['heatingcoil_2_Fa'],
  631. param = param['heatingcoil_2'],
  632. engine = engine
  633. )
  634. waste = cal_Q_waste(
  635. wheel_1_res = wheel_1_res_adj,
  636. wheel_2_res = wheel_2_res_adj,
  637. heatingcoil_1_res = heatingcoil_1_res,
  638. heatingcoil_2_res = heatingcoil_2_res,
  639. wheel_1_TinR = wheel_1_TinR,
  640. wheel_2_TinR = wheel_2_TinR
  641. )
  642. return {
  643. 'coil_2' : coil_2_res,
  644. 'coil_3' : coil_3_res,
  645. 'wheel_1' : wheel_1_res_adj,
  646. 'wheel_2' : wheel_2_res_adj,
  647. 'mixed_1' : mixed_1_res,
  648. 'mixed_2' : mixed_2_res,
  649. 'heatingcoil_1': heatingcoil_1_res,
  650. 'heatingcoil_2': heatingcoil_2_res,
  651. 'Fa' : air_flow,
  652. 'summary' : {
  653. 'Fs' : heatingcoil_1_res['Fs'] + heatingcoil_2_res['Fs'],
  654. **waste
  655. }
  656. }
  657. class AirFlow_DHU_AB:
  658. @classmethod
  659. def model(cls,fan_1_Hz,fan_2_Hz,param,type):
  660. # 当定频风机固定的时候,各出入口处的基准的风量
  661. F_air_S_base = 1
  662. F_air_X_base = param['F_air']['X_base']
  663. F_air_H_base = param['F_air'].get('H_base',0)
  664. F_air_B_base = param['F_air'].get('B_base',0)
  665. F_air_val_rw = param['F_air'].get('val_rw',0)
  666. F_air_val_pct = param['F_air'].get('val_pct',0)
  667. # 新风阀的变化造成的基准风量变化
  668. F_air_S_base_adj = F_air_S_base
  669. F_air_X_base_adj = F_air_X_base + F_air_val_rw
  670. 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
  671. 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
  672. # 考虑风机频率变化对风量的影响,得到最终风量
  673. F_air_HzP_X = param['F_air']['HzP_X']
  674. F_air_HzP_H = param['F_air'].get('HzP_H',0)
  675. F_air_HzP_S = F_air_HzP_X + F_air_HzP_H
  676. F_air_HzR_B = param['F_air'].get('HzR_B',0)
  677. Fa_S = F_air_S_base_adj + F_air_HzP_S * (fan_1_Hz / 50)
  678. Fa_H = F_air_H_base_adj + F_air_HzP_H * (fan_1_Hz / 50)
  679. Fa_X = F_air_X_base_adj + F_air_HzP_X * (fan_1_Hz / 50)
  680. Fa_B = F_air_B_base_adj + F_air_HzR_B * (fan_2_Hz / 50)
  681. Fa_P = Fa_B + Fa_X + Fa_H - Fa_S
  682. if type == 'DHU_A':
  683. wheel_1_FaP = Fa_S - Fa_H
  684. wheel_1_FaC = Fa_X - wheel_1_FaP
  685. wheel_1_FaR = Fa_P
  686. wheel_2_FaP = Fa_S
  687. wheel_2_FaC = wheel_1_FaC
  688. wheel_2_FaR = wheel_1_FaC
  689. mixed_1_FaM = Fa_H
  690. mixed_1_FaA = wheel_1_FaP
  691. mixed_2_FaM = Fa_B
  692. mixed_2_FaA = wheel_1_FaC
  693. coil_2_FaA = Fa_S
  694. coil_3_FaA = Fa_S
  695. heatingcoil_1_Fa = Fa_P
  696. heatingcoil_2_Fa = wheel_1_FaC
  697. elif type == 'DHU_B':
  698. wheel_1_FaP = Fa_X
  699. wheel_1_FaC = np.nan
  700. wheel_1_FaR = Fa_P
  701. wheel_2_FaP = Fa_S
  702. wheel_2_FaC = Fa_X + Fa_H - Fa_S
  703. wheel_2_FaR = wheel_2_FaC
  704. mixed_1_FaM = Fa_H
  705. mixed_1_FaA = Fa_X
  706. mixed_2_FaM = Fa_B
  707. mixed_2_FaA = wheel_2_FaC
  708. coil_2_FaA = Fa_S
  709. coil_3_FaA = Fa_S
  710. heatingcoil_1_Fa = Fa_P
  711. heatingcoil_2_Fa = wheel_2_FaC
  712. else:
  713. raise Exception('type error')
  714. return {
  715. 'Fa_S':Fa_S,'Fa_H':Fa_H,'Fa_X':Fa_X,'Fa_B':Fa_B,'Fa_P':Fa_P,
  716. 'wheel_1_FaP':wheel_1_FaP,'wheel_1_FaC':wheel_1_FaC,'wheel_1_FaR':wheel_1_FaR,
  717. 'wheel_2_FaP':wheel_2_FaP,'wheel_2_FaC':wheel_2_FaC,'wheel_2_FaR':wheel_2_FaR,
  718. 'mixed_1_FaM':mixed_1_FaM,'mixed_1_FaA':mixed_1_FaA,
  719. 'mixed_2_FaM':mixed_2_FaM,'mixed_2_FaA':mixed_2_FaA,
  720. 'coil_2_FaA':coil_2_FaA,'coil_3_FaA':coil_3_FaA,
  721. 'heatingcoil_1_Fa':heatingcoil_1_Fa,'heatingcoil_2_Fa':heatingcoil_2_Fa
  722. }
  723. @classmethod
  724. def prior(
  725. cls,
  726. rw_FA_val : bool,
  727. N : int,
  728. exist_Fa_H: bool,
  729. exist_Fa_B: bool
  730. ) -> dict:
  731. param = {}
  732. # 新风参数
  733. param['HzP_X'] = pm.HalfNormal('F_air_HzP_X',sigma=1,initval=1)
  734. param['X_base'] = pm.TruncatedNormal('F_air_X_base',mu=0.5,sigma=0.2,lower=0,initval=0.5)
  735. if exist_Fa_H:
  736. param['HzP_H'] = pm.HalfNormal('F_air_HzP_H',sigma=1,initval=0.1)
  737. param['H_base'] = pm.TruncatedNormal('F_air_H_base',mu=0.6,sigma=0.2,lower=0,upper=0.999,initval=0.6)
  738. if exist_Fa_B:
  739. param['HzR_B'] = pm.HalfNormal('F_air_HzR_B',sigma=1,initval=0.5)
  740. param['B_base'] = pm.TruncatedNormal('F_air_B_base',mu=0.2,sigma=0.1,lower=0,initval=0.1)
  741. if rw_FA_val:
  742. period = 48
  743. n_segments = int(np.ceil(N/period))
  744. remainder = N % period
  745. repeat = [period] * (n_segments - 1) + ([remainder] if remainder != 0 else [])
  746. rw = pm.GaussianRandomWalk(
  747. 'rw',sigma=0.1,init_dist=pm.Normal.dist(mu=0,sigma=0.3),shape=n_segments)
  748. param['val_rw'] = pm.Deterministic('F_air_val_rw',pt.repeat(rw,repeat))
  749. param['val_pct'] = pm.Beta('F_air_val_pct',alpha=8,beta=1,initval=0.9)
  750. # 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]))
  751. else:
  752. param['val_rw'] = 0
  753. param['val_pct'] = 0
  754. return param
  755. def cal_Q_waste(
  756. wheel_1_res,
  757. wheel_2_res,
  758. heatingcoil_1_res,
  759. heatingcoil_2_res,
  760. wheel_1_TinR,
  761. wheel_2_TinR
  762. ):
  763. waste_Qsen1 = wheel_1_res['Qsen']
  764. waste_Qsen2 = wheel_2_res['Qsen']
  765. waste_cond1 = heatingcoil_1_res['Q'] * (0.15 + 0.0001 * (wheel_1_TinR-70)**2)
  766. waste_cond2 = heatingcoil_2_res['Q'] * (0.15 + 0.0001 * (wheel_2_TinR-70)**2)
  767. waste_out = (
  768. heatingcoil_1_res['Q'] + heatingcoil_2_res['Q']
  769. - wheel_1_res['Qsen'] - wheel_1_res['Qlat']
  770. - wheel_2_res['Qsen'] - wheel_2_res['Qlat']
  771. )
  772. return {
  773. 'waste_Qsen1': waste_Qsen1,
  774. 'waste_Qsen2': waste_Qsen2,
  775. 'waste_Qout' : waste_out,
  776. 'waste_cond1': waste_cond1,
  777. 'waste_cond2': waste_cond2,
  778. 'waste_out' : waste_out,
  779. 'waste' : waste_Qsen1+waste_cond2+waste_cond1+waste_cond2+waste_out,
  780. }