-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunExperiment.py
executable file
·127 lines (100 loc) · 5.28 KB
/
runExperiment.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
123
124
125
126
127
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import buildingspy
from buildingspy.simulate.Dymola import Simulator
def simulateCase(s):
s.setStartTime(0)
s.setStopTime(365*24*3600)
s.setSolver("Radau")
s.setTolerance(1E-6)
s.deleteOutputFiles()
s.simulate()
def printResults(mat_file):
from buildingspy.io.outputfile import Reader
import sys
# Optionally, change fonts to use LaTeX fonts
# from matplotlib import rc
# rc('text', usetex=True)
# rc('font', family='serif')
# Read results
ofr = Reader(mat_file, "dymola")
(time, E_PV) = ofr.values('EPVTot.y')
if (abs(max(time)-365*24*3600.) > 1):
print(f"Error: Simulation did not run a full year, final time is {max(time)} s.")
sys.exit(1)
EHeaPum = ofr.max('EHeaPum.y')
print(f"Total HP electricity: {EHeaPum/1000.0/3600:g} kWh (was in Sommer 0.69 GWh)")
E_PVTot = ofr.max('EPVTot.y')
P_PVTot = ofr.max('ele[1].pv.P') + ofr.max('ele[2].pv.P') + ofr.max('ele[3].pv.P')
#print(ofr.varNames("EPV*"))
print(f'Total PV energy: {E_PVTot:g} J, ({E_PVTot /1000.0 / 3600:g} kWh)')
print(f'Total PV power: {P_PVTot:g} W')
# Heat pumps
QConMaxOff = ofr.max('bui[1].ets.proHeaWat.heaPum.QCon_flow')
QConMaxRes = ofr.max('bui[2].ets.proHeaWat.heaPum.QCon_flow')
QConMaxHos = ofr.max('bui[3].ets.proHeaWat.heaPum.QCon_flow')
print(f"Heat pump capacity (space heating only): {QConMaxOff:g}, {QConMaxRes:g}, {QConMaxHos:g} W (office, residential, hospital).")
print(f"Heat pump capacity (space heating only): {QConMaxOff + QConMaxRes + QConMaxHos:g} W (total).")
QSHWConMaxOff = ofr.max('bui[1].bui.QReqHotWat_flow')
QSHWConMaxRes = ofr.max('bui[2].bui.QReqHotWat_flow')
QSHWConMaxHos = ofr.max('bui[3].bui.QReqHotWat_flow')
print(f"Heat pump capacity (service hot water only): {QSHWConMaxOff:g}, {QSHWConMaxRes:g}, {QSHWConMaxHos:g} W (office, residential, hospital).")
print(f"Heat pump capacity (service hot water only): {QSHWConMaxOff + QSHWConMaxRes + QSHWConMaxHos:g} W (total).")
QCooHexMaxOff = ofr.min('bui[1].ets.hexChi.Q2_flow')
QCooHexMaxRes = ofr.min('bui[2].ets.hexChi.Q2_flow')
QCooHexMaxHos = ofr.min('bui[3].ets.hexChi.Q2_flow')
print(f"Cooling heat exchanger capacity: {QCooHexMaxOff:g}, {QCooHexMaxRes:g}, {QCooHexMaxHos:g} W (office, residential, hospital).")
print(f"Cooling heat exchanger capacity: {QCooHexMaxOff + QCooHexMaxRes + QCooHexMaxHos:g} W (total).")
# Borefield. This assumes the borefield to be balanced, which it roughly is.
QBorFieMin = ofr.min('EBorFie.y')
QBorFieMax = ofr.max('EBorFie.y')
print(f"Borefield used capacity: {(QBorFieMax-QBorFieMin):g} J, ({(QBorFieMax-QBorFieMin) /1000.0 / 3600:g} kWh)")
# Sewage plant
QSew = ofr.max('pla.senDifEntFlo.dH_flow')
print(f"Sewage heat, rejected from loop to sewage if positive: {QSew:g} W")
# Heat pumps SPF
EEleHeaPumHeaOff = ofr.integral('bui[1].ets.proHeaWat.heaPum.P')
EEleHeaPumHeaRes = ofr.integral('bui[2].ets.proHeaWat.heaPum.P')
EEleHeaPumHeaHos = ofr.integral('bui[3].ets.proHeaWat.heaPum.P')
EEleHeaPumSHWOff = ofr.integral('bui[1].ets.proHotWat.heaPum.P')
EEleHeaPumSHWRes = ofr.integral('bui[2].ets.proHotWat.heaPum.P')
EEleHeaPumSHWHos = ofr.integral('bui[3].ets.proHotWat.heaPum.P')
EEleHeaPum = EEleHeaPumHeaOff + EEleHeaPumHeaRes + EEleHeaPumHeaHos \
+ EEleHeaPumSHWOff + EEleHeaPumSHWRes + EEleHeaPumSHWHos # electrical energy of all heat pumps
# Space heating load
EHeaOff = ofr.integral('bui[1].bui.QReqHea_flow')
EHeaRes = ofr.integral('bui[2].bui.QReqHea_flow')
EHeaHos = ofr.integral('bui[3].bui.QReqHea_flow')
# Service hot water load
ESHWOff = ofr.integral('bui[1].bui.QReqHotWat_flow')
ESHWRes = ofr.integral('bui[2].bui.QReqHotWat_flow')
ESHWHos = ofr.integral('bui[3].bui.QReqHotWat_flow')
SPFHea = (ESHWOff + ESHWRes + ESHWHos + EHeaOff + EHeaRes + EHeaHos)/EEleHeaPum
print(f"SPF of heat pumps (space heating) : {EHeaOff/EEleHeaPumHeaOff:g}, {EHeaRes/EEleHeaPumHeaRes:g}, {EHeaHos/EEleHeaPumHeaHos:g}, \
{(EHeaOff + EHeaRes + EHeaHos)/(EEleHeaPumHeaOff + EEleHeaPumHeaRes + EEleHeaPumHeaHos):g} (office, residential, hospital, total)")
print(f"SPF of heat pumps (service hot water): {ESHWOff/EEleHeaPumSHWOff:g}, {ESHWRes/EEleHeaPumSHWRes:g}, {ESHWHos/EEleHeaPumSHWHos:g}, \
{(ESHWOff + ESHWRes + ESHWHos)/(EEleHeaPumSHWOff + EEleHeaPumSHWRes + EEleHeaPumSHWHos):g} (office, residential, hospital, total)")
print(f"Seasonal performance factor of all heat pumps: {SPFHea:g}")
# Constraint violation
class bcolors:
OKGREEN = '\033[92m'
FAIL = '\033[91m'
ENDC = '\033[0m'
(time, conVio_t) = ofr.values('conVio.y')
conVio = conVio_t[-1]
col = bcolors.OKGREEN if conVio < 3E-3 else bcolors.FAIL
#plt.plot(time, conVio_t)
#plt.show()
print(f"{col}Constraint violation {conVio:g}.{bcolors.ENDC}")
if __name__ == '__main__':
# If run with -p, no simulation is done.
import sys
skip_simulation = len(sys.argv) > 1 and sys.argv[1] == '-p'
if not skip_simulation:
model = "District.System"
s = Simulator(model)
simulateCase(s)
printResults('System.mat')