예제 #1
0
def transactive_price(house, T_curr, T_c_set, T_h_set, mean_p, var_p, epsilon):
	T_zero_h = T_h_set + (T_c_set - T_h_set)/2 - epsilon/2
	T_zero_c = T_c_set - (T_c_set - T_h_set)/2 + epsilon/2
	T_max = float(gridlabd_functions.get(house,'T_max')['value'][1:])
	T_min = float(gridlabd_functions.get(house,'T_min')['value'][1:])
	k = float(gridlabd_functions.get(house,'k')['value'][1:])
	if T_curr > T_max or T_curr < T_min:
		return 1 #max price
	# cooling
	elif T_curr > T_zero_c:
		#Remains here if comfort settings are changed during operation
		m = (mean_p + k * np.sqrt(var_p))/(T_max - T_zero_c)
		gridlabd_functions.set(house,'m',m)
		n = - m * T_zero_c
		gridlabd_functions.set(house,'n',n)
		return (m * T_curr + n)
	# heating
	elif T_curr < T_zero_h:
		m = (mean_p + k * np.sqrt(var_p))/(T_min - T_zero_h)
		gridlabd_functions.set(house,'m',m)
		n = - m * T_zero_h
		gridlabd_functions.set(house,'n',n)
		return (m * T_curr + n)
	else:
		return 0
예제 #2
0
def set_HVAC_setpoint(house,control_type,bid_price,Pd):

	#Set state: Load is active in that period
	if bid_price >= Pd:
		gridlabd_functions.set(house,'state',True)
	else:
		gridlabd_functions.set(house,'state',False)

	if 'deadband' in control_type:
		if bid_price >= Pd and bid_price > 0: #to exclude consumption when price is zero
			#switch on HVAC
			if 'COOL' in gridlabd_functions.get(house,'bid_mode')['value']:
				gridlabd_functions.set(house,'system_mode','COOL')
			elif 'HEAT' in gridlabd_functions.get(house,'bid_mode')['value']:
				gridlabd_functions.set(house,'system_mode','HEAT')
			else:
				print('Check bid mode - there might be an inconsistency in bidding and actual behavior')
			return
		else:
			#turn off HVAC
			gridlabd_functions.set(house,'system_mode','OFF')
			#gridlabd_functions.set('control_1','control','OFF')
			return

	elif ('trans' in control_type): 

		m = float(gridlabd_functions.get(house,'m')['value'])
		n = float(gridlabd_functions.get(house,'n')['value'])
		T_max = float(gridlabd_functions.get(house,'T_max')['value'][1:])
		T_min = float(gridlabd_functions.get(house,'T_min')['value'][1:])

		#change setpoint on HVAC
		if 'COOL' in gridlabd_functions.get(house,'bid_mode')['value']:
			gridlabd_functions.set(house,'system_mode','COOL')
			# calculate new setpoint
			T_c_set_new = (Pd - n)/m
			if T_c_set_new > T_max:
				gridlabd_functions.set(house,'cooling_setpoint',T_max)
			else:
				gridlabd_functions.set(house,'cooling_setpoint',T_c_set_new)
		
		elif 'HEAT' in gridlabd_functions.get(house,'bid_mode')['value']:
			gridlabd_functions.set(house,'system_mode','HEAT')
			#calculate new setpoint
			T_h_set_new = (Pd - n)/m
			if T_h_set_new < T_min:
				gridlabd_functions.set(house,'heating_setpoint',T_min)
			else:
				gridlabd_functions.set(house,'heating_setpoint',T_h_set_new)
		else:
			gridlabd_functions.set(house,'system_mode','OFF')
		return
	else:
		print('HVAC could not be set')
		return
