def adiabatic_cooling(ti, rhi, to, rho): V = duct_area * air_velocity * 60 * 60 #Volumetric Air Flow [m3/h] pv = HAPropsSI('P_w', 'T', to, 'P', 101325, 'R', rho) / 100000 # Partial pressure of water vapor va = (287 * ti) / ((1.0135 - pv) * 100000) #[m3/kg of dry air] hi = HAPropsSI('H', 'T', ti, 'P', 101325, 'R', rhi) / 1000 # Inlet Air Enthalpy[kJ/kg of dry air] ho = HAPropsSI('H', 'T', to, 'P', 101325, 'R', rho) / 1000 # Outlet Air Enthalpy[kJ/kg of dry air] W1 = HAPropsSI('W', 'T', ti, 'P', 101325, 'R', rhi) #[kg/kg of dry air] W2 = HAPropsSI('W', 'T', to, 'P', 101325, 'R', rho) #[kg/kg of dry air] spray_water = (W2 - W1) / va # amount_of_water_required_per_hour = spray_water * V #[kg/h] Qadiabatic = abs(p_air * (ho - hi) * V / 3600) print('\n') print('Air Volumetric Rate = {:.2f} m3/h'.format(V)) print('Inlet Air Enthalpy = {:.3f} kJ/kg of dry air'.format(hi)) print('Outlet Air Enthalpy = {:.3f} kJ/kg of dry air'.format(ho)) print('Partial Pressure of Water Vapour = {:.3f} bar'.format(pv)) print('Specific Humidity Inlet Air = {:.5f} kg/kg of dry air'.format(W1)) print('Specific Humidity Outlet Air = {:.5f} kg/kg of dry air'.format(W2)) print('Spray Water = {:.5f} kg of moisture/m3 of air'.format(spray_water)) print('Amount of Water Required per hour = {:.3f} kg/h'.format( amount_of_water_required_per_hour)) print('Adiabatic Cooler Power Output = {:.2f} kW'.format(Qadiabatic)) print('\n')
def plot(self,ax): for H in self.H_values: #Line goes from saturation to zero humidity ratio for this enthalpy T1 = HAPropsSI('T','H',H,'P',p,'R',1.0)-273.15 T0 = HAPropsSI('T','H',H,'P',p,'R',0.0)-273.15 w1 = HAPropsSI('W','H',H,'P',p,'R',1.0) w0 = HAPropsSI('W','H',H,'P',p,'R',0.0) ax.plot(numpy.r_[T1,T0],numpy.r_[w1,w0],'r',lw=1)
def plot(self,ax): xv = Tdb #[K] for RH in self.RH_values: yv = [HAPropsSI('W','T',T,'P',p,'R',RH) for T in Tdb] y = HAPropsSI('W','P',p,'H',self.h,'R',RH) T_K,w,rot = InlineLabel(xv, yv, y=y, axis = ax) string = r'$\phi$='+'{s:0.0f}'.format(s=RH*100)+'%' #Make a temporary label to get its bounding box bbox_opts = dict(boxstyle='square,pad=0.0',fc='white',ec='None',alpha = 0.5) ax.text(T_K-273.15,w,string,rotation = rot,ha ='center',va='center',bbox=bbox_opts)
def gibbs_HA(T,P,W, T_0): # This function calculates the flow exergy of a humid air mixture, on a basis of humid air # When T_0 = T, the specific gibbs function is equivalent to the flow exergy. # T: Temperature in K # P: Pressure in Pa # rh: Relative humidity [0,1] # T_0: Dead state temperature h = HAPropsSI('Hha','T', T, 'P', P, 'W',W) s = HAPropsSI('Sha','T', T, 'P', P, 'W',W) g = h-T_0*s return g
def calc_prop_of(counter, xdata, ydata): a = 'Point: ' + str(counter + 1) b = "-- R = " + str( round(100 * HAPropsSI('R', 'T', xdata + 273, 'P', 101325, 'W', ydata), 2)) + ' %' c = '-- T = ' + str(round(xdata, 2)) + ' [C]' d = '-- W = ' + str(round(ydata, 4)) e = '-- H = ' + str( round( (HAPropsSI('H', 'T', xdata + 273, 'P', 101325, 'W', ydata) / 1000), 3)) + ' kJ/kg' # f =' W = '+ str(100*HAPropsSI('Twb','T',xdata+273,'P',101325,'W',ydata)) +' [C]' return (str(a + b + c + d + e))
def calc_prop(self, xdata, ydata): # from CoolProp.HumidAirProp import HAPropsSI a = 'Point: ' + str(self.counter + 1) b = "'-- R = " + str( round( 100 * HAPropsSI('R', 'T', xdata + 273, 'P', 101325, 'W', ydata), 2)) + ' %' c = '-- T = ' + str(round(xdata, 2)) + ' [C]' d = '-- W = ' + str(round(ydata, 4)) e = '-- H = ' + str( round((HAPropsSI('H', 'T', xdata + 273, 'P', 101325, 'W', ydata) / 1000), 3)) + ' kJ/kg' # f =' W = '+ str(100*HAPropsSI('Twb','T',xdata+273,'P',101325,'W',ydata)) +' [C]' return (str(a + b + c + d + e))
def min_recovery(T,rh): recovery = np.linspace(0.01,0.9,20) DEW = [] rec = [] for r in recovery: W = HAPropsSI('W', 'T', T, 'P', P, 'R', rh) dw = r*W W_reject = W * (1 - r) T_dp = HAPropsSI('D', 'T', T, 'P', P, 'W', W_reject) if T_dp > 273.1: rec.append(r) DEW.append(calcDcooling(T,P,W,r)) loc = np.argmin(DEW) min_r = recovery[loc] return (min_r)
def calcDcooling(T,P,W,r): # This function calculates the minimum energy requirement for direct cooling without icing, and the optimal recovery ratio # The algorithm finds the maximum recovery to avoid icing. Then it slowly minimizes r until energy is sufficiently minimized # T: Ambient temperature in K # P: Ambient pressure in Pa # rh: Ambient relative humidity [0,1] # r: recovery ratio alpha = 0.005 #Predefined gradient descent coefficient dw = r*W W_reject = W * (1 - r) T_dp = HAPropsSI('D', 'T', T, 'P', P, 'W', W_reject) while T_dp - 273.15 < 5e-4 : r = r*(1-alpha) dw = r*W W_reject = W * (1 - r) T_dp = HAPropsSI('D', 'T', T, 'P', P, 'W', W_reject) if (r <=0): return('end') G_p = gibbs_satv(T_dp, T) G_f = gibbs_HA(T, P, W, T) G_b = gibbs_HA(T_dp, P, W_reject, T) sep = (G_p + G_b * (1 - dw) / dw - G_f / dw) / 1000 sep_new = sep - 1.1e-2 #Small numerical addition to enter the while loop condition r_new = r while sep - sep_new > 1e-2: sep = sep_new r = r_new r_new = r*(1-alpha) dw = r_new*W W_reject = W * (1 - r_new) T_dp = HAPropsSI('D', 'T', T, 'P', P, 'W', W_reject) G_p = gibbs_satv(T_dp, T) G_b = gibbs_HA(T_dp, P, W_reject, T) sep_new = (G_p + G_b * (1 - dw) / dw - G_f / dw) / 1000 if r<= 1e-2: return r,sep return r, sep
def RelativeHumidty( W, Tdb, P=101325 ): # returns relative humidity of air for W:kg/kg humidity ratio and T in Kelvin try: result = HAPropsSI('R', 'W', W, 'T', Tdb, 'P', P) # unitless except ValueError: result = 1.0 return result
def heating_and_cooling(ti, rhi, to, rho, air_velocity, duct_area): V = duct_area * air_velocity # Volumetric Flow Rate [m3/s] pv = HAPropsSI('P_w', 'T', ti, 'P', 101325, 'R', rhi) / 100000 # Partial pressure of water vapor ma = ((1.0135 - pv) * V) * 100000 / (287 * ti) # Air Mass Flow [kg/s] global Wi global Wo Wi = HAPropsSI('W', 'T', ti, 'P', 101325, 'R', rhi) # Inlet Humidity Ratio[kg/kg of dry air] Wo = HAPropsSI('W', 'T', to, 'P', 101325, 'R', rho) # Outlet Humidity Ratio[kg/kg of dry air] hi = HAPropsSI('H', 'T', ti, 'P', 101325, 'R', rhi) / 1000 # Inlet Air Enthalpy [kJ/kg] ho = HAPropsSI('H', 'T', to, 'P', 101325, 'R', rho) / 1000 # Outlet Air Enthalpy [kJ/kg] Qs = Cp * ma * (to - ti) #Sensible Heat Added/Removed from the Air [kW] Ql = hwe * ma * (Wo - Wi) # Latent Heat Added/Removed from the Air [kW] Qt = ma * (ho - hi) # Total Heat Added/Removed from the Air [kW] print('Partial Pressure of Water Vapour = {:.3f} bar'.format(pv)) print('Mass of dry air = {:.2f} kg/s'.format(ma)) print('Inlet Air Humidity Ratio = {:.5f} kg/kg of dry air'.format(Wi)) print('Outlet Air Humidity Ratio = {:.5f} kg/kg of dry air'.format(Wo)) print('Inlet Air Enthalpy = {:.3f} kJ/kg of dry air'.format(hi)) print('Outlet Air Enthalpy = {:.3f} kJ/kg of dry air'.format(ho)) print('Sensible Heat added/removed = {:.3f} kJ/s or kW'.format(Qs)) print('Latent Heat added/removed = {:.3f} kJ/s or kW'.format(Ql)) print('Amount of Heat added/removed = {:.2f} kJ/s or kW'.format(Qt)) print('\n')
def calc_enth(df: pd.DataFrame) -> pd.Series: """Calculate enthalpy. """ Tn = 273.15 # absolute temp. df_drop = df[["air_temperature", "dew_temperature", "sea_level_pressure"]].dropna() # NOTE: unit of temperature and pressure must be [K] and kPa respectively. enth = HAPropsSI("H",\ "T", df_drop["air_temperature"].values + Tn,\ "D", df_drop["dew_temperature"].values + Tn,\ "P", df_drop["sea_level_pressure"].values * 10.0 ) enth = pd.Series(enth, index=df_drop.index) df = df.assign(enth=enth) return df["enth"]
length = 150 # Specifies the resolution of the contour plot T = np.linspace(280,325,length) # Ambient temperature in K W = np.linspace(0.002,0.04,length) # Ambient Relative Humidity [0,1] # Initialize arrays DC = [] recovery = [] T_df = [] relhum = [] abshum = [] r_ref = [] LW = [] # Find the saturation line W_sat = HAPropsSI('W','T',T,'P',P, 'R',1) # Loop through all conditions counter = 0 for hum in W: idx = 0 for temp in T: # Check if the dewpoint is above freezing and the mixture is not super saturated if (HAPropsSI('D', 'T', temp, 'P', P, 'W', hum)>273.2) & (hum<=W_sat[idx]): RH = HAPropsSI('R', 'T', temp, 'P', P, 'W', hum) T_dp = HAPropsSI('D', 'T', temp, 'P', P, 'W', hum) LW.append(calcLW(temp, P, hum, 0.2)) r_temp, dc_temp = calcDcooling(temp,P,hum,0.9) DC.append(dc_temp) recovery.append(r_temp) T_df.append(temp)
def plot_results(my_dataframe): import matplotlib.pyplot import CoolProp.Plots import CoolProp.Plots.PsychChart import CoolProp.Plots.PsychScript #CoolProp.Plots.TwoStage('water',1,Te=280,Tc=300,DTsh=2,DTsc=2,eta_oi=0.9,f_p=0.1,Tsat_ic=290,DTsh_ic=2) matplotlib.pyplot.close('all') if True: from CoolProp.HumidAirProp import HAPropsSI from CoolProp.Plots.Plots import InlineLabel #from CoolProp.Plots.Common import BasePlot #bp = BasePlot() #InlineLabel = bp.inline_label p = 101325 Tdb = numpy.linspace(-10,40,100)+273.15 # Make the figure and the axes fig=matplotlib.pyplot.figure(figsize=(10,8)) ax=fig.add_axes((0.1,0.1,0.85,0.85)) # Saturation line w = [HAPropsSI('W','T',T,'P',p,'R',1.0) for T in Tdb] ax.plot(Tdb-273.15,w,lw=2) # Humidity lines RHValues = [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] for RH in RHValues: w = [HAPropsSI('W','T',T,'P',p,'R',RH) for T in Tdb] ax.plot(Tdb-273.15,w,'r',lw=1) # Humidity lines for H in [-20000, -10000, 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000]: #Line goes from saturation to zero humidity ratio for this enthalpy T1 = HAPropsSI('T','H',H,'P',p,'R',1.0)-273.15 T0 = HAPropsSI('T','H',H,'P',p,'R',0.0)-273.15 w1 = HAPropsSI('W','H',H,'P',p,'R',1.0) w0 = HAPropsSI('W','H',H,'P',p,'R',0.0) ax.plot(numpy.r_[T1,T0],numpy.r_[w1,w0],'r',lw=1) ax.set_xlim(Tdb[0]-273.15,Tdb[-1]-273.15) ax.set_ylim(0,0.03) ax.set_xlabel(r"$T_{db}$ [$^{\circ}$C]") ax.set_ylabel(r"$W$ ($m_{w}/m_{da}$) [-]") xv = Tdb #[K] for RH in [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]: yv = numpy.array([HAPropsSI('W','T',T,'P',p,'R',RH) for T in Tdb]) #y = HAPropsSI('W','P',p,'H',65000.000000,'R',RH) y = HAPropsSI('W','P',p,'H',45000.000000,'R',RH) T_K,w,rot = InlineLabel(xv, yv, y=y, fig=fig, axis = ax) string = r'$\phi$='+'{s:0.0f}'.format(s=RH*100)+'%' bbox_opts = dict(boxstyle='square,pad=0.0',fc='white',ec='None',alpha = 0.9) ax.text(T_K-273.15,w,string,rotation = rot,ha ='center',va='center',bbox=bbox_opts) ax.plot(my_dataframe.T_air-273.15, my_dataframe.HumRat_air, 'k.-') ax.plot(my_dataframe.T_water-273.15, my_dataframe.HumRat_interface, 'm.-') matplotlib.pyplot.show()
def get_real_obs(api_args: dict, meta_data_: dict, obs_space_vars : list, scaler, period, log): try: # arguements for the api query time_args = {'trend_id' : '2681', 'save_path' : 'data/trend_data/alumni_data_deployment.csv'} start_fields = ['start_'+i for i in ['year','month','day', 'hour', 'minute', 'second']] end_fields = ['end_'+i for i in ['year','month','day', 'hour', 'minute', 'second']] end_time = datetime.now(tz=pytz.utc) time_gap_minutes = int((period+3)*5) start_time = end_time - timedelta(minutes=time_gap_minutes) for idx, i in enumerate(start_fields): time_args[i] = start_time.timetuple()[idx] for idx, i in enumerate(end_fields): time_args[i] = end_time.timetuple()[idx] api_args.update(time_args) # pull the data into csv file try: dp.pull_online_data(**api_args) log.info('Deploy Control Module: Deployment Data obtained from API') except Exception: log.info('Deploy Control Module: BdX API could not get data: will resuse old data') # get the dataframe from a csv df_ = read_csv('data/trend_data/alumni_data_deployment.csv', ) df_['time'] = to_datetime(df_['time']) to_zone = tz.tzlocal() df_['time'] = df_['time'].apply(lambda x: x.astimezone(to_zone)) # convert time to loca timezones df_.set_index(keys='time',inplace=True, drop = True) df_ = a_utils.dropNaNrows(df_) # add wet bulb temperature to the data log.info('Deploy Control Module: Start of Wet Bulb Data Calculation') rh = df_['WeatherDataProfile humidity']/100 rh = rh.to_numpy() t_db = 5*(df_['AHU_1 outdoorAirTemp']-32)/9 + 273.15 t_db = t_db.to_numpy() T = HAPropsSI('T_wb','R',rh,'T',t_db,'P',101325) t_f = 9*(T-273.15)/5 + 32 df_['wbt'] = t_f log.info('Deploy Control Module: Wet Bulb Data Calculated') # rename the columns new_names = [] for i in df_.columns: new_names.append(meta_data_["reverse_col_alias"][i]) df_.columns = new_names # collect current set point hist_stpt = df_.loc[df_.index[-1],['sat_stpt']].to_numpy().copy().flatten() # clean the data df_cleaned = dp.online_data_clean( meta_data_ = meta_data_, df = df_ ) # clip less than 0 values df_cleaned.clip(lower=0, inplace=True) # aggregate data rolling_sum_target, rolling_mean_target = [], [] for col_name in df_cleaned.columns: if meta_data_['column_agg_type'][col_name] == 'sum' : rolling_sum_target.append(col_name) else: rolling_mean_target.append(col_name) df_cleaned[rolling_sum_target] = a_utils.window_sum(df_cleaned, window_size=6, column_names=rolling_sum_target) df_cleaned[rolling_mean_target] = a_utils.window_mean(df_cleaned, window_size=6, column_names=rolling_mean_target) df_cleaned = a_utils.dropNaNrows(df_cleaned) # Sample the last half hour data df_cleaned = df_cleaned.iloc[[-1],:] # also need an unscaled version of the observation for logging df_unscaled = df_cleaned.copy() # scale the columns: here we will use min-max df_cleaned[df_cleaned.columns] = scaler.minmax_scale(df_cleaned, df_cleaned.columns, df_cleaned.columns) # create avg_stpt column stpt_cols = [ele for ele in df_cleaned.columns if 'vrf' in ele] df_cleaned['avg_stpt'] = df_cleaned[stpt_cols].mean(axis=1) # drop individual set point cols df_cleaned.drop( columns = stpt_cols, inplace = True) # rearrange observation cols df_cleaned = df_cleaned[obs_space_vars] # create avg_stpt column stpt_cols = [ele for ele in df_unscaled.columns if 'vrf' in ele] df_unscaled['avg_stpt'] = df_unscaled[stpt_cols].mean(axis=1) # drop individual set point cols df_unscaled.drop( columns = stpt_cols, inplace = True) # rearrange observation cols df_unscaled = df_unscaled[obs_space_vars] return df_cleaned, df_unscaled, hist_stpt except Exception as e: log.error('Deploy Control Module: %s', str(e)) log.debug(e, exc_info=True)
# Density of carbon dioxide at 100 bar and 25C D = PropsSI('D', 'T', 298.15, 'P', 100e5, 'CO2') print(D) # Saturated vapor enthalpy [J/kg] of R134a at 25C H = PropsSI('H', 'T', 298.15, 'Q', 1, 'R134a') print(H) #%% # import the things you need from CoolProp.HumidAirProp import HAPropsSI # Enthalpy (J per kg dry air) as a function of temperature, pressure, # and relative humidity at STP h = HAPropsSI('H', 'T', 298.15, 'P', 101325, 'R', 0.5) print(h) # Temperature of saturated air at the previous enthalpy T = HAPropsSI('T', 'P', 101325, 'H', h, 'R', 1.0) print(T) # Temperature of saturated air - order of inputs doesn't matter T = HAPropsSI('T', 'H', h, 'R', 1.0, 'P', 101325) print(T) #%% import CoolProp from CoolProp.Plots import PropertyPlot plot = PropertyPlot('R290', 'ph')
def HotAir(num): from CoolProp.HumidAirProp import HAPropsSI if num=='8': Temp=str(200) T=200+273.15 elif num=='9': Temp=str(320) T=320+273.15 print 'A.'+num+'.1 Psychrometric Properties of Moist Air at 101.325 kPa ' print 'Dry Bulb temperature of '+Temp+'C' s5=' '*5 print '================================================================' print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=s5+' W',Twb=s5+'Twb',v=s5+' v',h=s5+'h',s=s5+' s',R=s5+'RH') print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=' kgw/kg_da',Twb=' C',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',R=' %') print '----------------------------------------------------------------' for W in [0.0,0.05,0.1,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.0]: h=HAPropsSI('H','T',T,'W',W,'P',101325)/1000 Twb=HAPropsSI('Twb','T',T,'W',W,'P',101325)-273.15 R=HAPropsSI('R','T',T,'W',W,'P',101325)*100 v=HAPropsSI('V','T',T,'W',W,'P',101325) s=HAPropsSI('S','T',T,'W',W,'P',101325)/1000 print "{W:10.2f}{Twb:10.2f}{v:10.3f}{h:10.2f}{s:10.4f}{R:10.4f}".format(W=W,Twb=Twb,v=v,h=h,s=s,R=R) print '================================================================' print ' ' print 'A.'+num+'.2 Psychrometric Properties of Moist Air at 1000 kPa ' print 'Dry Bulb temperature of '+Temp+'C' print '================================================================' print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=s5+' W',Twb=s5+'Twb',v=s5+' v',h=s5+'h',s=s5+' s',R=s5+'RH') print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=' kgw/kg_da',Twb=' C',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',R=' %') print '----------------------------------------------------------------' for W in [0.0,0.05,0.1,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.0]: h=HAPropsSI('H','T',T,'W',W,'P',1000e3)/1000 Twb=HAPropsSI('Twb','T',T,'W',W,'P',1000e3)-273.15 R=HAPropsSI('R','T',T,'W',W,'P',1000e3)*100 v=HAPropsSI('V','T',T,'W',W,'P',1000e3) s=HAPropsSI('S','T',T,'W',W,'P',1000e3)/1000 print "{W:10.2f}{Twb:10.2f}{v:10.3f}{h:10.2f}{s:10.4f}{R:10.4f}".format(W=W,Twb=Twb,v=v,h=h,s=s,R=R) print '================================================================' print ' ' s5=' '*5 print 'A.'+num+'.3 Psychrometric Properties of Moist Air at 2000 kPa ' print 'Dry Bulb temperature of '+Temp+'C' print '================================================================' print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=s5+' W',Twb=s5+'Twb',v=s5+' v',h=s5+'h',s=s5+' s',R=s5+'RH') print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=' kgw/kg_da',Twb=' C',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',R=' %') print '----------------------------------------------------------------' for W in [0.0,0.05,0.1,0.20,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.0]: h=HAPropsSI('H','T',T,'W',W,'P',2000e3)/1000 Twb=HAPropsSI('Twb','T',T,'W',W,'P',2000e3)-273.15 R=HAPropsSI('R','T',T,'W',W,'P',2000e3)*100 v=HAPropsSI('V','T',T,'W',W,'P',2000e3) s=HAPropsSI('S','T',T,'W',W,'P',2000e3)/1000 print "{W:10.2f}{Twb:10.2f}{v:10.3f}{h:10.2f}{s:10.4f}{R:10.4f}".format(W=W,Twb=Twb,v=v,h=h,s=s,R=R) print '================================================================' print ' ' s5=' '*5 print 'A.'+num+'.4 Psychrometric Properties of Moist Air at 5000 kPa ' print 'Dry Bulb temperature of '+Temp+'C' print '================================================================' print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=s5+' W',Twb=s5+'Twb',v=s5+' v',h=s5+'h',s=s5+' s',R=s5+'RH') print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=' kgw/kg_da',Twb=' C',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',R=' %') print '----------------------------------------------------------------' if Temp=='200': Wrange = [0.0,0.05,0.1,0.15,0.20,0.25,0.30] else: Wrange = [0.0,0.05,0.1,0.15,0.20,0.25,0.30,0.4,0.5,0.6,0.7,0.8,0.9,1.0] for W in Wrange: h=HAPropsSI('H','T',T,'W',W,'P',5000e3)/1000 Twb=HAPropsSI('Twb','T',T,'W',W,'P',5000e3)-273.15 R=HAPropsSI('R','T',T,'W',W,'P',5000e3)*100 v=HAPropsSI('V','T',T,'W',W,'P',5000e3) s=HAPropsSI('S','T',T,'W',W,'P',5000e3)/1000 print "{W:10.2f}{Twb:10.2f}{v:10.3f}{h:10.2f}{s:10.4f}{R:10.4f}".format(W=W,Twb=Twb,v=v,h=h,s=s,R=R) print '================================================================' print ' ' s5=' '*5 print 'A.'+num+'.5 Psychrometric Properties of Moist Air at 10,000 kPa ' print 'Dry Bulb temperature of '+Temp+'C' print '================================================================' print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=s5+' W',Twb=s5+'Twb',v=s5+' v',h=s5+'h',s=s5+' s',R=s5+'RH') print "{W:10s}{Twb:10s}{v:10s}{h:10s}{s:10s}{R:10s}".format(W=' kgw/kg_da',Twb=' C',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',R=' %') print '----------------------------------------------------------------' if Temp=='200': Wrange = [0.0,0.05,0.1] else: Wrange = [0.0,0.05,0.1,0.15,0.20,0.25,0.30,0.4,0.5,0.6,0.7,0.8,0.9,1.0] for W in Wrange: h=HAPropsSI('H','T',T,'W',W,'P',10000e3)/1000 Twb=HAPropsSI('Twb','T',T,'W',W,'P',10000e3)-273.15 R=HAPropsSI('R','T',T,'W',W,'P',10000e3)*100 v=HAPropsSI('V','T',T,'W',W,'P',10000e3) s=HAPropsSI('S','T',T,'W',W,'P',10000e3)/1000 print "{W:10.2f}{Twb:10.2f}{v:10.3f}{h:10.2f}{s:10.4f}{R:10.4f}".format(W=W,Twb=Twb,v=v,h=h,s=s,R=R) print '================================================================'
from CoolProp.HumidAirProp import HAPropsSI import numpy as np print ' Replicating the tables from ASHRAE RP-1485' print ' ' print 'A.6.1 Psychrometric Properties of Moist Air at 0C and Below' print 'Saturated air at 101.325 kPa' s5=' '*5 print '====================================================' print "{T:8s}{W:10s}{v:10s}{h:10s}{s:10s}".format(W=s5+' Ws',v=s5+' v',h=s5+'h',s=s5+' s',T=' T') print "{T:8s}{W:10s}{v:10s}{h:10s}{s:10s}".format(W=' kgw/kg_da',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',T=' C') print '----------------------------------------------------' for T in np.linspace(-60,0,13)+273.15: h = HAPropsSI('H','T',T,'R',1.0,'P',101325)/1000 Twb = HAPropsSI('Twb','T',T,'R',1.0,'P',101325)-273.15 W = HAPropsSI('W','T',T,'R',1.0,'P',101325) v = HAPropsSI('V','T',T,'R',1.0,'P',101325) s = HAPropsSI('S','T',T,'R',1.0,'P',101325)/1000 print "{T:8.0f}{W:10.7f}{v:10.4f}{h:10.3f}{s:10.4f}".format(W=W,T=T-273.15,v=v,h=h,s=s) print '====================================================' print ' ' print 'A.6.2 Psychrometric Properties of Moist Air at 0C and Above' print 'Saturated air at 101.325 kPa' s5=' '*5 print '====================================================' print "{T:8s}{W:10s}{v:10s}{h:10s}{s:10s}".format(W=s5+' Ws',v=s5+' v',h=s5+'h',s=s5+' s',T=' T') print "{T:8s}{W:10s}{v:10s}{h:10s}{s:10s}".format(W=' kgw/kg_da',v=' m3/kgda',h=' kJ/kgda',s=' kJ/kgda/K',T=' C') print '----------------------------------------------------' for T in np.linspace(0,90,19)+273.15: h=HAPropsSI('H','T',T,'R',1.0,'P',101325)/1000 Twb=HAPropsSI('Twb','T',T,'R',1.0,'P',101325)-273.15
#%% m cooling tower mCTtot = mCW.sum(axis=1) figure() mCTtot.plot() title('mCT total [gpm?]') savefig('mCT_tot_gpm.png') #%% weather data Toa = data['Toa'][startdate:enddate].resample('15T').mean() RH = data['RH'][startdate:enddate].resample('15T').mean() Weather = Toa.merge(RH, on='Date', how='inner') Weather.columns = ['Toa', 'RH'] Weather = Weather.dropna() from CoolProp.HumidAirProp import HAPropsSI Twb = HAPropsSI( 'B', 'T', Weather.iloc[:, 0].to_numpy() + 273.15, 'R', Weather.iloc[:, 1].to_numpy() * 1. / 100, 'P', 101325 ) #HumRat(AirH2O,T=T_a_in , P=p_atm,B=T_wb_in ) "lbm/lbm" "Humidity ratio" Weather['Twb'] = k2c(Twb) #%% Cooling Tower Power << sequencing. PCT = data['PCT'][startdate:enddate].resample('15T').mean() PCT[[k for k in PCT.columns.to_list() if 'Power' in k]].plot() PCTtot = PCT[[k for k in PCT.columns.to_list() if 'Power' in k]].sum(axis=1) PCT.plot() title('PCT') figure() PCTtot.plot() title('PCT') savefig('PCT_total_kW.png')
# water and air density rho_c = fpw.density(t_w) * 1000 rho_b = fpa.moist_air_density( p_standard, rH * fpa.temperature2saturation_vapour_pressure(t_in), t_mean) # initial value for critical radius r_max = np.full(re.shape, 0.0016) # initial values for Bond number, droplet aspect ratio, minimum contact angle and drag coefficient bo = Bo(rho_c, r_max, surf_tens) beta = aspect_ratio(bo) theta_m_0 = minimum_contact_angle(bo, theta_a) c_d = np.vectorize(c_drag)(r_max, theta_a, theta_m_0, re, d_h) # bulk velocity based on reynolds number u = re * HAPropsSI('mu', 'T', t_mean + 273.15, 'P', p_standard, 'R', rH) / \ (d_h * fpa.moist_air_density(p_standard, rH * fpa.temperature2saturation_vapour_pressure(t_in), t_mean)) # variable initialisation for forces and iteration f_g, f_s, f_d = np.zeros(re.shape), np.zeros(re.shape), np.zeros(re.shape) epsilon_1 = np.ones(re.shape) # a lot of debugging info logger.debug('flow direction: {a}'.format(a=flow_direction)) logger.debug('hydraulic diameter: {a}'.format(a=d_h)) logger.debug('duct height: {a}'.format(a=h)) logger.debug('diameter ratio: {a}'.format(a=d_h / h)) logger.debug('rho_water: {a}'.format(a=rho_c)) logger.debug('rho_air: {a}'.format(a=rho_b)) logger.debug('surface tension: {a}'.format(a=surf_tens)) logger.debug('Bo_0: {a}'.format(a=bo))
def HumidityRatio( Tdb, R, P=101325 ): # returns Kg-of-moisture/Kg-DryAir at sea level eg HumidityRatio(293.15,0.6) return HAPropsSI('W', 'T', Tdb, 'R', R, 'P', P) # Kg moisture/Kg Dry Air
def check_type(Tvals, wvals): HAPropsSI('H', 'T', Tvals, 'P', 101325, 'W', wvals)
def check_HAProps(*args): val = HAPropsSI(*args)
# Humid air example from Sphinx from CoolProp.HumidAirProp import HAPropsSI h = HAPropsSI('H','T',298.15,'P',101325,'R',0.5); print(h) T = HAPropsSI('T','P',101325,'H',h,'R',1.0); print(T) T = HAPropsSI('T','H',h,'R',1.0,'P',101325); print(T) # Verification script import CoolProp.CoolProp as CP import numpy as np import itertools from multiprocessing import Pool def generate_values(TR,P=101325): """ Starting with T,R as inputs, generate all other values """ T,R = TR psi_w = CP.HAPropsSI('psi_w','T',T,'R',R,'P',P) other_output_keys = ['T_wb','T_dp','Hda','Sda','Vda','Omega'] outputs = {'psi_w':psi_w,'T':T,'P':P,'R':R} for k in other_output_keys: outputs[k] = CP.HAPropsSI(k,'T',T,'R',R,'P',P) return outputs def get_supported_input_pairs(): """ Determine which input pairs are supported """ good_ones = [] inputs = generate_values((300, 0.5)) for k1, k2 in itertools.product(inputs.keys(), inputs.keys()): if 'P' in [k1,k2] or k1==k2: continue args = ('psi_w', k1, inputs[k1], k2, inputs[k2], 'P', inputs['P'])
def calculate_wbt(all_args): t_db, rh, cpu_id = all_args proc = psutil.Process() proc.cpu_affinity([cpu_id]) T = HAPropsSI('T_wb', 'R', rh, 'T', t_db, 'P', 101325) return T
# This file was auto-generated by the PsychChart.py script in wrappers/Python/CoolProp/Plots if __name__ == '__main__': import numpy, matplotlib from CoolProp.HumidAirProp import HAPropsSI from CoolProp.Plots.Plots import InlineLabel p = 101325 Tdb = numpy.linspace(-10, 60, 100) + 273.15 # Make the figure and the axes fig = matplotlib.pyplot.figure(figsize=(10, 8)) ax = fig.add_axes((0.1, 0.1, 0.85, 0.85)) # Saturation line w = [HAPropsSI('W', 'T', T, 'P', p, 'R', 1.0) for T in Tdb] ax.plot(Tdb - 273.15, w, lw=2) # Humidity lines RHValues = [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] for RH in RHValues: w = [HAPropsSI('W', 'T', T, 'P', p, 'R', RH) for T in Tdb] ax.plot(Tdb - 273.15, w, 'r', lw=1) # Humidity lines for H in [ -20000, -10000, 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000 ]: # Line goes from saturation to zero humidity ratio for this enthalpy T1 = HAPropsSI('T', 'H', H, 'P', p, 'R', 1.0) - 273.15
def plot_psy_chart(x_low_limit=-10, x_upp_limit=60, y_low_limit=0, y_upp_limit=0.03, p=101325, RH_lines='y', H_lines='y', WB_lines='y'): Tdb = np.linspace(x_low_limit, x_upp_limit, 100) + 273.15 # Make the figure and the axes fig, ax = plt.subplots(figsize=(10, 8)) fig.patch.set_alpha(0.9) ax.plot() ax.set_xlim(Tdb[0] - 273.15, Tdb[-1] - 273.15) ax.set_ylim(y_low_limit, y_upp_limit) ax.set_xlabel(r"$T_{db}$ [$^{\circ}$C]") ax.set_ylabel(r"$W$ ($m_{w}/m_{da}$) [-]") # Saturation line w = [HAPropsSI('W', 'T', T, 'P', p, 'R', 1.0) for T in Tdb] ax.plot(Tdb - 273.15, w, lw=2) # Enthalpy lines if H_lines == 'y': H_lines = [ -20000, -10000, 0, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000 ] for H in H_lines: #Line goes from saturation to zero humidity ratio for this enthalpy T1 = HAPropsSI('T', 'H', H, 'P', p, 'R', 1.0) - 273.15 T0 = HAPropsSI('T', 'H', H, 'P', p, 'R', 0.0) - 273.15 w1 = HAPropsSI('W', 'H', H, 'P', p, 'R', 1.0) w0 = HAPropsSI('W', 'H', H, 'P', p, 'R', 0.0) ax.plot(np.r_[T1, T0], np.r_[w1, w0], 'go--', lw=1, alpha=0.5) string = r'$H$=' + '{s:0.0f}'.format(s=H / 1000) + ' kJ/kg' bbox_opts = dict(boxstyle='square,pad=0.0', fc='white', ec='None', alpha=0) ax.text(T1 - 2, w1 + 0.0005, string, size='x-small', ha='center', va='center', bbox=bbox_opts) # Wet-blub temperature lines if WB_lines == 'y': WB_lines = np.linspace(0, 55, 12) + 273.15 for WB in WB_lines: #Line goes from saturation to zero humidity ratio for this enthalpy T1 = HAPropsSI('T', 'Twb', WB, 'P', p, 'R', 1.0) - 273.15 - 2 T0 = HAPropsSI('T', 'Twb', int(WB), 'P', p, 'R', 0.0) - 273.15 wb1 = HAPropsSI('W', 'Twb', WB, 'P', p, 'R', 1.0) + 0.002 wb0 = HAPropsSI('W', 'Twb', int(WB), 'P', p, 'R', 0.0) ax.plot(np.r_[T1, T0], np.r_[wb1, wb0], 'm--', lw=1, alpha=0.5) string = r'$WB$=' + '{s:0.0f}'.format(s=(WB - 273)) + ' [C]' bbox_opts = dict(boxstyle='square,pad=0.0', fc='white', ec='None', alpha=0) ax.text(T1 - 2, wb1 + 0.0005, string, size='x-small', ha='center', va='center', bbox=bbox_opts) # Humidity lines if RH_lines == 'y': RH_lines = [0.05, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] for RH in RH_lines: w = [HAPropsSI('W', 'T', T, 'P', p, 'R', RH) for T in Tdb] ax.plot(Tdb - 273.15, w, 'r--', lw=1, alpha=0.5) yv = [HAPropsSI('W', 'T', T, 'P', p, 'R', RH) for T in Tdb] T_K = Tdb[round(95.4082 - 40.8163 * RH)] w = yv[round(95.4082 - 40.8163 * RH)] string = r'$\phi$=' + '{s:0.0f}'.format(s=RH * 100) + '%' bbox_opts = dict(boxstyle='square,pad=0.0', fc='white', ec='None', alpha=0) ax.text(T_K - 273.15, w, string, size='x-small', ha='center', va='center', bbox=bbox_opts) # plt.close('all') return (fig, ax)
def plot(self,ax): w = [HAPropsSI('W','T',T,'P',p,'R',1.0) for T in Tdb] ax.plot(Tdb-273.15,w,lw=2)
def plot(self,ax): for RH in self.RH_values: w = [HAPropsSI('W','T',T,'P',p,'R',RH) for T in Tdb] ax.plot(Tdb-273.15,w,'r',lw=1)
def get_ws(Ts, RHs): # assert(len(Ts) == len(RHs)) ws = HAPropsSI('W', 'P', p_ref, 'T', Ts + C2K, 'R', RHs / 100) * PropsSI( 'D', 'P', p_ref, 'T', Ts + C2K, "air") return ws