def dispatch(self, dt_sim_time, p_lem, alpha): inverter = self.name if (self.Q_bid > 0.0) and (self.P_bid > p_lem): gridlabd.set_value(inverter, 'P_Out', str(-self.Q_bid * 1000.)) mode = 1. elif (self.Q_bid > 0.0) and (self.P_bid == p_lem): print('This HVAC is marginal; no partial implementation yet: ' + str(alpha)) gridlabd.set_value(inverter, 'P_Out', str(-self.Q_bid * 1000.)) mode = 1. else: gridlabd.set_value(inverter, 'P_Out', str(0.0)) mode = 0. parameter_string = '(timedate, P_bid, Q_bid, mode, DeltaE)' #DeltaE at beginning of period value_tuple = ( dt_sim_time, float(self.P_bid), float(self.Q_bid), float(mode), float(self.DeltaE), ) myfct.set_values('EV_' + self.ID + '_state_out', parameter_string, value_tuple) self.P_bid = -100000.0 self.Q_bid = 0.0 return
def dispatch(self, dt_sim_time, p_lem, alpha): #import pdb; pdb.set_trace() inverter = 'Bat_inverter_' + self.name.split('_')[-1] if (self.Q_buy_bid > 0.0) and (self.P_buy_bid > p_lem): gridlabd.set_value(inverter, 'P_Out', str(-self.Q_buy_bid * 1000.)) elif (self.Q_buy_bid > 0.0) and (self.P_buy_bid == p_lem): print('This HVAC is marginal; no partial implementation yet: ' + str(alpha)) gridlabd.set_value(inverter, 'P_Out', str(-self.Q_buy_bid * 1000.)) elif (self.Q_sell_bid > 0.0) and (self.P_sell_bid < p_lem): gridlabd.set_value(inverter, 'P_Out', str(self.Q_sell_bid * 1000.)) elif (self.Q_sell_bid > 0.0) and (self.P_sell_bid == p_lem): print('This HVAC is marginal; no partial implementation yet: ' + str(alpha)) gridlabd.set_value(inverter, 'P_Out', str(self.Q_sell_bid * 1000.)) else: gridlabd.set_value(inverter, 'P_Out', str(0.0)) myfct.set_values( self.name + '_state_out', '(timedate, p_demand, p_supply, q_demand, q_supply)', (dt_sim_time, str(self.P_buy_bid), str( self.P_sell_bid), str(self.Q_buy_bid), str(self.Q_sell_bid))) self.P_sell_bid = 100000.0 self.P_buy_bid = -100000.0 self.Q_sell_bid = 0.0 self.Q_buy_bid = 0.0
def switch_off(s_awarded,dt_sim_time): #houses if 'GLD' in s_awarded['appliance_name']: gridlabd_functions.set(s_awarded['appliance_name'],'thermostat_control','NONE') #batteries elif 'Bat' in s_awarded['appliance_name']: gridlabd_functions.set('Bat_inverter_'+s_awarded['appliance_name'][8:],'P_Out',0.0) #EV elif 'EV' in s_awarded['appliance_name']: gridlabd_functions.set('EV_inverter_'+s_awarded['appliance_name'][3:],'P_Out',0.0) else: print s_awarded['appliance_name']+' is not recognized' mysql_functions.set_values('system_operations', '(timedate,q,costs,appliance_name)',(dt_sim_time,float(s_awarded['q_bid']),float(s_awarded['p_bid']),s_awarded['appliance_name'],)) return
def shutdown_house(unresp_load,dt_sim_time,houses_off=[],market=None): if market: Pmax = market.Pmax else: Pmax = 100.0 while True: house_OFF = np.random.choice(houselist_inflex) while house_OFF in houses_off: house_OFF = np.random.choice(houselist_inflex) house_currHVAC = float(gridlabd_functions.get(house_OFF,'hvac_load')['value'][:-3]) if house_currHVAC > 0.0: unresp_load -= house_currHVAC print 'Switch off '+str(house_OFF)+' to '+str(unresp_load) gridlabd_functions.set(house_OFF,'thermostat_control','NONE') gridlabd_functions.set(house_OFF,'system_mode','OFF') houses_off += [house_OFF] mysql_functions.set_values('system_operations', '(timedate,q,costs,appliance_name)',(dt_sim_time,house_currHVAC,Pmax,'HVAC'+house_OFF[3:],)) break print 'Ready: '+str(unresp_load) return unresp_load, houses_off
retail = Mfct.Market() retail.reset() retail.Pmin = 0.0 retail.Pmax = 100.0 retail.Pprec = prec #Get historical parameters from mysql database df_prices = mysql_functions.get_values('clearing_pq', dt_sim_time-datetime.timedelta(days=1)) mean_p = df_prices['clearing_price'].iloc[-36:].mean() #last hour var_p = df_prices['clearing_price'].var() if math.isnan(mean_p): mean_p = (retail.Pmax - retail.Pmin)/2 #print var_p if math.isnan(var_p) or var_p == 0.0: var_p = 0.10 mysql_functions.set_values('market_prices', '(mean_price,var_price,timedate)',(float(mean_p),float(var_p),dt_sim_time-datetime.timedelta(seconds=interval),)) ### #Demand side ### #HVAC df_bids_HVAC = HHfct.calc_bids_HVAC(dt_sim_time,df_house_state,retail,mean_p,var_p) retail = HHfct.submit_bids_HVAC(dt_sim_time,retail,df_bids_HVAC) print retail.D_active #Batteries df_bids_battery = HHfct.calc_bids_battery(dt_sim_time,df_battery_state,retail,mean_p,var_p) retail = HHfct.submit_bids_battery(dt_sim_time,retail,df_bids_battery) #PV
def initialize(): mysql_functions.clear_databases() print('Initialize') #Start time of simulation is '2017-07-01 12:00:00' EST+5 - get this from GLOBALS or likewise interval = int(gridlabd_functions.get('retail', 'interval')['value']) #in seconds #prev_timedate = datetime.datetime(2015, 6, 30, 23, 60 - (interval/60)) #prev_timedate = datetime.datetime(2015, 7, 1, 4, 60 - (interval/60)) dt = parser.parse(os.getenv("clock")) prev_timedate = dt - timedelta(minutes=interval / 60) #Get list of house objects in GLM file and assign to global GLD variable "houselist" #houses = gridlabd_functions.find('class=house') #houselist = []; #Read in wholesale market prices df_prices = pandas.read_csv('ercot_2017.csv', parse_dates=[0]) mysql_functions.set_WSmarket(df_prices) #Check if downgrading pycurl changes gridlabd_functions # from sqlalchemy import create_engine # engine = create_engine("mysql://*****:*****@127.0.0.1/gridlabd") # con = engine.connect() # df_prices.to_sql(name='WS_market',con=con,if_exists='append') # con.close() for house in houselist: #houselist.append(name) #Fills TABLE market_houses (can this be done via GridlabD directly?) mysql_functions.set_values('market_houses', '(house_name)', (house, )) #Fills TABLE market_appliances (can this be done via GridlabD directly?) #HVAC k = float(gridlabd_functions.get(house, 'k')['value']) T_min = float(gridlabd_functions.get(house, 'T_min')['value']) T_max = float(gridlabd_functions.get(house, 'T_max')['value']) heat_q = float( gridlabd_functions.get( house, 'heating_demand')['value'][1:-3]) #heating_demand is in kW hvac_q = float( gridlabd_functions.get( house, 'cooling_demand')['value'][1:-3]) #cooling_demand is in kW #mysql_functions.set_values('market_HVAC', '(house_name,appliance_name,k,T_min,T_max,P_heat,P_cool)',(house['name'],'HVAC_'+str(houses.index(house)+1),k,T_min,T_max,heat_q,hvac_q,)) mysql_functions.set_values( 'market_HVAC', '(house_name,appliance_name,k,T_min,T_max,P_heat,P_cool)', ( house, 'HVAC_' + house[4:], k, T_min, T_max, heat_q, hvac_q, )) #Fills TABLE market_appliance_meter #HVAC heating_setpoint = float( gridlabd_functions.get(house, 'heating_setpoint')['value'][1:-5]) cooling_setpoint = float( gridlabd_functions.get(house, 'cooling_setpoint')['value'][1:-5]) #Set values for previous period, i.e. start - interval #mysql_functions.set_values('market_HVAC_meter', '(system_mode,heating_setpoint,cooling_setpoint,active,timedate,appliance_id)',('OFF',heating_setpoint,cooling_setpoint,0,prev_timedate,houses.index(house)+1,)) mysql_functions.set_values( 'market_HVAC_meter', '(system_mode,av_power,heating_setpoint,cooling_setpoint,active,timedate,appliance_id)', ( 'OFF', 0.0, heating_setpoint, cooling_setpoint, 0, prev_timedate, int(house.split('_')[-1]), )) #gridlabd_functions.set('houselist',';'.join(houselist)) #batteries = gridlabd_functions.find('class=battery') for battery in batterylist: house_name = 'GLD_' + battery[8:] #Fills TABLE market_appliances SOC_max = float( gridlabd_functions.get(battery, 'battery_capacity')['value'] [:-3]) / 1000 #Wh in Gridlabd -> kWh str_i_max = gridlabd_functions.get(battery, 'I_Max')['value'][:-2].replace( '-', '+') i_max = str_i_max.split('+')[1] u_max = float(gridlabd_functions.get(battery, 'V_Max')['value'] [:-2]) * float(i_max) / 1000 #W -> kW #better inverter? eff = float( gridlabd_functions.get(battery, 'base_efficiency')['value'][:-5]) mysql_functions.set_values( 'market_battery', '(house_name,appliance_name,appliance_id,SOC_max,u_max,eff)', ( house_name, battery, int(battery.split('_')[-1]), SOC_max, u_max, eff, )) #Fills TABLE market_appliance_meter SOC_0 = float( gridlabd_functions.get(battery, 'state_of_charge')['value'][:-3]) * SOC_max mysql_functions.set_values('market_battery_meter', '(SOC,active,timedate,appliance_id)', ( SOC_0, 0, prev_timedate, int(battery.split('_')[-1]), )) for EV in EVlist: house_name = 'GLD_' + EV[3:] #Fills TABLE market_appliances SOC_max = float( gridlabd_functions.get(EV, 'battery_capacity')['value'] [:-3]) / 1000 #Wh in Gridlabd -> kWh str_i_max = gridlabd_functions.get(EV, 'I_Max')['value'][:-2].replace( '-', '+') i_max = str_i_max.split('+')[1] u_max = float(gridlabd_functions.get(EV, 'V_Max')['value'] [:-2]) * float(i_max) / 1000 #W -> kW #better inverter? eff = float( gridlabd_functions.get(EV, 'base_efficiency')['value'][:-5]) charging_type = gridlabd_functions.get(EV, 'charging_type')['value'] k = gridlabd_functions.get(EV, 'k')['value'] mysql_functions.set_values( 'market_EV', '(house_name,appliance_name,appliance_id,SOC_max,u_max,eff,charging_type,k)', ( house_name, EV, int(EV.split('_')[-1]), SOC_max, u_max, eff, charging_type, k, )) #Fills TABLE market_appliance_meter mysql_functions.set_values( 'market_EV_meter', '(connected,SOC,active,timedate,appliance_id)', ( 0, 0, 0, prev_timedate, int(EV.split('_')[-1]), )) #Set all cars offline/disconnected in the beginning gridlabd_functions.set(EV, 'generator_status', 'OFFLINE') df_events = pandas.read_csv('EV_events.csv', index_col=[0]) df_events.to_csv('EV_events_pop.csv') # PVs = gridlabd_functions.find('class=solar') for pv in pvlist: house_name = 'GLD_' + pv[3:] #Fills TABLE market_appliances inverter_name = 'PV_inverter_' + pv[3:] rated_power = float( gridlabd_functions.get(inverter_name, 'rated_power')['value'][:-3]) / 1000 mysql_functions.set_values( 'market_pv', '(house_name,appliance_name,inverter_name,appliance_id,rated_power)', ( house_name, pv, inverter_name, int(pv.split('_')[-1]), rated_power, )) #Fills TABLE market_appliance_meter production = float( gridlabd_functions.get(inverter_name, 'P_Out')['value'][:-3]) / 1000 mysql_functions.set_values('market_pv_meter', '(P_Out,timedate,appliance_id)', ( production, prev_timedate, int(pv.split('_')[-1]), )) return dt