예제 #3
0
def bid_rule_HVAC(house, mean_p, var_p, interval):
	control_type = gridlabd_functions.get(house,'control_type')['value']
	k = float(gridlabd_functions.get(house,'k')['value'][1:])
	
	T_c_set = float(gridlabd_functions.get(house,'T_c_set_0')['value'][1:])
	T_h_set = float(gridlabd_functions.get(house,'T_h_set_0')['value'][1:])
	#T_curr = float(gridlabd_functions.get(house,'air_temperature')['value'][1:-5])
	#calculate energy
	hvac_q = float(gridlabd_functions.get(house,'cooling_demand')['value'][1:-3]) * interval / (60*60)
	heat_q = float(gridlabd_functions.get(house,'heating_demand')['value'][1:-3]) * interval / (60*60)

	#State of appliance in previous period
	status = int(gridlabd_functions.get(house,'state')['value'])
	
	if 'deadband' in control_type:
		# cooling
		if T_curr > T_c_set + k:
			bid_price = 1
			bid_quantity = hvac_q	
			gridlabd_functions.set(house,'bid_mode','COOL')		
			return bid_quantity, bid_price, status
		# heating
		elif T_curr < T_h_set - k:
			bid_price = 1
			bid_quantity = heat_q	
			gridlabd_functions.set(house,'bid_mode','HEAT')			
			return bid_quantity, bid_price, status
		# no activity
		else:
			bid_price = 0
			bid_quantity = 0
			gridlabd_functions.set(house,'bid_mode','NONE')	
			return bid_quantity, bid_price, status
	
	elif 'trans' in control_type:
		# Non-bid region size between cooling and heating [F]
		epsilon = 2
		bid_price = transactive_price(house, T_curr, T_c_set, T_h_set, mean_p, var_p, epsilon)
		if T_curr > T_c_set - (T_c_set - T_h_set)/2 + epsilon/2: #above T_c_zero
			bid_quantity = hvac_q
			gridlabd_functions.set(house,'bid_mode','COOL')
		elif T_curr < T_h_set + (T_c_set - T_h_set)/2 - epsilon/2: #below T_h_zero
			bid_quantity = heat_q
			gridlabd_functions.set(house,'bid_mode','HEAT')
		else:
			bid_quantity = 0
			gridlabd_functions.set(house,'bid_mode','NONE')
		return bid_quantity, bid_price, status
	else:
		print('Bid reserve price could not be calculated')
		return 0,0,0
예제 #4
0
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
예제 #5
0
	#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
	df_bids_PV = HHfct.calc_bids_PV(dt_sim_time,df_PV_state,retail)
	retail = HHfct.submit_bids_PV(dt_sim_time,retail,df_bids_PV)

	#EV
	dt_sim_time,df_EV_state,retail
	df_bids_EV = HHfct.calc_bids_EV(dt_sim_time,df_EV_state,retail,mean_p,var_p)
	retail = HHfct.submit_bids_EV(dt_sim_time,retail,df_bids_EV)

	#Include unresponsive load
	load_SLACK = float(gridlabd_functions.get('node_149','measured_real_power')['value'][:-1])/1000 #save to mysql #measured_real_power in [W]
	active_prev = retail.get_active() #needs to be after buy bid submission
	unresp_load = load_SLACK - active_prev
	mysql_functions.set_values('unresponsive_loads', '(unresp_load,slack,active_loads,timedate)',(unresp_load,load_SLACK,active_prev,dt_sim_time,))
	retail.buy(unresp_load)

	###
	#Supply side
	###

	#supply_costs = round(random.uniform(retail.Pmin,retail.Pmax),prec)
	supply_costs = min(mysql_functions.get_values('WS_market',begin=dt_sim_time,end=dt_sim_time)['RT'].iloc[0],retail.Pmax)
	print'supply costs: '+str(supply_costs)
	#Max capacity (later from CC)
	#C = 3262 + random.uniform(-10,10) #for test purposes [in kW]
	C = 800.0 #capacity restriction
예제 #6
0
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
예제 #7
0
import gridlabd_functions
import os

# Initializing variables
# set_P_out=-1000         # value to set P to (negative is charging, positive is discharging)
p_cc = 2000  # CC setpoint
soc_setpoint = 0.7  # Baterry SOC target

#Get state of charge of Battery object
soc_read = gridlabd_functions.get('node1_batt', 'state_of_charge')
soc = float(soc_read['value'][1:-3])

#Get power in the mains object
p_hApp_read = gridlabd_functions.get('meter1', 'measured_real_power')
p_hApp = float(p_hApp_read['value'][1:-2])

#Print out timestep and state of charge
sim_time = os.getenv("clock")
print soc
# print sim_time
print p_hApp

k = 20000  # Controller gain
p_control = -(soc_setpoint - soc) * k
gridlabd_functions.set('node1_batt_inv', 'P_Out',
                       p_control)  # Write p_control to battery

