SDHU_AB.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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 SDHU_AB(BaseDevice):
  16. val_rw_adj_target = ('coil_2_ToutA','coil_2_DoutA')
  17. def __init__(
  18. self,
  19. DHU_type = 'A',
  20. exist_Fa_H = True,
  21. wheel_1 = None,
  22. coolingcoil_2 = 'CoolingCoil2',
  23. heatingcoil_1 = 'SteamCoil',
  24. mixed_1 = 'Mixed',
  25. mixed_2 = 'Mixed',
  26. other_info = None
  27. ) -> None:
  28. super().__init__()
  29. self.DHU_type = DHU_type.replace('SDHU_','')
  30. if self.DHU_type == 'A':
  31. wheel_1 = wheel_1 if wheel_1 is not None else 'WheelS3V3'
  32. elif self.DHU_type == 'B':
  33. wheel_1 = wheel_1 if wheel_1 is not None else 'WheelS2V2'
  34. else:
  35. raise Exception('SDHU_type must be A or B')
  36. self.components_str = {
  37. 'wheel_1' : wheel_1,
  38. 'coil_2' : coolingcoil_2,
  39. 'heatingcoil_1': heatingcoil_1,
  40. 'mixed_1' : mixed_1,
  41. 'mixed_2' : mixed_2
  42. }
  43. self.exist_Fa_H = exist_Fa_H
  44. self.other_info = other_info if other_info is not None else {}
  45. self.record_load_info(
  46. components_str = self.components_str,
  47. DHU_type = self.DHU_type,
  48. exist_Fa_H = self.exist_Fa_H,
  49. other_info = self.other_info
  50. )
  51. @property
  52. def components(self):
  53. comp_map = {
  54. 'WheelS2':wheel2,'WheelS3':wheel3,'CoolingCoil':coil_water,
  55. 'SteamCoil':coil_steam,'Mixed':mixed
  56. }
  57. output ={}
  58. for comp_name,comp_model in self.components_str.items():
  59. if comp_model == 'SteamCoilVal':
  60. output[comp_name] = coil_steam.SteamCoilVal(
  61. name = comp_name,
  62. Fs_rated = self.other_info[f'{comp_name}_Fs_rated']
  63. )
  64. continue
  65. for comp_map_k,comp_map_v in comp_map.items():
  66. if comp_model.startswith(comp_map_k):
  67. output[comp_name] = getattr(comp_map_v,comp_model)(name = comp_name)
  68. return output
  69. @property
  70. def model_input_data_columns(self):
  71. columns = {
  72. 'Tin_F' : 'coil_1_ToutA',
  73. 'Hin_F' : 'coil_1_HoutA',
  74. 'fan_1_Hz' : 'fan_1_Hz',
  75. 'fan_2_Hz' : 'fan_2_Hz',
  76. 'coil_2_TinW' : 'coil_2_TinW',
  77. 'coil_2_Val' : 'coil_2_Val',
  78. 'wheel_1_TinR': 'wheel_1_TinR',
  79. }
  80. if self.exist_Fa_H:
  81. columns['mixed_1_TinM'] = 'mixed_1_TinM'
  82. columns['mixed_1_HinM'] = 'mixed_1_HinM'
  83. if self.DHU_type == 'A':
  84. columns['coil_1_ToutA'] = 'coil_1_ToutA'
  85. columns['coil_1_HoutA'] = 'coil_1_HoutA'
  86. return columns
  87. @property
  88. def model_observe_data_columns(self):
  89. columns = {
  90. 'mixed_1_ToutA': 'mixed_1_ToutA',
  91. 'mixed_1_DoutA': 'mixed_1_DoutA',
  92. 'coil_2_ToutA' : 'coil_2_ToutA',
  93. 'coil_2_DoutA' : 'coil_2_DoutA',
  94. }
  95. if self.DHU_type == 'A':
  96. columns['wheel_1_ToutC'] = 'wheel_1_ToutC' # A类除湿机前转轮是三分转轮
  97. exclude_obs = self.other_info.get('exclude_obs',[])
  98. for col in exclude_obs:
  99. if col in columns:
  100. del columns[col]
  101. return columns
  102. def model(self,*args,**kwargs):
  103. if self.DHU_type == 'A':
  104. return model_A(*args,**kwargs)
  105. elif self.DHU_type == 'B':
  106. return model_B(*args,**kwargs)
  107. else:
  108. raise ValueError('DHU_type must be A or B')
  109. def fit(
  110. self,
  111. input_data : pd.DataFrame,
  112. observed_data: pd.DataFrame,
  113. plot_TVP : bool = True,
  114. ):
  115. if len(input_data) < 30:
  116. raise Exception('数据量过少')
  117. with pm.Model() as self.MODEL_PYMC:
  118. param_prior = {name:comp.prior() for name,comp in self.components.items()}
  119. param_prior['F_air'] = AirFlow_SDHU_A.prior(exist_Fa_H = self.exist_Fa_H)
  120. res = self.model(
  121. **{k:input_data.loc[:,v].values for k,v in self.model_input_data_columns.items()},
  122. engine = 'pymc',
  123. components = self.components,
  124. param = param_prior
  125. )
  126. for std_name,name in self.model_observe_data_columns.items():
  127. if name not in observed_data.columns:
  128. raise Exception(f'Missing column: {name}')
  129. observed_data = observed_data.rename(columns={name:std_name})
  130. std_name_equp,std_name_point = std_name.rsplit('_',1)
  131. sigma = 1
  132. observe(
  133. name = std_name,
  134. var = res[std_name_equp][std_name_point],
  135. observed = observed_data,
  136. sigma = sigma
  137. )
  138. self.param_posterior = pm.find_MAP(maxeval=50000,include_transformed=False)
  139. self.record_load_info(param_posterior = self.param_posterior)
  140. self.record_model(
  141. model_name = 'ATD',
  142. model = reorder_posterior(param_prior,self.param_posterior),
  143. train_data = {
  144. 'wheel_1_TinR': observed_data.loc[:,'wheel_1_TinR'].values,
  145. 'fan_2_Hz' : observed_data.loc[:,'fan_2_Hz'].values,
  146. 'coil_2_DoutA': observed_data.loc[:,'coil_2_DoutA'].values,
  147. },
  148. train_metric = {'R2':1,'MAE':1,'MAPE':1}
  149. )
  150. self.TVP_data = self.get_TVP(self.param_posterior,observed_data)
  151. self.TVP_metric = self.get_metric(self.TVP_data)
  152. if plot_TVP:
  153. self.plot_TVP(self.TVP_data).show()
  154. return self
  155. @property
  156. def F_air_val_rw(self):
  157. return None
  158. def set_F_air_val_rw(self,value:float):
  159. return self
  160. def clean_data(
  161. self,
  162. data : pd.DataFrame,
  163. data_type : list=['input','observed'],
  164. print_process: bool = True,
  165. fill_zero : bool = False,
  166. save_log : Union[str,None] = None
  167. ) -> pd.DataFrame:
  168. data = data.replace(-9999,np.nan)
  169. clean_data = DataCleaner(data,print_process=print_process)
  170. filter_columns = []
  171. if 'input' in data_type:
  172. filter_columns += list(self.model_input_data_columns.values())
  173. clean_data = (
  174. clean_data
  175. .rm_rolling_fluct(window=60,fun='ptp',thre=0.1,include_cols=['State'])
  176. .rm_rule('State != 1')
  177. .rm_rule('fan_1_Hz < 10').rm_rule('fan_2_Hz < 10')
  178. .rm_outrange(method='raw',upper=140,lower=20,include_cols=['wheel_1_TinR'])
  179. )
  180. if 'observed' in data_type:
  181. filter_columns += list(self.model_observe_data_columns.values())
  182. clean_data = clean_data.get_data(
  183. fill = 0 if fill_zero else None,
  184. save_log = save_log
  185. )
  186. return clean_data
  187. def optimize(
  188. self,
  189. cur_input_data: pd.DataFrame,
  190. wheel_1_TinR : tuple = (70,120),
  191. fan_2_Hz : tuple = (30,50),
  192. constrains : list = None,
  193. logging : bool = True,
  194. target : str = 'summary_Fs',
  195. target_min : bool = True
  196. ) -> list:
  197. constrains = [] if constrains is None else constrains
  198. cur_input_data = cur_input_data.iloc[[0],:]
  199. opt_var_boundary = {}
  200. if wheel_1_TinR is not None:
  201. opt_var_boundary['wheel_1_TinR'] = {'lb':min(wheel_1_TinR),'ub':max(wheel_1_TinR)}
  202. if fan_2_Hz is not None:
  203. opt_var_boundary['fan_2_Hz'] = {'lb':min(fan_2_Hz),'ub':max(fan_2_Hz)}
  204. opt_var_value = cur_input_data.loc[:,list(opt_var_boundary.keys())]
  205. oth_var_value = (
  206. cur_input_data
  207. .loc[:,list(set(self.model_input_data_columns.values()))]
  208. .drop(opt_var_value.columns,axis=1)
  209. )
  210. opt_res = optimizer(
  211. model = self,
  212. opt_var_boundary = opt_var_boundary,
  213. opt_var_value = opt_var_value,
  214. oth_var_value = oth_var_value,
  215. target = target,
  216. target_min = target_min,
  217. constrains = constrains,
  218. logging = logging,
  219. other_kwargs = {'NIND':2000,'MAXGEN':50}
  220. )
  221. return opt_res
  222. def plot_opt(
  223. self,
  224. cur_input_data: pd.DataFrame,
  225. target_min : str = 'summary_waste',
  226. coil_2_DoutA : tuple = None
  227. ):
  228. if coil_2_DoutA is None:
  229. coil_2_DoutA = (
  230. self.model_info['model_train_info_ATD']['coil_2_DoutA_min'],
  231. self.model_info['model_train_info_ATD']['coil_2_DoutA_max']
  232. )
  233. data_input = (
  234. pd.MultiIndex.from_product(
  235. [
  236. np.linspace(
  237. self.model_info['model_train_info_ATD']['wheel_1_TinR_min']-5,
  238. self.model_info['model_train_info_ATD']['wheel_1_TinR_max']+5,
  239. 1000
  240. ),
  241. np.linspace(
  242. self.model_info['model_train_info_ATD']['fan_2_Hz_min']-5,
  243. self.model_info['model_train_info_ATD']['fan_2_Hz_max']+5,
  244. 1000
  245. ),
  246. ],
  247. names=['wheel_1_TinR','fan_2_Hz']
  248. )
  249. .to_frame(index=False)
  250. )
  251. for col in cur_input_data.columns:
  252. if col in data_input.columns:
  253. continue
  254. data_input[col] = cur_input_data.loc[:,col].iat[0]
  255. data_output = self.predict_system(data_input)
  256. data = (
  257. data_output
  258. .assign(
  259. wheel_1_TinR = data_input.loc[:,'wheel_1_TinR'],
  260. fan_2_Hz = data_input.loc[:,'fan_2_Hz'],
  261. )
  262. .assign(coil_2_DoutA=lambda dt:dt.coil_2_DoutA.round(1))
  263. .loc[lambda dt:dt.coil_2_DoutA.between(*(min(coil_2_DoutA),max(coil_2_DoutA)))]
  264. .loc[lambda dt:dt.groupby('coil_2_DoutA')[target_min].idxmin()]
  265. .loc[lambda dt:dt.coil_2_DoutA.mod(0.5)==0]
  266. )
  267. import plotnine as gg
  268. plot = (
  269. data
  270. .pipe(gg.ggplot)
  271. + gg.aes(x='wheel_1_TinR',y='fan_2_Hz')
  272. + gg.geom_path(size=1)
  273. + gg.geom_point()
  274. + gg.geom_label(gg.aes(label='coil_2_DoutA'))
  275. + gg.geom_abline(slope=1,intercept=0,color='red',linetype='--')
  276. )
  277. return plot
  278. def plot_check(self,cur_input_data:pd.DataFrame) -> dict:
  279. pa1=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_DoutP')
  280. pa2=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_ToutP')
  281. pa3=self.curve(input_data=cur_input_data,x='wheel_1_TinR',y='wheel_1_EFF')
  282. pb1=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_DoutP')
  283. pb2=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_ToutP')
  284. pb3=self.curve(input_data=cur_input_data,x='fan_2_Hz',y='wheel_1_EFF')
  285. plot1 = (pa1|pa2|pa3)/(pb1|pb2|pb3)
  286. return {'plot1':plot1}
  287. def model_A(
  288. Tin_F, # 前表冷后温度
  289. Hin_F, # 前表冷后湿度
  290. coil_1_ToutA,
  291. coil_1_HoutA,
  292. fan_1_Hz, # 处理侧风机频率
  293. fan_2_Hz, # 再生侧风机频率
  294. coil_2_TinW, # 中表冷进水温度
  295. coil_2_Val, # 中表冷阀门开度
  296. wheel_1_TinR, # 前转轮再生侧温度
  297. engine : str,
  298. components: dict,
  299. param : dict,
  300. mixed_1_TinM = 0, # 回风温度(处理侧)
  301. mixed_1_HinM = 0, # 回风湿度(处理侧)
  302. ) -> dict:
  303. # 水的质量流量
  304. coil_2_FW = coil_2_Val / 100
  305. # 空气的质量流量
  306. air_flow = AirFlow_SDHU_A.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param)
  307. # 前转轮
  308. wheel_1_res = components['wheel_1'].model(
  309. TinP = coil_1_ToutA,
  310. HinP = coil_1_HoutA,
  311. FP = air_flow['wheel_1_FaP'],
  312. TinR = wheel_1_TinR,
  313. HinR = 0,
  314. FR = air_flow['wheel_1_FaR'],
  315. TinC = Tin_F,
  316. HinC = Hin_F,
  317. FC = air_flow['wheel_1_FaC'],
  318. engine = engine,
  319. param = param['wheel_1']
  320. )
  321. # 处理侧混风(回风)
  322. mixed_1_res = components['mixed_1'].model(
  323. TinA = wheel_1_res['ToutP'],
  324. HinA = wheel_1_res['HoutP'],
  325. FA = air_flow['mixed_1_FaA'],
  326. TinM = mixed_1_TinM,
  327. HinM = mixed_1_HinM,
  328. FM = air_flow['mixed_1_FaM'],
  329. engine = engine
  330. )
  331. # 中表冷
  332. coil_2_res = components['coil_2'].model(
  333. TinA = mixed_1_res['ToutA'],
  334. HinA = mixed_1_res['HoutA'],
  335. FA = air_flow['coil_2_FaA'],
  336. TinW = coil_2_TinW,
  337. FW = coil_2_FW,
  338. engine = engine,
  339. param = param['coil_2']
  340. )
  341. # 后转轮湿度修正
  342. wheel_1_res_adj = components['wheel_1'].model(
  343. TinP = coil_1_ToutA,
  344. HinP = coil_1_HoutA,
  345. FP = air_flow['wheel_1_FaP'],
  346. TinR = wheel_1_TinR,
  347. HinR = wheel_1_res['HoutC'],
  348. FR = air_flow['wheel_1_FaR'],
  349. TinC = Tin_F,
  350. HinC = Hin_F,
  351. FC = air_flow['wheel_1_FaC'],
  352. engine = engine,
  353. param = param['wheel_1']
  354. )
  355. # 前再生加热盘管
  356. heatingcoil_1_res = components['heatingcoil_1'].model(
  357. TinA = wheel_1_res_adj['ToutC'],
  358. ToutA = wheel_1_TinR,
  359. FA = air_flow['heatingcoil_1_Fa'],
  360. param = param['heatingcoil_1'],
  361. engine = engine
  362. )
  363. waste = cal_Q_waste(
  364. wheel_1_res = wheel_1_res_adj,
  365. heatingcoil_1_res = heatingcoil_1_res,
  366. wheel_1_TinR = wheel_1_TinR,
  367. fan_2_Hz = fan_2_Hz
  368. )
  369. return {
  370. 'coil_2' : coil_2_res,
  371. 'wheel_1' : wheel_1_res_adj,
  372. 'mixed_1' : mixed_1_res,
  373. 'heatingcoil_1': heatingcoil_1_res,
  374. 'Fa' : air_flow,
  375. 'summary' : {
  376. 'Fs' : heatingcoil_1_res['Fs'],
  377. **waste,
  378. }
  379. }
  380. def model_B(
  381. Tin_Fr, # 再生侧入口温度
  382. Hin_Fr, # 再生侧入口湿度
  383. coil_1_ToutA,
  384. coil_1_HoutA,
  385. fan_1_Hz, # 处理侧风机频率
  386. fan_2_Hz, # 再生侧风机频率
  387. coil_2_TinW, # 中表冷进水温度
  388. coil_2_Val, # 中表冷阀门开度
  389. wheel_1_TinR, # 前转轮再生侧温度
  390. engine : str,
  391. components: dict,
  392. param : dict,
  393. mixed_1_TinM = 0, # 回风温度(处理侧)
  394. mixed_1_HinM = 0, # 回风湿度(处理侧)
  395. ) -> dict:
  396. # 水的质量流量
  397. coil_2_FW = coil_2_Val / 100
  398. # 空气的质量流量
  399. air_flow = AirFlow_SDHU_B.model(fan_1_Hz=fan_1_Hz,fan_2_Hz=fan_2_Hz,param=param)
  400. # 前转轮
  401. wheel_1_res = components['wheel_1'].model(
  402. TinP = coil_1_ToutA,
  403. HinP = coil_1_HoutA,
  404. FP = air_flow['wheel_1_FaP'],
  405. TinR = wheel_1_TinR,
  406. HinR = Hin_Fr,
  407. FR = air_flow['wheel_1_FaR'],
  408. engine = engine,
  409. param = param['wheel_1']
  410. )
  411. # 处理侧混风(回风)
  412. mixed_1_res = components['mixed_1'].model(
  413. TinA = wheel_1_res['ToutP'],
  414. HinA = wheel_1_res['HoutP'],
  415. FA = air_flow['mixed_1_FaA'],
  416. TinM = mixed_1_TinM,
  417. HinM = mixed_1_HinM,
  418. FM = air_flow['mixed_1_FaM'],
  419. engine = engine
  420. )
  421. # 中表冷
  422. coil_2_res = components['coil_2'].model(
  423. TinA = mixed_1_res['ToutA'],
  424. HinA = mixed_1_res['HoutA'],
  425. FA = air_flow['coil_2_FaA'],
  426. TinW = coil_2_TinW,
  427. FW = coil_2_FW,
  428. engine = engine,
  429. param = param['coil_2']
  430. )
  431. # 前再生加热盘管
  432. heatingcoil_1_res = components['heatingcoil_1'].model(
  433. TinA = Tin_Fr,
  434. ToutA = wheel_1_TinR,
  435. FA = air_flow['heatingcoil_1_Fa'],
  436. param = param['heatingcoil_1'],
  437. engine = engine
  438. )
  439. waste = cal_Q_waste(
  440. wheel_1_res = wheel_1_res,
  441. heatingcoil_1_res = heatingcoil_1_res,
  442. wheel_1_TinR = wheel_1_TinR,
  443. fan_2_Hz = fan_2_Hz
  444. )
  445. return {
  446. 'coil_2' : coil_2_res,
  447. 'wheel_1' : wheel_1_res,
  448. 'mixed_1' : mixed_1_res,
  449. 'heatingcoil_1': heatingcoil_1_res,
  450. 'Fa' : air_flow,
  451. 'summary' : {
  452. 'Fs' : heatingcoil_1_res['Fs'],
  453. **waste,
  454. }
  455. }
  456. class AirFlow_SDHU_A:
  457. @classmethod
  458. def model(cls,fan_1_Hz,fan_2_Hz,param):
  459. F_air_X2_base = 1 # 进入转轮处理侧的新风量
  460. F_air_H_base = param['F_air'].get('H_base',0)
  461. F_air_P_base = param['F_air']['P_base']
  462. Fa_H = F_air_H_base + (fan_1_Hz/50) * param['F_air'].get('HzP_H',0)
  463. Fa_X2 = F_air_X2_base + (fan_1_Hz/50) * param['F_air']['HzP_X2']
  464. Fa_S = Fa_H + Fa_X2
  465. Fa_P = F_air_P_base + (fan_2_Hz/50) * param['F_air']['HzR_P']
  466. return {
  467. 'wheel_1_FaP' : Fa_X2,
  468. 'wheel_1_FaC' : Fa_P,
  469. 'wheel_1_FaR' : Fa_P,
  470. 'coil_2_FaA' : Fa_S,
  471. 'mixed_1_FaM' : Fa_H,
  472. 'mixed_1_FaA' : Fa_X2,
  473. 'heatingcoil_1_Fa': Fa_P
  474. }
  475. @classmethod
  476. def prior(cls,exist_Fa_H):
  477. param = {}
  478. param['HzP_X2'] = pm.HalfNormal('F_air_HzP_X2',sigma=1,initval=0.5)
  479. param['HzR_P'] = pm.HalfNormal('F_air_HzR_P',sigma=1,initval=0.5)
  480. param['P_base'] = pm.TruncatedNormal('F_air_P_base',mu=1,sigma=0.2,lower=0,initval=1)
  481. if exist_Fa_H:
  482. param['H_base'] = pm.TruncatedNormal('F_air_H_base',mu=1,sigma=0.2,lower=0,initval=1)
  483. param['HzP_H'] = pm.HalfNormal('F_air_HzP_H',sigma=1,initval=0.5)
  484. return param
  485. class AirFlow_SDHU_B:
  486. @classmethod
  487. def model(cls,fan_1_Hz,fan_2_Hz,param):
  488. ...
  489. def cal_Q_waste(
  490. wheel_1_res,
  491. heatingcoil_1_res,
  492. wheel_1_TinR,
  493. fan_2_Hz
  494. ) -> dict:
  495. def waste_cond_func1(TinR):
  496. waste = 0.15 + 0.0001 * (TinR-70)**3
  497. return np.where(waste>0,waste,0)
  498. def waste_cond_func2(TinR):
  499. waste = 0.25 * (1 - np.exp(-0.04 * (TinR - 70)))
  500. return np.where(waste>0,waste,0)
  501. if isinstance(wheel_1_res['Qsen'],np.ndarray):
  502. WHERE = np.where
  503. else:
  504. WHERE = pm.math.switch
  505. heatingcoil_1_Q = heatingcoil_1_res['Q']
  506. heatingcoil_1_Q = WHERE(heatingcoil_1_Q>0,heatingcoil_1_Q,0)
  507. waste_Qsen1 = wheel_1_res['Qsen']
  508. waste_cond1 = heatingcoil_1_Q * waste_cond_func1(wheel_1_TinR)
  509. res = {
  510. 'waste_Qsen1': waste_Qsen1,
  511. 'waste_cond1': waste_cond1,
  512. }
  513. waste_out = heatingcoil_1_Q - wheel_1_res['Qsen'] - wheel_1_res['Qlat']
  514. waste_out = WHERE(waste_out>0,waste_out,0)
  515. waste = waste_Qsen1 + waste_cond1 + waste_out + fan_2_Hz/100
  516. res['waste_out'] = waste_out
  517. res['waste'] = waste
  518. return res