-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_sim.py
123 lines (99 loc) · 4.14 KB
/
temp_sim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import numpy as np
import matplotlib.pyplot as plt
import math
# set a random seeD
# np.random.seed(213)
delta_t = 5 / 60 # hr
time_values = np.arange(0, 91 * 24, delta_t)
change_over_time = time_values * 2 / 91
# Outside Temperature
a = 6 * np.sin(2 * math.pi * (time_values)) + 35
b = np.random.normal(0, .1, len(time_values))
outside_temperature = a + b.cumsum() + change_over_time
# First week is 11 degrees
# outside_temperature[0: 2016] = 11
# Thermostat - furnace
work_furnace = np.repeat(68, 9 / delta_t)
home_furnace = np.repeat(74, 6 / delta_t)
sleep_furnace = np.repeat(70, 9 / delta_t)
one_day_furnace = np.concatenate([work_furnace, home_furnace, sleep_furnace])
vacaction_furnace = np.repeat(55, 14 * 24 / delta_t)
pre_vac_furnace = np.tile(one_day_furnace, 37)
post_vac_furnace = np.tile(one_day_furnace, 40)
furnace = np.concatenate([pre_vac_furnace, vacaction_furnace, post_vac_furnace])
# set heating to 80
# furnace = np.repeat(80, len(time_values))
#Thermostat - A/C
work_AC = np.repeat(82, 9 / delta_t)
home_AC = np.repeat(79, 6 / delta_t)
sleep_AC = np.repeat(79, 9 / delta_t)
one_day_AC = np.concatenate([work_AC, home_AC, sleep_AC])
vacaction_AC = np.repeat(88, 14 * 24 / delta_t)
pre_vac_AC = np.tile(one_day_AC, 37)
post_vac_AC = np.tile(one_day_AC, 40)
AC = np.concatenate([pre_vac_AC, vacaction_AC, post_vac_AC])
# Set cooling to 70
# AC = np.repeat(70, len(time_values))
# variables
furnace_rate = 2 # degF / hr
AC_rate = 1.5 # degF / hr
house_leakage_factor = .02 # (degF / hr) / degF
hysteresis = 1 # degF
furnace_on = np.empty(len(time_values))
AC_on = np.empty(len(time_values))
furnace_on[0] = False # boolean
AC_on[0] = False # boolean
inside_temperature = np.zeros(len(time_values))
inside_temperature[0] = outside_temperature[0] # degF
furnace_cost_rate = 5 # dollar / hour
AC_cost_rate = 7 # dollar / hour
#Loop
for i in range(1, len(time_values)):
# Furnace
if furnace_on[i - 1]:
if inside_temperature[i - 1] - furnace[i - 1] > hysteresis:
furnace_on[i] = False # boolean
furnace_heat = 0 # degF / hr
else:
furnace_on[i] = True # boolean
furnace_heat = furnace_rate # degF / hr
else:
if inside_temperature[i - 1] - furnace[i - 1] < -hysteresis:
furnace_on[i] = True # boolean
furnace_heat = furnace_rate # degF / hr
else:
furnace_on[i] = False # boolean
furnace_heat = 0 # degF / hr
# AC
if AC_on[i - 1]:
if inside_temperature[i - 1] - AC[i - 1] < hysteresis:
AC_on[i] = False # boolean
AC_cool = 0 # degF / hr
else:
AC_on[i] = True # boolean
AC_cool = AC_rate # degF / hr
else:
if inside_temperature[i - 1] - AC[i - 1] > -hysteresis:
AC_on[i] = True # boolean
AC_cool = AC_rate # degF / hr
else:
AC_on[i] = False # boolean
AC_cool = 0 # degF / hr
leakage_rate = (house_leakage_factor * (inside_temperature[i - 1] - outside_temperature[i - 1])) # degF / hr
T_prime = furnace_heat - AC_cool - leakage_rate
inside_temperature[i] = inside_temperature[i - 1] + T_prime * delta_t
# utility cost
furnace_cost = furnace_on.sum() * (furnace_cost_rate * delta_t) # dollar
AC_cost = AC_on.sum() * (AC_cost_rate * delta_t) # dollar
print("estimated average monthly utility cost (in U.S. dollars): $" + str((furnace_cost + AC_cost) / 3))
print("estimated total utility cost (in U.S. dollars): $" + str((furnace_cost + AC_cost)))
# Plotting
plt.plot(time_values, outside_temperature, color='green', linestyle="-", label="Outside Temperature")
plt.plot(time_values, inside_temperature, color='black', linestyle="-", label="Inside Temperature")
plt.plot(time_values, furnace, color='red', linestyle="-", label="Furnace Setting")
plt.plot(time_values, AC, color='blue', linestyle="-", label="A/C Setting")
plt.plot(time_values, furnace_on * 2 + 5, color='orange', linestyle="-", label="Furnace on")
plt.plot(time_values, AC_on * 2 + 10, color='purple', linestyle="-", label="A/C on")
plt.ylim(0, 100)
plt.legend()
plt.show()