#batt_delta = -(p_cc - p_hApp)
#gridlabd_functions.set('node1_batt_inv','P_Out',batt_delta)  #Write P_Out to battery object
'''
if sim_time[14] != "4":
예제 #8
0
current_batt = []
#Get power and current of solar inverter through meter
power_solar = []
current_solar = []

# Getting house power:
for i in number_of_houses:
    #print 'TEST!!!!!!'
    #print gridlabd_functions.get('node1_meter_H'+str(i),'measured_real_power')['value'][1:-2]
    #a = gridlabd_functions.get('node1_meter_H'+str(i),'measured_real_power')
    #print float(a['value'][1:-2])

    #houses_dict[i]['HouseMeterRealPower'] =  gridlabd_functions.get('node1_meter_H'+str(i),'measured_real_power')
    #houses_dict[i]['HouseMeterReactivePower'] =  gridlabd_functions.get('node1_meter_H'+str(i),'measured_reactive_power')
    houses_dict[i]['HouseMeterRealPower'] = float(
        gridlabd_functions.get('node1_meter_H' + str(i),
                               'measured_real_power')['value'][1:-2])
    houses_dict[i]['HouseMeterReactivePower'] = float(
        gridlabd_functions.get('node1_meter_H' + str(i),
                               'measured_reactive_power')['value'][1:-4])

    #houses_dict[i]['HouseMeterCurrent'] =  gridlabd_functions.get('node1_meter_H'+str(i),'measured_current_1')['value']
    #power_house.append(gridlabd_functions.get('node1_meter_H'+str(i),'measured_power')['value'])
    #current_house.append(gridlabd_functions.get('node1_meter_H'+str(i),'measured_current_1')['value'])
#print 'power_house', power_house
#print 'current_house', current_house

# Getting soc
for i in batt_solar_houses:
    #houses_dict[i]['soc'] = gridlabd_functions.get('node1_batt_H'+str(i),'state_of_charge')
    #houses_dict[i]['BatteryRealPower'] = gridlabd_functions.get('node1_meter_B'+str(i),'measured_real_power')
    #houses_dict[i]['BatteryReactivePower'] = gridlabd_functions.get('node1_meter_B'+str(i),'measured_reactive_power')
for i in range(len(nodes_List)):
    socNode_dict[nodes_List[i]]={}
powerFile = 'PowerNode.json'
battFile = 'batt.json'

PWRNET_API_BASE_URL = 'http://pwrnet-158117.appspot.com/api/v1/'

##########################################

# sim_time string: "2015-07-01 14:58:30 EDT"
#                   01234567890123456789

# Collecting data every 14 minutes - minutes: 14, 28, 42 and 56
#if int(sim_time[14:16]) % 14 == 0 and int(sim_time[14:16]) != 0 and int(sim_time[17:18]) == 0:
if int(sim_time[14:16]) == 0 and int(sim_time[17:19] == 0):
    PowerNode_dict[4]['SOC'] = float(gridlabd_functions.get('Battery_1','state_of_charge')['value'][1:-3]) # This is node 4
    PowerNode_dict[12]['SOC'] = float(gridlabd_functions.get('Battery_2','state_of_charge')['value'][1:-3]) # This is node 12

    # write to table SOC in the database
    # WRITE CODE HERE

    # Setting up comms with CC every 2hrs
    if int(time_sim[11:13]) != 0 and int(time_sim[11:13]) % 2 == 0 and int(sim_time[15:16]) == 5:





############## OLD CODE ################
if int(sim_time[15:16]) == 5 and int(sim_time[17:18]) == 0:
    print 'OUTER Loop...'
예제 #10
0
import gridlabd_functions
import os

houses = gridlabd_functions.get('houselist')

#print(houses)

#print(houses['houselist'].split(';'))
prop = "air_temperature"
objects = houses['houselist'].split(';')
data = gridlabd_functions.get_blocks(objects, prop)

house_key = objects[5]

print(gridlabd_functions.get_blocks_double(data, house_key))
print(os.getenv("clock"))
예제 #11
0
import gridlabd_functions
import os

#Get state of charge of Battery object
SOC = gridlabd_functions.get('node1_batt', 'state_of_charge')
print(SOC['value'])

print(os.getenv("clock"))

#Write P_Out to battery object
gridlabd_functions.set('node1_batt_inv', 'P_Out', -1000)
예제 #12
0
PWRNET_API_BASE_URL = 'http://pwrnet-158117.appspot.com/api/v1/'

##########################################

# sim_time string: "2015-07-01 14:58:30 EDT"
#                   01234567890123456789

# Collecting data every 14 minutes - minutes: 14, 28, 42 and 56
#if int(sim_time[14:16]) % 14 == 0 and int(sim_time[14:16]) != 0 and int(sim_time[17:18]) == 0:
if int(sim_time[15:16]) == 5 and int(sim_time[17:18]) == 0:
    print 'OUTER Loop...'
    # Getting power at node level
    for i in nodes_List:
        PowerNode_dict[i]['pPowerNode'] = float(
            gridlabd_functions.get('meter_' + str(i), 'measured_real_power')
            ['value'][1:-2]) + random.uniform(-50, 50)
        PowerNode_dict[i]['rPowerNode'] = float(
            gridlabd_functions.get('meter_' + str(i), 'measured_reactive_power'
                                   )['value'][1:-4]) + random.uniform(-50, 50)

    # Getting soc at node level - need to call only when sending info to CC
    # Only need to get one SOC per node
    PowerNode_dict[4]['SOC'] = float(
        gridlabd_functions.get(
            'Battery_1', 'state_of_charge')['value'][1:-3])  # This is node 4
    PowerNode_dict[12]['SOC'] = float(
        gridlabd_functions.get(
            'Battery_2', 'state_of_charge')['value'][1:-3])  # This is node 12
    # Saving data to json
    rwText.create_file_json(powerFile, PowerNode_dict)