forked from vttresearch/ArchetypeBuildingModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestscript.jl
293 lines (239 loc) · 8.29 KB
/
testscript.jl
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#=
testscript.jl
A makeshift script for testing the functionality of `ArBuMo.jl`.
Contains a lot of old code snippets that might not work without changes to the
module. Included primarily to give some idea how the module operates under the
hood.
=#
using Pkg
Pkg.activate("test")
using Test
using Plots
using ArBuMo
m = Module()
# Open database
# Provide the url for a datastore containing the required raw input data and the archetype building definitions.
url = "sqlite:///C:\\_SPINEPROJECTS\\SpineOpt_PED_demo_fluid\\.spinetoolbox\\data_and_definitions.sqlite"
# Output url, in-memory db for testing.
output_url = "sqlite://"
@info "Opening database..."
@time using_spinedb(url, m)
realization = :realization # Realization data scenario name from stochastic input
## Run tests
lmt = Inf
@info "Running input data and definition tests..."
@testset begin
@time run_parameter_tests(m; limit=lmt)
@time run_object_class_tests(m; limit=lmt)
@time run_structure_type_tests(m)
end
## Test creating the `ScopeData` types automatically
#=
@info "Processing the `ScopeData` objects for the test `building_scope` objects..."
@time scope_data_final = Dict(scope => ScopeData(scope; mod=m) for scope in m.building_scope())
## Test creating `EnvelopeData`
@info "Processing the `EnvelopeData` objects for the test `building_archetype` objects..."
@time envelope_data = Dict(
archetype => EnvelopeData(
archetype,
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)];
mod=m,
) for archetype in m.building_archetype()
)
## Test creating `LoadsData`
@info "Processing the `LoadsData` objects for the test `building_archetype` objects..."
@time loads_data = Dict(
archetype => LoadsData(
archetype,
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)];
mod=m,
) for archetype in m.building_archetype()
)
## Test creating `BuildingNodeNetwork` and `BuildingNodeData`
@info "Processing `BuildingNodeNetwork` and `BuildingNodeData` for the test `building_archetype` objects..."
@time building_node_network = Dict(
archetype => create_building_node_network(
archetype,
only(m.building_archetype__building_fabrics(building_archetype=archetype)),
only(m.building_archetype__building_systems(building_archetype=archetype)),
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)],
envelope_data[archetype],
loads_data[archetype];
mod=m
) for archetype in m.building_archetype()
)
## Test autocreation of `WeatherData`
@info "Testing automatic creation of `WeatherData`..."
@time weather_data = Dict(
archetype => WeatherData(
archetype,
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)],
envelope_data[archetype],
building_node_network[archetype];
mod=m,
) for archetype in m.building_archetype()
)
## Test creating `AbstractNodeNetwork` and `AbstractNode`
@info "Processing `AbstractNodeNetwork` and `AbstractNode`..."
@time abstract_node_network = Dict(
archetype => create_abstract_node_network(
archetype,
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)],
envelope_data[archetype],
building_node_network[archetype],
weather_data[archetype];
mod=m
) for archetype in m.building_archetype()
)
## Test creating `BuildingProcessData`
@info "Processing the `BuildingProcessData` objects for the test `building_archetype` objects..."
@time building_process_data = Dict(
(archetype, process) => BuildingProcessData(
archetype,
process,
scope_data_final[only(
m.building_archetype__building_scope(building_archetype=archetype),
)],
weather_data[archetype];
mod=m,
) for archetype in m.building_archetype() for
process in m.building_systems__building_process(
building_systems=only(
m.building_archetype__building_systems(building_archetype=archetype),
),
)
)
=#
## Test creating `ArchetypeBuilding`s
@info "Processing `ArchetypeBuilding` objects..."
@time archetype_dictionary = Dict(
archetype => ArchetypeBuilding(
archetype;
mod=m,
save_layouts=false,
realization=realization,
) for archetype in m.building_archetype(:DH1_LBM)
)
## Test heating/cooling demand calculations.
@info "Creating `ArchetypeBuildingResults`..."
@time archetype_results = Dict(
archetype => ArchetypeBuildingResults(val; mod=m, realization=realization) for
(archetype, val) in archetype_dictionary
)
## Test creating the results database structures.
@info "Initializing result classes..."
@time results__building_archetype,
results__building_archetype__building_node,
results__building_archetype__building_process,
results__system_link_node = initialize_result_classes!(m)
@info "Adding results..."
@time add_results!(
results__building_archetype,
results__building_archetype__building_node,
results__building_archetype__building_process,
results__system_link_node,
archetype_results;
mod=m,
)
## Test creating and writing SpineOpt input
#=
@info "Creating `SpineOptInput`..."
@time spineopt = SpineOptInput(archetype_results; mod=m)
write_to_url(output_url, spineopt)
=#
## Test creating and writing Backbone input
#=
@info "Creating `BackboneInput`..."
@time backbone = BackboneInput(archetype_results; mod=m)
#write_to_url(output_url, backbone)
=#
## Test creating generic input
@info "Creating `GenericInput`..."
@time generic = GenericInput(archetype_results; mod=m)
@time write_to_url(output_url, generic)
## Plot diagnostics.
results = first(values(archetype_results))
weather_plt = plot(; title="Ambient temperatures in [C]")
plot!(
weather_plt,
keys(results.archetype.weather_data.ambient_temperature_K),
values(results.archetype.weather_data.ambient_temperature_K) .- 273.15;
label="Ambient",
)
plot!(
weather_plt,
keys(results.archetype.weather_data.ground_temperature_K),
values(results.archetype.weather_data.ground_temperature_K) .- 273.15;
label="Ground",
)
display(weather_plt)
irradiation_plot = plot(; title="Effective irradiation in [W/m2]")
for dir in ArBuMo.solar_directions
plot!(
irradiation_plot,
keys(results.archetype.weather_data.total_effective_solar_irradiation_W_m2[dir]),
values(results.archetype.weather_data.total_effective_solar_irradiation_W_m2[dir]),
label=string(dir),
)
end
display(irradiation_plot)
temp_plt = plot(; title="Node temperatures in [C]")
for (n, ts) in results.temperatures_K
plot!(temp_plt, keys(ts), values(ts) .- 273.15, label=string(n))
end
display(temp_plt)
hvac_plt = plot(; title="Heating/cooling demand in [kW]")
for (name, demand) in
["heating" => results.heating_demand_kW, "cooling" => results.cooling_demand_kW]
for (n, ts) in demand
plot!(hvac_plt, keys(ts), values(ts), label=name * ": " * string(n))
end
end
display(hvac_plt)
process_plt = plot(; title="HVAC consumption in [kW]")
for (p, ts) in results.hvac_consumption_kW
plot!(process_plt, keys(ts), values(ts), label=string(p))
end
display(process_plt)
correction_plt = plot(; title="Preliminary demands and corrections in [W]")
plot!(
correction_plt,
keys(results.archetype.weather_data.preliminary_heating_demand_W),
values(results.archetype.weather_data.preliminary_heating_demand_W),
label="Preliminary heating",
)
plot!(
correction_plt,
keys(results.archetype.weather_data.preliminary_cooling_demand_W),
values(results.archetype.weather_data.preliminary_cooling_demand_W),
label="Preliminary cooling",
)
plot!(
correction_plt,
keys(results.heating_correction_W),
values(results.heating_correction_W),
label="Heating correction",
)
plot!(
correction_plt,
keys(results.cooling_correction_W),
values(results.cooling_correction_W),
label="Cooling correction",
)
display(correction_plt)
hc_ratio_plt = plot(
keys(results.heating_to_cooling_ratio),
values(results.heating_to_cooling_ratio);
title="Heating-to-cooling demand ratio"
)
display(hc_ratio_plt)