1
1
import datetime as dt
2
2
import pandas as pd
3
3
4
- from ochre import Dwelling
4
+ from ochre import Dwelling , CreateFigures
5
5
from bin .run_dwelling import dwelling_args
6
6
7
7
# Test script to run single Dwelling with constant external control signal
8
8
9
- dwelling_args .update ({
10
- 'ext_time_res' : dt .timedelta (minutes = 60 ),
11
- })
9
+ dwelling_args .update (
10
+ {
11
+ "time_res" : dt .timedelta (minutes = 10 ),
12
+ "ext_time_res" : dt .timedelta (minutes = 60 ), # for duty cycle control only
13
+ "Equipment" : {
14
+ "EV" : {
15
+ 'vehicle_type' : 'BEV' ,
16
+ 'charging_level' : 'Level 2' ,
17
+ 'mileage' : 150 ,
18
+ },
19
+ },
20
+ }
21
+ )
12
22
13
23
example_control_signal = {
14
- 'HVAC Heating' : {'Setpoint' : 19 }, # in C
15
- 'HVAC Cooling' : {'Setpoint' : 22 }, # in C
16
- 'Water Heating' : {'Setpoint' : 50 }, # in C
17
- 'PV' : {'P Setpoint' : - 1.1 , 'Q Setpoint' : 0.5 }, # in kW, kVAR
18
- 'Battery' : {'P Setpoint' : - 1.0 }, # in kW
24
+ "HVAC Heating" : {
25
+ "Setpoint" : 19 ,
26
+ # 'Max Capacity Fraction': 0.8,
27
+ "Max ER Capacity Fraction" : 0.5 ,
28
+ }, # in C
29
+ "HVAC Cooling" : {"Setpoint" : 22 }, # in C
30
+ "Water Heating" : {"Setpoint" : 50 }, # in C
31
+ "PV" : {"P Setpoint" : - 1.1 , "Q Setpoint" : 0.5 }, # in kW, kVAR
32
+ "Battery" : {
33
+ # 'P Setpoint': -1.0, # in kW
34
+ # "SOC": 0.8,
35
+ "Self Consumption Mode" : True ,
36
+ "Max Import Limit" : 1 , # in kW
37
+ "Max Export Limit" : 1 , # in kW
38
+ # 'Min SOC': 0.2,
39
+ # 'Max SOC': 0.8,
40
+ },
41
+ "EV" : {
42
+ # "Delay": True,
43
+ "Max Power" : 6 ,
44
+ "Max SOC" : 0.7 ,
45
+ # "P Setpoint": 5,
46
+ # "SOC": 0.6,
47
+ # "SOC Rate": 0.02,
48
+ },
19
49
}
20
50
21
51
22
- def run_constant_control_signal (control_signal ):
52
+ def run_with_schedule_control ():
53
+ # Create Dwelling model (same as above)
54
+ dwelling = Dwelling (name = "Test House with Controller" , ** dwelling_args )
55
+
56
+ # Get HVAC heater setpoints
57
+ heater = dwelling .get_equipment_by_end_use ('HVAC Heating' )
58
+ setpoints = heater .schedule ['HVAC Heating Setpoint (C)' ]
59
+
60
+ # Reduce heating setpoint by 1C from 5-9PM
61
+ peak_times = setpoints .between_time (dt .time (17 , 0 , 0 ), dt .time (21 , 0 , 0 ), inclusive = 'left' ).index
62
+ setpoints .loc [peak_times ] -= 1
63
+ heater .reset_time () # resets the schedule
64
+
65
+ # Run simulation
66
+ dwelling .simulate ()
67
+
68
+
69
+ def run_constant_control_signal (control_signal = None ):
23
70
# Initialization
24
- dwelling = Dwelling (name = 'Test House with Controller' , ** dwelling_args )
71
+ dwelling = Dwelling (name = 'OCHRE with Controller' , ** dwelling_args )
25
72
26
73
# Simulation
27
74
for t in dwelling .sim_times :
28
- assert dwelling .current_time == t
75
+ # assert dwelling.current_time == t
29
76
house_status = dwelling .update (control_signal = control_signal )
30
77
31
- return dwelling .finalize ()
78
+ df , _ , _ = dwelling .finalize ()
79
+
80
+ df ["EV Electric Power (kW)" ].plot ()
81
+ df ["EV SOC (-)" ].plot ()
82
+ CreateFigures .plt .show ()
32
83
33
84
34
85
def get_hvac_controls (hour_of_day , occupancy , heating_setpoint , ** unused_inputs ):
35
86
# Use some of the controller_inputs to determine setpoints (or other control signals)
36
87
if 14 <= hour_of_day < 20 : # 2PM-8PM
37
- if occupancy > 0 :
38
- heating_setpoint -= 1 # reduce setpoint by 1 degree C
39
- else :
40
- heating_setpoint -= 2 # reduce setpoint by 2 degrees C
88
+ heating_setpoint -= 1 # reduce setpoint by 1 degree C
89
+ # if occupancy > 0:
90
+ # heating_setpoint -= 1 # reduce setpoint by 1 degree C
91
+ # else:
92
+ # heating_setpoint -= 2 # reduce setpoint by 2 degrees C
41
93
42
94
return {
43
- # 'HVAC Heating': {'Duty Cycle': 1 if heating_on else 0},
44
95
'HVAC Heating' : {
45
- 'Setpoint' : heating_setpoint ,
96
+ 'Capacity' : 1000 ,
97
+ # 'Setpoint': heating_setpoint,
46
98
# 'Deadband': 2,
47
99
# 'Load Fraction': 0, # Set to 0 for force heater off
48
100
# 'Duty Cycle': 0.5, # Sets fraction of on-time explicitly
@@ -53,7 +105,7 @@ def get_hvac_controls(hour_of_day, occupancy, heating_setpoint, **unused_inputs)
53
105
54
106
def run_with_hvac_controller ():
55
107
# Initialization
56
- dwelling = Dwelling (name = 'Test House with Controller' , ** dwelling_args )
108
+ dwelling = Dwelling (name = "OCHRE with Controller" , ** dwelling_args )
57
109
heater = dwelling .get_equipment_by_end_use ('HVAC Heating' )
58
110
cooler = dwelling .get_equipment_by_end_use ('HVAC Cooling' )
59
111
@@ -73,8 +125,9 @@ def run_with_hvac_controller():
73
125
'hour_of_day' : t .hour ,
74
126
'outdoor_temp' : dwelling .envelope .schedule .loc [t , 'Ambient Dry Bulb (C)' ],
75
127
'occupancy' : dwelling .envelope .schedule .loc [t , 'Occupancy (Persons)' ],
76
- 'heating_setpoint' : heater .schedule .loc [t , 'HVAC Heating Setpoint (C)' ], # Original setpoint for current time
77
- 'cooling_setpoint' : cooler .schedule .loc [t , 'HVAC Cooling Setpoint (C)' ], # Original setpoint for current time
128
+ # Original setpoints for current time
129
+ 'heating_setpoint' : heater .schedule .loc [t , 'HVAC Heating Setpoint (C)' ],
130
+ 'cooling_setpoint' : cooler .schedule .loc [t , 'HVAC Cooling Setpoint (C)' ],
78
131
})
79
132
80
133
control_signal = get_hvac_controls (** controller_inputs )
@@ -95,7 +148,7 @@ def run_controls_from_file(control_file):
95
148
df_ext = pd .read_csv (control_file , index_col = 'Time' , parse_dates = True )
96
149
97
150
# Initialization
98
- dwelling = Dwelling (name = 'Test House with Controller' , ** dwelling_args )
151
+ dwelling = Dwelling (name = "OCHRE with Controller" , ** dwelling_args )
99
152
100
153
# Simulation
101
154
control_signal = None
@@ -110,6 +163,7 @@ def run_controls_from_file(control_file):
110
163
111
164
112
165
if __name__ == '__main__' :
113
- # run_constant_control_signal(example_control_signal)
114
- # run_controls_from_file(external_control_file='path/to/control_file.csv')
115
- run_with_hvac_controller ()
166
+ # run_with_schedule_control()
167
+ run_constant_control_signal (example_control_signal )
168
+ # run_with_hvac_controller()
169
+ # run_controls_from_file(external_control_file='path/to/control_file.csv')
0 commit comments